Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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))]
5
6 [Attribute(defvalue: EResourceGeneratorID.DEFAULT_STORAGE.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Identifier for the generator used for storage", enums: ParamEnumArray.FromEnum(EResourceGeneratorID))]
8
9 [Attribute("#AR-Supplies_Refund_Action_Object_NoSupplies", desc: "If no supplies are returned or supplies are disabled action name")]
11
12 [Attribute("#AR-Supplies_Refund_Action_Vehicle_NoDepot", desc: "Invalid reason shown when there is no valid refund point")]
14
15 [Attribute("#AR-Supplies_Refund_Action_Vehicle_Occupied", desc: "Invalid reason shown when entity is a vehicle and it is occupied")]
17
19 protected SCR_EntityCatalogManagerComponent m_EntityCatalogManager;
20 protected SCR_CatalogEntitySpawnerComponent m_CatalogEntitySpawnerComponent;
21 protected RplComponent m_ReplicationComponent;
23 protected float m_fResourceCost = -1;
24
25 protected bool m_bIsResourceEnabled = true;
26
27 protected static ref ScriptInvokerEntity2 s_OnRefundPerformed;//Entity refundedEntity, Entity playerEntity
28
29 //~ For vehicles it sets the compartment manager to check if it is occupied
30 protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
31
42
43 //------------------------------------------------------------------------------------------------
44 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
45 {
47 return;
48
50 return;
51
52 //~ Vehicle is in use
53 if (m_CompartmentManager && m_CompartmentManager.AnyCompartmentsOccupiedOrLocked())
54 return;
55
56 //~ Refund if resource is enabled
58 {
59 if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(GetOwner()))
60 m_ResourceGenerator.RequestGeneration(SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier()));
61 else
62 m_ResourceGenerator.RequestGeneration(SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier()));
63 }
64
66 s_OnRefundPerformed.Invoke(pOwnerEntity, pUserEntity);
67
68 RplComponent.DeleteRplEntity(GetOwner(), false);
69 }
70
71 //------------------------------------------------------------------------------------------------
72 override bool GetActionNameScript(out string outName)
73 {
75 return false;
76
78 {
79 float resourceCost;
80
81 if (m_CatalogEntitySpawnerComponent.IsInGracePeriod(GetOwner()))
82 resourceCost = SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_ResourceGenerator.GetResourceMultiplier());
83 else
84 resourceCost = SCR_ResourceSystemHelper.RoundRefundSupplyAmount(m_fResourceCost * m_CatalogEntitySpawnerComponent.GetPostGracePeriodRefundMultiplier());
85
86 if (resourceCost > 0)
87 {
88 ActionNameParams[0] = SCR_ResourceSystemHelper.SuppliesToString(resourceCost);
89 }
90 else
91 {
93 return true;
94 }
95 }
96 else
97 {
99 return true;
100 }
101
102 return false;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 override event bool CanBePerformedScript(IEntity user)
107 {
108 /*if (!SelectSuitableResourceGenerator(user))
109 {
110 m_sCannotPerformReason = m_sInvalidNoValidRefundPoint;
111 return false;
112 }*/
113
114 //~ Additional settings has disabled the action so do not perform and show disabled reason
116 if (additionalSettings && !additionalSettings.IsEntityRefundingActionAllowed())
117 {
118 m_sCannotPerformReason = additionalSettings.GetEntityRefundingDisabledReason();
119 return false;
120 }
121
122 //~ Check if vehicle is in use
123 if (m_CompartmentManager && m_CompartmentManager.AnyCompartmentsOccupiedOrLocked())
124 {
126 return false;
127 }
128
129 return true;
130 }
131
132 //------------------------------------------------------------------------------------------------
138 {
139 SCR_ResourceComponent resourceComponent;
140 SCR_ResourceGenerator resourceGeneratorCompare;
141 m_ResourceGenerator = null;
143 vector ownerOrigin = GetOwner().GetOrigin();
144 float distanceSq = float.MAX;
145 float distanceSqCompare = float.MAX;
146
147 foreach (SCR_CatalogEntitySpawnerComponent component : SCR_CatalogEntitySpawnerComponent.INSTANCES)
148 {
149 distanceSqCompare = vector.DistanceSq(ownerOrigin, component.GetOwner().GetOrigin());
150
151 if (distanceSq <= distanceSqCompare && !component.CanRefund(GetOwner(), user))
152 continue;
153
154 resourceComponent = SCR_ResourceComponent.Cast(component.GetOwner().FindComponent(SCR_ResourceComponent));
155
156 if (resourceComponent && resourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, m_eResourceType, resourceGeneratorCompare) && distanceSqCompare < resourceGeneratorCompare.GetStorageRange() * resourceGeneratorCompare.GetStorageRange())
157 {
158 distanceSq = distanceSqCompare;
160 m_ResourceGenerator = resourceGeneratorCompare;
161
162 continue;
163 }
164
165 resourceGeneratorCompare = null;
166 }
167
168 //~ Is resource enabled
169 if (resourceComponent)
170 m_bIsResourceEnabled = resourceComponent.IsResourceTypeEnabled(m_eResourceType);
171 else
173
174 return m_ResourceGenerator;
175 }
176
177 //------------------------------------------------------------------------------------------------
178 override event bool CanBeShownScript(IEntity user)
179 {
181 return false;
182
184 return false;
185
186 //~ Additional settings has disabled the action and the reason for disabling is set empty so hide the action
188 if (additionalSettings && (!additionalSettings.IsEntityRefundingActionAllowed() && additionalSettings.GetEntityRefundingDisabledReason().IsEmpty()))
189 return false;
190
191 return super.CanBeShownScript(user);
192 }
193
194 //------------------------------------------------------------------------------------------------
195 override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
196 {
197 //~ Call a frame later so the catalog is initialized correctly
198 GetGame().GetCallqueue().CallLater(DelayedInit, param1: pOwnerEntity, param2: pManagerComponent);
199 }
200
201 //------------------------------------------------------------------------------------------------
202 protected void DelayedInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
203 {
204 m_fResourceCost = -1;
205
206 if (!pOwnerEntity)
207 return;
208
209 m_ReplicationComponent = RplComponent.Cast(pOwnerEntity.FindComponent(RplComponent));
210 m_EntityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
211
213 return;
214
216 ResourceName prefabName = pOwnerEntity.GetPrefabData().GetPrefabName();
217
219 if (factionComponent)
220 m_Faction = SCR_Faction.Cast(factionComponent.GetDefaultAffiliatedFaction());
221
222 //~ Has faction get it from faction
223 if (m_Faction)
224 {
225 entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.VEHICLE, prefabName, m_Faction);
226
227 if (!entry)
228 {
229 entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.CHARACTER, prefabName, m_Faction);
230
231 if (!entry)
232 entry = m_EntityCatalogManager.GetEntryWithPrefabFromGeneralOrFactionCatalog(EEntityCatalogType.GROUP, prefabName, m_Faction);
233 }
234 }
235 //~ Does not have faction so get factionless
236 else
237 {
238 entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.VEHICLE, prefabName);
239
240 if (!entry)
241 {
242 entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.CHARACTER, prefabName);
243
244 if (!entry)
245 entry = m_EntityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.GROUP, prefabName);
246 }
247 }
248
249 //~ No entry found
250 if (!entry)
251 return;
252
253 //~ Get compartment manager if vehicle
254 m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
255
257 if (uiInfo)
258 {
259 array<ref SCR_EntityBudgetValue> budgets = {};
260 uiInfo.GetEntityAndChildrenBudgetCost(budgets);
261
262 foreach (SCR_EntityBudgetValue budget : budgets)
263 {
264 if (budget.GetBudgetType() == EEditableEntityBudget.CAMPAIGN)
265 {
266 m_fResourceCost = budget.GetBudgetValue();
267 return;
268 }
269 }
270 }
271
272 //~ Could not get budget value from editable entity so use spawner data instead if any
274 if (!data)
275 return;
276
277 m_fResourceCost = data.GetSupplyCost();
278 }
279}
EEditableEntityBudget
EEntityCatalogType
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_AdditionalGameModeSettingsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Get all prefabs that have the spawner data
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerEntity2Method > ScriptInvokerEntity2
proto external IEntity GetOwner()
Returns the parent entity of this action.
string m_sCannotPerformReason
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external EntityPrefabData GetPrefabData()
void GetEntityAndChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get Entity and its children budgets.
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 UI info Prefab needs to be an editable entity or have a custom UI info logic Note that if UIInfo is NULL then the autotest will fail return Ui info *SCR_UIInfo GetEntityUiInfo()
override event bool CanBePerformedScript(IEntity user)
override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
void DelayedInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override event bool CanBeShownScript(IEntity user)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
static ScriptInvokerEntity2 GetOnRefundPerformed()
SCR_EntityCatalogManagerComponent m_EntityCatalogManager
SCR_CatalogEntitySpawnerComponent m_CatalogEntitySpawnerComponent
override bool GetActionNameScript(out string outName)
SCR_BaseCompartmentManagerComponent m_CompartmentManager
static ref ScriptInvokerEntity2 s_OnRefundPerformed
A scripted action class having optional logic to check if vehicle is valid.
SCR_FieldOfViewSettings Attribute
T2 param2
Definition tuple.c:92
Tuple param1