Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror: Added verb action to Glue/Lube system #303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions Content.Server/Glue/GlueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,13 +22,15 @@ 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()
{
base.Initialize();

SubscribeLocalEvent<GlueComponent, AfterInteractEvent>(OnInteract, after: new[] { typeof(OpenableSystem) });
SubscribeLocalEvent<GluedComponent, ComponentInit>(OnGluedInit);
SubscribeLocalEvent<GlueComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
SubscribeLocalEvent<GluedComponent, GotEquippedHandEvent>(OnHandPickUp);
}

Expand All @@ -41,35 +44,50 @@ private void OnInteract(Entity<GlueComponent> 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<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()
{
_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<GlueComponent> glue, EntityUid target, EntityUid actor)
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;
}

Expand Down
45 changes: 32 additions & 13 deletions Content.Server/Lube/LubeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -37,36 +41,51 @@ private void OnInteract(Entity<LubeComponent> 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<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()
{
_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<LubeComponent> lube, EntityUid target, EntityUid actor)
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;
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/glue/glue.ftl
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions Resources/Locale/en-US/lube/lube.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading