Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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.")]
5
6class 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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
SCR_ESpawnResult
Get all prefabs that have the spawner data
void SCR_FactionManager(IEntitySource src, IEntity parent)
Faction GetFactionFromPrefab(ResourceName prefab)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
SCR_ESpawnResult CanHandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
bool ShouldDeleteEntityOnSpawnFailure_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
bool PrepareEntity_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data)
int Type
proto external EntityPrefabData GetPrefabData()
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void OnPlayerFactionSet_S(SCR_PlayerFactionAffiliationComponent factionComponent, Faction faction)
IEntity GetEntity()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.