Solution refactor (#4407)

* Rename SolutionContainerCaps -> Capability

* Move IExamine event to Chemistry System.

* ECS the ISolutionChange into SolutionChangeEvent

* Unify SolutionContainer into a single shared component

* Replace ISolutionInteraction with SolutionContainerComponent

* Move all methods from SolutionContainer to ChemistrySystem

* Refactor EntitySystem calls to Dependencies

* Refactor SolutionContainer to SolutionManager

* Fix yamls

* Fix test fails

* Fix post merge issues

* Fix various issues with SolutionManager

* More fixes

* Fix more components

* Fix events not being directed

* Fixes for Hypospray

* Separate removal and iteration on Metabolism

* Fix creampie problems

* Address some of sloth's issues

* Refactors for Systems

* Refactored solution location

* Fix tests

* Address more sloth issues

* Fix dependency

* Fix merge conflicts

* Add xmldocs for Capabilities components

* Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable

* Replace Grindable/Juiceable with Extractable

* Refactor field names

* Fix Drainable

* Fix some issues with spillable and injector

* Fix issues with Grinder

* Fix Beaker having duplicate solutions

* Fix foaming

* Address some MGS issues

* Fix Uid issues

* Fix errors in solution Tranfer

* Fixed some extra values constant values

* Cola is drinkable now
This commit is contained in:
Ygg01
2021-09-06 15:49:44 +02:00
committed by GitHub
parent b8911d58ac
commit c209e3f29b
166 changed files with 4268 additions and 3278 deletions

View File

@@ -1,20 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Body.Circulatory;
using Content.Server.Chemistry.Components;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Solution;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Body.Metabolism
{
// TODO mirror in the future working on mechanisms move updating here to BodySystem so it can be ordered?
[UsedImplicitly]
public class MetabolizerSystem : EntitySystem
{
[Dependency]
private readonly SolutionContainerSystem _solutionContainerSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MetabolizerComponent, ComponentInit>(OnMetabolizerInit);
}
private void OnMetabolizerInit(EntityUid uid, MetabolizerComponent component, ComponentInit args)
{
_solutionContainerSystem.EnsureSolution(EntityManager.GetEntity(uid), component.SolutionName);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -35,37 +51,34 @@ namespace Content.Server.Body.Metabolism
private void TryMetabolize(MetabolizerComponent comp)
{
var owner = comp.Owner;
var reagentList = new List<Solution.ReagentQuantity>();
SolutionContainerComponent? solution = null;
IReadOnlyList<Solution.ReagentQuantity> reagentList = new List<Solution.ReagentQuantity>();
Solution? solution = null;
SharedBodyComponent? body = null;
var solutionsSys = Get<SolutionContainerSystem>();
// if this field is passed we should try and take from the bloodstream over anything else
if (comp.TakeFromBloodstream && owner.TryGetComponent<SharedMechanismComponent>(out var mech))
if (owner.TryGetComponent<SharedMechanismComponent>(out var mech))
{
body = mech.Body;
if (body != null)
{
if (body.Owner.TryGetComponent<BloodstreamComponent>(out var bloodstream)
&& bloodstream.Solution.CurrentVolume >= ReagentUnit.Zero)
if (body.Owner.HasComponent<BloodstreamComponent>()
&& solutionsSys.TryGetSolution(body.Owner, comp.SolutionName, out solution)
&& solution.CurrentVolume >= ReagentUnit.Zero)
{
solution = bloodstream.Solution;
reagentList = bloodstream.Solution.ReagentList.ToList();
reagentList = solution.Contents;
}
}
}
else if (owner.TryGetComponent<SolutionContainerComponent>(out var sol))
{
// if we have no mechanism/body but a solution container instead,
// we'll just use that to metabolize from
solution = sol;
reagentList = sol.ReagentList.ToList();
}
if (solution == null || reagentList.Count == 0)
{
// We're all outta ideas on where to metabolize from
return;
}
List<Solution.ReagentQuantity> removeReagents = new(5);
// Run metabolism for each reagent, remove metabolized reagents
foreach (var reagent in reagentList)
{
@@ -100,8 +113,10 @@ namespace Content.Server.Body.Metabolism
effect.Metabolize(ent, reagent);
}
solution.TryRemoveReagent(reagent.ReagentId, metabolism.MetabolismRate);
removeReagents.Add(new Solution.ReagentQuantity(reagent.ReagentId, metabolism.MetabolismRate));
}
solutionsSys.TryRemoveAllReagents(solution, removeReagents);
}
}
}