From 3c6c69a6180cb947e6cf0136e581f571f7e34dda Mon Sep 17 00:00:00 2001 From: SimpleStation14 <130339894+SimpleStation14@users.noreply.github.com> Date: Wed, 8 May 2024 22:32:08 -0700 Subject: [PATCH] Mirror: Added verb action to Glue/Lube system (#303) ## Mirror of PR #26002: [Added verb action to Glue/Lube system](https://github.com/space-wizards/space-station-14/pull/26002) from space-wizards [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `70c718f61cd952f49f6908107edfbeeb3b7e41e0` PR opened by SlamBamActionman at 2024-03-11 15:15:49 UTC --- PR changed 4 files with 67 additions and 25 deletions. The PR had the following labels: ---

Original Body

> > > > ## About the PR > > > Added right-click Glue/Lube verbs (used by Space glue / lube tubes). This allows them to be used on containers and glasses. > > ## Why / Balance > > > Attempting to glue/lube a container like a bag makes the insert verb take priority. Same for trying to glue/lube something like a glass, which empties the reagent into the container. That keeps those objects from being glued/lubed, but with a right-click verb it is now possible. > > ## Technical details > > > Added a verb in each system using the Forensic Scanner verb implementation as a base. Had to move where the sound/pop-up message appears to avoid duplicating too much code. > > ## Media > > > ![image](https://github.com/space-wizards/space-station-14/assets/83650252/7560e99b-5167-497a-9f7c-e9db391e06eb)![image](https://github.com/space-wizards/space-station-14/assets/83650252/749c950e-c091-4e35-9813-6fa95eb7fd54) > > - [x] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > ## Breaking changes > > > **Changelog** > > > :cl: > - tweak: Space glue/lube tubes can now be used through the right-click menu. >
Co-authored-by: SimpleStation14 --- Content.Server/Glue/GlueSystem.cs | 42 ++++++++++++++++++-------- Content.Server/Lube/LubeSystem.cs | 45 ++++++++++++++++++++-------- Resources/Locale/en-US/glue/glue.ftl | 3 ++ Resources/Locale/en-US/lube/lube.ftl | 2 ++ 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Content.Server/Glue/GlueSystem.cs b/Content.Server/Glue/GlueSystem.cs index 6bb6aca3ad2..44ff4e54593 100644 --- a/Content.Server/Glue/GlueSystem.cs +++ b/Content.Server/Glue/GlueSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Interaction.Components; using Content.Shared.Item; using Content.Shared.Popups; +using Content.Shared.Verbs; using Robust.Shared.Audio.Systems; using Robust.Shared.Timing; @@ -21,6 +22,7 @@ public sealed class GlueSystem : SharedGlueSystem [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly OpenableSystem _openable = default!; public override void Initialize() { @@ -28,6 +30,7 @@ public override void Initialize() SubscribeLocalEvent(OnInteract, after: new[] { typeof(OpenableSystem) }); SubscribeLocalEvent(OnGluedInit); + SubscribeLocalEvent>(OnUtilityVerb); SubscribeLocalEvent(OnHandPickUp); } @@ -41,35 +44,50 @@ private void OnInteract(Entity entity, ref AfterInteractEvent arg return; if (TryGlue(entity, target, args.User)) - { args.Handled = true; - _audio.PlayPvs(entity.Comp.Squeeze, entity); - _popup.PopupEntity(Loc.GetString("glue-success", ("target", target)), args.User, args.User, PopupType.Medium); - } - else + } + + private void OnUtilityVerb(Entity entity, ref GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess || args.Target is not { Valid: true } target || + _openable.IsClosed(entity)) + return; + + var user = args.User; + + var verb = new UtilityVerb() { - _popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), args.User, args.User, PopupType.Medium); - } + Act = () => TryGlue(entity, target, user), + IconEntity = GetNetEntity(entity), + Text = Loc.GetString("glue-verb-text"), + Message = Loc.GetString("glue-verb-message") + }; + + args.Verbs.Add(verb); } - private bool TryGlue(Entity glue, EntityUid target, EntityUid actor) + private bool TryGlue(Entity entity, EntityUid target, EntityUid actor) { // if item is glued then don't apply glue again so it can be removed for reasonable time if (HasComp(target) || !HasComp(target)) { + _popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), actor, actor, PopupType.Medium); return false; } - if (HasComp(target) && _solutionContainer.TryGetSolution(glue.Owner, glue.Comp.Solution, out _, out var solution)) + if (HasComp(target) && _solutionContainer.TryGetSolution(entity.Owner, entity.Comp.Solution, out _, out var solution)) { - var quantity = solution.RemoveReagent(glue.Comp.Reagent, glue.Comp.ConsumptionUnit); + var quantity = solution.RemoveReagent(entity.Comp.Reagent, entity.Comp.ConsumptionUnit); if (quantity > 0) { - EnsureComp(target).Duration = quantity.Double() * glue.Comp.DurationPerUnit; - _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(actor):actor} glued {ToPrettyString(target):subject} with {ToPrettyString(glue.Owner):tool}"); + EnsureComp(target).Duration = quantity.Double() * entity.Comp.DurationPerUnit; + _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(actor):actor} glued {ToPrettyString(target):subject} with {ToPrettyString(entity.Owner):tool}"); + _audio.PlayPvs(entity.Comp.Squeeze, entity.Owner); + _popup.PopupEntity(Loc.GetString("glue-success", ("target", target)), actor, actor, PopupType.Medium); return true; } } + _popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), actor, actor, PopupType.Medium); return false; } diff --git a/Content.Server/Lube/LubeSystem.cs b/Content.Server/Lube/LubeSystem.cs index d777ae9406d..5285cb389c5 100644 --- a/Content.Server/Lube/LubeSystem.cs +++ b/Content.Server/Lube/LubeSystem.cs @@ -2,11 +2,13 @@ using Content.Server.Chemistry.Containers.EntitySystems; using Content.Server.Nutrition.EntitySystems; using Content.Shared.Database; +using Content.Shared.Glue; using Content.Shared.IdentityManagement; using Content.Shared.Interaction; using Content.Shared.Item; using Content.Shared.Lube; using Content.Shared.Popups; +using Content.Shared.Verbs; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Random; @@ -20,12 +22,14 @@ public sealed class LubeSystem : EntitySystem [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly OpenableSystem _openable = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnInteract, after: new[] { typeof(OpenableSystem) }); + SubscribeLocalEvent>(OnUtilityVerb); } private void OnInteract(Entity entity, ref AfterInteractEvent args) @@ -37,36 +41,51 @@ private void OnInteract(Entity entity, ref AfterInteractEvent arg return; if (TryLube(entity, target, args.User)) - { args.Handled = true; - _audio.PlayPvs(entity.Comp.Squeeze, entity); - _popup.PopupEntity(Loc.GetString("lube-success", ("target", Identity.Entity(target, EntityManager))), args.User, args.User, PopupType.Medium); - } - else + } + + private void OnUtilityVerb(Entity entity, ref GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess || args.Target is not { Valid: true } target || + _openable.IsClosed(entity)) + return; + + var user = args.User; + + var verb = new UtilityVerb() { - _popup.PopupEntity(Loc.GetString("lube-failure", ("target", Identity.Entity(target, EntityManager))), args.User, args.User, PopupType.Medium); - } + Act = () => TryLube(entity, target, user), + IconEntity = GetNetEntity(entity), + Text = Loc.GetString("lube-verb-text"), + Message = Loc.GetString("lube-verb-message") + }; + + args.Verbs.Add(verb); } - private bool TryLube(Entity lube, EntityUid target, EntityUid actor) + private bool TryLube(Entity entity, EntityUid target, EntityUid actor) { if (HasComp(target) || !HasComp(target)) { + _popup.PopupEntity(Loc.GetString("lube-failure", ("target", Identity.Entity(target, EntityManager))), actor, actor, PopupType.Medium); return false; } - if (HasComp(target) && _solutionContainer.TryGetSolution(lube.Owner, lube.Comp.Solution, out _, out var solution)) + if (HasComp(target) && _solutionContainer.TryGetSolution(entity.Owner, entity.Comp.Solution, out _, out var solution)) { - var quantity = solution.RemoveReagent(lube.Comp.Reagent, lube.Comp.Consumption); + var quantity = solution.RemoveReagent(entity.Comp.Reagent, entity.Comp.Consumption); if (quantity > 0) { var lubed = EnsureComp(target); - lubed.SlipsLeft = _random.Next(lube.Comp.MinSlips * quantity.Int(), lube.Comp.MaxSlips * quantity.Int()); - lubed.SlipStrength = lube.Comp.SlipStrength; - _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(actor):actor} lubed {ToPrettyString(target):subject} with {ToPrettyString(lube.Owner):tool}"); + lubed.SlipsLeft = _random.Next(entity.Comp.MinSlips * quantity.Int(), entity.Comp.MaxSlips * quantity.Int()); + lubed.SlipStrength = entity.Comp.SlipStrength; + _adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(actor):actor} lubed {ToPrettyString(target):subject} with {ToPrettyString(entity.Owner):tool}"); + _audio.PlayPvs(entity.Comp.Squeeze, entity.Owner); + _popup.PopupEntity(Loc.GetString("lube-success", ("target", Identity.Entity(target, EntityManager))), actor, actor, PopupType.Medium); return true; } } + _popup.PopupEntity(Loc.GetString("lube-failure", ("target", Identity.Entity(target, EntityManager))), actor, actor, PopupType.Medium); return false; } } diff --git a/Resources/Locale/en-US/glue/glue.ftl b/Resources/Locale/en-US/glue/glue.ftl index 1d0db515cb8..1a711d51c21 100644 --- a/Resources/Locale/en-US/glue/glue.ftl +++ b/Resources/Locale/en-US/glue/glue.ftl @@ -1,3 +1,6 @@ glue-success = {THE($target)} has been covered in glue! glued-name-prefix = Glued {$target} glue-failure = Can't cover {THE($target)} in glue! +glue-verb-text = Apply Glue +glue-verb-message = Glue an object + diff --git a/Resources/Locale/en-US/lube/lube.ftl b/Resources/Locale/en-US/lube/lube.ftl index 57af8f774af..92dd2802ec7 100644 --- a/Resources/Locale/en-US/lube/lube.ftl +++ b/Resources/Locale/en-US/lube/lube.ftl @@ -2,3 +2,5 @@ lube-success = {THE($target)} has been covered in lube! lubed-name-prefix = Lubed {$target} lube-failure = Can't cover {THE($target)} in lube! lube-slip = {THE($target)} slips out of your hands! +lube-verb-text = Apply Lube +lube-verb-message = Lube an object