Add knife butchering and blood gibbing (#6770)

This commit is contained in:
mirrorcult
2022-02-18 15:57:42 -07:00
committed by GitHub
parent 67661ddbdb
commit 676ca21b5f
28 changed files with 223 additions and 45 deletions

View File

@@ -92,7 +92,7 @@ namespace Content.Server.Kitchen.EntitySystems
if (!Resolve(uid, ref component) || !Resolve(victimUid, ref butcherable))
return;
component.MeatPrototype = butcherable.MeatPrototype;
component.MeatPrototype = butcherable.SpawnedPrototype;
component.MeatParts = butcherable.Pieces;
// This feels not okay, but entity is getting deleted on "Spike", for now...
@@ -164,7 +164,7 @@ namespace Content.Server.Kitchen.EntitySystems
return false;
}
if (!Resolve(victimUid, ref butcherable, false) || butcherable.MeatPrototype == null)
if (!Resolve(victimUid, ref butcherable, false) || butcherable.SpawnedPrototype == null)
{
_popupSystem.PopupEntity(Loc.GetString("comp-kitchen-spike-deny-butcher", ("victim", victimUid), ("this", uid)), victimUid, Filter.Entities(userUid));
return false;
@@ -180,6 +180,9 @@ namespace Content.Server.Kitchen.EntitySystems
!Resolve(victimUid, ref butcherable) || butcherable.BeingButchered)
return false;
if (butcherable.Type != ButcheringType.Spike)
return false;
// THE WHAT? (again)
// Prevent dead from being spiked TODO: Maybe remove when rounds can be played and DOT is implemented
if (Resolve(victimUid, ref mobState, false) &&
@@ -201,7 +204,7 @@ namespace Content.Server.Kitchen.EntitySystems
butcherable.BeingButchered = true;
component.InUse = true;
var doAfterArgs = new DoAfterEventArgs(userUid, component.SpikeDelay, default, uid)
var doAfterArgs = new DoAfterEventArgs(userUid, component.SpikeDelay + butcherable.ButcherDelay, default, uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,

View File

@@ -0,0 +1,105 @@
using Content.Server.DoAfter;
using Content.Server.Kitchen.Components;
using Content.Server.Popups;
using Content.Shared.Body.Components;
using Content.Shared.Interaction;
using Content.Shared.MobState.Components;
using Content.Shared.Nutrition.Components;
using Content.Shared.Popups;
using Robust.Shared.Player;
namespace Content.Server.Kitchen.EntitySystems;
public sealed class SharpSystem : EntitySystem
{
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharpComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<SharpButcherDoafterComplete>(OnDoafterComplete);
SubscribeLocalEvent<SharpButcherDoafterCancelled>(OnDoafterCancelled);
}
private void OnAfterInteract(EntityUid uid, SharpComponent component, AfterInteractEvent args)
{
if (args.Target is null || !TryComp<SharedButcherableComponent>(args.Target, out var butcher))
return;
if (butcher.Type != ButcheringType.Knife)
return;
if (TryComp<MobStateComponent>(args.Target, out var mobState) && !mobState.IsDead())
return;
if (!component.Butchering.Add(args.Target.Value))
return;
var doAfter =
new DoAfterEventArgs(args.User, component.ButcherDelayModifier * butcher.ButcherDelay, default, args.Target)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnStun = true,
NeedHand = true,
BroadcastFinishedEvent = new SharpButcherDoafterComplete { User = args.User, Entity = args.Target.Value, Sharp = uid },
BroadcastCancelledEvent = new SharpButcherDoafterCancelled { Entity = args.Target.Value, Sharp = uid }
};
_doAfterSystem.DoAfter(doAfter);
}
private void OnDoafterComplete(SharpButcherDoafterComplete ev)
{
if (!TryComp<SharedButcherableComponent>(ev.Entity, out var butcher))
return;
if (!TryComp<SharpComponent>(ev.Sharp, out var sharp))
return;
sharp.Butchering.Remove(ev.Entity);
EntityUid popupEnt = default;
for (int i = 0; i < butcher.Pieces; i++)
{
popupEnt = Spawn(butcher.SpawnedPrototype, Transform(ev.Entity).Coordinates);
}
_popupSystem.PopupEntity(Loc.GetString("butcherable-knife-butchered-success", ("target", ev.Entity), ("knife", ev.Sharp)),
popupEnt, Filter.Entities(ev.User));
if (TryComp<SharedBodyComponent>(ev.Entity, out var body))
{
body.Gib();
}
else
{
QueueDel(ev.Entity);
}
}
private void OnDoafterCancelled(SharpButcherDoafterCancelled ev)
{
if (!TryComp<SharpComponent>(ev.Sharp, out var sharp))
return;
sharp.Butchering.Remove(ev.Entity);
}
}
public sealed class SharpButcherDoafterComplete : EntityEventArgs
{
public EntityUid Entity;
public EntityUid Sharp;
public EntityUid User;
}
public sealed class SharpButcherDoafterCancelled : EntityEventArgs
{
public EntityUid Entity;
public EntityUid Sharp;
}