Files
OldThink/Content.Server/Lube/LubeSystem.cs

73 lines
2.8 KiB
C#
Raw Normal View History

2023-08-04 21:18:29 -05:00
using Content.Server.Administration.Logs;
using Content.Server.Chemistry.Containers.EntitySystems;
2023-09-23 03:10:04 +01:00
using Content.Server.Nutrition.EntitySystems;
2023-08-04 21:18:29 -05:00
using Content.Shared.Database;
2023-06-28 05:48:06 +03:00
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Lube;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
2023-06-28 05:48:06 +03:00
using Robust.Shared.Random;
namespace Content.Server.Lube;
public sealed class LubeSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly IRobustRandom _random = default!;
2023-08-04 21:18:29 -05:00
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
2023-06-28 05:48:06 +03:00
public override void Initialize()
{
base.Initialize();
2023-09-23 03:10:04 +01:00
SubscribeLocalEvent<LubeComponent, AfterInteractEvent>(OnInteract, after: new[] { typeof(OpenableSystem) });
2023-06-28 05:48:06 +03:00
}
private void OnInteract(Entity<LubeComponent> entity, ref AfterInteractEvent args)
2023-06-28 05:48:06 +03:00
{
if (args.Handled)
return;
if (!args.CanReach || args.Target is not { Valid: true } target)
return;
if (TryLube(entity, target, args.User))
2023-06-28 05:48:06 +03:00
{
args.Handled = true;
_audio.PlayPvs(entity.Comp.Squeeze, entity);
2023-06-28 05:48:06 +03:00
_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)
2023-06-28 05:48:06 +03:00
{
if (HasComp<LubedComponent>(target) || !HasComp<ItemComponent>(target))
{
return false;
}
if (HasComp<ItemComponent>(target) && _solutionContainer.TryGetSolution(lube.Owner, lube.Comp.Solution, out _, out var solution))
2023-06-28 05:48:06 +03:00
{
var quantity = solution.RemoveReagent(lube.Comp.Reagent, lube.Comp.Consumption);
2023-06-28 05:48:06 +03:00
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}");
2023-06-28 05:48:06 +03:00
return true;
}
}
return false;
}
}