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:
mirrorcult
2021-11-11 16:10:57 -07:00
committed by GitHub
parent 509e1ba6e7
commit 457e8c64ee
77 changed files with 326 additions and 307 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Body.Part;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
namespace Content.Client.Body.Components

View File

@@ -1,4 +1,4 @@
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
namespace Content.Client.Body.Components

View File

@@ -1,5 +1,5 @@
using System;
using Content.Shared.Body.Scanner;
using Content.Shared.Body.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;

View File

@@ -1,6 +1,5 @@
using System.Linq;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Damage;
using Robust.Client.UserInterface.Controls;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Components;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Shared.Console;

View File

@@ -1,6 +1,5 @@
using System;
using Content.Client.Administration;
using Content.Shared.Body.Mechanism;
using Content.Client.Administration;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Shared.Console;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Components;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Shared.Console;

View File

@@ -73,6 +73,7 @@ namespace Content.Client.Entry
"Bucket",
"CableVis",
"Puddle",
"Stomach",
"CanSpill",
"SpeedLoader",
"Hitscan",

View File

@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Content.Server.Body;
using Content.Server.Body.Components;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Rotation;

View File

@@ -4,8 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Content.Server.Atmos;
using Content.Server.Body.Behavior;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Respiratory;
using Content.Server.Body.Components;
using Content.Shared.Atmos;
using Content.Shared.Body.Components;
using NUnit.Framework;

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Threading.Tasks;
using Content.Server.Body.Behavior;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using NUnit.Framework;
using Robust.Shared.GameObjects;

View File

@@ -1,5 +1,5 @@
using Content.Server.Body;
using Content.Server.Body.Mechanism;
using Content.Server.Body.Components;
using Content.Server.Body.Part;
using Content.Server.Storage.Components;
using Content.Shared.Administration;

View File

@@ -1,4 +1,3 @@
using Content.Server.Body.Mechanism;
using Content.Server.Body.Part;
using Content.Server.Storage.Components;
using Content.Shared.Administration;

View File

@@ -1,5 +1,5 @@
using Content.Server.Body;
using Content.Server.Body.Mechanism;
using Content.Server.Body.Components;
using Content.Server.Body.Part;
using Content.Server.Storage.Components;
using Content.Shared.Administration;

View File

@@ -1,4 +1,5 @@
using Content.Server.Body;
using Content.Server.Body.Components;
using Content.Server.Body.Part;
using Content.Shared.Administration;
using Robust.Shared.Console;

View File

@@ -1,4 +1,3 @@
using Content.Server.Body.Mechanism;
using Content.Server.Body.Part;
using Content.Server.Storage.Components;
using Content.Shared.Administration;

View File

@@ -1,5 +1,5 @@
using Content.Server.Body;
using Content.Server.Body.Mechanism;
using Content.Server.Body.Components;
using Content.Server.Body.Part;
using Content.Shared.Administration;
using Robust.Shared.Console;

View File

@@ -1,4 +1,4 @@
using Content.Server.Body.Respiratory;
using Content.Server.Body.Components;
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,6 +1,6 @@
using System;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Respiratory;
using Content.Server.Body.Components;
using Content.Server.Explosion.EntitySystems;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;

View File

@@ -2,8 +2,7 @@ using System;
using Content.Server.Atmos;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Respiratory;
using Content.Server.Body.Components;
using Content.Server.Popups;
using Content.Shared.Atmos;
using Content.Shared.Body.Components;

View File

@@ -1,6 +1,5 @@
using Content.Shared.Body.Behavior;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;

View File

