Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
6
8enum ECampaignClientNotificationID
9{
16}
17
18//~ Supplies transfer invoker
19void ScriptInvokerTransferSuppliesMethod(EResourcePlayerInteractionType interactionType, notnull SCR_ResourceComponent resourceComponentFrom, notnull SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, PlayerController playerController);
21typedef ScriptInvokerBase<ScriptInvokerTransferSuppliesMethod> ScriptInvokerTransferSupplies;
22
25{
26 // Member variables
28 protected RplComponent m_RplComponent;
29 protected bool m_bFirstSpawn = true;
30
32 protected SCR_ResourceComponent m_LastLoadedComponent;
33 protected float m_fLoadedSupplyAmount;
35
36 protected float m_fNoRewardSupplies;
37
39
42
43 static const int SUPPLY_DELIVERY_XP_PERCENT = 100; // Decimal fraction used in formula to calculate XP reward
44 static const int SUPPLY_DELIVERY_THRESHOLD_SQ = 200 * 200;
45
46 //********************************//
47 //RUNTIME SYNCHED MEMBER VARIABLES//
48 //********************************//
49
50 [RplProp(condition: RplCondition.OwnerOnly)]
52
53 [RplProp(condition: RplCondition.OwnerOnly)]
55
56 //------------------------------------------------------------------------------------------------
60 {
61 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
62
63 if (!playerController)
64 return null;
65
66 SCR_CampaignNetworkComponent networkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
67
68 return networkComponent;
69 }
70
71 //*********************//
72 //PUBLIC MEMBER METHODS//
73 //*********************//
74
75 //------------------------------------------------------------------------------------------------
81
82 //------------------------------------------------------------------------------------------------
83 SCR_ResourceComponent GetLastLoadedComponent()
84 {
86 }
87
88 //------------------------------------------------------------------------------------------------
91 {
92 if (IsProxy())
93 return;
94
96 Replication.BumpMe();
97 }
98
99 //------------------------------------------------------------------------------------------------
108
109 //------------------------------------------------------------------------------------------------
118
119 //------------------------------------------------------------------------------------------------
121 protected bool IsProxy()
122 {
123 return (m_RplComponent && m_RplComponent.IsProxy());
124 }
125
126 //------------------------------------------------------------------------------------------------
128 void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
129 {
130#ifdef ENABLE_BASE_DESTRUCTION
131 Rpc(RpcAsk_RepairComposition, index, repairCost, destructibleID, Replication.FindItemId(slotEnt), Replication.FindItemId(base));
132#endif
133 }
134
135 //***********//
136 //RPC METHODS//
137 //***********//
138
139 //------------------------------------------------------------------------------------------------
141 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
142 protected void RpcAsk_RepairComposition(int index, int repairCost, int destructibleID, RplId slotID, RplId baseID)
143 {
144#ifdef ENABLE_BASE_DESTRUCTION
145 if (index == -1 || repairCost == -1 || destructibleID == -1)
146 return;
147
149 if (!destructionManager)
150 return;
151
152 SCR_DestructionMultiPhaseComponent destructibleComp = SCR_DestructionMultiPhaseComponent.Cast(destructionManager.FindDynamicallySpawnedDestructibleByIndex(destructibleID, index));
153 if (!destructibleComp)
154 return;
155
157 if (!base)
158 return;
159
160 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
161 if (!campaign)
162 return;
163
164 IEntity composition = SCR_EntityHelper.GetMainParent(destructibleComp.GetOwner());
165 if (!composition)
166 return;
167
168 SCR_CampaignServiceEntityComponent serviceEntityComp = SCR_CampaignServiceEntityComponent.Cast(destructibleComp.GetOwner().FindComponent(SCR_CampaignServiceEntityComponent));
169 if (!serviceEntityComp)
170 return;
171
172 SCR_CampaignServiceCompositionComponent serviceCompositionComp = SCR_CampaignServiceCompositionComponent.Cast(composition.FindComponent(SCR_CampaignServiceCompositionComponent));
173 if (!serviceCompositionComp)
174 return;
175
176 // Check if the composition entity belong to is disabled or not. If so, increase number of spawn tickets again.
177// if (!serviceCompositionComp.IsServiceOperable())
178// campaign.OnStructureChanged(base, SCR_SiteSlotEntity.Cast(Replication.FindItem(slotID)), base.GetServiceByLabel(serviceCompositionComp.GetCompositionType()), true);
179
180 // Repair entity
181 serviceEntityComp.RepairEntity();
182
183 // Supply in base are reduced (cost of repair)
184 base.AddSupplies(-repairCost);
185
186 // Update map UI
187 if (RplSession.Mode() != RplMode.Dedicated)
188 base.GetMapDescriptor().HandleMapInfo();
189#endif
190 }
191
192 //------------------------------------------------------------------------------------------------
200 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)
201 {
202 SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
203
204 if (!fManager)
205 return;
206
208 return;
209
210 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
211
212 if (!campaign)
213 return;
214
215 SCR_CallsignManagerComponent callsignManager = SCR_CallsignManagerComponent.Cast(campaign.FindComponent(SCR_CallsignManagerComponent));
216
217 if (!callsignManager)
218 return;
219
220 IEntity player = m_PlayerController.GetMainEntity();
221
222 if (!player)
223 return;
224
225 int companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller;
226
227 if (!callsignManager.GetEntityCallsignIndexes(player, companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller))
228 return;
229
231
232 if (!gadgetMan)
233 return;
234
235 IEntity radioEnt = gadgetMan.GetGadgetByType(EGadgetType.RADIO);
236
237 if (!radioEnt)
238 return;
239
240 BaseRadioComponent radio = BaseRadioComponent.Cast(radioEnt.FindComponent(BaseRadioComponent));
241
242 if (!radio || !radio.IsPowered())
243 return;
244
245 BaseTransceiver transmitter = radio.GetTransceiver(0);
246
247 if (!transmitter)
248 return;
249
250 IEntity called = GetGame().GetPlayerManager().GetPlayerControlledEntity(calledID);
251
252 int factionId = fManager.GetFactionIndex(fManager.GetPlayerFaction(m_PlayerController.GetPlayerId()));
253
255 msg.SetRadioMsg(msgType);
256 msg.SetFactionId(factionId);
257 msg.SetBaseCallsign(baseCallsign);
258 msg.SetCallerCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller);
259 msg.SetIsPublic(public);
260 msg.SetParam(param);
261 msg.SetPlayerID(m_PlayerController.GetPlayerId());
262 msg.SetEncryptionKey(radio.GetEncryptionKey());
263
264 int companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled;
265
266 if (called && callsignManager.GetEntityCallsignIndexes(called, companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled))
267 msg.SetCalledCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled);
268
269 Rpc(RpcDo_PlayRadioMsg, msgType, factionId, baseCallsign, CompressCallsign(companyCallsignIndexCaller, platoonCallsignIndexCaller, squadCallsignIndexCaller, characterCallsignIndexCaller), CompressCallsign(companyCallsignIndexCalled, platoonCallsignIndexCalled, squadCallsignIndexCalled, characterCallsignIndexCalled), param, msg.GetSeed(), 1.0);
270
271 if (public)
272 transmitter.BeginTransmission(msg);
273 }
274
275 //------------------------------------------------------------------------------------------------
282
283 //------------------------------------------------------------------------------------------------
284 protected int CompressCallsign(int company, int platoon, int squad, int character)
285 {
286 return (company * 1000000) + (platoon * 10000) + (squad * 100) + character;
287 }
288
289 //------------------------------------------------------------------------------------------------
290 protected void DecompressCallsign(int callsign, out int company, out int platoon, out int squad, out int character)
291 {
292 company = Math.Floor(callsign * 0.000001);
293 callsign = callsign - (company * 1000000);
294
295 platoon = Math.Floor(callsign * 0.0001);
296 callsign = callsign - (platoon * 10000);
297
298 squad = Math.Floor(callsign * 0.01);
299 callsign = callsign - (squad * 100);
300
301 character = callsign;
302 }
303
304 //------------------------------------------------------------------------------------------------
307 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
308 protected void RpcDo_PlayerFeedback(int msgID)
309 {
310 PlayerFeedbackImpl(msgID);
311 }
312
313 //------------------------------------------------------------------------------------------------
318 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
319 protected void RpcDo_PlayerFeedbackValueBase(int msgID, float value, int baseID)
320 {
321 // Short delay so replicated values have time to catch up on client's machine
322 GetGame().GetCallqueue().CallLater(PlayerFeedbackImpl, SCR_GameModeCampaign.MINIMUM_DELAY, false, msgID, value, -1, baseID);
323 }
324
325 //------------------------------------------------------------------------------------------------
329 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
330 protected void RpcDo_PlayerFeedbackBase(int msgID, int baseID)
331 {
332 PlayerFeedbackImpl(msgID, 0, -1, baseID);
333 }
334
335 //------------------------------------------------------------------------------------------------
341 protected void PlayerFeedbackImpl(int msgID, float value = 0, int assetID = -1, int baseID = -1)
342 {
343 LocalizedString msg;
344 LocalizedString msg2;
345 int duration = 2;
346 int prio = -1;
347 string msg1param1;
348 string msg2param1;
349 string msg2param2;
350 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
351 SCR_CampaignMilitaryBaseComponent base = campaign.GetBaseManager().FindBaseByCallsign(baseID);
352 SCR_CampaignFeedbackComponent manager = SCR_CampaignFeedbackComponent.GetInstance();
353
354 if (!campaign)
355 return;
356
357 switch (msgID)
358 {
359 case ECampaignClientNotificationID.SUPPLIES_LOADED:
360 {
361 msg = "#AR-Campaign_SuppliesLoaded-UC";
362 duration = 6;
363 prio = SCR_ECampaignPopupPriority.SUPPLIES_HANDLED;
364 msg1param1 = value.ToString();
365
366 if (base)
367 {
368 msg2 = "#AR-Campaign_SuppliesAmountInfo-UC";
369 msg2param1 = base.GetBaseName();
370 msg2param2 = base.GetSupplies().ToString();
371 }
372
373 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_LOADSUPPLIES);
374 break;
375 }
376
377 case ECampaignClientNotificationID.SUPPLIES_UNLOADED:
378 {
379 msg = "#AR-Campaign_SuppliesUnloaded-UC";
380 duration = 6;
381 prio = SCR_ECampaignPopupPriority.SUPPLIES_HANDLED;
382 msg1param1 = value.ToString();
383
384 if (base)
385 {
386 msg2 = "#AR-Campaign_SuppliesAmountInfo-UC";
387 msg2param1 = base.GetBaseName();
388 msg2param2 = base.GetSupplies().ToString();
389 }
390
391 if (!campaign.IsTutorial())
392 {
393 if (manager)
394 manager.ShowHint(EHint.CONFLICT_BUILDING);
395 }
396
397 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_UNLOADSUPPLIES);
398 break;
399 }
400
401 case ECampaignClientNotificationID.RESPAWN:
402 {
403 //manager.SetIsPlayerInRadioRange(true);
404 if (manager)
405 manager.OnRespawn();
406
407 if (!base)
408 return;
409
410 msg = base.GetBaseNameUpperCase();
411 ChimeraWorld world = m_PlayerController.GetWorld();
412 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
413
414 if (timeManager)
415 {
416 int hours;
417 int minutes;
418 int seconds;
419 timeManager.GetHoursMinutesSeconds(hours, minutes, seconds);
420 string strHours = hours.ToString();
421
422 if (hours > 0 && hours < 10)
423 strHours = "0" + strHours;
424
425 string strMinutes = minutes.ToString();
426
427 if (minutes < 10)
428 strMinutes = "0" + strMinutes;
429
430 msg = string.Format("%1, %2:%3", msg, strHours, strMinutes);
431 }
432
433 msg2 = SCR_TextsTaskManagerComponent.TASK_HINT_TEXT;
435 duration = 5;
436 prio = SCR_ECampaignPopupPriority.RESPAWN;
437
438 if (m_bFirstSpawn)
439 {
440 m_bFirstSpawn = false;
441 duration = 15;
442 }
443
444 break;
445 };
446
447 default:
448 {
449 return;
450 };
451 }
452
453 SCR_PopUpNotification.GetInstance().PopupMsg(msg, duration, msg2, param1: msg1param1, text2param1: msg2param1, text2param2: msg2param2);
454 }
455
456 //------------------------------------------------------------------------------------------------
459 void SendVehicleSpawnHint(int hintID)
460 {
462 }
463
464 //------------------------------------------------------------------------------------------------
465 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
466 protected void RpcDo_VehicleSpawnHint(int hintID)
467 {
468 SCR_CampaignFeedbackComponent feedbackComponent = SCR_CampaignFeedbackComponent.GetInstance();
469
470 if (!feedbackComponent)
471 return;
472
473 feedbackComponent.ShowHint(hintID);
474 }
475
476 //------------------------------------------------------------------------------------------------
479 void RespawnLocationPopup(int baseID)
480 {
481 Rpc(RpcDo_PlayerFeedbackBase, ECampaignClientNotificationID.RESPAWN, baseID);
482 }
483
484 //------------------------------------------------------------------------------------------------
487 {
488 IEntity player = m_PlayerController.GetControlledEntity();
489 if (alive && player)
490 {
491 Rpc(RpcDo_UpdatePlayerSpawnHint, alive, player.GetOrigin());
492 }
493 else
494 {
496 }
497
498 if (!player)
499 return;
500
501 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.Cast(GetOwner().FindComponent(SCR_CampaignFeedbackComponent));
502 if (!comp)
503 return;
504
505 EventHandlerManagerComponent eventHandlerManagerComponent = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
506 if (!eventHandlerManagerComponent)
507 return;
508
509 if (alive)
510 {
511 comp.OnConsciousnessChanged(true);
512 eventHandlerManagerComponent.RegisterScriptHandler("OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
513 }
514 else
515 {
516 eventHandlerManagerComponent.RemoveScriptHandler("OnConsciousnessChanged", comp, comp.OnConsciousnessChanged);
517 }
518 }
519
520 //------------------------------------------------------------------------------------------------
521 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
522 protected void RpcDo_UpdatePlayerSpawnHint(bool show, vector position)
523 {
524 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
525 comp.UpdatePlayerSpawnHint(show, position);
526 }
527
528 //------------------------------------------------------------------------------------------------
529 protected void HandleRadioRespawnTimer(RplId spawnPointId)
530 {
531 SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(SCR_SpawnPoint.GetSpawnPointByRplId(spawnPointId));
532
533 if (!spawnpoint)
534 return;
535
536 Rpc(RpcAsk_HandleRadioRespawnTimer, spawnPointId);
537 }
538
539 //------------------------------------------------------------------------------------------------
540 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
541 protected void RpcAsk_HandleRadioRespawnTimer(RplId selectedSpawnPointId)
542 {
544 return;
545
546 SCR_PlayerRadioSpawnPointCampaign spawnpoint = SCR_PlayerRadioSpawnPointCampaign.Cast(SCR_SpawnPoint.GetSpawnPointByRplId(selectedSpawnPointId));
547
548 if (!spawnpoint)
549 return;
550
551 IEntity operator = GetGame().GetPlayerManager().GetPlayerControlledEntity(spawnpoint.GetPlayerID());
552
553 if (!operator)
554 return;
555
556 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
557
558 if (!campaign)
559 return;
560
561 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
562
563 if (!fManager)
564 return;
565
566 SCR_TimedSpawnPointComponent timer = SCR_TimedSpawnPointComponent.Cast(campaign.FindComponent(SCR_TimedSpawnPointComponent));
567
568 if (!timer)
569 return;
570
571 int playerId = m_PlayerController.GetPlayerId();
572 float suicidePenalty;
573
574 SCR_CampaignClientData data = campaign.GetClientData(playerId);
575 if (data)
576 suicidePenalty = data.GetRespawnPenalty();
577
578 timer.SetRespawnTime(playerId, fManager.GetRankRadioRespawnCooldown(SCR_CharacterRankComponent.GetCharacterRank(operator), playerId) + suicidePenalty);
579 }
580
581 //------------------------------------------------------------------------------------------------
592 void PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality, int playerID)
593 {
594 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
595 if (!campaign)
596 return;
597
598 if (playerID == 0 || playerID > 0 && playerID == m_PlayerController.GetPlayerId())
599 Rpc(RpcDo_PlayTaskNotificationMsg, taskNotification, msg, factionId, baseCallsign, callerGroupId, calledGroupId, grid, quality);
600 }
601
602 //------------------------------------------------------------------------------------------------
603 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
604 protected void RpcDo_PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality)
605 {
607 if (!taskNotificationManager)
608 return;
609
610 taskNotificationManager.PlayTaskNotificationMsg(taskNotification, msg, factionId, baseCallsign, callerGroupId, calledGroupId, grid, quality);
611 }
612
613 //------------------------------------------------------------------------------------------------
631 void PlayRadioMsg(SCR_ERadioMsg msg, int FactionId, int baseCallsign, int callerCallsignCompany, int callerCallsignPlatoon, int callerCallsignSquad, int callerCallsignCharacter, int calledCallsignCompany, int calledCallsignPlatoon, int calledCallsignSquad, int calledCallsignCharacter, bool isPublic, int param, float seed, float quality, int playerID)
632 {
633 if (isPublic || playerID == m_PlayerController.GetPlayerId())
634 Rpc(RpcDo_PlayRadioMsg, msg, FactionId, baseCallsign, CompressCallsign(callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter), CompressCallsign(calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter), param, seed, quality);
635 }
636
637 //------------------------------------------------------------------------------------------------
647 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
648 protected void RpcDo_PlayRadioMsg(SCR_ERadioMsg msg, int factionId, int baseCallsign, int callerCallsign, int calledCallsign, int param, float seed, float quality)
649 {
650 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
651
652 int callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter;
653 DecompressCallsign(callerCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter);
654 DecompressCallsign(calledCallsign, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter);
655
656 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
657
658 if (!comp)
659 return;
660
661 comp.PlayRadioMsg(msg, factionId, baseCallsign, callerCallsignCompany, callerCallsignPlatoon, callerCallsignSquad, callerCallsignCharacter, calledCallsignCompany, calledCallsignPlatoon, calledCallsignSquad, calledCallsignCharacter, param, seed, quality);
662 }
663
664 //------------------------------------------------------------------------------------------------
666 protected void OnBeforePlayerInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
667 {
669 SCR_ResourceConsumer consumer = resourceComponentFrom.GetConsumer(EResourceGeneratorID.VEHICLE_LOAD, resourceType);
670
671 if (!consumer && !resourceComponentFrom.GetConsumer(EResourceGeneratorID.DEFAULT, resourceType, consumer))
672 return;
673
674 SCR_ResourceContainerQueue containerQueue = SCR_ResourceContainerQueue.Cast(consumer.GetContainerQueue());
675
676 if (containerQueue.GetStorageTypeCount(EResourceContainerStorageType.STORED) == 0)
678 }
679
680 //------------------------------------------------------------------------------------------------
687 protected void OnPlayerSuppliesInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
688 {
689 if (!playerController || !resourceComponentFrom || !resourceComponentTo)
690 return;
691
692 GetOnTransferSupplies().Invoke(interactionType, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue, playerController);
693
694 vector pos = resourceComponentFrom.GetOwner().GetOrigin();
695
696 switch (interactionType)
697 {
698 case EResourcePlayerInteractionType.VEHICLE_LOAD:
699 {
700 OnSuppliesLoaded(pos, resourceValue, resourceComponentTo);
701 break;
702 }
703
704 case EResourcePlayerInteractionType.VEHICLE_UNLOAD:
705 {
706 OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId(), resourceComponentFrom);
707 break;
708 }
709
710 case EResourcePlayerInteractionType.INVENTORY_SPLIT:
711 {
712 Vehicle vehicleFrom = Vehicle.Cast(SCR_EntityHelper.GetMainParent(resourceComponentFrom.GetOwner(), true));
713 Vehicle vehicleTo = Vehicle.Cast(SCR_EntityHelper.GetMainParent(resourceComponentTo.GetOwner(), true));
714
715 // Ignore vehicle to vehicle transfers
716 if (vehicleFrom && vehicleTo)
717 break;
718
719 if (vehicleFrom)
720 OnSuppliesUnloaded(pos, resourceValue, playerController.GetPlayerId(), resourceComponentFrom);
721 else
722 OnSuppliesLoaded(pos, resourceValue, resourceComponentTo);
723
724 break;
725 }
726 }
727 }
728
729 //------------------------------------------------------------------------------------------------
730 protected void OnSuppliesLoaded(vector position, float amount, notnull SCR_ResourceComponent resourceComponentTo)
731 {
732 // Allow XP for orphan supplies only when loaded in a base or supply depot
734 {
735 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
736
737 if (campaign)
738 {
739 SCR_CampaignMilitaryBaseManager manager = campaign.GetBaseManager();
740
741 if (manager)
742 {
744
745 if (!nearestBase || !nearestBase.IsInitialized() || vector.DistanceXZ(position, nearestBase.GetOwner().GetOrigin()) > nearestBase.GetRadius())
746 {
748
749 if (!nearestDepot || vector.DistanceXZ(position, nearestDepot.GetOwner().GetOrigin()) > 100)
750 {
752 return;
753 }
754 }
755 }
756 }
757 }
758
760 SCR_ResourceContainer containerTo = resourceComponentTo.GetContainer(EResourceType.SUPPLIES);
761
762 if (!containerTo)
763 {
765 return;
766 }
767
770 m_LastLoadedComponent = resourceComponentTo;
771 }
772
773 //------------------------------------------------------------------------------------------------
774 protected void OnSuppliesUnloaded(vector position, float amount, int playerId, notnull SCR_ResourceComponent resourceComponentFrom, int assistantId = 0)
775 {
776 // Identify the player who actually loaded the supplies
777 if (resourceComponentFrom != m_LastLoadedComponent)
778 {
779 array<int> allPlayerIds = {};
780 PlayerManager pManager = GetGame().GetPlayerManager();
781 pManager.GetPlayers(allPlayerIds);
782 PlayerController loaderController;
783 SCR_CampaignNetworkComponent networkComponent;
784
785 foreach (int loaderId : allPlayerIds)
786 {
787 loaderController = pManager.GetPlayerController(loaderId);
788
789 if (!loaderController)
790 continue;
791
792 networkComponent = SCR_CampaignNetworkComponent.Cast(loaderController.FindComponent(SCR_CampaignNetworkComponent));
793
794 if (!networkComponent)
795 continue;
796
797 if (networkComponent.GetLastLoadedComponent() == resourceComponentFrom)
798 {
799 networkComponent.OnSuppliesUnloaded(position, amount, loaderId, resourceComponentFrom, playerId);
800 return;
801 }
802 }
803
804 return;
805 }
806
808 return;
809
810 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
811
812 if (!campaign)
813 return;
814
815 SCR_CampaignMilitaryBaseManager manager = campaign.GetBaseManager();
816
817 if (!manager)
818 return;
819
821
822 // Only award XP if supplies were unloaded in a base
823 if (!nearestBase || !nearestBase.IsInitialized() || vector.DistanceXZ(position, nearestBase.GetOwner().GetOrigin()) > nearestBase.GetRadius())
824 return;
825
826 m_fLoadedSupplyAmount -= amount;
828
830 s_OnSuppliesDelivered.Invoke(playerId, (int)amount, m_iTotalSuppliesDelivered);
831
832 SCR_XPHandlerComponent compXP = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
833 if (compXP)
834 {
835 float suppliesXPmultiplier = amount / SUPPLY_DELIVERY_XP_PERCENT;
836 compXP.AwardXP(playerId, SCR_EXPRewards.SUPPLIES_DELIVERED, suppliesXPmultiplier);
837
838 if (assistantId > 0)
839 compXP.AwardXP(assistantId, SCR_EXPRewards.SUPPLIES_DELIVERED, suppliesXPmultiplier * campaign.GetSupplyOffloadAssistanceReward());
840 }
841 }
842
843 //------------------------------------------------------------------------------------------------
846 {
847 m_vLastLoadedAt = vector.Zero;
850 }
851
852 //------------------------------------------------------------------------------------------------
853 // Init
854 override protected void EOnInit(IEntity owner)
855 {
856 m_PlayerController = SCR_PlayerController.Cast(PlayerController.Cast(owner));
857
859 {
860 Print("SCR_CampaignNetworkComponent must be attached to PlayerController!", LogLevel.ERROR);
861 return;
862 }
863
864 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
865
868
869 if (IsProxy())
870 return;
871
873
874 if (comp)
875 {
878 }
879 }
880
881 //------------------------------------------------------------------------------------------------
882 override protected void OnPostInit(IEntity owner)
883 {
884 super.OnPostInit(owner);
885 SetEventMask(owner, EntityEvent.INIT);
886 }
887
888 //------------------------------------------------------------------------------------------------
889 // destructor
894}
EHint
Definition EHint.c:11
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_ECampaignPopupPriority
Popup message priorities sorted from lowest to highest.
func ScriptInvokerTransferSuppliesMethod
SCR_CampaignNetworkComponentClass VEHICLE_SPAWNED
Used to identify various notifications for client.
SCR_CampaignNetworkComponentClass NO_SPACE
SCR_CampaignNetworkComponentClass SUPPLIES_LOADED
SCR_CampaignNetworkComponentClass OUT_OF_STOCK
SCR_CampaignNetworkComponentClass SUPPLIES_UNLOADED
ScriptInvokerBase< ScriptInvokerTransferSuppliesMethod > ScriptInvokerTransferSupplies
void SCR_CampaignSuppliesComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_ETaskNotification
Objective and request notifications types.
SCR_ETaskNotificationMsg
Various types of task notifications for different events and states.
Get all prefabs that have the spawner data
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
EResourceContainerStorageType
EResourceGeneratorID
ScriptInvokerBase< ScriptInvokerInt3Method > ScriptInvokerInt3
void SCR_TaskNotificationManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_TextsTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
bool GetEntityCallsignIndexes(IEntity entity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
Used for storing client data to be reapplied for reconnecting clients.
SCR_CampaignMilitaryBaseComponent FindClosestBase(vector position, SCR_ECampaignBaseType searchedType=-1)
SCR_CampaignSuppliesComponent FindClosestSupplyDepot(vector position)
Takes care of Campaign-specific server <> client communication and requests.
void SetLastRequestTimestamp(WorldTimestamp timestamp)
void RpcAsk_RepairComposition(int index, int repairCost, int destructibleID, RplId slotID, RplId baseID)
Repair damaged entity in composition.
void RpcDo_PlayerFeedbackValueBase(int msgID, float value, int baseID)
void OnSuppliesUnloaded(vector position, float amount, int playerId, notnull SCR_ResourceComponent resourceComponentFrom, int assistantId=0)
static SCR_CampaignNetworkComponent GetCampaignNetworkComponent(int playerID)
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)
void HandleRadioRespawnTimer(RplId spawnPointId)
void DecompressCallsign(int callsign, out int company, out int platoon, out int squad, out int character)
SCR_ResourceComponent GetLastLoadedComponent()
static ScriptInvokerTransferSupplies GetOnTransferSupplies()
void RpcDo_UpdatePlayerSpawnHint(bool show, vector position)
void RpcAsk_HandleRadioRespawnTimer(RplId selectedSpawnPointId)
void SetLastHQRadioMessageTimestamp(WorldTimestamp time)
void PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality, int playerID)
static ref ScriptInvokerInt3 s_OnSuppliesDelivered
void OnPlayerSuppliesInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
static ScriptInvokerInt3 GetOnSuppliesDelivered()
void RpcDo_PlayTaskNotificationMsg(SCR_ETaskNotification taskNotification, SCR_ETaskNotificationMsg msg, int factionId, int baseCallsign, int callerGroupId, int calledGroupId, int grid, float quality)
void RpcDo_PlayRadioMsg(SCR_ERadioMsg msg, int factionId, int baseCallsign, int callerCallsign, int calledCallsign, int param, float seed, float quality)
void RepairComposition(int index, int repairCost, int destructibleID, SCR_SiteSlotEntity slotEnt, notnull SCR_CampaignMilitaryBaseComponent base)
Repair destroyed mandatory part of composition.
void OnSuppliesLoaded(vector position, float amount, notnull SCR_ResourceComponent resourceComponentTo)
void RpcDo_PlayerFeedbackBase(int msgID, int baseID)
int CompressCallsign(int company, int platoon, int squad, int character)
static ref ScriptInvokerTransferSupplies s_OnSuppliesTransferred
void PlayerFeedbackImpl(int msgID, float value=0, int assetID=-1, int baseID=-1)
void OnBeforePlayerInteraction(EResourcePlayerInteractionType interactionType, PlayerController playerController, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
Callback.
void PlayRadioMsg(SCR_ERadioMsg msg, int FactionId, int baseCallsign, int callerCallsignCompany, int callerCallsignPlatoon, int callerCallsignSquad, int callerCallsignCharacter, int calledCallsignCompany, int calledCallsignPlatoon, int calledCallsignSquad, int calledCallsignCharacter, bool isPublic, int param, float seed, float quality, int playerID)
void SetRadioMsg(SCR_ERadioMsg msg)
void SetCallerCallsign(int companyID, int platoonID, int squadID, int characterID)
void SetFactionId(int factionId)
void SetCalledCallsign(int companyID, int platoonID, int squadID, int characterID)
void SetIsPublic(bool public)
void SetPlayerID(int playerID)
void SetBaseCallsign(int callsign)
static IEntity GetMainParent(IEntity entity, bool self=false)
IEntity GetGadgetByType(EGadgetType type)
SCR_DestructionDamageManagerComponent FindDynamicallySpawnedDestructibleByIndex(RplId rplId, int index)
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
Takes care of dynamic and static onscreen popups.
void PopupMsg(string text, float duration=DEFAULT_DURATION, string text2="", int prio=-1, string param1="", string param2="", string param3="", string param4="", string text2param1="", string text2param2="", string text2param3="", string text2param4="", string sound="", SCR_EPopupMsgFilter category=SCR_EPopupMsgFilter.ALL, WorldTimestamp progressStart=null, WorldTimestamp progressEnd=null)
static SCR_PopUpNotification GetInstance()
static const string TASKS_KEY_IMAGE_FORMAT
Spawn point entity defines positions on which players can possibly spawn.
static SCR_SpawnPoint GetSpawnPointByRplId(RplId id)
proto external GenericEntity GetOwner()
Get owner entity.
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EntityEvent
Various entity events.
Definition EntityEvent.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
Tuple param1