CatStation/Content.Shared/RCD/Systems/RCDAmmoSystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

63 lines
2.1 KiB
C#

using Content.Shared.Charges.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.RCD.Components;
using Robust.Shared.Timing;
namespace Content.Shared.RCD.Systems;
public sealed partial class RCDAmmoSystem : EntitySystem
{
[Dependency] private SharedChargesSystem _sharedCharges = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RCDAmmoComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<RCDAmmoComponent, AfterInteractEvent>(OnAfterInteract);
}
private void OnExamine(EntityUid uid, RCDAmmoComponent comp, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
var examineMessage = Loc.GetString("rcd-ammo-component-on-examine", ("charges", comp.Charges));
args.PushText(examineMessage);
}
private void OnAfterInteract(EntityUid uid, RCDAmmoComponent comp, AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || !_timing.IsFirstTimePredicted)
return;
if (args.Target is not { Valid: true } target ||
!HasComp<RCDComponent>(target) ||
!TryComp<LimitedChargesComponent>(target, out var charges))
return;
var current = _sharedCharges.GetCurrentCharges((target, charges));
var user = args.User;
args.Handled = true;
var count = Math.Min(charges.MaxCharges - current, comp.Charges);
if (count <= 0)
{
_popup.PopupEntity(Loc.GetString("rcd-ammo-component-after-interact-full"), target, user);
return;
}
_popup.PopupEntity(Loc.GetString("rcd-ammo-component-after-interact-refilled"), target, user);
_sharedCharges.AddCharges(target, count);
comp.Charges -= count;
Dirty(uid, comp);
// prevent having useless ammo with 0 charges
if (comp.Charges <= 0)
QueueDel(uid);
}
}