let animals drink things (#18236)

* thirst .Owner removal

* thirst file scope

* drink update + minor refactor

* drink file scope

* let animals drink things

* dont eat/drink when dont need to

* admeme mouse override

* moo

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-07-25 21:32:10 +00:00
committed by GitHub
parent d55cd23b0a
commit 063f75ca29
8 changed files with 705 additions and 594 deletions

View File

@@ -0,0 +1,6 @@
namespace Content.Server.NPC.Queries.Considerations;
public sealed class DrinkValueCon : UtilityConsideration
{
}

View File

@@ -12,6 +12,7 @@ using Content.Server.Storage.Components;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Fluids.Components; using Content.Shared.Fluids.Components;
using Content.Shared.Mobs.Systems; using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition.Components;
using Robust.Server.Containers; using Robust.Server.Containers;
using Robust.Shared.Collections; using Robust.Shared.Collections;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -23,12 +24,13 @@ namespace Content.Server.NPC.Systems;
/// </summary> /// </summary>
public sealed class NPCUtilitySystem : EntitySystem public sealed class NPCUtilitySystem : EntitySystem
{ {
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly ContainerSystem _container = default!; [Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly DrinkSystem _drink = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
[Dependency] private readonly FoodSystem _food = default!; [Dependency] private readonly FoodSystem _food = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
[Dependency] private readonly PuddleSystem _puddle = default!; [Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SolutionContainerSystem _solutions = default!; [Dependency] private readonly SolutionContainerSystem _solutions = default!;
@@ -132,13 +134,38 @@ public sealed class NPCUtilitySystem : EntitySystem
if (!_food.IsDigestibleBy(owner, targetUid, food)) if (!_food.IsDigestibleBy(owner, targetUid, food))
return 0f; return 0f;
// no mouse don't eat the uranium-235
var avoidBadFood = !HasComp<IgnoreBadFoodComponent>(owner); var avoidBadFood = !HasComp<IgnoreBadFoodComponent>(owner);
// only eat when hungry or if it will eat anything
if (TryComp<HungerComponent>(owner, out var hunger) && hunger.CurrentThreshold > HungerThreshold.Okay && avoidBadFood)
return 0f;
// no mouse don't eat the uranium-235
if (avoidBadFood && HasComp<BadFoodComponent>(targetUid)) if (avoidBadFood && HasComp<BadFoodComponent>(targetUid))
return 0f; return 0f;
return 1f; return 1f;
} }
case DrinkValueCon:
{
if (!TryComp<DrinkComponent>(targetUid, out var drink) || !drink.Opened)
return 0f;
// only drink when thirsty
if (TryComp<ThirstComponent>(owner, out var thirst) && thirst.CurrentThirstThreshold > ThirstThreshold.Okay)
return 0f;
// no janicow don't drink the blood puddle
if (HasComp<BadDrinkComponent>(targetUid))
return 0f;
// needs to have something that will satiate thirst, mice wont try to drink 100% pure mutagen.
var hydration = _drink.TotalHydration(targetUid, drink);
if (hydration <= 1.0f)
return 0f;
return 1f;
}
case TargetAccessibleCon: case TargetAccessibleCon:
{ {
if (_container.TryGetContainingContainer(targetUid, out var container)) if (_container.TryGetContainingContainer(targetUid, out var container))

View File

@@ -0,0 +1,12 @@
using Content.Server.Nutrition.EntitySystems;
namespace Content.Server.Nutrition.Components;
/// <summary>
/// This component prevents NPC mobs like mice or cows from wanting to drink something that shouldn't be drank from.
/// Including but not limited to: puddles
/// </summary>
[RegisterComponent, Access(typeof(DrinkSystem))]
public sealed class BadDrinkComponent : Component
{
}

View File

@@ -2,6 +2,7 @@ using Content.Server.Body.Components;
using Content.Server.Body.Systems; using Content.Server.Body.Systems;
using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Chemistry.ReagentEffects;
using Content.Server.Fluids.EntitySystems; using Content.Server.Fluids.EntitySystems;
using Content.Server.Forensics; using Content.Server.Forensics;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
@@ -24,32 +25,32 @@ using Content.Shared.Nutrition;
using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.Components;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.Nutrition.EntitySystems namespace Content.Server.Nutrition.EntitySystems;
public sealed class DrinkSystem : EntitySystem
{ {
[UsedImplicitly] [Dependency] private readonly BodySystem _body = default!;
public sealed class DrinkSystem : EntitySystem [Dependency] private readonly FoodSystem _food = default!;
{ [Dependency] private readonly FlavorProfileSystem _flavorProfile = default!;
[Dependency] private readonly FoodSystem _foodSystem = default!; [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly FlavorProfileSystem _flavorProfileSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly StomachSystem _stomachSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!; [Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PuddleSystem _puddleSystem = default!; [Dependency] private readonly PuddleSystem _puddleSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly ReactiveSystem _reaction = 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() public override void Initialize()
{ {
@@ -69,10 +70,10 @@ namespace Content.Server.Nutrition.EntitySystems
private FixedPoint2 DrinkVolume(EntityUid uid, DrinkComponent? component = null) private FixedPoint2 DrinkVolume(EntityUid uid, DrinkComponent? component = null)
{ {
if(!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
return FixedPoint2.Zero; return FixedPoint2.Zero;
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var sol)) if (!_solutionContainer.TryGetSolution(uid, component.SolutionName, out var sol))
return FixedPoint2.Zero; return FixedPoint2.Zero;
return sol.Volume; return sol.Volume;
@@ -80,12 +81,46 @@ namespace Content.Server.Nutrition.EntitySystems
public bool IsEmpty(EntityUid uid, DrinkComponent? component = null) public bool IsEmpty(EntityUid uid, DrinkComponent? component = null)
{ {
if(!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
return true; return true;
return DrinkVolume(uid, component) <= 0; 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;
if (!_solutionContainer.TryGetSolution(uid, comp.SolutionName, out var solution))
return 0f;
var total = 0f;
foreach (var quantity in solution.Contents)
{
var reagent = _proto.Index<ReagentPrototype>(quantity.ReagentId);
if (reagent.Metabolisms == null)
continue;
foreach ((var _, var entry) in reagent.Metabolisms)
{
foreach (var effect in entry.Effects)
{
// ignores any effect conditions, just cares about how much it can hydrate
if (effect is SatiateThirst thirst)
{
total += thirst.HydrationFactor * quantity.Quantity.Float();
}
}
}
}
return total;
}
private void OnExamined(EntityUid uid, DrinkComponent component, ExaminedEvent args) private void OnExamined(EntityUid uid, DrinkComponent component, ExaminedEvent args)
{ {
if (!component.Opened || !args.IsInDetailsRange || !component.Examinable) if (!component.Opened || !args.IsInDetailsRange || !component.Examinable)
@@ -105,7 +140,7 @@ namespace Content.Server.Nutrition.EntitySystems
else else
{ {
//general approximation //general approximation
var remainingString = (int) _solutionContainerSystem.PercentFull(uid) switch var remainingString = (int) _solutionContainer.PercentFull(uid) switch
{ {
100 => "drink-component-on-examine-is-full", 100 => "drink-component-on-examine-is-full",
> 66 => "drink-component-on-examine-is-mostly-full", > 66 => "drink-component-on-examine-is-mostly-full",
@@ -127,12 +162,12 @@ namespace Content.Server.Nutrition.EntitySystems
component.Opened = opened; component.Opened = opened;
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out _)) if (!_solutionContainer.TryGetSolution(uid, component.SolutionName, out _))
return; return;
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance)) if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
{ {
_appearanceSystem.SetData(uid, DrinkCanStateVisual.Opened, opened, appearance); _appearance.SetData(uid, DrinkCanStateVisual.Opened, opened, appearance);
} }
} }
@@ -166,12 +201,12 @@ namespace Content.Server.Nutrition.EntitySystems
if (component.Pressurized && if (component.Pressurized &&
!component.Opened && !component.Opened &&
_random.Prob(0.25f) && _random.Prob(0.25f) &&
_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var interactions)) _solutionContainer.TryGetSolution(uid, component.SolutionName, out var interactions))
{ {
component.Opened = true; component.Opened = true;
UpdateAppearance(component); UpdateAppearance(uid, component);
var solution = _solutionContainerSystem.SplitSolution(uid, interactions, interactions.Volume); var solution = _solutionContainer.SplitSolution(uid, interactions, interactions.Volume);
_puddleSystem.TrySpillAt(uid, solution, out _); _puddleSystem.TrySpillAt(uid, solution, out _);
_audio.PlayPvs(_audio.GetSound(component.BurstSound), uid, AudioParams.Default.WithVolume(-4)); _audio.PlayPvs(_audio.GetSound(component.BurstSound), uid, AudioParams.Default.WithVolume(-4));
@@ -189,10 +224,10 @@ namespace Content.Server.Nutrition.EntitySystems
} }
else else
{ {
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName); _solutionContainer.EnsureSolution(uid, component.SolutionName);
} }
UpdateAppearance(component); UpdateAppearance(uid, component);
if (TryComp(uid, out RefillableSolutionComponent? refillComp)) if (TryComp(uid, out RefillableSolutionComponent? refillComp))
refillComp.Solution = component.SolutionName; refillComp.Solution = component.SolutionName;
@@ -203,28 +238,27 @@ namespace Content.Server.Nutrition.EntitySystems
private void OnSolutionChange(EntityUid uid, DrinkComponent component, SolutionChangedEvent args) private void OnSolutionChange(EntityUid uid, DrinkComponent component, SolutionChangedEvent args)
{ {
UpdateAppearance(component); UpdateAppearance(uid, component);
} }
public void UpdateAppearance(DrinkComponent component) public void UpdateAppearance(EntityUid uid, DrinkComponent component)
{ {
if (!EntityManager.TryGetComponent((component).Owner, out AppearanceComponent? appearance) || if (!TryComp<AppearanceComponent>(uid, out var appearance) ||
!EntityManager.HasComponent<SolutionContainerManagerComponent>((component).Owner)) !HasComp<SolutionContainerManagerComponent>(uid))
{ {
return; return;
} }
var drainAvailable = DrinkVolume((component.Owner), component); var drainAvailable = DrinkVolume(uid, component);
_appearanceSystem.SetData(component.Owner, FoodVisuals.Visual, drainAvailable.Float(), appearance); _appearance.SetData(uid, FoodVisuals.Visual, drainAvailable.Float(), appearance);
_appearanceSystem.SetData(component.Owner, DrinkCanStateVisual.Opened, component.Opened, appearance); _appearance.SetData(uid, DrinkCanStateVisual.Opened, component.Opened, appearance);
} }
private void OnTransferAttempt(EntityUid uid, DrinkComponent component, SolutionTransferAttemptEvent args) private void OnTransferAttempt(EntityUid uid, DrinkComponent component, SolutionTransferAttemptEvent args)
{ {
if (!component.Opened) if (!component.Opened)
{ {
args.Cancel(Loc.GetString("drink-component-try-use-drink-not-open", args.Cancel(Loc.GetString("drink-component-try-use-drink-not-open", ("owner", uid)));
("owner", EntityManager.GetComponent<MetaDataComponent>(component.Owner).EntityName)));
} }
} }
@@ -235,15 +269,15 @@ namespace Content.Server.Nutrition.EntitySystems
if (!drink.Opened) if (!drink.Opened)
{ {
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open", _popup.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open",
("owner", EntityManager.GetComponent<MetaDataComponent>(item).EntityName)), item, user); ("owner", EntityManager.GetComponent<MetaDataComponent>(item).EntityName)), item, user);
return true; return true;
} }
if (!_solutionContainerSystem.TryGetSolution(item, drink.SolutionName, out var drinkSolution) || if (!_solutionContainer.TryGetSolution(item, drink.SolutionName, out var drinkSolution) ||
drinkSolution.Volume <= 0) drinkSolution.Volume <= 0)
{ {
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty", _popup.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty",
("entity", EntityManager.GetComponent<MetaDataComponent>(item).EntityName)), item, user); ("entity", EntityManager.GetComponent<MetaDataComponent>(item).EntityName)), item, user);
return true; return true;
} }
@@ -251,10 +285,10 @@ namespace Content.Server.Nutrition.EntitySystems
if (drinkSolution.Name == null) if (drinkSolution.Name == null)
return false; return false;
if (_foodSystem.IsMouthBlocked(target, user)) if (_food.IsMouthBlocked(target, user))
return true; return true;
if (!_interactionSystem.InRangeUnobstructed(user, item, popup: true)) if (!_interaction.InRangeUnobstructed(user, item, popup: true))
return true; return true;
var forceDrink = user != target; var forceDrink = user != target;
@@ -263,7 +297,7 @@ namespace Content.Server.Nutrition.EntitySystems
{ {
var userName = Identity.Entity(user, EntityManager); var userName = Identity.Entity(user, EntityManager);
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed", ("user", userName)), _popup.PopupEntity(Loc.GetString("drink-component-force-feed", ("user", userName)),
user, target); user, target);
// logging // logging
@@ -275,7 +309,7 @@ namespace Content.Server.Nutrition.EntitySystems
_adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(target):target} is drinking {ToPrettyString(item):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution)}"); _adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(target):target} is drinking {ToPrettyString(item):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution)}");
} }
var flavors = _flavorProfileSystem.GetLocalizedFlavorsMessage(user, drinkSolution); var flavors = _flavorProfile.GetLocalizedFlavorsMessage(user, drinkSolution);
var doAfterEventArgs = new DoAfterArgs( var doAfterEventArgs = new DoAfterArgs(
user, user,
@@ -295,7 +329,7 @@ namespace Content.Server.Nutrition.EntitySystems
NeedHand = forceDrink, NeedHand = forceDrink,
}; };
_doAfterSystem.TryStartDoAfter(doAfterEventArgs); _doAfter.TryStartDoAfter(doAfterEventArgs);
return true; return true;
} }
@@ -310,28 +344,28 @@ namespace Content.Server.Nutrition.EntitySystems
if (!TryComp<BodyComponent>(args.Target, out var body)) if (!TryComp<BodyComponent>(args.Target, out var body))
return; return;
if (!_solutionContainerSystem.TryGetSolution(args.Used, args.Solution, out var solution)) if (!_solutionContainer.TryGetSolution(args.Used, args.Solution, out var solution))
return; return;
// TODO this should really be checked every tick. // TODO this should really be checked every tick.
if (_foodSystem.IsMouthBlocked(args.Target.Value)) if (_food.IsMouthBlocked(args.Target.Value))
return; return;
// TODO this should really be checked every tick. // TODO this should really be checked every tick.
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target.Value)) if (!_interaction.InRangeUnobstructed(args.User, args.Target.Value))
return; return;
var transferAmount = FixedPoint2.Min(component.TransferAmount, solution.Volume); var transferAmount = FixedPoint2.Min(component.TransferAmount, solution.Volume);
var drained = _solutionContainerSystem.SplitSolution(uid, solution, transferAmount); var drained = _solutionContainer.SplitSolution(uid, solution, transferAmount);
var forceDrink = args.User != args.Target; var forceDrink = args.User != args.Target;
args.Handled = true; args.Handled = true;
if (transferAmount <= 0) if (transferAmount <= 0)
return; return;
if (!_bodySystem.TryGetBodyOrganComponents<StomachComponent>(args.Target.Value, out var stomachs, body)) if (!_body.TryGetBodyOrganComponents<StomachComponent>(args.Target.Value, out var stomachs, body))
{ {
_popupSystem.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); _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);
if (HasComp<RefillableSolutionComponent>(args.Target.Value)) if (HasComp<RefillableSolutionComponent>(args.Target.Value))
{ {
@@ -339,24 +373,24 @@ namespace Content.Server.Nutrition.EntitySystems
return; return;
} }
_solutionContainerSystem.Refill(args.Target.Value, solution, drained); _solutionContainer.Refill(args.Target.Value, solution, drained);
return; return;
} }
var firstStomach = stomachs.FirstOrNull(stomach => _stomachSystem.CanTransferSolution(stomach.Comp.Owner, drained)); var firstStomach = stomachs.FirstOrNull(stomach => _stomach.CanTransferSolution(stomach.Comp.Owner, drained));
//All stomachs are full or can't handle whatever solution we have. //All stomachs are full or can't handle whatever solution we have.
if (firstStomach == null) if (firstStomach == null)
{ {
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough"), args.Target.Value, args.Target.Value); _popup.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough"), args.Target.Value, args.Target.Value);
if (forceDrink) if (forceDrink)
{ {
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough-other"), args.Target.Value, args.User); _popup.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough-other"), args.Target.Value, args.User);
_puddleSystem.TrySpillAt(args.Target.Value, drained, out _); _puddleSystem.TrySpillAt(args.Target.Value, drained, out _);
} }
else else
_solutionContainerSystem.TryAddSolution(uid, solution, drained); _solutionContainer.TryAddSolution(uid, solution, drained);
return; return;
} }
@@ -368,21 +402,21 @@ namespace Content.Server.Nutrition.EntitySystems
var targetName = Identity.Entity(args.Target.Value, EntityManager); var targetName = Identity.Entity(args.Target.Value, EntityManager);
var userName = Identity.Entity(args.User, EntityManager); var userName = Identity.Entity(args.User, EntityManager);
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed-success", ("user", userName), ("flavors", flavors)), args.Target.Value, args.Target.Value); _popup.PopupEntity(Loc.GetString("drink-component-force-feed-success", ("user", userName), ("flavors", flavors)), args.Target.Value, args.Target.Value);
_popupSystem.PopupEntity( _popup.PopupEntity(
Loc.GetString("drink-component-force-feed-success-user", ("target", targetName)), Loc.GetString("drink-component-force-feed-success-user", ("target", targetName)),
args.User, args.User); args.User, args.User);
// log successful forced drinking // log successful forced drinking
_adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(uid):user} forced {ToPrettyString(args.User):target} to drink {ToPrettyString(component.Owner):drink}"); _adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(uid):user} forced {ToPrettyString(args.User):target} to drink {ToPrettyString(uid):drink}");
} }
else else
{ {
_popupSystem.PopupEntity( _popup.PopupEntity(
Loc.GetString("drink-component-try-use-drink-success-slurp-taste", ("flavors", flavors)), args.User, Loc.GetString("drink-component-try-use-drink-success-slurp-taste", ("flavors", flavors)), args.User,
args.User); args.User);
_popupSystem.PopupEntity( _popup.PopupEntity(
Loc.GetString("drink-component-try-use-drink-success-slurp"), args.User, Filter.PvsExcept(args.User), true); Loc.GetString("drink-component-try-use-drink-success-slurp"), args.User, Filter.PvsExcept(args.User), true);
// log successful voluntary drinking // log successful voluntary drinking
@@ -393,7 +427,7 @@ namespace Content.Server.Nutrition.EntitySystems
_reaction.DoEntityReaction(args.Target.Value, solution, ReactionMethod.Ingestion); _reaction.DoEntityReaction(args.Target.Value, solution, ReactionMethod.Ingestion);
//TODO: Grab the stomach UIDs somehow without using Owner //TODO: Grab the stomach UIDs somehow without using Owner
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp); _stomach.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp);
var comp = EnsureComp<ForensicsComponent>(uid); var comp = EnsureComp<ForensicsComponent>(uid);
if (TryComp<DnaComponent>(args.Target, out var dna)) if (TryComp<DnaComponent>(args.Target, out var dna))
@@ -409,7 +443,7 @@ namespace Content.Server.Nutrition.EntitySystems
!ev.CanInteract || !ev.CanInteract ||
!ev.CanAccess || !ev.CanAccess ||
!EntityManager.TryGetComponent(ev.User, out BodyComponent? body) || !EntityManager.TryGetComponent(ev.User, out BodyComponent? body) ||
!_bodySystem.TryGetBodyOrganComponents<StomachComponent>(ev.User, out var stomachs, body)) !_body.TryGetBodyOrganComponents<StomachComponent>(ev.User, out var stomachs, body))
return; return;
if (EntityManager.TryGetComponent<MobStateComponent>(uid, out var mobState) && _mobStateSystem.IsAlive(uid, mobState)) if (EntityManager.TryGetComponent<MobStateComponent>(uid, out var mobState) && _mobStateSystem.IsAlive(uid, mobState))
@@ -440,5 +474,4 @@ namespace Content.Server.Nutrition.EntitySystems
return remainingString; return remainingString;
} }
}
} }

