1
1
using System . Linq ;
2
2
using System . Numerics ;
3
3
using Content . Server . Administration ;
4
+ using Content . Server . Chat . Managers ;
4
5
using Content . Server . DeviceNetwork . Components ;
5
6
using Content . Server . DeviceNetwork . Systems ;
6
7
using Content . Server . GameTicking ;
16
17
using Content . Server . Station . Systems ;
17
18
using Content . Shared . Administration ;
18
19
using Content . Shared . CCVar ;
20
+ using Content . Shared . Damage . Components ;
19
21
using Content . Shared . DeviceNetwork ;
22
+ using Content . Shared . GameTicking ;
20
23
using Content . Shared . Mobs . Components ;
21
24
using Content . Shared . Movement . Components ;
22
25
using Content . Shared . Parallax . Biomes ;
23
26
using Content . Shared . Roles ;
24
- using Content . Shared . Preferences ;
25
27
using Content . Shared . Salvage ;
26
28
using Content . Shared . Shuttles . Components ;
27
29
using Content . Shared . Tiles ;
30
32
using Robust . Shared . Configuration ;
31
33
using Robust . Shared . Console ;
32
34
using Robust . Shared . Map ;
35
+ using Robust . Shared . Player ;
33
36
using Robust . Shared . Prototypes ;
34
37
using Robust . Shared . Random ;
35
38
using Robust . Shared . Timing ;
@@ -45,17 +48,20 @@ public sealed class ArrivalsSystem : EntitySystem
45
48
[ Dependency ] private readonly IConfigurationManager _cfgManager = default ! ;
46
49
[ Dependency ] private readonly IConsoleHost _console = default ! ;
47
50
[ Dependency ] private readonly IGameTiming _timing = default ! ;
48
- [ Dependency ] private readonly IMapManager _mapManager = default ! ;
49
51
[ Dependency ] private readonly IPrototypeManager _protoManager = default ! ;
50
52
[ Dependency ] private readonly IRobustRandom _random = default ! ;
53
+ [ Dependency ] private readonly IChatManager _chat = default ! ;
54
+ [ Dependency ] private readonly SharedMapSystem _mapSystem = default ! ;
51
55
[ Dependency ] private readonly BiomeSystem _biomes = default ! ;
52
56
[ Dependency ] private readonly GameTicker _ticker = default ! ;
53
57
[ Dependency ] private readonly MapLoaderSystem _loader = default ! ;
58
+ [ Dependency ] private readonly MetaDataSystem _metaData = default ! ;
54
59
[ Dependency ] private readonly DeviceNetworkSystem _deviceNetworkSystem = default ! ;
55
60
[ Dependency ] private readonly SharedTransformSystem _transform = default ! ;
56
61
[ Dependency ] private readonly ShuttleSystem _shuttles = default ! ;
57
62
[ Dependency ] private readonly StationSpawningSystem _stationSpawning = default ! ;
58
63
[ Dependency ] private readonly StationSystem _station = default ! ;
64
+ [ Dependency ] private readonly ActorSystem _actor = default ! ;
59
65
60
66
private EntityQuery < PendingClockInComponent > _pendingQuery ;
61
67
private EntityQuery < ArrivalsBlacklistComponent > _blacklistQuery ;
@@ -87,7 +93,7 @@ public override void Initialize()
87
93
{
88
94
base . Initialize ( ) ;
89
95
90
- SubscribeLocalEvent < PlayerSpawningEvent > ( HandlePlayerSpawning , before : new [ ] { typeof ( ContainerSpawnPointSystem ) , typeof ( SpawnPointSystem ) } ) ;
96
+ SubscribeLocalEvent < PlayerSpawningEvent > ( HandlePlayerSpawning , before : new [ ] { typeof ( SpawnPointSystem ) } , after : new [ ] { typeof ( ContainerSpawnPointSystem ) } ) ;
91
97
92
98
SubscribeLocalEvent < StationArrivalsComponent , StationPostInitEvent > ( OnStationPostInit ) ;
93
99
@@ -98,6 +104,8 @@ public override void Initialize()
98
104
SubscribeLocalEvent < ArrivalsShuttleComponent , FTLStartedEvent > ( OnArrivalsFTL ) ;
99
105
SubscribeLocalEvent < ArrivalsShuttleComponent , FTLCompletedEvent > ( OnArrivalsDocked ) ;
100
106
107
+ SubscribeLocalEvent < PlayerSpawnCompleteEvent > ( SendDirections ) ;
108
+
101
109
_pendingQuery = GetEntityQuery < PendingClockInComponent > ( ) ;
102
110
_blacklistQuery = GetEntityQuery < ArrivalsBlacklistComponent > ( ) ;
103
111
_mobQuery = GetEntityQuery < MobStateComponent > ( ) ;
@@ -263,6 +271,9 @@ private void OnArrivalsFTL(EntityUid shuttleUid, ArrivalsShuttleComponent compon
263
271
// The player has successfully left arrivals and is also not on the shuttle. Remove their warp coupon.
264
272
RemCompDeferred < PendingClockInComponent > ( pUid ) ;
265
273
RemCompDeferred < AutoOrientComponent > ( pUid ) ;
274
+
275
+ if ( ArrivalsGodmode )
276
+ RemCompDeferred < GodmodeComponent > ( pUid ) ;
266
277
}
267
278
}
268
279
@@ -287,16 +298,20 @@ private void OnArrivalsDocked(EntityUid uid, ArrivalsShuttleComponent component,
287
298
private void DumpChildren ( EntityUid uid , ref FTLStartedEvent args )
288
299
{
289
300
var toDump = new List < Entity < TransformComponent > > ( ) ;
290
- DumpChildren ( uid , ref args , toDump ) ;
301
+ FindDumpChildren ( uid , toDump ) ;
291
302
foreach ( var ( ent , xform ) in toDump )
292
303
{
293
304
var rotation = xform . LocalRotation ;
294
305
_transform . SetCoordinates ( ent , new EntityCoordinates ( args . FromMapUid ! . Value , Vector2 . Transform ( xform . LocalPosition , args . FTLFrom ) ) ) ;
295
306
_transform . SetWorldRotation ( ent , args . FromRotation + rotation ) ;
307
+ if ( _actor . TryGetSession ( ent , out var session ) )
308
+ {
309
+ _chat . DispatchServerMessage ( session ! , Loc . GetString ( "latejoin-arrivals-dumped-from-shuttle" ) ) ;
310
+ }
296
311
}
297
312
}
298
313
299
- private void DumpChildren ( EntityUid uid , ref FTLStartedEvent args , List < Entity < TransformComponent > > toDump )
314
+ private void FindDumpChildren ( EntityUid uid , List < Entity < TransformComponent > > toDump )
300
315
{
301
316
if ( _pendingQuery . HasComponent ( uid ) )
302
317
return ;
@@ -312,7 +327,7 @@ private void DumpChildren(EntityUid uid, ref FTLStartedEvent args, List<Entity<T
312
327
var children = xform . ChildEnumerator ;
313
328
while ( children . MoveNext ( out var child ) )
314
329
{
315
- DumpChildren ( child , ref args , toDump ) ;
330
+ FindDumpChildren ( child , toDump ) ;
316
331
}
317
332
}
318
333
@@ -321,8 +336,7 @@ public void HandlePlayerSpawning(PlayerSpawningEvent ev)
321
336
if ( ev . SpawnResult != null )
322
337
return ;
323
338
324
- if ( ev . HumanoidCharacterProfile ? . SpawnPriority != SpawnPriorityPreference . Arrivals )
325
- return ;
339
+ // We use arrivals as the default spawn so don't check for job prio.
326
340
327
341
// Only works on latejoin even if enabled.
328
342
if ( ! Enabled || _ticker . RunLevel != GameRunLevel . InRound )
@@ -333,39 +347,56 @@ public void HandlePlayerSpawning(PlayerSpawningEvent ev)
333
347
&& _protoManager . Index < JobPrototype > ( ev . Job . Prototype . Value . Id ) . AlwaysUseSpawner )
334
348
return ;
335
349
336
-
337
350
if ( ! HasComp < StationArrivalsComponent > ( ev . Station ) )
338
351
return ;
339
352
340
353
TryGetArrivals ( out var arrivals ) ;
341
354
342
- if ( TryComp < TransformComponent > ( arrivals , out var arrivalsXform ) )
343
- {
344
- var mapId = arrivalsXform . MapID ;
355
+ if ( ! TryComp ( arrivals , out TransformComponent ? arrivalsXform ) )
356
+ return ;
345
357
346
- var points = EntityQueryEnumerator < SpawnPointComponent , TransformComponent > ( ) ;
347
- var possiblePositions = new List < EntityCoordinates > ( ) ;
348
- while ( points . MoveNext ( out var uid , out var spawnPoint , out var xform ) )
349
- {
350
- if ( spawnPoint . SpawnType != SpawnPointType . LateJoin || xform . MapID != mapId )
351
- continue ;
358
+ var mapId = arrivalsXform . MapID ;
352
359
353
- possiblePositions . Add ( xform . Coordinates ) ;
354
- }
360
+ var points = EntityQueryEnumerator < SpawnPointComponent , TransformComponent > ( ) ;
361
+ var possiblePositions = new List < EntityCoordinates > ( ) ;
362
+ while ( points . MoveNext ( out var uid , out var spawnPoint , out var xform ) )
363
+ {
364
+ if ( spawnPoint . SpawnType != SpawnPointType . LateJoin || xform . MapID != mapId )
365
+ continue ;
355
366
356
- if ( possiblePositions . Count > 0 )
357
- {
358
- var spawnLoc = _random . Pick ( possiblePositions ) ;
359
- ev . SpawnResult = _stationSpawning . SpawnPlayerMob (
360
- spawnLoc ,
361
- ev . Job ,
362
- ev . HumanoidCharacterProfile ,
363
- ev . Station ) ;
364
-
365
- EnsureComp < PendingClockInComponent > ( ev . SpawnResult . Value ) ;
366
- EnsureComp < AutoOrientComponent > ( ev . SpawnResult . Value ) ;
367
- }
367
+ possiblePositions . Add ( xform . Coordinates ) ;
368
368
}
369
+
370
+ if ( possiblePositions . Count <= 0 )
371
+ return ;
372
+
373
+ var spawnLoc = _random . Pick ( possiblePositions ) ;
374
+ ev . SpawnResult = _stationSpawning . SpawnPlayerMob (
375
+ spawnLoc ,
376
+ ev . Job ,
377
+ ev . HumanoidCharacterProfile ,
378
+ ev . Station ) ;
379
+
380
+ EnsureComp < PendingClockInComponent > ( ev . SpawnResult . Value ) ;
381
+ EnsureComp < AutoOrientComponent > ( ev . SpawnResult . Value ) ;
382
+
383
+ // If you're forced to spawn, you're invincible until you leave wherever you were forced to spawn.
384
+ if ( ArrivalsGodmode )
385
+ EnsureComp < GodmodeComponent > ( ev . SpawnResult . Value ) ;
386
+ }
387
+
388
+ private void SendDirections ( PlayerSpawnCompleteEvent ev )
389
+ {
390
+ if ( ! Enabled || ! ev . LateJoin || ! _pendingQuery . HasComp ( ev . Mob ) )
391
+ return ;
392
+
393
+ var arrival = NextShuttleArrival ( ) ;
394
+
395
+ var message = arrival is not null
396
+ ? Loc . GetString ( "latejoin-arrivals-direction-time" , ( "time" , $ "{ arrival : mm\\:ss} ") )
397
+ : Loc . GetString ( "latejoin-arrivals-direction" ) ;
398
+
399
+ _chat . DispatchServerMessage ( ev . Player , message ) ;
369
400
}
370
401
371
402
private bool TryTeleportToMapSpawn ( EntityUid player , EntityUid stationId , TransformComponent ? transform = null )
@@ -391,6 +422,10 @@ private bool TryTeleportToMapSpawn(EntityUid player, EntityUid stationId, Transf
391
422
{
392
423
// Move the player to a random late-join spawnpoint.
393
424
_transform . SetCoordinates ( player , transform , _random . Pick ( possiblePositions ) ) ;
425
+ if ( _actor . TryGetSession ( player , out var session ) )
426
+ {
427
+ _chat . DispatchServerMessage ( session ! , Loc . GetString ( "latejoin-arrivals-teleport-to-spawn" ) ) ;
428
+ }
394
429
return true ;
395
430
}
396
431
@@ -436,7 +471,7 @@ public override void Update(float frameTime)
436
471
var curTime = _timing . CurTime ;
437
472
TryGetArrivals ( out var arrivals ) ;
438
473
439
- if ( TryComp < TransformComponent > ( arrivals , out var arrivalsXform ) )
474
+ if ( TryComp ( arrivals , out TransformComponent ? arrivalsXform ) )
440
475
{
441
476
while ( query . MoveNext ( out var uid , out var comp , out var shuttle , out var xform ) )
442
477
{
@@ -449,7 +484,7 @@ public override void Update(float frameTime)
449
484
if ( xform . MapUid != arrivalsXform . MapUid )
450
485
{
451
486
if ( arrivals . IsValid ( ) )
452
- _shuttles . FTLToDock ( uid , shuttle , arrivals , _cfgManager . GetCVar ( CCVars . ArrivalsStartupTime ) , _cfgManager . GetCVar ( CCVars . ArrivalsHyperspaceTime ) , "DockArrivals" ) ;
487
+ _shuttles . FTLToDock ( uid , shuttle , arrivals ) ;
453
488
454
489
comp . NextArrivalsTime = _timing . CurTime + TimeSpan . FromSeconds ( tripTime ) ;
455
490
}
@@ -459,7 +494,7 @@ public override void Update(float frameTime)
459
494
var targetGrid = _station . GetLargestGrid ( data ) ;
460
495
461
496
if ( targetGrid != null )
462
- _shuttles . FTLToDock ( uid , shuttle , targetGrid . Value , _cfgManager . GetCVar ( CCVars . ArrivalsStartupTime ) , _cfgManager . GetCVar ( CCVars . ArrivalsHyperspaceTime ) , "DockArrivals" ) ;
497
+ _shuttles . FTLToDock ( uid , shuttle , targetGrid . Value ) ;
463
498
464
499
// The ArrivalsCooldown includes the trip there, so we only need to add the time taken for
465
500
// the trip back.
@@ -483,9 +518,8 @@ private void OnRoundStarting(RoundStartingEvent ev)
483
518
484
519
private void SetupArrivalsStation ( )
485
520
{
486
- var mapId = _mapManager . CreateMap ( ) ;
487
- var mapUid = _mapManager . GetMapEntityId ( mapId ) ;
488
- _mapManager . AddUninitializedMap ( mapId ) ;
521
+ var mapUid = _mapSystem . CreateMap ( out var mapId , false ) ;
522
+ _metaData . SetEntityName ( mapUid , Loc . GetString ( "map-name-terminal" ) ) ;
489
523
490
524
if ( ! _loader . TryLoad ( mapId , _cfgManager . GetCVar ( CCVars . ArrivalsMap ) , out var uids ) )
491
525
{
@@ -504,9 +538,14 @@ private void SetupArrivalsStation()
504
538
{
505
539
var template = _random . Pick ( _arrivalsBiomeOptions ) ;
506
540
_biomes . EnsurePlanet ( mapUid , _protoManager . Index ( template ) ) ;
541
+ var restricted = new RestrictedRangeComponent
542
+ {
543
+ Range = 32f
544
+ } ;
545
+ AddComp ( mapUid , restricted ) ;
507
546
}
508
547
509
- _mapManager . DoMapInitialize ( mapId ) ;
548
+ _mapSystem . InitializeMap ( mapId ) ;
510
549
511
550
// Handle roundstart stations.
512
551
var query = AllEntityQuery < StationArrivalsComponent > ( ) ;
@@ -564,10 +603,10 @@ private void SetupShuttle(EntityUid uid, StationArrivalsComponent component)
564
603
return ;
565
604
566
605
// Spawn arrivals on a dummy map then dock it to the source.
567
- var dummyMap = _mapManager . CreateMap ( ) ;
606
+ var dummpMapEntity = _mapSystem . CreateMap ( out var dummyMapId ) ;
568
607
569
608
if ( TryGetArrivals ( out var arrivals ) &&
570
- _loader . TryLoad ( dummyMap , component . ShuttlePath . ToString ( ) , out var shuttleUids ) )
609
+ _loader . TryLoad ( dummyMapId , component . ShuttlePath . ToString ( ) , out var shuttleUids ) )
571
610
{
572
611
component . Shuttle = shuttleUids [ 0 ] ;
573
612
var shuttleComp = Comp < ShuttleComponent > ( component . Shuttle ) ;
@@ -579,7 +618,7 @@ private void SetupShuttle(EntityUid uid, StationArrivalsComponent component)
579
618
}
580
619
581
620
// Don't start the arrivals shuttle immediately docked so power has a time to stabilise?
582
- var timer = AddComp < TimedDespawnComponent > ( _mapManager . GetMapEntityId ( dummyMap ) ) ;
621
+ var timer = AddComp < TimedDespawnComponent > ( dummpMapEntity ) ;
583
622
timer . Lifetime = 15f ;
584
623
}
585
624
}
0 commit comments