Adds Special Respawn, spawns a new disk if the old one was deleted (#12762)
* Spawns a new disk if one was deleted * Adds tiledef to space checks, also adds a way to randomly check for a respawn point on station * Removes unused method * Cuts down on tile checks needed by checking surrounding tiles first * Fixes up an issue where the coords wouldn't spawn * Removes disk system, adds special respawning system and comp * Fixes spelling error * Fixes linter issue * Maybe fixes the linter with a ref event? * Empty commit to rerun tests * Maybe fix? * check for deleted grid * Moves shutdown code to terminating code * Customtypeseralizer * changes name of datafield * Removes owning station references * Trying the queue event again
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
using System.Text;
|
|
||||||
using Content.Server.AlertLevel;
|
using Content.Server.AlertLevel;
|
||||||
using Content.Server.Audio;
|
using Content.Server.Audio;
|
||||||
using Content.Server.Chat;
|
|
||||||
using Content.Server.Chat.Managers;
|
|
||||||
using Content.Server.Chat.Systems;
|
using Content.Server.Chat.Systems;
|
||||||
using Content.Server.Coordinates.Helpers;
|
using Content.Server.Coordinates.Helpers;
|
||||||
using Content.Server.DoAfter;
|
using Content.Server.DoAfter;
|
||||||
@@ -19,7 +16,6 @@ using Robust.Shared.Audio;
|
|||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
|
|
||||||
namespace Content.Server.Nuke
|
namespace Content.Server.Nuke
|
||||||
{
|
{
|
||||||
@@ -48,6 +44,7 @@ namespace Content.Server.Nuke
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<NukeComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<NukeComponent, ComponentInit>(OnInit);
|
||||||
SubscribeLocalEvent<NukeComponent, ComponentRemove>(OnRemove);
|
SubscribeLocalEvent<NukeComponent, ComponentRemove>(OnRemove);
|
||||||
SubscribeLocalEvent<NukeComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<NukeComponent, MapInitEvent>(OnMapInit);
|
||||||
@@ -105,9 +102,8 @@ namespace Content.Server.Nuke
|
|||||||
var originStation = _stationSystem.GetOwningStation(uid);
|
var originStation = _stationSystem.GetOwningStation(uid);
|
||||||
|
|
||||||
if (originStation != null)
|
if (originStation != null)
|
||||||
{
|
|
||||||
nuke.OriginStation = originStation;
|
nuke.OriginStation = originStation;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var transform = Transform(uid);
|
var transform = Transform(uid);
|
||||||
@@ -124,7 +120,8 @@ namespace Content.Server.Nuke
|
|||||||
|
|
||||||
private void OnItemSlotChanged(EntityUid uid, NukeComponent component, ContainerModifiedMessage args)
|
private void OnItemSlotChanged(EntityUid uid, NukeComponent component, ContainerModifiedMessage args)
|
||||||
{
|
{
|
||||||
if (!component.Initialized) return;
|
if (!component.Initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
if (args.Container.ID != component.DiskSlot.ID)
|
if (args.Container.ID != component.DiskSlot.ID)
|
||||||
return;
|
return;
|
||||||
@@ -229,9 +226,8 @@ namespace Content.Server.Nuke
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.Status == NukeStatus.AWAIT_ARM && Transform(uid).Anchored)
|
if (component.Status == NukeStatus.AWAIT_ARM && Transform(uid).Anchored)
|
||||||
{
|
|
||||||
ArmBomb(uid, component);
|
ArmBomb(uid, component);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (args.Session.AttachedEntity is not { } user)
|
if (args.Session.AttachedEntity is not { } user)
|
||||||
@@ -303,10 +299,9 @@ namespace Content.Server.Nuke
|
|||||||
nuke.RemainingTime = 0;
|
nuke.RemainingTime = 0;
|
||||||
ActivateBomb(uid, nuke);
|
ActivateBomb(uid, nuke);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
UpdateUserInterface(uid, nuke);
|
UpdateUserInterface(uid, nuke);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStatus(EntityUid uid, NukeComponent? component = null)
|
private void UpdateStatus(EntityUid uid, NukeComponent? component = null)
|
||||||
@@ -456,9 +451,7 @@ namespace Content.Server.Nuke
|
|||||||
// let people know that a nuclear bomb was armed in their vicinity instead.
|
// let people know that a nuclear bomb was armed in their vicinity instead.
|
||||||
// Otherwise, you could set every station to whatever AlertLevelOnActivate is.
|
// Otherwise, you could set every station to whatever AlertLevelOnActivate is.
|
||||||
if (stationUid != null)
|
if (stationUid != null)
|
||||||
{
|
|
||||||
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true);
|
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true);
|
||||||
}
|
|
||||||
|
|
||||||
var nukeXform = Transform(uid);
|
var nukeXform = Transform(uid);
|
||||||
var pos = nukeXform.MapPosition;
|
var pos = nukeXform.MapPosition;
|
||||||
@@ -493,9 +486,7 @@ namespace Content.Server.Nuke
|
|||||||
|
|
||||||
var stationUid = _stationSystem.GetOwningStation(uid);
|
var stationUid = _stationSystem.GetOwningStation(uid);
|
||||||
if (stationUid != null)
|
if (stationUid != null)
|
||||||
{
|
|
||||||
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnDeactivate, true, true, true);
|
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnDeactivate, true, true, true);
|
||||||
}
|
|
||||||
|
|
||||||
// warn a crew
|
// warn a crew
|
||||||
var announcement = Loc.GetString("nuke-component-announcement-unarmed");
|
var announcement = Loc.GetString("nuke-component-announcement-unarmed");
|
||||||
@@ -614,11 +605,17 @@ namespace Content.Server.Nuke
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed on the nuke when its disarm doafter is successful.
|
/// Raised directed on the nuke when its disarm doafter is successful.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class NukeDisarmSuccessEvent : EntityEventArgs {}
|
public sealed class NukeDisarmSuccessEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed on the nuke when its disarm doafter is cancelled.
|
/// Raised directed on the nuke when its disarm doafter is cancelled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class NukeDisarmCancelledEvent : EntityEventArgs {}
|
public sealed class NukeDisarmCancelledEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
184
Content.Server/Respawn/SpecialRespawnSystem.cs
Normal file
184
Content.Server/Respawn/SpecialRespawnSystem.cs
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
using Content.Server.Administration.Logs;
|
||||||
|
using Content.Server.Atmos.EntitySystems;
|
||||||
|
using Content.Server.GameTicking;
|
||||||
|
using Content.Server.Station.Components;
|
||||||
|
using Content.Server.Station.Systems;
|
||||||
|
using Content.Shared.Database;
|
||||||
|
using Content.Shared.Maps;
|
||||||
|
using Content.Shared.Respawn;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Server.Respawn;
|
||||||
|
|
||||||
|
public sealed class SpecialRespawnSystem : SharedSpecialRespawnSystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
[Dependency] private readonly IAdminLogManager _adminLog = default!;
|
||||||
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged);
|
||||||
|
SubscribeLocalEvent<SpecialRespawnSetupEvent>(OnSpecialRespawnSetup);
|
||||||
|
SubscribeLocalEvent<SpecialRespawnComponent, ComponentStartup>(OnStartup);
|
||||||
|
SubscribeLocalEvent<SpecialRespawnComponent, EntityTerminatingEvent>(OnTermination);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRunLevelChanged(GameRunLevelChangedEvent ev)
|
||||||
|
{
|
||||||
|
//Try to compensate for restartroundnow command
|
||||||
|
if (ev.Old == GameRunLevel.InRound && ev.New == GameRunLevel.PreRoundLobby)
|
||||||
|
OnRoundEnd();
|
||||||
|
|
||||||
|
switch (ev.New)
|
||||||
|
{
|
||||||
|
case GameRunLevel.PostRound:
|
||||||
|
OnRoundEnd();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSpecialRespawnSetup(SpecialRespawnSetupEvent ev)
|
||||||
|
{
|
||||||
|
if (!TryComp<SpecialRespawnComponent>(ev.Entity, out var comp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var xform = Transform(ev.Entity);
|
||||||
|
|
||||||
|
if (xform.GridUid != null)
|
||||||
|
comp.StationMap = (xform.MapUid, xform.GridUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRoundEnd()
|
||||||
|
{
|
||||||
|
var specialRespawnQuery = EntityQuery<SpecialRespawnComponent>();
|
||||||
|
|
||||||
|
//Turn respawning off so the entity doesn't respawn during reset
|
||||||
|
foreach (var entity in specialRespawnQuery)
|
||||||
|
{
|
||||||
|
entity.Respawn = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnStartup(EntityUid uid, SpecialRespawnComponent component, ComponentStartup args)
|
||||||
|
{
|
||||||
|
var ev = new SpecialRespawnSetupEvent(uid);
|
||||||
|
QueueLocalEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTermination(EntityUid uid, SpecialRespawnComponent component, ref EntityTerminatingEvent args)
|
||||||
|
{
|
||||||
|
var entityMapUid = component.StationMap.Item1;
|
||||||
|
var entityGridUid = component.StationMap.Item2;
|
||||||
|
|
||||||
|
if (!component.Respawn || !HasComp<StationMemberComponent>(entityGridUid) || entityMapUid == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_mapManager.TryGetGrid(entityGridUid, out var grid) || MetaData(entityGridUid.Value).EntityLifeStage >= EntityLifeStage.Terminating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (TryFindRandomTile(entityGridUid.Value, entityMapUid.Value, 10, out var coords))
|
||||||
|
Respawn(component.Prototype, coords);
|
||||||
|
|
||||||
|
//If the above fails, spawn at the center of the grid on the station
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var xform = Transform(entityGridUid.Value);
|
||||||
|
var pos = xform.Coordinates;
|
||||||
|
var mapPos = xform.MapPosition;
|
||||||
|
var circle = new Circle(mapPos.Position, 2);
|
||||||
|
|
||||||
|
var found = false;
|
||||||
|
|
||||||
|
foreach (var tile in grid.GetTilesIntersecting(circle))
|
||||||
|
{
|
||||||
|
if (tile.IsSpace(_tileDefinitionManager) || tile.IsBlockedTurf(true) || !_atmosphere.IsTileMixtureProbablySafe(entityGridUid, entityMapUid.Value, grid.TileIndicesFor(mapPos)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pos = tile.GridPosition();
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Respawn(component.Prototype, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Respawn the entity and log it.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prototype">The prototype being spawned</param>
|
||||||
|
/// <param name="coords">The place where it will be spawned</param>
|
||||||
|
private void Respawn(string prototype, EntityCoordinates coords)
|
||||||
|
{
|
||||||
|
var entity = Spawn(prototype, coords);
|
||||||
|
var name = MetaData(entity).EntityName;
|
||||||
|
_adminLog.Add(LogType.Respawn, LogImpact.High, $"{name} was deleted and was respawned at {coords.ToMap(EntityManager)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Try to find a random safe tile on the supplied grid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="targetGrid">The grid that you're looking for a safe tile on</param>
|
||||||
|
/// <param name="targetMap">The map that you're looking for a safe tile on</param>
|
||||||
|
/// <param name="maxAttempts">The maximum amount of attempts it should try before it gives up</param>
|
||||||
|
/// <param name="targetCoords">If successful, the coordinates of the safe tile</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool TryFindRandomTile(EntityUid targetGrid, EntityUid targetMap, int maxAttempts, out EntityCoordinates targetCoords)
|
||||||
|
{
|
||||||
|
targetCoords = EntityCoordinates.Invalid;
|
||||||
|
|
||||||
|
if (!_mapManager.TryGetGrid(targetGrid, out var grid))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var xform = Transform(targetGrid);
|
||||||
|
|
||||||
|
if (!grid.TryGetTileRef(xform.Coordinates, out var tileRef))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var tile = tileRef.GridIndices;
|
||||||
|
|
||||||
|
var found = false;
|
||||||
|
var (gridPos, _, gridMatrix) = xform.GetWorldPositionRotationMatrix();
|
||||||
|
var gridBounds = gridMatrix.TransformBox(grid.LocalAABB);
|
||||||
|
|
||||||
|
//Obviously don't put anything ridiculous in here
|
||||||
|
for (var i = 0; i < maxAttempts; i++)
|
||||||
|
{
|
||||||
|
var randomX = _random.Next((int) gridBounds.Left, (int) gridBounds.Right);
|
||||||
|
var randomY = _random.Next((int) gridBounds.Bottom, (int) gridBounds.Top);
|
||||||
|
|
||||||
|
tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y);
|
||||||
|
var mapPos = grid.GridTileToWorldPos(tile);
|
||||||
|
var mapTarget = grid.WorldToTile(mapPos);
|
||||||
|
var circle = new Circle(mapPos, 2);
|
||||||
|
|
||||||
|
foreach (var newTileRef in grid.GetTilesIntersecting(circle))
|
||||||
|
{
|
||||||
|
if (newTileRef.IsSpace(_tileDefinitionManager) || newTileRef.IsBlockedTurf(true) || !_atmosphere.IsTileMixtureProbablySafe(targetGrid, targetMap, mapTarget))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
targetCoords = grid.GridTileToLocal(tile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Found a safe tile, no need to continue
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,4 +6,7 @@ namespace Content.Shared.Nuke;
|
|||||||
/// Used for tracking the nuke disk - isn't a tag for pinpointer purposes.
|
/// Used for tracking the nuke disk - isn't a tag for pinpointer purposes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public sealed class NukeDiskComponent : Component {}
|
public sealed class NukeDiskComponent : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
6
Content.Shared/Respawn/SharedSpecialRespawnSystem.cs
Normal file
6
Content.Shared/Respawn/SharedSpecialRespawnSystem.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Shared.Respawn;
|
||||||
|
|
||||||
|
public abstract class SharedSpecialRespawnSystem : EntitySystem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
41
Content.Shared/Respawn/SpecialRespawnComponent.cs
Normal file
41
Content.Shared/Respawn/SpecialRespawnComponent.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
|
namespace Content.Shared.Respawn;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is to be used where you need some item respawned on station if it was deleted somehow in round
|
||||||
|
/// Items like the nuke disk.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent]
|
||||||
|
public sealed class SpecialRespawnComponent: Component
|
||||||
|
{
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("stationMap")]
|
||||||
|
public (EntityUid?, EntityUid?) StationMap;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the entityentity should respawn on the station grid
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("respawn")]
|
||||||
|
public bool Respawn = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The prototypeID of the entity to be respawned
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("prototype", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||||
|
public string Prototype = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SpecialRespawnSetupEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public EntityUid Entity;
|
||||||
|
|
||||||
|
public SpecialRespawnSetupEvent(EntityUid entity)
|
||||||
|
{
|
||||||
|
Entity = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
description: A nuclear auth disk, capable of arming a nuke if used along with a code. Note from nanotrasen reads "THIS IS YOUR MOST IMPORTANT POSESSION, SECURE DAT FUKKEN DISK!"
|
description: A nuclear auth disk, capable of arming a nuke if used along with a code. Note from nanotrasen reads "THIS IS YOUR MOST IMPORTANT POSESSION, SECURE DAT FUKKEN DISK!"
|
||||||
components:
|
components:
|
||||||
- type: NukeDisk
|
- type: NukeDisk
|
||||||
|
- type: SpecialRespawn
|
||||||
|
prototype: NukeDisk
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
sprite: Objects/Misc/nukedisk.rsi
|
sprite: Objects/Misc/nukedisk.rsi
|
||||||
|
|||||||
Reference in New Issue
Block a user