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:
@@ -2,11 +2,13 @@ using Content.Server.Administration.Logs;
|
||||
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<LubeComponent, AfterInteractEvent>(OnInteract, after: new[] { typeof(OpenableSystem) });
|
||||
SubscribeLocalEvent<LubeComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
|
||||
}
|
||||
|
||||
private void OnInteract(Entity<LubeComponent> entity, ref AfterInteractEvent args)
|
||||
@@ -37,36 +41,51 @@ public sealed class LubeSystem : EntitySystem
|
||||
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
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("lube-failure", ("target", Identity.Entity(target, EntityManager))), args.User, args.User, PopupType.Medium);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryLube(Entity<LubeComponent> lube, EntityUid target, EntityUid actor)
|
||||
private void OnUtilityVerb(Entity<LubeComponent> 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 = () => 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<LubeComponent> entity, EntityUid target, EntityUid actor)
|
||||
{
|
||||
if (HasComp<LubedComponent>(target) || !HasComp<ItemComponent>(target))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("lube-failure", ("target", Identity.Entity(target, EntityManager))), actor, actor, PopupType.Medium);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasComp<ItemComponent>(target) && _solutionContainer.TryGetSolution(lube.Owner, lube.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(lube.Comp.Reagent, lube.Comp.Consumption);
|
||||
var quantity = solution.RemoveReagent(entity.Comp.Reagent, entity.Comp.Consumption);
|
||||
if (quantity > 0)
|
||||
{
|
||||
var lubed = EnsureComp<LubedComponent>(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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user