modded class ERR_AdminMenu { void ERR_GroundProbeShow() { ShowPage(20); } bool ERR_GroundProbeSave() { int index = m_StarterCatalog.Find(ERR_TerrainCatalog.Key(ERR_Supplies.Pistol())); if (index < 0 || !m_Ready || !IsFocused() || m_Age > 6 || m_ClickDelay > 0) return false; SCR_ComboBoxComponent.GetComboBoxComponent("StarterCatalogItem", GetRootWidget()).SetCurrentItem(index, false, false, false); SCR_ComboBoxComponent.GetComboBoxComponent("StarterDestination", GetRootWidget()).SetCurrentItem(1, false, false, false); SCR_EditBoxComponent.GetEditBoxComponent("StarterQuantity", GetRootWidget()).SetValue("2"); OnStarterButton(SCR_ButtonTextComponent.GetButtonText("StarterAdd", GetRootWidget())); return true; } bool ERR_GroundProbeVisible() { return m_Ready && m_StarterSaved.Contains(ERR_TerrainCatalog.Key(ERR_Supplies.Pistol()) + " ground") && m_StarterSaved.Contains(ERR_TerrainCatalog.Key(ERR_Supplies.Pistol()) + " backpack"); } } modded class ERR_SiteService { void ERR_LogStarterStock() { foreach (ERR_StockPlacement item : m_Placements) { if (!item.Item || !item.Inventory) { Print("ERR RIFLE STOCK: missing entity"); continue; } array contents = {}; item.Inventory.GetItems(contents); PrintFormat("ERR RIFLE STOCK: prefab=%1 accepted=%2 contained=%3 optional=%4 canInsert=%5", item.Item.GetPrefabData().GetPrefabName(), item.Accepted, contents.Contains(item.Item), item.Optional, item.Inventory.CanInsertItem(item.Item)); } } } modded class ERR_GameMode { protected ref ERR_SiteService m_ERRRifleSites; protected ResourceName m_ERRTestRifle; protected ResourceName m_ERRTestCarbine; protected int m_ERRRifleTicks; protected bool m_ERRStockConfigured; protected IEntity m_ERRLooseRifle; protected bool m_ERRPickupRequested; protected int m_ERRGroundMenuStage; protected override void EOnInit(IEntity owner) { super.EOnInit(owner); if (System.IsCLIParam("errRifleFull") && Replication.IsServer() && !SCR_Global.IsEditMode()) GetGame().GetCallqueue().CallLater(ERR_RifleFullPoll, 500, true); } protected bool ERR_CheckRifleScene(ERR_SiteService service) { ERR_SiteRuntime site = service.Find("everon-prison-1"); if (!site || !site.Container) return false; array scene = {}; if (!service.SpawnScene(site.Container.GetOrigin(), scene)) return false; int rifles, groundCarbines; foreach (IEntity entity : scene) { if (!entity || !entity.GetPrefabData()) continue; if (entity.GetPrefabData().GetPrefabName() == m_ERRTestCarbine) { InventoryItemComponent loose = InventoryItemComponent.Cast(entity.FindComponent(InventoryItemComponent)); if (loose && !loose.GetParentSlot() && vector.Distance(entity.GetOrigin(), site.Container.GetOrigin()) < 3) groundCarbines++; } if (entity.GetPrefabData().GetPrefabName() != m_ERRTestRifle) continue; InventoryItemComponent item = InventoryItemComponent.Cast(entity.FindComponent(InventoryItemComponent)); if (!item || item.GetParentSlot() || !ERR_Actors.DryGround(entity.GetOrigin()) || vector.Distance(entity.GetOrigin(), site.Container.GetOrigin()) > 3) return false; rifles++; m_ERRLooseRifle = entity; PrintFormat("ERR RIFLE LOOSE: distance=%1 origin=%2", vector.Distance(entity.GetOrigin(), site.Container.GetOrigin()), entity.GetOrigin()); } InventoryStorageManagerComponent inventory = InventoryStorageManagerComponent.Cast(site.Container.FindComponent(InventoryStorageManagerComponent)); array contents = {}; inventory.GetItems(contents); int maps, pistols, carbines; foreach (IEntity contained : contents) { if (contained.GetPrefabData().GetPrefabName() == ERR_Supplies.Pistol()) pistols++; if (contained.FindComponent(SCR_MapGadgetComponent)) maps++; if (contained.GetPrefabData().GetPrefabName() == m_ERRTestCarbine) carbines++; } PrintFormat("ERR RIFLE VERIFIED: loose=%1 maps=%2 pistols=%3 sceneRoots=%4", rifles, maps, pistols, scene.Count()); PrintFormat("ERR GROUND CARBINE: stored=%1 ground=%2", carbines, groundCarbines); return rifles == 1 && maps == 1 && pistols == 1 && (!System.IsCLIParam("errRifleCarbine") || carbines == 0 && groundCarbines == 1); } protected void ERR_RifleFullPoll() { if (!PreparationError().IsEmpty()) { Print("ERR SMOKE FAIL: full rifle mission " + PreparationError(), LogLevel.ERROR); GetGame().GetCallqueue().Remove(ERR_RifleFullPoll); return; } if (!Active()) return; SCR_PlayerController pc = SCR_PlayerController.Cast(GetGame().GetPlayerController()); if (!pc || !pc.GetControlledEntity() || !Players().CurrentActor(pc.GetControlledEntity())) return; InventoryStorageManagerComponent inventory = InventoryStorageManagerComponent.Cast(pc.GetControlledEntity().FindComponent(InventoryStorageManagerComponent)); if (!m_ERRPickupRequested) { if (!ERR_CheckRifleScene(Sites()) || !inventory || !inventory.TryInsertItem(m_ERRLooseRifle)) { Print("ERR SMOKE FAIL: full mission rifle scene or pickup", LogLevel.ERROR); GetGame().GetCallqueue().Remove(ERR_RifleFullPoll); return; } m_ERRPickupRequested = true; return; } array carried = {}; inventory.GetItems(carried); if (!carried.Contains(m_ERRLooseRifle) || !ERR_SpawnSceneInventory.InStorage(m_ERRLooseRifle)) return; if (m_ERRGroundMenuStage == 0) { ERR_AdminMenu.Open(); m_ERRGroundMenuStage = 1; return; } ERR_AdminMenu menu = ERR_AdminMenu.GetOpenMenu(); if (!menu) return; if (m_ERRGroundMenuStage == 1) { if (!menu.ERR_StarterProbeReady(1)) return; menu.ERR_GroundProbeShow(); if (!menu.ERR_StarterProbeBrowse()) return; m_ERRGroundMenuStage = 2; return; } if (m_ERRGroundMenuStage == 2) { if (!menu.ERR_GroundProbeSave()) return; m_ERRGroundMenuStage = 3; return; } if (!menu.ERR_GroundProbeVisible()) return; ERR_StartBackpack savedLoadout = new ERR_StartBackpack(); array savedStock = {}; savedLoadout.Stock(savedStock); int inBag, onGround; foreach (ERR_SiteStock stock : savedStock) { if (stock.Prefab != ERR_Supplies.Pistol()) continue; if (stock.OnGround) onGround += stock.Count; else inBag += stock.Count; } if (inBag != 1 || onGround != 2) { Print("ERR SMOKE FAIL: menu destination edit or persistence", LogLevel.ERROR); return; } Print("ERR SMOKE PASS: actual destination menu saved two ground pistols separately from one backpack pistol; snapshot and disk reload verified"); menu.Close(); Print("ERR SMOKE PASS: full mission active; player admitted; map and pistol stored; oversized rifle streamed and picked up into player inventory"); Print("ERR SMOKE COMPLETE: starting rifles full mission"); GetGame().GetCallqueue().Remove(ERR_RifleFullPoll); } protected void ERR_FindTestRifle(ResourceName resource, string exactPath = "") { if (resource.EndsWith("/Rifle_M16A2.et")) m_ERRTestRifle = resource; if (resource.EndsWith("/Rifle_M16A2_carbine_M203.et")) m_ERRTestCarbine = resource; } override protected void StartScenario() { string outcome; if (!System.GetCLIParam("errSmokeOutcome", outcome) || outcome != "starting-rifles") { super.StartScenario(); return; } if (!m_ERRStockConfigured) { SearchResourcesFilter filter = new SearchResourcesFilter(); filter.fileExtensions = {"et"}; filter.recursive = true; filter.rootPath = "$ArmaReforger:Prefabs/Weapons/Rifles/M16"; ResourceDatabase.SearchResources(filter, ERR_FindTestRifle); if (m_ERRTestRifle.IsEmpty()) { Print("ERR SMOKE FAIL: M16 resource not found", LogLevel.ERROR); return; } ERR_StartBackpack supplies = GetGame().ERR_StartingSupplies(); if (!supplies.Set(m_ERRTestRifle, 1) || !supplies.Set(ERR_Supplies.Pistol(), 1) || !supplies.SetMode(true)) { Print("ERR SMOKE FAIL: custom stock not saved", LogLevel.ERROR); return; } if (System.IsCLIParam("errRifleCarbine") && (m_ERRTestCarbine.IsEmpty() || !supplies.Set(m_ERRTestCarbine, 1, "ground"))) { Print("ERR SMOKE FAIL: carbine not configured", LogLevel.ERROR); return; } ERR_StartBackpack reloaded = new ERR_StartBackpack(); array stock = {}; reloaded.Stock(stock); bool savedGround; foreach (ERR_SiteStock saved : stock) if (saved.Prefab == m_ERRTestCarbine && saved.OnGround && saved.Count == 1) savedGround = true; if (System.IsCLIParam("errRifleCarbine") && !savedGround) { Print("ERR SMOKE FAIL: ground destination not persisted", LogLevel.ERROR); return; } m_ERRStockConfigured = true; } if (System.IsCLIParam("errRifleFull")) { super.StartScenario(); return; } ERR_ScenarioDefinition def = ERR_ScenarioDefinition.Cast(SCR_BaseContainerTools.CreateInstanceFromPrefab("{ACA98B44E2173605}Configs/ERR/Tests/LegacySites.conf")); if (!def) { Print("ERR SMOKE FAIL: definition missing", LogLevel.ERROR); return; } ERR_SiteDefinition prison = def.Find("everon-prison-1"); prison.Guarded = false; m_ERRRifleSites = new ERR_SiteService(this); if (!m_ERRRifleSites.Begin(def, ERR_Supplies.Map(), false, prison)) { Print("ERR SMOKE FAIL: setup " + m_ERRRifleSites.FailureReason(), LogLevel.ERROR); return; } GetGame().GetCallqueue().CallLater(ERR_RiflePoll, 250, true); } protected void ERR_RiflePoll() { m_ERRRifleTicks++; if (m_ERRRifleTicks == 1 || m_ERRRifleTicks == 8 || m_ERRRifleTicks == 55) m_ERRRifleSites.ERR_LogStarterStock(); ERR_PrepareResult result = m_ERRRifleSites.Prepare(); if (result == ERR_PrepareResult.PENDING && m_ERRRifleTicks < 100) return; GetGame().GetCallqueue().Remove(ERR_RiflePoll); PrintFormat("ERR RIFLE RESULT: state=%1 reason=%2 ticks=%3", result, m_ERRRifleSites.FailureReason(), m_ERRRifleTicks); if (result != ERR_PrepareResult.READY) { Print("ERR SMOKE FAIL: starting rifle did not prepare", LogLevel.ERROR); return; } ERR_SiteRuntime site = m_ERRRifleSites.Find("everon-prison-1"); InventoryStorageManagerComponent inventory = InventoryStorageManagerComponent.Cast(site.Container.FindComponent(InventoryStorageManagerComponent)); array items = {}; inventory.GetItems(items); foreach (IEntity item : items) Print("ERR RIFLE CONTENT: " + item.GetPrefabData().GetPrefabName()); if (!ERR_CheckRifleScene(m_ERRRifleSites)) { Print("ERR SMOKE FAIL: rifle scene lost stock", LogLevel.ERROR); return; } Print("ERR SMOKE COMPLETE: starting rifles"); } }