View File

@@ -6,11 +6,11 @@ using Content.Shared.Alert;
using Content.Shared.Movement.Systems; using Content.Shared.Movement.Systems;
using Content.Shared.Rejuvenate; using Content.Shared.Rejuvenate;
namespace Content.Server.Nutrition.EntitySystems namespace Content.Server.Nutrition.EntitySystems;
[UsedImplicitly]
public sealed class ThirstSystem : EntitySystem
{ {
[UsedImplicitly]
public sealed class ThirstSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!; [Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
@@ -24,10 +24,12 @@ namespace Content.Server.Nutrition.EntitySystems
base.Initialize(); base.Initialize();
_sawmill = Logger.GetSawmill("thirst"); _sawmill = Logger.GetSawmill("thirst");
SubscribeLocalEvent<ThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed); SubscribeLocalEvent<ThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ThirstComponent, ComponentStartup>(OnComponentStartup); SubscribeLocalEvent<ThirstComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate); SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate);
} }
private void OnComponentStartup(EntityUid uid, ThirstComponent component, ComponentStartup args) private void OnComponentStartup(EntityUid uid, ThirstComponent component, ComponentStartup args)
{ {
// Do not change behavior unless starting value is explicitly defined // Do not change behavior unless starting value is explicitly defined
@@ -40,13 +42,13 @@ namespace Content.Server.Nutrition.EntitySystems
component.CurrentThirstThreshold = GetThirstThreshold(component, component.CurrentThirst); component.CurrentThirstThreshold = GetThirstThreshold(component, component.CurrentThirst);
component.LastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects. component.LastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
// TODO: Check all thresholds make sense and throw if they don't. // TODO: Check all thresholds make sense and throw if they don't.
UpdateEffects(component); UpdateEffects(uid, component);
} }
private void OnRefreshMovespeed(EntityUid uid, ThirstComponent component, RefreshMovementSpeedModifiersEvent args) private void OnRefreshMovespeed(EntityUid uid, ThirstComponent component, RefreshMovementSpeedModifiersEvent args)
{ {
// TODO: This should really be taken care of somewhere else // TODO: This should really be taken care of somewhere else
if (_jetpack.IsUserFlying(component.Owner)) if (_jetpack.IsUserFlying(uid))
return; return;
var mod = component.CurrentThirstThreshold <= ThirstThreshold.Parched ? 0.75f : 1.0f; var mod = component.CurrentThirstThreshold <= ThirstThreshold.Parched ? 0.75f : 1.0f;
@@ -100,22 +102,22 @@ namespace Content.Server.Nutrition.EntitySystems
} }
} }
private void UpdateEffects(ThirstComponent component) private void UpdateEffects(EntityUid uid, ThirstComponent component)
{ {
if (IsMovementThreshold(component.LastThirstThreshold) != IsMovementThreshold(component.CurrentThirstThreshold) && if (IsMovementThreshold(component.LastThirstThreshold) != IsMovementThreshold(component.CurrentThirstThreshold) &&
TryComp(component.Owner, out MovementSpeedModifierComponent? movementSlowdownComponent)) TryComp(uid, out MovementSpeedModifierComponent? movementSlowdownComponent))
{ {
_movement.RefreshMovementSpeedModifiers(component.Owner, movementSlowdownComponent); _movement.RefreshMovementSpeedModifiers(uid, movementSlowdownComponent);
} }
// Update UI // Update UI
if (ThirstComponent.ThirstThresholdAlertTypes.TryGetValue(component.CurrentThirstThreshold, out var alertId)) if (ThirstComponent.ThirstThresholdAlertTypes.TryGetValue(component.CurrentThirstThreshold, out var alertId))
{ {
_alerts.ShowAlert(component.Owner, alertId); _alerts.ShowAlert(uid, alertId);
} }
else else
{ {
_alerts.ClearAlertCategory(component.Owner, AlertCategory.Thirst); _alerts.ClearAlertCategory(uid, AlertCategory.Thirst);
} }
switch (component.CurrentThirstThreshold) switch (component.CurrentThirstThreshold)
@@ -136,7 +138,7 @@ namespace Content.Server.Nutrition.EntitySystems
component.ActualDecayRate = component.BaseDecayRate * 0.8f; component.ActualDecayRate = component.BaseDecayRate * 0.8f;
return; return;
case ThirstThreshold.Parched: case ThirstThreshold.Parched:
_movement.RefreshMovementSpeedModifiers(component.Owner); _movement.RefreshMovementSpeedModifiers(uid);
component.LastThirstThreshold = component.CurrentThirstThreshold; component.LastThirstThreshold = component.CurrentThirstThreshold;
component.ActualDecayRate = component.BaseDecayRate * 0.6f; component.ActualDecayRate = component.BaseDecayRate * 0.6f;
return; return;
@@ -149,24 +151,25 @@ namespace Content.Server.Nutrition.EntitySystems
throw new ArgumentOutOfRangeException($"No thirst threshold found for {component.CurrentThirstThreshold}"); throw new ArgumentOutOfRangeException($"No thirst threshold found for {component.CurrentThirstThreshold}");
} }
} }
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
_accumulatedFrameTime += frameTime; _accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime > 1) if (_accumulatedFrameTime > 1)
{ {
foreach (var component in EntityManager.EntityQuery<ThirstComponent>()) var query = EntityManager.EntityQueryEnumerator<ThirstComponent>();
while (query.MoveNext(out var uid, out var comp))
{ {
UpdateThirst(component, - component.ActualDecayRate); UpdateThirst(comp, - comp.ActualDecayRate);
var calculatedThirstThreshold = GetThirstThreshold(component, component.CurrentThirst); var calculatedThirstThreshold = GetThirstThreshold(comp, comp.CurrentThirst);
if (calculatedThirstThreshold != component.CurrentThirstThreshold) if (calculatedThirstThreshold != comp.CurrentThirstThreshold)
{ {
component.CurrentThirstThreshold = calculatedThirstThreshold; comp.CurrentThirstThreshold = calculatedThirstThreshold;
UpdateEffects(component); UpdateEffects(uid, comp);
} }
} }
_accumulatedFrameTime -= 1; _accumulatedFrameTime -= 1;
} }
} }
}
} }

