Refactor Resolve and IEntity in SolutionContainerSystem (#5083)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables]
|
||||
private Solution BufferSolution => _bufferSolution ??= EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
|
||||
private Solution BufferSolution => _bufferSolution ??= EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, SolutionName);
|
||||
|
||||
private Solution? _bufferSolution;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Content.Server.Chemistry.Components
|
||||
BeakerContainer =
|
||||
ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-reagentContainerContainer");
|
||||
|
||||
_bufferSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
|
||||
_bufferSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, SolutionName);
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
@@ -181,7 +181,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker, fits.Solution, out var beakerSolution))
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
{
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), ReagentUnit.New(0),
|
||||
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer,
|
||||
@@ -230,7 +230,7 @@ namespace Content.Server.Chemistry.Components
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker, fits.Solution, out var beakerSolution))
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
return;
|
||||
|
||||
if (isBuffer)
|
||||
@@ -307,7 +307,7 @@ namespace Content.Server.Chemistry.Components
|
||||
var bottle = Owner.EntityManager.SpawnEntity("ChemistryEmptyBottle01", Owner.Transform.Coordinates);
|
||||
|
||||
var bufferSolution = BufferSolution.SplitSolution(actualVolume);
|
||||
var bottleSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(bottle, "drink");
|
||||
var bottleSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(bottle.Uid, "drink");
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(bottle.Uid, bottleSolution, bufferSolution);
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
var bufferSolution = BufferSolution.SplitSolution(actualVolume);
|
||||
|
||||
var pillSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(pill, "food");
|
||||
var pillSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(pill.Uid, "food");
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(pill.Uid, pillSolution, bufferSolution);
|
||||
|
||||
//Try to give them the bottle
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Chemistry.Components
|
||||
protected override void UpdateVisuals()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance) &&
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
appearance.SetData(FoamVisuals.Color, solution.Color.WithAlpha(0.80f));
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
protected override void ReactWithEntity(IEntity entity, double solutionFraction)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
return;
|
||||
|
||||
if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
solutionsSys.TryGetSolution(Owner, SolutionName, out var hypoSpraySolution);
|
||||
solutionsSys.TryGetSolution(Owner.Uid, SolutionName, out var hypoSpraySolution);
|
||||
|
||||
if (hypoSpraySolution == null || hypoSpraySolution.CurrentVolume == 0)
|
||||
{
|
||||
@@ -124,7 +124,7 @@ namespace Content.Server.Chemistry.Components
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
var solutionSys = Owner.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>();
|
||||
return solutionSys.TryGetSolution(Owner, SolutionName, out var solution)
|
||||
return solutionSys.TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? new HyposprayComponentState(solution.CurrentVolume, solution.MaxVolume)
|
||||
: new HyposprayComponentState(ReagentUnit.Zero, ReagentUnit.Zero);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
else if (ToggleState == InjectorToggleMode.Draw)
|
||||
{
|
||||
if (solutionsSys.TryGetDrawableSolution(targetEntity, out var drawableSolution))
|
||||
if (solutionsSys.TryGetDrawableSolution(targetEntity.Uid, out var drawableSolution))
|
||||
{
|
||||
TryDraw(targetEntity, drawableSolution, eventArgs.User);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private void TryInjectIntoBloodstream(BloodstreamComponent targetBloodstream, IEntity user)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(user, SharedBloodstreamComponent.DefaultSolutionName, out var bloodstream)
|
||||
.TryGetSolution(user.Uid, SharedBloodstreamComponent.DefaultSolutionName, out var bloodstream)
|
||||
|| bloodstream.CurrentVolume == 0)
|
||||
return;
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
private void TryInject(IEntity targetEntity, Solution targetSolution, IEntity user, bool asRefill)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
|| solution.CurrentVolume == 0)
|
||||
{
|
||||
return;
|
||||
@@ -259,7 +259,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private void AfterInject()
|
||||
{
|
||||
// Automatically set syringe to draw after completely draining it.
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
&& solution.CurrentVolume == 0)
|
||||
{
|
||||
ToggleState = InjectorToggleMode.Draw;
|
||||
@@ -269,7 +269,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private void AfterDraw()
|
||||
{
|
||||
// Automatically set syringe to inject after completely filling it.
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
&& solution.AvailableVolume == 0)
|
||||
{
|
||||
ToggleState = InjectorToggleMode.Inject;
|
||||
@@ -278,7 +278,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
private void TryDraw(IEntity targetEntity, Solution targetSolution, IEntity user)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
|| solution.AvailableVolume == 0)
|
||||
{
|
||||
return;
|
||||
@@ -315,7 +315,7 @@ namespace Content.Server.Chemistry.Components
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
Owner.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>()
|
||||
.TryGetSolution(Owner, SolutionName, out var solution);
|
||||
.TryGetSolution(Owner.Uid, SolutionName, out var solution);
|
||||
|
||||
var currentVolume = solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution);
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution);
|
||||
return solution;
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker, fits.Solution, out var solution))
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
{
|
||||
return new ReagentDispenserBoundUserInterfaceState(Powered, false, ReagentUnit.New(0),
|
||||
ReagentUnit.New(0),
|
||||
@@ -280,7 +280,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
if (!HasBeaker || !BeakerContainer.ContainedEntity!.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity, fits.Solution, out var solution))
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity.Uid, fits.Solution, out var solution))
|
||||
return;
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().RemoveAllSolution(BeakerContainer.ContainedEntity!.Uid, solution);
|
||||
@@ -298,7 +298,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
if (BeakerContainer.ContainedEntity is not {} contained || !contained.TryGetComponent(out FitsInDispenserComponent? fits)
|
||||
|| !EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity, fits.Solution, out var solution)) return;
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity.Uid, fits.Solution, out var solution)) return;
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryAddReagent(BeakerContainer.ContainedEntity.Uid, solution, Inventory[dispenseIndex].ID, _dispenseAmount, out _);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.Chemistry.Components
|
||||
protected override void UpdateVisuals()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance) &&
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
appearance.SetData(SmokeVisuals.Color, solution.Color);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
protected override void ReactWithEntity(IEntity entity, double solutionFraction)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
return;
|
||||
|
||||
if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Content.Server.Chemistry.Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
effectComponent.TryAddSolution(solution.Clone());
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace Content.Server.Chemistry.Components
|
||||
/// with the other area effects from the inception.</param>
|
||||
public void React(float averageExposures)
|
||||
{
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
return;
|
||||
|
||||
var chemistry = EntitySystem.Get<ChemistrySystem>();
|
||||
@@ -160,7 +160,7 @@ namespace Content.Server.Chemistry.Components
|
||||
if (solution.TotalVolume == 0)
|
||||
return;
|
||||
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solutionArea))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solutionArea))
|
||||
return;
|
||||
|
||||
var addSolution =
|
||||
|
||||
@@ -8,133 +8,124 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
public partial class SolutionContainerSystem
|
||||
{
|
||||
public void Refill(EntityUid targetUid, Solution targetSolution, Solution addedSolution)
|
||||
public void Refill(EntityUid targetUid, Solution targetSolution, Solution addedSolution,
|
||||
RefillableSolutionComponent? refillableSolution = null)
|
||||
{
|
||||
if (!EntityManager.HasComponent<RefillableSolutionComponent>(targetUid))
|
||||
if (!Resolve(targetUid, ref refillableSolution, false))
|
||||
return;
|
||||
|
||||
TryAddSolution(targetUid, targetSolution, addedSolution);
|
||||
}
|
||||
|
||||
public void Inject(EntityUid targetUid, Solution targetSolution, Solution addedSolution)
|
||||
public void Inject(EntityUid targetUid, Solution targetSolution, Solution addedSolution,
|
||||
InjectableSolutionComponent? injectableSolution = null)
|
||||
{
|
||||
if (!EntityManager.HasComponent<InjectableSolutionComponent>(targetUid))
|
||||
if (!Resolve(targetUid, ref injectableSolution, false))
|
||||
return;
|
||||
|
||||
TryAddSolution(targetUid, targetSolution, addedSolution);
|
||||
}
|
||||
|
||||
public Solution Draw(EntityUid targetUid, Solution solution, ReagentUnit amount)
|
||||
public Solution Draw(EntityUid targetUid, Solution solution, ReagentUnit amount,
|
||||
DrawableSolutionComponent? drawableSolution = null)
|
||||
{
|
||||
if (!EntityManager.HasComponent<DrawableSolutionComponent>(targetUid))
|
||||
{
|
||||
if (!Resolve(targetUid, ref drawableSolution, false))
|
||||
return new Solution();
|
||||
}
|
||||
|
||||
return SplitSolution(targetUid, solution, amount);
|
||||
}
|
||||
|
||||
public Solution Drain(EntityUid targetUid, Solution targetSolution, ReagentUnit amount)
|
||||
public Solution Drain(EntityUid targetUid, Solution targetSolution, ReagentUnit amount,
|
||||
DrainableSolutionComponent? drainableSolution = null)
|
||||
{
|
||||
if (!EntityManager.HasComponent<DrainableSolutionComponent>(targetUid))
|
||||
{
|
||||
if (!Resolve(targetUid, ref drainableSolution, false))
|
||||
return new Solution();
|
||||
}
|
||||
|
||||
return SplitSolution(targetUid, targetSolution, amount);
|
||||
}
|
||||
|
||||
public bool TryGetInjectableSolution(EntityUid targetUid,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
InjectableSolutionComponent? injectable = null,
|
||||
SolutionContainerManagerComponent? manager = null
|
||||
)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(targetUid, out InjectableSolutionComponent? injectable) &&
|
||||
EntityManager.TryGetComponent(targetUid, out SolutionContainerManagerComponent? manager) &&
|
||||
manager.Solutions.TryGetValue(injectable.Solution, out solution))
|
||||
if (!Resolve(targetUid, ref manager, ref injectable, false)
|
||||
|| !manager.Solutions.TryGetValue(injectable.Solution, out solution))
|
||||
{
|
||||
return true;
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
solution = null;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetRefillableSolution(EntityUid targetUid,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
SolutionContainerManagerComponent? solutionManager = null,
|
||||
RefillableSolutionComponent? refillable = null)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(targetUid, out RefillableSolutionComponent? refillable) &&
|
||||
EntityManager.TryGetComponent(targetUid, out SolutionContainerManagerComponent? manager) &&
|
||||
manager.Solutions.TryGetValue(refillable.Solution, out var refillableSolution))
|
||||
if (!Resolve(targetUid, ref solutionManager, ref refillable, false)
|
||||
|| !solutionManager.Solutions.TryGetValue(refillable.Solution, out var refillableSolution))
|
||||
{
|
||||
solution = refillableSolution;
|
||||
return true;
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
solution = null;
|
||||
return false;
|
||||
solution = refillableSolution;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetDrainableSolution(EntityUid targetUid,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
public bool TryGetDrainableSolution(EntityUid uid,
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
DrainableSolutionComponent? drainable = null,
|
||||
SolutionContainerManagerComponent? manager = null)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(targetUid,out DrainableSolutionComponent? drainable) &&
|
||||
EntityManager.TryGetComponent(targetUid,out SolutionContainerManagerComponent? manager) &&
|
||||
manager.Solutions.TryGetValue(drainable.Solution, out solution))
|
||||
if (!Resolve(uid, ref drainable, ref manager, false)
|
||||
|| !manager.Solutions.TryGetValue(drainable.Solution, out solution))
|
||||
{
|
||||
return true;
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
solution = null;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetDrawableSolution(IEntity owner,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
public bool TryGetDrawableSolution(EntityUid uid,
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
DrawableSolutionComponent? drawable = null,
|
||||
SolutionContainerManagerComponent? manager = null)
|
||||
{
|
||||
if (owner.TryGetComponent(out DrawableSolutionComponent? drawable) &&
|
||||
owner.TryGetComponent(out SolutionContainerManagerComponent? manager) &&
|
||||
manager.Solutions.TryGetValue(drawable.Solution, out solution))
|
||||
if (!Resolve(uid, ref drawable, ref manager, false)
|
||||
|| !manager.Solutions.TryGetValue(drawable.Solution, out solution))
|
||||
{
|
||||
return true;
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public ReagentUnit DrainAvailable(IEntity? owner)
|
||||
{
|
||||
if (owner == null || !TryGetDrainableSolution(owner.Uid, out var solution))
|
||||
return ReagentUnit.Zero;
|
||||
|
||||
return solution.CurrentVolume;
|
||||
return true;
|
||||
}
|
||||
|
||||
public ReagentUnit DrainAvailable(EntityUid uid)
|
||||
{
|
||||
if (!TryGetDrainableSolution(uid, out var solution))
|
||||
return ReagentUnit.Zero;
|
||||
|
||||
return solution.CurrentVolume;
|
||||
}
|
||||
|
||||
public bool HasFitsInDispenser(IEntity owner)
|
||||
{
|
||||
return !owner.Deleted && owner.HasComponent<FitsInDispenserComponent>();
|
||||
return !TryGetDrainableSolution(uid, out var solution)
|
||||
? ReagentUnit.Zero
|
||||
: solution.CurrentVolume;
|
||||
}
|
||||
|
||||
public bool TryGetFitsInDispenser(EntityUid owner,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
FitsInDispenserComponent? dispenserFits = null,
|
||||
SolutionContainerManagerComponent? solutionManager = null)
|
||||
{
|
||||
if (EntityManager.TryGetEntity(owner, out var ownerEntity) &&
|
||||
ownerEntity.TryGetComponent(out FitsInDispenserComponent? dispenserFits) &&
|
||||
ownerEntity.TryGetComponent(out SolutionContainerManagerComponent? manager) &&
|
||||
manager.Solutions.TryGetValue(dispenserFits.Solution, out solution))
|
||||
if (!Resolve(owner, ref dispenserFits, ref solutionManager, false)
|
||||
|| !solutionManager.Solutions.TryGetValue(dispenserFits.Solution, out solution))
|
||||
{
|
||||
return true;
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
solution = null;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
private void OnExamineSolution(EntityUid uid, ExaminableSolutionComponent examinableComponent,
|
||||
ExaminedEvent args)
|
||||
{
|
||||
if (!args.Examined.TryGetComponent(out SolutionContainerManagerComponent? solutionsManager)
|
||||
SolutionContainerManagerComponent? solutionsManager = null;
|
||||
if (!Resolve(args.Examined.Uid, ref solutionsManager)
|
||||
|| !solutionsManager.Solutions.TryGetValue(examinableComponent.Solution, out var solutionHolder))
|
||||
return;
|
||||
|
||||
@@ -96,15 +97,15 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
("desc", Loc.GetString(proto.PhysicalDescription))));
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, Solution solution)
|
||||
private void UpdateAppearance(EntityUid uid, Solution solution,
|
||||
SharedAppearanceComponent? appearanceComponent = null)
|
||||
{
|
||||
if (!EntityManager.TryGetEntity(uid, out var solutionEntity)
|
||||
|| solutionEntity.Deleted
|
||||
|| !solutionEntity.TryGetComponent<SharedAppearanceComponent>(out var appearance))
|
||||
if (!EntityManager.EntityExists(uid)
|
||||
|| !Resolve(uid, ref appearanceComponent, false))
|
||||
return;
|
||||
|
||||
var filledVolumeFraction = solution.CurrentVolume.Float() / solution.MaxVolume.Float();
|
||||
appearance.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumeFraction));
|
||||
appearanceComponent.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumeFraction));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,9 +144,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
UpdateChemicals(uid, solutionHolder);
|
||||
}
|
||||
|
||||
public void RemoveAllSolution(EntityUid uid)
|
||||
public void RemoveAllSolution(EntityUid uid, SolutionContainerManagerComponent? solutionContainerManager = null)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out SolutionContainerManagerComponent? solutionContainerManager))
|
||||
if (!Resolve(uid, ref solutionContainerManager))
|
||||
return;
|
||||
|
||||
foreach (var solution in solutionContainerManager.Solutions.Values)
|
||||
@@ -210,19 +211,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetSolution(IEntity? target, string name,
|
||||
[NotNullWhen(true)] out Solution? solution, SolutionContainerManagerComponent? solutionsMgr = null)
|
||||
{
|
||||
if (target == null || target.Deleted)
|
||||
{
|
||||
solution = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryGetSolution(target.Uid, name, out solution, solutionsMgr);
|
||||
}
|
||||
|
||||
public bool TryGetSolution(EntityUid uid, string name, [NotNullWhen(true)] out Solution? solution, SolutionContainerManagerComponent? solutionsMgr = null)
|
||||
public bool TryGetSolution(EntityUid uid, string name,
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
SolutionContainerManagerComponent? solutionsMgr = null)
|
||||
{
|
||||
if (!Resolve(uid, ref solutionsMgr))
|
||||
{
|
||||
@@ -233,17 +224,6 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return solutionsMgr.Solutions.TryGetValue(name, out solution);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will ensure a solution is added to given entity even if it's missing solutionContainerManager
|
||||
/// </summary>
|
||||
/// <param name="owner">Entity to which to add solution</param>
|
||||
/// <param name="name">name for the solution</param>
|
||||
/// <returns>solution</returns>
|
||||
public Solution EnsureSolution(IEntity owner, string name)
|
||||
{
|
||||
return EnsureSolution(owner.Uid, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will ensure a solution is added to given entity even if it's missing solutionContainerManager
|
||||
/// </summary>
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, SharedVaporComponent.SolutionName,
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner.Uid, SharedVaporComponent.SolutionName,
|
||||
out var vaporSolution))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
{
|
||||
// TODO see if this is correct
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(entity, _solution, out var solutionContainer)
|
||||
.TryGetSolution(entity.Uid, _solution, out var solutionContainer)
|
||||
|| (_reagents.Count > 0 && !_reagents.Contains(reagent.ID))) return;
|
||||
|
||||
if (EntitySystem.Get<SolutionContainerSystem>()
|
||||
|
||||
Reference in New Issue
Block a user