Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RespawnSystemComponent.c
Go to the documentation of this file.
2{
3}
4
8class SCR_RespawnSystemComponent : RespawnSystemComponent
9{
10 [Attribute(category: "Respawn System")]
11 protected ref SCR_SpawnLogic m_SpawnLogic;
12
13 [Attribute("1", uiwidget: UIWidgets.CheckBox, category: "Respawn System")]
14 protected bool m_bEnableRespawn;
15
16 [Attribute("1", desc: "Handles visibility of the Respawn button in Pause menu.", category: "Respawn System")]
17 protected bool m_bEnablePauseMenuRespawn;
18
19 [Attribute("{A1CE9D1EC16DA9BE}UI/layouts/Menus/MainMenu/SplashScreen.layout", desc: "Optional: Layout shown during world load completion and respawn menu opening or automatically completing.", category: "Respawn System")]
20 protected ResourceName m_sLoadingLayout;
21
22 [Attribute("{A39BE59EB6F41125}Configs/Respawn/SpawnPointRequestResultInfoConfig.conf", desc: "Holds a config of all reasons why a specific spawnpoint can be disabled", category: "Respawn System")]
23 protected ResourceName m_sSpawnPointRequestResultInfoHolder;
24
25 protected ref SCR_SpawnPointRequestResultInfoConfig m_SpawnPointRequestResultInfoHolder;
26
27 // Instance of this component
28 private static SCR_RespawnSystemComponent s_Instance = null;
29
30 // The parent of this entity which should be a gamemode
32
33 // Parent entity's rpl component
34 protected RplComponent m_RplComponent;
35
36 // Preload
37 protected ref SimplePreload m_Preload;
38 protected ref ScriptInvoker Event_OnRespawnEnabledChanged;
39
40 // Loading placeholder
41 protected bool m_bAudioMuted;
42 protected Widget m_wLoadingPlaceholder;
44
45 //------------------------------------------------------------------------------------------------
50 SCR_BaseSpawnPointRequestResultInfo GetSpawnPointRequestResultInfo(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response, SCR_SpawnData data)
51 {
52 if (!m_SpawnPointRequestResultInfoHolder)
53 return null;
54
55 return m_SpawnPointRequestResultInfoHolder.GetFirstValidRequestResultInfo(requestComponent, response, data);
56 }
57
58 //------------------------------------------------------------------------------------------------
60 static SCR_RespawnSystemComponent GetInstance()
61 {
62 if (!s_Instance)
63 {
64 BaseGameMode pGameMode = GetGame().GetGameMode();
65 if (pGameMode)
66 s_Instance = SCR_RespawnSystemComponent.Cast(pGameMode.FindComponent(SCR_RespawnSystemComponent));
67 }
68
69 return s_Instance;
70 }
71
72 //------------------------------------------------------------------------------------------------
74 RplComponent GetRplComponent()
75 {
76 return m_RplComponent;
77 }
78
79 //------------------------------------------------------------------------------------------------
81 static MenuBase OpenRespawnMenu()
82 {
83 MenuManager pMenuManager = GetGame().GetMenuManager();
84 if (!pMenuManager)
85 return null;
86
87 return pMenuManager.OpenMenu(ChimeraMenuPreset.RespawnSuperMenu);
88 }
89
90 //------------------------------------------------------------------------------------------------
92 static void CloseRespawnMenu()
93 {
94 MenuManager pMenuManager = GetGame().GetMenuManager();
95 if (!pMenuManager)
96 return;
97
98 MenuBase menu = pMenuManager.FindMenuByPreset(ChimeraMenuPreset.RespawnSuperMenu);
99 if (menu)
100 pMenuManager.CloseMenu(menu);
101 }
102
103 //------------------------------------------------------------------------------------------------
106 void ServerSetEnableRespawn(bool enableSpawning)
107 {
108 if (enableSpawning == m_bEnableRespawn || !Replication.IsServer())
109 return;
110
111 SetEnableRespawnBroadcast(enableSpawning);
112 Rpc(SetEnableRespawnBroadcast, enableSpawning);
113 }
114
115 //------------------------------------------------------------------------------------------------
118 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
119 protected void SetEnableRespawnBroadcast(bool enableSpawning)
120 {
121 m_bEnableRespawn = enableSpawning;
122 if (Event_OnRespawnEnabledChanged)
123 Event_OnRespawnEnabledChanged.Invoke(m_bEnableRespawn);
124 }
125
126 //------------------------------------------------------------------------------------------------
128 bool IsRespawnEnabled()
129 {
130 return m_bEnableRespawn;
131 }
132
133 //------------------------------------------------------------------------------------------------
135 bool IsPauseMenuRespawnEnabled()
136 {
137 return m_bEnablePauseMenuRespawn;
138 }
139
140 //------------------------------------------------------------------------------------------------
142 bool IsFactionChangeAllowed()
143 {
144 return m_pGameMode.IsFactionChangeAllowed();
145 }
146
147 //------------------------------------------------------------------------------------------------
149 ScriptInvoker GetOnRespawnEnabledChanged()
150 {
151 if (!Event_OnRespawnEnabledChanged)
152 Event_OnRespawnEnabledChanged = new ScriptInvoker();
153
154 return Event_OnRespawnEnabledChanged;
155 }
156
157 //------------------------------------------------------------------------------------------------
167 bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
168 {
169 #ifdef _ENABLE_RESPAWN_LOGS
170 Print(string.Format("%1::CanRequestSpawn_S(playerId: %2, handler: %2, data: %3)", Type().ToString(),
171 requestComponent.GetPlayerId(),
172 handlerComponent,
173 data), LogLevel.NORMAL);
174 #endif
175
176 if (!m_bEnableRespawn)
177 {
178 result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNING_DISABLED;
179 return false;
180 }
181
182 return m_pGameMode.CanPlayerSpawn_S(requestComponent, handlerComponent, data, result);
183 }
184
185 //------------------------------------------------------------------------------------------------
197 bool PreparePlayerEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
198 {
199 return m_pGameMode.PreparePlayerEntity_S(requestComponent, handlerComponent, data, entity);
200 }
201
202 //------------------------------------------------------------------------------------------------
212 void OnPlayerEntityChange_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity previousEntity, IEntity newEntity, SCR_SpawnData data)
213 {
214 EmitPlayerEntityChange_S(requestComponent.GetPlayerId(), previousEntity, newEntity)
215 }
216
217 //------------------------------------------------------------------------------------------------
218 void EmitPlayerEntityChange_S(int playerId, IEntity previousEntity, IEntity newEntity)
219 {
220 m_pGameMode.OnPlayerEntityChanged_S(playerId, previousEntity, newEntity);
221 m_SpawnLogic.OnPlayerEntityChanged_S(playerId, previousEntity, newEntity);
222 }
223
224 //------------------------------------------------------------------------------------------------
227 void OnSpawnPlayerEntityFailure_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
228 {
229 m_pGameMode.OnSpawnPlayerEntityFailure_S(requestComponent, handlerComponent, entity, data, reason);
230 }
231
232 //------------------------------------------------------------------------------------------------
241 void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
242 {
243 m_pGameMode.OnPlayerSpawnFinalize_S(requestComponent, handlerComponent, data, entity);
244 m_SpawnLogic.OnPlayerSpawned_S(requestComponent.GetPlayerId(), entity);
245 }
246
247 //------------------------------------------------------------------------------------------------
249 void OnPlayerRegistered_S(int playerId)
250 {
251 m_SpawnLogic.OnPlayerRegistered_S(playerId);
252 }
253
254 //------------------------------------------------------------------------------------------------
256 void OnPlayerAuditSuccess_S(int playerId)
257 {
258 m_SpawnLogic.OnPlayerAuditSuccess_S(playerId);
259 }
260
261 //------------------------------------------------------------------------------------------------
265 void OnPlayerDisconnected_S(int playerId, KickCauseCode cause, int timeout)
266 {
267 m_SpawnLogic.OnPlayerDisconnected_S(playerId, cause, timeout);
268 }
269
270 //------------------------------------------------------------------------------------------------
275 void OnPlayerKilled_S(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
276 {
277 m_SpawnLogic.OnPlayerKilled_S(playerId, playerEntity, killerEntity, killer);
278 }
279
280 //------------------------------------------------------------------------------------------------
282 void OnPlayerDeleted_S(int playerId)
283 {
284 const bool isDisconnect = !GetGame().GetPlayerManager().IsPlayerConnected(playerId);
285 m_SpawnLogic.OnPlayerDeleted_S(playerId, isDisconnect);
286 }
287
288 //------------------------------------------------------------------------------------------------
291 void OnPlayerEntityCleanup_S(notnull IEntity playerEntity)
292 {
293 m_SpawnLogic.OnPlayerEntityCleanup_S(playerEntity);
294 }
295
296 //------------------------------------------------------------------------------------------------
298 SCR_SpawnLogic GetSpawnLogic()
299 {
300 return m_SpawnLogic;
301 }
302
303 //------------------------------------------------------------------------------------------------
304 override void OnInit(IEntity owner)
305 {
306 m_SpawnPointRequestResultInfoHolder = SCR_ConfigHelperT<SCR_SpawnPointRequestResultInfoConfig>.GetConfigObject(m_sSpawnPointRequestResultInfoHolder);
307 if (!m_SpawnPointRequestResultInfoHolder)
308 Print("'SCR_RespawnSystemComponent' has no valid m_SpawnPointRequestResultInfoHolder! This means the disabled reason cannot be disabled spawn point!", LogLevel.ERROR);
309
310 m_pGameMode = SCR_BaseGameMode.Cast(owner);
311 if (!m_pGameMode)
312 Print("SCR_RespawnSystemComponent has to be attached to a SCR_BaseGameMode (or inherited) entity!", LogLevel.ERROR);
313 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
314
315 if (!m_SpawnLogic)
316 Print("SCR_RespawnSystemComponent is missing SCR_SpawnLogic!", LogLevel.ERROR);
317
318 if (GetGame().InPlayMode())
319 {
320 m_SpawnLogic.OnInit(this);
321
322 // Validate faction manager
323 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
324 if (!factionManager)
325 {
326 string text = string.Format("No %1 found in the world, %2 might not work as intended!",
327 SCR_FactionManager, SCR_RespawnSystemComponent);
328 Print(text, LogLevel.WARNING);
329 }
330
331 // Validate loadout manager
332 SCR_LoadoutManager loadoutManager = GetGame().GetLoadoutManager();
333 if (!loadoutManager)
334 {
335 string text = string.Format("No %1 found in the world, %2 might not work as intended!",
336 SCR_LoadoutManager, SCR_RespawnSystemComponent);
337 Print(text, LogLevel.WARNING);
338 }
339
340 if (!System.IsConsoleApp())
341 CreateLoadingPlaceholder();
342 }
343 }
344
345 //------------------------------------------------------------------------------------------------
346 protected override event bool OnRplSave(ScriptBitWriter w)
347 {
348 w.WriteBool(m_bEnableRespawn);
349
350 return super.OnRplSave(w);
351 }
352
353 //------------------------------------------------------------------------------------------------
354 protected override event bool OnRplLoad(ScriptBitReader r)
355 {
356 bool enableRespawn;
357 r.ReadBool(enableRespawn);
358
359 SetEnableRespawnBroadcast(enableRespawn);
360
361 return super.OnRplLoad(r);
362 }
363
364 //------------------------------------------------------------------------------------------------
365 protected void CreateLoadingPlaceholder()
366 {
367 if (!UsesLoadingPlaceholder())
368 return;
369
370 m_wLoadingPlaceholder = GetGame().GetWorkspace().CreateWidgets(m_sLoadingLayout);
371 if (!m_wLoadingPlaceholder)
372 return;
373
374 AudioSystem.Pause(1 << AudioSystem.SFX);
375 m_bAudioMuted = true;
376
377 const Widget spinner = m_wLoadingPlaceholder.FindAnyWidget("Spinner");
378 if (spinner)
379 m_LoadingSpinner = SCR_LoadingSpinner.Cast(spinner.FindHandler(SCR_LoadingSpinner));
380 }
381
382 //------------------------------------------------------------------------------------------------
383 bool UsesLoadingPlaceholder()
384 {
385 return !m_sLoadingLayout.IsEmpty();
386 }
387
388 //------------------------------------------------------------------------------------------------
389 void UpdateLoadingPlaceholder(float dt)
390 {
391 if (!m_wLoadingPlaceholder)
392 return;
393
394 const bool placeHolderVisible = !GetGame().IsPlayingCinematic();
395 m_wLoadingPlaceholder.SetVisible(placeHolderVisible);
396
397 if (placeHolderVisible && !m_bAudioMuted)
398 {
399 AudioSystem.Pause(1 << AudioSystem.SFX);
400 m_bAudioMuted = true;
401 }
402 else if (!placeHolderVisible && m_bAudioMuted)
403 {
404 AudioSystem.Resume(1 << AudioSystem.SFX);
405 m_bAudioMuted = false;
406 }
407
410 }
411
412 //------------------------------------------------------------------------------------------------
413 void DestroyLoadingPlaceholder()
414 {
415 if (m_bAudioMuted) // Unmute audio regardless of widget in case it was implicitly destoryed early.
416 {
417 AudioSystem.Resume(1 << AudioSystem.SFX);
418 m_bAudioMuted = false;
419 }
420
421 if (!m_wLoadingPlaceholder)
422 return;
423
424 m_wLoadingPlaceholder.RemoveFromHierarchy();
425 m_wLoadingPlaceholder = null;
426 m_LoadingSpinner = null;
427 }
428
429 //------------------------------------------------------------------------------------------------
430 // destructor
431 void ~SCR_RespawnSystemComponent()
432 {
433 DestroyLoadingPlaceholder();
434 s_Instance = null;
435 }
436}
ChimeraMenuPreset
Menu presets.
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameModeComponentClass m_pGameMode
The game mode entity this component is attached to.
bool PreparePlayerEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
RplComponent m_RplComponent
override bool OnRplSave(ScriptBitWriter writer)
override bool OnRplLoad(ScriptBitReader reader)
SCR_LoadingSpinner m_LoadingSpinner
SCR_ESpawnResult
Get all prefabs that have the spawner data
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_LoadoutManager(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_RespawnSystemComponentClass RespawnSystemComponentClass ComponentEditorProps(icon:HYBRID_COMPONENT_ICON)
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
override void OnSpawnPlayerEntityFailure_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
int Type
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external MenuBase FindMenuByPreset(ScriptMenuPresetEnum preset)
Finds first menu/dialog with given preset index, or nullptr when there is no such menu opened.
proto external bool CloseMenu(MenuBase menu)
Put menu into queue for closing (which is processed during next MenuManeger update).
proto external MenuBase OpenMenu(ScriptMenuPresetEnum preset, int userId=0, bool unique=false, bool hideParentMenu=true)
void Update(float deltaTime)
override void OnPlayerAuditSuccess_S(int playerId)
HYBRID_COMPONENT_ICON
Default icon for all components written in script that don't inherit ScriptComponent.
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
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134