Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceEntityRefundAction.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: EResourceType.SUPPLIES.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Sets the type of Resource to be used.\nOnly a transaction matching Resource types can be successfully concluded.", enums: ParamEnumArray.FromEnum(EResourceType))]
4  protected EResourceType m_eResourceType;
5 
6  [Attribute(defvalue: EResourceGeneratorID.DEFAULT_STORAGE.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Identifier for the generator used for storage", enums: ParamEnumArray.FromEnum(EResourceGeneratorID))]
7  protected EResourceGeneratorID m_eGeneratorIdentifier;
8 
9  [Attribute("#AR-Supplies_Refund_Action_Object_NoSupplies", desc: "If no supplies are returned or supplies are disabled action name")]
10  protected LocalizedString m_sNoSuppliesActionName;
11 
12  [Attribute("#AR-Supplies_Refund_Action_Vehicle_NoDepot", desc: "Invalid reason shown when there is no valid refund point")]
13  protected LocalizedString m_sInvalidNoValidRefundPoint;
14 
15  [Attribute("#AR-Supplies_Refund_Action_Vehicle_Occupied", desc: "Invalid reason shown when entity is a vehicle and it is occupied")]
16  protected LocalizedString m_sInvalidIsOccupied;
17 
18  protected SCR_Faction m_Faction;
19  protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager;
20  protected SCR_CatalogEntitySpawnerComponent m_CatalogEntitySpawnerComponent;
21  protected RplComponent m_ReplicationComponent;
22  protected SCR_ResourceGenerator m_ResourceGenerator;
23  protected float m_fResourceCost = -1;
24 
25  protected bool m_bIsResourceEnabled = true;
26 
27  //~ For vehicles it sets the compartment manager to check if it is occupied
28  protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
29 
30  //------------------------------------------------------------------------------------------------
31  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
32  {
34  return;
35 
36  if (!SelectSuitableResourceGenerator(pUserEntity) || !m_CatalogEntitySpawnerComponent)
37  return;
38 
39  //~ Vehicle is in use
40  if (m_CompartmentManager && m_CompartmentManager.AnyCompartmentsOccupiedOrLocked())
41  return;
42 
43  //~ Refund if resource is enabled
44  if (m_bIsResourceEnabled)
45  {
46  if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(GetOwner()))
47  m_ResourceGenerator.RequestGeneration(SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier()));
48  else
49  m_ResourceGenerator.RequestGeneration(SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier()));
50  }
51 
52  RplComponent.DeleteRplEntity(GetOwner(), false);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override bool GetActionNameScript(out string outName)
57  {
58  if (!m_CatalogEntitySpawnerComponent)
59  return false;
60 
61  if (m_bIsResourceEnabled)
62  {
63  float resourceCost;
64 
65  if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(GetOwner()))
66  resourceCost = SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier());
67  else
68  resourceCost = SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier());
69 
70  if (resourceCost > 0)
71  {
72  ActionNameParams[0] = SCR_ResourceSystemHelper.SuppliesToString(resourceCost);
73  }
74  else
75  {
76  outName = m_sNoSuppliesActionName;
77  return true;
78  }
79  }
80  else
81  {
82  outName = m_sNoSuppliesActionName;
83  return true;
84  }
85 
86  return false;
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override event bool CanBePerformedScript(IEntity user)
91  {
92  if (!SelectSuitableResourceGenerator(user))
93  {
94  m_sCannotPerformReason = m_sInvalidNoValidRefundPoint;
95  return false;
96  }
97 
98  //~ Check if vehicle is in use
99  if (m_CompartmentManager && m_CompartmentManager.AnyCompartmentsOccupiedOrLocked())
100  {
101  m_sCannotPerformReason = m_sInvalidIsOccupied;
102  return false;
103  }
104 
105  return true;
106  }
107 
108  //------------------------------------------------------------------------------------------------
113  bool SelectSuitableResourceGenerator(IEntity user)
114  {
115  SCR_ResourceComponent resourceComponent;
116  SCR_ResourceGenerator resourceGeneratorCompare;
117  m_ResourceGenerator = null;
118  m_CatalogEntitySpawnerComponent = null;
119  vector ownerOrigin = GetOwner().GetOrigin();
120  float distanceSq = float.MAX;
121  float distanceSqCompare = float.MAX;
122 
123  foreach (SCR_CatalogEntitySpawnerComponent component : SCR_CatalogEntitySpawnerComponent.INSTANCES)
124  {
125  distanceSqCompare = vector.DistanceSq(ownerOrigin, component.GetOwner().GetOrigin());
126 
127  if (distanceSq <= distanceSqCompare && !component.CanRefund(GetOwner(), user))
128  continue;
129 
130  resourceComponent = SCR_ResourceComponent.Cast(component.GetOwner().FindComponent(SCR_ResourceComponent));
131 
132  if (resourceComponent && resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, m_eResourceType, resourceGeneratorCompare) && distanceSqCompare < resourceGeneratorCompare.GetStorageRange() * resourceGeneratorCompare.GetStorageRange())
133  {
134  distanceSq = distanceSqCompare;
135  m_CatalogEntitySpawnerComponent = component;
136  m_ResourceGenerator = resourceGeneratorCompare;
137 
138  continue;
139  }
140 
141  resourceGeneratorCompare = null;
142  }
143 
144  //~ Is resource enabled
145  if (resourceComponent)
146  m_bIsResourceEnabled = resourceComponent.IsResourceTypeEnabled(m_eResourceType);
147  else
148  m_bIsResourceEnabled = SCR_ResourceSystemHelper.IsGlobalResourceTypeEnabled(m_eResourceType);
149 
150  return m_ResourceGenerator;
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  override event bool CanBeShownScript(IEntity user)
155  {
156  if (m_fResourceCost <= 0 || !m_ReplicationComponent)
157  return false;
158 
159  return super.CanBeShownScript(user);
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
164  {
165  //~ Call a frame later so the catalog is initialized correctly
166  GetGame().GetCallqueue().CallLater(DelayedInit, param1: pOwnerEntity, param2: pManagerComponent);
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  protected void DelayedInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
171  {
172  m_fResourceCost = -1;
173 
174  m_ReplicationComponent = RplComponent.Cast(pOwnerEntity.FindComponent(RplComponent));
175  m_EntityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
176 
178  return;
179 
181  ResourceName prefabName = pOwnerEntity.GetPrefabData().GetPrefabName();
182 
184  if (factionComponent)
185  m_Faction = SCR_Faction.Cast(factionComponent.GetDefaultAffiliatedFaction());
186 
187  //~ Has faction get it from faction
188  if (m_Faction)
189  {
190  entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.VEHICLE, prefabName, m_Faction);
191 
192  if (!entry)
193  {
194  entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.CHARACTER, prefabName, m_Faction);
195 
196  if (!entry)
197  entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.GROUP, prefabName, m_Faction);
198  }
199  }
200  //~ Does not have faction so get factionless
201  else
202  {
203  entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.VEHICLE, prefabName);
204 
205  if (!entry)
206  {
207  entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.CHARACTER, prefabName);
208 
209  if (!entry)
210  entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.GROUP, prefabName);
211  }
212  }
213 
214  //~ No entry found
215  if (!entry)
216  return;
217 
218  //~ Get compartment manager if vehicle
219  m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
220 
221  SCR_EditableEntityUIInfo uiInfo = SCR_EditableEntityUIInfo.Cast(entry.GetEntityUiInfo());
222  if (uiInfo)
223  {
224  array<ref SCR_EntityBudgetValue> budgets = {};
225  uiInfo.GetEntityAndChildrenBudgetCost(budgets);
226 
227  foreach (SCR_EntityBudgetValue budget : budgets)
228  {
229  if (budget.GetBudgetType() == EEditableEntityBudget.CAMPAIGN)
230  {
231  m_fResourceCost = budget.GetBudgetValue();
232  return;
233  }
234  }
235  }
236 
237  //~ Could not get budget value from editable entity so use spawner data instead if any
239  if (!data)
240  return;
241 
242  m_fResourceCost = data.GetSupplyCost();
243  }
244 }
m_EntityCatalogManager
protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager
Definition: SCR_ResupplySupportStationComponent.c:14
SCR_ResourceSystemHelper
Definition: SCR_ResourceSystemHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition: SCR_ScriptedUserAction.c:2
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
m_ReplicationComponent
protected RplComponent m_ReplicationComponent
Replication component attached to the owner entity.
Definition: SCR_ResourceComponent.c:122
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
EEditableEntityBudget
EEditableEntityBudget
Definition: EEditableEntityBudget.c:1
SCR_ResourceEntityRefundAction
Definition: SCR_ResourceEntityRefundAction.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_CompartmentManager
protected SCR_BaseCompartmentManagerComponent m_CompartmentManager
Definition: SCR_VehicleDamageManagerComponent.c:191
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_EntityBudgetValue
Definition: SCR_EntityBudgetValue.c:2
SCR_EntityCatalogSpawnerData
Definition: SCR_EntityCatalogSpawnerData.c:5
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_FactionAffiliationComponent
Definition: SCR_FactionAffiliationComponent.c:10
m_Faction
Faction m_Faction
Definition: SCR_AITargetInfo.c:18
LocalizedString
Definition: LocalizedString.c:21
SCR_Faction
Definition: SCR_Faction.c:6
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1