2021-11-29 16:27:15 +13:00
|
|
|
using Content.Shared.Administration.Logs;
|
2025-06-09 07:36:04 -07:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2021-11-29 16:27:15 +13:00
|
|
|
using Content.Shared.Database;
|
2025-08-06 09:53:38 -07:00
|
|
|
using Content.Shared.Forensics;
|
2022-07-29 14:13:12 +12:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
|
|
|
|
using Content.Shared.IdentityManagement;
|
2021-11-21 10:35:09 +03:00
|
|
|
using Content.Shared.Interaction;
|
2022-07-29 14:13:12 +12:00
|
|
|
using Content.Shared.Interaction.Events;
|
|
|
|
|
using Content.Shared.Inventory;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs.Systems;
|
2025-06-09 07:36:04 -07:00
|
|
|
using Content.Shared.Nutrition.Components;
|
|
|
|
|
using Content.Shared.Popups;
|
2023-10-10 20:06:24 -07:00
|
|
|
using Content.Shared.Verbs;
|
2021-11-21 10:35:09 +03:00
|
|
|
using Robust.Shared.Audio;
|
2023-12-28 20:45:42 -07:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-06-09 07:36:04 -07:00
|
|
|
namespace Content.Shared.Nutrition.EntitySystems;
|
2023-09-23 03:10:04 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles feeding attempts both on yourself and on the target.
|
|
|
|
|
/// </summary>
|
2025-08-06 09:53:38 -07:00
|
|
|
[Obsolete("Migration to Content.Shared.Nutrition.EntitySystems.IngestionSystem is required")]
|
2023-09-23 03:10:04 +01:00
|
|
|
public sealed class FoodSystem : EntitySystem
|
2021-11-21 10:35:09 +03:00
|
|
|
{
|
2023-09-23 03:10:04 +01:00
|
|
|
[Dependency] private readonly FlavorProfileSystem _flavorProfile = default!;
|
2025-08-06 09:53:38 -07:00
|
|
|
[Dependency] private readonly IngestionSystem _ingestion = default!;
|
2023-09-23 03:10:04 +01:00
|
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
|
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
2025-06-09 07:36:04 -07:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
2023-09-23 03:10:04 +01:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
2024-08-02 00:30:45 -07:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
2025-06-09 07:36:04 -07:00
|
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
2023-09-23 03:10:04 +01:00
|
|
|
|
|
|
|
|
public const float MaxFeedDistance = 1.0f;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2025-06-09 07:36:04 -07:00
|
|
|
SubscribeLocalEvent<FoodComponent, UseInHandEvent>(OnUseFoodInHand, after: new[] { typeof(OpenableSystem), typeof(InventorySystem) });
|
2023-09-23 03:10:04 +01:00
|
|
|
SubscribeLocalEvent<FoodComponent, AfterInteractEvent>(OnFeedFood);
|
2025-08-06 09:53:38 -07:00
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
SubscribeLocalEvent<FoodComponent, GetVerbsEvent<AlternativeVerb>>(AddEatVerb);
|
2025-08-06 09:53:38 -07:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, BeforeIngestedEvent>(OnBeforeFoodEaten);
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, IngestedEvent>(OnFoodEaten);
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, FullyEatenEvent>(OnFoodFullyEaten);
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, GetUtensilsEvent>(OnGetUtensils);
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, IsDigestibleEvent>(OnIsFoodDigestible);
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, EdibleEvent>(OnFood);
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, GetEdibleTypeEvent>(OnGetEdibleType);
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FoodComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-21 10:35:09 +03:00
|
|
|
/// <summary>
|
2025-08-06 09:53:38 -07:00
|
|
|
/// Eat or drink an item
|
2021-11-21 10:35:09 +03:00
|
|
|
/// </summary>
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnUseFoodInHand(Entity<FoodComponent> entity, ref UseInHandEvent ev)
|
2021-11-21 10:35:09 +03:00
|
|
|
{
|
2023-09-23 03:10:04 +01:00
|
|
|
if (ev.Handled)
|
|
|
|
|
return;
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
ev.Handled = _ingestion.TryIngest(ev.User, ev.User, entity);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Feed someone else
|
|
|
|
|
/// </summary>
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnFeedFood(Entity<FoodComponent> entity, ref AfterInteractEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
|
|
|
|
if (args.Handled || args.Target == null || !args.CanReach)
|
|
|
|
|
return;
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
args.Handled = _ingestion.TryIngest(args.User, args.Target.Value, entity);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void AddEatVerb(Entity<FoodComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
var user = args.User;
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (entity.Owner == user || !args.CanInteract || !args.CanAccess)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
Flavor profiles (#10991)
* flavor profiles
TODO: every single flavor! yeah!!!
* adds basic localization, and flavors/lastFlavor values for when you get the flavor profile message
* multiple and single flavor messages
* start on flavor localization, multiple flavors in localized flavors
* flavor prototypes
* a few more flavors, descriptions on what each section of the flavor file should be doing
* localization for flavor profiles in drink/food system
* adds an event that allows a flavor profile list to be transformed base on the user entity
* raises it on the food entity too
* changes a field in flavor, adds some more flavors, starts adding flavor prototypes
* adds basic flavors to several entities, and consumable drinks, renames flavor field to 'flavors'
* changes call ordering in flavorprofile, adds flavor to ignored components server-side
flavor is really just a popup message, and those are all processed server-side
* fixes where food tried to get the flavor of the user instead of the food
* single flavors will now get the localized string
* getting the flavor message now ensures that flavors are deduplicated
* makes flavor processing more strictly unique bu making everything hashsets
* yeah, that could just not have distinctby now
* adds flavorprofile directly to food base instead for generic food taste
* FlavorProfileModificationEvent now passes a hashset of strings and not flavorprototypes
* flavorprofilesystem now broadcasts the flavor profile modification event
* adds more flavors to the flavor profile loc file
* skips a flavor, if the flavor string is null/empty
* adds some more flavors, adds generic medicine flavor to medicinal chemicals
* more food flavors, adds flavors to swallowing
* adds some cocktails to the set of flavor profiles
* regenerates flavor prototypes
* adds flavor type to all flavors, adds whitespace between variants
* adds more flavors, adds flavors to several chemicals and food items
this is the part that took the longest
* changes backup flavor message
* spelling mistake
* more flavors, and flavors on food
* readds all the type fields, whoops
* fixes localization strings for forcefeeding food/drink
* fixes multiple flavor profile
* adds flavor limit for flavors
* makes that fetch the cvardef instead
2022-09-08 16:14:49 -07:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (!_ingestion.TryGetIngestionVerb(user, entity, IngestionSystem.Food, out var verb))
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2023-03-05 00:26:03 -05:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
2023-04-03 13:13:48 +12:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnBeforeFoodEaten(Entity<FoodComponent> food, ref BeforeIngestedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Cancelled || args.Solution is not { } solution)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2023-04-17 19:56:42 +12:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// Set it to transfer amount if it exists, otherwise eat the whole volume if possible.
|
|
|
|
|
args.Transfer = food.Comp.TransferAmount ?? solution.Volume;
|
|
|
|
|
}
|
2023-05-02 04:57:11 +10:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnFoodEaten(Entity<FoodComponent> entity, ref IngestedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2023-04-03 13:13:48 +12:00
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
args.Handled = true;
|
2023-05-03 19:49:25 -07:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
_audio.PlayPredicted(entity.Comp.UseSound, args.Target, args.User, AudioParams.Default.WithVolume(-1f).WithVariation(0.20f));
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
var flavors = _flavorProfile.GetLocalizedFlavorsMessage(entity.Owner, args.Target, args.Split);
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (args.ForceFed)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
var targetName = Identity.Entity(args.Target, EntityManager);
|
2023-09-23 03:10:04 +01:00
|
|
|
var userName = Identity.Entity(args.User, EntityManager);
|
2025-08-06 09:53:38 -07:00
|
|
|
_popup.PopupEntity(Loc.GetString("edible-force-feed-success", ("user", userName), ("verb", _ingestion.GetProtoVerb(IngestionSystem.Food)), ("flavors", flavors)), entity, entity);
|
2022-02-07 00:37:38 +11:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
_popup.PopupClient(Loc.GetString("edible-force-feed-success-user", ("target", targetName), ("verb", _ingestion.GetProtoVerb(IngestionSystem.Food))), args.User, args.User);
|
2022-12-02 19:19:44 -06:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// log successful forced feeding
|
|
|
|
|
_adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(entity):user} forced {ToPrettyString(args.User):target} to eat {ToPrettyString(entity):food}");
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-09 07:36:04 -07:00
|
|
|
_popup.PopupClient(Loc.GetString(entity.Comp.EatMessage, ("food", entity.Owner), ("flavors", flavors)), args.User, args.User);
|
2022-12-02 19:19:44 -06:00
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
// log successful voluntary eating
|
2025-08-06 09:53:38 -07:00
|
|
|
_adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(args.User):target} ate {ToPrettyString(entity):food}");
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// BREAK OUR UTENSILS
|
|
|
|
|
if (_ingestion.TryGetUtensils(args.User, entity, out var utensils))
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
foreach (var utensil in utensils)
|
2023-04-15 18:14:26 -04:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
_ingestion.TryBreak(utensil, args.User);
|
2023-04-15 18:14:26 -04:00
|
|
|
}
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2025-08-06 09:53:38 -07:00
|
|
|
|
|
|
|
|
if (_ingestion.GetUsesRemaining(entity, entity.Comp.Solution, args.Split.Volume) > 0)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
// Leave some of the consumer's DNA on the consumed item...
|
|
|
|
|
var ev = new TransferDnaEvent
|
|
|
|
|
{
|
|
|
|
|
Donor = args.Target,
|
|
|
|
|
Recipient = entity,
|
|
|
|
|
CanDnaBeCleaned = false,
|
|
|
|
|
};
|
|
|
|
|
RaiseLocalEvent(args.Target, ref ev);
|
|
|
|
|
|
|
|
|
|
args.Repeat = !args.ForceFed;
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2021-11-21 10:35:09 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// Food is always destroyed...
|
|
|
|
|
args.Destroy = true;
|
2023-11-17 08:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnFoodFullyEaten(Entity<FoodComponent> food, ref FullyEatenEvent args)
|
2023-11-17 08:51:51 +00:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (food.Comp.Trash.Count == 0)
|
2025-05-09 22:06:19 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-05-12 07:31:54 -07:00
|
|
|
var position = _transform.GetMapCoordinates(food);
|
2025-08-06 09:53:38 -07:00
|
|
|
var trashes = food.Comp.Trash;
|
|
|
|
|
var tryPickup = _hands.IsHolding(args.User, food, out _);
|
2021-11-21 10:35:09 +03:00
|
|
|
|
2024-08-10 22:31:32 +03:00
|
|
|
foreach (var trash in trashes)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-06-26 16:32:36 -04:00
|
|
|
var spawnedTrash = EntityManager.PredictedSpawn(trash, position);
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2024-08-10 22:31:32 +03:00
|
|
|
// If the user is holding the item
|
|
|
|
|
if (tryPickup)
|
|
|
|
|
{
|
|
|
|
|
// Put the trash in the user's hand
|
2025-08-06 09:53:38 -07:00
|
|
|
_hands.TryPickupAnyHand(args.User, spawnedTrash);
|
2024-08-10 22:31:32 +03:00
|
|
|
}
|
2021-11-21 10:35:09 +03:00
|
|
|
}
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnFood(Entity<FoodComponent> food, ref EdibleEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (args.Cancelled)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (args.Cancelled || args.Solution != null)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (food.Comp.UtensilRequired && !_ingestion.HasRequiredUtensils(args.User, food.Comp.Utensil))
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2025-08-06 09:53:38 -07:00
|
|
|
}
|
2023-09-23 03:10:04 +01:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// Check this last
|
|
|
|
|
_solutionContainer.TryGetSolution(food.Owner, food.Comp.Solution, out args.Solution);
|
|
|
|
|
args.Time += TimeSpan.FromSeconds(food.Comp.Delay);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-30 13:45:33 +03:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnGetUtensils(Entity<FoodComponent> entity, ref GetUtensilsEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (entity.Comp.Utensil == UtensilType.None)
|
|
|
|
|
return;
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
if (entity.Comp.UtensilRequired)
|
|
|
|
|
args.AddRequiredTypes(entity.Comp.Utensil);
|
|
|
|
|
else
|
|
|
|
|
args.Types |= entity.Comp.Utensil;
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// TODO: When DrinkComponent and FoodComponent are properly obseleted, make the IsDigestionBools in IngestionSystem private again.
|
|
|
|
|
private void OnIsFoodDigestible(Entity<FoodComponent> ent, ref IsDigestibleEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (ent.Comp.RequireDead && _mobState.IsAlive(ent))
|
|
|
|
|
return;
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
args.AddDigestible(ent.Comp.RequiresSpecialDigestion);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnGetEdibleType(Entity<FoodComponent> ent, ref GetEdibleTypeEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (args.Type != null)
|
|
|
|
|
return;
|
2021-12-03 03:51:05 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
args.SetPrototype(IngestionSystem.Food);
|
2023-09-23 03:10:04 +01:00
|
|
|
}
|
2021-12-03 03:51:05 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void OnBeforeFullySliced(Entity<FoodComponent> food, ref BeforeFullySlicedEvent args)
|
2023-09-23 03:10:04 +01:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
if (food.Comp.Trash.Count == 0)
|
2023-09-23 03:10:04 +01:00
|
|
|
return;
|
2021-12-03 03:51:05 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
var position = _transform.GetMapCoordinates(food);
|
|
|
|
|
var trashes = food.Comp.Trash;
|
|
|
|
|
var tryPickup = _hands.IsHolding(args.User, food, out _);
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
foreach (var trash in trashes)
|
2021-11-29 16:27:15 +13:00
|
|
|
{
|
2025-08-06 09:53:38 -07:00
|
|
|
var spawnedTrash = EntityManager.PredictedSpawn(trash, position);
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
// If the user is holding the item
|
|
|
|
|
if (tryPickup)
|
|
|
|
|
{
|
|
|
|
|
// Put the trash in the user's hand
|
|
|
|
|
_hands.TryPickupAnyHand(args.User, spawnedTrash);
|
|
|
|
|
}
|
2021-11-29 16:27:15 +13:00
|
|
|
}
|
2021-11-21 10:35:09 +03:00
|
|
|
}
|
|
|
|
|
}
|