@@ -1,198 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Body.Circulatory;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Behavior
{
/// <summary>
/// Where reagents go when ingested. Tracks ingested reagents over time, and
/// eventually transfers them to <see cref="SharedBloodstreamComponent"/> once digested.
/// </summary>
public class StomachBehavior : MechanismBehavior
{
private const string DefaultSolutionName = "stomach";
private float _accumulatedFrameTime;
/// <summary>
/// Updates digestion status of ingested reagents.
/// Once reagents surpass _digestionDelay they are moved to the
/// bloodstream, where they are then metabolized.
/// </summary>
/// <param name="frameTime">
/// The time since the last update in seconds.
/// </param>
public override void Update(float frameTime)
{
// Do not metabolise if the organ does not have a body.
if (Body == null)
{
return;
}
_accumulatedFrameTime += frameTime;
// Update at most once per second
if (_accumulatedFrameTime < 1)
{
return;
}
_accumulatedFrameTime -= 1;
if (!Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream) ||
StomachSolution == null) // Something has gone wrong here.
{
return;
}
// Reagents ready to transfer into the bloodstream are added to this solution
var transferSolution = new Solution();
// Use ToList here to remove entries while iterating
foreach (var delta in _reagentDeltas.ToList())
{
//Increment lifetime of reagents
delta.Increment(1);
if (delta.Lifetime > _digestionDelay)
{
// This reagent has been in the stomach long enough, TRY to transfer it.
// But first, check if the reagent still exists, and how much is left.
// Some poor spessman may have washed down a potassium snack with some water.
if (StomachSolution.ContainsReagent(delta.ReagentId, out FixedPoint2 quantity))
{
if (quantity > delta.Quantity)
{
quantity = delta.Quantity;
}
EntitySystem.Get<SolutionContainerSystem>()
.TryRemoveReagent(Owner.Uid, StomachSolution, delta.ReagentId, quantity);
transferSolution.AddReagent(delta.ReagentId, quantity);
}
_reagentDeltas.Remove(delta);
}
}
// Transfer digested reagents to bloodstream
bloodstream.TryTransferSolution(transferSolution);
}
public Solution? StomachSolution
{
get
{
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, DefaultSolutionName, out var solution);
return solution;
}
}
/// <summary>
/// Max volume of internal solution storage
/// </summary>
public FixedPoint2 MaxVolume
{
get =>
StomachSolution?.MaxVolume ?? FixedPoint2.Zero;
set
{
if (StomachSolution != null)
{
StomachSolution.MaxVolume = value;
}
}
}
/// <summary>
/// Initial internal solution storage volume
/// </summary>
[DataField("maxVolume")]
[ViewVariables]
protected FixedPoint2 InitialMaxVolume { get; private set; } = FixedPoint2.New(100);
/// <summary>
/// Time in seconds between reagents being ingested and them being
/// transferred to <see cref="SharedBloodstreamComponent"/>
/// </summary>
[DataField("digestionDelay")] [ViewVariables]
private float _digestionDelay = 20;
/// <summary>
/// Used to track how long each reagent has been in the stomach
/// </summary>
[ViewVariables] private readonly List<ReagentDelta> _reagentDeltas = new();
public override void Startup()
{
base.Startup();
var solution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, DefaultSolutionName);
solution.MaxVolume = InitialMaxVolume;
}
public bool CanTransferSolution(Solution solution)
{
if (StomachSolution == null)
{
return false;
}
// TODO: For now no partial transfers. Potentially change by design
if (!StomachSolution.CanAddSolution(solution))
{
return false;
}
return true;
}
public bool TryTransferSolution(Solution solution)
{
if (Owner == null || !CanTransferSolution(solution))
return false;
if (StomachSolution == null)
{
return false;
}
// Add solution to _stomachContents
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(Owner.Uid, StomachSolution, solution);
// Add each reagent to _reagentDeltas. Used to track how long each reagent has been in the stomach
foreach (var reagent in solution.Contents)
{
_reagentDeltas.Add(new ReagentDelta(reagent.ReagentId, reagent.Quantity));
}
return true;
}
/// <summary>
/// Used to track quantity changes when ingesting & digesting reagents
/// </summary>
protected class ReagentDelta
{
public readonly string ReagentId;
public readonly FixedPoint2 Quantity;
public float Lifetime { get; private set; }
public ReagentDelta(string reagentId, FixedPoint2 quantity)
{
ReagentId = reagentId;
Quantity = quantity;
Lifetime = 0.0f;
}
public void Increment(float delta) => Lifetime += delta;
}
}
}

View File

@@ -1,18 +1,16 @@
using System;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Respiratory;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Body.Networks;
using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Circulatory
namespace Content.Server.Body.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedBloodstreamComponent))]

View File

@@ -1,8 +1,8 @@
using Content.Server.Ghost;
using Content.Shared.Audio;
using Content.Shared.Body;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Body.Slot;
using Content.Shared.Random.Helpers;
using Content.Shared.Sound;
using Robust.Shared.Audio;
@@ -12,7 +12,7 @@ using Robust.Shared.Log;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Body
namespace Content.Server.Body.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedBodyComponent))]

View File

@@ -2,7 +2,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Respiratory
namespace Content.Server.Body.Components
{
[RegisterComponent]
public class InternalsComponent : Component

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.UserInterface;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Body.Surgery;
using Content.Shared.Interaction;
@@ -14,7 +13,7 @@ using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Mechanism
namespace Content.Server.Body.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedMechanismComponent))]

View File

