Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ArsenalDisplayComponent.c
Go to the documentation of this file.
4
5class SCR_ArsenalDisplayComponent : SCR_ArsenalComponent
6{
7 [Attribute("0", desc: "Type of display data an arsenal item needs in in order to be displayed on this arsenal display", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EArsenalItemDisplayType), category: "Display settings")]
8 protected EArsenalItemDisplayType m_eArsenalItemDisplayType;
9
10 [Attribute("4", desc: "Refresh time in seconds. Every x time the arsenal will try to refresh")]
11 protected float m_fRefreshDelay;
12
13 protected ref array<SCR_WeaponRackSlotEntity> m_aSlots = {};
14
15 //------------------------------------------------------------------------------------------------
17 {
19 super.SetSupportedArsenalItemTypes(types);
20 }
21
22 //------------------------------------------------------------------------------------------------
24 {
26 super.SetSupportedArsenalItemModes(modes);
27 }
28
29 //------------------------------------------------------------------------------------------------
31 {
32 if (!slot || m_aSlots.Find(slot) != -1)
33 {
34 return;
35 }
36
37 m_aSlots.Insert(slot);
38 }
39
40 //------------------------------------------------------------------------------------------------
41 override void OnFactionChanged(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
42 {
45 }
46
47 //------------------------------------------------------------------------------------------------
48 override void OnArsenalGameModeTypeChanged(SCR_EArsenalGameModeType newArsenalGameModeType)
49 {
52 }
53
54 //------------------------------------------------------------------------------------------------
56 override void ClearArsenal()
57 {
58 for (int i = 0; i < m_aSlots.Count(); i++)
59 {
60 m_aSlots[i].RemoveItem();
61 }
62 }
63
64 //------------------------------------------------------------------------------------------------
66 protected void RefreshUpdate()
67 {
69 }
70
71 //------------------------------------------------------------------------------------------------
72 override void RefreshArsenal(bool init = false, SCR_Faction faction = null)
73 {
74 array<SCR_ArsenalItem> filteredArsenalItems = {};
75
76 //~ Could not get arsenal items
77 if (!GetFilteredArsenalItems(filteredArsenalItems, m_eArsenalItemDisplayType))
78 return;
79
80 int availableItemCount = filteredArsenalItems.Count();
81 int availableSlotCount = m_aSlots.Count();
82
83 SCR_ArsenalItem itemToSpawn;
84 SCR_WeaponRackSlotEntity currentSlot = null;
85 for (int i = 0; i < availableSlotCount; i++)
86 {
87 currentSlot = m_aSlots[i];
88 if (GetSlotValid(currentSlot))
89 {
90 continue;
91 }
92 else if(currentSlot && currentSlot.GetChildren())
93 {
94 currentSlot.RemoveItem();
95 }
96 else if (!currentSlot)
97 {
98 m_aSlots.RemoveOrdered(i--);
99 availableSlotCount--;
100 continue;
101 }
102
103 if (!currentSlot.CanSpawnItem())
104 {
105 continue;
106 }
107
108 int index = i % availableItemCount;
109 for (int j = 0; j < availableItemCount; j++)
110 {
111 itemToSpawn = filteredArsenalItems[index];
112 if (GetItemValidForSlot(itemToSpawn.GetItemType(), itemToSpawn.GetItemMode(), currentSlot.GetSlotSupportedItemTypes(), currentSlot.GetSlotSupportedItemModes()))
113 break;
114
115 itemToSpawn = null;
116 index++;
117 if (index >= availableItemCount)
118 index = 0;
119 }
120
121 if (!itemToSpawn)
122 continue;
123
124 currentSlot.SpawnNewItem(itemToSpawn.GetItemResource(), itemToSpawn, itemToSpawn.GetDisplayDataOfType(m_eArsenalItemDisplayType));
125 }
126 }
127
128 //------------------------------------------------------------------------------------------------
129 protected bool GetSlotValid(SCR_WeaponRackSlotEntity slotEntity, out bool isEmpty = true)
130 {
131 if (!slotEntity)
132 return false;
133
134 if (slotEntity.GetChildren() && slotEntity.GetChildren().GetPrefabData())
135 {
136 isEmpty = false;
138 }
139
140 return false;
141 }
142
143 //------------------------------------------------------------------------------------------------
144 protected bool GetItemValidForSlot(SCR_EArsenalItemType itemType, SCR_EArsenalItemMode itemMode, SCR_EArsenalItemType supportedSlotTypes, SCR_EArsenalItemMode supportedSlotModes)
145 {
146 return GetItemValid(itemType, itemMode) && SCR_Enum.HasPartialFlag(supportedSlotTypes, itemType) && SCR_Enum.HasPartialFlag(supportedSlotModes, itemMode);
147 }
148
149 //------------------------------------------------------------------------------------------------
150 override void EOnInit(IEntity owner)
151 {
152 super.EOnInit(owner);
153
154 IEntity child = owner.GetChildren();
155 while (child)
156 {
158 if (slot)
159 RegisterSlot(slot);
160
161 child = child.GetSibling();
162 }
163
164 RplComponent rpl = RplComponent.Cast(owner.FindComponent(RplComponent));
165 if (!rpl || (rpl && rpl.Role() == RplRole.Authority))
166 {
167 RefreshArsenal(true);
168
169 if (!SCR_Global.IsEditMode())
170 GetGame().GetCallqueue().CallLater(RefreshUpdate, m_fRefreshDelay * 1000, true);
171 }
172 }
173
174 //------------------------------------------------------------------------------------------------
175 override void OnPostInit(IEntity owner)
176 {
178 return;
179
180 super.OnPostInit(owner);
181
182 SetEventMask(owner, EntityEvent.INIT);
183 }
184
185 //------------------------------------------------------------------------------------------------
186 override protected void OnDelete(IEntity owner)
187 {
188 super.OnDelete(owner);
189
191 return;
192
193 GetGame().GetCallqueue().Remove(RefreshUpdate);
194 }
195}
ArmaReforgerScripted GetGame()
Definition game.c:1398
bool GetSlotValid(SCR_WeaponRackSlotEntity slotEntity, out bool isEmpty=true)
void RefreshUpdate()
Refresh arsenal after m_fRefreshDelay delay.
void RegisterSlot(SCR_WeaponRackSlotEntity slot)
bool GetItemValidForSlot(SCR_EArsenalItemType itemType, SCR_EArsenalItemMode itemMode, SCR_EArsenalItemType supportedSlotTypes, SCR_EArsenalItemMode supportedSlotModes)
float m_fRefreshDelay
ref array< SCR_WeaponRackSlotEntity > m_aSlots
void OnArsenalGameModeTypeChanged()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EArsenalGameModeType
SCR_EArsenalItemMode
SCR_EArsenalItemType
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external IEntity GetSibling()
void SetSupportedArsenalItemModes(SCR_EArsenalItemMode modes)
bool GetItemValid(SCR_EArsenalItemType arsenalItemType, SCR_EArsenalItemMode arsenalItemMode)
void RefreshArsenal(bool init=false, SCR_Faction faction=null)
bool GetFilteredArsenalItems(out notnull array< SCR_ArsenalItem > filteredArsenalItems, EArsenalItemDisplayType requiresDisplayType=-1)
void EOnInit(IEntity owner)
void SetSupportedArsenalItemTypes(SCR_EArsenalItemType types)
SCR_EArsenalItemType GetItemType()
SCR_ArsenalItemDisplayData GetDisplayDataOfType(EArsenalItemDisplayType displayType)
Resource GetItemResource()
SCR_EArsenalItemMode GetItemMode()
static bool IsEditMode()
Definition Functions.c:1566
void RemoveItem()
Delete the slot's item (first found child).
SCR_EArsenalItemType GetSlotSupportedItemTypes()
SCR_EArsenalItemMode GetCurrentOccupiedItemMode()
void SpawnNewItem(Resource itemResource, SCR_ArsenalItem arsenalData, SCR_ArsenalItemDisplayData itemDisplayData=null, bool deleteExisting=false)
SCR_EArsenalItemMode GetSlotSupportedItemModes()
bool CanSpawnItem(bool deleteExisting=false)
SCR_EArsenalItemMode GetCurrentOccupiedItemType()
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14