Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseItemHolderSupportStationAction.c
Go to the documentation of this file.
1[BaseContainerProps(), BaseContainerCustomStringTitleField("USE INHERITED VERSION ONLY!")]
3{
4 [Attribute(desc: "This decides what items will be resupplied when using the action")]
5 protected ref SCR_ResupplySupportStationData m_ResupplyData;
7 [Attribute("#AR-SupportStation_Resupply_ActionInvalid_InvalidNotInStorage", desc: "Text shown on action if player cannot attach the pylon as the storage has no valid pylons", uiwidget: UIWidgets.LocaleEditBox)]
9
12 protected string m_sItemName = "MISSING NAME OR INVALID PREFAB";
13
14 //------------------------------------------------------------------------------------------------
16 {
17 if (reasonInvalid == ESupportStationReasonInvalid.RESUPPLY_NOT_IN_STORAGE)
19
20 return super.GetInvalidPerformReasonString(reasonInvalid);
21 }
22
23 //------------------------------------------------------------------------------------------------
24 protected override void DelayedInit(IEntity owner)
25 {
26 if (!owner)
27 return;
28
29 super.DelayedInit(owner);
30
32 m_ResupplyData.Init(owner);
33 }
34
35 //------------------------------------------------------------------------------------------------
36 protected void SetItemName()
37 {
38 Resource resource = Resource.Load(m_sItemPrefab);
39 if (!resource || !resource.IsValid())
40 return;
41
42 IEntitySource entitySource = SCR_BaseContainerTools.FindEntitySource(resource);
43 if (!entitySource)
44 return;
45
46 UIInfo uiInfo;
47
48 //~ Get UI info from item
49 IEntityComponentSource inventoryEntitySource = SCR_ComponentHelper.GetInventoryItemComponentSource(entitySource);
50 if (inventoryEntitySource)
51 {
52 SCR_ItemAttributeCollection inventoryEntityUiInfo = SCR_ComponentHelper.GetInventoryItemInfo(inventoryEntitySource);
53 if (inventoryEntityUiInfo)
54 {
55 uiInfo = inventoryEntityUiInfo.GetUIInfo();
56
57 if (uiInfo && !uiInfo.GetName().IsEmpty())
58 {
59 m_sItemName = uiInfo.GetName();
60 return;
61 }
62 }
63 }
64
65 //~ Get UI info from weapon
66 IEntityComponentSource weaponEntitySource = SCR_ComponentHelper.GetWeaponComponentSource(entitySource);
67 if (weaponEntitySource)
68 {
69 uiInfo = SCR_ComponentHelper.GetWeaponComponentInfo(weaponEntitySource);
70
71 if (uiInfo && !uiInfo.GetName().IsEmpty())
72 {
73 m_sItemName = uiInfo.GetName();
74 return;
75 }
76 }
77 }
78
79 //------------------------------------------------------------------------------------------------
80 /*bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
81 {
82 return m_ResupplyData.GetResupplyItemOrMuzzle(targetCharacter, actionOwner, supportStationGadget, item, muzzle);
83 }*/
84
85 //------------------------------------------------------------------------------------------------
90}
91
93class SCR_ResupplySupportStationData
94{
95 //------------------------------------------------------------------------------------------------
96 void Init(IEntity owner);
97
98 //------------------------------------------------------------------------------------------------
99 bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
100 {
101 return false;
102 }
103
104 //------------------------------------------------------------------------------------------------
105 protected FactionAffiliationComponent GetFactionAffiliationGadgetOrOwner(notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget)
106 {
107 FactionAffiliationComponent factionAffiliationComponent;
108
109 if (supportStationGadget)
110 {
111 factionAffiliationComponent = FactionAffiliationComponent.Cast(supportStationGadget.GetOwner().FindComponent(FactionAffiliationComponent));
112 if (factionAffiliationComponent)
113 return factionAffiliationComponent;
114 }
115
116 factionAffiliationComponent = FactionAffiliationComponent.Cast(actionOwner.FindComponent(FactionAffiliationComponent));
117 if (!factionAffiliationComponent)
118 {
119 IEntity parent = actionOwner.GetParent();
120 if (parent)
121 factionAffiliationComponent = FactionAffiliationComponent.Cast(parent.FindComponent(FactionAffiliationComponent));
122 }
123
124 return factionAffiliationComponent;
125 }
126}
127
129class SCR_ResupplyItemSupportStationData : SCR_ResupplySupportStationData
130{
131 [Attribute(desc: "Prefab of entity", UIWidgets.ResourcePickerThumbnail, params: "et")]
133
134 //------------------------------------------------------------------------------------------------
135 override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
136 {
137 item = m_sItemPrefab;
138
140 }
141
142 //------------------------------------------------------------------------------------------------
144 {
145 return m_sItemPrefab;
146 }
147}
148
150class SCR_ResupplyCatalogItemSupportStationData : SCR_ResupplySupportStationData
151{
152 [Attribute(desc: "This will go through all the inventory items in the catalog and grab the first one with the given type (needs the SCR_EntityCatalogSupportStationResupplyData)", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_ESupportStationResupplyType))]
153 protected SCR_ESupportStationResupplyType m_eResupplyType;
154
155 [Attribute("0", desc: "If true will use the item associated with the support station default faction. Otherwise will only take default if no faction is set")]
156 protected bool m_bAlwaysTakeDefaultFaction;
157
158 protected ref map<FactionKey, ref SCR_EntityCatalogEntry> m_mFactionItems = new map<FactionKey, ref SCR_EntityCatalogEntry>();
159
160 //------------------------------------------------------------------------------------------------
161 override void Init(IEntity owner)
162 {
163 FactionManager factionManager = GetGame().GetFactionManager();
164 if (!factionManager)
165 return;
166
167 array<Faction> factions = {};
168 factionManager.GetFactionsList(factions);
169
170 SCR_Faction scrFaction;
171 SCR_EntityCatalog itemCatalog;
172
173 array<SCR_EntityCatalogEntry> filteredEntityList = {};
174 array<SCR_BaseEntityCatalogData> dataList = {};
175 SCR_EntityCatalogSupportStationResupplyData resupplyData;
176 int count;
177
178 //~ Go over each faction and set which items will be used for the resupply
179 foreach (Faction faction : factions)
180 {
181 scrFaction = SCR_Faction.Cast(faction);
182 if (!scrFaction)
183 continue;
184
185 itemCatalog = scrFaction.GetFactionEntityCatalogOfType(EEntityCatalogType.ITEM);
186 if (!itemCatalog)
187 continue;
188
189 count = itemCatalog.GetEntityListWithData(SCR_EntityCatalogSupportStationResupplyData, filteredEntityList, dataList);
190 if (count <= 0)
191 continue;
192
193 for (int i = 0; i < count; i++)
194 {
195 resupplyData = SCR_EntityCatalogSupportStationResupplyData.Cast(dataList[i]);
196 if (!resupplyData || resupplyData.GetResupplyType() != m_eResupplyType)
197 continue;
198
199 m_mFactionItems.Insert(faction.GetFactionKey(), filteredEntityList[i]);
200 break;
201 }
202 }
203 }
204
205 //------------------------------------------------------------------------------------------------
206 SCR_ECharacterRank GetRequiredRank(notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget)
207 {
208 SCR_ECharacterRank requiredRank = SCR_ECharacterRank.PRIVATE;
209
210 if (m_mFactionItems.IsEmpty())
211 return requiredRank;
212
213 FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
214 if (!factionAffiliationComponent)
215 return false;
216
217 Faction faction;
218 if (!m_bAlwaysTakeDefaultFaction)
219 faction = factionAffiliationComponent.GetAffiliatedFaction();
220
221 if (!faction)
222 faction = factionAffiliationComponent.GetDefaultAffiliatedFaction();
223
224 if (!faction)
225 return requiredRank;
226
227 SCR_EntityCatalogEntry catalogEntry;
228 if (!m_mFactionItems.Find(faction.GetFactionKey(), catalogEntry) || !catalogEntry)
229 return requiredRank;
230
231 SCR_ArsenalItem itemData = SCR_ArsenalItem.Cast(catalogEntry.GetEntityDataOfType(SCR_ArsenalItem));
232 if (itemData)
233 requiredRank = itemData.GetRequiredRank();
234
235 return requiredRank;
236 }
237
238 //------------------------------------------------------------------------------------------------
239 int GetRequiredAvailableAllocatedSupplies(notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget)
240 {
241 if (m_mFactionItems.IsEmpty())
242 return 0;
243
244 FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
245 if (!factionAffiliationComponent)
246 return 0;
247
248 if (m_bAlwaysTakeDefaultFaction)
249 return 0;
250
251 Faction faction = factionAffiliationComponent.GetAffiliatedFaction();
252 if (!faction)
253 return 0;
254
255 SCR_EntityCatalogEntry catalogEntry;
256 if (!m_mFactionItems.Find(faction.GetFactionKey(), catalogEntry) || !catalogEntry)
257 return 0;
258
259 SCR_ArsenalItem itemData = SCR_ArsenalItem.Cast(catalogEntry.GetEntityDataOfType(SCR_ArsenalItem));
260 if (itemData && itemData.GetUseMilitarySupplyAllocation())
261 return itemData.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
262
263 return 0;
264 }
265
266 //------------------------------------------------------------------------------------------------
267 override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
268 {
269 if (m_mFactionItems.IsEmpty())
270 return false;
271
272 FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
273 if (!factionAffiliationComponent)
274 return false;
275
276 //~ Get faction
277 Faction faction;
278 if (m_bAlwaysTakeDefaultFaction)
279 {
280 faction = factionAffiliationComponent.GetDefaultAffiliatedFaction();
281 if (!faction)
282 return false;
283 }
284 else
285 {
286 faction = factionAffiliationComponent.GetAffiliatedFaction();
287 if (!faction)
288 {
289 faction = factionAffiliationComponent.GetDefaultAffiliatedFaction();
290 if (!faction)
291 return false;
292 }
293 }
294
295 SCR_EntityCatalogEntry catalogEntry;
296 if (!m_mFactionItems.Find(faction.GetFactionKey(), catalogEntry) || !catalogEntry)
297 return false;
298
299 item = catalogEntry.GetPrefab();
300 return !SCR_StringHelper.IsEmptyOrWhiteSpace(item);
301 }
302}
303
305class SCR_ResupplyHeldWeaponSupportStationData : SCR_ResupplySupportStationData
306{
307 [Attribute(uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EMuzzleType))]
308 protected ref array<EMuzzleType> m_aMuzzleTypes;
309
310 [Attribute("0", desc: "If true will check if the found ammo is part of the entity default faction or owner default faction. Only do this check when item has no inventory, else check if item is in storage instead!")]
311 protected bool m_bCheckFaction;
312
313 //------------------------------------------------------------------------------------------------
314 override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
315 {
316 if (m_aMuzzleTypes.IsEmpty())
317 return false;
318
319 BaseWeaponManagerComponent weaponsManager = BaseWeaponManagerComponent.Cast(targetCharacter.FindComponent(BaseWeaponManagerComponent));
320 if (!weaponsManager)
321 return false;
322
323 //~ Get held weapon to resupply
324 BaseWeaponComponent baseWeaponComp = weaponsManager.GetCurrentWeapon();
325 if (!baseWeaponComp)
326 return false;
327
328 string weaponSlotType = baseWeaponComp.GetWeaponSlotType();
329 if (weaponSlotType != "primary" && weaponSlotType != "secondary")
330 return false;
331
332 array<BaseMuzzleComponent> muzzles = {};
333
334 //~ Get base muzzle to only supply magazines
335 baseWeaponComp.GetMuzzlesList(muzzles);
336 SCR_MuzzleInMagComponent inMagMuzzle;
337
338 foreach (BaseMuzzleComponent muzzleComp : muzzles)
339 {
340 if (m_aMuzzleTypes.Contains(muzzleComp.GetMuzzleType()))
341 {
342 //~ Cannot be reloaded
343 inMagMuzzle = SCR_MuzzleInMagComponent.Cast(muzzleComp);
344 if (inMagMuzzle && !inMagMuzzle.CanBeReloaded())
345 continue;
346
347 //~ Check if has default magazine
348 item = muzzleComp.GetDefaultMagazineOrProjectileName();
349 if (!item.IsEmpty())
350 {
351 muzzle = muzzleComp;
352 break;
353 }
354 }
355 }
356
357 //~ No valid muzzle found
358 if (!muzzle)
359 return false;
360
361 //~ Check if ammo is part of the faction of gadget or action owner
362 if (m_bCheckFaction)
363 {
364 SCR_EntityCatalogManagerComponent catalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
365 if (!catalogManager)
366 return true;
367
368 FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
369 if (!factionAffiliationComponent)
370 return true;
371
372 SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComponent.GetDefaultAffiliatedFaction());
373 if (!faction)
374 return true;
375
376 //~ Not the correct faction so do not allow for resupply
377 if (!catalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, item, faction))
378 return false;
379 }
380
381 return true;
382 }
383
384 //------------------------------------------------------------------------------------------------
385 int GetRequiredAvailableAllocatedSupplies(notnull IEntity actionOwner, ResourceName resourceName)
386 {
387 SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
388 if (!entityCatalogManager)
389 return 0;
390
391 SCR_EntityCatalogEntry catalogEntry = entityCatalogManager.GetEntryWithPrefabFromAnyCatalog(EEntityCatalogType.ITEM, resourceName);
392 if (!catalogEntry)
393 return 0;
394
395 SCR_ArsenalItem arsenalItemData = SCR_ArsenalItem.Cast(catalogEntry.GetEntityDataOfType(SCR_ArsenalItem));
396 if (!arsenalItemData)
397 return 0;
398
399 if (!arsenalItemData.GetUseMilitarySupplyAllocation())
400 return 0;
401
402 return arsenalItemData.GetSupplyCost(SCR_EArsenalSupplyCostType.GADGET_ARSENAL, false);
403 }
404}
override void Init()
EEntityCatalogType
ArmaReforgerScripted GetGame()
Definition game.c:1398
ResourceName resourceName
Definition SCR_AIGroup.c:66
SCR_ECharacterRank GetRequiredRank()
ref SCR_ResupplySupportStationData m_ResupplyData
SCR_BaseItemHolderSupportStationAction SCR_BaseAudioSupportStationAction BaseContainerProps()
SCR_BaseItemHolderSupportStationAction SCR_BaseAudioSupportStationAction BaseContainerCustomStringTitleField("DO NOT USE!")
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
bool GetUseMilitarySupplyAllocation()
int GetSupplyCost(SCR_EArsenalSupplyCostType supplyCostType, bool addAdditionalCosts=true)
SCR_ECharacterRank GetRequiredRank()
override LocalizedString GetInvalidPerformReasonString(ESupportStationReasonInvalid reasonInvalid)
Get prefab entity Data of type Ignores disabled Data s param dataType class of Data type you with to obtain return Entity Data of given type Null if not found *SCR_BaseEntityCatalogData GetEntityDataOfType(typename dataType)
Get Prefab data return Prefab data *ResourceName GetPrefab()
SCR_EntityCatalog GetFactionEntityCatalogOfType(EEntityCatalogType catalogType, bool printNotFound=true)
override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
static bool IsEmptyOrWhiteSpace(string input)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
SCR_FieldOfViewSettings Attribute
EMuzzleType
Definition EMuzzleType.c:13