RCD logs (#7208)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Threading;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
@@ -5,7 +6,7 @@ using Robust.Shared.ViewVariables;
|
|||||||
|
|
||||||
namespace Content.Server.RCD.Components
|
namespace Content.Server.RCD.Components
|
||||||
{
|
{
|
||||||
public enum RcdMode
|
public enum RcdMode : byte
|
||||||
{
|
{
|
||||||
Floors,
|
Floors,
|
||||||
Walls,
|
Walls,
|
||||||
@@ -16,11 +17,10 @@ namespace Content.Server.RCD.Components
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class RCDComponent : Component
|
public sealed class RCDComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
private const int DefaultAmmoCount = 5;
|
||||||
[DataField("maxAmmo")] public int MaxAmmo = 5;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
[DataField("startingAmmo")] public int StartingAmmo = 5;
|
[DataField("maxAmmo")] public int MaxAmmo = DefaultAmmoCount;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("delay")]
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("delay")]
|
||||||
public float Delay = 2f;
|
public float Delay = 2f;
|
||||||
@@ -34,12 +34,16 @@ namespace Content.Server.RCD.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// What mode are we on? Can be floors, walls, deconstruct.
|
/// What mode are we on? Can be floors, walls, deconstruct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("mode")]
|
||||||
public RcdMode Mode = RcdMode.Floors;
|
public RcdMode Mode = RcdMode.Floors;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How much "ammo" we have left. You can refill this with RCD ammo.
|
/// How much "ammo" we have left. You can refill this with RCD ammo.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CurrentAmmo;
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("ammo")]
|
||||||
|
public int CurrentAmmo = DefaultAmmoCount;
|
||||||
|
|
||||||
|
public CancellationTokenSource? CancelToken = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Content.Server.Administration.Logs;
|
||||||
using Content.Server.DoAfter;
|
using Content.Server.DoAfter;
|
||||||
|
using Content.Server.Popups;
|
||||||
using Content.Server.RCD.Components;
|
using Content.Server.RCD.Components;
|
||||||
using Content.Shared.Coordinates;
|
using Content.Shared.Coordinates;
|
||||||
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
@@ -25,26 +28,22 @@ namespace Content.Server.RCD.Systems
|
|||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
|
||||||
|
[Dependency] private readonly AdminLogSystem _logs = default!;
|
||||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||||
|
[Dependency] private readonly PopupSystem _popup = default!;
|
||||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||||
|
|
||||||
private readonly RcdMode[] _modes = (RcdMode[]) Enum.GetValues(typeof(RcdMode));
|
private readonly int RCDModeCount = Enum.GetValues(typeof(RcdMode)).Length;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<RCDComponent, MapInitEvent>(OnMapInit);
|
|
||||||
SubscribeLocalEvent<RCDComponent, ExaminedEvent>(OnExamine);
|
SubscribeLocalEvent<RCDComponent, ExaminedEvent>(OnExamine);
|
||||||
SubscribeLocalEvent<RCDComponent, UseInHandEvent>(OnUseInHand);
|
SubscribeLocalEvent<RCDComponent, UseInHandEvent>(OnUseInHand);
|
||||||
SubscribeLocalEvent<RCDComponent, AfterInteractEvent>(OnAfterInteract);
|
SubscribeLocalEvent<RCDComponent, AfterInteractEvent>(OnAfterInteract);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapInit(EntityUid uid, RCDComponent component, MapInitEvent args)
|
|
||||||
{
|
|
||||||
component.CurrentAmmo = component.StartingAmmo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnExamine(EntityUid uid, RCDComponent component, ExaminedEvent args)
|
private void OnExamine(EntityUid uid, RCDComponent component, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
var msg = Loc.GetString("rcd-component-examine-detail-count",
|
var msg = Loc.GetString("rcd-component-examine-detail-count",
|
||||||
@@ -66,7 +65,16 @@ namespace Content.Server.RCD.Systems
|
|||||||
if (args.Handled || !args.CanReach)
|
if (args.Handled || !args.CanReach)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME: Make this work properly. Right now it relies on the click location being on a grid, which is bad.
|
if (rcd.CancelToken != null)
|
||||||
|
{
|
||||||
|
rcd.CancelToken?.Cancel();
|
||||||
|
rcd.CancelToken = null;
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args.ClickLocation.IsValid(EntityManager)) return;
|
||||||
|
|
||||||
var clickLocationMod = args.ClickLocation;
|
var clickLocationMod = args.ClickLocation;
|
||||||
// Initial validity check
|
// Initial validity check
|
||||||
if (!clickLocationMod.IsValid(EntityManager))
|
if (!clickLocationMod.IsValid(EntityManager))
|
||||||
@@ -89,41 +97,46 @@ namespace Content.Server.RCD.Systems
|
|||||||
|
|
||||||
//No changing mode mid-RCD
|
//No changing mode mid-RCD
|
||||||
var startingMode = rcd.Mode;
|
var startingMode = rcd.Mode;
|
||||||
|
args.Handled = true;
|
||||||
|
var user = args.User;
|
||||||
|
|
||||||
//Using an RCD isn't instantaneous
|
//Using an RCD isn't instantaneous
|
||||||
var cancelToken = new CancellationTokenSource();
|
rcd.CancelToken = new CancellationTokenSource();
|
||||||
var doAfterEventArgs = new DoAfterEventArgs(args.User, rcd.Delay, cancelToken.Token, args.Target)
|
var doAfterEventArgs = new DoAfterEventArgs(user, rcd.Delay, rcd.CancelToken.Token, args.Target)
|
||||||
{
|
{
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
BreakOnStun = true,
|
BreakOnStun = true,
|
||||||
NeedHand = true,
|
NeedHand = true,
|
||||||
ExtraCheck = () => IsRCDStillValid(rcd, args, mapGrid, tile, snapPos, startingMode) //All of the sanity checks are here
|
ExtraCheck = () => IsRCDStillValid(rcd, args, mapGrid, tile, startingMode) //All of the sanity checks are here
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await _doAfterSystem.WaitDoAfter(doAfterEventArgs);
|
var result = await _doAfterSystem.WaitDoAfter(doAfterEventArgs);
|
||||||
|
|
||||||
|
rcd.CancelToken = null;
|
||||||
|
|
||||||
if (result == DoAfterStatus.Cancelled)
|
if (result == DoAfterStatus.Cancelled)
|
||||||
{
|
|
||||||
args.Handled = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
switch (rcd.Mode)
|
switch (rcd.Mode)
|
||||||
{
|
{
|
||||||
//Floor mode just needs the tile to be a space tile (subFloor)
|
//Floor mode just needs the tile to be a space tile (subFloor)
|
||||||
case RcdMode.Floors:
|
case RcdMode.Floors:
|
||||||
mapGrid.SetTile(clickLocationMod, new Tile(_tileDefinitionManager["floor_steel"].TileId));
|
mapGrid.SetTile(snapPos, new Tile(_tileDefinitionManager["floor_steel"].TileId));
|
||||||
|
_logs.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridIndex} {snapPos} to floor_steel");
|
||||||
break;
|
break;
|
||||||
//We don't want to place a space tile on something that's already a space tile. Let's do the inverse of the last check.
|
//We don't want to place a space tile on something that's already a space tile. Let's do the inverse of the last check.
|
||||||
case RcdMode.Deconstruct:
|
case RcdMode.Deconstruct:
|
||||||
if (!tile.IsBlockedTurf(true)) //Delete the turf
|
if (!tile.IsBlockedTurf(true)) //Delete the turf
|
||||||
{
|
{
|
||||||
mapGrid.SetTile(snapPos, Tile.Empty);
|
mapGrid.SetTile(snapPos, Tile.Empty);
|
||||||
|
_logs.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridIndex} tile: {snapPos} to space");
|
||||||
}
|
}
|
||||||
else //Delete what the user targeted
|
else //Delete what the user targeted
|
||||||
{
|
{
|
||||||
if (args.Target is {Valid: true} target)
|
if (args.Target is {Valid: true} target)
|
||||||
{
|
{
|
||||||
EntityManager.DeleteEntity(target);
|
_logs.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to delete {ToPrettyString(target):target}");
|
||||||
|
QueueDel(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -131,28 +144,30 @@ namespace Content.Server.RCD.Systems
|
|||||||
// thus we early return to avoid the tile set code.
|
// thus we early return to avoid the tile set code.
|
||||||
case RcdMode.Walls:
|
case RcdMode.Walls:
|
||||||
var ent = EntityManager.SpawnEntity("WallSolid", mapGrid.GridTileToLocal(snapPos));
|
var ent = EntityManager.SpawnEntity("WallSolid", mapGrid.GridTileToLocal(snapPos));
|
||||||
EntityManager.GetComponent<TransformComponent>(ent).LocalRotation = Angle.Zero; // Walls always need to point south.
|
Transform(ent).LocalRotation = Angle.Zero; // Walls always need to point south.
|
||||||
|
_logs.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(ent)} at {snapPos} on grid {mapGrid.Index}");
|
||||||
break;
|
break;
|
||||||
case RcdMode.Airlock:
|
case RcdMode.Airlock:
|
||||||
var airlock = EntityManager.SpawnEntity("Airlock", mapGrid.GridTileToLocal(snapPos));
|
var airlock = EntityManager.SpawnEntity("Airlock", mapGrid.GridTileToLocal(snapPos));
|
||||||
EntityManager.GetComponent<TransformComponent>(airlock).LocalRotation = EntityManager.GetComponent<TransformComponent>(rcd.Owner).LocalRotation; //Now apply icon smoothing.
|
Transform(airlock).LocalRotation = Transform(rcd.Owner).LocalRotation; //Now apply icon smoothing.
|
||||||
|
_logs.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(airlock)} at {snapPos} on grid {mapGrid.Index}");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
return; //I don't know why this would happen, but sure I guess. Get out of here invalid state!
|
return; //I don't know why this would happen, but sure I guess. Get out of here invalid state!
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(uid), rcd.SuccessSound.GetSound(), rcd.Owner);
|
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), rcd.SuccessSound.GetSound(), rcd.Owner);
|
||||||
rcd.CurrentAmmo--;
|
rcd.CurrentAmmo--;
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsRCDStillValid(RCDComponent rcd, AfterInteractEvent eventArgs, IMapGrid mapGrid, TileRef tile, Vector2i snapPos, RcdMode startingMode)
|
private bool IsRCDStillValid(RCDComponent rcd, AfterInteractEvent eventArgs, IMapGrid mapGrid, TileRef tile, RcdMode startingMode)
|
||||||
{
|
{
|
||||||
//Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
|
//Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
|
||||||
if (rcd.CurrentAmmo <= 0)
|
if (rcd.CurrentAmmo <= 0)
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-no-ammo-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-no-ammo-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +189,7 @@ namespace Content.Server.RCD.Systems
|
|||||||
case RcdMode.Floors:
|
case RcdMode.Floors:
|
||||||
if (!tile.Tile.IsEmpty)
|
if (!tile.Tile.IsEmpty)
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-cannot-build-floor-tile-not-empty-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-cannot-build-floor-tile-not-empty-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,13 +204,13 @@ namespace Content.Server.RCD.Systems
|
|||||||
//They tried to decon a turf but the turf is blocked
|
//They tried to decon a turf but the turf is blocked
|
||||||
if (eventArgs.Target == null && tile.IsBlockedTurf(true))
|
if (eventArgs.Target == null && tile.IsBlockedTurf(true))
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-tile-obstructed-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-tile-obstructed-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//They tried to decon a non-turf but it's not in the whitelist
|
//They tried to decon a non-turf but it's not in the whitelist
|
||||||
if (eventArgs.Target != null && !_tagSystem.HasTag(eventArgs.Target.Value, "RCDDeconstructWhitelist"))
|
if (eventArgs.Target != null && !_tagSystem.HasTag(eventArgs.Target.Value, "RCDDeconstructWhitelist"))
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-deconstruct-target-not-on-whitelist-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-deconstruct-target-not-on-whitelist-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,25 +219,25 @@ namespace Content.Server.RCD.Systems
|
|||||||
case RcdMode.Walls:
|
case RcdMode.Walls:
|
||||||
if (tile.Tile.IsEmpty)
|
if (tile.Tile.IsEmpty)
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-cannot-build-wall-tile-not-empty-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-cannot-build-wall-tile-not-empty-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile.IsBlockedTurf(true))
|
if (tile.IsBlockedTurf(true))
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-tile-obstructed-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-tile-obstructed-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case RcdMode.Airlock:
|
case RcdMode.Airlock:
|
||||||
if (tile.Tile.IsEmpty)
|
if (tile.Tile.IsEmpty)
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-cannot-build-airlock-tile-not-empty-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-cannot-build-airlock-tile-not-empty-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tile.IsBlockedTurf(true))
|
if (tile.IsBlockedTurf(true))
|
||||||
{
|
{
|
||||||
rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-tile-obstructed-message"));
|
_popup.PopupEntity(Loc.GetString("rcd-component-tile-obstructed-message"), rcd.Owner, Filter.Entities(eventArgs.User));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -233,14 +248,14 @@ namespace Content.Server.RCD.Systems
|
|||||||
|
|
||||||
private void NextMode(EntityUid uid, RCDComponent rcd, EntityUid user)
|
private void NextMode(EntityUid uid, RCDComponent rcd, EntityUid user)
|
||||||
{
|
{
|
||||||
SoundSystem.Play(Filter.Pvs(uid), rcd.SwapModeSound.GetSound(), uid);
|
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), rcd.SwapModeSound.GetSound(), uid);
|
||||||
|
|
||||||
var mode = (int) rcd.Mode; //Firstly, cast our RCDmode mode to an int (enums are backed by ints anyway by default)
|
var mode = (int) rcd.Mode;
|
||||||
mode = (++mode) % _modes.Length; //Then, do a rollover on the value so it doesnt hit an invalid state
|
mode = ++mode % RCDModeCount;
|
||||||
rcd.Mode = (RcdMode) mode; //Finally, cast the newly acquired int mode to an RCDmode so we can use it.
|
rcd.Mode = (RcdMode) mode;
|
||||||
|
|
||||||
var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString()));
|
var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString()));
|
||||||
rcd.Owner.PopupMessage(user, msg); //Prints an overhead message above the RCD
|
_popup.PopupEntity(msg, rcd.Owner, Filter.Entities(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,5 +64,7 @@ public enum LogType
|
|||||||
GhostRoleTaken = 60,
|
GhostRoleTaken = 60,
|
||||||
Chat = 61,
|
Chat = 61,
|
||||||
Action = 62,
|
Action = 62,
|
||||||
|
RCD = 63,
|
||||||
|
// haha so funny
|
||||||
Emag = 69,
|
Emag = 69,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user