mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
## Mirror of PR #25980: [Add admin logs for butchering](https://github.com/space-wizards/space-station-14/pull/25980) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `f9bb70aea170f8f02b5245a256a5136f3da70509` PR opened by <img src="https://avatars.githubusercontent.com/u/62253058?v=4" width="16"/><a href="https://github.com/Gyrandola"> Gyrandola</a> at 2024-03-10 22:13:55 UTC PR merged by <img src="https://avatars.githubusercontent.com/u/19864447?v=4" width="16"/><a href="https://github.com/web-flow"> web-flow</a> at 2024-03-11 01:41:02 UTC --- PR changed 1 files with 8 additions and 1 deletions. The PR had the following labels: --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > ## About the PR > <!-- What did you change in this PR? --> > Adds an admin log for when someone successfully butchers something. The attempt was already logged. > > ## Why / Balance > <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> > Fixes #25278 > > ## Technical details > <!-- If this is a code change, summarize at high level how your new code works. This makes it easier to review. --> > Added a couple dependencies and the log at the end of SharpSystem's OnDoAfter. > > ## Media > <!-- > PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. > Small fixes/refactors are exempt. > Any media may be used in SS14 progress reports, with clear credit given. > > If you're unsure whether your PR will require media, ask a maintainer. > > Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): > --> > > - [X] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase >  > </details> Co-authored-by: Gyrandola <pasta.frollagg@gmail.com>
175 lines
6.2 KiB
C#
175 lines
6.2 KiB
C#
using Content.Server.Body.Systems;
|
|
using Content.Server.Kitchen.Components;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Body.Components;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Storage;
|
|
using Content.Shared.Verbs;
|
|
using Content.Shared.Destructible;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Kitchen;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Robust.Server.Containers;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Kitchen.EntitySystems;
|
|
|
|
public sealed class SharpSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly BodySystem _bodySystem = default!;
|
|
[Dependency] private readonly SharedDestructibleSystem _destructibleSystem = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly ContainerSystem _containerSystem = default!;
|
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<SharpComponent, AfterInteractEvent>(OnAfterInteract);
|
|
SubscribeLocalEvent<SharpComponent, SharpDoAfterEvent>(OnDoAfter);
|
|
|
|
SubscribeLocalEvent<ButcherableComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
|
|
}
|
|
|
|
private void OnAfterInteract(EntityUid uid, SharpComponent component, AfterInteractEvent args)
|
|
{
|
|
if (args.Target is null || !args.CanReach)
|
|
return;
|
|
|
|
TryStartButcherDoafter(uid, args.Target.Value, args.User);
|
|
}
|
|
|
|
private void TryStartButcherDoafter(EntityUid knife, EntityUid target, EntityUid user)
|
|
{
|
|
if (!TryComp<ButcherableComponent>(target, out var butcher))
|
|
return;
|
|
|
|
if (!TryComp<SharpComponent>(knife, out var sharp))
|
|
return;
|
|
|
|
if (butcher.Type != ButcheringType.Knife)
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("butcherable-different-tool", ("target", target)), knife, user);
|
|
return;
|
|
}
|
|
|
|
if (TryComp<MobStateComponent>(target, out var mobState) && !_mobStateSystem.IsDead(target, mobState))
|
|
return;
|
|
|
|
if (!sharp.Butchering.Add(target))
|
|
return;
|
|
|
|
var doAfter =
|
|
new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife)
|
|
{
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
BreakOnDamage = true,
|
|
NeedHand = true
|
|
};
|
|
_doAfterSystem.TryStartDoAfter(doAfter);
|
|
}
|
|
|
|
private void OnDoAfter(EntityUid uid, SharpComponent component, DoAfterEvent args)
|
|
{
|
|
if (args.Handled || !TryComp<ButcherableComponent>(args.Args.Target, out var butcher))
|
|
return;
|
|
|
|
if (args.Cancelled)
|
|
{
|
|
component.Butchering.Remove(args.Args.Target.Value);
|
|
return;
|
|
}
|
|
|
|
component.Butchering.Remove(args.Args.Target.Value);
|
|
|
|
if (_containerSystem.IsEntityInContainer(args.Args.Target.Value))
|
|
{
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
|
|
var spawnEntities = EntitySpawnCollection.GetSpawns(butcher.SpawnedEntities, _robustRandom);
|
|
var coords = Transform(args.Args.Target.Value).MapPosition;
|
|
EntityUid popupEnt = default!;
|
|
foreach (var proto in spawnEntities)
|
|
{
|
|
// distribute the spawned items randomly in a small radius around the origin
|
|
popupEnt = Spawn(proto, coords.Offset(_robustRandom.NextVector2(0.25f)));
|
|
}
|
|
|
|
var hasBody = TryComp<BodyComponent>(args.Args.Target.Value, out var body);
|
|
|
|
// only show a big popup when butchering living things.
|
|
var popupType = PopupType.Small;
|
|
if (hasBody)
|
|
popupType = PopupType.LargeCaution;
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("butcherable-knife-butchered-success", ("target", args.Args.Target.Value), ("knife", uid)),
|
|
popupEnt, args.Args.User, popupType);
|
|
|
|
if (hasBody)
|
|
_bodySystem.GibBody(args.Args.Target.Value, body: body);
|
|
|
|
_destructibleSystem.DestroyEntity(args.Args.Target.Value);
|
|
|
|
args.Handled = true;
|
|
|
|
_adminLogger.Add(LogType.Gib,
|
|
$"{EntityManager.ToPrettyString(args.User):user} " +
|
|
$"has butchered {EntityManager.ToPrettyString(args.Target):target} " +
|
|
$"with {EntityManager.ToPrettyString(args.Used):knife}");
|
|
}
|
|
|
|
private void OnGetInteractionVerbs(EntityUid uid, ButcherableComponent component, GetVerbsEvent<InteractionVerb> args)
|
|
{
|
|
if (component.Type != ButcheringType.Knife || args.Hands == null || !args.CanAccess || !args.CanInteract)
|
|
return;
|
|
|
|
bool disabled = false;
|
|
string? message = null;
|
|
|
|
if (!HasComp<SharpComponent>(args.Using))
|
|
{
|
|
disabled = true;
|
|
message = Loc.GetString("butcherable-need-knife",
|
|
("target", uid));
|
|
}
|
|
else if (_containerSystem.IsEntityInContainer(uid))
|
|
{
|
|
message = Loc.GetString("butcherable-not-in-container",
|
|
("target", uid));
|
|
disabled = true;
|
|
}
|
|
else if (TryComp<MobStateComponent>(uid, out var state) && !_mobStateSystem.IsDead(uid, state))
|
|
{
|
|
disabled = true;
|
|
message = Loc.GetString("butcherable-mob-isnt-dead");
|
|
}
|
|
|
|
InteractionVerb verb = new()
|
|
{
|
|
Act = () =>
|
|
{
|
|
if (!disabled)
|
|
TryStartButcherDoafter(args.Using!.Value, args.Target, args.User);
|
|
},
|
|
Message = message,
|
|
Disabled = disabled,
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/cutlery.svg.192dpi.png")),
|
|
Text = Loc.GetString("butcherable-verb-name"),
|
|
};
|
|
|
|
args.Verbs.Add(verb);
|
|
}
|
|
}
|