11 [
Attribute(SCR_EArsenalSupplyCostType.DEFAULT.ToString(),
desc:
"Cost type of items. If it is not DEFAULT than it will try to get the diffrent supply cost if the item has it assigned" , uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalSupplyCostType),
category:
"Settings")]
12 protected SCR_EArsenalSupplyCostType m_eSupplyCostType;
14 [
Attribute(
"",
desc:
"Toggle supported SCR_EArsenalItemType by this arsenal, items are gathered from SCR_Faction or from the overwrite config", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(
SCR_EArsenalItemType),
category:
"Settings")]
17 [
Attribute(
"",
desc:
"Toggle supported SCR_EArsenalItemMode by this arsenal, items are gathered from SCR_Faction or from the overwrite config", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(
SCR_EArsenalItemMode),
category:
"Settings")]
23 [
Attribute(
category:
"Overwrite",
desc:
"If empty this will be ignored. For ease of use do not edit this directly in the prefab, use a config instead. The items added the config will allow the arsenal to spawn these items within it. Note that it will still filter on type, meaning that if weapons are added to the list but disabled in the Supported types then they will not show in the arsenal. Changing faction will not have any effect if this is not null")]
26 [
Attribute(
"1",
desc:
"Get default faction if current faction could not be found",
category:
"Settings")]
27 protected bool m_bGetDefaultIfNoFaction;
29 [
Attribute(
"0",
desc:
"If true will try and find the SCR_FactionAffiliationComponent from parent if it was not found on self",
category:
"Settings")]
30 protected bool m_bAllowGetFactionFromParent;
32 [
Attribute(
"0",
desc:
"Save type of Arsenal. Only applicable if there is a save arsenal action attached to the arsenal.\nSAVING_DISABLED: Saving action is disabled.\nIN_ARSENAL_ITEMS_ONLY: Only allow saving if all the items the player has are in the arsenal as well.\nFACTION_ITEMS_ONLY: Only allow saving if all the items the player has in their inventory are of the faction of the arsenal.\nNO_RESTRICTIONS: No restriction as what the arsenal is allowed to save.", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalSaveType),
category:
"Settings")]
33 protected SCR_EArsenalSaveType m_eArsenalSaveType;
35 [
Attribute(
"0",
desc:
"If false it will get the arsenals current faction and change when the faction is updated. If true it will never check the on faction and use the default faction assigned. Use this if you want the content to never change or if there is never a current faction",
category:
"Settings")]
36 protected bool m_bAlwaysUseDefaultFaction;
38 protected bool m_bArsenalEnabled =
true;
41 protected bool m_bArsenalSavingDisplayedIfDisabled =
true;
42 protected bool m_bHasSaveArsenalAction =
false;
44 protected SCR_ArsenalInventoryStorageManagerComponent m_InventoryComponent;
45 protected UniversalInventoryStorageComponent m_StorageComponent;
47 protected FactionManager m_FactionManager;
52 protected bool m_bIsClearingInventory;
56 bool IsArsenalEnabled()
58 return m_bArsenalEnabled;
63 void SetArsenalEnabled(
bool enable)
65 if (m_bArsenalEnabled == enable)
69 if ((gameMode && !gameMode.IsMaster()) || (!gameMode && Replication.IsClient()))
74 m_eOnDisableArsenalModes = m_eSupportedArsenalItemModes;
75 SetSupportedArsenalItemModes(0);
79 SetSupportedArsenalItemModes(m_eOnDisableArsenalModes);
82 SetArsenalEnabledBroadcast(enable);
83 Rpc(SetArsenalEnabledBroadcast, enable);
87 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
88 protected void SetArsenalEnabledBroadcast(
bool enable)
90 m_bArsenalEnabled = enable;
95 SCR_EArsenalSupplyCostType GetSupplyCostType()
97 return m_eSupplyCostType;
102 bool IsArsenalUsingSupplies()
108 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(owner);
110 return resourceComponent && resourceComponent.IsResourceTypeEnabled();
115 SCR_EArsenalSaveType GetArsenalSaveType()
117 return m_eArsenalSaveType;
122 bool IsArsenalSavingDisplayedIfDisabled()
124 return m_bArsenalSavingDisplayedIfDisabled;
131 void SetHasSaveArsenalAction(
bool hasSaveArsenalAction)
133 m_bHasSaveArsenalAction = hasSaveArsenalAction;
139 bool HasSaveArsenalAction()
141 return m_bHasSaveArsenalAction;
147 void SetArsenalSaveType(SCR_EArsenalSaveType saveType)
149 if (m_eArsenalSaveType == saveType)
152 RPL_SetArsenalSaveType(saveType);
153 Rpc(RPL_SetArsenalSaveType, saveType);
159 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
160 void RPL_SetArsenalSaveType(SCR_EArsenalSaveType saveType)
163 if (m_eArsenalSaveType == saveType)
166 m_eArsenalSaveType = saveType;
168 if (saveType != SCR_EArsenalSaveType.SAVING_DISABLED)
169 m_bArsenalSavingDisplayedIfDisabled =
true;
176 return m_eSupportedArsenalItemTypes;
183 static SCR_ArsenalComponent FindArsenalComponent(notnull IEntity entity,
bool getFromSlotted =
true)
192 return arsenalComponent;
199 m_eSupportedArsenalItemTypes = types;
207 return m_eSupportedArsenalItemModes;
214 m_eSupportedArsenalItemModes = modes;
222 return m_eEditableAttributeGroups;
227 SCR_ArsenalInventoryStorageManagerComponent GetArsenalInventoryComponent()
229 return m_InventoryComponent;
237 return m_OverwriteArsenalConfig;
243 bool GetAvailablePrefabs(out notnull array<ResourceName> availablePrefabs)
245 array<SCR_ArsenalItem> arsenalItems = {};
246 if (!GetFilteredArsenalItems(arsenalItems))
251 for (
int i = 0; i < arsenalItems.Count(); i++)
257 availablePrefabs.Insert(itemToSpawn.GetItemResourceName());
259 return !availablePrefabs.IsEmpty();
273 if (m_bAlwaysUseDefaultFaction)
277 if (!faction && m_bGetDefaultIfNoFaction)
292 bool GetFilteredArsenalItems(out notnull array<SCR_ArsenalItem> filteredArsenalItems, EArsenalItemDisplayType requiresDisplayType = -1)
295 if (m_OverwriteArsenalConfig)
297 GetFilteredOverwriteArsenalItems(filteredArsenalItems, requiresDisplayType);
298 return !filteredArsenalItems.IsEmpty();
302 SCR_EntityCatalogManagerComponent catalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
307 filteredArsenalItems = catalogManager.GetFilteredArsenalItems(m_eSupportedArsenalItemTypes, m_eSupportedArsenalItemModes, GetAssignedFaction(), requiresDisplayType);
308 return !filteredArsenalItems.IsEmpty();
315 bool GetFilteredOverwriteArsenalItems(out notnull array<SCR_ArsenalItem> filteredArsenalItems, EArsenalItemDisplayType requiresDisplayType = -1)
317 filteredArsenalItems = m_OverwriteArsenalConfig.GetFilteredArsenalItems(m_eSupportedArsenalItemTypes, m_eSupportedArsenalItemModes, requiresDisplayType);
318 return !filteredArsenalItems.IsEmpty();
335 array<SCR_ArsenalItem> arsenalItems = {};
336 if (!GetFilteredArsenalItems(arsenalItems))
341 array<ResourceName> arsenalPrefabs = {};
343 int arsenalItemCount = arsenalItems.Count();
344 for (
int i = 0; i < arsenalItemCount; i++)
350 arsenalPrefabs.Insert(itemToSpawn.GetItemResourceName());
353 if (m_OnArsenalUpdated)
354 m_OnArsenalUpdated.Invoke(arsenalPrefabs);
356 if (Replication.IsServer())
357 Rpc(RPC_OnArsenalUpdated, m_eSupportedArsenalItemTypes, m_eSupportedArsenalItemModes);
361 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
365 GetGame().GetCallqueue().CallLater(DelayedOnArsenalUpdatedClient, param1: itemTypes, param2: itemModes);
371 m_eSupportedArsenalItemTypes = itemTypes;
372 m_eSupportedArsenalItemModes = itemModes;
377 if (m_OnArsenalUpdated)
379 array<ResourceName> arsenalPrefabs = {};
380 GetAvailablePrefabs(arsenalPrefabs);
382 m_OnArsenalUpdated.Invoke(arsenalPrefabs);
389 return arsenalItemType & m_eSupportedArsenalItemTypes
390 && arsenalItemMode & m_eSupportedArsenalItemModes;
394 protected bool GetItemValid(
SCR_Faction faction,
int index, out
bool isEmpty =
true)
403 if (!m_OnArsenalUpdated)
406 return m_OnArsenalUpdated;
410 protected void OnFactionChanged(FactionAffiliationComponent owner,
Faction previousFaction,
Faction newFaction)
416 override protected void OnPostInit(IEntity owner)
422 if (GetArsenalSaveType() == SCR_EArsenalSaveType.SAVING_DISABLED)
423 m_bArsenalSavingDisplayedIfDisabled =
false;
425 SetEventMask(owner, EntityEvent.INIT);
428 m_InventoryComponent = SCR_ArsenalInventoryStorageManagerComponent.Cast(owner.FindComponent(SCR_ArsenalInventoryStorageManagerComponent));
429 m_StorageComponent = UniversalInventoryStorageComponent.Cast(owner.FindComponent(UniversalInventoryStorageComponent));
434 override protected void EOnInit(IEntity owner)
439 GetGame().GetCallqueue().CallLater(FactionInit, param1: owner);
446 protected void FactionInit(IEntity owner)
455 if (owner.GetParent())
464 if (!m_bAlwaysUseDefaultFaction)
466 RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
467 if (rplComponent && rplComponent.Role() == RplRole.Authority)
475 override protected void OnDelete(IEntity owner)
480 RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
481 if (rplComponent && rplComponent.Role() == RplRole.Authority)
489 override bool RplSave(ScriptBitWriter writer)
491 writer.WriteInt(m_eSupportedArsenalItemTypes);
492 writer.WriteInt(m_eSupportedArsenalItemModes);
493 writer.WriteInt(GetArsenalSaveType());
494 writer.WriteBool(m_bArsenalEnabled);
499 override bool RplLoad(ScriptBitReader reader)
501 int itemTypes, itemModes, saveType;
502 bool isArsenalEnabled;
504 reader.ReadInt(itemTypes);
505 reader.ReadInt(itemModes);
506 reader.ReadInt(saveType);
507 reader.ReadBool(isArsenalEnabled);
509 RPC_OnArsenalUpdated(itemTypes, itemModes);
510 RPL_SetArsenalSaveType(saveType);
511 SetArsenalEnabledBroadcast(isArsenalEnabled);
518 enum SCR_EArsenalSaveType
527 enum SCR_EArsenalSupplyCostType