Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ArsenalItem.c
Go to the documentation of this file.
1[BaseContainerProps(configRoot: true), BaseContainerCustomCheckIntTitleField("m_bEnabled", "Arsenal Data", "DISABLED - Arsenal Data", 1)]
3{
4 [Attribute("2", desc: "Type of the arsenal item. An arsenal will only spawn items of types that it allows to be spawned. The item will not show up if it is not allowed. Eg: FieldDressing = HEAL", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalItemType))]
6
7 [Attribute("2", desc: "Item mode of arsenal, set this to what the behaviour is for the item. EG: FieldDressing = CONSUMABLE as it is used up or M16 with attachments = WEAPON_VARIANTS as it is not a default M16. Check other items in the faction config to see how it works.", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalItemMode))]
9
10 [Attribute(SCR_Enum.GetFlagValues(SCR_EArsenalGameModeType).ToString(), desc: "This value dictates in what (game)modes the arsenal item is available. All items with an Arsenal Data are always available if the Game Mode set in the ArsenalManager is Unrestricted", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(SCR_EArsenalGameModeType))]
12
13 [Attribute("10", desc: "Supply cost of item when using the resupply action and/or taking them from the arsenal inventory. Note in overwrite arsenal config this value is ignored and still taken from catalog.\n\nAny weapon should have their base cost as the attachment cost will be calculated by the system on init and on refund (Supports Item mode WEAPON and WEAPON_VARIANTS only to save performance)", params: "0 inf 1")]
14 protected int m_iSupplyCost;
15
16 [Attribute(desc: "Display data for SCR_ArsenalDisplayComponent. If Arsenal item has display data of the correct type for the entity with SCR_ArsenalDisplayComponent then it can be displayed on said entity")]
17 protected ref array<ref SCR_ArsenalItemDisplayData> m_aArsenalDisplayData;
18
19 [Attribute(desc: "Depending on the settings of the arsenal component arsenal items can have an alternative supply cost. So it will take the cost of the alternative rather than the default cost. \n\nIf an Arsenal is not cost type default and the arsenal item does not have that cost type defined than it will still use the default cost.\n\nIf multiple entries have the same value than the last in the array will be used")]
20 protected ref array<ref SCR_ArsenalAlternativeCostData> m_aArsenalAlternativeCostData;
21
22 [Attribute(SCR_ECharacterRank.PRIVATE.ToString(), desc: "Player must meet or exceed this rank in order to purchase this item", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_ECharacterRank))]
23 protected SCR_ECharacterRank m_eRequiredRank;
24
25 [Attribute("1", desc: "When true, buying the item consumes player's military allocated supplies. The cost is equal to supply cost of the item.")]
27
28 //~ Any attachements on the weapon or additional costs are saved for performance on cost calculation
29 protected ref array<SCR_ArsenalItem> m_aAdditionalCosts;
30 protected ref array<SCR_NonArsenalItemCostCatalogData> m_aNonArsenalAdditionalCosts;
33
35 protected ref Resource m_ItemResource;
36
37 //------------------------------------------------------------------------------------------------
43
44 //------------------------------------------------------------------------------------------------
50
51 //------------------------------------------------------------------------------------------------
57
58 //------------------------------------------------------------------------------------------------
61 {
62 if (!m_EntryParent)
63 return string.Empty;
64
65 return m_EntryParent.GetPrefab();
66 }
67
68 //------------------------------------------------------------------------------------------------
71 {
72 return m_ItemResource;
73 }
74
75 //------------------------------------------------------------------------------------------------
79 SCR_ArsenalItemDisplayData GetDisplayDataOfType(EArsenalItemDisplayType displayType)
80 {
82 {
83 if (displayData.GetDisplayType() == displayType)
84 return displayData;
85 }
86
87 return null;
88 }
89
90 //------------------------------------------------------------------------------------------------
92 SCR_ECharacterRank GetRequiredRank()
93 {
94 return m_eRequiredRank;
95 }
96
97 //------------------------------------------------------------------------------------------------
103
104 //--------------------------------- Direct Getter general or any faction ---------------------------------\\
105
106 //------------------------------------------------------------------------------------------------
107 //! Get supply cost of arsenal item
108 //! \param[in] supplyCostType What the supply cost is that should be obtained from the arsenal data. If the specific supply cost is not found then Default will be used instead
109 //! \param[in] addAdditionalCosts Will add any additional cost to the item, in general these are weapon attachments. You want to turn this false if refunding an item as it should reevaluate the cost depending on the attachments
110 //! \return Supplycost
111 int GetSupplyCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts = true)
112 {
113 int additionalCost;
114
115 if (addAdditionalCosts)
116 {
117 //~ Get the cost of any attachments on the item that are not in arsenal but still have a cost
119 {
121 {
122 additionalCost += data.GetSupplyCost(supplyCostType);
123 }
124 }
125 //~ Get the cost of any attachments on the item that can be in the arsenal
127 {
129 {
130 additionalCost += data.GetSupplyCost(supplyCostType);
131 }
132 }
133 }
134
135 if (supplyCostType != SCR_EArsenalSupplyCostType.DEFAULT && m_mArsenalAlternativeCostData != null)
136 {
137 SCR_ArsenalAlternativeCostData alternativeCost;
138 if (m_mArsenalAlternativeCostData.Find(supplyCostType, alternativeCost))
139 return alternativeCost.m_iSupplyCost + additionalCost;
140 }
141
142 return m_iSupplyCost + additionalCost;
143 }
144
145 //------------------------------------------------------------------------------------------------
146 int GetSupplyRefundAmount(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts = true)
147 {
148 int additionalCost;
149
150 if (addAdditionalCosts)
151 {
152 //~ Get the cost of any attachments on the item that are not in arsenal but still have a cost
154 {
156 {
157 additionalCost += data.GetSupplyCost(supplyCostType, false);
158 }
159 }
160 //~ Get the cost of any attachments on the item that can be in the arsenal
162 {
164 {
165 additionalCost += data.GetSupplyRefundAmount(supplyCostType);
166 }
167 }
168 }
169
170 if (supplyCostType != SCR_EArsenalSupplyCostType.DEFAULT && m_mArsenalAlternativeCostData != null)
171 {
172 SCR_ArsenalAlternativeCostData alternativeCost;
173 if (m_mArsenalAlternativeCostData.Find(supplyCostType, alternativeCost))
174 return alternativeCost.GetRefundAmount() + additionalCost;
175 }
176
177 return GetRefundAmountValue() + additionalCost;
178 }
179
180 //------------------------------------------------------------------------------------------------
181 int GetMilitarySupplyAllocationCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts = true)
182 {
184 return 0;
185
186 int additionalCost;
187
188 if (addAdditionalCosts)
189 {
190 //~ Get the cost of any attachments on the item that are not in arsenal but still have a cost
192 {
194 {
195 additionalCost += data.GetSupplyCost(supplyCostType);
196 }
197 }
198 //~ Get the cost of any attachments on the item that can be in the arsenal
200 {
202 {
203 if (!data.GetUseMilitarySupplyAllocation())
204 continue;
205
206 additionalCost += data.GetSupplyCost(supplyCostType);
207 }
208 }
209 }
210
211 if (supplyCostType != SCR_EArsenalSupplyCostType.DEFAULT && m_mArsenalAlternativeCostData != null)
212 {
213 SCR_ArsenalAlternativeCostData alternativeCost;
214 if (m_mArsenalAlternativeCostData.Find(supplyCostType, alternativeCost))
215 return alternativeCost.m_iSupplyCost + additionalCost;
216 }
217
218 return m_iSupplyCost + additionalCost;
219 }
220
221 //------------------------------------------------------------------------------------------------
222 protected int GetRefundAmountValue()
223 {
225 }
226
227 //------------------------------------------------------------------------------------------------
228 override void InitData(notnull SCR_EntityCatalogEntry entry)
229 {
230 m_EntryParent = entry;
231
232 m_ItemResource = Resource.Load(m_EntryParent.GetPrefab());
233
234 //~ Save alternative costs in map and delete the array
235 if (!m_aArsenalAlternativeCostData.IsEmpty())
236 {
238
239 foreach (SCR_ArsenalAlternativeCostData data : m_aArsenalAlternativeCostData)
240 {
241 //~ Ignore default as that is m_iSupplyCost defined in the arsenal item
242 if (data.m_eAlternativeCostType == SCR_EArsenalSupplyCostType.DEFAULT)
243 continue;
244
245 m_mArsenalAlternativeCostData.Insert(data.m_eAlternativeCostType, data);
246 }
247
248 //~ Delete array
250 }
252
253 //------------------------------------------------------------------------------------------------
254 //~ Gets the calculated cost of the attachments if the item is a weapon
255 override void PostInitData(notnull SCR_EntityCatalogEntry entry)
256 {
257 if (!m_ItemResource || !m_ItemResource.IsValid())
258 return;
259
260 //~ Get attachemts only from weapons to save performance
261 if (m_eItemMode != SCR_EArsenalItemMode.WEAPON && m_eItemMode != SCR_EArsenalItemMode.WEAPON_VARIANTS && m_eItemMode != SCR_EArsenalItemMode.ATTACHMENT)
262 return;
263
265 }
266
267 //------------------------------------------------------------------------------------------------
268 //~ Gets the calculated cost of the attachments if the item is a weapon
269 static void AddAdditionalCosts(notnull SCR_EntityCatalogEntry entry, Resource resource, inout array<SCR_ArsenalItem> arsenalCosts, inout array<SCR_NonArsenalItemCostCatalogData> nonArsenalCosts)
270 {
271 IEntitySource entitySource = SCR_BaseContainerTools.FindEntitySource(resource);
272 if (!entitySource)
273 return;
274
275 SCR_EntityCatalog catalog = entry.GetCatalogParent();
276 array<IEntityComponentSource> componentSources = {};
277 array<SCR_BaseEntityCatalogData> entityDataList = {};
278
279 SCR_ArsenalItem arsenalData;
281
282 //~ Get all attachments on the weapon
283 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(entitySource, AttachmentSlotComponent, true, componentSources) > 0)
284 {
285 SCR_EntityCatalogEntry attachmentEntry;
286 ResourceName attachmentPrefab;
287 bool attachmentEnabled;
288 EntitySlotInfo slotInfo;
289 BaseContainer attachSlot;
290
291 foreach (IEntityComponentSource attachmentSource : componentSources)
292 {
293 attachSlot = attachmentSource.GetObject("AttachmentSlot");
294 if (!attachSlot)
295 continue;
296
297 //~ Check if the slot is enabled
298 attachSlot.Get("Enabled", attachmentEnabled);
299 if (!attachmentEnabled)
300 continue;
301
302 //~ Get the prefab on the slot and see if it is not empty
303 attachSlot.Get("Prefab", attachmentPrefab);
304 if (attachmentPrefab.IsEmpty())
305 continue;
306
307 //~ Get the catalog entry with the given prefab
308 attachmentEntry = catalog.GetEntryWithPrefab(attachmentPrefab);
309 if (!attachmentEntry)
310 {
311 #ifdef WORKBENCH
312 //~ Print if in workbench
313 Print("Catalog Entry Arsenal Item: '" + WidgetManager.Translate(entry.GetEntityName()) + "' has an attachment which is not in the same catalog thus cannot get the supply cost of. Attachment: '" + attachmentPrefab + "'", LogLevel.VERBOSE);
314 #endif
315 continue;
316 }
317
318 bool foundData;
319
320 attachmentEntry.GetEntityDataList(entityDataList);
321 foreach (SCR_BaseEntityCatalogData data : entityDataList)
322 {
323 arsenalData = SCR_ArsenalItem.Cast(data);
324 if (arsenalData)
325 {
326 if (!arsenalCosts)
327 arsenalCosts = {};
328
329 arsenalCosts.Insert(arsenalData);
330 foundData = true;
331 break;
332 }
333
334 nonArsenalData = SCR_NonArsenalItemCostCatalogData.Cast(data);
335 if (nonArsenalData)
336 {
337 if (!nonArsenalCosts)
338 nonArsenalCosts = {};
339
340 nonArsenalCosts.Insert(nonArsenalData);
341 foundData = true;
342 break;
343 }
344 }
345
346 if (!foundData)
347 Print("Catalog Entry Arsenal Item: '" + WidgetManager.Translate(entry.GetEntityName()) + "' has an attachment which has no 'SCR_ArsenalItem' nor 'SCR_NonArsenalItemCostCatalogData' data in the catalog, thus it cannot get the supply cost from it. Attachment: '" + attachmentPrefab + "'", LogLevel.VERBOSE);
348 }
349 }
350
351 //~ Get all ammunition in the weapon
352 if (SCR_BaseContainerTools.FindComponentSourcesOfClass(entitySource, BaseMuzzleComponent, true, componentSources) > 0)
353 {
354 SCR_EntityCatalogEntry ammoEntry;
355 ResourceName ammoPrefab;
356
357 foreach (IEntityComponentSource muzzleSource : componentSources)
358 {
359 muzzleSource.Get("MagazineTemplate", ammoPrefab);
360 if (ammoPrefab.IsEmpty())
361 {
362 muzzleSource.Get("AmmoTemplate", ammoPrefab);
363 if (ammoPrefab.IsEmpty())
364 continue;
365 }
366
367 //~ Get the catalog entry with the given prefab
368 ammoEntry = catalog.GetEntryWithPrefab(ammoPrefab);
369 if (!ammoEntry)
370 continue;
371
372 ammoEntry.GetEntityDataList(entityDataList);
373 foreach (SCR_BaseEntityCatalogData data : entityDataList)
374 {
375 arsenalData = SCR_ArsenalItem.Cast(data);
376 if (arsenalData)
377 {
378 if (!arsenalCosts)
379 arsenalCosts = {};
380
381 arsenalCosts.Insert(arsenalData);
382 break;
383 }
384
385 nonArsenalData = SCR_NonArsenalItemCostCatalogData.Cast(data);
386 if (nonArsenalData)
387 {
388 if (!nonArsenalCosts)
389 nonArsenalCosts = {};
390
391 nonArsenalCosts.Insert(nonArsenalData);
392 break;
393 }
394 }
395 }
396 }
397 }
398}
399
400[BaseContainerProps(), BaseContainerCustomEnumWithValue(SCR_EArsenalSupplyCostType, "m_eAlternativeCostType", "m_iSupplyCost", "1", "%1 - Supply cost: %2")]
401class SCR_ArsenalAlternativeCostData
402{
403 [Attribute(SCR_EArsenalSupplyCostType.GADGET_ARSENAL.ToString(), desc: "Cost type if system searches for the cost. Do not use DEFAULT as this will be ignored", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EArsenalSupplyCostType))]
404 SCR_EArsenalSupplyCostType m_eAlternativeCostType;
405
406 [Attribute("1", desc: "Alternative supply cost", params: "0 inf")]
407 int m_iSupplyCost;
408
409 //------------------------------------------------------------------------------------------------
410 int GetRefundAmount()
411 {
412 return m_iSupplyCost;
413 }
414}
415
416[BaseContainerProps(), BaseContainerCustomEnumWithValue(SCR_EArsenalSupplyCostType, "m_eAlternativeCostType", "m_iSupplyCost", "1", "%1 - Supply cost: %2")]
417class SCR_ArsenalAlternativeCostSellAmountData : SCR_ArsenalAlternativeCostData
418{
419 [Attribute("1", desc: "Alternative supply refund amount. Supply refundmultiplier is still added to it", params: "0 inf")]
421
422 //------------------------------------------------------------------------------------------------
423 override int GetRefundAmount()
424 {
426 }
427}
SCR_ArsenalItem SCR_BaseEntityCatalogData BaseContainerCustomEnumWithValue(SCR_EArsenalSupplyCostType, "m_eAlternativeCostType", "m_iSupplyCost", "1", "%1 - Supply cost: %2")
SCR_ArsenalItem SCR_BaseEntityCatalogData BaseContainerProps()
int m_iSupplyCost
SCR_EArsenalGameModeType
SCR_EArsenalItemMode
SCR_EArsenalItemType
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ValuableIntelArsenalRefundEffect SCR_WeightedListArsenalRefundEffect BaseContainerCustomCheckIntTitleField("m_bEnabled", "Valuable Intel - Add XP", "(Disabled) Valuable Intel - Add XP", 1)
Adds ability to attach an object to a slot.
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
SCR_EArsenalItemType GetItemType()
int GetSupplyRefundAmount(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts=true)
override void PostInitData(notnull SCR_EntityCatalogEntry entry)
bool m_bUseMilitarySupplyAllocation
SCR_EntityCatalogEntry m_EntryParent
ref map< SCR_EArsenalSupplyCostType, ref SCR_ArsenalAlternativeCostData > m_mArsenalAlternativeCostData
SCR_EArsenalItemType m_eItemType
bool GetUseMilitarySupplyAllocation()
SCR_EArsenalItemMode m_eItemMode
SCR_ArsenalItemDisplayData GetDisplayDataOfType(EArsenalItemDisplayType displayType)
ref array< SCR_ArsenalItem > m_aAdditionalCosts
ref array< ref SCR_ArsenalItemDisplayData > m_aArsenalDisplayData
ref array< SCR_NonArsenalItemCostCatalogData > m_aNonArsenalAdditionalCosts
int GetSupplyCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts=true)
ref Resource m_ItemResource
SCR_ECharacterRank GetRequiredRank()
ResourceName GetItemResourceName()
ref array< ref SCR_ArsenalAlternativeCostData > m_aArsenalAlternativeCostData
Resource GetItemResource()
override void InitData(notnull SCR_EntityCatalogEntry entry)
SCR_EArsenalGameModeType GetArsenalGameModeTypes()
int GetMilitarySupplyAllocationCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts=true)
static void AddAdditionalCosts(notnull SCR_EntityCatalogEntry entry, Resource resource, inout array< SCR_ArsenalItem > arsenalCosts, inout array< SCR_NonArsenalItemCostCatalogData > nonArsenalCosts)
SCR_EArsenalGameModeType m_eArsenalGameModeTypes
SCR_EArsenalItemMode GetItemMode()
SCR_ECharacterRank m_eRequiredRank
Get list of entity Data of all types Ignores Disabled Elements param[out] Array of enabled entity Data list return List size *int GetEntityDataList(notnull out array< SCR_BaseEntityCatalogData > entityDataList)
SCR_EntityCatalogEntry GetEntryWithPrefab(ResourceName prefabToFind)
Base Used for items and attachments which should not be shown in the arsenal but should have a cost t...
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute