Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnPointSpawnHandlerComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Respawn/Handlers", description: "Allows the respawn system to utilize spawning on SpawnPoint(s). Requires a SCR_SpawnPointRespawnComponent attached to PlayerController.")]
3 {
4 }
5 
6 class SCR_SpawnPointSpawnHandlerComponent : SCR_SpawnHandlerComponent
7 {
8  protected SCR_PlayerSpawnPointManagerComponent m_PlayerSpawnPointManager;
9 
10  //------------------------------------------------------------------------------------------------
11  protected override void OnPostInit(IEntity owner)
12  {
13  super.OnPostInit(owner);
14  m_PlayerSpawnPointManager = SCR_PlayerSpawnPointManagerComponent.Cast(owner.FindComponent(SCR_PlayerSpawnPointManagerComponent));
15  }
16 
17  //------------------------------------------------------------------------------------------------
18  protected override bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
19  {
20  if (!super.ValidateData_S(requestComponent, data))
21  return false;
22 
24  if (!spawnPointData)
25  return false;
26 
27  // Spawn point must exist
28  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
29  if (!spawnPoint)
30  return false;
31 
32  // If player spawn points are used, verify against such type
34  {
35  // Of player spawn point type, but spawning of this kind is disallowed
36  SCR_PlayerSpawnPoint playerSpawnPoint = SCR_PlayerSpawnPoint.Cast(spawnPoint);
37  if (playerSpawnPoint && !m_PlayerSpawnPointManager.IsPlayerSpawnPointsEnabled())
38  return false;
39  }
40 
41  return true;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  override SCR_ESpawnResult HandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out IEntity spawnedEntity)
46  {
47  // Handle request as usual
48  SCR_ESpawnResult result = super.HandleRequest_S(requestComponent, data, spawnedEntity);
49  if (result != SCR_ESpawnResult.OK)
50  {
51  // But in case of failure, clear pending reservation
53  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
54  if (spawnPoint)
55  spawnPoint.ClearReservationFor_S(requestComponent.GetPlayerId());
56  }
57 
58  return result;
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected override bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
63  {
65  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
66  if (!spawnPoint)
67  {
68  result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED;
69  return false;
70  }
71 
72  // Cannot reserve = will not be able to spawn
73  if (!spawnPoint.CanReserveFor_S(requestComponent.GetPlayerId(), result))
74  {
75  //result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED;
76  return false;
77  }
78 
79  return super.CanRequestSpawn_S(requestComponent, data, result);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  protected override bool PrepareEntity_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data)
84  {
85  #ifdef _ENABLE_RESPAWN_LOGS
86  Print(string.Format("%1::PrepareEntity_S(playerId: %2, entity: %3, data: %4)", Type().ToString(),
87  requestComponent.GetPlayerController().GetPlayerId(),
88  entity,
89  data), LogLevel.NORMAL);
90  #endif
91 
93  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
94  if (!spawnPoint.PrepareSpawnedEntity_S(requestComponent, data, entity))
95  return false;
96 
97  return super.PrepareEntity_S(requestComponent, entity, data);
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  protected override SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
102  {
104  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
105  int playerId = requestComponent.GetPlayerId();
106 
107  // Lock spawn point
108  if (!spawnPoint.ReserveFor_S(playerId))
109  return SCR_ESpawnResult.SPAWN_NOT_ALLOWED;
110 
111  // Process spawn
112  SCR_ESpawnResult result = super.SpawnEntity_S(requestComponent, data, spawnedEntity);
113 
114  return result;
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override bool CanFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
119  {
121  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
122  if (!super.CanFinalize_S(requestComponent, data, entity))
123  return false;
124 
125  return spawnPoint.CanFinalizeSpawn_S(requestComponent, data, entity);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  override void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
130  {
132  SCR_SpawnPoint spawnPoint = spawnPointData.GetSpawnPoint();
133  spawnPoint.OnFinalizeSpawnDone_S(requestComponent, data, entity);
134 
135  // Clear reservation on spawn complete
136  spawnPoint.ClearReservationFor_S(requestComponent.GetPlayerId());
137  }
138 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
CanRequestSpawn_S
protected override bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:62
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
SCR_SpawnHandlerComponentClass
Definition: SCR_SpawnHandlerComponent.c:1
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
CanFinalize_S
override bool CanFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:118
SpawnEntity_S
protected override SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:101
m_PlayerSpawnPointManager
SCR_SpawnPointSpawnHandlerComponentClass m_PlayerSpawnPointManager
SCR_SpawnPointSpawnHandlerComponentClass
Definition: SCR_SpawnPointSpawnHandlerComponent.c:2
SCR_SpawnData
Definition: SCR_SpawnData.c:9
SCR_SpawnPointSpawnData
Definition: SCR_SpawnPointSpawnData.c:2
OnPostInit
protected override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_SpawnPointSpawnHandlerComponent.c:11
PrepareEntity_S
protected override bool PrepareEntity_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:83
OnFinalizeDone_S
override void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:129
ValidateData_S
protected override bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:18
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
HandleRequest_S
override SCR_ESpawnResult HandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out IEntity spawnedEntity)
Definition: SCR_SpawnPointSpawnHandlerComponent.c:45
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180