ECS and cleanup body system, merge body templates and presets into body prototypes (#11991)

Co-authored-by: Jezithyr <Jezithyr@gmail.com>
This commit is contained in:
DrSmugleaf
2022-10-23 00:46:28 +02:00
committed by GitHub
parent 9a38736c3c
commit f323fb7644
140 changed files with 2478 additions and 2571 deletions

View File

@@ -1,7 +1,7 @@
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.Organ;
using Content.Shared.Chemistry.Components;
using Robust.Shared.Utility;
@@ -9,6 +9,7 @@ namespace Content.Server.Body.Systems
{
public sealed class StomachSystem : EntitySystem
{
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
public const string DefaultSolutionName = "stomach";
@@ -21,12 +22,8 @@ namespace Content.Server.Body.Systems
public override void Update(float frameTime)
{
foreach (var (stomach, mech, sol)
in EntityManager.EntityQuery<StomachComponent, MechanismComponent, SolutionContainerManagerComponent>(false))
foreach (var (stomach, organ, sol)in EntityManager.EntityQuery<StomachComponent, OrganComponent, SolutionContainerManagerComponent>())
{
if (mech.Body == null)
continue;
stomach.AccumulatedFrameTime += frameTime;
if (stomach.AccumulatedFrameTime < stomach.UpdateInterval)
@@ -35,12 +32,11 @@ namespace Content.Server.Body.Systems
stomach.AccumulatedFrameTime -= stomach.UpdateInterval;
// Get our solutions
if (!_solutionContainerSystem.TryGetSolution((stomach).Owner, DefaultSolutionName,
out var stomachSolution, sol))
if (!_solutionContainerSystem.TryGetSolution(stomach.Owner, DefaultSolutionName,
out var stomachSolution, sol))
continue;
if (!_solutionContainerSystem.TryGetSolution((mech.Body).Owner, stomach.BodySolutionName,
out var bodySolution))
if (organ.Body is not { } body || !_solutionContainerSystem.TryGetSolution(body, stomach.BodySolutionName, out var bodySolution))
continue;
var transferSolution = new Solution();
@@ -71,23 +67,25 @@ namespace Content.Server.Body.Systems
}
// Transfer everything to the body solution!
_solutionContainerSystem.TryAddSolution((mech.Body).Owner, bodySolution, transferSolution);
_solutionContainerSystem.TryAddSolution(body, bodySolution, transferSolution);
}
}
private void OnApplyMetabolicMultiplier(EntityUid uid, StomachComponent component, ApplyMetabolicMultiplierEvent args)
{
if (args.Apply)
private void OnApplyMetabolicMultiplier(EntityUid uid, StomachComponent component,
ApplyMetabolicMultiplierEvent args)
{
component.UpdateInterval *= args.Multiplier;
return;
if (args.Apply)
{
component.UpdateInterval *= args.Multiplier;
return;
}
// This way we don't have to worry about it breaking if the stasis bed component is destroyed
component.UpdateInterval /= args.Multiplier;
// Reset the accumulator properly
if (component.AccumulatedFrameTime >= component.UpdateInterval)
component.AccumulatedFrameTime = component.UpdateInterval;
}
// This way we don't have to worry about it breaking if the stasis bed component is destroyed
component.UpdateInterval /= args.Multiplier;
// Reset the accumulator properly
if (component.AccumulatedFrameTime >= component.UpdateInterval)
component.AccumulatedFrameTime = component.UpdateInterval;
}
private void OnComponentInit(EntityUid uid, StomachComponent component, ComponentInit args)
{
@@ -96,7 +94,7 @@ namespace Content.Server.Body.Systems
}
public bool CanTransferSolution(EntityUid uid, Solution solution,
SolutionContainerManagerComponent? solutions=null)
SolutionContainerManagerComponent? solutions = null)
{
if (!Resolve(uid, ref solutions, false))
return false;
@@ -112,8 +110,8 @@ namespace Content.Server.Body.Systems
}
public bool TryTransferSolution(EntityUid uid, Solution solution,
StomachComponent? stomach=null,
SolutionContainerManagerComponent? solutions=null)
StomachComponent? stomach = null,
SolutionContainerManagerComponent? solutions = null)
{
if (!Resolve(uid, ref stomach, ref solutions, false))
return false;