18 private PlayerController m_PlayerController;
20 private RplComponent m_RplComponent;
22 private SCR_SpawnLockComponent m_Lock;
29 PlayerController GetPlayerController()
38 return GetPlayerController().GetPlayerId();
43 protected SCR_SpawnLockComponent GetLock()
52 return m_FactionAffiliation;
69 return m_OnCanPlayerLoadoutRequestInvoker_O;
78 return m_OnCanPlayerLoadoutRequestInvoker_S;
88 return m_OnCanPlayerLoadoutResponseInvoker_O;
96 return m_OnCanPlayerLoadoutResponseInvoker_S;
106 return m_OnPlayerLoadoutRequestInvoker_O;
114 return m_OnPlayerLoadoutRequestInvoker_S;
124 return m_OnPlayerLoadoutResponseInvoker_O;
133 return m_OnPlayerLoadoutResponseInvoker_S;
137 protected bool IsOwner()
143 protected bool IsProxy()
149 protected override void OnPostInit(IEntity owner)
151 super.OnPostInit(owner);
154 Debug.Error(
string.Format(
"%1 is not attached to a %2", Type().ToString(), PlayerController));
158 if (m_FactionAffiliation)
159 m_FactionAffiliation.GetOnFactionChanged().Insert(OnFactionChanged);
161 m_Lock = SCR_SpawnLockComponent.Cast(owner.FindComponent(SCR_SpawnLockComponent));
162 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
165 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_LOADOUT_DIAG,
"",
"Player Loadouts",
"GameMode");
171 protected override void OnDelete(IEntity owner)
173 if (m_FactionAffiliation)
174 m_FactionAffiliation.GetOnFactionChanged().Remove(OnFactionChanged);
176 super.OnDelete(owner);
180 protected void OnFactionChanged(FactionAffiliationComponent owner,
Faction old,
Faction current)
189 Print(
"Loadout manager is missing in the world!", LogLevel.ERROR);
193 int previous = loadoutManager.GetLoadoutIndex(m_Loadout);
200 if (!CanAssignLoadout_S(previous))
205 SendRequestLoadoutResponse_S(-1,
true);
227 #ifdef _ENABLE_RESPAWN_LOGS
228 PrintFormat(
"%1::RequestLoadout(loadout: %2)", Type().ToString(),
loadout);
232 int loadoutIndex =
GetGame().GetLoadoutManager().GetLoadoutIndex(
loadout);
233 SCR_SpawnLockComponent lock = GetLock();
234 if (lock && !lock.TryLock(
this,
false))
236 Print(
"Caught request on locked player!", LogLevel.WARNING);
242 GetOnPlayerLoadoutRequestInvoker_O().Invoke(
this, loadoutIndex);
245 GetOnPlayerLoadoutRequestInvoker_S().Invoke(
this, loadoutIndex);
247 Rpc(Rpc_RequestLoadout_S, loadoutIndex);
254 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
255 protected void Rpc_RequestLoadout_S(
int loadoutIndex)
257 #ifdef _ENABLE_RESPAWN_LOGS
258 PrintFormat(
"%1::Rpc_RequestLoadout_S(loadoutIdx: %2)", Type().ToString(), loadoutIndex);
262 SCR_SpawnLockComponent lock = GetLock();
263 if (lock && !lock.TryLock(
this,
true))
265 Debug.Error(
"Caught request on locked player!");
270 GetOnPlayerLoadoutRequestInvoker_S().Invoke(
this, loadoutIndex);
273 if (CanAssignLoadout_S(loadoutIndex))
276 if (AssignLoadout_S(loadoutIndex))
279 SendRequestLoadoutResponse_S(loadoutIndex,
true);
285 SendRequestLoadoutResponse_S(loadoutIndex,
false);
289 protected bool AssignLoadout_S(
int loadoutIndex)
297 loadoutManager.UpdatePlayerLoadout_S(
this);
301 gameMode.OnPlayerLoadoutSet_S(
this,
loadout);
311 protected void SendRequestLoadoutResponse_S(
int loadoutIndex,
bool response)
313 #ifdef _ENABLE_RESPAWN_LOGS
314 PrintFormat(
"%1::SendRequestLoadoutResponse_S(loadoutIdx: %2, response: %3)", Type().ToString(), loadoutIndex, response);
318 SCR_SpawnLockComponent lock = GetLock();
321 lock.Unlock(
this,
true);
322 lock.Unlock(
this,
false);
326 GetOnPlayerLoadoutResponseInvoker_S().Invoke(
this, loadoutIndex, response);
329 Rpc(RequestLoadoutResponse_O, loadoutIndex, response);
337 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
338 protected void RequestLoadoutResponse_O(
int loadoutIndex,
bool response)
340 #ifdef _ENABLE_RESPAWN_LOGS
341 PrintFormat(
"%1::RequestLoadoutResponse_O(loadoutIdx: %2, response: %3)", Type().ToString(), loadoutIndex, response);
345 SCR_SpawnLockComponent lock = GetLock();
348 lock.Unlock(
this,
false);
353 m_Loadout = loadoutManager.GetLoadoutByIndex(loadoutIndex);
357 GetOnPlayerLoadoutResponseInvoker_O().Invoke(
this, loadoutIndex, response);
368 #ifdef _ENABLE_RESPAWN_LOGS
369 Print(
string.Format(
"%1::CanRequestLoadout(loadout: %2)", Type().ToString(),
loadout), LogLevel.NORMAL);
373 SCR_SpawnLockComponent lock = GetLock();
374 if (lock && !lock.TryLock(
this,
false))
376 Debug.Error(
"Caught request on locked player!");
380 int loadoutIndex =
GetGame().GetLoadoutManager().GetLoadoutIndex(
loadout);
383 GetOnCanPlayerLoadoutRequestInvoker_O().Invoke(
this, loadoutIndex);
387 GetOnCanPlayerLoadoutRequestInvoker_S().Invoke(
this, loadoutIndex);
389 Rpc(Rpc_CanRequestLoadout_S, loadoutIndex);
396 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
397 protected void Rpc_CanRequestLoadout_S(
int loadoutIndex)
399 #ifdef _ENABLE_RESPAWN_LOGS
400 PrintFormat(
"%1::Rpc_CanRequestLoadout_S(loadoutIdx: %2)", Type().ToString(), loadoutIndex);
404 SCR_SpawnLockComponent lock = GetLock();
405 if (lock && !lock.TryLock(
this,
true))
407 Debug.Error(
"Caught request on locked player!");
412 GetOnCanPlayerLoadoutRequestInvoker_S().Invoke(
this, loadoutIndex);
415 if (!CanAssignLoadout_S(loadoutIndex))
417 SendCanRequestLoadoutResponse_S(loadoutIndex,
false);
421 SendCanRequestLoadoutResponse_S(loadoutIndex,
true);
428 protected bool CanAssignLoadout_S(
int loadoutIndex)
436 if (factionAffiliation)
437 playerFaction = factionAffiliation.GetAffiliatedFaction();
440 if (!IsLoadoutUseableByFaction(
loadout, playerFaction))
443 return loadoutManager.CanAssignLoadout_S(
this,
loadout);
459 key = faction.GetFactionKey();
461 return key == factionLoadout.GetFactionKey();
469 protected void SendCanRequestLoadoutResponse_S(
int loadoutIndex,
bool response)
471 #ifdef _ENABLE_RESPAWN_LOGS
472 PrintFormat(
"%1::SendCanRequestLoadoutResponse_S(loadoutIdx: %2, response: %3)", Type().ToString(), loadoutIndex, response);
476 SCR_SpawnLockComponent lock = GetLock();
479 lock.Unlock(
this,
true);
480 lock.Unlock(
this,
false);
484 GetOnCanPlayerLoadoutResponseInvoker_S().Invoke(
this, loadoutIndex, response);
487 Rpc(CanRequestLoadoutResponse_O, loadoutIndex, response);
495 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
496 protected void CanRequestLoadoutResponse_O(
int loadoutIndex,
bool response)
498 #ifdef _ENABLE_RESPAWN_LOGS
499 PrintFormat(
"%1::CanRequestLoadoutResponse_O(loadoutIdx: %2, response: %3)", Type().ToString(), loadoutIndex, response);
503 SCR_SpawnLockComponent lock = GetLock();
506 lock.Unlock(
this,
false);
510 GetOnCanPlayerLoadoutResponseInvoker_O().Invoke(
this, loadoutIndex, response);
518 if (!DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_LOADOUT_DIAG))
521 int playerId = GetPlayerController().GetPlayerId();
522 DbgUI.Begin(
string.Format(
"PlayerLoadout (id: %1)", playerId));
525 string loadoutName =
"None";
527 loadoutName =
loadout.GetLoadoutName();
532 DbgUI.InputInt(
"Wanted Loadout Idx", wantedIdx);
537 DbgUI.Text(
string.Format(
"Wanted: %1 (%2)", wantedLoadout.GetLoadoutName(), wantedLoadout));
539 DbgUI.Text(
string.Format(
"Wanted: None (Clear)"));
541 if (DbgUI.Button(
"CanRequest"))
542 CanRequestLoadout(wantedLoadout);
543 if (DbgUI.Button(
"Request"))
544 RequestLoadout(wantedLoadout);