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,8 +1,10 @@
using System.Linq;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Solution;
using Content.Shared.Physics;
using Content.Shared.Vapor;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -18,6 +20,7 @@ namespace Content.Server.Chemistry.EntitySystems
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
private const float ReactTime = 0.125f;
@@ -29,14 +32,17 @@ namespace Content.Server.Chemistry.EntitySystems
private void HandleCollide(EntityUid uid, VaporComponent component, StartCollideEvent args)
{
if (!ComponentManager.TryGetComponent(uid, out SolutionContainerComponent? contents)) return;
if (!ComponentManager.TryGetComponent(uid, out SolutionContainerManagerComponent? contents)) return;
contents.Solution.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch);
foreach (var (_, value) in contents.Solutions)
{
value.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch);
}
// Check for collision with a impassable object (e.g. wall) and stop
if ((args.OtherFixture.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && args.OtherFixture.Hard)
{
EntityManager.QueueDeleteEntity(uid);
EntityManager.QueueDeleteEntity(uid);
}
}
@@ -60,14 +66,7 @@ namespace Content.Server.Chemistry.EntitySystems
return false;
}
if (!vapor.Owner.TryGetComponent(out SolutionContainerComponent? contents))
{
return false;
}
var result = contents.TryAddSolution(solution);
if (!result)
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, SharedVaporComponent.SolutionName, out _))
{
return false;
}
@@ -77,13 +76,17 @@ namespace Content.Server.Chemistry.EntitySystems
public override void Update(float frameTime)
{
foreach (var (vaporComp, solution) in ComponentManager.EntityQuery<VaporComponent, SolutionContainerComponent>(true))
foreach (var (vaporComp, solution) in ComponentManager
.EntityQuery<VaporComponent, SolutionContainerManagerComponent>(true))
{
Update(frameTime, vaporComp, solution);
foreach (var (_, value) in solution.Solutions)
{
Update(frameTime, vaporComp, value);
}
}
}
private void Update(float frameTime, VaporComponent vapor, SolutionContainerComponent contents)
private void Update(float frameTime, VaporComponent vapor, Solution contents)
{
if (!vapor.Active)
return;
@@ -99,16 +102,19 @@ namespace Content.Server.Chemistry.EntitySystems
var mapGrid = _mapManager.GetGrid(entity.Transform.GridID);
var tile = mapGrid.GetTileRef(entity.Transform.Coordinates.ToVector2i(EntityManager, _mapManager));
foreach (var reagentQuantity in contents.ReagentList.ToArray())
foreach (var reagentQuantity in contents.Contents.ToArray())
{
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
var reagent = _protoManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
_solutionContainerSystem.TryRemoveReagent(vapor.Owner.Uid, contents, reagentQuantity.ReagentId,
reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
}
}
// Check if we've reached our target.
if(!vapor.Reached && vapor.Target.TryDistance(EntityManager, entity.Transform.Coordinates, out var distance) && distance <= 0.5f)
if (!vapor.Reached &&
vapor.Target.TryDistance(EntityManager, entity.Transform.Coordinates, out var distance) &&
distance <= 0.5f)
{
vapor.Reached = true;
}