119 lines
7.1 KiB
C
119 lines
7.1 KiB
C
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<IEntity> 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 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<IEntity> scene = {};
|
|
if (!service.SpawnScene(site.Container.GetOrigin(), scene)) return false;
|
|
int rifles;
|
|
foreach (IEntity entity : scene)
|
|
{
|
|
if (!entity || !entity.GetPrefabData() || 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<IEntity> 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 RIFLE CARBINE: stored=%1", carbines);
|
|
return rifles == 1 && maps == 1 && pistols == 1 && (!System.IsCLIParam("errRifleCarbine") || carbines == 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<IEntity> carried = {}; inventory.GetItems(carried);
|
|
if (!carried.Contains(m_ERRLooseRifle) || !ERR_SpawnSceneInventory.InStorage(m_ERRLooseRifle)) return;
|
|
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))) { Print("ERR SMOKE FAIL: carbine not configured", 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<IEntity> 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");
|
|
}
|
|
}
|