7 static const string PLAY_LIMITS_CLI =
"playerLimits";
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;
18 protected ref SCR_SortedArray<SCR_Faction> m_SortedFactions =
new SCR_SortedArray<SCR_Faction>();
22 [
RplProp(onRplName:
"OnPlayerFactionInfoChanged")]
23 protected ref array<ref SCR_PlayerFactionInfo> m_aPlayerFactionInfo = {};
81 array<Faction> factions = {};
84 foreach(
Faction baseFaction : factions)
101 int factionIndex = -1;
103 factionIndex = factionInfo.GetFactionIndex();
111 for (
int i = 0, cnt = m_aPlayerFactionInfo.Count(); i < cnt; i++)
114 int playerId = m_aPlayerFactionInfo[i].GetPlayerId();
118 int playerFactionIndex = m_aPlayerFactionInfo[i].GetFactionIndex();
119 if (playerFactionIndex != -1)
127 int previousFactionIndex;
129 previousFactionIndex = -1;
131 if (previousFactionIndex != playerFactionIndex)
142 if (factionIndex == -1)
158 if (!scriptedFaction)
172 #ifdef _ENABLE_RESPAWN_LOGS
173 Print(
string.Format(
"%1::OnPlayerFactionSet_S(playerId: %2, faction: %3)",
Type().
ToString(), playerComponent.GetPlayerId(), faction),
LogLevel.NORMAL);
190 #ifdef _ENABLE_RESPAWN_LOGS
193 key = faction.GetFactionKey();
195 Print(
string.Format(
"%1::OnPlayerFactionCountChanged(faction: %2 [%3], count: %4)",
Type().
ToString(), faction, key, newCount),
LogLevel.NORMAL);
205 character.m_pFactionComponent.SetAffiliatedFaction(faction);
207 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(character);
209 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
210 if (!playerController)
214 if (!playerFactionAffiliation)
228 return m_DefaultRanks;
235 return m_DefaultRanks;
261 const FactionAffiliationComponent factionManager = FactionAffiliationComponent.Cast(entity.
FindComponent(FactionAffiliationComponent));
265 return factionManager.GetAffiliatedFaction();
275 static Faction SGetPlayerFaction(
int playerId)
281 return factionManager.GetPlayerFaction(playerId);
300 static Faction SGetLocalPlayerFaction()
306 return factionManager.GetLocalPlayerFaction();
318 int playerCount, childPlayerCounts;
321 array<SCR_Faction> factions =
new array<SCR_Faction>;
322 m_SortedFactions.ToArray(factions);
325 if (!lookedAtFaction || lookedAtFaction == faction || lookedAtFaction.GetParent() != faction)
329 playerCount += childPlayerCounts;
342 static int SGetFactionPlayerCount(
Faction faction)
348 return factionManager.GetFactionPlayerCount(faction);
357 return outFactions.CopyFrom(m_SortedFactions);
363 array<string> ancestors;
364 array<Faction> factions = {};
365 string scriptedFactionKey;
373 missionFactionLimitMap = missionHeader.GetFactionLimitMap();
377 for (
int i = factions.Count() - 1; i >= 0; i--)
382 scriptedFactionKey = scriptedFaction.GetFactionKey();
386 m_SortedFactions.Insert(scriptedFaction.
GetOrder(), scriptedFaction);
388 int playerTotalLimit = -1;
389 int playerMissionLimit = -1;
394 if (missionFactionLimitMap && missionFactionLimitMap.Contains(scriptedFactionKey))
395 playerMissionLimit = missionFactionLimitMap.Get(scriptedFactionKey);
397 if (cliFactionLimitMap && cliFactionLimitMap.Contains(scriptedFactionKey))
399 if (playerMissionLimit >= 0)
400 playerTotalLimit =
Math.Min(playerMissionLimit, cliFactionLimitMap.Get(scriptedFactionKey));
402 playerTotalLimit = cliFactionLimitMap.Get(scriptedFactionKey);
405 if (playerTotalLimit < 0 && playerMissionLimit >= 0)
407 playerTotalLimit = playerMissionLimit;
409 if (playerTotalLimit >= 0)
429 array<Managed> components = {};
433 component.OnFactionsInit(factions);
437 foreach (
Faction currentFaction : factions)
439 scriptedFaction =
SCR_Faction.Cast(currentFaction);
457 super.EOnFixedFrame(owner,timeSlice);
474 super.EOnDiag(owner, timeSlice);
476 if (!DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_FACTION_DIAG))
479 DbgUI.Begin(
"SCR_FactionManager");
481 DbgUI.Text(
"* Faction Player Count *");
482 array<Faction> factions = {};
484 foreach (
Faction faction : factions)
486 DbgUI.Text(
string.Format(
"%1: %2 player(s)", faction.GetFactionKey(),
GetFactionPlayerCount(faction)));
502 ConnectToDiagSystem();
508 string factionKey, parentKey;
509 for (
int i, count = factionSources.Count(); i < count; i++)
511 factionSource = factionSources.Get(i);
512 factionSource.Get(
"FactionKey", factionKey);
514 array<string> ancestors = {};
515 while (factionSource)
517 factionSource.Get(
"FactionKey", parentKey);
518 if (!ancestors.Contains(parentKey))
519 ancestors.Insert(parentKey);
521 factionSource = factionSource.GetAncestor();
533 DisconnectFromDiagSystem();
543 return m_bCanChangeFactionsPlayable;
555 string factionKey = faction.GetFactionKey();
594 if (factionA.DoCheckIfFactionFriendly(factionB) && factionB.DoCheckIfFactionFriendly(factionA))
598 bool isServer = (gameMode && gameMode.
IsMaster()) || (!gameMode &&
Replication.IsServer());
601 if (factionA == factionB)
603 factionA.SetFactionFriendly(factionA);
605 if (playerChanged > 0 && isServer)
606 SCR_NotificationsComponent.SendToEveryone(
ENotification.EDITOR_FACTION_SET_FRIENDLY_TO_SELF, playerChanged, GetFactionIndex(factionA));
610 factionA.SetFactionFriendly(factionB);
611 factionB.SetFactionFriendly(factionA);
613 if (playerChanged > 0 && isServer)
614 SCR_NotificationsComponent.SendToEveryone(
ENotification.EDITOR_FACTION_SET_FRIENDLY_TO, playerChanged, GetFactionIndex(factionA),
GetFactionIndex(factionB));
626 if (!delegateFactionManager)
629 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.
GetFactionDelegate(factionA);
631 if (!factionDelegate)
647 bool isServer = (gameMode && gameMode.
IsMaster()) || (!gameMode &&
Replication.IsServer());
649 factionB.SetFactionFriendly(factionA);
658 if (!delegateFactionManager)
661 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.
GetFactionDelegate(factionA);
662 if (!factionDelegate)
679 if (!factionA.DoCheckIfFactionFriendly(factionB))
683 bool isServer = (gameMode && gameMode.
IsMaster()) || (!gameMode &&
Replication.IsServer());
686 if (factionA == factionB)
688 factionA.SetFactionHostile(factionA);
690 if (playerChanged > 0 && isServer)
691 SCR_NotificationsComponent.SendToEveryone(
ENotification.EDITOR_FACTION_SET_HOSTILE_TO_SELF, playerChanged, GetFactionIndex(factionA));
695 factionA.SetFactionHostile(factionB);
696 factionB.SetFactionHostile(factionA);
698 if (playerChanged > 0 && isServer)
699 SCR_NotificationsComponent.SendToEveryone(
ENotification.EDITOR_FACTION_SET_HOSTILE_TO, playerChanged, GetFactionIndex(factionA),
GetFactionIndex(factionB));
710 if (!delegateFactionManager)
713 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.
GetFactionDelegate(factionA);
714 if (!factionDelegate)
727 PerceptionManager pm =
GetGame().GetPerceptionManager();
729 pm.RequestUpdateAllTargetsFactions();
738 int targetPlayerId = playerFactionComponent.GetPlayerController().GetPlayerId();
739 Faction targetFaction = playerFactionComponent.GetAffiliatedFaction();
752 if (previousIndex != -1)
756 int newCount = previousCount - 1;
766 if (targetFactionIndex != -1)
770 int newCount = previousCount + 1;
785 m_aPlayerFactionInfo.Insert(newInfo);
789 if (targetFactionIndex != -1)
793 int newCount = previousCount + 1;
811 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
815 if (!playerFactionAffiliation)
819 if (!playerFactionAffiliation.GetAffiliatedFaction())
827 override protected bool RplSave(ScriptBitWriter writer)
829 array<Faction> factions = {};
832 writer.WriteInt(factions.Count());
834 foreach (
Faction basefaction : factions)
837 writer.WriteString(faction.GetFactionKey());
849 reader.ReadInt(count);
851 for (
int i = 0; i < count; i++)
854 reader.ReadString(key);
883 switch (unparsedMap[
index])
893 result.Insert(factionKey, limit.ToInt());
901 limit += unparsedMap[
index];
903 factionKey += unparsedMap[
index];
909 result.Insert(factionKey, limit.ToInt());
911 if (result.IsEmpty())
ArmaReforgerScripted GetGame()
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
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
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external int FindComponents(typename typeName, notnull array< Managed > outComponents)
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 DoRplSave(ScriptBitWriter writer)
void SetPlayerLimit(int playerLimit)
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.
bool RequestFaction(Faction faction)
static SCR_PlayerFactionInfo Create(int playerId)
void SetFactionIndex(int factionIndex)
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.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
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="")
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.