From 70422845e2778c5239ed6a0a9088f3fbac8c91fe Mon Sep 17 00:00:00 2001 From: Errant <35878406+Errant-4@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:42:36 +0000 Subject: [PATCH] Gun bolt fixes and QoL (#19349) Co-authored-by: Errant <35878406+errant@users.noreply.github.com> --- .../SharedGunSystem.ChamberMagazine.cs | 47 +++++++++++++------ Resources/Locale/en-US/weapons/ranged/gun.ftl | 2 + 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs index 04e92e8c1d..31fbde44f4 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs @@ -25,7 +25,6 @@ public abstract partial class SharedGunSystem * Racking does both in one hit and has a different sound (to avoid RSI + sounds cooler). */ - SubscribeLocalEvent>(OnChamberVerb); SubscribeLocalEvent>(OnChamberActivationVerb); SubscribeLocalEvent>(OnChamberInteractionVerb); SubscribeLocalEvent>(OnMagazineVerb); @@ -47,18 +46,9 @@ public abstract partial class SharedGunSystem } } - private void OnChamberVerb(EntityUid uid, ChamberMagazineAmmoProviderComponent component, GetVerbsEvent args) - { - if (component.BoltClosed != null) - { - args.Verbs.Add(new Verb() - { - Text = component.BoltClosed.Value ? Loc.GetString("gun-chamber-bolt-open") : Loc.GetString("gun-chamber-bolt-close"), - Act = () => ToggleBolt(uid, component, args.User), - }); - } - } - + /// + /// Called when user "Activated In World" (E) with the gun as the target + /// private void OnChamberActivate(EntityUid uid, ChamberMagazineAmmoProviderComponent component, ActivateInWorldEvent args) { if (args.Handled) @@ -68,6 +58,9 @@ public abstract partial class SharedGunSystem ToggleBolt(uid, component, args.User); } + /// + /// Called when gun was "Activated In Hand" (Z) + /// private void OnChamberUse(EntityUid uid, ChamberMagazineAmmoProviderComponent component, UseInHandEvent args) { if (args.Handled) @@ -77,6 +70,9 @@ public abstract partial class SharedGunSystem UseChambered(uid, component, args.User); } + /// + /// Creates "Rack" verb on the gun + /// private void OnChamberActivationVerb(EntityUid uid, ChamberMagazineAmmoProviderComponent component, GetVerbsEvent args) { if (!args.CanAccess || !args.CanInteract || component.BoltClosed == null) @@ -92,10 +88,16 @@ public abstract partial class SharedGunSystem }); } + /// + /// Opens then closes the bolt, or just closes it if currently open. + /// private void UseChambered(EntityUid uid, ChamberMagazineAmmoProviderComponent component, EntityUid? user = null) { if (component.BoltClosed == false) + { + ToggleBolt(uid, component, user); return; + } if (TryTakeChamberEntity(uid, out var chamberEnt)) { @@ -118,6 +120,9 @@ public abstract partial class SharedGunSystem } } + /// + /// Creates "Open/Close bolt" verb on the gun + /// private void OnChamberInteractionVerb(EntityUid uid, ChamberMagazineAmmoProviderComponent component, GetVerbsEvent args) { if (!args.CanAccess || !args.CanInteract || component.BoltClosed == null) @@ -134,6 +139,9 @@ public abstract partial class SharedGunSystem }); } + /// + /// Updates the bolt to its new state + /// public void SetBoltClosed(EntityUid uid, ChamberMagazineAmmoProviderComponent component, bool value, EntityUid? user = null, AppearanceComponent? appearance = null, ItemSlotsComponent? slots = null) { if (component.BoltClosed == null || value == component.BoltClosed) @@ -235,6 +243,9 @@ public abstract partial class SharedGunSystem } } + /// + /// Sets the bolt's positional value to the other state + /// public void ToggleBolt(EntityUid uid, ChamberMagazineAmmoProviderComponent component, EntityUid? user = null) { if (component.BoltClosed == null) @@ -243,16 +254,24 @@ public abstract partial class SharedGunSystem SetBoltClosed(uid, component, !component.BoltClosed.Value, user); } + /// + /// Called when the gun was Examined + /// private void OnChamberMagazineExamine(EntityUid uid, ChamberMagazineAmmoProviderComponent component, ExaminedEvent args) { if (!args.IsInDetailsRange) return; var (count, _) = GetChamberMagazineCountCapacity(uid, component); + string boltState; if (component.BoltClosed != null) { - args.PushMarkup(Loc.GetString("gun-chamber-bolt", ("bolt", component.BoltClosed), ("color", component.BoltClosed.Value ? Color.FromHex("#94e1f2") : Color.FromHex("#f29d94")))); + if (component.BoltClosed == true) + boltState = Loc.GetString("gun-chamber-bolt-open-state"); + else + boltState = Loc.GetString("gun-chamber-bolt-closed-state"); + args.PushMarkup(Loc.GetString("gun-chamber-bolt", ("bolt", boltState), ("color", component.BoltClosed.Value ? Color.FromHex("#94e1f2") : Color.FromHex("#f29d94")))); } args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", count))); diff --git a/Resources/Locale/en-US/weapons/ranged/gun.ftl b/Resources/Locale/en-US/weapons/ranged/gun.ftl index 8b99fba592..fe60f3eed1 100644 --- a/Resources/Locale/en-US/weapons/ranged/gun.ftl +++ b/Resources/Locale/en-US/weapons/ranged/gun.ftl @@ -34,6 +34,8 @@ gun-chamber-bolt-closed = Closed bolt gun-chamber-bolt-opened = Opened bolt gun-chamber-bolt-close = Close bolt gun-chamber-bolt-open = Open bolt +gun-chamber-bolt-closed-state = open +gun-chamber-bolt-open-state = closed gun-chamber-rack = Rack # MagazineAmmoProvider