2021-11-11 16:10:57 -07:00
using Content.Server.Body.Components ;
using Content.Server.Body.Systems ;
2021-10-29 13:40:15 +01:00
using Content.Server.Chemistry.Components.SolutionManager ;
using Content.Server.Chemistry.EntitySystems ;
2023-07-25 21:32:10 +00:00
using Content.Server.Chemistry.ReagentEffects ;
2021-12-05 04:18:30 +01:00
using Content.Server.Fluids.EntitySystems ;
2023-03-31 07:49:25 +03:00
using Content.Server.Forensics ;
2021-09-12 16:22:58 +10:00
using Content.Server.Nutrition.Components ;
2021-11-09 11:28:27 +01:00
using Content.Server.Popups ;
2021-11-29 16:27:15 +13:00
using Content.Shared.Administration.Logs ;
2021-11-02 11:40:55 +11:00
using Content.Shared.Body.Components ;
2023-02-24 19:01:25 -05:00
using Content.Shared.Chemistry ;
2023-04-10 15:37:03 +10:00
using Content.Shared.Chemistry.Components ;
2021-11-02 11:40:55 +11: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-02 11:40:55 +11:00
using Content.Shared.Examine ;
2021-11-03 16:48:03 -07:00
using Content.Shared.FixedPoint ;
2022-07-10 18:36:53 -07:00
using Content.Shared.IdentityManagement ;
2021-11-02 11:40:55 +11:00
using Content.Shared.Interaction ;
2022-03-13 01:33:23 +13:00
using Content.Shared.Interaction.Events ;
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-10-03 06:56:29 +02:00
using Content.Shared.Nutrition.Components ;
2021-09-12 16:22:58 +10:00
using Content.Shared.Throwing ;
2022-04-23 19:38:21 -04:00
using Content.Shared.Verbs ;
2021-09-12 16:22:58 +10:00
using Robust.Shared.Audio ;
using Robust.Shared.Player ;
2023-07-25 21:32:10 +00:00
using Robust.Shared.Prototypes ;
2021-09-12 16:22:58 +10:00
using Robust.Shared.Random ;
2021-11-30 18:25:02 -07:00
using Robust.Shared.Utility ;
2021-09-06 15:49:44 +02:00
2023-07-25 21:32:10 +00:00
namespace Content.Server.Nutrition.EntitySystems ;
public sealed class DrinkSystem : EntitySystem
2021-09-06 15:49:44 +02:00
{
2023-07-25 21:32:10 +00:00
[Dependency] private readonly BodySystem _body = default ! ;
[Dependency] private readonly FoodSystem _food = default ! ;
[Dependency] private readonly FlavorProfileSystem _flavorProfile = default ! ;
[Dependency] private readonly IPrototypeManager _proto = default ! ;
[Dependency] private readonly IRobustRandom _random = default ! ;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default ! ;
[Dependency] private readonly MobStateSystem _mobStateSystem = default ! ;
[Dependency] private readonly PopupSystem _popup = default ! ;
[Dependency] private readonly PuddleSystem _puddleSystem = default ! ;
[Dependency] private readonly ReactiveSystem _reaction = default ! ;
[Dependency] private readonly SharedAppearanceSystem _appearance = default ! ;
[Dependency] private readonly SharedAudioSystem _audio = default ! ;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default ! ;
[Dependency] private readonly SharedInteractionSystem _interaction = default ! ;
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default ! ;
[Dependency] private readonly StomachSystem _stomach = default ! ;
public override void Initialize ( )
2021-09-06 15:49:44 +02:00
{
2023-07-25 21:32:10 +00:00
base . Initialize ( ) ;
// TODO add InteractNoHandEvent for entities like mice.
SubscribeLocalEvent < DrinkComponent , SolutionChangedEvent > ( OnSolutionChange ) ;
SubscribeLocalEvent < DrinkComponent , ComponentInit > ( OnDrinkInit ) ;
SubscribeLocalEvent < DrinkComponent , LandEvent > ( HandleLand ) ;
SubscribeLocalEvent < DrinkComponent , UseInHandEvent > ( OnUse ) ;
SubscribeLocalEvent < DrinkComponent , AfterInteractEvent > ( AfterInteract ) ;
SubscribeLocalEvent < DrinkComponent , GetVerbsEvent < AlternativeVerb > > ( AddDrinkVerb ) ;
SubscribeLocalEvent < DrinkComponent , ExaminedEvent > ( OnExamined ) ;
SubscribeLocalEvent < DrinkComponent , SolutionTransferAttemptEvent > ( OnTransferAttempt ) ;
SubscribeLocalEvent < DrinkComponent , ConsumeDoAfterEvent > ( OnDoAfter ) ;
}
2021-12-07 19:19:26 +13:00
2023-07-25 21:32:10 +00:00
private FixedPoint2 DrinkVolume ( EntityUid uid , DrinkComponent ? component = null )
{
if ( ! Resolve ( uid , ref component ) )
return FixedPoint2 . Zero ;
2023-05-20 20:05:22 -07:00
2023-07-25 21:32:10 +00:00
if ( ! _solutionContainer . TryGetSolution ( uid , component . SolutionName , out var sol ) )
return FixedPoint2 . Zero ;
2023-05-20 20:05:22 -07:00
2023-07-25 21:32:10 +00:00
return sol . Volume ;
}
2023-05-20 20:05:22 -07:00
2023-07-25 21:32:10 +00:00
public bool IsEmpty ( EntityUid uid , DrinkComponent ? component = null )
{
if ( ! Resolve ( uid , ref component ) )
return true ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
return DrinkVolume ( uid , component ) < = 0 ;
}
/// <summary>
/// Get the total hydration factor contained in a drink's solution.
/// </summary>
public float TotalHydration ( EntityUid uid , DrinkComponent ? comp = null )
{
if ( ! Resolve ( uid , ref comp ) )
return 0f ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( ! _solutionContainer . TryGetSolution ( uid , comp . SolutionName , out var solution ) )
return 0f ;
var total = 0f ;
foreach ( var quantity in solution . Contents )
2021-11-02 11:40:55 +11:00
{
2023-07-25 21:32:10 +00:00
var reagent = _proto . Index < ReagentPrototype > ( quantity . ReagentId ) ;
if ( reagent . Metabolisms = = null )
continue ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
foreach ( ( var _ , var entry ) in reagent . Metabolisms )
2022-06-21 22:02:24 -04:00
{
2023-07-25 21:32:10 +00:00
foreach ( var effect in entry . Effects )
2022-06-21 22:02:24 -04:00
{
2023-07-25 21:32:10 +00:00
// ignores any effect conditions, just cares about how much it can hydrate
if ( effect is SatiateThirst thirst )
2022-06-21 22:02:24 -04:00
{
2023-07-25 21:32:10 +00:00
total + = thirst . HydrationFactor * quantity . Quantity . Float ( ) ;
}
2022-06-21 22:02:24 -04:00
}
}
2021-11-02 11:40:55 +11:00
}
2023-07-25 21:32:10 +00:00
return total ;
}
private void OnExamined ( EntityUid uid , DrinkComponent component , ExaminedEvent args )
{
if ( ! component . Opened | | ! args . IsInDetailsRange | | ! component . Examinable )
return ;
var color = IsEmpty ( uid , component ) ? "gray" : "yellow" ;
var openedText =
Loc . GetString ( IsEmpty ( uid , component ) ? "drink-component-on-examine-is-empty" : "drink-component-on-examine-is-opened" ) ;
args . Message . AddMarkup ( $"\n{Loc.GetString(" drink - component - on - examine - details - text ", (" colorName ", color), (" text ", openedText))}" ) ;
if ( ! IsEmpty ( uid , component ) )
2021-11-02 11:40:55 +11:00
{
2023-07-25 21:32:10 +00:00
if ( TryComp < ExaminableSolutionComponent > ( uid , out var comp ) )
{
//provide exact measurement for beakers
args . Message . AddMarkup ( $" - {Loc.GetString(" drink - component - on - examine - exact - volume ", (" amount ", DrinkVolume(uid, component)))}" ) ;
}
else
{
//general approximation
var remainingString = ( int ) _solutionContainer . PercentFull ( uid ) switch
{
100 = > "drink-component-on-examine-is-full" ,
> 66 = > "drink-component-on-examine-is-mostly-full" ,
> 33 = > HalfEmptyOrHalfFull ( args ) ,
_ = > "drink-component-on-examine-is-mostly-empty" ,
} ;
args . Message . AddMarkup ( $" - {Loc.GetString(remainingString)}" ) ;
}
}
}
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
private void SetOpen ( EntityUid uid , bool opened = false , DrinkComponent ? component = null )
{
if ( ! Resolve ( uid , ref component ) )
return ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( opened = = component . Opened )
return ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
component . Opened = opened ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( ! _solutionContainer . TryGetSolution ( uid , component . SolutionName , out _ ) )
return ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( EntityManager . TryGetComponent < AppearanceComponent > ( uid , out var appearance ) )
2021-11-02 11:40:55 +11:00
{
2023-07-25 21:32:10 +00:00
_appearance . SetData ( uid , DrinkCanStateVisual . Opened , opened , appearance ) ;
2021-11-02 11:40:55 +11:00
}
2023-07-25 21:32:10 +00:00
}
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
private void AfterInteract ( EntityUid uid , DrinkComponent component , AfterInteractEvent args )
{
if ( args . Handled | | args . Target = = null | | ! args . CanReach )
return ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
args . Handled = TryDrink ( args . User , args . Target . Value , component , uid ) ;
}
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
private void OnUse ( EntityUid uid , DrinkComponent component , UseInHandEvent args )
{
if ( args . Handled )
return ;
if ( ! component . Opened )
{
//Do the opening stuff like playing the sounds.
_audio . PlayPvs ( _audio . GetSound ( component . OpenSounds ) , args . User ) ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
SetOpen ( uid , true , component ) ;
return ;
2021-09-12 16:22:58 +10:00
}
2023-07-25 21:32:10 +00:00
args . Handled = TryDrink ( args . User , args . User , component , uid ) ;
}
private void HandleLand ( EntityUid uid , DrinkComponent component , ref LandEvent args )
{
if ( component . Pressurized & &
! component . Opened & &
_random . Prob ( 0.25f ) & &
_solutionContainer . TryGetSolution ( uid , component . SolutionName , out var interactions ) )
2021-09-12 16:22:58 +10:00
{
2023-07-25 21:32:10 +00:00
component . Opened = true ;
UpdateAppearance ( uid , component ) ;
2021-09-12 16:22:58 +10:00
2023-07-25 21:32:10 +00:00
var solution = _solutionContainer . SplitSolution ( uid , interactions , interactions . Volume ) ;
_puddleSystem . TrySpillAt ( uid , solution , out _ ) ;
2021-09-12 16:22:58 +10:00
2023-07-25 21:32:10 +00:00
_audio . PlayPvs ( _audio . GetSound ( component . BurstSound ) , uid , AudioParams . Default . WithVolume ( - 4 ) ) ;
2021-09-06 15:49:44 +02:00
}
2023-07-25 21:32:10 +00:00
}
2021-09-06 15:49:44 +02:00
2023-07-25 21:32:10 +00:00
private void OnDrinkInit ( EntityUid uid , DrinkComponent component , ComponentInit args )
{
SetOpen ( uid , component . DefaultToOpened , component ) ;
if ( EntityManager . TryGetComponent ( uid , out DrainableSolutionComponent ? existingDrainable ) )
2021-09-06 15:49:44 +02:00
{
2023-07-25 21:32:10 +00:00
// Beakers have Drink component but they should use the existing Drainable
component . SolutionName = existingDrainable . Solution ;
}
else
{
_solutionContainer . EnsureSolution ( uid , component . SolutionName ) ;
}
2021-09-06 15:49:44 +02:00
2023-07-25 21:32:10 +00:00
UpdateAppearance ( uid , component ) ;
2021-09-06 15:49:44 +02:00
2023-07-25 21:32:10 +00:00
if ( TryComp ( uid , out RefillableSolutionComponent ? refillComp ) )
refillComp . Solution = component . SolutionName ;
2022-04-15 23:17:48 +02:00
2023-07-25 21:32:10 +00:00
if ( TryComp ( uid , out DrainableSolutionComponent ? drainComp ) )
drainComp . Solution = component . SolutionName ;
}
2022-08-17 12:47:58 +12:00
2023-07-25 21:32:10 +00:00
private void OnSolutionChange ( EntityUid uid , DrinkComponent component , SolutionChangedEvent args )
{
UpdateAppearance ( uid , component ) ;
}
2021-09-06 15:49:44 +02:00
2023-07-25 21:32:10 +00:00
public void UpdateAppearance ( EntityUid uid , DrinkComponent component )
{
if ( ! TryComp < AppearanceComponent > ( uid , out var appearance ) | |
! HasComp < SolutionContainerManagerComponent > ( uid ) )
2021-09-06 15:49:44 +02:00
{
2023-07-25 21:32:10 +00:00
return ;
2021-10-03 06:56:29 +02:00
}
2023-07-25 21:32:10 +00:00
var drainAvailable = DrinkVolume ( uid , component ) ;
_appearance . SetData ( uid , FoodVisuals . Visual , drainAvailable . Float ( ) , appearance ) ;
_appearance . SetData ( uid , DrinkCanStateVisual . Opened , component . Opened , appearance ) ;
}
2021-10-03 06:56:29 +02:00
2023-07-25 21:32:10 +00:00
private void OnTransferAttempt ( EntityUid uid , DrinkComponent component , SolutionTransferAttemptEvent args )
{
if ( ! component . Opened )
{
args . Cancel ( Loc . GetString ( "drink-component-try-use-drink-not-open" , ( "owner" , uid ) ) ) ;
2021-09-06 15:49:44 +02:00
}
2023-07-25 21:32:10 +00:00
}
private bool TryDrink ( EntityUid user , EntityUid target , DrinkComponent drink , EntityUid item )
{
if ( ! EntityManager . HasComponent < BodyComponent > ( target ) )
return false ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( ! drink . Opened )
2022-04-15 23:17:48 +02:00
{
2023-07-25 21:32:10 +00:00
_popup . PopupEntity ( Loc . GetString ( "drink-component-try-use-drink-not-open" ,
( "owner" , EntityManager . GetComponent < MetaDataComponent > ( item ) . EntityName ) ) , item , user ) ;
return true ;
2022-04-15 23:17:48 +02:00
}
2023-07-25 21:32:10 +00:00
if ( ! _solutionContainer . TryGetSolution ( item , drink . SolutionName , out var drinkSolution ) | |
drinkSolution . Volume < = 0 )
2021-11-02 11:40:55 +11:00
{
2023-07-25 21:32:10 +00:00
_popup . PopupEntity ( Loc . GetString ( "drink-component-try-use-drink-is-empty" ,
( "entity" , EntityManager . GetComponent < MetaDataComponent > ( item ) . EntityName ) ) , item , user ) ;
return true ;
}
2021-12-03 03:51:05 +13:00
2023-07-25 21:32:10 +00:00
if ( drinkSolution . Name = = null )
return false ;
2021-11-02 11:40:55 +11:00
2023-07-25 21:32:10 +00:00
if ( _food . IsMouthBlocked ( target , user ) )
return true ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
if ( ! _interaction . InRangeUnobstructed ( user , item , popup : true ) )
return true ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
var forceDrink = user ! = target ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
if ( forceDrink )
{
var userName = Identity . Entity ( user , EntityManager ) ;
2022-03-17 12:46:18 +11:00
2023-07-25 21:32:10 +00:00
_popup . PopupEntity ( Loc . GetString ( "drink-component-force-feed" , ( "user" , userName ) ) ,
user , target ) ;
2022-09-13 19:36:19 -07:00
2023-07-25 21:32:10 +00:00
// logging
_adminLogger . Add ( LogType . ForceFeed , LogImpact . Medium , $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to drink {ToPrettyString(item):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution)}" ) ;
2021-11-29 16:27:15 +13:00
}
2023-07-25 21:32:10 +00:00
else
{
// log voluntary drinking
_adminLogger . Add ( LogType . Ingestion , LogImpact . Low , $"{ToPrettyString(target):target} is drinking {ToPrettyString(item):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution)}" ) ;
}
var flavors = _flavorProfile . GetLocalizedFlavorsMessage ( user , drinkSolution ) ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
var doAfterEventArgs = new DoAfterArgs (
user ,
forceDrink ? drink . ForceFeedDelay : drink . Delay ,
new ConsumeDoAfterEvent ( drinkSolution . Name , flavors ) ,
eventTarget : item ,
target : target ,
used : item )
2021-11-29 16:27:15 +13:00
{
2023-07-25 21:32:10 +00:00
BreakOnUserMove = forceDrink ,
BreakOnDamage = true ,
BreakOnTargetMove = forceDrink ,
MovementThreshold = 0.01f ,
DistanceThreshold = 1.0f ,
// Mice and the like can eat without hands.
// TODO maybe set this based on some CanEatWithoutHands event or component?
NeedHand = forceDrink ,
} ;
_doAfter . TryStartDoAfter ( doAfterEventArgs ) ;
return true ;
}
2023-02-26 00:33:06 -05:00
2023-07-25 21:32:10 +00:00
/// <summary>
/// Raised directed at a victim when someone has force fed them a drink.
/// </summary>
private void OnDoAfter ( EntityUid uid , DrinkComponent component , ConsumeDoAfterEvent args )
{
if ( args . Handled | | args . Cancelled | | component . Deleted )
return ;
2023-02-24 19:01:25 -05:00
2023-07-25 21:32:10 +00:00
if ( ! TryComp < BodyComponent > ( args . Target , out var body ) )
return ;
2021-12-07 19:19:26 +13:00
2023-07-25 21:32:10 +00:00
if ( ! _solutionContainer . TryGetSolution ( args . Used , args . Solution , out var solution ) )
return ;
2023-04-17 19:56:42 +12:00
2023-07-25 21:32:10 +00:00
// TODO this should really be checked every tick.
if ( _food . IsMouthBlocked ( args . Target . Value ) )
return ;
2023-04-17 19:56:42 +12:00
2023-07-25 21:32:10 +00:00
// TODO this should really be checked every tick.
if ( ! _interaction . InRangeUnobstructed ( args . User , args . Target . Value ) )
return ;
2023-03-09 03:45:19 -05:00
2023-07-25 21:32:10 +00:00
var transferAmount = FixedPoint2 . Min ( component . TransferAmount , solution . Volume ) ;
var drained = _solutionContainer . SplitSolution ( uid , solution , transferAmount ) ;
var forceDrink = args . User ! = args . Target ;
2022-02-07 00:37:38 +11:00
2023-07-25 21:32:10 +00:00
args . Handled = true ;
if ( transferAmount < = 0 )
return ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
if ( ! _body . TryGetBodyOrganComponents < StomachComponent > ( args . Target . Value , out var stomachs , body ) )
{
_popup . PopupEntity ( forceDrink ? Loc . GetString ( "drink-component-try-use-drink-cannot-drink-other" ) : Loc . GetString ( "drink-component-try-use-drink-had-enough" ) , args . Target . Value , args . User ) ;
2022-02-07 00:37:38 +11:00
2023-07-25 21:32:10 +00:00
if ( HasComp < RefillableSolutionComponent > ( args . Target . Value ) )
{
_puddleSystem . TrySpillAt ( args . User , drained , out _ ) ;
2021-11-29 16:27:15 +13:00
return ;
}
2023-07-25 21:32:10 +00:00
_solutionContainer . Refill ( args . Target . Value , solution , drained ) ;
return ;
}
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
var firstStomach = stomachs . FirstOrNull ( stomach = > _stomach . CanTransferSolution ( stomach . Comp . Owner , drained ) ) ;
2022-07-07 11:21:26 -07:00
2023-07-25 21:32:10 +00:00
//All stomachs are full or can't handle whatever solution we have.
if ( firstStomach = = null )
{
_popup . PopupEntity ( Loc . GetString ( "drink-component-try-use-drink-had-enough" ) , args . Target . Value , args . Target . Value ) ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
if ( forceDrink )
{
_popup . PopupEntity ( Loc . GetString ( "drink-component-try-use-drink-had-enough-other" ) , args . Target . Value , args . User ) ;
_puddleSystem . TrySpillAt ( args . Target . Value , drained , out _ ) ;
2021-11-29 16:27:15 +13:00
}
2023-07-25 21:32:10 +00:00
else
_solutionContainer . TryAddSolution ( uid , solution , drained ) ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00: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-07-25 21:32:10 +00:00
var flavors = args . FlavorMessage ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
if ( forceDrink )
{
var targetName = Identity . Entity ( args . Target . Value , EntityManager ) ;
var userName = Identity . Entity ( args . User , EntityManager ) ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
_popup . PopupEntity ( Loc . GetString ( "drink-component-force-feed-success" , ( "user" , userName ) , ( "flavors" , flavors ) ) , args . Target . Value , args . Target . Value ) ;
2022-12-02 19:19:44 -06:00
2023-07-25 21:32:10 +00:00
_popup . PopupEntity (
Loc . GetString ( "drink-component-force-feed-success-user" , ( "target" , targetName ) ) ,
args . User , args . User ) ;
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
// log successful forced drinking
_adminLogger . Add ( LogType . ForceFeed , LogImpact . Medium , $"{ToPrettyString(uid):user} forced {ToPrettyString(args.User):target} to drink {ToPrettyString(uid):drink}" ) ;
}
else
{
_popup . PopupEntity (
Loc . GetString ( "drink-component-try-use-drink-success-slurp-taste" , ( "flavors" , flavors ) ) , args . User ,
args . User ) ;
_popup . PopupEntity (
Loc . GetString ( "drink-component-try-use-drink-success-slurp" ) , args . User , Filter . PvsExcept ( args . User ) , true ) ;
// log successful voluntary drinking
_adminLogger . Add ( LogType . Ingestion , LogImpact . Low , $"{ToPrettyString(args.User):target} drank {ToPrettyString(uid):drink}" ) ;
}
2021-11-29 16:27:15 +13:00
2023-07-25 21:32:10 +00:00
_audio . PlayPvs ( _audio . GetSound ( component . UseSound ) , args . Target . Value , AudioParams . Default . WithVolume ( - 2f ) ) ;
2023-03-31 07:49:25 +03:00
2023-07-25 21:32:10 +00:00
_reaction . DoEntityReaction ( args . Target . Value , solution , ReactionMethod . Ingestion ) ;
//TODO: Grab the stomach UIDs somehow without using Owner
_stomach . TryTransferSolution ( firstStomach . Value . Comp . Owner , drained , firstStomach . Value . Comp ) ;
2023-04-15 18:14:26 -04:00
2023-07-25 21:32:10 +00:00
var comp = EnsureComp < ForensicsComponent > ( uid ) ;
if ( TryComp < DnaComponent > ( args . Target , out var dna ) )
comp . DNAs . Add ( dna . DNA ) ;
2022-04-23 19:38:21 -04:00
2023-07-25 21:32:10 +00:00
if ( ! forceDrink & & solution . Volume > 0 )
args . Repeat = true ;
}
2022-04-23 19:38:21 -04:00
2023-07-25 21:32:10 +00:00
private void AddDrinkVerb ( EntityUid uid , DrinkComponent component , GetVerbsEvent < AlternativeVerb > ev )
{
if ( uid = = ev . User | |
! ev . CanInteract | |
! ev . CanAccess | |
! EntityManager . TryGetComponent ( ev . User , out BodyComponent ? body ) | |
! _body . TryGetBodyOrganComponents < StomachComponent > ( ev . User , out var stomachs , body ) )
return ;
2022-04-23 19:38:21 -04:00
2023-07-25 21:32:10 +00:00
if ( EntityManager . TryGetComponent < MobStateComponent > ( uid , out var mobState ) & & _mobStateSystem . IsAlive ( uid , mobState ) )
return ;
2022-06-21 22:02:24 -04:00
2023-07-25 21:32:10 +00:00
AlternativeVerb verb = new ( )
2022-06-21 22:02:24 -04:00
{
2023-07-25 21:32:10 +00:00
Act = ( ) = >
{
TryDrink ( ev . User , ev . User , component , uid ) ;
} ,
Icon = new SpriteSpecifier . Texture ( new ( "/Textures/Interface/VerbIcons/drink.svg.192dpi.png" ) ) ,
Text = Loc . GetString ( "drink-system-verb-drink" ) ,
Priority = 2
} ;
ev . Verbs . Add ( verb ) ;
}
// some see half empty, and others see half full
private string HalfEmptyOrHalfFull ( ExaminedEvent args )
{
string remainingString = "drink-component-on-examine-is-half-full" ;
2022-06-21 22:02:24 -04:00
2023-07-25 21:32:10 +00:00
if ( TryComp < MetaDataComponent > ( args . Examiner , out var examiner ) & & examiner . EntityName . Length > 0
& & string . Compare ( examiner . EntityName . Substring ( 0 , 1 ) , "m" , StringComparison . InvariantCultureIgnoreCase ) > 0 )
remainingString = "drink-component-on-examine-is-half-empty" ;
2022-06-21 22:02:24 -04:00
2023-07-25 21:32:10 +00:00
return remainingString ;
2021-09-06 15:49:44 +02:00
}
}