Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnLogic.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 /*
3  Authority:
4  Object responsible for defining respawn logic.
5 
6  This object receives callbacks from parent SCR_RespawnSystemComponent that can be used
7  to either spawn the player on the authority side or just notify the remote player that
8  they can process to spawn, or any combination based on derived implementations.
9 */
10 [BaseContainerProps(category: "Respawn")]
12 {
13  //------------------------------------------------------------------------------------------------
14  void OnInit(SCR_RespawnSystemComponent owner)
15  {
16  }
17 
18  //------------------------------------------------------------------------------------------------
19  void OnPlayerRegistered_S(int playerId)
20  {
21  #ifdef _ENABLE_RESPAWN_LOGS
22  PrintFormat("%1::OnPlayerRegistered_S(playerId: %2)", Type().ToString(), playerId);
23  #endif
24 
25  SCR_RespawnComponent respawnComponent = GetPlayerRespawnComponent_S(playerId);
26  respawnComponent.GetOnRespawnRequestInvoker_S().Insert(OnPlayerSpawnRequest_S);
27  respawnComponent.GetOnRespawnResponseInvoker_S().Insert(OnPlayerSpawnResponse_S);
28  }
29 
30  //------------------------------------------------------------------------------------------------
31  void OnPlayerDisconnected_S(int playerId, KickCauseCode cause, int timeout)
32  {
33  #ifdef _ENABLE_RESPAWN_LOGS
34  PrintFormat("%1::OnPlayerDisconnected_S(playerId: %2)", Type().ToString(), playerId);
35  #endif
36 
37  SCR_RespawnComponent respawnComponent = GetPlayerRespawnComponent_S(playerId);
38  respawnComponent.GetOnRespawnRequestInvoker_S().Remove(OnPlayerSpawnRequest_S);
39  respawnComponent.GetOnRespawnResponseInvoker_S().Remove(OnPlayerSpawnResponse_S);
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  void OnPlayerSpawnRequest_S(SCR_SpawnRequestComponent requestComponent)
44  {
45  #ifdef _ENABLE_RESPAWN_LOGS
46  PrintFormat("%1::OnPlayerSpawnRequest_S(playerId: %2)", Type().ToString(), requestComponent.GetPlayerId());
47  #endif
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  void OnPlayerSpawnResponse_S(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response)
52  {
53  #ifdef _ENABLE_RESPAWN_LOGS
54  PrintFormat("%1::OnPlayerSpawnResponse_S(playerId: %2, response: %3)",
55  Type().ToString(), requestComponent.GetPlayerId(), typename.EnumToString(SCR_ESpawnResult, response));
56  #endif
57 
58  if (response != SCR_ESpawnResult.OK)
59  OnPlayerSpawnFailed_S(requestComponent.GetPlayerId());
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected void OnPlayerSpawnFailed_S(int playerId)
64  {
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  void OnPlayerSpawned_S(int playerId, IEntity entity)
69  {
70  #ifdef _ENABLE_RESPAWN_LOGS
71  PrintFormat("%1::OnPlayerSpawned_S(playerId: %2, entity: %3)", Type().ToString(), playerId, entity);
72  #endif
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  void OnPlayerEntityChanged_S(int playerId, IEntity previousEntity, IEntity newEntity)
77  {
78  #ifdef _ENABLE_RESPAWN_LOGS
79  PrintFormat("%1::OnPlayerEntityChanged_S(playerId: %2, previousEntity: %3, newEntity: %4)",
80  Type().ToString(), playerId, previousEntity, newEntity);
81  #endif
82 
83  if (!newEntity)
84  OnPlayerEntityLost_S(playerId);
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  void OnPlayerKilled_S(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
89  {
90  #ifdef _ENABLE_RESPAWN_LOGS
91  PrintFormat("%1::OnPlayerKilled_S(playerId: %2, playerEntity: %3, killerEntity: %4, killerId: %5)",
92  Type().ToString(), playerId, playerEntity, killerEntity, killer.GetInstigatorPlayerID());
93  #endif
94 
95  OnPlayerEntityLost_S(playerId);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  void OnPlayerDeleted_S(int playerId)
100  {
101  #ifdef _ENABLE_RESPAWN_LOGS
102  PrintFormat("%1::OnPlayerDeleted_S(playerId: %2)", Type().ToString(), playerId);
103  #endif
104 
105  OnPlayerEntityLost_S(playerId);
106  }
107 
108  //------------------------------------------------------------------------------------------------
113  protected void OnPlayerEntityLost_S(int playerId)
114  {
115  #ifdef _ENABLE_RESPAWN_LOGS
116  PrintFormat("%1::OnPlayerEntityLost_S(playerId: %2)", Type().ToString(), playerId);
117  #endif
118  }
119 
120  //------------------------------------------------------------------------------------------------
125  protected void NotifyPlayerReadyForSpawn(int playerId)
126  {
127  GetPlayerRespawnComponent_S(playerId).NotifyReadyForSpawn_S();
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  /*
132  Probe the SCR_ReconnectComponent for player of given playerId.
133  If player is eligible for respawn using the reconnection method, true is returned.
134  */
135  bool IsEligibleForReconnection(int playerId)
136  {
137  SCR_ReconnectComponent reconnectComponent = SCR_ReconnectComponent.GetInstance();
138  if (!reconnectComponent || !reconnectComponent.IsReconnectEnabled())
139  return false;
140 
141  SCR_EReconnectState recState = reconnectComponent.IsInReconnectList(playerId);
142  if (recState == SCR_EReconnectState.NOT_RECONNECT)
143  return false;
144 
145  PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerId);
146  if (controller)
147  {
148  SCR_ReconnectSynchronizationComponent syncComp = SCR_ReconnectSynchronizationComponent.Cast(controller.FindComponent(SCR_ReconnectSynchronizationComponent));
149  if (syncComp)
150  syncComp.CreateReconnectDialog(recState);
151  }
152 
153  return recState == SCR_EReconnectState.ENTITY_AVAILABLE;
154  }
155 
156  //------------------------------------------------------------------------------------------------
164  protected bool ResolveReconnection(int playerId, out IEntity assignedEntity)
165  {
166  if (!IsEligibleForReconnection(playerId))
167  return false;
168 
169  #ifdef _ENABLE_RESPAWN_LOGS
170  PrintFormat("%1::ResolveReconnection(playerId: %2)", Type().ToString(), playerId);
171  #endif
172 
173  SCR_ReconnectComponent reconnectComponent = SCR_ReconnectComponent.GetInstance();
174  assignedEntity = reconnectComponent.ReturnControlledEntity(playerId);
175  return assignedEntity != null;
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  SCR_RespawnComponent GetPlayerRespawnComponent_S(int playerId)
180  {
181  return SCR_RespawnComponent.Cast(GetGame().GetPlayerManager().GetPlayerRespawnComponent(playerId));
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  SCR_RespawnComponent GetLocalPlayerRespawnComponent()
186  {
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  SCR_PlayerFactionAffiliationComponent GetPlayerFactionComponent_S(int playerId)
192  {
193  return SCR_PlayerFactionAffiliationComponent.Cast(GetGame().GetPlayerManager().GetPlayerController(playerId).FindComponent(SCR_PlayerFactionAffiliationComponent));
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  SCR_PlayerLoadoutComponent GetPlayerLoadoutComponent_S(int playerId)
198  {
199  return SCR_PlayerLoadoutComponent.Cast(GetGame().GetPlayerManager().GetPlayerController(playerId).FindComponent(SCR_PlayerLoadoutComponent));
200  }
201 };
SCR_PlayerLoadoutComponent
Definition: SCR_PlayerLoadoutComponent.c:16
SCR_RespawnComponent
void SCR_RespawnComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_RespawnComponent.c:576
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
GetRespawnComponent
proto external RespawnComponent GetRespawnComponent()
Definition: SCR_SpawnRequestComponent.c:45
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
Instigator
Definition: Instigator.c:6
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
SCR_SpawnLogic
Definition: SCR_SpawnLogic.c:11
SCR_ReconnectComponent
Definition: SCR_ReconnectComponent.c:41
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180