Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PossessSpawnHandlerComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Respawn/Handlers", description: "Allows the respawn system to utilize spawning on AI(s). Requires a SCR_OnAIRespawnComponent attached to PlayerController.")]
3 {
4 }
5 
6 class SCR_PossessSpawnHandlerComponent : SCR_SpawnHandlerComponent
7 {
8  [Attribute("1", desc: "When enabled, conditions like respawn time will not be checked.")]
9  protected bool m_bIgnoreConditions;
10 
11  //------------------------------------------------------------------------------------------------
12  protected override SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
13  {
14  int playerId = requestComponent.GetPlayerController().GetPlayerId();
15  #ifdef _ENABLE_RESPAWN_LOGS
16  Print(string.Format("%1::SpawnEntity(playerId: %2, data: %3)", Type().ToString(),
17  playerId,
18  data), LogLevel.NORMAL);
19  #endif
20 
21  // We simply use the entity without spawning it
22  spawnedEntity = GetEntity(data);
23  if (!spawnedEntity)
24  return SCR_ESpawnResult.CANNOT_VALIDATE;
25 
26  if (!PrepareEntity_S(requestComponent, spawnedEntity, data))
27  return SCR_ESpawnResult.CANNOT_PREPARE;
28 
29  return SCR_ESpawnResult.OK;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  override SCR_ESpawnResult CanHandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
34  {
35  SCR_ESpawnResult result = super.CanHandleRequest_S(requestComponent, data);
36  if (result != SCR_ESpawnResult.OK)
37  return result;
38 
39  IEntity entity = GetEntity(data);
40  if (!entity)
41  return SCR_ESpawnResult.CANNOT_VALIDATE;
42 
43  // Also for now allow only characters, for.. reasons
44  ChimeraCharacter character = ChimeraCharacter.Cast(entity);
45  if (!character)
46  return SCR_ESpawnResult.CANNOT_POSSES;
47 
48  // And alive, if possible
49  if (character.GetCharacterController().IsDead())
50  return SCR_ESpawnResult.CANNOT_POSSES;
51 
52  // Ensure that entity to be possessed is not already possessed
53  int controllingPlayerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(entity);
54  if (controllingPlayerId != 0)
55  return SCR_ESpawnResult.CANNOT_POSSES;
56 
57  return SCR_ESpawnResult.OK;
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  protected IEntity GetEntity(SCR_SpawnData data)
62  {
64  if (!possessData)
65  return null;
66 
67  RplComponent rplComponent = RplComponent.Cast(Replication.FindItem(possessData.GetRplId()));
68  if (!rplComponent)
69  return null;
70 
71  return rplComponent.GetEntity();
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  override protected bool ShouldDeleteEntityOnSpawnFailure_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
76  {
77  return false;
78  }
79 
80  //------------------------------------------------------------------------------------------------
84  protected override bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
85  {
86  if (!super.ValidateData_S(requestComponent, data))
87  return false;
88 
90  if (!possessData || !possessData.GetRplId().IsValid())
91  return false;
92 
93  Managed rplComponent = Replication.FindItem(possessData.GetRplId());
94  return rplComponent != null;
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  override bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
99  {
100  return m_bIgnoreConditions || super.CanRequestSpawn_S(requestComponent, data, result);
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  override void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
105  {
106  // Assign possessed entity's faction to the player
107  PlayerController pc = requestComponent.GetPlayerController();
109  Faction targetFaction = GetFactionFromPrefab(entity.GetPrefabData().GetPrefabName());
110  if (!targetFaction || targetFaction == playerFactionComp.GetAffiliatedFaction())
111  return;
112 
113  playerFactionComp.SetAffiliatedFaction(targetFaction);
114 
115  // Notify faction manager
116  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
117  factionManager.UpdatePlayerFaction_S(playerFactionComp);
118 
119  // Notify game mode
121  gameMode.OnPlayerFactionSet_S(playerFactionComp, targetFaction);
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  protected Faction GetFactionFromPrefab(ResourceName prefab)
126  {
127  Resource res = Resource.Load(prefab);
128  IEntityComponentSource src = SCR_BaseContainerTools.FindComponentSource(res, FactionAffiliationComponent);
129  if (!src)
130  return null;
131 
132  string factionKey;
133  src.Get("faction affiliation", factionKey);
134 
135  return GetGame().GetFactionManager().GetFactionByKey(factionKey);
136  }
137 }
GetEntity
protected IEntity GetEntity(SCR_SpawnData data)
Definition: SCR_PossessSpawnHandlerComponent.c:61
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
CanRequestSpawn_S
override bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
Definition: SCR_PossessSpawnHandlerComponent.c:98
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SpawnHandlerComponentClass
Definition: SCR_SpawnHandlerComponent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
SCR_PossessSpawnHandlerComponentClass SCR_SpawnHandlerComponentClass Attribute("1", desc:"When enabled, conditions like respawn time will not be checked.")] protected bool m_bIgnoreConditions
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_SpawnData
Definition: SCR_SpawnData.c:9
SCR_PossessSpawnHandlerComponentClass
Definition: SCR_PossessSpawnHandlerComponent.c:2
ValidateData_S
protected override bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
Definition: SCR_PossessSpawnHandlerComponent.c:84
ShouldDeleteEntityOnSpawnFailure_S
override protected bool ShouldDeleteEntityOnSpawnFailure_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
Definition: SCR_PossessSpawnHandlerComponent.c:75
SCR_BaseContainerTools
Definition: SCR_BaseContainerTools.c:3
Faction
Definition: Faction.c:12
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
PrepareEntity_S
protected bool PrepareEntity_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data)
Definition: SCR_SpawnHandlerComponent.c:302
OnFinalizeDone_S
override void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_PossessSpawnHandlerComponent.c:104
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_PossessSpawnData
Definition: SCR_PossessSpawnData.c:2
SpawnEntity_S
protected override SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
Definition: SCR_PossessSpawnHandlerComponent.c:12
CanHandleRequest_S
override SCR_ESpawnResult CanHandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
Definition: SCR_PossessSpawnHandlerComponent.c:33
GetFactionFromPrefab
protected Faction GetFactionFromPrefab(ResourceName prefab)
Definition: SCR_PossessSpawnHandlerComponent.c:125
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180