@@ -1,18 +1,15 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Content.Shared.Body.Metabolism;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Reagent;
using Content.Server.Body.Systems;
using Content.Shared.Body.Components;
using Content.Shared.Body.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Body.Metabolism
namespace Content.Server.Body.Components
{
/// <summary>
/// Handles metabolizing various reagents with given effects.

View File

@@ -5,7 +5,6 @@ using Content.Server.Alert;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Behavior;
using Content.Server.Body.Circulatory;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Shared.ActionBlocker;
@@ -20,7 +19,7 @@ using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Respiratory
namespace Content.Server.Body.Components
{
[RegisterComponent]
public class RespiratorComponent : Component

View File

@@ -1,7 +1,7 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Body.Respiratory
namespace Content.Server.Body.Components
{
[UsedImplicitly]
public class RespiratorSystem : EntitySystem

View File

@@ -0,0 +1,69 @@
using System.Collections.Generic;
using Content.Server.Body.Systems;
using Content.Shared.Body.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Components
{
[RegisterComponent, Friend(typeof(StomachSystem))]
public class StomachComponent : Component
{
public override string Name => "Stomach";
public float AccumulatedFrameTime;
/// <summary>
/// How fast should this component update, in seconds?
/// </summary>
[DataField("updateInterval")]
public float UpdateInterval = 1.0f;
/// <summary>
/// What solution should this stomach push reagents into, on the body?
/// </summary>
[DataField("bodySolutionName")]
public string BodySolutionName = SharedBloodstreamComponent.DefaultSolutionName;
/// <summary>
/// Initial internal solution storage volume
/// </summary>
[DataField("maxVolume")]
public FixedPoint2 InitialMaxVolume { get; private set; } = FixedPoint2.New(100);
/// <summary>
/// Time in seconds between reagents being ingested and them being
/// transferred to <see cref="SharedBloodstreamComponent"/>
/// </summary>
[DataField("digestionDelay")]
public float DigestionDelay = 20;
/// <summary>
/// Used to track how long each reagent has been in the stomach
/// </summary>
[ViewVariables]
public readonly List<ReagentDelta> ReagentDeltas = new();
/// <summary>
/// Used to track quantity changes when ingesting & digesting reagents
/// </summary>
public class ReagentDelta
{
public readonly string ReagentId;
public readonly FixedPoint2 Quantity;
public float Lifetime { get; private set; }
public ReagentDelta(string reagentId, FixedPoint2 quantity)
{
ReagentId = reagentId;
Quantity = quantity;
Lifetime = 0.0f;
}
public void Increment(float delta) => Lifetime += delta;
}
}
}

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.UserInterface;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Body.Surgery;
using Content.Shared.Interaction;

View File

@@ -1,6 +1,5 @@
using Content.Server.UserInterface;
using Content.Shared.Body.Components;
using Content.Shared.Body.Scanner;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;

View File

@@ -4,7 +4,6 @@ using System.Text;
using System.Threading.Tasks;
using Content.Server.DoAfter;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Body.Surgery;
using Content.Shared.Popups;

View File

@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.Body.Mechanism;
using Content.Server.Body.Components;
using Content.Server.Body.Surgery.Messages;
using Content.Server.UserInterface;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Body.Surgery;
using Content.Shared.Interaction;

View File

@@ -1,12 +1,17 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Body.Components;
using Content.Server.GameTicking;
using Content.Server.Mind.Components;
using Content.Shared.Body.Components;
using Content.Shared.MobState.Components;
using Content.Shared.Movement.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Timing;
namespace Content.Server.Body
namespace Content.Server.Body.Systems
{
public sealed class BodySystem : EntitySystem
{
@@ -34,5 +39,40 @@ namespace Content.Server.Body
_ticker.OnGhostAttempt(mind.Mind!, true);
}
}
public IEnumerable<T> GetComponentsOnMechanisms<T>(EntityUid uid,
SharedBodyComponent? body) where T : Component
{
if (!Resolve(uid, ref body))
yield break;
foreach (var (part, _) in body.Parts)
foreach (var mechanism in part.Mechanisms)
{
if (EntityManager.TryGetComponent<T>(mechanism.OwnerUid, out var comp))
yield return comp;
}
}
public bool TryGetComponentsOnMechanisms<T>(EntityUid uid,
[NotNullWhen(true)] out IEnumerable<T>? comps,
SharedBodyComponent? body) where T: Component
{
if (!Resolve(uid, ref body))
{
comps = null;
return false;
}
comps = GetComponentsOnMechanisms<T>(uid, body).ToArray();
if (!comps.Any())
{
comps = null;
return false;
}
return true;
}
}
}

View File

@@ -1,11 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Mechanism;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
@@ -16,7 +12,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Body.Metabolism
namespace Content.Server.Body.Systems
{
// TODO mirror in the future working on mechanisms move updating here to BodySystem so it can be ordered?
[UsedImplicitly]

View File

@@ -0,0 +1,121 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
namespace Content.Server.Body.Systems
{
public class StomachSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
public const string DefaultSolutionName = "stomach";
public override void Initialize()
{
SubscribeLocalEvent<StomachComponent, ComponentInit>(OnComponentInit);
}
public override void Update(float frameTime)
{
foreach (var (stomach, mech, sol)
in EntityManager.EntityQuery<StomachComponent, MechanismComponent, SolutionContainerManagerComponent>(false))
{
if (mech.Body == null)
continue;
stomach.AccumulatedFrameTime += frameTime;
if (stomach.AccumulatedFrameTime < stomach.UpdateInterval)
continue;
stomach.AccumulatedFrameTime -= stomach.UpdateInterval;
// Get our solutions
if (!_solutionContainerSystem.TryGetSolution(stomach.OwnerUid, DefaultSolutionName,
out var stomachSolution, sol))
continue;
if (!_solutionContainerSystem.TryGetSolution(mech.Body.OwnerUid, stomach.BodySolutionName,
out var bodySolution))
continue;
var transferSolution = new Solution();
var queue = new RemQueue<StomachComponent.ReagentDelta>();
foreach (var delta in stomach.ReagentDeltas)
{
delta.Increment(stomach.UpdateInterval);
if (delta.Lifetime > stomach.DigestionDelay)
{
if (stomachSolution.ContainsReagent(delta.ReagentId, out var quant))
{
if (quant > delta.Quantity)
quant = delta.Quantity;
_solutionContainerSystem.TryRemoveReagent(stomach.OwnerUid, stomachSolution,
delta.ReagentId, quant);
transferSolution.AddReagent(delta.ReagentId, quant);
}
queue.Add(delta);
}
}
foreach (var item in queue)
{
stomach.ReagentDeltas.Remove(item);
}
// Transfer everything to the body solution!
_solutionContainerSystem.TryAddSolution(mech.Body.OwnerUid, bodySolution, transferSolution);
}
}
private void OnComponentInit(EntityUid uid, StomachComponent component, ComponentInit args)
{
var solution = _solutionContainerSystem.EnsureSolution(uid, DefaultSolutionName);
solution.MaxVolume = component.InitialMaxVolume;
}
public bool CanTransferSolution(EntityUid uid, Solution solution,
SolutionContainerManagerComponent? solutions=null)
{
if (!Resolve(uid, ref solutions, false))
return false;
if (!_solutionContainerSystem.TryGetSolution(uid, DefaultSolutionName, out var stomachSolution, solutions))
return false;
// TODO: For now no partial transfers. Potentially change by design
if (!stomachSolution.CanAddSolution(solution))
return false;
return true;
}
public bool TryTransferSolution(EntityUid uid, Solution solution,
StomachComponent? stomach=null,
SolutionContainerManagerComponent? solutions=null)
{
if (!Resolve(uid, ref stomach, ref solutions, false))
return false;
if (!_solutionContainerSystem.TryGetSolution(uid, DefaultSolutionName, out var stomachSolution, solutions)
|| !CanTransferSolution(uid, solution, solutions))
return false;
_solutionContainerSystem.TryAddSolution(uid, stomachSolution, solution);
// Add each reagent to ReagentDeltas. Used to track how long each reagent has been in the stomach
foreach (var reagent in solution.Contents)
{
stomach.ReagentDeltas.Add(new StomachComponent.ReagentDelta(reagent.ReagentId, reagent.Quantity));
}
return true;
}
}
}

View File

@@ -1,4 +1,4 @@
using Content.Server.Body.Circulatory;
using Content.Server.Body.Components;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Inventory.Components;
using Content.Server.Items;

View File

@@ -1,9 +1,9 @@
using System;
using System.Threading.Tasks;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Body.Networks;
using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;

View File

@@ -1,5 +1,4 @@
using Content.Server.Body.Circulatory;
using Content.Server.Body.Respiratory;
using Content.Server.Body.Components;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Reagent;

View File

@@ -215,7 +215,7 @@ namespace Content.Server.Chemistry.EntitySystems
[NotNullWhen(true)] out Solution? solution,
SolutionContainerManagerComponent? solutionsMgr = null)
{
if (!Resolve(uid, ref solutionsMgr))
if (!Resolve(uid, ref solutionsMgr, false))
{
solution = null;
return false;

View File

@@ -1,4 +1,4 @@
using Content.Server.Body.Circulatory;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using JetBrains.Annotations;

View File

@@ -1,5 +1,5 @@
using Content.Server.Body.Metabolism;
using Content.Shared.Body.Metabolism;
using Content.Server.Body.Components;
using Content.Shared.Body.Prototypes;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.GameObjects;

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Cooldown;

View File

@@ -1,9 +1,9 @@
using Content.Shared.DragDrop;
using Content.Shared.Body.Events;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Body.Metabolism;
using Content.Shared.Movement;
using Content.Shared.Speech;
using Content.Shared.Throwing;

View File

@@ -1,5 +1,4 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Slot
namespace Content.Shared.Body
{
public class BodyPartSlot
{

View File

@@ -1,7 +1,7 @@
using Content.Shared.Chemistry.Components;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Networks
namespace Content.Shared.Body.Components
{
public abstract class SharedBloodstreamComponent : Component
{

View File

@@ -5,9 +5,7 @@ using System.Linq;
using Content.Shared.Body.Behavior;
using Content.Shared.Body.Part;
using Content.Shared.Body.Part.Property;
using Content.Shared.Body.Preset;
using Content.Shared.Body.Slot;
using Content.Shared.Body.Template;
using Content.Shared.Body.Prototypes;
using Content.Shared.CharacterAppearance.Systems;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;

View File

@@ -3,8 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Body.Behavior;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Part;
using Content.Shared.Body.Part.Property;
using Content.Shared.Body.Surgery;
using Robust.Shared.GameObjects;
@@ -17,7 +16,7 @@ using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Part
namespace Content.Shared.Body.Components
{
[NetworkedComponent()]
public abstract class SharedBodyPartComponent : Component, IBodyPartContainer

View File

@@ -2,7 +2,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Scanner
namespace Content.Shared.Body.Components
{
public abstract class SharedBodyScannerComponent : Component
{

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Body.Behavior;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -11,7 +10,7 @@ using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
namespace Content.Shared.Body.Mechanism
namespace Content.Shared.Body.Components
{
public abstract class SharedMechanismComponent : Component, ISerializationHooks
{

View File

@@ -1,6 +1,6 @@
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Metabolism
namespace Content.Shared.Body.Events
{
public class ShiverAttemptEvent : CancellableEntityEventArgs
{

View File

@@ -1,6 +1,6 @@
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Metabolism
namespace Content.Shared.Body.Events
{
public class SweatAttemptEvent : CancellableEntityEventArgs
{

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part

View File

@@ -1,3 +1,4 @@
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,3 +1,4 @@
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,4 +1,5 @@
using Robust.Shared.GameObjects;
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Part.Property
{

View File

@@ -1,4 +1,5 @@
using Robust.Shared.GameObjects;
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Part.Property
{

View File

@@ -1,3 +1,4 @@
using Content.Shared.Body.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Preset
namespace Content.Shared.Body.Prototypes
{
/// <summary>
/// Defines the parts used in a body.

View File

@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Body.Template
namespace Content.Shared.Body.Prototypes
{
/// <summary>
/// Defines the layout of a body.

View File

@@ -1,7 +1,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Body.Metabolism
namespace Content.Shared.Body.Prototypes
{
[Prototype("metabolismGroup")]
public class MetabolismGroupPrototype : IPrototype

View File

@@ -1,7 +1,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Body.Metabolism
namespace Content.Shared.Body.Prototypes
{
[Prototype("metabolizerType")]
public class MetabolizerTypePrototype : IPrototype

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Body.Mechanism;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Robust.Shared.GameObjects;

View File

@@ -1,7 +1,8 @@
using JetBrains.Annotations;
using Content.Shared.Body.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Shared.Body.Mechanism
namespace Content.Shared.Body.Systems
{
[UsedImplicitly]
public class MechanismSystem : EntitySystem

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
namespace Content.Shared.CharacterAppearance

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Shared.Body.Metabolism;
using Content.Shared.Body.Prototypes;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reaction;

View File

@@ -136,14 +136,13 @@
- type: Mechanism
size: 1
compatibility: Biological
behaviors:
- !type:StomachBehavior
max_volume: 250
digestionDelay: 20
- type: SolutionContainerManager
solutions:
stomach:
maxVol: 250
- type: Stomach
maxVolume: 250
digestionDelay: 20
# The stomach metabolizes stuff like foods and drinks.
# TODO: Have it work off of the ent's solution container, and move this
# to intestines instead.