Added verb action to Glue/Lube system (#26002)
* Added verb action to Glue/Lube system * Changes based on feedback * Fix TryGlue/Lube to use Entity<> rather than EntityUid, Component
This commit is contained in:
@@ -8,6 +8,7 @@ using Content.Shared.Interaction;
|
||||
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 sealed class GlueSystem : SharedGlueSystem
|
||||
|
||||
SubscribeLocalEvent<GlueComponent, AfterInteractEvent>(OnInteract, after: new[] { typeof(OpenableSystem) });
|
||||
SubscribeLocalEvent<GluedComponent, ComponentInit>(OnGluedInit);
|
||||
SubscribeLocalEvent<GlueComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
|
||||
SubscribeLocalEvent<GluedComponent, GotEquippedHandEvent>(OnHandPickUp);
|
||||
}
|
||||
|
||||
@@ -41,35 +44,50 @@ public sealed class GlueSystem : SharedGlueSystem
|
||||
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
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), args.User, args.User, PopupType.Medium);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGlue(Entity<GlueComponent> glue, EntityUid target, EntityUid actor)
|
||||
private void OnUtilityVerb(Entity<GlueComponent> entity, ref GetVerbsEvent<UtilityVerb> 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()
|
||||
{
|
||||
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<GlueComponent> 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<GluedComponent>(target) || !HasComp<ItemComponent>(target))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), actor, actor, PopupType.Medium);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasComp<ItemComponent>(target) && _solutionContainer.TryGetSolution(glue.Owner, glue.Comp.Solution, out _, out var solution))
|
||||
if (HasComp<ItemComponent>(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<GluedComponent>(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<GluedComponent>(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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user