2023-05-03 19:49:25 -07:00
using System.Linq ;
2021-11-21 10:35:09 +03:00
using Content.Server.Body.Components ;
using Content.Server.Body.Systems ;
using Content.Server.Chemistry.EntitySystems ;
using Content.Server.Nutrition.Components ;
using Content.Server.Popups ;
2023-05-06 10:23:05 +03:00
using Content.Server.Stack ;
2021-11-29 16:27:15 +13:00
using Content.Shared.Administration.Logs ;
2021-11-21 10:35:09 +03:00
using Content.Shared.Body.Components ;
2023-05-03 19:49:25 -07:00
using Content.Shared.Body.Organ ;
2023-02-24 19:01:25 -05:00
using Content.Shared.Chemistry ;
2021-11-21 10:35:09 +03:00
using Content.Shared.Chemistry.Reagent ;
2021-11-29 16:27:15 +13:00
using Content.Shared.Database ;
2023-02-24 19:01:25 -05:00
using Content.Shared.DoAfter ;
2021-11-21 10:35:09 +03:00
using Content.Shared.FixedPoint ;
2023-04-07 11:21:12 -07:00
using Content.Shared.Hands.Components ;
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.Components ;
using Content.Shared.Mobs.Systems ;
2023-04-03 13:13:48 +12:00
using Content.Shared.Nutrition ;
2021-11-21 10:35:09 +03:00
using Content.Shared.Verbs ;
2023-05-06 10:23:05 +03:00
using Content.Shared.Stacks ;
2021-11-21 10:35:09 +03:00
using Robust.Shared.Audio ;
using Robust.Shared.Player ;
2021-11-30 18:25:02 -07:00
using Robust.Shared.Utility ;
2023-08-03 22:21:28 -07:00
using Content.Shared.Tag ;
2023-08-08 21:05:05 -07:00
using Content.Server.Storage.Components ;
2021-11-21 10:35:09 +03:00
namespace Content.Server.Nutrition.EntitySystems
{
/// <summary>
/// Handles feeding attempts both on yourself and on the target.
/// </summary>
2022-02-07 00:37:38 +11:00
public sealed class FoodSystem : EntitySystem
2021-11-21 10:35:09 +03:00
{
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default ! ;
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
[Dependency] private readonly FlavorProfileSystem _flavorProfileSystem = default ! ;
2021-11-21 10:35:09 +03:00
[Dependency] private readonly BodySystem _bodySystem = default ! ;
[Dependency] private readonly StomachSystem _stomachSystem = default ! ;
[Dependency] private readonly PopupSystem _popupSystem = default ! ;
2022-12-19 19:25:35 -08:00
[Dependency] private readonly MobStateSystem _mobStateSystem = default ! ;
2021-11-21 10:35:09 +03:00
[Dependency] private readonly UtensilSystem _utensilSystem = default ! ;
2023-04-03 13:13:48 +12:00
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default ! ;
2022-05-28 23:41:17 -07:00
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default ! ;
2021-12-30 22:56:10 +01:00
[Dependency] private readonly InventorySystem _inventorySystem = default ! ;
2022-02-17 15:40:03 +13:00
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default ! ;
2022-03-17 20:13:31 +13:00
[Dependency] private readonly SharedHandsSystem _handsSystem = default ! ;
2023-02-24 19:01:25 -05:00
[Dependency] private readonly ReactiveSystem _reaction = default ! ;
[Dependency] private readonly SharedAudioSystem _audio = default ! ;
2023-05-06 10:23:05 +03:00
[Dependency] private readonly StackSystem _stack = default ! ;
2023-08-03 22:21:28 -07:00
[Dependency] private readonly TagSystem _tags = default ! ;
2021-11-21 10:35:09 +03:00
2023-05-07 14:58:20 +12:00
public const float MaxFeedDistance = 1.0f ;
2021-11-21 10:35:09 +03:00
public override void Initialize ( )
{
base . Initialize ( ) ;
2023-04-03 13:13:48 +12:00
// TODO add InteractNoHandEvent for entities like mice.
2021-11-21 10:35:09 +03:00
SubscribeLocalEvent < FoodComponent , UseInHandEvent > ( OnUseFoodInHand ) ;
SubscribeLocalEvent < FoodComponent , AfterInteractEvent > ( OnFeedFood ) ;
2022-03-28 13:53:20 -07:00
SubscribeLocalEvent < FoodComponent , GetVerbsEvent < AlternativeVerb > > ( AddEatVerb ) ;
2023-04-03 13:13:48 +12:00
SubscribeLocalEvent < FoodComponent , ConsumeDoAfterEvent > ( OnDoAfter ) ;
2021-12-05 07:56:27 +13:00
SubscribeLocalEvent < InventoryComponent , IngestionAttemptEvent > ( OnInventoryIngestAttempt ) ;
2021-11-21 10:35:09 +03:00
}
/// <summary>
/// Eat item
/// </summary>
private void OnUseFoodInHand ( EntityUid uid , FoodComponent foodComponent , UseInHandEvent ev )
{
if ( ev . Handled )
return ;
2023-05-07 14:58:20 +12:00
var result = TryFeed ( ev . User , ev . User , uid , foodComponent ) ;
ev . Handled = result . Handled ;
2021-11-21 10:35:09 +03:00
}
/// <summary>
/// Feed someone else
/// </summary>
2021-11-29 16:27:15 +13:00
private void OnFeedFood ( EntityUid uid , FoodComponent foodComponent , AfterInteractEvent args )
2021-11-21 10:35:09 +03:00
{
2022-02-05 15:39:01 +13:00
if ( args . Handled | | args . Target = = null | | ! args . CanReach )
2021-11-29 16:27:15 +13:00
return ;
2023-05-07 14:58:20 +12:00
var result = TryFeed ( args . User , args . Target . Value , uid , foodComponent ) ;
args . Handled = result . Handled ;
2021-11-21 10:35:09 +03:00
}
2023-05-07 14:58:20 +12:00
public ( bool Success , bool Handled ) TryFeed ( EntityUid user , EntityUid target , EntityUid food , FoodComponent foodComp )
2021-11-21 10:35:09 +03:00
{
2023-02-24 19:01:25 -05:00
//Suppresses self-eating
2023-05-03 19:49:25 -07:00
if ( food = = user | | TryComp < MobStateComponent > ( food , out var mobState ) & & _mobStateSystem . IsAlive ( food , mobState ) ) // Suppresses eating alive mobs
2023-05-07 14:58:20 +12:00
return ( false , false ) ;
2022-02-07 00:37:38 +11:00
2023-03-05 00:26:03 -05:00
// Target can't be fed or they're already eating
2023-05-03 19:49:25 -07:00
if ( ! TryComp < BodyComponent > ( target , out var body ) )
2023-05-07 14:58:20 +12:00
return ( false , false ) ;
2021-11-30 13:45:33 +03:00
2023-04-03 13:13:48 +12:00
if ( ! _solutionContainerSystem . TryGetSolution ( food , foodComp . SolutionName , out var foodSolution ) | | foodSolution . Name = = null )
2023-05-07 14:58:20 +12:00
return ( false , false ) ;
2021-11-21 10:35:09 +03:00
2023-05-03 19:49:25 -07:00
if ( ! _bodySystem . TryGetBodyOrganComponents < StomachComponent > ( target , out var stomachs , body ) )
2023-05-07 14:58:20 +12:00
return ( false , false ) ;
2023-05-03 19:49:25 -07:00
var forceFeed = user ! = target ;
2023-08-03 22:21:28 -07:00
// Check for special digestibles
2023-05-03 19:49:25 -07:00
if ( ! IsDigestibleBy ( food , foodComp , stomachs ) )
{
_popupSystem . PopupEntity (
forceFeed
? Loc . GetString ( "food-system-cant-digest-other" , ( "entity" , food ) )
: Loc . GetString ( "food-system-cant-digest" , ( "entity" , food ) ) , user , user ) ;
2023-05-07 14:58:20 +12:00
return ( false , true ) ;
2023-05-03 19:49:25 -07:00
}
2023-08-08 21:05:05 -07:00
// Check for used storage on the food item
if ( TryComp < ServerStorageComponent > ( food , out var storageState ) & & storageState . StorageUsed ! = 0 )
{
_popupSystem . PopupEntity ( Loc . GetString ( "food-has-used-storage" , ( "food" , food ) ) , user , user ) ;
return ( false , true ) ;
}
2023-02-24 19:01:25 -05:00
var flavors = _flavorProfileSystem . GetLocalizedFlavorsMessage ( food , user , foodSolution ) ;
2022-09-13 19:36:19 -07:00
2023-02-24 19:01:25 -05:00
if ( foodComp . UsesRemaining < = 0 )
2021-11-21 10:35:09 +03:00
{
2023-02-24 19:01:25 -05:00
_popupSystem . PopupEntity ( Loc . GetString ( "food-system-try-use-food-is-empty" , ( "entity" , food ) ) , user , user ) ;
DeleteAndSpawnTrash ( foodComp , food , user ) ;
2023-05-07 14:58:20 +12:00
return ( false , true ) ;
2021-11-21 10:35:09 +03:00
}
2022-02-07 00:37:38 +11:00
if ( IsMouthBlocked ( target , user ) )
2023-05-07 14:58:20 +12:00
return ( false , true ) ;
2021-11-21 10:35:09 +03:00
2023-02-24 19:01:25 -05:00
if ( ! _interactionSystem . InRangeUnobstructed ( user , food , popup : true ) )
2023-05-07 14:58:20 +12:00
return ( false , true ) ;
if ( ! _interactionSystem . InRangeUnobstructed ( user , target , MaxFeedDistance , popup : true ) )
return ( false , true ) ;
// TODO make do-afters account for fixtures in the range check.
if ( ! Transform ( user ) . MapPosition . InRange ( Transform ( target ) . MapPosition , MaxFeedDistance ) )
{
var message = Loc . GetString ( "interaction-system-user-interaction-cannot-reach" ) ;
_popupSystem . PopupEntity ( message , user , user ) ;
return ( false , true ) ;
}
2022-02-07 00:37:38 +11:00
2023-04-03 13:13:48 +12:00
if ( ! TryGetRequiredUtensils ( user , foodComp , out _ ) )
2023-05-07 14:58:20 +12:00
return ( false , true ) ;
2022-02-07 00:37:38 +11:00
2023-04-03 13:13:48 +12:00
if ( forceFeed )
2022-02-07 00:37:38 +11:00
{
2022-07-31 15:43:38 +12:00
var userName = Identity . Entity ( user , EntityManager ) ;
2022-02-07 00:37:38 +11:00
_popupSystem . PopupEntity ( Loc . GetString ( "food-system-force-feed" , ( "user" , userName ) ) ,
2022-12-19 10:41:47 +13:00
user , target ) ;
2022-02-07 00:37:38 +11:00
// logging
2023-02-24 19:01:25 -05:00
_adminLogger . Add ( LogType . ForceFeed , LogImpact . Medium , $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(food):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}" ) ;
2021-12-03 03:51:05 +13:00
}
2022-12-02 19:19:44 -06:00
else
{
// log voluntary eating
2023-02-24 19:01:25 -05:00
_adminLogger . Add ( LogType . Ingestion , LogImpact . Low , $"{ToPrettyString(target):target} is eating {ToPrettyString(food):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}" ) ;
2022-12-02 19:19:44 -06:00
}
2021-12-03 03:51:05 +13:00
2023-04-15 18:14:26 -04:00
var doAfterArgs = new DoAfterArgs (
2023-04-03 13:13:48 +12:00
user ,
forceFeed ? foodComp . ForceFeedDelay : foodComp . Delay ,
new ConsumeDoAfterEvent ( foodSolution . Name , flavors ) ,
eventTarget : food ,
target : target ,
used : food )
2022-02-07 00:37:38 +11:00
{
2023-04-03 13:13:48 +12:00
BreakOnUserMove = forceFeed ,
2022-02-07 00:37:38 +11:00
BreakOnDamage = true ,
2023-04-03 13:13:48 +12:00
BreakOnTargetMove = forceFeed ,
2022-02-07 00:37:38 +11:00
MovementThreshold = 0.01f ,
2023-05-07 14:58:20 +12:00
DistanceThreshold = MaxFeedDistance ,
2023-04-03 13:13:48 +12:00
// Mice and the like can eat without hands.
// TODO maybe set this based on some CanEatWithoutHands event or component?
NeedHand = forceFeed ,
2023-02-24 19:01:25 -05:00
} ;
2023-04-15 18:14:26 -04:00
_doAfterSystem . TryStartDoAfter ( doAfterArgs ) ;
2023-05-07 14:58:20 +12:00
return ( true , true ) ;
2022-02-07 00:37:38 +11:00
}
2021-11-21 10:35:09 +03:00
2023-04-03 13:13:48 +12:00
private void OnDoAfter ( EntityUid uid , FoodComponent component , ConsumeDoAfterEvent args )
2022-02-07 00:37:38 +11:00
{
2023-04-17 19:56:42 +12:00
if ( args . Cancelled | | args . Handled | | component . Deleted | | args . Target = = null )
2022-02-07 00:37:38 +11:00
return ;
2023-04-17 19:56:42 +12:00
if ( ! TryComp < BodyComponent > ( args . Target . Value , out var body ) )
2022-02-07 00:37:38 +11:00
return ;
2021-11-21 10:35:09 +03:00
2023-04-17 19:56:42 +12:00
if ( ! _bodySystem . TryGetBodyOrganComponents < StomachComponent > ( args . Target . Value , out var stomachs , body ) )
2023-02-24 19:01:25 -05: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
2023-04-03 13:13:48 +12:00
if ( ! _solutionContainerSystem . TryGetSolution ( args . Used , args . Solution , out var solution ) )
return ;
2023-03-05 00:26:03 -05:00
2023-04-03 13:13:48 +12:00
if ( ! TryGetRequiredUtensils ( args . User , component , out var utensils ) )
return ;
2023-04-17 19:56:42 +12:00
// TODO this should really be checked every tick.
if ( IsMouthBlocked ( args . Target . Value ) )
return ;
// TODO this should really be checked every tick.
if ( ! _interactionSystem . InRangeUnobstructed ( args . User , args . Target . Value ) )
return ;
2023-05-02 04:57:11 +10:00
2023-04-15 18:14:26 -04:00
var forceFeed = args . User ! = args . Target ;
2023-04-03 13:13:48 +12:00
2023-04-15 18:14:26 -04:00
args . Handled = true ;
2023-04-03 13:13:48 +12:00
var transferAmount = component . TransferAmount ! = null ? FixedPoint2 . Min ( ( FixedPoint2 ) component . TransferAmount , solution . Volume ) : solution . Volume ;
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
2023-04-03 13:13:48 +12:00
var split = _solutionContainerSystem . SplitSolution ( uid , solution , transferAmount ) ;
2023-05-03 19:49:25 -07:00
2023-02-24 19:01:25 -05:00
//TODO: Get the stomach UID somehow without nabbing owner
2023-05-03 19:49:25 -07:00
// Get the stomach with the highest available solution volume
var highestAvailable = FixedPoint2 . Zero ;
StomachComponent ? stomachToUse = null ;
foreach ( var ( stomach , _ ) in stomachs )
{
var owner = stomach . Owner ;
if ( ! _stomachSystem . CanTransferSolution ( owner , split ) )
continue ;
if ( ! _solutionContainerSystem . TryGetSolution ( owner , StomachSystem . DefaultSolutionName ,
out var stomachSol ) )
continue ;
if ( stomachSol . AvailableVolume < = highestAvailable )
continue ;
stomachToUse = stomach ;
highestAvailable = stomachSol . AvailableVolume ;
}
2021-11-21 10:35:09 +03:00
2022-02-07 00:37:38 +11:00
// No stomach so just popup a message that they can't eat.
2023-05-03 19:49:25 -07:00
if ( stomachToUse = = null )
2021-11-21 10:35:09 +03:00
{
2023-04-03 13:13:48 +12:00
_solutionContainerSystem . TryAddSolution ( uid , solution , split ) ;
2023-04-17 19:56:42 +12:00
_popupSystem . PopupEntity ( forceFeed ? Loc . GetString ( "food-system-you-cannot-eat-any-more-other" ) : Loc . GetString ( "food-system-you-cannot-eat-any-more" ) , args . Target . Value , args . User ) ;
2022-02-07 00:37:38 +11:00
return ;
2021-11-21 10:35:09 +03:00
}
2023-04-17 19:56:42 +12:00
_reaction . DoEntityReaction ( args . Target . Value , solution , ReactionMethod . Ingestion ) ;
2023-05-03 19:49:25 -07:00
_stomachSystem . TryTransferSolution ( stomachToUse . Owner , split , stomachToUse ) ;
2021-11-21 10:35:09 +03:00
2023-04-03 13:13:48 +12:00
var flavors = args . FlavorMessage ;
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
2023-04-03 13:13:48 +12:00
if ( forceFeed )
2022-02-07 00:37:38 +11:00
{
2023-04-17 19:56:42 +12:00
var targetName = Identity . Entity ( args . Target . Value , EntityManager ) ;
var userName = Identity . Entity ( args . User , EntityManager ) ;
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
_popupSystem . PopupEntity ( Loc . GetString ( "food-system-force-feed-success" , ( "user" , userName ) , ( "flavors" , flavors ) ) ,
2022-12-19 10:41:47 +13:00
uid , uid ) ;
2022-02-07 00:37:38 +11:00
2023-04-17 19:56:42 +12:00
_popupSystem . PopupEntity ( Loc . GetString ( "food-system-force-feed-success-user" , ( "target" , targetName ) ) , args . User , args . User ) ;
2022-12-02 19:19:44 -06:00
// log successful force feed
2023-04-17 19:56:42 +12:00
_adminLogger . Add ( LogType . ForceFeed , LogImpact . Medium , $"{ToPrettyString(uid):user} forced {ToPrettyString(args.User):target} to eat {ToPrettyString(uid):food}" ) ;
2022-02-07 00:37:38 +11:00
}
else
2021-11-21 10:35:09 +03:00
{
2023-04-17 19:56:42 +12:00
_popupSystem . PopupEntity ( Loc . GetString ( component . EatMessage , ( "food" , uid ) , ( "flavors" , flavors ) ) , args . User , args . User ) ;
2022-12-02 19:19:44 -06:00
// log successful voluntary eating
2023-04-17 19:56:42 +12:00
_adminLogger . Add ( LogType . Ingestion , LogImpact . Low , $"{ToPrettyString(args.User):target} ate {ToPrettyString(uid):food}" ) ;
2021-11-21 10:35:09 +03:00
}
2023-04-17 19:56:42 +12:00
_audio . Play ( component . UseSound , Filter . Pvs ( args . Target . Value ) , args . Target . Value , true , AudioParams . Default . WithVolume ( - 1f ) ) ;
2022-02-07 00:37:38 +11:00
// Try to break all used utensils
2023-04-03 13:13:48 +12:00
foreach ( var utensil in utensils )
2021-11-21 10:35:09 +03:00
{
2023-04-17 19:56:42 +12:00
_utensilSystem . TryBreak ( utensil , args . User ) ;
2021-11-21 10:35:09 +03:00
}
2023-05-06 10:23:05 +03:00
args . Repeat = ! forceFeed ;
2023-05-07 14:58:20 +12:00
2023-05-06 10:23:05 +03:00
if ( TryComp < StackComponent > ( uid , out var stack ) )
{
//Not deleting whole stack piece will make troubles with grinding object
2023-05-07 14:58:20 +12:00
if ( stack . Count > 1 )
2023-05-06 10:23:05 +03:00
{
_stack . SetCount ( uid , stack . Count - 1 ) ;
_solutionContainerSystem . TryAddSolution ( uid , solution , split ) ;
return ;
}
}
else if ( component . UsesRemaining > 0 )
2023-04-15 18:14:26 -04:00
{
2022-02-07 00:37:38 +11:00
return ;
2023-04-15 18:14:26 -04:00
}
2023-02-24 19:01:25 -05:00
2023-06-03 19:08:52 +00:00
var ev = new BeforeFullyEatenEvent
{
User = args . User
} ;
RaiseLocalEvent ( uid , ev ) ;
if ( ev . Cancelled )
return ;
2021-11-21 10:35:09 +03:00
2023-06-03 19:08:52 +00:00
if ( string . IsNullOrEmpty ( component . TrashPrototype ) )
QueueDel ( uid ) ;
2022-02-07 00:37:38 +11:00
else
2023-04-17 19:56:42 +12:00
DeleteAndSpawnTrash ( component , uid , args . User ) ;
2021-11-21 10:35:09 +03:00
}
2023-06-03 04:31:47 +01:00
public void DeleteAndSpawnTrash ( FoodComponent component , EntityUid food , EntityUid ? user = null )
2021-11-21 10:35:09 +03:00
{
//We're empty. Become trash.
2023-02-24 19:01:25 -05:00
var position = Transform ( food ) . MapPosition ;
2021-12-05 18:09:01 +01:00
var finisher = EntityManager . SpawnEntity ( component . TrashPrototype , position ) ;
2021-11-21 10:35:09 +03:00
// If the user is holding the item
2023-02-24 19:01:25 -05:00
if ( user ! = null & & _handsSystem . IsHolding ( user . Value , food , out var hand ) )
2021-11-21 10:35:09 +03:00
{
2023-02-24 19:01:25 -05:00
EntityManager . DeleteEntity ( food ) ;
2021-11-21 10:35:09 +03:00
// Put the trash in the user's hand
2022-03-17 20:13:31 +13:00
_handsSystem . TryPickup ( user . Value , finisher , hand ) ;
2021-11-29 16:27:15 +13:00
return ;
2021-11-21 10:35:09 +03:00
}
2021-11-29 16:27:15 +13:00
2023-02-24 19:01:25 -05:00
EntityManager . QueueDeleteEntity ( food ) ;
2021-11-21 10:35:09 +03:00
}
2022-03-28 13:53:20 -07:00
private void AddEatVerb ( EntityUid uid , FoodComponent component , GetVerbsEvent < AlternativeVerb > ev )
2021-11-21 10:35:09 +03:00
{
2021-12-05 18:09:01 +01:00
if ( uid = = ev . User | |
2021-11-30 13:45:33 +03:00
! ev . CanInteract | |
2021-11-25 05:16:56 +03:00
! ev . CanAccess | |
2022-10-23 00:46:28 +02:00
! EntityManager . TryGetComponent ( ev . User , out BodyComponent ? body ) | |
! _bodySystem . TryGetBodyOrganComponents < StomachComponent > ( ev . User , out var stomachs , body ) )
2021-11-30 13:45:33 +03:00
return ;
2022-12-19 19:25:35 -08:00
if ( EntityManager . TryGetComponent < MobStateComponent > ( uid , out var mobState ) & & _mobStateSystem . IsAlive ( uid , mobState ) )
2021-11-21 10:35:09 +03:00
return ;
2022-03-28 13:53:20 -07:00
AlternativeVerb verb = new ( )
2021-11-21 10:35:09 +03:00
{
2021-12-05 18:09:01 +01:00
Act = ( ) = >
{
2023-02-24 19:01:25 -05:00
TryFeed ( ev . User , ev . User , uid , component ) ;
2021-12-05 18:09:01 +01:00
} ,
2023-04-20 20:16:01 +10:00
Icon = new SpriteSpecifier . Texture ( new ( "/Textures/Interface/VerbIcons/cutlery.svg.192dpi.png" ) ) ,
2021-12-05 18:09:01 +01:00
Text = Loc . GetString ( "food-system-verb-eat" ) ,
Priority = - 1
2021-11-21 10:35:09 +03:00
} ;
2021-11-30 18:25:02 -07:00
2021-11-21 10:35:09 +03:00
ev . Verbs . Add ( verb ) ;
}
2021-11-29 16:27:15 +13:00
/// <summary>
2023-05-03 19:49:25 -07:00
/// Returns true if the food item can be digested by the user.
2021-11-29 16:27:15 +13:00
/// </summary>
2023-05-03 19:49:25 -07:00
public bool IsDigestibleBy ( EntityUid uid , EntityUid food , FoodComponent ? foodComp = null )
2021-11-29 16:27:15 +13:00
{
2023-05-03 19:49:25 -07:00
if ( ! Resolve ( food , ref foodComp , false ) )
return false ;
2021-11-29 16:27:15 +13:00
2023-05-03 19:49:25 -07:00
if ( ! _bodySystem . TryGetBodyOrganComponents < StomachComponent > ( uid , out var stomachs ) )
return false ;
2021-11-29 16:27:15 +13:00
2023-05-03 19:49:25 -07:00
return IsDigestibleBy ( food , foodComp , stomachs ) ;
}
2021-11-29 16:27:15 +13:00
2023-05-03 19:49:25 -07:00
/// <summary>
2023-08-03 22:21:28 -07:00
/// Returns true if <paramref name="stomachs"/> has a <see cref="StomachComponent.SpecialDigestible"/> that whitelists
/// this <paramref name="food"/> (or if they even have enough stomachs in the first place).
2023-05-03 19:49:25 -07:00
/// </summary>
private bool IsDigestibleBy ( EntityUid food , FoodComponent component , List < ( StomachComponent , OrganComponent ) > stomachs )
{
var digestible = true ;
2021-11-30 18:25:02 -07:00
2023-08-03 22:21:28 -07:00
// Does the mob have enough stomachs?
2023-05-03 19:49:25 -07:00
if ( stomachs . Count < component . RequiredStomachs )
return false ;
2021-11-29 16:27:15 +13:00
2023-08-03 22:21:28 -07:00
// Run through the mobs' stomachs
2023-05-03 19:49:25 -07:00
foreach ( var ( comp , _ ) in stomachs )
{
2023-08-03 22:21:28 -07:00
// Find a stomach with a SpecialDigestible
2023-05-03 19:49:25 -07:00
if ( comp . SpecialDigestible = = null )
continue ;
2023-08-03 22:21:28 -07:00
// Check if the food is in the whitelist
if ( comp . SpecialDigestible . IsValid ( food , EntityManager ) )
return true ;
// They can only eat whitelist food and the food isn't in the whitelist. It's not edible.
return false ;
}
2021-11-29 16:27:15 +13:00
2023-08-03 22:21:28 -07:00
if ( component . RequiresSpecialDigestion )
2023-05-03 19:49:25 -07:00
return false ;
2021-11-29 16:27:15 +13:00
2023-05-03 19:49:25 -07:00
return digestible ;
2021-11-29 16:27:15 +13:00
}
2021-12-05 18:09:01 +01:00
private bool TryGetRequiredUtensils ( EntityUid user , FoodComponent component ,
2023-04-03 13:13:48 +12:00
out List < EntityUid > utensils , HandsComponent ? hands = null )
2021-11-29 16:27:15 +13:00
{
2023-04-03 13:13:48 +12:00
utensils = new List < EntityUid > ( ) ;
2021-11-29 16:27:15 +13:00
if ( component . Utensil ! = UtensilType . None )
return true ;
2021-12-05 18:09:01 +01:00
if ( ! Resolve ( user , ref hands , false ) )
2021-11-29 16:27:15 +13:00
return false ;
var usedTypes = UtensilType . None ;
2022-03-17 20:13:31 +13:00
foreach ( var item in _handsSystem . EnumerateHeld ( user , hands ) )
2021-11-29 16:27:15 +13:00
{
// Is utensil?
2022-03-17 20:13:31 +13:00
if ( ! EntityManager . TryGetComponent ( item , out UtensilComponent ? utensil ) )
2021-11-29 16:27:15 +13:00
continue ;
if ( ( utensil . Types & component . Utensil ) ! = 0 & & // Acceptable type?
( usedTypes & utensil . Types ) ! = utensil . Types ) // Type is not used already? (removes usage of identical utensils)
{
// Add to used list
usedTypes | = utensil . Types ;
2023-04-03 13:13:48 +12:00
utensils . Add ( item ) ;
2021-11-29 16:27:15 +13:00
}
}
// If "required" field is set, try to block eating without proper utensils used
if ( component . UtensilRequired & & ( usedTypes & component . Utensil ) ! = component . Utensil )
{
2022-12-19 10:41:47 +13:00
_popupSystem . PopupEntity ( Loc . GetString ( "food-you-need-to-hold-utensil" , ( "utensil" , component . Utensil ^ usedTypes ) ) , user , user ) ;
2021-11-29 16:27:15 +13:00
return false ;
}
return true ;
}
2021-12-03 03:51:05 +13:00
/// <summary>
2021-12-05 07:56:27 +13:00
/// Block ingestion attempts based on the equipped mask or head-wear
2021-12-03 03:51:05 +13:00
/// </summary>
2021-12-05 07:56:27 +13:00
private void OnInventoryIngestAttempt ( EntityUid uid , InventoryComponent component , IngestionAttemptEvent args )
2021-12-03 03:51:05 +13:00
{
2021-12-05 07:56:27 +13:00
if ( args . Cancelled )
return ;
2021-12-03 03:51:05 +13:00
2022-06-04 19:17:48 +12:00
IngestionBlockerComponent ? blocker ;
2021-12-03 03:51:05 +13:00
2021-12-30 22:56:10 +01:00
if ( _inventorySystem . TryGetSlotEntity ( uid , "mask" , out var maskUid ) & &
EntityManager . TryGetComponent ( maskUid , out blocker ) & &
2021-12-05 07:56:27 +13:00
blocker . Enabled )
2021-12-03 03:51:05 +13:00
{
2021-12-30 22:56:10 +01:00
args . Blocker = maskUid ;
2021-12-05 07:56:27 +13:00
args . Cancel ( ) ;
return ;
2021-12-03 03:51:05 +13:00
}
2021-12-30 22:56:10 +01:00
if ( _inventorySystem . TryGetSlotEntity ( uid , "head" , out var headUid ) & &
EntityManager . TryGetComponent ( headUid , out blocker ) & &
2021-12-05 07:56:27 +13:00
blocker . Enabled )
2021-12-03 03:51:05 +13:00
{
2021-12-30 22:56:10 +01:00
args . Blocker = headUid ;
2021-12-05 07:56:27 +13:00
args . Cancel ( ) ;
2021-12-03 03:51:05 +13:00
}
}
2021-11-29 16:27:15 +13:00
2021-12-05 07:56:27 +13:00
/// <summary>
/// Check whether the target's mouth is blocked by equipment (masks or head-wear).
/// </summary>
/// <param name="uid">The target whose equipment is checked</param>
/// <param name="popupUid">Optional entity that will receive an informative pop-up identifying the blocking
/// piece of equipment.</param>
/// <returns></returns>
public bool IsMouthBlocked ( EntityUid uid , EntityUid ? popupUid = null )
2021-11-29 16:27:15 +13:00
{
2021-12-05 07:56:27 +13:00
var attempt = new IngestionAttemptEvent ( ) ;
RaiseLocalEvent ( uid , attempt , false ) ;
if ( attempt . Cancelled & & attempt . Blocker ! = null & & popupUid ! = null )
{
var name = EntityManager . GetComponent < MetaDataComponent > ( attempt . Blocker . Value ) . EntityName ;
_popupSystem . PopupEntity ( Loc . GetString ( "food-system-remove-mask" , ( "entity" , name ) ) ,
2022-12-19 10:41:47 +13:00
uid , popupUid . Value ) ;
2021-12-05 07:56:27 +13:00
}
2021-11-29 16:27:15 +13:00
2021-12-05 07:56:27 +13:00
return attempt . Cancelled ;
2021-11-29 16:27:15 +13:00
}
2021-11-21 10:35:09 +03:00
}
}