Skip to content

Commit

Permalink
Rat kings can butcher things (#32232)
Browse files Browse the repository at this point in the history
* rat kings can butcher things

* minor organization

* fix

* important comma
  • Loading branch information
Plykiya authored Sep 21, 2024
1 parent cd761ea commit 1b81ce4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
33 changes: 27 additions & 6 deletions Content.Server/Kitchen/EntitySystems/SharpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Content.Shared.Verbs;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.Hands.Components;
using Content.Shared.Kitchen;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
Expand Down Expand Up @@ -72,12 +73,17 @@ private bool TryStartButcherDoafter(EntityUid knife, EntityUid target, EntityUid
if (!sharp.Butchering.Add(target))
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 =
new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife)
{
BreakOnDamage = true,
BreakOnMove = true,
NeedHand = true,
NeedHand = needHand,
};
_doAfterSystem.TryStartDoAfter(doAfter);
return true;
Expand Down Expand Up @@ -136,36 +142,51 @@ private void OnDoAfter(EntityUid uid, SharpComponent component, DoAfterEvent arg

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;

// 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;

bool disabled = false;
var disabled = false;
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;
message = Loc.GetString("butcherable-need-knife",
("target", uid));
}
else if (_containerSystem.IsEntityInContainer(uid))
{
disabled = true;
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");
}

// 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()
{
Act = () =>
{
if (!disabled)
TryStartButcherDoafter(args.Using!.Value, args.Target, args.User);
TryStartButcherDoafter(sharpObject, args.Target, args.User);
},
Message = message,
Disabled = disabled,
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
- type: Grammar
attributes:
gender: male
- type: Sharp

- type: entity
id: MobRatKingBuff
Expand Down

0 comments on commit 1b81ce4

Please sign in to comment.