Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignNetworkComponent.c
Go to the documentation of this file.
1 #define ENABLE_BASE_DESTRUCTION
2 [EntityEditorProps(category: "GameScripted/Campaign", description: "Handles client > server communication in Campaign. Should be attached to PlayerController.", color: "0 0 255 255")]
3 class SCR_CampaignNetworkComponentClass : ScriptComponentClass
4 {
5 }
6 
8 enum ECampaignClientNotificationID
9 {
11  NO_SPACE,
15  RESPAWN
16 }
17 
19 class SCR_CampaignNetworkComponent : ScriptComponent
20 {
21  // Member variables
23  protected RplComponent m_RplComponent;
24  protected bool m_bFirstSpawn = true;
25 
26  protected vector m_vLastLoadedAt;
27  protected vector m_vLastUnloadedAt;
28 
29  protected float m_fNoRewardSupplies;
30 
32 
33  protected static ref ScriptInvokerInt3 s_OnSuppliesDelivered;
34 
35  static const float FULL_SUPPLY_TRUCK_AMOUNT = 600.0;
36  static const int SUPPLY_DELIVERY_THRESHOLD_SQ = 200 * 200;
37 
38  //********************************//
39  //RUNTIME SYNCHED MEMBER VARIABLES//
40  //********************************//
41 
42  [RplProp(condition: RplCondition.OwnerOnly)]
43  protected WorldTimestamp m_fLastAssetRequestTimestamp;
44 
45  [RplProp(condition: RplCondition.OwnerOnly)]
46  protected WorldTimestamp m_fLastHQRadioMessageTimestamp;
47 
48  //------------------------------------------------------------------------------------------------
51  static SCR_CampaignNetworkComponent GetCampaignNetworkComponent(int playerID)
52  {
53  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
54 
55  if (!playerController)
56  return null;
57 
58  SCR_CampaignNetworkComponent networkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
59 
60  return networkComponent;
61  }
62 
63  //*********************//
64  //PUBLIC MEMBER METHODS//
65  //*********************//
66 
67  //------------------------------------------------------------------------------------------------
69  WorldTimestamp GetLastRequestTimestamp()
70  {
72  }
73 
74  //------------------------------------------------------------------------------------------------
76  void SetLastRequestTimestamp(WorldTimestamp timestamp)
77  {
78  if (IsProxy())
79  return;
80 
81  m_fLastAssetRequestTimestamp = timestamp;
82  Replication.BumpMe();
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  static ScriptInvokerInt3 GetOnSuppliesDelivered()
88  {
89  if (!s_OnSuppliesDelivered)
90  s_OnSuppliesDelivered = new ScriptInvokerInt3();
91 
92  return s_OnSuppliesDelivered;
93  }
94 
95  //------------------------------------------------------------------------------------------------
97  protected bool IsProxy()
98  {
99  return (m_RplComponent && m_RplComponent.IsProxy());
100  }
101 
102  //------------------------------------------------------------------------------------------------
104  void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
105  {
106 #ifdef ENABLE_BASE_DESTRUCTION
107  Rpc(RpcAsk_RepairComposition, index, repairCost, destructibleID, Replication.FindId(slotEnt), Replication.FindId(base));
108 #endif
109  }
110 
111  //------------------------------------------------------------------------------------------------
117  void LoadSupplies(RplId suppliesID, IEntity player, SCR_CampaignMilitaryBaseComponent base, int amount = 0)
118  {
119  if (!player || !base)
120  return;
121 
122  RplId baseID = Replication.FindId(base);
123 
124  if (!m_PlayerController)
125  return;
126 
127  int playerID = m_PlayerController.GetPlayerId();
128  Rpc(RpcAsk_LoadSupplies, suppliesID, playerID, baseID, amount);
129  }
130 
131  //------------------------------------------------------------------------------------------------
137  void LoadSuppliesStandalone(RplId suppliesID, IEntity player, SCR_CampaignSuppliesComponent depot, int amount = 0)
138  {
139  if (!player || !depot)
140  return;
141 
142  RplId depotID = Replication.FindId(depot);
143 
144  if (!m_PlayerController)
145  return;
146 
147  int playerID = m_PlayerController.GetPlayerId();
148  Rpc(RpcAsk_LoadSuppliesStandalone, suppliesID, playerID, depotID, amount);
149  }
150 
151  //------------------------------------------------------------------------------------------------
156  void StartLoading(RplId suppliesID, int supplies, bool IsUnloading = false)
157  {
158  int playerID = m_PlayerController.GetPlayerId();
159  Rpc(RpcAsk_SuppliesLoadingStarted, suppliesID, playerID, supplies, IsUnloading);
160  }
161 
162  //------------------------------------------------------------------------------------------------
166  void StopLoading(RplId suppliesID, bool IsUnloading = false)
167  {
168  int playerID = m_PlayerController.GetPlayerId();
169  Rpc(RpcAsk_SuppliesLoadingCanceled, suppliesID, playerID, IsUnloading);
170  }
171 
172  //------------------------------------------------------------------------------------------------
177  void UnloadSupplies(RplId suppliesID, IEntity player, SCR_CampaignMilitaryBaseComponent base, int amount = 0)
178  {
179  if (!player || !base)
180  return;
181 
182  RplId baseID = Replication.FindId(base);
183 
184  if (!m_PlayerController)
185  return;
186 
187  int playerID = m_PlayerController.GetPlayerId();
188  Rpc(RpcAsk_UnloadSupplies, suppliesID, playerID, baseID, amount);
189  }
190 
191  //------------------------------------------------------------------------------------------------
193  void AddRadio()
194  {
195  Rpc(RpcAsk_AddRadio, SCR_PlayerController.GetLocalPlayerId());
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
200  protected void RpcAsk_AddRadio(int playerID)
201  {
202  PlayerManager pMan = GetGame().GetPlayerManager();
203 
204  if (!pMan)
205  return;
206 
207  SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(pMan.GetPlayerControlledEntity(playerID));
208 
209  if (!player)
210  return;
211 
212  EntitySpawnParams spawnParams = EntitySpawnParams();
213  spawnParams.TransformMode = ETransformMode.WORLD;
214  player.GetWorldTransform(spawnParams.Transform);
215 
216  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(player.GetFaction());
217 
218  if (!faction)
219  return;
220 
221  Resource res = Resource.Load(faction.GetRadioPrefab());
222 
223  if (!res)
224  return;
225 
226  IEntity radio = GetGame().SpawnEntityPrefab(res, GetGame().GetWorld(),spawnParams);
227 
228  if (!radio)
229  return;
230 
231  RplComponent rplC = RplComponent.Cast(radio.FindComponent(RplComponent));
232 
233  if (!rplC)
234  return;
235 
236  Rpc(RpcDo_AddRadio, rplC.Id());
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
241  protected void RpcDo_AddRadio(RplId ID)
242  {
243  GetGame().GetCallqueue().CallLater(FindRadioDelayed, 10, true, ID)
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  protected void FindRadioDelayed(RplId ID)
248  {
249  RplComponent rplC = RplComponent.Cast(Replication.FindItem(ID));
250 
251  if (!rplC)
252  return;
253 
254  GetGame().GetCallqueue().Remove(FindRadioDelayed);
255  IEntity player = SCR_PlayerController.GetLocalControlledEntity();
256 
257  if (!player)
258  return;
259 
260  IEntity radio = rplC.GetEntity();
261 
262  if (!radio)
263  return;
264 
265  SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(player.FindComponent(SCR_InventoryStorageManagerComponent));
266 
267  if (!inventory)
268  return;
269 
270  inventory.InsertItem(radio);
271  }
272 
273  //------------------------------------------------------------------------------------------------
277  void DeployMobileAsembly(notnull SCR_CampaignMobileAssemblyComponent comp, bool deploy)
278  {
279  Rpc(RpcAsk_DeployMobileAsembly, Replication.FindId(comp), deploy, SCR_PlayerController.GetLocalPlayerId());
280  }
281 
282  //------------------------------------------------------------------------------------------------
283  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
284  protected void RpcAsk_DeployMobileAsembly(RplId assemblyComponentID, bool deploy, int playerID)
285  {
286  SCR_CampaignMobileAssemblyComponent comp = SCR_CampaignMobileAssemblyComponent.Cast(Replication.FindItem(assemblyComponentID));
287 
288  if (!comp)
289  return;
290 
291  float depth;
292 
293  if (SCR_WorldTools.IsObjectUnderwater(comp.GetOwner(), vector.Zero, -1, depth) && depth > SCR_CampaignMobileAssemblyComponent.MAX_WATER_DEPTH)
294  return;
295 
296  if (comp.IsDeployed() == deploy)
297  return;
298 
299  if (deploy)
300  comp.Deploy(SCR_EMobileAssemblyStatus.DEPLOYED, playerID);
301  else
302  comp.Deploy(SCR_EMobileAssemblyStatus.DISMANTLED, playerID);
303  }
304 
305  //------------------------------------------------------------------------------------------------
309  {
310  if (!base)
311  return;
312 
313  Faction faction = SCR_FactionManager.SGetLocalPlayerFaction();
314  int factionID = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager()).GetFactionIndex(faction);
315  int playerID = m_PlayerController.GetPlayerId();
316  IEntity player = m_PlayerController.GetControlledEntity();
317 
318  if (!player)
319  return;
320 
321  CharacterControllerComponent comp = CharacterControllerComponent.Cast(player.FindComponent(CharacterControllerComponent));
322 
323  if (!comp)
324  return;
325 
326  if (comp.IsDead())
327  return;
328 
329  Rpc(RpcAsk_CaptureBase, Replication.FindId(base), factionID, playerID);
330  }
331 
332  //------------------------------------------------------------------------------------------------
337  {
338  if (!base)
339  return;
340 
341  Rpc(RpcAsk_CaptureBase, Replication.FindId(base), factionIndex, SCR_CampaignMilitaryBaseComponent.INVALID_PLAYER_INDEX);
342  }
343 
344  //------------------------------------------------------------------------------------------------
348  void ToggleBaseCapture(notnull SCR_CampaignMilitaryBaseComponent base, bool isBeingCaptured)
349  {
350  Faction faction = SCR_FactionManager.SGetLocalPlayerFaction();
351  int factionID = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager()).GetFactionIndex(faction);
352  int playerID = m_PlayerController.GetPlayerId();
353 
354  if (isBeingCaptured)
355  Rpc(RpcAsk_CaptureBaseBegin, Replication.FindId(base), factionID, playerID);
356  else
357  Rpc(RpcAsk_CaptureBaseEnd, Replication.FindId(base));
358  }
359 
360  //***********//
361  //RPC METHODS//
362  //***********//
363 
364 #ifdef ENABLE_BASE_DESTRUCTION
365  //------------------------------------------------------------------------------------------------
367  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
368  protected void RpcAsk_RepairComposition(int index, int repairCost, int destructibleID, RplId slotID, RplId baseID)
369  {
370  if (index == -1 || repairCost == -1 || destructibleID == -1)
371  return;
372 
373  SCR_MPDestructionManager destructionManager = SCR_MPDestructionManager.GetInstance();
374  if (!destructionManager)
375  return;
376 
377  SCR_DestructionMultiPhaseComponent destructibleComp = SCR_DestructionMultiPhaseComponent.Cast(destructionManager.FindDynamicallySpawnedDestructibleByIndex(destructibleID, index));
378  if (!destructibleComp)
379  return;
380 
381  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
382  if (!base)
383  return;
384 
385  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
386  if (!campaign)
387  return;
388 
389  IEntity composition = IEntity.Cast(SCR_EntityHelper.GetMainParent(destructibleComp.GetOwner()));
390  if (!composition)
391  return;
392 
393  SCR_CampaignServiceEntityComponent serviceEntityComp = SCR_CampaignServiceEntityComponent.Cast(destructibleComp.GetOwner().FindComponent(SCR_CampaignServiceEntityComponent));
394  if (!serviceEntityComp)
395  return;
396 
397  SCR_CampaignServiceCompositionComponent serviceCompositionComp = SCR_CampaignServiceCompositionComponent.Cast(composition.FindComponent(SCR_CampaignServiceCompositionComponent));
398  if (!serviceCompositionComp)
399  return;
400 
401  // Check if the composition entity belong to is disabled or not. If so, increase number of spawn tickets again.
402 // if (!serviceCompositionComp.IsServiceOperable())
403 // campaign.OnStructureChanged(base, SCR_SiteSlotEntity.Cast(Replication.FindItem(slotID)), base.GetServiceByLabel(serviceCompositionComp.GetCompositionType()), true);
404 
405  // Repair entity
406  serviceEntityComp.RepairEntity();
407 
408  // Supply in base are reduced (cost of repair)
409  base.AddSupplies(-repairCost);
410 
411  // Update map UI
412  if (RplSession.Mode() != RplMode.Dedicated)
413  base.GetMapDescriptor().HandleMapInfo();
414  }
415 #endif
416 
417  //------------------------------------------------------------------------------------------------
422  {
423  RplId baseID = Replication.FindId(base);
424 
425  if (!baseID.IsValid())
426  return;
427 
428  Rpc(RpcAsk_AddSuppliesFromContextMenu, baseID, suppliesCnt);
429  }
430 
431  //------------------------------------------------------------------------------------------------
432  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
433  protected void RpcAsk_AddSuppliesFromContextMenu(RplId baseID, int suppliesCnt)
434  {
435  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
436 
437  if (!base)
438  return;
439 
440  if (base.GetSupplies() >= base.GetSuppliesMax())
441  return;
442 
443  base.AddSupplies(Math.Min(suppliesCnt, base.GetSuppliesMax() - base.GetSupplies()));
444  }
445  //------------------------------------------------------------------------------------------------
446  // Sends player notification to players inside Vehicle
451  protected void SendToVehicleOccupants(ENotification messageID, IEntity vehicleEntity, int playerID, int number = 0)
452  {
453  if (!vehicleEntity)
454  return;
455 
456  IEntity parentVehicle = vehicleEntity.GetParent();
457  if (!parentVehicle)
458  return;
459 
460  //Gettings players from inside of vehicle. Condition allows spawning only Cargo.
461  SCR_BaseCompartmentManagerComponent comp = SCR_BaseCompartmentManagerComponent.Cast(parentVehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
462  if (!comp)
463  return;
464 
465  array<IEntity> occupants = {};
466  comp.GetOccupants(occupants);
467 
468  if(occupants.IsEmpty())
469  return;
470 
471  foreach (IEntity occupant : occupants)
472  {
473  int occupantID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(occupant);
474  if(number != 0)
475  SCR_NotificationsComponent.SendToPlayer(occupantID, messageID, playerID, number);
476  else
477  SCR_NotificationsComponent.SendToPlayer(occupantID, messageID, playerID);
478  }
479  }
480 
481  //------------------------------------------------------------------------------------------------
482  // Handles start of loading/unloading supplies
483  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
484  protected void RpcAsk_SuppliesLoadingStarted(RplId suppliesID, int playerID, int supplies, bool IsUnloading)
485  {
486  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(suppliesID));
487  array<IEntity> occupants = {}; //new array<IEntity>;
488 
489  if(!suppliesComponent)
490  return;
491 
492  //Gettings vehicle entity from cargo
493  IEntity vehicleEntity = suppliesComponent.GetOwner();
494 
495  if(!IsUnloading)
496  {
497  //suppliesComponent.SetSupplyLoadingPlayer(playerID);
498  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_LOADING_PLAYER, vehicleEntity, playerID, supplies);
499  }
500  else
501  {
502  //suppliesComponent.SetSupplyUnloadingPlayer(playerID);
503  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_UNLOADING_PLAYER, vehicleEntity, playerID, supplies);
504  }
505  }
506 
507  //------------------------------------------------------------------------------------------------
508  // Handles canceling of loading/unloading supplies
509  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
510  protected void RpcAsk_SuppliesLoadingCanceled(RplId suppliesID, int playerID, bool IsUnloading)
511  {
512  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(suppliesID));
513 
514  if(!suppliesComponent)
515  return;
516 
517  //Gettings vehicle entity from cargo
518  IEntity vehicleEntity = suppliesComponent.GetOwner();
519 
520  if(!IsUnloading)
521  {
522  //suppliesComponent.DeleteSupplyLoadingPlayer(playerID);
523  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_LOADING_PLAYER_STOPPED, vehicleEntity, playerID);
524  }
525  else
526  {
527  //suppliesComponent.DeleteSupplyUnloadingPlayer(playerID);
528  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_UNLOADING_PLAYER_STOPPED, vehicleEntity, playerID);
529  }
530 
531  }
532 
533  //------------------------------------------------------------------------------------------------
539  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
540  protected void RpcAsk_LoadSupplies(RplId suppliesID, int playerID, RplId baseID, int amount)
541  {
542  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(suppliesID));
543 
544  if (!suppliesComponent)
545  return;
546 
547  IEntity box = suppliesComponent.GetOwner();
548 
549  if (!box)
550  return;
551 
552  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
553 
554  if (!base)
555  return;
556 
557  if (amount > base.GetSupplies())
558  return;
559 
560  IEntity player = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
561 
562  if (!player)
563  return;
564 
565 // if (suppliesComponent.GetSupplies() == suppliesComponent.GetSuppliesMax())
566 // return;
567 
568  Faction playerFaction = SCR_CampaignReconfigureRelayUserAction.GetPlayerFaction(player);
569 
570  if (!playerFaction || playerFaction != base.GetFaction())
571  return;
572 
573  SCR_CampaignSuppliesComponent baseSuppliesComponent = SCR_CampaignSuppliesComponent.Cast(base.GetOwner().FindComponent(SCR_CampaignSuppliesComponent));
574  if (!baseSuppliesComponent)
575  return;
576 
577 // float distSq = Math.Pow(baseSuppliesComponent.GetOperationalRadius(), 2);
578 // vector vehPos = box.GetOrigin();
579 //
580 // if (vector.DistanceSq(vehPos, player.GetOrigin()) > 100)
581 // return;
582 //
583 // if (vector.DistanceSq(vehPos, base.GetOwner().GetOrigin()) > distSq)
584 // {
585 // SCR_ServicePointComponent service = base.GetServiceByType(SCR_EServicePointType.SUPPLY_DEPOT);
586 // if (!service)
587 // return;
588 //
589 // if (vector.DistanceSq(vehPos, service.GetOwner().GetOrigin()) > distSq)
590 // return;
591 // }
592 //
593 // // Validity check passed, perform action
594 // int finalAmount = Math.Min(suppliesComponent.GetSuppliesMax() - suppliesComponent.GetSupplies(), amount);
595 // suppliesComponent.AddSupplies(finalAmount);
596 // base.AddSupplies(-finalAmount);
597 // suppliesComponent.SetLastLoadedAt(base);
598 // Rpc(RpcDo_PlayerFeedbackValueBase, ECampaignClientNotificationID.SUPPLIES_LOADED, (float)finalAmount, base.GetCallsign());
599 // suppliesComponent.DeleteSupplyLoadingPlayer(playerID);
600 
601  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_LOADING_PLAYER_FINISHED, box, playerID);
602  }
603 
604  //------------------------------------------------------------------------------------------------
605  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
606  protected void RpcAsk_LoadSuppliesStandalone(RplId suppliesID, int playerID, RplId depotID, int amount)
607  {
608  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(suppliesID));
609 
610  if (!suppliesComponent)
611  return;
612 
613  SCR_CampaignSuppliesComponent depot = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(depotID));
614 
615  if (!depot)
616  return;
617 
618  IEntity player = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
619 
620  if (!player)
621  return;
622 
623  IEntity box = suppliesComponent.GetOwner();
624 
625  if (!box)
626  return;
627 
628 // if (amount > depot.GetSupplies())
629 // return;
630 //
631 // if (suppliesComponent.GetSupplies() == suppliesComponent.GetSuppliesMax())
632 // return;
633 //
634 // float distSq = Math.Pow(depot.GetOperationalRadius(), 2);
635 // vector vehPos = box.GetOrigin();
636 //
637 // if (vector.DistanceSq(vehPos, depot.GetOwner().GetOrigin()) > distSq || vector.DistanceSq(vehPos, player.GetOrigin()) > 100)
638 // return;
639 //
640 // // Validity check passed, perform action
641 // int finalAmount = Math.Min(suppliesComponent.GetSuppliesMax() - suppliesComponent.GetSupplies(), amount);
642 // suppliesComponent.AddSupplies(finalAmount);
643 // Rpc(RpcDo_PlayerFeedbackValueBase, ECampaignClientNotificationID.SUPPLIES_LOADED, (float)finalAmount, -1);
644 // suppliesComponent.DeleteSupplyLoadingPlayer(playerID);
645  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_LOADING_PLAYER_FINISHED, box, playerID);
646  }
647 
648  //------------------------------------------------------------------------------------------------
653  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
654  protected void RpcAsk_UnloadSupplies(RplId suppliesID, int playerID, RplId baseID, int amount)
655  {
656  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(Replication.FindItem(suppliesID));
657 
658  if (!suppliesComponent)
659  return;
660 
661  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
662 
663  if (!base)
664  return;
665 
666  IEntity player = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
667 
668  if (!player)
669  return;
670 
671  IEntity box = suppliesComponent.GetOwner();
672 
673  if (!box)
674  return;
675 
676 // if (amount > suppliesComponent.GetSupplies())
677 // return;
678 //
679 // Faction playerFaction = SCR_CampaignReconfigureRelayUserAction.GetPlayerFaction(player);
680 // SCR_CampaignFaction owningFaction = base.GetCampaignFaction();
681 //
682 // if (!playerFaction || playerFaction != owningFaction)
683 // return;
684 //
685 // SCR_CampaignSuppliesComponent baseSuppliesComponent = SCR_CampaignSuppliesComponent.Cast(base.GetOwner().FindComponent(SCR_CampaignSuppliesComponent));
686 // if (!baseSuppliesComponent)
687 // return;
688 //
689 // float distSq = Math.Pow(baseSuppliesComponent.GetOperationalRadius(), 2);
690 // vector vehPos = box.GetOrigin();
691 //
692 // if (vector.DistanceSq(vehPos, player.GetOrigin()) > 100)
693 // return;
694 //
695 // if (vector.DistanceSq(vehPos, base.GetOwner().GetOrigin()) > distSq)
696 // {
697 // SCR_ServicePointComponent service = base.GetServiceByType(SCR_EServicePointType.SUPPLY_DEPOT);
698 // if (!service)
699 // return;
700 //
701 // if (vector.DistanceSq(vehPos, service.GetOwner().GetOrigin()) > distSq)
702 // return;
703 // }
704 //
705 // // Validity check passed, perform action
706 // int suppliesCur = base.GetSupplies();
707 // int suppliesMax = base.GetSuppliesMax();
708 // int suppliesCnt = Math.Min(amount, suppliesMax - suppliesCur);
709 // float rewardMultiplier = suppliesCnt / suppliesComponent.GetSuppliesMax();
710 // suppliesComponent.AddSupplies(-suppliesCnt);
711 // base.AddSupplies(suppliesCnt);
712 // suppliesComponent.SetLastUnloadedAt(base);
713 // Rpc(RpcDo_PlayerFeedbackValueBase, ECampaignClientNotificationID.SUPPLIES_UNLOADED, (float)suppliesCnt, base.GetCallsign());
714 //
715 // SCR_XPHandlerComponent compXP = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
716 //
717 // // Award XP unless the truck was just loaded in this base
718 // // ... or if it was both loaded and unloaded in the previous base
719 // // (handled in suppliesComponent)
720 // if (compXP && suppliesComponent.AwardXP())
721 // compXP.AwardXP(playerID, SCR_EXPRewards.SUPPLIES_DELIVERED, rewardMultiplier);
722 //
723 // SendPlayerMessage(SCR_ERadioMsg.SUPPLIES, base.GetCallsign(), public: false);
724 // suppliesComponent.DeleteSupplyUnloadingPlayer(playerID);
725 
726  SendToVehicleOccupants(ENotification.SUPPLY_TRUCK_UNLOADING_PLAYER_FINISHED, box, playerID);
727  }
728 
729  //------------------------------------------------------------------------------------------------
730  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
731  protected void RpcAsk_CaptureBaseBegin(RplId baseID, int factionIndex, int playerID)
732  {
733  SCR_CampaignFaction faction = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager()).GetCampaignFactionByIndex(factionIndex);
734 
735  if (!faction)
736  return;
737 
738  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
739 
740  if (!base)
741  return;
742 
743  base.BeginCapture(faction, playerID);
744  }
745 
746  //------------------------------------------------------------------------------------------------
747  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
748  protected void RpcAsk_CaptureBaseEnd(RplId baseID)
749  {
750  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
751 
752  if (!base)
753  return;
754 
755  base.EndCapture();
756  }
757 
758  //------------------------------------------------------------------------------------------------
766  void SendPlayerMessage(SCR_ERadioMsg msgType, int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN, int calledID = SCR_CampaignMilitaryBaseComponent.INVALID_PLAYER_INDEX, bool public = true, int param = SCR_CampaignRadioMsg.INVALID_RADIO_MSG_PARAM, bool checkHQReached = false)
767  {
768  SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
769 
770  if (!fManager)
771  return;
772 
773  if (!m_PlayerController)
774  return;
775 
776  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
777 
778  if (!campaign)
779  return;
780 
781  SCR_CallsignManagerComponent callsignManager = SCR_CallsignManagerComponent.Cast(campaign.FindComponent(SCR_CallsignManagerComponent));
782 
783  if (!callsignManager)
784  return;
785 
786  IEntity player = m_PlayerController.GetMainEntity();
787 
788  if (!player)
789  return;
790 
791  int companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller;
792 
793  if (!callsignManager.GetEntityCallsignIndexes(player, companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller))
794  return;
795 
797 
798  if (!gadgetMan)
799  return;
800 
801  IEntity radioEnt = gadgetMan.GetGadgetByType(EGadgetType.RADIO);
802 
803  if (!radioEnt)
804  return;
805 
806  BaseRadioComponent radio = BaseRadioComponent.Cast(radioEnt.FindComponent(BaseRadioComponent));
807 
808  if (!radio || !radio.IsPowered())
809  return;
810 
811  BaseTransceiver transmitter = radio.GetTransceiver(0);
812 
813  if (!transmitter)
814  return;
815 
816  IEntity called = GetGame().GetPlayerManager().GetPlayerControlledEntity(calledID);
817 
818  int factionId = fManager.GetFactionIndex(fManager.GetPlayerFaction(m_PlayerController.GetPlayerId()));
819 
821  msg.SetRadioMsg(msgType);
822  msg.SetFactionId(factionId);
823  msg.SetBaseCallsign(baseCallsign);
824  msg.SetCallerCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller);
825  msg.SetIsPublic(public);
826  msg.SetParam(param);
827  msg.SetPlayerID(m_PlayerController.GetPlayerId());
828  msg.SetEncryptionKey(radio.GetEncryptionKey());
829 
830  int companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled;
831 
832  if (called && callsignManager.GetEntityCallsignIndexes(called, companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled))
833  msg.SetCalledCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled);
834 
835  Rpc(RpcDo_PlayRadioMsg, msgType, factionId, baseCallsign, CompressCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller), CompressCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled), param, msg.GetSeed(), 1.0);
836 
837  if (public)
838  transmitter.BeginTransmission(msg);
839  }
840 
841  //------------------------------------------------------------------------------------------------
843  void SetLastHQRadioMessageTimestamp(WorldTimestamp time)
844  {
846  Replication.BumpMe();
847  }
848 
849  //------------------------------------------------------------------------------------------------
850  protected int CompressCallsign(int company, int platoon, int squad)
851  {
852  return (company * 10000) + (platoon * 100) + squad;
853  }
854 
855  //------------------------------------------------------------------------------------------------
856  protected void DecompressCallsign(int callsign, out int company, out int platoon, out int squad)
857  {
858  company = Math.Floor(callsign * 0.0001);
859  callsign = callsign - (company * 10000);
860 
861  platoon = Math.Floor(callsign * 0.01);
862  callsign = callsign - (platoon * 100);
863 
864  squad = callsign;
865  }
866 
867  //------------------------------------------------------------------------------------------------
872  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
873  protected void RpcAsk_CaptureBase(RplId baseID, int factionIndex, int playerID)
874  {
875  SCR_CampaignFaction faction = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager()).GetCampaignFactionByIndex(factionIndex);
876 
877  if (!faction)
878  return;
879 
880  SCR_CampaignMilitaryBaseComponent base = SCR_CampaignMilitaryBaseComponent.Cast(Replication.FindItem(baseID));
881 
882  if (!base)
883  return;
884 
885  if (base.BeginCapture(faction, playerID))
886  base.SetFaction(faction);
887 
888  if (base.GetType() == SCR_ECampaignBaseType.RELAY && playerID != SCR_CampaignMilitaryBaseComponent.INVALID_PLAYER_INDEX)
890  }
891 
892  //------------------------------------------------------------------------------------------------
895  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
896  protected void RpcDo_PlayerFeedback(int msgID)
897  {
898  PlayerFeedbackImpl(msgID);
899  }
900 
901  //------------------------------------------------------------------------------------------------
906  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
907  protected void RpcDo_PlayerFeedbackValueBase(int msgID, float value, int baseID)
908  {
909  // Short delay so replicated values have time to catch up on client's machine
910  GetGame().GetCallqueue().CallLater(PlayerFeedbackImpl, SCR_GameModeCampaign.MINIMUM_DELAY, false, msgID, value, -1, baseID);
911  }
912 
913  //------------------------------------------------------------------------------------------------
917  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
918  protected void RpcDo_PlayerFeedbackBase(int msgID, int baseID)
919  {
920  PlayerFeedbackImpl(msgID, 0, -1, baseID);
921  }
922 
923  //------------------------------------------------------------------------------------------------
929  protected void PlayerFeedbackImpl(int msgID, float value = 0, int assetID = -1, int baseID = -1)
930  {
931  LocalizedString msg;
932  LocalizedString msg2;
933  int duration = 2;
934  int prio = -1;
935  string msg1param1;
936  string msg2param1;
937  string msg2param2;
938  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
939  SCR_CampaignMilitaryBaseComponent base = campaign.GetBaseManager().FindBaseByCallsign(baseID);
940  SCR_CampaignFeedbackComponent manager = SCR_CampaignFeedbackComponent.GetInstance();
941 
942  if (!campaign)
943  return;
944 
945  switch (msgID)
946  {
947  case ECampaignClientNotificationID.SUPPLIES_LOADED:
948  {
949  msg = "#AR-Campaign_SuppliesLoaded-UC";
950  duration = 6;
951  prio = SCR_ECampaignPopupPriority.SUPPLIES_HANDLED;
952  msg1param1 = value.ToString();
953 
954  if (base)
955  {
956  msg2 = "#AR-Campaign_SuppliesAmountInfo-UC";
957  msg2param1 = base.GetBaseName();
958  msg2param2 = base.GetSupplies().ToString();
959  }
960 
961  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_LOADSUPPLIES);
962  break;
963  }
964 
965  case ECampaignClientNotificationID.SUPPLIES_UNLOADED:
966  {
967  msg = "#AR-Campaign_SuppliesUnloaded-UC";
968  duration = 6;
969  prio = SCR_ECampaignPopupPriority.SUPPLIES_HANDLED;
970  msg1param1 = value.ToString();
971 
972  if (base)
973  {
974  msg2 = "#AR-Campaign_SuppliesAmountInfo-UC";
975  msg2param1 = base.GetBaseName();
976  msg2param2 = base.GetSupplies().ToString();
977  }
978 
979  if (!campaign.IsTutorial())
980  {
981  if (manager)
982  manager.ShowHint(EHint.CONFLICT_BUILDING);
983  }
984 
985  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_UNLOADSUPPLIES);
986  break;
987  }
988 
989  case ECampaignClientNotificationID.RESPAWN:
990  {
991  //manager.SetIsPlayerInRadioRange(true);
992  if (manager)
993  manager.OnRespawn();
994 
995  if (!base)
996  return;
997 
998  msg = base.GetBaseNameUpperCase();
999  ChimeraWorld world = m_PlayerController.GetWorld();
1000  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
1001 
1002  if (timeManager)
1003  {
1004  int hours;
1005  int minutes;
1006  int seconds;
1007  timeManager.GetHoursMinutesSeconds(hours, minutes, seconds);
1008  string strHours = hours.ToString();
1009 
1010  if (hours > 0 && hours < 10)
1011  strHours = "0" + strHours;
1012 
1013  string strMinutes = minutes.ToString();
1014 
1015  if (minutes < 10)
1016  strMinutes = "0" + strMinutes;
1017 
1018  msg = string.Format("%1, %2:%3", msg, strHours, strMinutes);
1019  }
1020 
1021  msg2 = SCR_BaseTask.TASK_HINT_TEXT;
1022  msg2param1 = SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT;
1023  duration = 5;
1024  prio = SCR_ECampaignPopupPriority.RESPAWN;
1025 
1026  if (m_bFirstSpawn)
1027  {
1028  m_bFirstSpawn = false;
1029  duration = 120;
1030  }
1031 
1032  break;
1033  };
1034 
1035  default:
1036  {
1037  return;
1038  };
1039  }
1040 
1041  SCR_PopUpNotification.GetInstance().PopupMsg(msg, duration, msg2, param1: msg1param1, text2param1: msg2param1, text2param2: msg2param2);
1042  }
1043 
1044  //------------------------------------------------------------------------------------------------
1047  void SendVehicleSpawnHint(int hintID)
1048  {
1049  Rpc(RpcDo_VehicleSpawnHint, hintID);
1050  }
1051 
1052  //------------------------------------------------------------------------------------------------
1053  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1054  protected void RpcDo_VehicleSpawnHint(int hintID)
1055  {
1056  SCR_CampaignFeedbackComponent feedbackComponent = SCR_CampaignFeedbackComponent.GetInstance();
1057 
1058  if (!feedbackComponent)
1059  return;
1060 
1061  feedbackComponent.ShowHint(hintID);
1062  }
1063 
1064  //------------------------------------------------------------------------------------------------
1067  void RespawnLocationPopup(int baseID)
1068  {
1069  Rpc(RpcDo_PlayerFeedbackBase, ECampaignClientNotificationID.RESPAWN, baseID);
1070  }
1071 
1072  //------------------------------------------------------------------------------------------------
1074  void OnPlayerAliveStateChanged(bool alive)
1075  {
1077  SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.Cast(GetOwner().FindComponent(SCR_CampaignFeedbackComponent));
1078 
1079  if (!comp)
1080  return;
1081 
1082  IEntity player = m_PlayerController.GetControlledEntity();
1083 
1084  if (!player)
1085  return;
1086 
1087  EventHandlerManagerComponent eventHandlerManagerComponent = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
1088 
1089  if (!eventHandlerManagerComponent)
1090  return;
1091 
1092  if (alive)
1093  {
1094  comp.OnConsciousnessChanged(true);
1095  eventHandlerManagerComponent.RegisterScriptHandler("OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
1096  }
1097  else
1098  {
1099  eventHandlerManagerComponent.RemoveScriptHandler("OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
1100  }
1101  }
1102 
1103  //------------------------------------------------------------------------------------------------
1106  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1108  {
1109  // Adds function to queue. Sometimes, game is not fast enough to spawn player entity
1110  SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
1111  GetGame().GetCallqueue().CallLater(comp.EnablePlayerSpawnHint, 100, true, enable);
1112 
1113  if (!enable)
1114  comp.PauseHintQueue();
1115  }
1116 
1117  //------------------------------------------------------------------------------------------------
1118  protected void HandleRadioRespawnTimer(RplId spawnPointId)
1119  {
1120  SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(SCR_SpawnPoint.GetSpawnPointByRplId(spawnPointId));
1121 
1122  if (!spawnpoint)
1123  return;
1124 
1125  Rpc(RpcAsk_HandleRadioRespawnTimer, spawnPointId);
1126  }
1127 
1128  //------------------------------------------------------------------------------------------------
1129  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
1130  protected void RpcAsk_HandleRadioRespawnTimer(RplId selectedSpawnPointId)
1131  {
1132  if (!m_PlayerController)
1133  return;
1134 
1135  SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(SCR_SpawnPoint.GetSpawnPointByRplId(selectedSpawnPointId));
1136 
1137  if (!spawnpoint)
1138  return;
1139 
1140  IEntity operator = GetGame().GetPlayerManager().GetPlayerControlledEntity(spawnpoint.GetPlayerID());
1141 
1142  if (!operator)
1143  return;
1144 
1145  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
1146 
1147  if (!campaign)
1148  return;
1149 
1150  SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
1151 
1152  if (!fManager)
1153  return;
1154 
1155  SCR_TimedSpawnPointComponent timer = SCR_TimedSpawnPointComponent.Cast(campaign.FindComponent(SCR_TimedSpawnPointComponent));
1156 
1157  if (!timer)
1158  return;
1159 
1160  int playerId = m_PlayerController.GetPlayerId();
1161  float suicidePenalty;
1162 
1163  SCR_CampaignClientData data = campaign.GetClientData(playerId);
1164 
1165  if (data)
1166  suicidePenalty = data.GetRespawnPenalty();
1167 
1168  timer.SetRespawnTime(playerId, fManager.GetRankRadioRespawnCooldown(SCR_CharacterRankComponent.GetCharacterRank(operator)) + suicidePenalty);
1169  }
1170 
1171  //------------------------------------------------------------------------------------------------
1187  void PlayRadioMsg(SCR_ERadioMsg msg, int FactionId, int baseCallsign, int callerCallsignCompany, int callerCallsignPlatoon, int callerCallsignSquad, int calledCallsignCompany, int calledCallsignPlatoon, int calledCallsignSquad, bool isPublic, int param, float seed, float quality, int playerID)
1188  {
1189  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
1190 
1191  if (!campaign)
1192  return;
1193 
1194  SCR_CallsignManagerComponent callsignManager = SCR_CallsignManagerComponent.Cast(campaign.FindComponent(SCR_CallsignManagerComponent));
1195 
1196  if (!callsignManager)
1197  return;
1198 
1199  int playerCallsignCompany, playerCallsignPlatoon, playerCallsignSquad, playerCallsignCharacter;
1200  callsignManager.GetEntityCallsignIndexes(m_PlayerController.GetMainEntity(), playerCallsignCompany, playerCallsignPlatoon, playerCallsignSquad, playerCallsignCharacter);
1201 
1202  if (isPublic || playerID == m_PlayerController.GetPlayerId())
1203  Rpc(RpcDo_PlayRadioMsg, msg, FactionId, baseCallsign, CompressCallsign(callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad), CompressCallsign(calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad), param, seed, quality);
1204  }
1205 
1206  //------------------------------------------------------------------------------------------------
1216  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1217  void RpcDo_PlayRadioMsg(SCR_ERadioMsg msg, int factionId, int baseCallsign, int callerCallsign, int calledCallsign, int param, float seed, float quality)
1218  {
1219  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
1220 
1221  int callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad;
1222  DecompressCallsign(callerCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad);
1223  DecompressCallsign(calledCallsign, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad);
1224 
1225  SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
1226 
1227  if (!comp)
1228  return;
1229 
1230  comp.PlayRadioMsg(msg, factionId, baseCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, param, seed, quality);
1231 
1232 // if (checkHQReached)
1233 // GetGame().GetCallqueue().CallLater(CheckHQReached, 7000)
1234  }
1235 
1236  //------------------------------------------------------------------------------------------------
1239  {
1240 // ChimeraWorld world = GetOwner().GetWorld();
1241 // if (m_fLastHQRadioMessageTimestamp.PlusMilliseconds(8000).Less(world.GetServerTimestamp()))
1242 // return;
1243  }
1244 
1245  //------------------------------------------------------------------------------------------------
1252  void OnPlayerSuppliesInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
1253  {
1254  if (!playerController || !resourceComponentFrom || !resourceComponentTo)
1255  return;
1256 
1257  vector pos = resourceComponentFrom.GetOwner().GetOrigin();
1258 
1259  switch (interactionType)
1260  {
1261  case EResourcePlayerInteractionType.VEHICLE_LOAD:
1262  {
1263  OnSuppliesLoaded(pos, resourceValue);
1264  break;
1265  }
1266 
1267  case EResourcePlayerInteractionType.VEHICLE_UNLOAD:
1268  {
1269  OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId());
1270  break;
1271  }
1272 
1273  case EResourcePlayerInteractionType.INVENTORY_SPLIT:
1274  {
1275  Vehicle vehicleFrom = Vehicle.Cast(SCR_EntityHelper.GetMainParent(resourceComponentFrom.GetOwner(), true));
1276  Vehicle vehicleTo = Vehicle.Cast(SCR_EntityHelper.GetMainParent(resourceComponentTo.GetOwner(), true));
1277 
1278  // Ignore vehicle to vehicle transfers
1279  if (vehicleFrom && vehicleTo)
1280  break;
1281 
1282  if (vehicleFrom)
1283  OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId());
1284  else
1285  OnSuppliesLoaded(pos, resourceValue);
1286 
1287  break;
1288  }
1289  }
1290  }
1291 
1292  //------------------------------------------------------------------------------------------------
1293  protected void OnSuppliesLoaded(vector position, float amount)
1294  {
1296  }
1297 
1298  //------------------------------------------------------------------------------------------------
1299  protected void OnSuppliesUnloaded(vector position, float amount, int playerId)
1300  {
1301  if (m_vLastLoadedAt == vector.Zero || vector.DistanceSqXZ(m_vLastLoadedAt, position) <= SUPPLY_DELIVERY_THRESHOLD_SQ)
1302  return;
1303 
1304  m_iTotalSuppliesDelivered += amount;
1305 
1306  if (s_OnSuppliesDelivered)
1307  s_OnSuppliesDelivered.Invoke(playerId, (int)amount, m_iTotalSuppliesDelivered);
1308 
1309  SCR_XPHandlerComponent compXP = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
1310 
1311  if (compXP)
1312  compXP.AwardXP(playerId, SCR_EXPRewards.SUPPLIES_DELIVERED, amount / FULL_SUPPLY_TRUCK_AMOUNT);
1313  }
1314 
1315  //------------------------------------------------------------------------------------------------
1318  {
1319  m_vLastLoadedAt = vector.Zero;
1320  }
1321 
1322  //------------------------------------------------------------------------------------------------
1323  // Init
1324  override void EOnInit(IEntity owner)
1325  {
1326  m_PlayerController = SCR_PlayerController.Cast(PlayerController.Cast(owner));
1327 
1328  if (!m_PlayerController)
1329  {
1330  Print("SCR_CampaignNetworkComponent must be attached to PlayerController!", LogLevel.ERROR);
1331  return;
1332  }
1333 
1334  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
1335 
1336  if (m_PlayerController.GetPlayerId() == SCR_PlayerController.GetLocalPlayerId())
1337  SCR_SpawnPointRequestUIComponent.SGetOnSpawnPointSelected().Insert(HandleRadioRespawnTimer);
1338 
1339  if (IsProxy())
1340  return;
1341 
1343 
1344  if (comp)
1345  comp.GetOnPlayerInteraction().Insert(OnPlayerSuppliesInteraction);
1346  }
1347 
1348  //------------------------------------------------------------------------------------------------
1349  override void OnPostInit(IEntity owner)
1350  {
1351  super.OnPostInit(owner);
1352  SetEventMask(owner, EntityEvent.INIT);
1353  }
1354 
1355  //------------------------------------------------------------------------------------------------
1356  // destructor
1358  {
1359  SCR_SpawnPointRequestUIComponent.SGetOnSpawnPointSelected().Remove(HandleRadioRespawnTimer);
1360  }
1361 }
SendVehicleSpawnHint
void SendVehicleSpawnHint(int hintID)
Definition: SCR_CampaignNetworkComponent.c:1047
RpcAsk_UnloadSupplies
protected void RpcAsk_UnloadSupplies(RplId suppliesID, int playerID, RplId baseID, int amount)
Definition: SCR_CampaignNetworkComponent.c:654
ChimeraWorld
Definition: ChimeraWorld.c:12
RpcAsk_HandleRadioRespawnTimer
protected void RpcAsk_HandleRadioRespawnTimer(RplId selectedSpawnPointId)
Definition: SCR_CampaignNetworkComponent.c:1130
RpcDo_PlayerFeedbackBase
protected void RpcDo_PlayerFeedbackBase(int msgID, int baseID)
Definition: SCR_CampaignNetworkComponent.c:918
RpcDo_PlayerFeedback
protected void RpcDo_PlayerFeedback(int msgID)
Definition: SCR_CampaignNetworkComponent.c:896
AddRadio
void AddRadio()
Definition: SCR_CampaignNetworkComponent.c:193
RpcDo_PlayRadioMsg
void RpcDo_PlayRadioMsg(SCR_ERadioMsg msg, int factionId, int baseCallsign, int callerCallsign, int calledCallsign, int param, float seed, float quality)
Definition: SCR_CampaignNetworkComponent.c:1217
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
~SCR_CampaignNetworkComponent
void ~SCR_CampaignNetworkComponent()
Definition: SCR_CampaignNetworkComponent.c:1357
RESPAWN
@ RESPAWN
Definition: SCR_CampaignFeedbackComponent.c:1430
ScriptInvokerInt3
ScriptInvokerBase< ScriptInvokerInt3Method > ScriptInvokerInt3
Definition: SCR_ScriptInvokerHelper.c:26
RpcAsk_SuppliesLoadingStarted
protected void RpcAsk_SuppliesLoadingStarted(RplId suppliesID, int playerID, int supplies, bool IsUnloading)
Definition: SCR_CampaignNetworkComponent.c:484
RpcDo_PlayerEnableShowingSpawnPosition
void RpcDo_PlayerEnableShowingSpawnPosition(bool enable)
Definition: SCR_CampaignNetworkComponent.c:1107
SCR_SpawnPointRequestUIComponent
Definition: SCR_SpawnPointRequestUIComponent.c:1
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
RespawnLocationPopup
void RespawnLocationPopup(int baseID)
Definition: SCR_CampaignNetworkComponent.c:1067
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
StopLoading
void StopLoading(RplId suppliesID, bool IsUnloading=false)
Definition: SCR_CampaignNetworkComponent.c:166
NO_SPACE
SCR_CampaignNetworkComponentClass NO_SPACE
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
RpcAsk_CaptureBaseBegin
protected void RpcAsk_CaptureBaseBegin(RplId baseID, int factionIndex, int playerID)
Definition: SCR_CampaignNetworkComponent.c:731
GetLastRequestTimestamp
WorldTimestamp GetLastRequestTimestamp()
Definition: SCR_CampaignNetworkComponent.c:69
SCR_CampaignClientData
Used for storing client data to be reapplied for reconnecting clients.
Definition: SCR_CampaignClientData.c:3
OnPlayerSuppliesInteraction
void OnPlayerSuppliesInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
Definition: SCR_CampaignNetworkComponent.c:1252
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
SetLastHQRadioMessageTimestamp
void SetLastHQRadioMessageTimestamp(WorldTimestamp time)
Definition: SCR_CampaignNetworkComponent.c:843
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
m_bFirstSpawn
protected bool m_bFirstSpawn
Definition: SCR_CampaignNetworkComponent.c:24
VEHICLE_SPAWNED
SCR_CampaignNetworkComponentClass VEHICLE_SPAWNED
Used to identify various notifications for client.
SCR_ERadioMsg
SCR_ERadioMsg
Definition: SCR_CampaignRadioMsg.c:138
SCR_WorldTools
Definition: SCR_WorldTools.c:1
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
CompressCallsign
protected int CompressCallsign(int company, int platoon, int squad)
Definition: SCR_CampaignNetworkComponent.c:850
RpcAsk_AddSuppliesFromContextMenu
protected void RpcAsk_AddSuppliesFromContextMenu(RplId baseID, int suppliesCnt)
Definition: SCR_CampaignNetworkComponent.c:433
SCR_CharacterRankComponent
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CharacterRankComponent.c:209
SUPPLIES_LOADED
SCR_CampaignNetworkComponentClass SUPPLIES_LOADED
m_iTotalSuppliesDelivered
protected int m_iTotalSuppliesDelivered
Definition: SCR_CampaignNetworkComponent.c:31
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_CampaignSuppliesComponent
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CampaignSuppliesComponent.c:327
OnSuppliesLoaded
protected void OnSuppliesLoaded(vector position, float amount)
Definition: SCR_CampaignNetworkComponent.c:1293
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
SUPPLIES_UNLOADED
SCR_CampaignNetworkComponentClass SUPPLIES_UNLOADED
ENotification
ENotification
Definition: ENotification.c:4
SCR_CampaignNetworkComponentClass
Definition: SCR_CampaignNetworkComponent.c:3
RpcAsk_CaptureBaseEnd
protected void RpcAsk_CaptureBaseEnd(RplId baseID)
Definition: SCR_CampaignNetworkComponent.c:748
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignNetworkComponent.c:23
DecompressCallsign
protected void DecompressCallsign(int callsign, out int company, out int platoon, out int squad)
Definition: SCR_CampaignNetworkComponent.c:856
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignNetworkComponent.c:97
RpcDo_AddRadio
protected void RpcDo_AddRadio(RplId ID)
Definition: SCR_CampaignNetworkComponent.c:241
SCR_MPDestructionManager
Definition: SCR_MPDestructionManager.c:103
StartLoading
void StartLoading(RplId suppliesID, int supplies, bool IsUnloading=false)
Definition: SCR_CampaignNetworkComponent.c:156
RpcAsk_LoadSupplies
protected void RpcAsk_LoadSupplies(RplId suppliesID, int playerID, RplId baseID, int amount)
Definition: SCR_CampaignNetworkComponent.c:540
SCR_ECampaignPopupPriority
SCR_ECampaignPopupPriority
Popup message priorities sorted from lowest to highest.
Definition: SCR_CampaignFeedbackComponent.c:1419
PlayRadioMsg
void PlayRadioMsg(SCR_ERadioMsg msg, int FactionId, int baseCallsign, int callerCallsignCompany, int callerCallsignPlatoon, int callerCallsignSquad, int calledCallsignCompany, int calledCallsignPlatoon, int calledCallsignSquad, bool isPublic, int param, float seed, float quality, int playerID)
Definition: SCR_CampaignNetworkComponent.c:1187
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CampaignNetworkComponent.c:1349
OnSuppliesUnloaded
protected void OnSuppliesUnloaded(vector position, float amount, int playerId)
Definition: SCR_CampaignNetworkComponent.c:1299
FindRadioDelayed
protected void FindRadioDelayed(RplId ID)
Definition: SCR_CampaignNetworkComponent.c:247
BaseTransceiver
Definition: BaseTransceiver.c:12
CaptureBase
void CaptureBase(SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignNetworkComponent.c:308
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
RpcAsk_CaptureBase
protected void RpcAsk_CaptureBase(RplId baseID, int factionIndex, int playerID)
Definition: SCR_CampaignNetworkComponent.c:873
CaptureBaseGM
void CaptureBaseGM(SCR_CampaignMilitaryBaseComponent base, int factionIndex)
Definition: SCR_CampaignNetworkComponent.c:336
AddSuppliesFromContextMenu
void AddSuppliesFromContextMenu(notnull SCR_CampaignMilitaryBaseComponent base, int suppliesCnt)
Definition: SCR_CampaignNetworkComponent.c:421
SetLastRequestTimestamp
void SetLastRequestTimestamp(WorldTimestamp timestamp)
Definition: SCR_CampaignNetworkComponent.c:76
RepairComposition
void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
Repair destroyed mandatory part of composition.
Definition: SCR_CampaignNetworkComponent.c:104
m_fNoRewardSupplies
protected float m_fNoRewardSupplies
Definition: SCR_CampaignNetworkComponent.c:29
m_fLastHQRadioMessageTimestamp
protected WorldTimestamp m_fLastHQRadioMessageTimestamp
Definition: SCR_CampaignNetworkComponent.c:46
RpcDo_VehicleSpawnHint
protected void RpcDo_VehicleSpawnHint(int hintID)
Definition: SCR_CampaignNetworkComponent.c:1054
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_CampaignNetworkComponent.c:1324
Faction
Definition: Faction.c:12
OnPlayerAliveStateChanged
void OnPlayerAliveStateChanged(bool alive)
Definition: SCR_CampaignNetworkComponent.c:1074
SCR_EXPRewards
SCR_EXPRewards
Definition: SCR_XPHandlerComponent.c:403
ToggleBaseCapture
void ToggleBaseCapture(notnull SCR_CampaignMilitaryBaseComponent base, bool isBeingCaptured)
Definition: SCR_CampaignNetworkComponent.c:348
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
RpcAsk_RepairComposition
protected void RpcAsk_RepairComposition(int index, int repairCost, int destructibleID, RplId slotID, RplId baseID)
Repair damaged entity in composition.
Definition: SCR_CampaignNetworkComponent.c:368
SCR_SiteSlotEntity
Definition: SCR_SiteSlotEntity.c:26
m_vLastLoadedAt
protected vector m_vLastLoadedAt
Definition: SCR_CampaignNetworkComponent.c:26
m_PlayerController
SCR_CampaignNetworkComponentClass m_PlayerController
Takes care of Campaign-specific server <> client communication and requests.
UnloadSupplies
void UnloadSupplies(RplId suppliesID, IEntity player, SCR_CampaignMilitaryBaseComponent base, int amount=0)
Definition: SCR_CampaignNetworkComponent.c:177
RpcDo_PlayerFeedbackValueBase
protected void RpcDo_PlayerFeedbackValueBase(int msgID, float value, int baseID)
Definition: SCR_CampaignNetworkComponent.c:907
PlayerFeedbackImpl
protected void PlayerFeedbackImpl(int msgID, float value=0, int assetID=-1, int baseID=-1)
Definition: SCR_CampaignNetworkComponent.c:929
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
LoadSupplies
void LoadSupplies(RplId suppliesID, IEntity player, SCR_CampaignMilitaryBaseComponent base, int amount=0)
Definition: SCR_CampaignNetworkComponent.c:117
SCR_EMobileAssemblyStatus
SCR_EMobileAssemblyStatus
Definition: SCR_CampaignMobileAssemblyComponent.c:437
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
SCR_CampaignRadioMsg
Definition: SCR_CampaignRadioMsg.c:2
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
ResetSavedSupplies
void ResetSavedSupplies()
Definition: SCR_CampaignNetworkComponent.c:1317
SCR_CallsignManagerComponent
Definition: SCR_CallsignManagerComponent.c:12
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
RpcAsk_SuppliesLoadingCanceled
protected void RpcAsk_SuppliesLoadingCanceled(RplId suppliesID, int playerID, bool IsUnloading)
Definition: SCR_CampaignNetworkComponent.c:510
DeployMobileAsembly
void DeployMobileAsembly(notnull SCR_CampaignMobileAssemblyComponent comp, bool deploy)
Definition: SCR_CampaignNetworkComponent.c:277
m_vLastUnloadedAt
protected vector m_vLastUnloadedAt
Definition: SCR_CampaignNetworkComponent.c:27
EResourcePlayerInteractionType
EResourcePlayerInteractionType
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:1
RpcAsk_DeployMobileAsembly
protected void RpcAsk_DeployMobileAsembly(RplId assemblyComponentID, bool deploy, int playerID)
Definition: SCR_CampaignNetworkComponent.c:284
OUT_OF_STOCK
SCR_CampaignNetworkComponentClass OUT_OF_STOCK
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
LocalizedString
Definition: LocalizedString.c:21
RpcAsk_LoadSuppliesStandalone
protected void RpcAsk_LoadSuppliesStandalone(RplId suppliesID, int playerID, RplId depotID, int amount)
Definition: SCR_CampaignNetworkComponent.c:606
EHint
EHint
Definition: EHint.c:10
PlayerManager
Definition: PlayerManager.c:12
HandleRadioRespawnTimer
protected void HandleRadioRespawnTimer(RplId spawnPointId)
Definition: SCR_CampaignNetworkComponent.c:1118
LoadSuppliesStandalone
void LoadSuppliesStandalone(RplId suppliesID, IEntity player, SCR_CampaignSuppliesComponent depot, int amount=0)
Definition: SCR_CampaignNetworkComponent.c:137
RpcAsk_AddRadio
protected void RpcAsk_AddRadio(int playerID)
Definition: SCR_CampaignNetworkComponent.c:200
CheckHQReached
void CheckHQReached()
Definition: SCR_CampaignNetworkComponent.c:1238
SendPlayerMessage
void SendPlayerMessage(SCR_ERadioMsg msgType, int baseCallsign=SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN, int calledID=SCR_CampaignMilitaryBaseComponent.INVALID_PLAYER_INDEX, bool public=true, int param=SCR_CampaignRadioMsg.INVALID_RADIO_MSG_PARAM, bool checkHQReached=false)
Definition: SCR_CampaignNetworkComponent.c:766
m_fLastAssetRequestTimestamp
protected WorldTimestamp m_fLastAssetRequestTimestamp
Definition: SCR_CampaignNetworkComponent.c:43
SendToVehicleOccupants
protected void SendToVehicleOccupants(ENotification messageID, IEntity vehicleEntity, int playerID, int number=0)
Definition: SCR_CampaignNetworkComponent.c:451
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_CampaignReconfigureRelayUserAction
Action to reconfigure relays in Campaign.
Definition: SCR_CampaignReconfigureRelayUserAction.c:2