2022-03-31 20:08:30 +13:00
|
|
|
using Content.Shared.Administration.Logs;
|
|
|
|
|
using Content.Shared.Database;
|
2022-02-17 21:43:24 -05:00
|
|
|
using Content.Shared.Emag.Components;
|
|
|
|
|
using Content.Shared.Emag.Systems;
|
2022-03-31 20:08:30 +13:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Popups;
|
2022-04-23 20:37:49 -04:00
|
|
|
using Content.Shared.Tag;
|
2022-03-31 20:08:30 +13:00
|
|
|
using Robust.Shared.Player;
|
2022-02-17 21:43:24 -05:00
|
|
|
|
|
|
|
|
namespace Content.Server.Emag
|
|
|
|
|
{
|
|
|
|
|
public sealed class EmagSystem : EntitySystem
|
|
|
|
|
{
|
2022-03-31 20:08:30 +13:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
2022-05-28 23:41:17 -07:00
|
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
2022-03-31 20:08:30 +13:00
|
|
|
|
2022-04-23 20:37:49 -04:00
|
|
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
|
|
|
|
|
2022-03-31 20:08:30 +13:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<EmagComponent, AfterInteractEvent>(OnAfterInteract);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 21:43:24 -05:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
foreach (var emag in EntityManager.EntityQuery<EmagComponent>())
|
|
|
|
|
{
|
|
|
|
|
if (emag.Charges == emag.MaxCharges)
|
|
|
|
|
{
|
|
|
|
|
emag.Accumulator = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emag.Accumulator += frameTime;
|
|
|
|
|
|
|
|
|
|
if (emag.Accumulator < emag.RechargeTime)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emag.Accumulator -= emag.RechargeTime;
|
|
|
|
|
emag.Charges++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-31 20:08:30 +13:00
|
|
|
|
|
|
|
|
private void OnAfterInteract(EntityUid uid, EmagComponent component, AfterInteractEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.CanReach || args.Target == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-04-23 20:37:49 -04:00
|
|
|
if (_tagSystem.HasTag(args.Target.Value, "EmagImmune"))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-03-31 20:08:30 +13:00
|
|
|
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));
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(args.User):player} emagged {ToPrettyString(args.Target.Value):target}");
|
2022-03-31 20:08:30 +13:00
|
|
|
component.Charges--;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-17 21:43:24 -05:00
|
|
|
}
|
|
|
|
|
}
|