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:
24
Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Normal file
24
Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ChemMasterSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ChemMasterComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, ChemMasterComponent component,
|
||||
SolutionChangedEvent solutionChanged)
|
||||
{
|
||||
component.UpdateUserInterface();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -8,9 +9,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
public class ChemicalReactionSystem : SharedChemicalReactionSystem
|
||||
{
|
||||
protected override void OnReaction(ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
|
||||
protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
|
||||
{
|
||||
base.OnReaction(reaction, owner, unitReactions);
|
||||
base.OnReaction(solution, reaction, owner, unitReactions);
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(owner), reaction.Sound.GetSound(), owner);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class HypospraySystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
@@ -13,6 +16,12 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
|
||||
SubscribeLocalEvent<HyposprayComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<HyposprayComponent, ClickAttackEvent>(OnClickAttack);
|
||||
SubscribeLocalEvent<HyposprayComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, HyposprayComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
component.Dirty();
|
||||
}
|
||||
|
||||
public void OnAfterInteract(EntityUid uid, HyposprayComponent comp, AfterInteractEvent args)
|
||||
|
||||
23
Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Normal file
23
Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class InjectorSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<InjectorComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, InjectorComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
component.Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ReagentDispenserSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, ReagentDispenserComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
component.UpdateUserInterface();
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs
Normal file
51
Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Notification;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class RehydratableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RehydratableComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, RehydratableComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
if (_solutionsSystem.GetReagentQuantity(uid, component.CatalystPrototype) > ReagentUnit.Zero)
|
||||
{
|
||||
Expand(component, component.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
// Try not to make this public if you can help it.
|
||||
private void Expand(RehydratableComponent component, IEntity owner)
|
||||
{
|
||||
if (component.Expanding)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.Expanding = true;
|
||||
owner.PopupMessageEveryone(Loc.GetString("rehydratable-component-expands-message", ("owner", owner)));
|
||||
if (!string.IsNullOrEmpty(component.TargetPrototype))
|
||||
{
|
||||
var ent = component.Owner.EntityManager.SpawnEntity(component.TargetPrototype,
|
||||
owner.Transform.Coordinates);
|
||||
ent.Transform.AttachToGridOrMap();
|
||||
}
|
||||
|
||||
owner.QueueDelete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
using Content.Server.Body.Circulatory;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
@@ -9,6 +12,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
[UsedImplicitly]
|
||||
internal sealed class SolutionInjectOnCollideSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -18,15 +22,15 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
|
||||
private void HandleInit(EntityUid uid, SolutionInjectOnCollideComponent component, ComponentInit args)
|
||||
{
|
||||
component.Owner.EnsureComponentWarn<SolutionContainerComponent>($"{nameof(SolutionInjectOnCollideComponent)} requires a SolutionContainer on {component.Owner}!");
|
||||
component.Owner
|
||||
.EnsureComponentWarn<SolutionContainerManagerComponent>($"{nameof(SolutionInjectOnCollideComponent)} requires a SolutionContainerManager on {component.Owner}!");
|
||||
}
|
||||
|
||||
private void HandleInjection(EntityUid uid, SolutionInjectOnCollideComponent component, StartCollideEvent args)
|
||||
{
|
||||
if (!args.OtherFixture.Body.Owner.TryGetComponent<BloodstreamComponent>(out var bloodstream) ||
|
||||
!ComponentManager.TryGetComponent(uid, out SolutionContainerComponent? solutionContainer)) return;
|
||||
!_solutionsSystem.TryGetInjectableSolution(component.Owner.Uid, out var solution)) return;
|
||||
|
||||
var solution = solutionContainer.Solution;
|
||||
var solRemoved = solution.SplitSolution(component.TransferAmount);
|
||||
var solRemovedVol = solRemoved.TotalVolume;
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class TransformableContainerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TransformableContainerComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, TransformableContainerComponent component,
|
||||
SolutionChangedEvent args)
|
||||
{
|
||||
if (!_solutionsSystem.TryGetFitsInDispenser(uid, out var solution))
|
||||
return;
|
||||
//Transform container into initial state when emptied
|
||||
if (component.CurrentReagent != null && solution.Contents.Count == 0)
|
||||
{
|
||||
CancelTransformation(component);
|
||||
}
|
||||
|
||||
//the biggest reagent in the solution decides the appearance
|
||||
var reagentId = solution.GetPrimaryReagentId();
|
||||
|
||||
//If biggest reagent didn't changed - don't change anything at all
|
||||
if (component.CurrentReagent != null && component.CurrentReagent.ID == reagentId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Only reagents with spritePath property can change appearance of transformable containers!
|
||||
if (!string.IsNullOrWhiteSpace(reagentId)
|
||||
&& _prototypeManager.TryIndex(reagentId, out ReagentPrototype? proto)
|
||||
&& !string.IsNullOrWhiteSpace(proto.SpriteReplacementPath))
|
||||
{
|
||||
var spriteSpec =
|
||||
new SpriteSpecifier.Rsi(
|
||||
new ResourcePath("Objects/Consumable/Drinks/" + proto.SpriteReplacementPath), "icon");
|
||||
var ownerEntity = EntityManager.GetEntity(uid);
|
||||
if (ownerEntity.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite?.LayerSetSprite(0, spriteSpec);
|
||||
}
|
||||
|
||||
ownerEntity.Name = proto.Name + " glass";
|
||||
ownerEntity.Description = proto.Description;
|
||||
component.CurrentReagent = proto;
|
||||
component.Transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelTransformation(TransformableContainerComponent component)
|
||||
{
|
||||
component.CurrentReagent = null;
|
||||
component.Transformed = false;
|
||||
|
||||
if (component.Owner.TryGetComponent(out SpriteComponent? sprite) &&
|
||||
component.InitialSprite != null)
|
||||
{
|
||||
sprite.LayerSetSprite(0, component.InitialSprite);
|
||||
}
|
||||
|
||||
component.Owner.Name = component.InitialName;
|
||||
component.Owner.Description = component.InitialDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user