Rat kings can butcher things (#32232)

* rat kings can butcher things

* minor organization

* fix

* important comma
This commit is contained in:
Plykiya
2024-09-21 16:21:52 -07:00
committed by GitHub
parent cd761eae69
commit 1b81ce4b53
2 changed files with 28 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ using Content.Shared.Storage;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Content.Shared.Destructible; using Content.Shared.Destructible;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
using Content.Shared.Hands.Components;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems; using Content.Shared.Mobs.Systems;
@@ -72,12 +73,17 @@ public sealed class SharpSystem : EntitySystem
if (!sharp.Butchering.Add(target)) if (!sharp.Butchering.Add(target))
return false; return false;
// if the user isn't the entity with the sharp component,
// they will need to be holding something with their hands, so we set needHand to true
// so that the doafter can be interrupted if they drop the item in their hands
var needHand = user != knife;
var doAfter = var doAfter =
new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife) new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife)
{ {
BreakOnDamage = true, BreakOnDamage = true,
BreakOnMove = true, BreakOnMove = true,
NeedHand = true, NeedHand = needHand,
}; };
_doAfterSystem.TryStartDoAfter(doAfter); _doAfterSystem.TryStartDoAfter(doAfter);
return true; return true;
@@ -136,13 +142,20 @@ public sealed class SharpSystem : EntitySystem
private void OnGetInteractionVerbs(EntityUid uid, ButcherableComponent component, GetVerbsEvent<InteractionVerb> args) private void OnGetInteractionVerbs(EntityUid uid, ButcherableComponent component, GetVerbsEvent<InteractionVerb> args)
{ {
if (component.Type != ButcheringType.Knife || args.Hands == null || !args.CanAccess || !args.CanInteract) if (component.Type != ButcheringType.Knife || !args.CanAccess || !args.CanInteract)
return; return;
bool disabled = false; // if the user has no hands, don't show them the verb if they have no SharpComponent either
if (!TryComp<SharpComponent>(args.User, out var userSharpComp) && args.Hands == null)
return;
var disabled = false;
string? message = null; string? message = null;
if (!HasComp<SharpComponent>(args.Using)) // if the user has hands
// and the item they're holding doesn't have the SharpComponent
// disable the verb
if (!TryComp<SharpComponent>(args.Using, out var usingSharpComp) && args.Hands != null)
{ {
disabled = true; disabled = true;
message = Loc.GetString("butcherable-need-knife", message = Loc.GetString("butcherable-need-knife",
@@ -150,9 +163,9 @@ public sealed class SharpSystem : EntitySystem
} }
else if (_containerSystem.IsEntityInContainer(uid)) else if (_containerSystem.IsEntityInContainer(uid))
{ {
disabled = true;
message = Loc.GetString("butcherable-not-in-container", message = Loc.GetString("butcherable-not-in-container",
("target", uid)); ("target", uid));
disabled = true;
} }
else if (TryComp<MobStateComponent>(uid, out var state) && !_mobStateSystem.IsDead(uid, state)) else if (TryComp<MobStateComponent>(uid, out var state) && !_mobStateSystem.IsDead(uid, state))
{ {
@@ -160,12 +173,20 @@ public sealed class SharpSystem : EntitySystem
message = Loc.GetString("butcherable-mob-isnt-dead"); message = Loc.GetString("butcherable-mob-isnt-dead");
} }
// set the object doing the butchering to the item in the user's hands or to the user themselves
// if either has the SharpComponent
EntityUid sharpObject = default;
if (usingSharpComp != null)
sharpObject = args.Using!.Value;
else if (userSharpComp != null)
sharpObject = args.User;
InteractionVerb verb = new() InteractionVerb verb = new()
{ {
Act = () => Act = () =>
{ {
if (!disabled) if (!disabled)
TryStartButcherDoafter(args.Using!.Value, args.Target, args.User); TryStartButcherDoafter(sharpObject, args.Target, args.User);
}, },
Message = message, Message = message,
Disabled = disabled, Disabled = disabled,

View File

@@ -121,6 +121,7 @@
- type: Grammar - type: Grammar
attributes: attributes:
gender: male gender: male
- type: Sharp
- type: entity - type: entity
id: MobRatKingBuff id: MobRatKingBuff