Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignMobileAssemblyStandaloneComponent.c
Go to the documentation of this file.
4
5class SCR_CampaignMobileAssemblyStandaloneComponent : ScriptComponent
6{
8 static ref ScriptInvokerVoid s_OnUpdateRespawnCooldown = new ScriptInvokerVoid();
9
10 static const int RESPAWN_COOLDOWN = 60000;
11
12 protected RplComponent m_RplComponent;
13
14 protected MapItem m_MapItem;
15
16 protected IEntity m_Vehicle;
17
20
21 protected bool m_bIsInRadioRange;
22 protected bool m_bCooldownDone = true;
23
24 protected const EResourceType RESOURCE_TYPE = EResourceType.SUPPLIES;
26
27 [RplProp(onRplName: "OnFactionChanged")]
29
30 [RplProp(onRplName: "OnParentFactionIDSet")]
32
33 [RplProp()]
35
36 [RplProp()]
37 protected int m_iRadioRange;
38
39 //------------------------------------------------------------------------------------------------
40 override void OnPostInit(IEntity owner)
41 {
42 if (!GetGame().InPlayMode())
43 return;
44
45 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
46
47 if (!campaign)
48 return;
49
50 super.OnPostInit(owner);
51
52 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
53
54 GetGame().GetCallqueue().CallLater(UpdateRadioCoverage, 1000, true);
55 GetGame().GetCallqueue().CallLater(UpdateRespawnCooldown, 250, true, null);
56
57 if (IsProxy())
58 {
59 campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Insert(OnParentFactionIDSet);
60 }
61 else
62 {
63 // Only update respawn cooldown if a load state has not been applied
64 ChimeraWorld world = GetGame().GetWorld();
65 if (world.GetWorldTime() > 10000)
66 {
67 m_fRespawnAvailableSince = world.GetServerTimestamp().PlusMilliseconds(RESPAWN_COOLDOWN);
68 m_bCooldownDone = false;
69 }
70 else
71 {
72 m_fRespawnAvailableSince = world.GetServerTimestamp();
73 m_bCooldownDone = true;
74 }
75 Replication.BumpMe();
76 }
77 }
78
79 //------------------------------------------------------------------------------------------------
80 override void OnDelete(IEntity owner)
81 {
82 super.OnDelete(owner);
83
84 GetGame().GetCallqueue().Remove(UpdateRadioCoverage);
85 GetGame().GetCallqueue().Remove(UpdateRespawnCooldown);
86
87 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
88
89 if (!campaign)
90 return;
91
92 campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Remove(OnParentFactionIDSet);
93 }
94
95 //------------------------------------------------------------------------------------------------
96 protected bool IsProxy()
97 {
98 return (m_RplComponent && m_RplComponent.IsProxy());
99 }
100
101 //------------------------------------------------------------------------------------------------
103 void SetVehicle(IEntity vehicle)
104 {
105 m_Vehicle = vehicle;
106 }
107
108 //------------------------------------------------------------------------------------------------
111 {
112 return m_Vehicle;
113 }
114
115 //------------------------------------------------------------------------------------------------
117 void SetParentFactionID(int factionID)
118 {
119 m_iParentFaction = factionID;
120 Replication.BumpMe();
122 }
123
124 //------------------------------------------------------------------------------------------------
126 {
127 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
128 m_ParentFaction = SCR_CampaignFaction.Cast(fManager.GetFactionByIndex(m_iParentFaction));
129
130 if (!m_ParentFaction)
131 return;
132
133 SCR_CoverageRadioComponent radioComponent = SCR_CoverageRadioComponent.Cast(GetOwner().FindComponent(BaseRadioComponent));
134
135 if (radioComponent)
136 radioComponent.SetEncryptionKey(m_ParentFaction.GetFactionRadioEncryptionKey());
137
138 m_ParentFaction.SetMobileAssembly(this);
139
140 // Delay so map item can initialize
141 if (!System.IsConsoleApp())
142 GetGame().GetCallqueue().CallLater(UpdateMapItem, SCR_GameModeCampaign.MINIMUM_DELAY);
143
146 }
147
148 //------------------------------------------------------------------------------------------------
151 {
152 return m_iParentFaction;
153 }
154
155 //------------------------------------------------------------------------------------------------
161
162 //------------------------------------------------------------------------------------------------
165 {
166 return m_Faction;
167 }
168
169 //------------------------------------------------------------------------------------------------
171 void SetRadioRange(int range)
172 {
173 m_iRadioRange = range;
174 }
175
176 //------------------------------------------------------------------------------------------------
179 {
180 return m_iRadioRange;
181 }
182
183 //------------------------------------------------------------------------------------------------
184 protected void UpdateMapItem()
185 {
186 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
187
188 if (!campaign)
189 return;
190
191 SCR_MapDescriptorComponent mapDescriptor = SCR_MapDescriptorComponent.Cast(GetOwner().FindComponent(SCR_MapDescriptorComponent));
192
193 if (mapDescriptor)
194 m_MapItem = mapDescriptor.Item();
195
196 Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
197
198 if (!m_MapItem || m_ParentFaction != playerFaction)
199 return;
200
201 m_MapItem.SetVisible(true);
202
203 switch (m_ParentFaction.GetFactionKey())
204 {
205 case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.BLUFOR):
206 {
207 m_MapItem.SetFactionIndex(EFactionMapID.WEST);
208 break;
209 }
210
211 case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.OPFOR):
212 {
213 m_MapItem.SetFactionIndex(EFactionMapID.EAST);
214 break;
215 }
216
217 default:
218 {
219 m_MapItem.SetFactionIndex(EFactionMapID.UNKNOWN);
220 }
221 }
222 }
223
224 //------------------------------------------------------------------------------------------------
226 {
227 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
228
229 if (!fManager)
230 return;
231
232 FactionKey fKey;
233 Faction f = fManager.GetFactionByIndex(m_iFaction);
234
235 if (f)
236 {
237 fKey = f.GetFactionKey();
239 }
240
243 }
244
245 //------------------------------------------------------------------------------------------------
248 {
249 return m_bIsInRadioRange;
250 }
251
252 //------------------------------------------------------------------------------------------------
255 {
256 return m_MapItem;
257 }
258
259 //------------------------------------------------------------------------------------------------
262 {
263 if (!m_ParentFaction)
264 return;
265
266 bool inRangeNow = SCR_GameModeCampaign.GetInstance().GetBaseManager().IsEntityInFactionRadioSignal(GetOwner(), m_ParentFaction);
267 m_bIsInRadioRange = inRangeNow;
268
270
271 if (damageComponent && damageComponent.GetState() == EDamageState.DESTROYED)
272 {
273 if (m_MapItem)
274 m_MapItem.SetVisible(false);
275
276 if (!IsProxy())
277 {
278 SCR_CoverageRadioComponent radioComponent = SCR_CoverageRadioComponent.Cast(GetOwner().FindComponent(BaseRadioComponent));
279
280 if (radioComponent)
281 radioComponent.SetPower(false);
282 }
283 }
284
285 if (IsProxy())
286 return;
287
289 {
291 Replication.BumpMe();
293 }
294
296 {
298 Replication.BumpMe();
300 }
301 }
302
303 //------------------------------------------------------------------------------------------------
307 {
308 if (!m_ParentFaction)
309 return;
310
312
313 TextWidget respawn;
314 ImageWidget respawnImg;
315
316 if (!hq)
317 return;
318
320
321 if (w && imageset)
322 {
323 respawn = TextWidget.Cast(w.FindAnyWidget("Respawn"));
324 respawnImg = ImageWidget.Cast(w.FindAnyWidget("RespawnIMG"));
325 respawnImg.LoadImageFromSet(0, imageset, "RespawnBig");
326 }
327
328 ChimeraWorld world = GetOwner().GetWorld();
329 if (m_fRespawnAvailableSince.Greater(world.GetServerTimestamp()))
330 {
331 if (m_bCooldownDone)
332 m_bCooldownDone = false;
333
334 if (RplSession.Mode() != RplMode.Dedicated)
335 {
336 if (!w)
337 s_OnUpdateRespawnCooldown.Invoke();
338 else
339 {
340 respawn.SetVisible(true);
341 respawnImg.SetVisible(true);
342
343 float respawnCooldown = Math.Ceil(m_fRespawnAvailableSince.DiffMilliseconds(world.GetServerTimestamp()) * 0.001);
344 int d, h, m, s;
345 string sStr;
346 SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(respawnCooldown, d, h, m, s);
347 sStr = s.ToString();
348
349 if (s < 10)
350 sStr = "0" + sStr;
351
352 respawn.SetTextFormat("#AR-Campaign_MobileAssemblyCooldown", m, sStr);
353 }
354 }
355 }
356 else
357 {
358 GetGame().GetCallqueue().Remove(UpdateRespawnCooldown);
359
360 if (w)
361 {
362 if (RplSession.Mode() != RplMode.Dedicated)
363 {
364 respawn.SetVisible(false);
365 respawnImg.SetVisible(false);
366 }
367 }
368 else
369 {
370 if (!m_bCooldownDone)
371 {
372 m_bCooldownDone = true;
373 s_OnUpdateRespawnCooldown.Invoke();
374
375 if (!IsProxy() && IsInRadioRange())
376 {
378 Replication.BumpMe();
380 }
381 }
382 }
383 }
384 }
385
386 //------------------------------------------------------------------------------------------------
390 {
391 if (!w || !m_ParentFaction)
392 return;
393
395 if (!hq)
396 return;
397
399 if (!imageset)
400 return;
401
402 TextWidget resource = TextWidget.Cast(w.FindAnyWidget("Supplies"));
403 ImageWidget resourceImg = ImageWidget.Cast(w.FindAnyWidget("SuppliesIMG"));
404
405 if (!resource || !resourceImg)
406 return;
407
408 SCR_ResourceComponent resourceComp = SCR_ResourceComponent.FindResourceComponent(GetOwner());
409 if (!resourceComp)
410 return;
411
412 SCR_ResourceConsumer resourceConsumer;
413 if (!resourceComp.GetConsumer(RESOURCE_GENERATOR_ID, RESOURCE_TYPE, resourceConsumer))
414 return;
415
416 float resourceAmount = resourceConsumer.GetAggregatedResourceValue();
417 float maxResourceAmount = resourceConsumer.GetAggregatedMaxResourceValue();
418
419 resource.SetTextFormat("#AR-Campaign_BaseSuppliesAmount", resourceAmount, maxResourceAmount);
420 resourceImg.LoadImageFromSet(0, imageset, "SuppliesBig");
421
422 resource.SetVisible(true);
423 resourceImg.SetVisible(true);
424 }
425}
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
Faction m_Faction
enum EAICompartmentType m_Vehicle
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
RplComponent m_RplComponent
void UpdateSuppliesAmount(Widget w=null)
SCR_CampaignFaction GetParentFaction()
void UpdateRespawnCooldown(Widget w=null)
void SetParentFactionID(int factionID)
void SetVehicle(IEntity vehicle)
const EResourceGeneratorID RESOURCE_GENERATOR_ID
SCR_CampaignFaction GetFaction()
WorldTimestamp m_fRespawnAvailableSince
SCR_CampaignFaction m_ParentFaction
SCR_CampaignMobileAssemblyStandaloneComponentClass s_OnSpawnPointOwnerChanged
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
EResourceGeneratorID
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
SCR_SuppliesTransferWaypoint RESOURCE_TYPE
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Definition Math.c:13
Main replication API.
Definition Replication.c:14
static bool UpdateAll(bool forceRecalculation=false)
Spawn point entity defines positions on which players can possibly spawn.
void SetFaction(Faction faction)
proto external GenericEntity GetOwner()
Get owner entity.
EDamageState