1 [
ComponentEditorProps(
category:
"GameScripted/GameMode", description:
"Communicator for RespawnSystemComponent. Should be attached to PlayerController.")]
19 enum ERespawnSelectionResult
40 protected ref map<typename, SCR_SpawnRequestComponent>
m_mRequestComponents =
new map<typename, SCR_SpawnRequestComponent>();
49 if (!s_OnLocalPlayerSpawned)
52 return s_OnLocalPlayerSpawned;
155 #ifdef DEBUGUI_RESPAWN_REQUEST_COMPONENT_DIAG
156 static bool s_DebugRegistered;
163 PlayerController playerController =
GetGame().GetPlayerController();
164 if (playerController)
176 PlayerController playerController =
GetGame().GetPlayerController();
177 if (!playerController)
191 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
192 if (!playerController)
206 [
Obsolete(
"Use SCR_PlayerFactionAffiliationComponent instead!")]
210 [
Obsolete(
"Use SCR_PlayerLoadoutComponent instead!")]
214 [
Obsolete(
"Use SCR_RespawnComponent.RequestSpawn directly instead!")]
218 [
Obsolete(
"Use SCR_PlayerLoadoutComponent instead!")]
222 [
Obsolete(
"Use SCR_PlayerFactionAffiliationComponent instead!")]
226 [
Obsolete(
"Use SCR_RespawnComponent.RequestSpawn directly instead!")]
237 if (!controlledEntity)
240 CharacterControllerComponent characterController = CharacterControllerComponent.Cast(controlledEntity.FindComponent(CharacterControllerComponent));
241 if (characterController)
243 characterController.ForceDeath();
249 [
Obsolete(
"Use SCR_PlayerLoadoutComponent instead!")]
253 [
Obsolete(
"Use SCR_PlayerFactionAffiliationComponent instead!")]
257 [
Obsolete(
"Use SCR_RespawnComponent.RequestSpawn directly instead!")]
269 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
272 #ifdef _ENABLE_RESPAWN_LOGS
279 if (Diag_IsCLISpawnEnabled())
280 Diag_RequestCLISpawn();
289 [
Obsolete(
"Use SCR_RespawnComponent.RequestSpawn instead.")]
294 override void OnDiag(IEntity owner,
float timeSlice)
301 requestComponent.DrawDiag();
310 ConnectToDiagSystem(owner);
311 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_COMPONENT_DIAG,
"",
"Respawn Component",
"GameMode");
312 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_COMPONENT_TIME,
"",
"Respawn Time Measures",
"GameMode");
318 Print(
"SCR_RespawnComponent must be attached to PlayerController!", LogLevel.ERROR);
322 SCR_SpawnLockComponent lockComponent = SCR_SpawnLockComponent.Cast(owner.FindComponent(SCR_SpawnLockComponent));
325 Print(
string.Format(
"%1 does not have a %2 attached!",
326 Type().ToString(), SCR_SpawnLockComponent),
330 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
336 Print(
"No game mode found in the world, SCR_RespawnComponent will not function correctly!", LogLevel.ERROR);
344 DisconnectFromDiagSystem(owner);
346 super.OnDelete(owner);
367 if (!requestComponent)
369 Print(
string.Format(
"%1::RequestRespawn(data: %2) could not find associated %3!",
370 Type().ToString(),
data, SCR_SpawnRequestComponent), LogLevel.ERROR);
374 return requestComponent.RequestRespawn(
data);
395 if (!requestComponent)
397 Print(
string.Format(
"%1::RequestRespawn(data: %2) could not find associated %3!",
398 Type().ToString(),
data, SCR_SpawnRequestComponent), LogLevel.ERROR);
402 return requestComponent.CanRequestRespawn(
data);
410 array<GenericComponent> components = {};
411 FindComponents(SCR_SpawnRequestComponent, components);
412 foreach (GenericComponent genericComponent : components)
414 SCR_SpawnRequestComponent requestComponent = SCR_SpawnRequestComponent.Cast(genericComponent);
415 typename dataType = requestComponent.GetDataType();
418 Debug.Error(
string.Format(
"Cannot register %1! %2 already contains a mapping for %3 data type! (old: %4)",
419 requestComponent.Type().ToString(),
429 #ifdef _ENABLE_RESPAWN_LOGS
430 string typeName =
"null";
431 if (dataType !=
typename.Empty)
432 typeName = dataType.ToString();
433 Print(
string.Format(
"%1::RegisterRespawnRequestComponents() registered %2 component for requests of %3 type.", Type().ToString(),
434 requestComponent.Type().ToString(),
435 typeName), LogLevel.NORMAL);
449 SCR_SpawnRequestComponent component;
458 static bool Diag_IsCLISpawnEnabled()
460 return System.IsCLIParam(
"autodeployFaction") || System.IsCLIParam(
"autodeployLoadout") ||
461 System.IsCLIParam(
"tdmf") || System.IsCLIParam(
"tdml");
466 void Diag_RequestCLISpawn()
470 if (System.GetCLIParam(
"autodeployFaction", fs) || System.GetCLIParam(
"tdmf", fs))
472 Faction factionFromKey =
GetGame().GetFactionManager().GetFactionByKey(fs);
474 if (factionFromKey !=
null)
475 factionId =
GetGame().GetFactionManager().GetFactionIndex(factionFromKey);
477 factionId = fs.ToInt();
482 if (System.GetCLIParam(
"autodeployLoadout", fs) || System.GetCLIParam(
"tdml", ls))
486 if (loadoutFromKey !=
null)
487 loadoutId =
GetGame().GetLoadoutManager().GetLoadoutIndex(loadoutFromKey);
489 loadoutId = ls.ToInt();
492 Rpc(Rpc_RequestCLISpawn_S, factionId, loadoutId);
496 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
497 protected void Rpc_RequestCLISpawn_S(
int factionIdx,
int loadoutIdx)
500 Faction faction =
GetGame().GetFactionManager().GetFactionByIndex(factionIdx);
508 faction =
GetGame().GetFactionManager().GetFactionByKey(factionLoadout.GetFactionKey());
513 loadout =
GetGame().GetLoadoutManager().GetRandomFactionLoadout(faction);
516 if (factionComponent)
518 if (factionComponent.RequestFaction(faction))
523 if (loadoutComponent)
525 if (loadoutComponent.RequestLoadout(
loadout))
531 ResourceName resource =
loadout.GetLoadoutResource();
533 if (!resource.IsEmpty() && spawnPoint)
541 Rpc(Rpc_ResponseCLISpawn_O, ok);
545 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
546 protected void Rpc_ResponseCLISpawn_O(
int response)
548 bool faction = (response & (1 << 1));
549 bool loadout = (response & (1 << 2));
550 bool spawn = (response & (1 << 3));
552 string msg =
"Server request to spawn using diagnostics mode processed (-autodeployFaction/-autodeployLoadout), result:\n\tFaction: %1, Loadout: %2, Spawn: %3";
566 Print(
string.Format(msg, fs, ls, ss), LogLevel.NORMAL);