using Content.Shared._White.Xenomorphs; using Content.Shared._White.Xenomorphs.Plasma; using Content.Shared.Actions; using Content.Shared.Actions.Events; using Content.Shared.FixedPoint; using Content.Shared._White.Xenomorphs.Plasma.Components; namespace Content.Shared._White.Actions; public sealed class PlasmaCostActionSystem : EntitySystem { [Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly SharedPlasmaSystem _plasma = default!; public override void Initialize() { SubscribeLocalEvent>(OnPlasmaAmountChange); SubscribeLocalEvent(OnActionAttempt); // Goobstation } /// /// Checks if the performer has enough plasma for the action. /// Returns true if the action should proceed, false if it should be blocked. /// Goobstation /// public bool HasEnoughPlasma(EntityUid performer, FixedPoint2 cost) { if (cost <= 0) return true; return TryComp(performer, out var plasmaVessel) && plasmaVessel.Plasma >= cost; } /// /// Deducts plasma from the performer. Call this after confirming the action succeeds. /// public void DeductPlasma(EntityUid performer, FixedPoint2 cost) { if (cost > 0) _plasma.ChangePlasmaAmount(performer, -cost); } [Obsolete("Use HasEnoughPlasma and DeductPlasma separately for better control")] public bool CheckPlasmaCost(EntityUid performer, FixedPoint2 cost) { if (!HasEnoughPlasma(performer, cost)) return false; DeductPlasma(performer, cost); return true; } private void OnPlasmaAmountChange(EntityUid uid, PlasmaCostActionComponent component, ActionRelayedEvent args) { _actions.SetEnabled(uid, component.PlasmaCost <= args.Args.Amount); } private void OnActionAttempt(Entity ent, ref ActionAttemptEvent args) { if (!_plasma.HasPlasma(args.User, ent.Comp.PlasmaCost)) args.Cancelled = true; } }