Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionManager.c
Go to the documentation of this file.
1//~ Event when player faction changed
2void SCR_FactionManager_PlayerFactionChanged(int playerId, SCR_PlayerFactionAffiliationComponent playerFactionAffiliationComponent, Faction faction);
4
6{
7 static const string PLAY_LIMITS_CLI = "playerLimits";
8}
9
10class SCR_FactionManager : FactionManager
11{
12 [Attribute(defvalue: "1", desc: "Whether or not the isPlayable state of a faction can be changed on run time")]
13 protected bool m_bCanChangeFactionsPlayable;
14
15 [Attribute(desc: "Default list of ranks")]
16 protected ref SCR_RankContainer m_DefaultRanks;
17
18 protected ref SCR_SortedArray<SCR_Faction> m_SortedFactions = new SCR_SortedArray<SCR_Faction>();
20
22 [RplProp(onRplName: "OnPlayerFactionInfoChanged")]
23 protected ref array<ref SCR_PlayerFactionInfo> m_aPlayerFactionInfo = {};
24
27
29 protected ref set<int> m_ChangedFactions = new set<int>();
30
33
36
37 //~ Script invokers
40
41 //~ Server only \/
42 protected ref ScriptInvokerBase<SCR_FactionManager_PlayerFactionChanged> m_OnPlayerFactionChanged;
43
44 // if nonempty this stores player limits of factions, that are different on server and client
46
47 //------------------------------------------------------------------------------------------------
56
57 //------------------------------------------------------------------------------------------------
66
67 //------------------------------------------------------------------------------------------------
69 ScriptInvokerBase<SCR_FactionManager_PlayerFactionChanged> GetOnPlayerFactionChanged_S()
70 {
72 m_OnPlayerFactionChanged = new ScriptInvokerBase<SCR_FactionManager_PlayerFactionChanged>();
73
75 }
76
77 //------------------------------------------------------------------------------------------------
80 {
81 array<Faction> factions = {};
82 GetFactionsList(factions);
83 SCR_Faction faction;
84 foreach(Faction baseFaction : factions)
85 {
86 faction = SCR_Faction.Cast(baseFaction);
87 if (faction)
88 faction.UpdateCustomLoadoutSupportState(loadoutMgr);
89 }
90 }
91
92 //------------------------------------------------------------------------------------------------
95 {
96 // Store previous factions, so we can raise events
97 m_ChangedFactions.Clear();
99 foreach (int id, SCR_PlayerFactionInfo factionInfo : m_MappedPlayerFactionInfo)
100 {
101 int factionIndex = -1;
102 if (factionInfo)
103 factionIndex = factionInfo.GetFactionIndex();
104
105 m_PreviousPlayerFactions.Set(id, factionIndex);
106 }
107
108 // Clear all records and rebuild them from scratch
110 m_PlayerCount.Clear();
111 for (int i = 0, cnt = m_aPlayerFactionInfo.Count(); i < cnt; i++)
112 {
113 // Map player to info
114 int playerId = m_aPlayerFactionInfo[i].GetPlayerId();
115 m_MappedPlayerFactionInfo.Insert(playerId, m_aPlayerFactionInfo[i]);
116
117 // Resolve player-faction count
118 int playerFactionIndex = m_aPlayerFactionInfo[i].GetFactionIndex();
119 if (playerFactionIndex != -1)
120 {
121 int previousCount;
122 m_PlayerCount.Find(playerFactionIndex, previousCount);
123 m_PlayerCount.Set(playerFactionIndex, previousCount+1);
124 }
125
126 // If player count changed, append to temp list
127 int previousFactionIndex;
128 if (!m_PreviousPlayerFactions.Find(playerId, previousFactionIndex))
129 previousFactionIndex = -1; // If player had no affiliated faction previously, always assume none instead
130
131 if (previousFactionIndex != playerFactionIndex)
132 {
133 m_ChangedFactions.Insert(previousFactionIndex);
134 m_ChangedFactions.Insert(playerFactionIndex);
135 }
136 }
137
138 // Raise callback for all factions of which the count has changed
139 foreach (int factionIndex : m_ChangedFactions)
140 {
141 // Null faction
142 if (factionIndex == -1)
143 continue;
144
145 Faction faction = GetFactionByIndex(factionIndex);
146 int count;
147 m_PlayerCount.Find(factionIndex, count);
148 OnPlayerFactionCountChanged(faction, count);
149 }
150 }
151
152 //------------------------------------------------------------------------------------------------
154 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
155 protected void RPC_UpdatePlayerLimit(FactionKey factionKey, int playerLimit)
156 {
157 SCR_Faction scriptedFaction = SCR_Faction.Cast(GetFactionByKey(factionKey));
158 if (!scriptedFaction)
159 return;
160
161 scriptedFaction.SetPlayerLimit(playerLimit);
162 }
163
164 //------------------------------------------------------------------------------------------------
168 {
170 m_OnPlayerFactionChanged.Invoke(playerComponent.GetPlayerId(), playerComponent, faction);
171
172 #ifdef _ENABLE_RESPAWN_LOGS
173 Print(string.Format("%1::OnPlayerFactionSet_S(playerId: %2, faction: %3)", Type().ToString(), playerComponent.GetPlayerId(), faction), LogLevel.NORMAL);
174 #endif
175 }
176
177 //------------------------------------------------------------------------------------------------
185 protected void OnPlayerFactionCountChanged(Faction faction, int newCount)
186 {
188 s_OnPlayerFactionCountChanged.Invoke(faction, newCount);
189
190 #ifdef _ENABLE_RESPAWN_LOGS
191 FactionKey key;
192 if (faction)
193 key = faction.GetFactionKey();
194
195 Print(string.Format("%1::OnPlayerFactionCountChanged(faction: %2 [%3], count: %4)", Type().ToString(), faction, key, newCount), LogLevel.NORMAL);
196 #endif
197 }
198
199 //------------------------------------------------------------------------------------------------
200 // Helper method for overriding a specific players faction, can be used while the character is in the world.
202 bool SetPlayerFaction(notnull SCR_ChimeraCharacter character, notnull Faction faction)
203 {
204 // this will set the SCR_CharacterFactionAffiliationComponent faction, AKA the faction of the posessed entity
205 character.m_pFactionComponent.SetAffiliatedFaction(faction);
206
207 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(character);
208
209 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
210 if (!playerController)
211 return false;
212
214 if (!playerFactionAffiliation)
215 return false;
216
217 return playerFactionAffiliation.RequestFaction(faction);
218 }
219
220 //------------------------------------------------------------------------------------------------
225 {
226 Faction fac = GetPlayerFaction(playerId);
227 if (!fac)
228 return m_DefaultRanks;
229
230 SCR_Faction faction = SCR_Faction.Cast(fac);
231 if (faction)
232 return faction.GetRanks();
233
234 // either something went wrong or the player doesn't have a faction yet so we stick to the default for now!
235 return m_DefaultRanks;
236 }
237
238 //------------------------------------------------------------------------------------------------
244 {
246 if (m_MappedPlayerFactionInfo.Find(playerId, info))
247 {
248 int factionIndex = info.GetFactionIndex();
249 return GetFactionByIndex(factionIndex);
250 }
251
252 return null;
253 }
254
255 //------------------------------------------------------------------------------------------------
256 static Faction SGetFaction(IEntity entity)
257 {
258 if (!entity)
259 return null;
260
261 const FactionAffiliationComponent factionManager = FactionAffiliationComponent.Cast(entity.FindComponent(FactionAffiliationComponent));
262 if (!factionManager)
263 return null;
264
265 return factionManager.GetAffiliatedFaction();
266 }
267
268 //------------------------------------------------------------------------------------------------
275 static Faction SGetPlayerFaction(int playerId)
276 {
277 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
278 if (!factionManager)
279 return null;
280
281 return factionManager.GetPlayerFaction(playerId);
282 }
283
284 //------------------------------------------------------------------------------------------------
289 {
290 int localPlayerId = SCR_PlayerController.GetLocalPlayerId();
291 return GetPlayerFaction(localPlayerId);
292 }
293
294 //------------------------------------------------------------------------------------------------
300 static Faction SGetLocalPlayerFaction()
301 {
302 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
303 if (!factionManager)
304 return null;
305
306 return factionManager.GetLocalPlayerFaction();
307 }
308
309 //------------------------------------------------------------------------------------------------
314 {
315 if (!faction)
316 return 0;
317
318 int playerCount, childPlayerCounts;
319 m_PlayerCount.Find(GetFactionIndex(faction), playerCount);
320
321 array<SCR_Faction> factions = new array<SCR_Faction>;
322 m_SortedFactions.ToArray(factions);
323 foreach (SCR_Faction lookedAtFaction : factions)
324 {
325 if (!lookedAtFaction || lookedAtFaction == faction || lookedAtFaction.GetParent() != faction)
326 continue;
327
328 m_PlayerCount.Find(GetFactionIndex(lookedAtFaction), childPlayerCounts);
329 playerCount += childPlayerCounts;
330 }
331
332 return playerCount;
333 }
334
335 //------------------------------------------------------------------------------------------------
342 static int SGetFactionPlayerCount(Faction faction)
343 {
344 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
345 if (!factionManager)
346 return 0;
347
348 return factionManager.GetFactionPlayerCount(faction);
349 }
350
351 //------------------------------------------------------------------------------------------------
355 int GetSortedFactionsList(out notnull SCR_SortedArray<SCR_Faction> outFactions)
356 {
357 return outFactions.CopyFrom(m_SortedFactions);
358 }
359
360 //------------------------------------------------------------------------------------------------
361 override void EOnInit(IEntity owner)
362 {
363 array<string> ancestors;
364 array<Faction> factions = {};
365 string scriptedFactionKey;
366 GetFactionsList(factions);
367 SCR_Faction scriptedFaction;
368 SCR_MissionHeader missionHeader = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
369 map<FactionKey, int> missionFactionLimitMap = new map<FactionKey, int>();
370 map<FactionKey, int> cliFactionLimitMap = new map<FactionKey, int>();
371
372 if (missionHeader)
373 missionFactionLimitMap = missionHeader.GetFactionLimitMap();
374
375 cliFactionLimitMap = GetFactionLimitMapCLI();
376
377 for (int i = factions.Count() - 1; i >= 0; i--)
378 {
379 scriptedFaction = SCR_Faction.Cast(factions[i]);
380 if (scriptedFaction)
381 {
382 scriptedFactionKey = scriptedFaction.GetFactionKey();
383 if (m_aAncestors.Find(scriptedFactionKey, ancestors))
384 scriptedFaction.SetAncestors(ancestors);
385
386 m_SortedFactions.Insert(scriptedFaction.GetOrder(), scriptedFaction);
387
388 int playerTotalLimit = -1;
389 int playerMissionLimit = -1;
390
391 // player limit is a minimum of limits set in mission and in cli param - server side only, client gets the limits via RplProp
392 if (Replication.IsServer())
393 {
394 if (missionFactionLimitMap && missionFactionLimitMap.Contains(scriptedFactionKey))
395 playerMissionLimit = missionFactionLimitMap.Get(scriptedFactionKey);
396
397 if (cliFactionLimitMap && cliFactionLimitMap.Contains(scriptedFactionKey))
398 {
399 if (playerMissionLimit >= 0)
400 playerTotalLimit = Math.Min(playerMissionLimit, cliFactionLimitMap.Get(scriptedFactionKey));
401 else
402 playerTotalLimit = cliFactionLimitMap.Get(scriptedFactionKey);
403 }
404
405 if (playerTotalLimit < 0 && playerMissionLimit >= 0)
406 // we have only mission header limit
407 playerTotalLimit = playerMissionLimit;
408
409 if (playerTotalLimit >= 0)
410 {
411 scriptedFaction.SetPlayerLimit(playerTotalLimit);
413 {
415 SetEventMask(EntityEvent.FIXEDFRAME);
416 }
417
418 m_mPendingLimitUpdates.Insert(scriptedFactionKey, playerTotalLimit);
419 }
420 }
421
422 scriptedFaction.InitializeFaction();
423 }
424 }
425 m_aAncestors = null; //--- Don't keep in the memory anymore, stored on factions now
426
427 //--- Initialise components (OnPostInit doesn't work in them)
429 array<Managed> components = {};
430 for (int i = 0, count = owner.FindComponents(SCR_BaseFactionManagerComponent, components); i < count; i++)
431 {
432 component = SCR_BaseFactionManagerComponent.Cast(components[i]);
433 component.OnFactionsInit(factions);
434 }
435
436 // Faction manager finished initializing, so lets finish setting up the factions
437 foreach (Faction currentFaction : factions)
438 {
439 scriptedFaction = SCR_Faction.Cast(currentFaction);
440 if (scriptedFaction)
441 scriptedFaction.InitFactionRelationships();
442 }
443
444 //--- Hook player disconnection event
445 #ifdef WORKBENCH
446 if (!GetGame().InPlayMode())
447 return;
448 #endif
449
452 }
453
454 //------------------------------------------------------------------------------------------------
455 override protected void EOnFixedFrame(IEntity owner, float timeSlice)
456 {
457 super.EOnFixedFrame(owner,timeSlice);
459 {
460 foreach (FactionKey factionKey, int playerLimit : m_mPendingLimitUpdates)
461 {
462 Rpc(RPC_UpdatePlayerLimit, factionKey, playerLimit);
463 }
464
466 }
467 ClearEventMask(EntityEvent.FIXEDFRAME);
468 }
469
470 #ifdef ENABLE_DIAG
471 //------------------------------------------------------------------------------------------------
472 protected override void EOnDiag(IEntity owner, float timeSlice)
473 {
474 super.EOnDiag(owner, timeSlice);
475
476 if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_FACTION_DIAG))
477 return;
478
479 DbgUI.Begin("SCR_FactionManager");
480 {
481 DbgUI.Text("* Faction Player Count *");
482 array<Faction> factions = {};
483 GetFactionsList(factions);
484 foreach (Faction faction : factions)
485 {
486 DbgUI.Text(string.Format("%1: %2 player(s)", faction.GetFactionKey(), GetFactionPlayerCount(faction)));
487 }
488 }
489
490 DbgUI.End();
491 }
492 #endif
493
494 //------------------------------------------------------------------------------------------------
495 // constructor
499 {
500 SetEventMask(EntityEvent.INIT);
501 #ifdef ENABLE_DIAG
502 ConnectToDiagSystem();
503 #endif
504
505 //--- Save faction ancestors
506 BaseContainerList factionSources = src.GetObjectArray("Factions");
507 BaseContainer factionSource;
508 string factionKey, parentKey;
509 for (int i, count = factionSources.Count(); i < count; i++)
510 {
511 factionSource = factionSources.Get(i);
512 factionSource.Get("FactionKey", factionKey);
513
514 array<string> ancestors = {};
515 while (factionSource)
516 {
517 factionSource.Get("FactionKey", parentKey);
518 if (!ancestors.Contains(parentKey))
519 ancestors.Insert(parentKey);
520
521 factionSource = factionSource.GetAncestor();
522 }
523
524 m_aAncestors.Insert(factionKey, ancestors);
525 }
526 }
527
528 //------------------------------------------------------------------------------------------------
529 // destructor
531 {
532 #ifdef ENABLE_DIAG
533 DisconnectFromDiagSystem();
534 #endif
535 }
536
537 //------------------------------------------------------------------------------------------------
542 {
543 return m_bCanChangeFactionsPlayable;
544 }
545
546 //------------------------------------------------------------------------------------------------
550 void SetFactionTasksEnabled(notnull SCR_Faction faction, bool isTasksEnabled)
551 {
552 if (Replication.IsClient())
553 return;
554
555 string factionKey = faction.GetFactionKey();
556
557 RpcDo_SetFactionTasksEnabled(factionKey, isTasksEnabled);
558 Rpc(RpcDo_SetFactionTasksEnabled, factionKey, isTasksEnabled);
559 }
560
561 //------------------------------------------------------------------------------------------------
565 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
566 protected void RpcDo_SetFactionTasksEnabled(string factionKey, bool isTasksEnabled)
567 {
568 SCR_Faction faction = SCR_Faction.Cast(GetFactionByKey(factionKey));
569
570 if (!faction || faction.IsTasksEnabled() == isTasksEnabled)
571 return;
572
573 faction.SetTasksEnabled(isTasksEnabled);
574
575 //Update the bases/tasks if the state of the player's faction changed
576 SCR_Faction playerfaction = SCR_Faction.Cast(GetLocalPlayerFaction());
577
578 if (playerfaction && playerfaction == faction && m_OnFactionTaskEnabledChanged)
579 m_OnFactionTaskEnabledChanged.Invoke(playerfaction);
580 }
581
582 //======================================== FACTION RELATIONS ========================================\\
583
584 //------------------------------------------------------------------------------------------------
591 void SetFactionsFriendly(notnull SCR_Faction factionA, notnull SCR_Faction factionB, int playerChanged = -1, bool updateAIs = true)
592 {
593 //~ Already friendly
594 if (factionA.DoCheckIfFactionFriendly(factionB) && factionB.DoCheckIfFactionFriendly(factionA))
595 return;
596
598 bool isServer = (gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer());
599
600 //~ Only call once if setting self as friendly
601 if (factionA == factionB)
602 {
603 factionA.SetFactionFriendly(factionA);
604
605 if (playerChanged > 0 && isServer)
606 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_FACTION_SET_FRIENDLY_TO_SELF, playerChanged, GetFactionIndex(factionA));
607 }
608 else
609 {
610 factionA.SetFactionFriendly(factionB);
611 factionB.SetFactionFriendly(factionA);
612
613 if (playerChanged > 0 && isServer)
614 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_FACTION_SET_FRIENDLY_TO, playerChanged, GetFactionIndex(factionA), GetFactionIndex(factionB));
615 }
616
617 //~ Replicate the setting of friendly Factions
618 if (isServer)
619 {
620 //~ Update AIs
621 if (updateAIs)
623
625
626 if (!delegateFactionManager)
627 return;
628
629 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.GetFactionDelegate(factionA);
630
631 if (!factionDelegate)
632 return;
633
634 //~ Replicate set friendly
635 factionDelegate.SetFactionFriendly_S(GetFactionIndex(factionB));
636 }
637 }
638
639 //------------------------------------------------------------------------------------------------
644 void SetFactionFriendlyOneWay(notnull SCR_Faction factionA, notnull SCR_Faction factionB, bool updateAIs = true)
645 {
647 bool isServer = (gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer());
648
649 factionB.SetFactionFriendly(factionA);
650
651 if (!isServer)
652 return;
653
654 if (updateAIs)
656
658 if (!delegateFactionManager)
659 return;
660
661 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.GetFactionDelegate(factionA);
662 if (!factionDelegate)
663 return;
664
665 // Replicate of setting the faction friendlyness.
666 factionDelegate.SetFactionFriendlyOneWay_S(GetFactionIndex(factionB));
667 }
668
669 //------------------------------------------------------------------------------------------------
676 void SetFactionsHostile(notnull SCR_Faction factionA, notnull SCR_Faction factionB, int playerChanged = -1, bool updateAIs = true)
677 {
678 //~ Already Hostile
679 if (!factionA.DoCheckIfFactionFriendly(factionB))
680 return;
681
683 bool isServer = (gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer());
684
685 //~ Only call once if setting self as hostile
686 if (factionA == factionB)
687 {
688 factionA.SetFactionHostile(factionA);
689
690 if (playerChanged > 0 && isServer)
691 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_FACTION_SET_HOSTILE_TO_SELF, playerChanged, GetFactionIndex(factionA));
692 }
693 else
694 {
695 factionA.SetFactionHostile(factionB);
696 factionB.SetFactionHostile(factionA);
697
698 if (playerChanged > 0 && isServer)
699 SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_FACTION_SET_HOSTILE_TO, playerChanged, GetFactionIndex(factionA), GetFactionIndex(factionB));
700 }
701
702 //~ Replicate the setting of hostile Factions
703 if (isServer)
704 {
705 //~ Update AIs
706 if (updateAIs)
708
710 if (!delegateFactionManager)
711 return;
712
713 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.GetFactionDelegate(factionA);
714 if (!factionDelegate)
715 return;
716
717 //~ Replicate set hostile
718 factionDelegate.SetFactionHostile_S(GetFactionIndex(factionB));
719 }
720 }
721
722 //------------------------------------------------------------------------------------------------
726 {
727 PerceptionManager pm = GetGame().GetPerceptionManager();
728 if (pm)
729 pm.RequestUpdateAllTargetsFactions();
730 }
731
732 //------------------------------------------------------------------------------------------------
737 {
738 int targetPlayerId = playerFactionComponent.GetPlayerController().GetPlayerId();
739 Faction targetFaction = playerFactionComponent.GetAffiliatedFaction();
740 int targetFactionIndex = GetFactionIndex(targetFaction);
741
742 // See if we have a record of player in the map
743 SCR_PlayerFactionInfo foundInfo;
744 if (m_MappedPlayerFactionInfo.Find(targetPlayerId, foundInfo))
745 {
746 // Adjust player counts
747 Faction previousFaction = GetPlayerFaction(targetPlayerId);
748 if (previousFaction)
749 {
750 // But only if previous entry was valid
751 int previousIndex = GetFactionIndex(previousFaction);
752 if (previousIndex != -1)
753 {
754 int previousCount;
755 m_PlayerCount.Find(previousIndex, previousCount); // Will not set value if not found
756 int newCount = previousCount - 1;
757 m_PlayerCount.Set(previousIndex, newCount); // Remove this player
758 OnPlayerFactionCountChanged(previousFaction, newCount);
759 }
760 }
761
762 // Update existing record
763 foundInfo.SetFactionIndex(targetFactionIndex);
764
765 // If new faction is valid, add to player count
766 if (targetFactionIndex != -1)
767 {
768 int previousCount;
769 m_PlayerCount.Find(targetFactionIndex, previousCount); // Will not set value if not found
770 int newCount = previousCount + 1;
771 m_PlayerCount.Set(targetFactionIndex, newCount); // Remove this player
772 OnPlayerFactionCountChanged(targetFaction, newCount);
773 }
774
775 // Raise authority callback
776 OnPlayerFactionSet_S(playerFactionComponent, targetFaction);
777
778 Replication.BumpMe();
779 return;
780 }
781
782 // Insert new record
783 SCR_PlayerFactionInfo newInfo = SCR_PlayerFactionInfo.Create(targetPlayerId);
784 newInfo.SetFactionIndex(targetFactionIndex);
785 m_aPlayerFactionInfo.Insert(newInfo);
786 // And map it
787 m_MappedPlayerFactionInfo.Set(targetPlayerId, newInfo);
788 // And since this player was not assigned, increment the count of players for target faction
789 if (targetFactionIndex != -1)
790 {
791 int previousCount;
792 m_PlayerCount.Find(targetFactionIndex, previousCount);
793 int newCount = previousCount + 1;
794 m_PlayerCount.Set(targetFactionIndex, newCount);
795 OnPlayerFactionCountChanged(targetFaction, newCount);
796 }
797
798 // Raise authority callback
799 OnPlayerFactionSet_S(playerFactionComponent, targetFaction);
800 Replication.BumpMe();
801 }
802
803 //------------------------------------------------------------------------------------------------
809 protected void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
810 {
811 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
812
813 // If faction is unused, no need to do anything
815 if (!playerFactionAffiliation)
816 return;
817
818 // No faction does not need update
819 if (!playerFactionAffiliation.GetAffiliatedFaction())
820 return;
821
822 // Clear faction, this will result in proper update of things
823 playerFactionAffiliation.RequestFaction(null);
824 }
825
826 //------------------------------------------------------------------------------------------------
827 override protected bool RplSave(ScriptBitWriter writer)
828 {
829 array<Faction> factions = {};
830 GetFactionsList(factions);
831
832 writer.WriteInt(factions.Count());
833
834 foreach (Faction basefaction : factions)
835 {
836 SCR_Faction faction = SCR_Faction.Cast(basefaction);
837 writer.WriteString(faction.GetFactionKey());
838
839 faction.DoRplSave(writer);
840 }
841
842 return true;
843 }
844
845 //------------------------------------------------------------------------------------------------
846 override protected bool RplLoad(ScriptBitReader reader)
847 {
848 int count;
849 reader.ReadInt(count);
850
851 for (int i = 0; i < count; i++)
852 {
853 string key;
854 reader.ReadString(key);
855
856 SCR_Faction faction = SCR_Faction.Cast(GetFactionByKey(key));
857 faction.DoRplLoad(reader);
858 }
859
860 return true;
861 }
862
863 //-----------------------------------------------------------------------------------------------
868 {
869 if (!System.IsCLIParam(SCR_FactionManagerClass.PLAY_LIMITS_CLI))
870 return null;
871
873
874 string unparsedMap;
875 System.GetCLIParam(SCR_FactionManagerClass.PLAY_LIMITS_CLI, unparsedMap);
876
877 FactionKey factionKey;
878 string limit;
879 bool limitRead;
880
881 for (int index = 0, l = unparsedMap.Length(); index < l; index++)
882 {
883 switch (unparsedMap[index])
884 {
885 case ":" :
886 {
887 limitRead = true;
888 break;
889 }
890 case "," :
891 {
892 limitRead = false;
893 result.Insert(factionKey, limit.ToInt());
894 factionKey = "";
895 limit = "";
896 break;
897 }
898 default :
899 {
900 if (limitRead)
901 limit += unparsedMap[index];
902 else
903 factionKey += unparsedMap[index];
904 }
905 }
906 }
907
908 if (limitRead)
909 result.Insert(factionKey, limit.ToInt());
910
911 if (result.IsEmpty())
912 return null;
913
914 return result;
915 }
916}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
int GetFactionIndex()
override bool RplLoad(ScriptBitReader reader)
void SCR_BaseFactionManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
override bool RplSave(ScriptBitWriter writer)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
ref array< string > m_aAncestors
Definition SCR_Faction.c:74
void UpdateCustomLoadoutSupportState(SCR_LoadoutManager loadoutMgr)
Updates local state of which determines if players from this faction can save custom loadouts.
void SetFactionTasksEnabled(notnull SCR_Faction faction, bool isTasksEnabled)
ref map< int, int > m_PlayerCount
Mapping of faction id : player count.
func SCR_FactionManager_PlayerFactionChanged
void RpcDo_SetFactionTasksEnabled(string factionKey, bool isTasksEnabled)
void OnPlayerFactionSet_S(SCR_PlayerFactionAffiliationComponent playerComponent, Faction faction)
int GetFactionPlayerCount(Faction faction)
void OnPlayerFactionCountChanged(Faction faction, int newCount)
ref ScriptInvoker s_OnPlayerFactionCountChanged
void ~SCR_FactionManager()
void RPC_UpdatePlayerLimit(FactionKey factionKey, int playerLimit)
Update server player limit to clients.
void SetFactionFriendlyOneWay(notnull SCR_Faction factionA, notnull SCR_Faction factionB, bool updateAIs=true)
ref ScriptInvokerBase< SCR_FactionManager_PlayerFactionChanged > m_OnPlayerFactionChanged
Faction GetLocalPlayerFaction()
ref ScriptInvokerFaction m_OnFactionTaskEnabledChanged
SCR_RankContainer GetFactionRanks(int playerId)
void SetFactionsHostile(notnull SCR_Faction factionA, notnull SCR_Faction factionB, int playerChanged=-1, bool updateAIs=true)
void SCR_FactionManager(IEntitySource src, IEntity parent)
ScriptInvokerBase< SCR_FactionManager_PlayerFactionChanged > GetOnPlayerFactionChanged_S()
return Script invoker on player faction changed (Server only)
ScriptInvoker GetOnPlayerFactionCountChanged()
bool SetPlayerFaction(notnull SCR_ChimeraCharacter character, notnull Faction faction)
void SetFactionsFriendly(notnull SCR_Faction factionA, notnull SCR_Faction factionB, int playerChanged=-1, bool updateAIs=true)
bool CanChangeFactionsPlayable()
ref map< FactionKey, int > m_mPendingLimitUpdates
int GetSortedFactionsList(out notnull SCR_SortedArray< SCR_Faction > outFactions)
ScriptInvokerFaction GetOnFactionTasksEnabledChanged()
map< FactionKey, int > GetFactionLimitMapCLI()
void OnPlayerFactionInfoChanged()
Update local player faction mapping.
ref map< int, ref SCR_PlayerFactionInfo > m_MappedPlayerFactionInfo
Local mapping of playerId to player faction info.
ref map< int, int > m_PreviousPlayerFactions
Map of previous players <playerId : factionIndex>.
ref set< int > m_ChangedFactions
List of indices of factions whose count has changed since last update.
void UpdatePlayerFaction_S(SCR_PlayerFactionAffiliationComponent playerFactionComponent)
override void EOnFixedFrame(IEntity owner, float timeSlice)
void SCR_LoadoutManager(IEntitySource src, IEntity parent)
Faction GetPlayerFaction(int playerID)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerFactionMethod > ScriptInvokerFaction
int Type
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external int FindComponents(typename typeName, notnull array< Managed > outComponents)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
sealed bool IsMaster()
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
SCR_EditableFactionComponent GetFactionDelegate(Faction faction)
static SCR_DelegateFactionManagerComponent GetInstance()
SCR_RankContainer GetRanks()
bool DoRplLoad(ScriptBitReader reader)
void SetTasksEnabled(bool isTasksEnabled)
void InitFactionRelationships()
Set up the faction relationships like friendlyness and parents.
bool IsTasksEnabled()
bool DoRplSave(ScriptBitWriter writer)
void SetPlayerLimit(int playerLimit)
void InitializeFaction()
void UpdateCustomLoadoutSupportState(SCR_LoadoutManager loadoutMgr)
Updates local state of which determines if players from this faction can save custom loadouts.
void SetAncestors(notnull array< string > ancestors)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static SCR_PlayerFactionInfo Create(int playerId)
void SetFactionIndex(int factionIndex)
Definition Types.c:486
override void EOnDiag(IEntity owner, float timeSlice)
override void EOnInit(IEntity owner)
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
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto external Faction GetFactionByIndex(int index)
FactionManagerClass GenericEntityClass GetFactionByKey(FactionKey factionKey)
proto external int GetFactionsList(out notnull array< Faction > outFactions)
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
proto external void RequestUpdateAllTargetsFactions()
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134