Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResupplySupportStationAction.c
Go to the documentation of this file.
1 //~ Use the inherent versions!
2 [BaseContainerProps(), BaseContainerCustomStringTitleField("USE INHERENT VERSION ONLY!")]
4 {
5  [Attribute(ESupportStationType.RESUPPLY_AMMO.ToString(), desc: "Which Resupply this action is: Medical or ammo", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(ESupportStationType))]
6  protected ESupportStationType m_eSupportStationType;
7 
8  [Attribute(desc: "This decides what items will be resupplied when using the action")]
9  protected ref SCR_ResupplySupportStationData m_ResupplyData;
10 
11  [Attribute("-1", desc: "How much of the given item (or weapon magazines) can be in the inventory of the character. -1 means it is unlimited")]
12  protected int m_iMaxResupplyCount;
13 
14  [Attribute("#AR-SupportStation_Resupply_ActionInvalid_NoInventorySpace", desc: "Text shown on action if player cannot resupply because inventory is full", uiwidget: UIWidgets.LocaleEditBox)]
15  protected LocalizedString m_sInvalidNoInventorySpace;
16 
17  [Attribute("#AR-SupportStation_Resupply_ActionInvalid_InvalidNotInStorage", desc: "Text shown on action if player cannot resupply because the item is not in the storage of which the character wants to resupply", uiwidget: UIWidgets.LocaleEditBox)]
18  protected LocalizedString m_sInvalidNotInStorage;
19 
20  [Attribute(ENotification.UNKNOWN.ToString(), desc: "Notification when the action is used. Shown to player using the action if resupply self or on the player that is being resupplied if resupply other. Leave unknown to ignore", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(ENotification))]
21  protected ENotification m_eNotificationOnUse;
22 
23  protected SCR_InventoryStorageManagerComponent m_InventoryManagerTarget;
24 
25  protected EResupplyUnavailableReason m_eResupplyUnavailableReason;
26 
27  protected bool m_bCanResupply;
28  protected ResourceName m_sItemToResupply;
29  protected int m_iCurrentItemAmount = -1;
30 
31  protected const LocalizedString X_OUTOF_Y_FORMATTING = "#AR-SupportStation_ActionFormat_ItemAmount";
32  protected const LocalizedString CURRENT_ITEM_AMOUNT_FORMATTING = "#AR-SupportStation_ActionFormat_CurrentItemAmount";
33 
34  //------------------------------------------------------------------------------------------------
35  protected override ESupportStationType GetSupportStationType()
36  {
37  return m_eSupportStationType;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  protected override LocalizedString GetInvalidPerformReasonString(ESupportStationReasonInvalid reasonInvalid)
42  {
43  if (reasonInvalid == ESupportStationReasonInvalid.RESUPPLY_ENOUGH_ITEMS)
44  return WidgetManager.Translate(X_OUTOF_Y_FORMATTING, m_iCurrentItemAmount, m_iMaxResupplyCount);
45  else if (reasonInvalid == ESupportStationReasonInvalid.RESUPPLY_INVENTORY_FULL)
47  else if (reasonInvalid == ESupportStationReasonInvalid.RESUPPLY_NOT_IN_STORAGE)
49 
50  return super.GetInvalidPerformReasonString(reasonInvalid);
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  //~ Returns true if the action is shown but disabled because of no supplies, max items or inventory full. Otherwise hide it to avoid to many options
55  protected bool GetShowButDisabled()
56  {
57  if (m_eResupplyUnavailableReason == EResupplyUnavailableReason.ENOUGH_ITEMS || m_eResupplyUnavailableReason == EResupplyUnavailableReason.INVENTORY_FULL)
58  return true;
59 
60  if (m_eCannotPerformReason == ESupportStationReasonInvalid.NO_SUPPLIES)
61  return true;
62 
63  return false;
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  ENotification GetNotificationOnUse()
68  {
69  return m_eNotificationOnUse;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  protected override bool CanHaveMultipleUsers()
74  {
75  return true;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  override bool CanBeShownScript(IEntity user)
80  {
81  if (!m_ResupplyData)
82  return false;
83 
84  return super.CanBeShownScript(user);
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  override bool CanBePerformedScript(IEntity user)
89  {
90  if (m_sItemToResupply.IsEmpty())
91  {
92  UpdateCanResupply(GetOwner(), user);
93  if (m_sItemToResupply.IsEmpty())
94  return false;
95  }
96 
97  bool canBePerformed = super.CanBePerformedScript(user);
98 
99  //~ Cannot resupply as resupply action unavailible
100  if (canBePerformed && !m_bCanResupply)
101  {
102  //~ Set reason action is unavailible
103  if (m_eResupplyUnavailableReason == EResupplyUnavailableReason.ENOUGH_ITEMS)
104  SetCanPerform(false, ESupportStationReasonInvalid.RESUPPLY_ENOUGH_ITEMS);
105  else if (m_eResupplyUnavailableReason == EResupplyUnavailableReason.INVENTORY_FULL)
106  SetCanPerform(false, ESupportStationReasonInvalid.RESUPPLY_INVENTORY_FULL);
107  else if (m_eResupplyUnavailableReason == EResupplyUnavailableReason.NOT_IN_GIVEN_STORAGE)
108  SetCanPerform(false, ESupportStationReasonInvalid.RESUPPLY_NOT_IN_STORAGE);
109  else if (m_eResupplyUnavailableReason == EResupplyUnavailableReason.NO_VALID_WEAPON)
110  SetCanPerform(false, ESupportStationReasonInvalid.RESUPPLY_NO_VALID_WEAPON);
111 
112  return false;
113  }
114 
115  return canBePerformed;
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected override void CanBePerformedUpdate(IEntity user)
120  {
121  //~ Check if can add to inventory. Only called every x seconds to save performance
122  UpdateCanResupply(GetOwner(), user);
123  super.CanBePerformedUpdate(user);
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  ResourceName GetItemToResupply()
128  {
129  return m_sItemToResupply;
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  //~ Can Resupply loops through entire inventory so only call this every x seconds
134  protected void UpdateCanResupply(IEntity owner, IEntity user)
135  {
136  m_bCanResupply = false;
137 
138  //~ Reset reason
139  m_eResupplyUnavailableReason = EResupplyUnavailableReason.NO_VALID_WEAPON;
140 
141  SetTargetInventory(user, owner);
143  return;
144 
145  BaseMuzzleComponent muzzle;
146  if (!m_ResupplyData.GetResupplyItemOrMuzzle(m_InventoryManagerTarget.GetOwner(), owner, m_SupportStationGadget, m_sItemToResupply, muzzle))
147  return;
148 
149  //~ No valid item found
150  if (SCR_StringHelper.IsEmptyOrWhiteSpace(m_sItemToResupply))
151  return;
152 
153  //~ Check if resupply is availible (And get current item amount)
154  if (muzzle)
155  m_eResupplyUnavailableReason = m_InventoryManagerTarget.CanResupplyMuzzle(muzzle, m_iMaxResupplyCount, GetProviderInventory(), m_iCurrentItemAmount);
156  else
158 
159  m_bCanResupply = m_eResupplyUnavailableReason == EResupplyUnavailableReason.RESUPPLY_VALID;
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
164  {
165  super.PerformAction(pOwnerEntity, pUserEntity);
166  UpdateCanResupply(pOwnerEntity, pUserEntity);
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  protected void SetTargetInventory(IEntity user, IEntity owner)
171  {
172  return;
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  SCR_InventoryStorageManagerComponent GetTargetInventory()
177  {
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  //~ Get inventory of who ever provide the item. This simply checkes if the item is in the inventory. This should be an arsenal as it does not remove anything from the inventory
183  protected InventoryStorageManagerComponent GetProviderInventory()
184  {
185  return null;
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected override void ResetReferencesOnServer()
190  {
191  m_sItemToResupply = string.Empty;
192  super.ResetReferencesOnServer();
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  protected override void DelayedInit(IEntity owner)
197  {
198  if (!owner)
199  return;
200 
201  super.DelayedInit(owner);
202 
203  if (m_ResupplyData)
204  m_ResupplyData.Init(owner);
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  protected override string GetActionStringParam()
209  {
210  if (!m_bCanPerform)
211  {
212  if (m_eResupplyUnavailableReason != EResupplyUnavailableReason.INVENTORY_FULL)
213  return string.Empty;
214  }
215 
216  if (m_iMaxResupplyCount < 0)
217  return WidgetManager.Translate(CURRENT_ITEM_AMOUNT_FORMATTING, m_iCurrentItemAmount);
218 
219  return WidgetManager.Translate(X_OUTOF_Y_FORMATTING, m_iCurrentItemAmount, m_iMaxResupplyCount);
220  }
221 }
222 
223 //------------------------------------------------------------------------------------------------
225 class SCR_ResupplySupportStationData
226 {
227  //------------------------------------------------------------------------------------------------
228  void Init(IEntity owner)
229  {
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
234  {
235  return false;
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  protected FactionAffiliationComponent GetFactionAffiliationGadgetOrOwner(notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget)
240  {
241  FactionAffiliationComponent factionAffiliationComponent;
242 
243  if (supportStationGadget)
244  {
245  factionAffiliationComponent = FactionAffiliationComponent.Cast(supportStationGadget.GetOwner().FindComponent(FactionAffiliationComponent));
246  if (factionAffiliationComponent)
247  return factionAffiliationComponent;
248  }
249 
250  factionAffiliationComponent = FactionAffiliationComponent.Cast(actionOwner.FindComponent(FactionAffiliationComponent));
251  if (!factionAffiliationComponent)
252  {
253  IEntity parent = actionOwner.GetParent();
254  if (parent)
255  factionAffiliationComponent = FactionAffiliationComponent.Cast(parent.FindComponent(FactionAffiliationComponent));
256  }
257 
258  return factionAffiliationComponent;
259  }
260 }
261 
262 //------------------------------------------------------------------------------------------------
264 class SCR_ResupplyItemSupportStationData : SCR_ResupplySupportStationData
265 {
266  [Attribute(desc: "Prefab of entity", UIWidgets.ResourcePickerThumbnail, params: "et")]
267  protected ResourceName m_sItemPrefab;
268 
269  //------------------------------------------------------------------------------------------------
270  override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
271  {
272  item = m_sItemPrefab;
273 
274  return !SCR_StringHelper.IsEmptyOrWhiteSpace(item);
275  }
276 }
277 
278 //------------------------------------------------------------------------------------------------
280 class SCR_ResupplyCatalogItemSupportStationData : SCR_ResupplySupportStationData
281 {
282  [Attribute(desc: "This will go through 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))]
283  protected SCR_ESupportStationResupplyType m_eResupplyType;
284 
285  [Attribute("0", desc: "If true will use the item associated with the support station default faction. Otherwise will only take defualt if no faction is set")]
286  protected bool m_bAlwaysTakeDefaultFaction;
287 
288  protected ref map<FactionKey, ResourceName> m_mFactionItems = new map<FactionKey, ResourceName>;
289 
290  //------------------------------------------------------------------------------------------------
291  override void Init(IEntity owner)
292  {
293  FactionManager factionManager = GetGame().GetFactionManager();
294  if (!factionManager)
295  return;
296 
297  array<Faction> factions = {};
298  factionManager.GetFactionsList(factions);
299 
300  SCR_Faction scrFaction;
301  SCR_EntityCatalog itemCatalog;
302 
303  array<SCR_EntityCatalogEntry> filteredEntityList = {};
304  array<SCR_BaseEntityCatalogData> dataList = {};
306  int count;
307 
308  //~ Go over each faction and set which items will be used for the resupply
309  foreach (Faction faction : factions)
310  {
311  scrFaction = SCR_Faction.Cast(faction);
312  if (!scrFaction)
313  continue;
314 
315  itemCatalog = scrFaction.GetFactionEntityCatalogOfType(EEntityCatalogType.ITEM);
316  if (!itemCatalog)
317  continue;
318 
319  count = itemCatalog.GetEntityListWithData(SCR_EntityCatalogSupportStationResupplyData, filteredEntityList, dataList);
320  if (count <= 0)
321  continue;
322 
323  for (int i = 0; i < count; i++)
324  {
325  resupplyData = SCR_EntityCatalogSupportStationResupplyData.Cast(dataList[i]);
326  if (!resupplyData || resupplyData.GetResupplyType() != m_eResupplyType)
327  continue;
328 
329  m_mFactionItems.Insert(faction.GetFactionKey(), filteredEntityList[i].GetPrefab());
330  break;
331  }
332  }
333  }
334 
335  //------------------------------------------------------------------------------------------------
336  override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
337  {
338  if (m_mFactionItems.IsEmpty())
339  return false;
340 
341  FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
342  if (!factionAffiliationComponent)
343  return false;
344 
345  //~ Get faction
346  Faction faction;
347  if (m_bAlwaysTakeDefaultFaction)
348  {
349  faction = factionAffiliationComponent.GetDefaultAffiliatedFaction();
350  if (!faction)
351  return false;
352  }
353  else
354  {
355  faction = factionAffiliationComponent.GetAffiliatedFaction();
356  if (!faction)
357  {
358  faction = factionAffiliationComponent.GetDefaultAffiliatedFaction();
359  if (!faction)
360  return false;
361  }
362  }
363 
364  if (!m_mFactionItems.Find(faction.GetFactionKey(), item))
365  return false;
366 
367  return !SCR_StringHelper.IsEmptyOrWhiteSpace(item);
368  }
369 }
370 
371 //------------------------------------------------------------------------------------------------
373 class SCR_ResupplyHeldWeaponSupportStationData : SCR_ResupplySupportStationData
374 {
375  [Attribute(uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EMuzzleType))]
376  protected ref array<EMuzzleType> m_aMuzzleTypes;
377 
378  [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!")]
379  protected bool m_bCheckFaction;
380 
381  //------------------------------------------------------------------------------------------------
382  override bool GetResupplyItemOrMuzzle(notnull IEntity targetCharacter, notnull IEntity actionOwner, SCR_SupportStationGadgetComponent supportStationGadget, out ResourceName item, out BaseMuzzleComponent muzzle)
383  {
384  if (m_aMuzzleTypes.IsEmpty())
385  return false;
386 
387  BaseWeaponManagerComponent weaponsManager = BaseWeaponManagerComponent.Cast(targetCharacter.FindComponent(BaseWeaponManagerComponent));
388  if (!weaponsManager)
389  return false;
390 
391  //~ Get held weapon to resupply
392  BaseWeaponComponent baseWeaponComp = weaponsManager.GetCurrentWeapon();
393  if (!baseWeaponComp)
394  return false;
395 
396  string weaponSlotType = baseWeaponComp.GetWeaponSlotType();
397  if (weaponSlotType != "primary" && weaponSlotType != "secondary")
398  return false;
399 
400  array<BaseMuzzleComponent> muzzles = {};
401 
402  //~ Get base muzzle to only supply magazines
403  baseWeaponComp.GetMuzzlesList(muzzles);
404  SCR_MuzzleInMagComponent inMagMuzzle;
405 
406  foreach (BaseMuzzleComponent muzzleComp : muzzles)
407  {
408  if (m_aMuzzleTypes.Contains(muzzleComp.GetMuzzleType()))
409  {
410  //~ Cannot be reloaded
411  inMagMuzzle = SCR_MuzzleInMagComponent.Cast(muzzleComp);
412  if (inMagMuzzle && !inMagMuzzle.CanBeReloaded())
413  continue;
414 
415  //~ Check if has default magazine
416  item = muzzleComp.GetDefaultMagazineOrProjectileName();
417  if (!item.IsEmpty())
418  {
419  muzzle = muzzleComp;
420  break;
421  }
422  }
423  }
424 
425  //~ No valid muzzle found
426  if (!muzzle)
427  return false;
428 
429  //~ Check if ammo is part of the faction of gadget or action owner
430  if (m_bCheckFaction)
431  {
432  SCR_EntityCatalogManagerComponent catalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
433  if (!catalogManager)
434  return true;
435 
436  FactionAffiliationComponent factionAffiliationComponent = GetFactionAffiliationGadgetOrOwner(actionOwner, supportStationGadget);
437  if (!factionAffiliationComponent)
438  return true;
439 
440  SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComponent.GetDefaultAffiliatedFaction());
441  if (!faction)
442  return true;
443 
444  //~ Not the correct faction so do not allow for resupply
445  if (!catalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, item, faction))
446  return false;
447  }
448 
449  return true;
450  }
451 }
452 
m_eResupplyUnavailableReason
protected EResupplyUnavailableReason m_eResupplyUnavailableReason
Definition: SCR_ResupplySupportStationAction.c:22
m_sInvalidNotInStorage
protected LocalizedString m_sInvalidNotInStorage
Definition: SCR_ResupplySupportStationAction.c:15
m_iMaxResupplyCount
protected int m_iMaxResupplyCount
Definition: SCR_ResupplySupportStationAction.c:9
SCR_EntityCatalogSupportStationResupplyData
Definition: SCR_EntityCatalogSupportStationResupplyData.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
SCR_StringHelper
Definition: SCR_StringHelper.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_eNotificationOnUse
protected ENotification m_eNotificationOnUse
Definition: SCR_ResupplySupportStationAction.c:18
Init
void Init(IEntity entity=null, vector worldPos=vector.Zero, float timestamp=0.0, EAITargetInfoCategory category=0)
Definition: SCR_AITargetInfo.c:27
ENotification
ENotification
Definition: ENotification.c:4
ESupportStationReasonInvalid
ESupportStationReasonInvalid
Definition: ESupportStationReasonInvalid.c:3
InventoryStorageManagerComponent
Definition: InventoryStorageManagerComponent.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_bCanResupply
protected bool m_bCanResupply
Definition: SCR_ResupplySupportStationAction.c:24
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
ESupportStationType
ESupportStationType
Definition: ESupportStationType.c:2
BaseContainerCustomStringTitleField
SCR_BaseResupplySupportStationAction SCR_BaseUseSupportStationAction BaseContainerCustomStringTitleField("DO NOT USE!")
Definition: SCR_ResupplySupportStationAction.c:224
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
X_OUTOF_Y_FORMATTING
const protected LocalizedString X_OUTOF_Y_FORMATTING
Definition: SCR_ResupplySupportStationAction.c:28
m_InventoryManagerTarget
protected SCR_InventoryStorageManagerComponent m_InventoryManagerTarget
Definition: SCR_ResupplySupportStationAction.c:20
EMuzzleType
EMuzzleType
Definition: EMuzzleType.c:12
Faction
Definition: Faction.c:12
m_eSupportStationType
protected ESupportStationType m_eSupportStationType
Definition: SCR_ResupplySupportStationAction.c:3
m_sItemToResupply
protected ResourceName m_sItemToResupply
Definition: SCR_ResupplySupportStationAction.c:25
SCR_ResupplyItemSupportStationData
Definition: SCR_ResupplySupportStationAction.c:264
SCR_EntityCatalog
Definition: SCR_EntityCatalog.c:181
SCR_BaseResupplySupportStationAction
Definition: SCR_ResupplySupportStationAction.c:3
m_sInvalidNoInventorySpace
protected LocalizedString m_sInvalidNoInventorySpace
Definition: SCR_ResupplySupportStationAction.c:12
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_BaseUseSupportStationAction
Definition: SCR_BaseUseSupportStationAction.c:1
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12
m_iCurrentItemAmount
protected int m_iCurrentItemAmount
Definition: SCR_ResupplySupportStationAction.c:26
LocalizedString
Definition: LocalizedString.c:21
m_ResupplyData
protected ref SCR_ResupplySupportStationData m_ResupplyData
Definition: SCR_ResupplySupportStationAction.c:6
SCR_Faction
Definition: SCR_Faction.c:6
BaseContainerProps
SCR_BaseResupplySupportStationAction SCR_BaseUseSupportStationAction BaseContainerProps()