View File

@@ -159,3 +159,4 @@
examinable: false examinable: false
- type: ExaminableSolution - type: ExaminableSolution
solution: puddle solution: puddle
- type: BadDrink

View File

@@ -6,6 +6,11 @@
- id: MoveToCombatTargetPrimitive - id: MoveToCombatTargetPrimitive
- id: EatPrimitive - id: EatPrimitive
- id: WaitIdleTimePrimitive - id: WaitIdleTimePrimitive
- tasks:
- id: PickDrinkTargetPrimitive
- id: MoveToCombatTargetPrimitive
- id: EatPrimitive
- id: WaitIdleTimePrimitive
- type: htnPrimitive - type: htnPrimitive
@@ -13,6 +18,11 @@
operator: !type:UtilityOperator operator: !type:UtilityOperator
proto: NearbyFood proto: NearbyFood
- type: htnPrimitive
id: PickDrinkTargetPrimitive
operator: !type:UtilityOperator
proto: NearbyDrink
- type: htnPrimitive - type: htnPrimitive
id: EatPrimitive id: EatPrimitive
preconditions: preconditions:

View File

@@ -17,6 +17,25 @@
- !type:TargetAccessibleCon - !type:TargetAccessibleCon
curve: !type:BoolCurve curve: !type:BoolCurve
- type: utilityQuery
id: NearbyDrink
query:
- !type:ComponentQuery
components:
- type: Drink
considerations:
- !type:TargetIsAliveCon
curve: !type:InverseBoolCurve
- !type:TargetDistanceCon
curve: !type:PresetCurve
preset: TargetDistance
- !type:DrinkValueCon
curve: !type:QuadraticCurve
slope: 1.0
exponent: 0.4
- !type:TargetAccessibleCon
curve: !type:BoolCurve
- type: utilityQuery - type: utilityQuery
id: NearbyMeleeTargets id: NearbyMeleeTargets
query: query: