Convert StomachBehavior to a component/system + rejig body namespaces (#5249)
* Convert StomachBehavior to a component/system + rejig body namespaces * test * slightly more namespace changes * remove * Hello????? * fuck you github test runner * reviews * oobsy!
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Body.Behavior;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
@@ -102,6 +104,9 @@ namespace Content.Server.Nutrition.Components
|
||||
public bool TryUseFood(IEntity? user, IEntity? target, UtensilComponent? utensilUsed = null)
|
||||
{
|
||||
var solutionContainerSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
var bodySys = EntitySystem.Get<BodySystem>();
|
||||
var stomachSys = EntitySystem.Get<StomachSystem>();
|
||||
|
||||
if (!solutionContainerSys.TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
return false;
|
||||
@@ -122,7 +127,7 @@ namespace Content.Server.Nutrition.Components
|
||||
var trueTarget = target ?? user;
|
||||
|
||||
if (!trueTarget.TryGetComponent(out SharedBodyComponent? body) ||
|
||||
!body.TryGetMechanismBehaviors<StomachBehavior>(out var stomachs))
|
||||
!bodySys.TryGetComponentsOnMechanisms<StomachComponent>(body.OwnerUid, out var stomachs, body))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -165,7 +170,7 @@ namespace Content.Server.Nutrition.Components
|
||||
|
||||
var transferAmount = TransferAmount != null ? FixedPoint2.Min((FixedPoint2)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume;
|
||||
var split = solutionContainerSys.SplitSolution(Owner.Uid, solution, transferAmount);
|
||||
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));
|
||||
var firstStomach = stomachs.FirstOrDefault(stomach => stomachSys.CanTransferSolution(stomach.OwnerUid, split));
|
||||
|
||||
if (firstStomach == null)
|
||||
{
|
||||
@@ -175,13 +180,9 @@ namespace Content.Server.Nutrition.Components
|
||||
}
|
||||
|
||||
// TODO: Account for partial transfer.
|
||||
|
||||
split.DoEntityReaction(trueTarget.Uid, ReactionMethod.Ingestion);
|
||||
|
||||
firstStomach.TryTransferSolution(split);
|
||||
|
||||
stomachSys.TryTransferSolution(firstStomach.OwnerUid, split, firstStomach);
|
||||
SoundSystem.Play(Filter.Pvs(trueTarget), UseSound.GetSound(), trueTarget, AudioParams.Default.WithVolume(-1f));
|
||||
|
||||
trueTarget.PopupMessage(user, Loc.GetString(_eatMessage, ("food", Owner)));
|
||||
|
||||
// If utensils were used
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Body.Behavior;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Fluids.Components;
|
||||
@@ -31,6 +33,8 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
[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!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -211,7 +215,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(targetUid, out SharedBodyComponent? body) ||
|
||||
!body.TryGetMechanismBehaviors<StomachBehavior>(out var stomachs))
|
||||
!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(targetUid, out var stomachs, body))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-cannot-drink", ("owner", owner)), targetUid, Filter.Entities(targetUid));
|
||||
return false;
|
||||
@@ -222,7 +226,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
|
||||
var transferAmount = FixedPoint2.Min(component.TransferAmount, interactions.DrainAvailable);
|
||||
var drain = _solutionContainerSystem.Drain(owner.Uid, interactions, transferAmount);
|
||||
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(drain));
|
||||
var firstStomach = stomachs.FirstOrDefault(stomach => _stomachSystem.CanTransferSolution(stomach.OwnerUid, drain));
|
||||
|
||||
// All stomach are full or can't handle whatever solution we have.
|
||||
if (firstStomach == null)
|
||||
@@ -244,10 +248,8 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-success-slurp"), targetUid, Filter.Pvs(targetUid));
|
||||
|
||||
// TODO: Account for partial transfer.
|
||||
|
||||
drain.DoEntityReaction(targetUid, ReactionMethod.Ingestion);
|
||||
|
||||
firstStomach.TryTransferSolution(drain);
|
||||
_stomachSystem.TryTransferSolution(firstStomach.OwnerUid, drain, firstStomach);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Body.Circulatory;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
|
||||
Reference in New Issue
Block a user