Emags (#6738)
This commit is contained in:
@@ -27,6 +27,11 @@ namespace Content.Shared.APC
|
||||
/// APC battery is full and has enough power.
|
||||
/// </summary>
|
||||
Full,
|
||||
|
||||
/// <summary>
|
||||
/// APC is emagged (and not displaying other useful power colors at a glance)
|
||||
/// </summary>
|
||||
Emag,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.Access.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -22,6 +23,7 @@ namespace Content.Shared.Access.Systems
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<AccessReaderComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<AccessReaderComponent, GotEmaggedEvent>(OnEmagged);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, AccessReaderComponent reader, ComponentInit args)
|
||||
@@ -36,6 +38,15 @@ namespace Content.Shared.Access.Systems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, AccessReaderComponent reader, GotEmaggedEvent args)
|
||||
{
|
||||
if (reader.Enabled == true)
|
||||
{
|
||||
reader.Enabled = false;
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches an <see cref="AccessComponent"/> in the entity itself, in its active hand or in its ID slot.
|
||||
/// Then compares the found access with the configured access lists to see if it is allowed.
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Content.Shared.Atmos.Monitor
|
||||
{
|
||||
Normal = 0,
|
||||
Warning = 1,
|
||||
Danger = 2 // 1 << 1 is the exact same thing and we're not really doing **bitmasking** are we?
|
||||
Danger = 2, // 1 << 1 is the exact same thing and we're not really doing **bitmasking** are we?
|
||||
Emagged = 3,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Shared.Chemistry.Dispenser
|
||||
/// <summary>
|
||||
/// A list of reagents which this may dispense. Defined in yaml prototype, see <see cref="ReagentDispenserInventoryPrototype"/>.
|
||||
/// </summary>
|
||||
protected readonly List<ReagentDispenserInventoryEntry> Inventory = new();
|
||||
public readonly List<ReagentDispenserInventoryEntry> Inventory = new();
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ReagentDispenserBoundUserInterfaceState : BoundUserInterfaceState
|
||||
|
||||
16
Content.Shared/Emag/Components/EmagComponent.cs
Normal file
16
Content.Shared/Emag/Components/EmagComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Content.Shared.Emag.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class EmagComponent : Component
|
||||
{
|
||||
[DataField("maxCharges")]
|
||||
public int MaxCharges = 3;
|
||||
|
||||
[DataField("charges")]
|
||||
public int Charges = 3;
|
||||
|
||||
[DataField("rechargeTime")]
|
||||
public float RechargeTime = 90f;
|
||||
public float Accumulator = 0f;
|
||||
}
|
||||
}
|
||||
65
Content.Shared/Emag/Systems/SharedEmagSystem.cs
Normal file
65
Content.Shared/Emag/Systems/SharedEmagSystem.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Content.Shared.Emag.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Shared.Emag.Systems
|
||||
{
|
||||
/// How to add an emag interaction:
|
||||
/// 1. Go to the system for the component you want the interaction with
|
||||
/// 2. Subscribe to the GotEmaggedEvent
|
||||
/// 3. Have some check for if this actually needs to be emagged or is already emagged (to stop charge waste)
|
||||
/// 4. Past the check, add all the effects you desire and HANDLE THE EVENT ARGUMENT so a charge is spent
|
||||
public sealed class SharedEmagSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAdminLogSystem _adminLog = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EmagComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<EmagComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, EmagComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("emag-charges-remaining", ("charges", component.Charges)));
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, EmagComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (component.Charges <= 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-no-charges"), args.User, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
var emaggedEvent = new GotEmaggedEvent(args.User);
|
||||
RaiseLocalEvent(args.Target.Value, emaggedEvent, false);
|
||||
if (emaggedEvent.Handled)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("emag-success",("target", args.Target)), args.User, Filter.Entities(args.User));
|
||||
_adminLog.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(args.User):player} emagged {ToPrettyString(args.Target.Value):target}");
|
||||
component.Charges--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GotEmaggedEvent : HandledEntityEventArgs
|
||||
{
|
||||
public readonly EntityUid UserUid;
|
||||
|
||||
public GotEmaggedEvent(EntityUid userUid)
|
||||
{
|
||||
userUid = UserUid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user