18 private PlayerController m_PlayerController;
19 private RplComponent m_RplComponent;
21 private SCR_SpawnLockComponent m_Lock;
25 PlayerController GetPlayerController()
34 return GetPlayerController().GetPlayerId();
39 protected SCR_SpawnLockComponent GetLock()
51 return m_OnCanPlayerFactionRequestInvoker_O;
60 return m_OnCanPlayerFactionRequestInvoker_S;
70 return m_OnCanPlayerFactionResponseInvoker_O;
79 return m_OnCanPlayerFactionResponseInvoker_S;
89 return m_OnPlayerFactionRequestInvoker_O;
98 return m_OnPlayerFactionRequestInvoker_S;
109 return m_OnPlayerFactionResponseInvoker_O;
116 return m_OnPlayerFactionResponseInvoker_S;
120 protected bool IsOwner()
126 protected bool IsProxy()
132 protected override void OnPostInit(IEntity owner)
134 super.OnPostInit(owner);
137 Debug.Error(
string.Format(
"%1 is not attached to a %2", Type().ToString(), PlayerController));
140 m_Lock = SCR_SpawnLockComponent.Cast(owner.FindComponent(SCR_SpawnLockComponent));
141 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
144 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_FACTION_DIAG,
"",
"Player Factions",
"GameMode");
155 bool RequestFaction(
Faction faction)
157 #ifdef _ENABLE_RESPAWN_LOGS
158 Print(
string.Format(
"%1::RequestFaction(faction: %2)", Type().ToString(), faction), LogLevel.NORMAL);
162 int factionIndex =
GetGame().GetFactionManager().GetFactionIndex(faction);
163 SCR_SpawnLockComponent lock = GetLock();
164 if (lock && !lock.TryLock(
this,
false))
166 Debug.Error(
"Caught request on locked player!");
172 GetOnPlayerFactionRequestInvoker_O().Invoke(
this, factionIndex);
175 GetOnPlayerFactionRequestInvoker_S().Invoke(
this, factionIndex);
177 Rpc(Rpc_RequestFaction_S, factionIndex);
184 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
185 protected void Rpc_RequestFaction_S(
int factionIndex)
187 #ifdef _ENABLE_RESPAWN_LOGS
188 Print(
string.Format(
"%1::Rpc_RequestFaction_S(factionIdx: %2)", Type().ToString(), factionIndex), LogLevel.NORMAL);
192 SCR_SpawnLockComponent lock = GetLock();
193 if (lock && !lock.TryLock(
this,
true))
195 Debug.Error(
"Caught request on locked player!");
200 GetOnPlayerFactionRequestInvoker_S().Invoke(
this, factionIndex);
202 Faction faction =
GetGame().GetFactionManager().GetFactionByIndex(factionIndex);
203 if (CanRequestFaction_S(faction))
205 if (SetFaction_S(faction))
208 SendRequestFactionResponse_S(factionIndex,
true);
214 SendRequestFactionResponse_S(factionIndex,
false);
222 protected bool SetFaction_S(
Faction faction)
224 #ifdef _ENABLE_RESPAWN_LOGS
225 Print(
string.Format(
"%1::RequestFaction_S(Faction: %2)", Type().ToString(), faction), LogLevel.NORMAL);
234 factionManager.UpdatePlayerFaction_S(
this);
238 gameMode.OnPlayerFactionSet_S(
this, faction);
250 protected void SendRequestFactionResponse_S(
int factionIndex,
bool response)
252 #ifdef _ENABLE_RESPAWN_LOGS
253 Print(
string.Format(
"%1::SendRequestFactionResponse_S(factionIdx: %2, response: %3)", Type().ToString(), factionIndex, response), LogLevel.NORMAL);
257 SCR_SpawnLockComponent lock = GetLock();
260 lock.Unlock(
this,
true);
262 lock.Unlock(
this,
false);
266 GetOnPlayerFactionResponseInvoker_S().Invoke(
this, factionIndex, response);
269 Rpc(RequestFactionResponse_O, factionIndex, response);
277 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
278 protected void RequestFactionResponse_O(
int factionIndex,
bool response)
280 #ifdef _ENABLE_RESPAWN_LOGS
281 Print(
string.Format(
"%1::RequestFactionResponse_O(factionIdx: %2, response: %3)", Type().ToString(), factionIndex, response), LogLevel.NORMAL);
285 SCR_SpawnLockComponent lock = GetLock();
287 lock.Unlock(
this,
false);
290 GetOnPlayerFactionResponseInvoker_O().Invoke(
this, factionIndex, response);
299 bool CanRequestFaction(
Faction faction)
301 #ifdef _ENABLE_RESPAWN_LOGS
302 Print(
string.Format(Format(
"%1::CanRequestFaction(faction: %2)", Type().ToString(), faction), LogLevel.NORMAL);
306 SCR_SpawnLockComponent lock = GetLock();
307 if (lock && !lock.TryLock(
this,
false))
309 Debug.Error(
"Caught request on locked player!");
317 GetOnCanPlayerFactionRequestInvoker_O().Invoke(
this, factionIndex);
321 GetOnCanPlayerFactionRequestInvoker_S().Invoke(
this, factionIndex);
323 Rpc(Rpc_CanRequestFaction_S, factionIndex);
330 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
331 protected void Rpc_CanRequestFaction_S(
int factionIndex)
333 #ifdef _ENABLE_RESPAWN_LOGS
334 Print(
string.Format(
"%1::Rpc_CanRequestFaction_S(factionIdx: %2)", Type().ToString(), factionIndex), LogLevel.NORMAL);
338 SCR_SpawnLockComponent lock = GetLock();
339 if (lock && !lock.TryLock(
this,
true))
341 Debug.Error(
"Caught request on locked player!");
346 GetOnCanPlayerFactionRequestInvoker_S().Invoke(
this, factionIndex);
348 Faction faction =
GetGame().GetFactionManager().GetFactionByIndex(factionIndex);
349 if (!CanRequestFaction_S(faction))
351 SendCanRequestFactionResponse_S(factionIndex,
false);
355 SendCanRequestFactionResponse_S(factionIndex,
true);
363 protected bool CanRequestFaction_S(
Faction faction)
365 #ifdef _ENABLE_RESPAWN_LOGS
366 Print(
string.Format(
"%1::CanRequestFaction_S(Faction: %2)", Type().ToString(), faction), LogLevel.NORMAL);
383 protected void SendCanRequestFactionResponse_S(
int factionIndex,
bool response)
385 #ifdef _ENABLE_RESPAWN_LOGS
386 Print(
string.Format(
"%1::SendCanRequestFactionResponse_S(factionIdx: %2, response: %3)", Type().ToString(), factionIndex, response), LogLevel.NORMAL);
390 SCR_SpawnLockComponent lock = GetLock();
393 lock.Unlock(
this,
true);
395 lock.Unlock(
this,
false);
399 GetOnCanPlayerFactionResponseInvoker_S().Invoke(
this, factionIndex, response);
402 Rpc(CanRequestFactionResponse_O, factionIndex, response);
410 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
411 protected void CanRequestFactionResponse_O(
int factionIndex,
bool response)
413 #ifdef _ENABLE_RESPAWN_LOGS
414 Print(
string.Format(
"%1::CanRequestFactionResponse_O(factionIdx: %2, response: %3)", Type().ToString(), factionIndex, response), LogLevel.NORMAL);
418 SCR_SpawnLockComponent lock = GetLock();
420 lock.Unlock(
this,
false);
423 GetOnCanPlayerFactionResponseInvoker_O().Invoke(
this, factionIndex, response);
431 if (!DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_FACTION_DIAG))
434 int playerId = GetPlayerController().GetPlayerId();
435 DbgUI.Begin(
string.Format(
"PlayerFaction (id: %1)", playerId));
437 FactionKey factionKey =
"Unassigned";
441 factionKey = faction.GetFactionKey();
443 DbgUI.Text(
string.Format(
"Current: %1 (%2)", factionKey, faction));
445 FactionManager factionManager =
GetGame().GetFactionManager();
446 string availableFactions =
"Available Factions: ";
447 array<Faction> factions = {};
448 factionManager.GetFactionsList(factions);
449 if (factions.Count() > 0)
451 string fk = factions[0].GetFactionKey();
452 availableFactions += fk;
454 for (
int i = 1; i < factions.Count(); i++)
456 fk = factions[i].GetFactionKey();
457 availableFactions +=
string.Format(
", %1", fk);
461 if (availableFactions.IsEmpty())
462 availableFactions +=
"None";
464 DbgUI.Text(availableFactions);
467 DbgUI.InputText(
"Wanted Faction Key", wanted);
469 Faction wantedFaction = factionManager.GetFactionByKey(wanted);
472 DbgUI.Text(
string.Format(
"Wanted: %1 (%2)", wantedFaction.GetFactionKey(), wantedFaction));
473 if (DbgUI.Button(
"CanRequest"))
474 CanRequestFaction(wantedFaction);
475 if (DbgUI.Button(
"Request"))
476 RequestFaction(wantedFaction);