mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
## Mirror of PR #25661: [Fix Butcherable handling, ItemSlots for clown shoes](https://github.com/space-wizards/space-station-14/pull/25661) 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) ###### `674b42b3a0ab9fa607887c1401f38ca1f8bb3911` PR opened by <img src="https://avatars.githubusercontent.com/u/42424291?v=4" width="16"/><a href="https://github.com/Krunklehorn"> Krunklehorn</a> at 2024-02-28 02:04:52 UTC --- PR changed 9 files with 75 additions and 30 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > ## About the PR > > - Fixes improper popups with edible+butcherable items, and sharp+utensil items > - Clown shoes have item slots > - Intended for non-harmful items other than their job specific gun > - Currently supports plastic knives, cap gun & fake cap gun > > Minor stuff... > - Spoons are metal > - Plastic knives are actually plastic knives > - Plastic utensils are now zero damage weapons > - Raw rat meat is sliceable > > > ## Why / Balance > > Funny suggestion, but also a legitimate way for a Clown to sneak their job specific gun into a holding cell/perma. > > > ## Media > > - [X] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > > **Changelog** > > 🆑 Krunk > - add: Clown & Jester shoes can now hold plastic knives and cap guns! All clowning, all the time! > </details> Co-authored-by: SimpleStation14 <Unknown>
83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
using Content.Shared.Containers.ItemSlots;
|
|
using Content.Server.Nutrition.Components;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Interaction;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Nutrition.EntitySystems
|
|
{
|
|
/// <summary>
|
|
/// Handles usage of the utensils on the food items
|
|
/// </summary>
|
|
internal sealed class UtensilSystem : SharedUtensilSystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
[Dependency] private readonly FoodSystem _foodSystem = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<UtensilComponent, AfterInteractEvent>(OnAfterInteract, after: new[] { typeof(ItemSlotsSystem) });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clicked with utensil
|
|
/// </summary>
|
|
private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev)
|
|
{
|
|
if (ev.Handled)
|
|
return;
|
|
|
|
if (ev.Target == null || !ev.CanReach)
|
|
return;
|
|
|
|
var result = TryUseUtensil(ev.User, ev.Target.Value, component);
|
|
ev.Handled = result.Handled;
|
|
}
|
|
|
|
public (bool Success, bool Handled) TryUseUtensil(EntityUid user, EntityUid target, UtensilComponent component)
|
|
{
|
|
if (!EntityManager.TryGetComponent(target, out FoodComponent? food))
|
|
return (false, true);
|
|
|
|
//Prevents food usage with a wrong utensil
|
|
if ((food.Utensil & component.Types) == 0)
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("food-system-wrong-utensil", ("food", target), ("utensil", component.Owner)), user, user);
|
|
return (false, true);
|
|
}
|
|
|
|
if (!_interactionSystem.InRangeUnobstructed(user, target, popup: true))
|
|
return (false, true);
|
|
|
|
return _foodSystem.TryFeed(user, user, target, food);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to break the utensil after interaction.
|
|
/// </summary>
|
|
/// <param name="uid">Utensil.</param>
|
|
/// <param name="userUid">User of the utensil.</param>
|
|
public void TryBreak(EntityUid uid, EntityUid userUid, UtensilComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (_robustRandom.Prob(component.BreakChance))
|
|
{
|
|
_audio.PlayPvs(component.BreakSound, userUid, AudioParams.Default.WithVolume(-2f));
|
|
EntityManager.DeleteEntity(uid);
|
|
}
|
|
}
|
|
}
|
|
}
|