22 private PlayerController m_PlayerController;
23 private RplComponent m_RplComponent;
25 private SCR_SpawnLockComponent m_Lock;
31 return m_PlayerController;
43 protected SCR_SpawnLockComponent
GetLock()
135 return !m_RplComponent || m_RplComponent.IsOwner();
141 return m_RplComponent && m_RplComponent.IsProxy();
147 super.OnPostInit(owner);
148 m_PlayerController = PlayerController.Cast(owner);
149 if (!m_PlayerController)
150 Debug.Error(
string.Format(
"%1 is not attached to a %2",
Type().
ToString(), PlayerController));
153 m_Lock = SCR_SpawnLockComponent.Cast(owner.
FindComponent(SCR_SpawnLockComponent));
154 m_RplComponent = RplComponent.Cast(owner.
FindComponent(RplComponent));
170 #ifdef _ENABLE_RESPAWN_LOGS
175 int factionIndex =
GetGame().GetFactionManager().GetFactionIndex(faction);
176 SCR_SpawnLockComponent lock =
GetLock();
177 if (lock && !lock.TryLock(
this,
false))
179 Print(
"SCR_PlayerFactionAffiliationComponent::RequestFaction - Caught request on locked player!",
LogLevel.DEBUG);
200 #ifdef _ENABLE_RESPAWN_LOGS
205 SCR_SpawnLockComponent lock =
GetLock();
206 if (lock && !lock.TryLock(
this,
true))
208 Print(
"SCR_PlayerFactionAffiliationComponent::Rpc_RequestFaction_S - Caught request on locked player!",
LogLevel.DEBUG);
216 Faction faction =
GetGame().GetFactionManager().GetFactionByIndex(factionIndex);
239 if (!m_PlayerController)
244 if (!originalFaction)
245 PrintFormat(
"INFO: Faction: player %1 has joined faction %2 (%3)", playerIdentity, newFaction.GetFactionName(), newFaction.GetFactionKey(),
LogLevel.NORMAL);
247 PrintFormat(
"INFO: Faction: player %1 has switched from faction %2 (%3) to faction %4 (%5).", playerIdentity, originalFaction.GetFactionName(), originalFaction.GetFactionKey(), newFaction.GetFactionName(), newFaction.GetFactionKey(),
LogLevel.NORMAL);
257 #ifdef _ENABLE_RESPAWN_LOGS
267 factionManager.UpdatePlayerFaction_S(
this);
285 #ifdef _ENABLE_RESPAWN_LOGS
286 Print(
string.Format(
"%1::SendRequestFactionResponse_S(factionIdx: %2, response: %3)",
Type().
ToString(), factionIndex, response),
LogLevel.NORMAL);
290 SCR_SpawnLockComponent lock =
GetLock();
293 lock.Unlock(
this,
true);
295 lock.Unlock(
this,
false);
313 #ifdef _ENABLE_RESPAWN_LOGS
314 Print(
string.Format(
"%1::RequestFactionResponse_O(factionIdx: %2, response: %3)",
Type().
ToString(), factionIndex, response),
LogLevel.NORMAL);
318 SCR_SpawnLockComponent lock =
GetLock();
320 lock.Unlock(
this,
false);
334 #ifdef _ENABLE_RESPAWN_LOGS
339 SCR_SpawnLockComponent lock =
GetLock();
340 if (lock && !lock.TryLock(
this,
false))
342 Print(
"SCR_PlayerFactionAffiliationComponent::CanRequestFaction - Caught request on locked player!",
LogLevel.DEBUG);
346 int factionIndex =
GetGame().GetFactionManager().GetFactionIndex(faction);
366 #ifdef _ENABLE_RESPAWN_LOGS
371 SCR_SpawnLockComponent lock =
GetLock();
372 if (lock && !lock.TryLock(
this,
true))
374 Print(
"SCR_PlayerFactionAffiliationComponent::Rpc_RequestFaction_S - Caught request on locked player!",
LogLevel.DEBUG);
381 Faction faction =
GetGame().GetFactionManager().GetFactionByIndex(factionIndex);
398 #ifdef _ENABLE_RESPAWN_LOGS
418 #ifdef _ENABLE_RESPAWN_LOGS
419 Print(
string.Format(
"%1::SendCanRequestFactionResponse_S(factionIdx: %2, response: %3)",
Type().
ToString(), factionIndex, response),
LogLevel.NORMAL);
423 SCR_SpawnLockComponent lock =
GetLock();
426 lock.Unlock(
this,
true);
428 lock.Unlock(
this,
false);
446 #ifdef _ENABLE_RESPAWN_LOGS
447 Print(
string.Format(
"%1::CanRequestFactionResponse_O(factionIdx: %2, response: %3)",
Type().
ToString(), factionIndex, response),
LogLevel.NORMAL);
451 SCR_SpawnLockComponent lock =
GetLock();
453 lock.Unlock(
this,
false);
462 super.OnFactionChanged(previous, current);
477 DbgUI.Begin(
string.Format(
"PlayerFaction (id: %1)", playerId));
483 factionKey = faction.GetFactionKey();
485 DbgUI.Text(
string.Format(
"Current: %1 (%2)", factionKey, faction));
487 FactionManager factionManager =
GetGame().GetFactionManager();
488 string availableFactions =
"Available Factions: ";
489 array<Faction> factions = {};
490 factionManager.GetFactionsList(factions);
491 if (factions.Count() > 0)
493 string fk = factions[0].GetFactionKey();
494 availableFactions += fk;
496 for (
int i = 1; i < factions.Count(); i++)
498 fk = factions[i].GetFactionKey();
499 availableFactions +=
string.Format(
", %1", fk);
503 if (availableFactions.IsEmpty())
504 availableFactions +=
"None";
506 DbgUI.Text(availableFactions);
509 DbgUI.InputText(
"Wanted Faction Key", wanted);
511 Faction wantedFaction = factionManager.GetFactionByKey(wanted);
514 DbgUI.Text(
string.Format(
"Wanted: %1 (%2)", wantedFaction.GetFactionKey(), wantedFaction));
515 if (DbgUI.Button(
"CanRequest"))
517 if (DbgUI.Button(
"Request"))
ArmaReforgerScripted GetGame()
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
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)
void SCR_FactionManager(IEntitySource src, IEntity parent)
func PlayerFactionRequestDelegate
func PlayerFactionResponseDelegate
ScriptInvokerBase< PlayerFactionResponseDelegate > OnPlayerFactionResponseInvoker
ScriptInvokerBase< PlayerFactionChangedDelegate > OnPlayerFactionChangedInvoker
func PlayerFactionChangedDelegate
ScriptInvokerBase< PlayerFactionRequestDelegate > OnPlayerFactionRequestInvoker
void SCR_RespawnComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
void OnPlayerFactionSet_S(SCR_PlayerFactionAffiliationComponent factionComponent, Faction faction)
ref OnPlayerFactionRequestInvoker m_OnCanPlayerFactionRequestInvoker_O
OnPlayerFactionResponseInvoker GetOnPlayerFactionResponseInvoker_S()
void CanRequestFactionResponse_O(int factionIndex, bool response)
void RequestFactionResponse_O(int factionIndex, bool response)
override void OnPostInit(IEntity owner)
ref OnPlayerFactionChangedInvoker m_OnPlayerFactionChangedInvoker
OnPlayerFactionResponseInvoker GetOnCanPlayerFactionResponseInvoker_O()
void Rpc_CanRequestFaction_S(int factionIndex)
ref OnPlayerFactionResponseInvoker m_OnCanPlayerFactionResponseInvoker_S
OnPlayerFactionChangedInvoker GetOnPlayerFactionChangedInvoker()
void Rpc_RequestFaction_S(int factionIndex)
OnPlayerFactionResponseInvoker GetOnPlayerFactionResponseInvoker_O()
SCR_SpawnLockComponent GetLock()
void SendCanRequestFactionResponse_S(int factionIndex, bool response)
bool RequestFaction(Faction faction)
ref OnPlayerFactionResponseInvoker m_OnPlayerFactionResponseInvoker_S
ref OnPlayerFactionResponseInvoker m_OnCanPlayerFactionResponseInvoker_O
void SendRequestFactionResponse_S(int factionIndex, bool response)
OnPlayerFactionRequestInvoker GetOnPlayerFactionRequestInvoker_O()
OnPlayerFactionResponseInvoker GetOnCanPlayerFactionResponseInvoker_S()
ref OnPlayerFactionRequestInvoker m_OnCanPlayerFactionRequestInvoker_S
bool CanRequestFaction_S(Faction faction)
OnPlayerFactionRequestInvoker GetOnCanPlayerFactionRequestInvoker_S()
ref OnPlayerFactionRequestInvoker m_OnPlayerFactionRequestInvoker_S
bool SetFaction_S(Faction faction)
bool CanRequestFaction(Faction faction)
ref OnPlayerFactionRequestInvoker m_OnPlayerFactionRequestInvoker_O
void LogFactionChange(notnull Faction newFaction, Faction originalFaction=null)
ref OnPlayerFactionResponseInvoker m_OnPlayerFactionResponseInvoker_O
OnPlayerFactionRequestInvoker GetOnPlayerFactionRequestInvoker_S()
OnPlayerFactionRequestInvoker GetOnCanPlayerFactionRequestInvoker_O()
void OnFactionChanged(Faction previous, Faction current)
proto external void SetAffiliatedFaction(Faction faction)
SCR_CampaignFaction GetAffiliatedFaction()
Returns the affiliated faction or null if none.
void OnDiag(IEntity owner, float timeslice)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()
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.