* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
184 lines
6.3 KiB
C#
184 lines
6.3 KiB
C#
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.Chemistry.Reaction;
|
|
using Content.Shared.FixedPoint;
|
|
using Robust.Shared.Utility;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text;
|
|
|
|
namespace Content.Shared.Chemistry.EntitySystems;
|
|
|
|
public abstract partial class SharedSolutionContainerSystem
|
|
{
|
|
#region Solution Accessors
|
|
|
|
public bool TryGetRefillableSolution(Entity<RefillableSolutionComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetDrainableSolution(Entity<DrainableSolutionComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetDumpableSolution(Entity<DumpableSolutionComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetDrawableSolution(Entity<DrawableSolutionComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetInjectableSolution(Entity<InjectableSolutionComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetFitsInDispenser(Entity<FitsInDispenserComponent?, SolutionContainerManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
|
|
{
|
|
(soln, solution) = (default!, null);
|
|
return false;
|
|
}
|
|
|
|
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
|
|
}
|
|
|
|
public bool TryGetMixableSolution(Entity<SolutionContainerManagerComponent?> container, [NotNullWhen(true)] out Entity<SolutionComponent>? solution)
|
|
{
|
|
var getMixableSolutionAttempt = new GetMixableSolutionAttemptEvent(container);
|
|
RaiseLocalEvent(container, ref getMixableSolutionAttempt);
|
|
if (getMixableSolutionAttempt.MixedSolution != null)
|
|
{
|
|
solution = getMixableSolutionAttempt.MixedSolution;
|
|
return true;
|
|
}
|
|
|
|
if (!Resolve(container, ref container.Comp, false))
|
|
{
|
|
solution = default!;
|
|
return false;
|
|
}
|
|
|
|
var tryGetSolution = EnumerateSolutions(container).FirstOrNull(x => x.Solution.Comp.Solution.CanMix);
|
|
if (tryGetSolution.HasValue)
|
|
{
|
|
solution = tryGetSolution.Value.Solution;
|
|
return true;
|
|
}
|
|
|
|
solution = default!;
|
|
return false;
|
|
}
|
|
|
|
#endregion Solution Accessors
|
|
|
|
#region Solution Modifiers
|
|
|
|
public void Refill(Entity<RefillableSolutionComponent?> entity, Entity<SolutionComponent> soln, Solution refill)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, logMissing: false))
|
|
return;
|
|
|
|
AddSolution(soln, refill);
|
|
}
|
|
|
|
public void Inject(Entity<InjectableSolutionComponent?> entity, Entity<SolutionComponent> soln, Solution inject)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, logMissing: false))
|
|
return;
|
|
|
|
AddSolution(soln, inject);
|
|
}
|
|
|
|
public Solution Drain(Entity<DrainableSolutionComponent?> entity, Entity<SolutionComponent> soln, FixedPoint2 quantity)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, logMissing: false))
|
|
return new();
|
|
|
|
return SplitSolution(soln, quantity);
|
|
}
|
|
|
|
public Solution Draw(Entity<DrawableSolutionComponent?> entity, Entity<SolutionComponent> soln, FixedPoint2 quantity)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, logMissing: false))
|
|
return new();
|
|
|
|
return SplitSolution(soln, quantity);
|
|
}
|
|
|
|
#endregion Solution Modifiers
|
|
|
|
public float PercentFull(EntityUid uid)
|
|
{
|
|
if (!TryGetDrainableSolution(uid, out _, out var solution) || solution.MaxVolume.Equals(FixedPoint2.Zero))
|
|
return 0;
|
|
|
|
return solution.FillFraction * 100;
|
|
}
|
|
|
|
#region Static Methods
|
|
|
|
public static string ToPrettyString(Solution solution)
|
|
{
|
|
var sb = new StringBuilder();
|
|
if (solution.Name == null)
|
|
sb.Append("[");
|
|
else
|
|
sb.Append($"{solution.Name}:[");
|
|
var first = true;
|
|
foreach (var (id, quantity) in solution.Contents)
|
|
{
|
|
if (first)
|
|
{
|
|
first = false;
|
|
}
|
|
else
|
|
{
|
|
sb.Append(", ");
|
|
}
|
|
|
|
sb.AppendFormat("{0}: {1}u", id, quantity);
|
|
}
|
|
|
|
sb.Append(']');
|
|
return sb.ToString();
|
|
}
|
|
|
|
#endregion Static Methods
|
|
}
|