using Content.Server.Power.Components; using Content.Server.Weapon.Ranged.Barrels.Components; using Content.Shared.ActionBlocker; using Content.Shared.Popups; using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; namespace Content.Server.Weapon.Ranged.Barrels { public sealed class BarrelSystem : EntitySystem { [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(AddSpinVerb); SubscribeLocalEvent(AddEjectCellVerb); SubscribeLocalEvent(AddInsertCellVerb); SubscribeLocalEvent(AddToggleBoltVerb); SubscribeLocalEvent(AddMagazineInteractionVerbs); SubscribeLocalEvent(AddEjectMagazineVerb); } private void AddSpinVerb(EntityUid uid, RevolverBarrelComponent component, GetAlternativeVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract) return; if (component.Capacity <= 1 || component.ShotsLeft == 0) return; Verb verb = new(); verb.Text = Loc.GetString("spin-revolver-verb-get-data-text"); verb.IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png"; verb.Act = () => { component.Spin(); component.Owner.PopupMessage(args.User, Loc.GetString("spin-revolver-verb-on-activate")); }; args.Verbs.Add(verb); } private void AddToggleBoltVerb(EntityUid uid, BoltActionBarrelComponent component, GetInteractionVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract) return; Verb verb = new(); verb.Text = component.BoltOpen ? Loc.GetString("close-bolt-verb-get-data-text") : Loc.GetString("open-bolt-verb-get-data-text"); verb.Act = () => component.BoltOpen = !component.BoltOpen; args.Verbs.Add(verb); } // TODO VERBS EJECTABLES Standardize eject/insert verbs into a single system? // Really, why isn't this just PowerCellSlotComponent? private void AddEjectCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetAlternativeVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract || !component.PowerCellRemovable || component.PowerCell == null || !_actionBlockerSystem.CanPickup(args.User.Uid)) return; Verb verb = new(); verb.Text = IoCManager.Resolve().GetComponent(component.PowerCell.Owner.Uid).EntityName; verb.Category = VerbCategory.Eject; verb.Act = () => component.TryEjectCell(args.User); args.Verbs.Add(verb); } private void AddInsertCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetInteractionVerbsEvent args) { if (args.Using == null || !args.CanAccess || !args.CanInteract || component.PowerCell != null || !IoCManager.Resolve().HasComponent(args.Using.Uid) || !_actionBlockerSystem.CanDrop(args.User.Uid)) return; Verb verb = new(); verb.Text = IoCManager.Resolve().GetComponent(args.Using.Uid).EntityName; verb.Category = VerbCategory.Insert; verb.Act = () => component.TryInsertPowerCell(args.Using); args.Verbs.Add(verb); } private void AddEjectMagazineVerb(EntityUid uid, ServerMagazineBarrelComponent component, GetAlternativeVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract || !component.HasMagazine || !_actionBlockerSystem.CanPickup(args.User.Uid)) return; if (component.MagNeedsOpenBolt && !component.BoltOpen) return; Verb verb = new(); verb.Text = IoCManager.Resolve().GetComponent(component.MagazineContainer.ContainedEntity!.Uid).EntityName; verb.Category = VerbCategory.Eject; verb.Act = () => component.RemoveMagazine(args.User); args.Verbs.Add(verb); } private void AddMagazineInteractionVerbs(EntityUid uid, ServerMagazineBarrelComponent component, GetInteractionVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract) return; // Toggle bolt verb Verb toggleBolt = new(); toggleBolt.Text = component.BoltOpen ? Loc.GetString("close-bolt-verb-get-data-text") : Loc.GetString("open-bolt-verb-get-data-text"); toggleBolt.Act = () => component.BoltOpen = !component.BoltOpen; args.Verbs.Add(toggleBolt); // Are we holding a mag that we can insert? if (args.Using == null || !component.CanInsertMagazine(args.User, args.Using) || !_actionBlockerSystem.CanDrop(args.User.Uid)) return; // Insert mag verb Verb insert = new(); insert.Text = IoCManager.Resolve().GetComponent(args.Using.Uid).EntityName; insert.Category = VerbCategory.Insert; insert.Act = () => component.InsertMagazine(args.User, args.Using); args.Verbs.Add(insert); } } }