Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -45,11 +45,11 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ChemMasterComponent, ComponentStartup>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ChemMasterComponent, SolutionChangedEvent>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntInsertedIntoContainerMessage>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntRemovedFromContainerMessage>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ChemMasterComponent, BoundUIOpenedEvent>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ChemMasterComponent, ComponentStartup>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ChemMasterComponent, SolutionChangedEvent>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntInsertedIntoContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntRemovedFromContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ChemMasterComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);
|
||||
|
||||
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetModeMessage>(OnSetModeMessage);
|
||||
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetPillTypeMessage>(OnSetPillTypeMessage);
|
||||
@@ -58,12 +58,18 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
SubscribeLocalEvent<ChemMasterComponent, ChemMasterOutputToBottleMessage>(OnOutputToBottleMessage);
|
||||
}
|
||||
|
||||
private void UpdateUiState(ChemMasterComponent chemMaster, bool updateLabel = false)
|
||||
private void SubscribeUpdateUiState<T>(Entity<ChemMasterComponent> ent, ref T ev)
|
||||
{
|
||||
if (!_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
UpdateUiState(ent);
|
||||
}
|
||||
|
||||
private void UpdateUiState(Entity<ChemMasterComponent> ent, bool updateLabel = false)
|
||||
{
|
||||
var (owner, chemMaster) = ent;
|
||||
if (!_solutionContainerSystem.TryGetSolution(owner, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
return;
|
||||
var inputContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.InputSlotName);
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName);
|
||||
var inputContainer = _itemSlotsSystem.GetItemOrNull(owner, SharedChemMaster.InputSlotName);
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(owner, SharedChemMaster.OutputSlotName);
|
||||
|
||||
var bufferReagents = bufferSolution.Contents;
|
||||
var bufferCurrentVolume = bufferSolution.Volume;
|
||||
@@ -72,38 +78,38 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
chemMaster.Mode, BuildInputContainerInfo(inputContainer), BuildOutputContainerInfo(outputContainer),
|
||||
bufferReagents, bufferCurrentVolume, chemMaster.PillType, chemMaster.PillDosageLimit, updateLabel);
|
||||
|
||||
_userInterfaceSystem.TrySetUiState(chemMaster.Owner, ChemMasterUiKey.Key, state);
|
||||
_userInterfaceSystem.TrySetUiState(owner, ChemMasterUiKey.Key, state);
|
||||
}
|
||||
|
||||
private void OnSetModeMessage(EntityUid uid, ChemMasterComponent chemMaster, ChemMasterSetModeMessage message)
|
||||
private void OnSetModeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetModeMessage message)
|
||||
{
|
||||
// Ensure the mode is valid, either Transfer or Discard.
|
||||
if (!Enum.IsDefined(typeof(ChemMasterMode), message.ChemMasterMode))
|
||||
return;
|
||||
|
||||
chemMaster.Mode = message.ChemMasterMode;
|
||||
chemMaster.Comp.Mode = message.ChemMasterMode;
|
||||
UpdateUiState(chemMaster);
|
||||
ClickSound(chemMaster);
|
||||
}
|
||||
|
||||
private void OnSetPillTypeMessage(EntityUid uid, ChemMasterComponent chemMaster, ChemMasterSetPillTypeMessage message)
|
||||
private void OnSetPillTypeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetPillTypeMessage message)
|
||||
{
|
||||
// Ensure valid pill type. There are 20 pills selectable, 0-19.
|
||||
if (message.PillType > SharedChemMaster.PillTypes - 1)
|
||||
return;
|
||||
|
||||
chemMaster.PillType = message.PillType;
|
||||
chemMaster.Comp.PillType = message.PillType;
|
||||
UpdateUiState(chemMaster);
|
||||
ClickSound(chemMaster);
|
||||
}
|
||||
|
||||
private void OnReagentButtonMessage(EntityUid uid, ChemMasterComponent chemMaster, ChemMasterReagentAmountButtonMessage message)
|
||||
private void OnReagentButtonMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterReagentAmountButtonMessage message)
|
||||
{
|
||||
// Ensure the amount corresponds to one of the reagent amount buttons.
|
||||
if (!Enum.IsDefined(typeof(ChemMasterReagentAmount), message.Amount))
|
||||
return;
|
||||
|
||||
switch (chemMaster.Mode)
|
||||
switch (chemMaster.Comp.Mode)
|
||||
{
|
||||
case ChemMasterMode.Transfer:
|
||||
TransferReagents(chemMaster, message.ReagentId, message.Amount.GetFixedPoint(), message.FromBuffer);
|
||||
@@ -119,12 +125,12 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
ClickSound(chemMaster);
|
||||
}
|
||||
|
||||
private void TransferReagents(ChemMasterComponent chemMaster, ReagentId id, FixedPoint2 amount, bool fromBuffer)
|
||||
private void TransferReagents(Entity<ChemMasterComponent> chemMaster, ReagentId id, FixedPoint2 amount, bool fromBuffer)
|
||||
{
|
||||
var container = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.InputSlotName);
|
||||
var container = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.InputSlotName);
|
||||
if (container is null ||
|
||||
!_solutionContainerSystem.TryGetFitsInDispenser(container.Value, out var containerSolution) ||
|
||||
!_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
!_solutionContainerSystem.TryGetSolution(chemMaster, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -145,19 +151,18 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
UpdateUiState(chemMaster, updateLabel: true);
|
||||
}
|
||||
|
||||
private void DiscardReagents(ChemMasterComponent chemMaster, ReagentId id, FixedPoint2 amount, bool fromBuffer)
|
||||
private void DiscardReagents(Entity<ChemMasterComponent> chemMaster, ReagentId id, FixedPoint2 amount, bool fromBuffer)
|
||||
{
|
||||
|
||||
if (fromBuffer)
|
||||
{
|
||||
if (_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
if (_solutionContainerSystem.TryGetSolution(chemMaster, SharedChemMaster.BufferSolutionName, out var bufferSolution))
|
||||
bufferSolution.RemoveReagent(id, amount);
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var container = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.InputSlotName);
|
||||
var container = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.InputSlotName);
|
||||
if (container is not null &&
|
||||
_solutionContainerSystem.TryGetFitsInDispenser(container.Value, out var containerSolution))
|
||||
{
|
||||
@@ -170,10 +175,10 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
UpdateUiState(chemMaster, updateLabel: fromBuffer);
|
||||
}
|
||||
|
||||
private void OnCreatePillsMessage(EntityUid uid, ChemMasterComponent chemMaster, ChemMasterCreatePillsMessage message)
|
||||
private void OnCreatePillsMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterCreatePillsMessage message)
|
||||
{
|
||||
var user = message.Session.AttachedEntity;
|
||||
var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName);
|
||||
var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.OutputSlotName);
|
||||
if (maybeContainer is not { Valid: true } container
|
||||
|| !TryComp(container, out StorageComponent? storage)
|
||||
|| storage.Container is null)
|
||||
@@ -186,7 +191,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return;
|
||||
|
||||
// Ensure the amount is valid.
|
||||
if (message.Dosage == 0 || message.Dosage > chemMaster.PillDosageLimit)
|
||||
if (message.Dosage == 0 || message.Dosage > chemMaster.Comp.PillDosageLimit)
|
||||
return;
|
||||
|
||||
// Ensure label length is within the character limit.
|
||||
@@ -211,8 +216,8 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
item, itemSolution, withdrawal.SplitSolution(message.Dosage));
|
||||
|
||||
var pill = EnsureComp<PillComponent>(item);
|
||||
pill.PillType = chemMaster.PillType;
|
||||
Dirty(pill);
|
||||
pill.PillType = chemMaster.Comp.PillType;
|
||||
Dirty(item, pill);
|
||||
|
||||
if (user.HasValue)
|
||||
{
|
||||
@@ -232,11 +237,10 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
ClickSound(chemMaster);
|
||||
}
|
||||
|
||||
private void OnOutputToBottleMessage(
|
||||
EntityUid uid, ChemMasterComponent chemMaster, ChemMasterOutputToBottleMessage message)
|
||||
private void OnOutputToBottleMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterOutputToBottleMessage message)
|
||||
{
|
||||
var user = message.Session.AttachedEntity;
|
||||
var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName);
|
||||
var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.OutputSlotName);
|
||||
if (maybeContainer is not { Valid: true } container
|
||||
|| !_solutionContainerSystem.TryGetSolution(
|
||||
container, SharedChemMaster.BottleSolutionName, out var solution))
|
||||
@@ -277,14 +281,14 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
|
||||
private bool WithdrawFromBuffer(
|
||||
IComponent chemMaster,
|
||||
Entity<ChemMasterComponent> chemMaster,
|
||||
FixedPoint2 neededVolume, EntityUid? user,
|
||||
[NotNullWhen(returnValue: true)] out Solution? outputSolution)
|
||||
{
|
||||
outputSolution = null;
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(
|
||||
chemMaster.Owner, SharedChemMaster.BufferSolutionName, out var solution))
|
||||
chemMaster, SharedChemMaster.BufferSolutionName, out var solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -308,9 +312,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ClickSound(ChemMasterComponent chemMaster)
|
||||
private void ClickSound(Entity<ChemMasterComponent> chemMaster)
|
||||
{
|
||||
_audioSystem.PlayPvs(chemMaster.ClickSound, chemMaster.Owner, AudioParams.Default.WithVolume(-2f));
|
||||
_audioSystem.PlayPvs(chemMaster.Comp.ClickSound, chemMaster, AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
|
||||
private ContainerInfo? BuildInputContainerInfo(EntityUid? container)
|
||||
|
||||
@@ -34,11 +34,11 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ComponentStartup>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, SolutionChangedEvent>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, BoundUIOpenedEvent>((_, comp, _) => UpdateUiState(comp));
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ComponentStartup>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, SolutionChangedEvent>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, GotEmaggedEvent>(OnEmagged);
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserSetDispenseAmountMessage>(OnSetDispenseAmountMessage);
|
||||
@@ -46,15 +46,20 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserClearContainerSolutionMessage>(OnClearContainerSolutionMessage);
|
||||
}
|
||||
|
||||
private void UpdateUiState(ReagentDispenserComponent reagentDispenser)
|
||||
private void SubscribeUpdateUiState<T>(Entity<ReagentDispenserComponent> ent, ref T ev)
|
||||
{
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser.Owner, SharedReagentDispenser.OutputSlotName);
|
||||
UpdateUiState(ent);
|
||||
}
|
||||
|
||||
private void UpdateUiState(Entity<ReagentDispenserComponent> reagentDispenser)
|
||||
{
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, SharedReagentDispenser.OutputSlotName);
|
||||
var outputContainerInfo = BuildOutputContainerInfo(outputContainer);
|
||||
|
||||
var inventory = GetInventory(reagentDispenser);
|
||||
|
||||
var state = new ReagentDispenserBoundUserInterfaceState(outputContainerInfo, inventory, reagentDispenser.DispenseAmount);
|
||||
_userInterfaceSystem.TrySetUiState(reagentDispenser.Owner, ReagentDispenserUiKey.Key, state);
|
||||
var state = new ReagentDispenserBoundUserInterfaceState(outputContainerInfo, inventory, reagentDispenser.Comp.DispenseAmount);
|
||||
_userInterfaceSystem.TrySetUiState(reagentDispenser, ReagentDispenserUiKey.Key, state);
|
||||
}
|
||||
|
||||
private ContainerInfo? BuildOutputContainerInfo(EntityUid? container)
|
||||
@@ -73,8 +78,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ReagentId> GetInventory(ReagentDispenserComponent reagentDispenser)
|
||||
private List<ReagentId> GetInventory(Entity<ReagentDispenserComponent> ent)
|
||||
{
|
||||
var reagentDispenser = ent.Comp;
|
||||
var inventory = new List<ReagentId>();
|
||||
|
||||
if (reagentDispenser.PackPrototypeId is not null
|
||||
@@ -83,7 +89,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
inventory.AddRange(packPrototype.Inventory.Select(x => new ReagentId(x, null)));
|
||||
}
|
||||
|
||||
if (HasComp<EmaggedComponent>(reagentDispenser.Owner)
|
||||
if (HasComp<EmaggedComponent>(ent)
|
||||
&& reagentDispenser.EmagPackPrototypeId is not null
|
||||
&& _prototypeManager.TryIndex(reagentDispenser.EmagPackPrototypeId, out ReagentDispenserInventoryPrototype? emagPackPrototype))
|
||||
{
|
||||
@@ -93,32 +99,32 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return inventory;
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, ReagentDispenserComponent reagentDispenser, ref GotEmaggedEvent args)
|
||||
private void OnEmagged(Entity<ReagentDispenserComponent> reagentDispenser, ref GotEmaggedEvent args)
|
||||
{
|
||||
// adding component manually to have correct state
|
||||
EntityManager.AddComponent<EmaggedComponent>(uid);
|
||||
EntityManager.AddComponent<EmaggedComponent>(reagentDispenser);
|
||||
UpdateUiState(reagentDispenser);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSetDispenseAmountMessage(EntityUid uid, ReagentDispenserComponent reagentDispenser, ReagentDispenserSetDispenseAmountMessage message)
|
||||
private void OnSetDispenseAmountMessage(Entity<ReagentDispenserComponent> reagentDispenser, ref ReagentDispenserSetDispenseAmountMessage message)
|
||||
{
|
||||
reagentDispenser.DispenseAmount = message.ReagentDispenserDispenseAmount;
|
||||
reagentDispenser.Comp.DispenseAmount = message.ReagentDispenserDispenseAmount;
|
||||
UpdateUiState(reagentDispenser);
|
||||
ClickSound(reagentDispenser);
|
||||
}
|
||||
|
||||
private void OnDispenseReagentMessage(EntityUid uid, ReagentDispenserComponent reagentDispenser, ReagentDispenserDispenseReagentMessage message)
|
||||
private void OnDispenseReagentMessage(Entity<ReagentDispenserComponent> reagentDispenser, ref ReagentDispenserDispenseReagentMessage message)
|
||||
{
|
||||
// Ensure that the reagent is something this reagent dispenser can dispense.
|
||||
if (!GetInventory(reagentDispenser).Contains(message.ReagentId))
|
||||
return;
|
||||
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser.Owner, SharedReagentDispenser.OutputSlotName);
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, SharedReagentDispenser.OutputSlotName);
|
||||
if (outputContainer is not {Valid: true} || !_solutionContainerSystem.TryGetFitsInDispenser(outputContainer.Value, out var solution))
|
||||
return;
|
||||
|
||||
if (_solutionContainerSystem.TryAddReagent(outputContainer.Value, solution, message.ReagentId, (int)reagentDispenser.DispenseAmount, out var dispensedAmount)
|
||||
if (_solutionContainerSystem.TryAddReagent(outputContainer.Value, solution, message.ReagentId, (int)reagentDispenser.Comp.DispenseAmount, out var dispensedAmount)
|
||||
&& message.Session.AttachedEntity is not null)
|
||||
{
|
||||
_adminLogger.Add(LogType.ChemicalReaction, LogImpact.Medium,
|
||||
@@ -129,9 +135,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
ClickSound(reagentDispenser);
|
||||
}
|
||||
|
||||
private void OnClearContainerSolutionMessage(EntityUid uid, ReagentDispenserComponent reagentDispenser, ReagentDispenserClearContainerSolutionMessage message)
|
||||
private void OnClearContainerSolutionMessage(Entity<ReagentDispenserComponent> reagentDispenser, ref ReagentDispenserClearContainerSolutionMessage message)
|
||||
{
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser.Owner, SharedReagentDispenser.OutputSlotName);
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, SharedReagentDispenser.OutputSlotName);
|
||||
if (outputContainer is not {Valid: true} || !_solutionContainerSystem.TryGetFitsInDispenser(outputContainer.Value, out var solution))
|
||||
return;
|
||||
|
||||
@@ -140,9 +146,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
ClickSound(reagentDispenser);
|
||||
}
|
||||
|
||||
private void ClickSound(ReagentDispenserComponent reagentDispenser)
|
||||
private void ClickSound(Entity<ReagentDispenserComponent> reagentDispenser)
|
||||
{
|
||||
_audioSystem.PlayPvs(reagentDispenser.ClickSound, reagentDispenser.Owner, AudioParams.Default.WithVolume(-2f));
|
||||
_audioSystem.PlayPvs(reagentDispenser.Comp.ClickSound, reagentDispenser, AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Inventory;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
@@ -26,13 +23,17 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
|
||||
}
|
||||
|
||||
private void HandleInjection(EntityUid uid, SolutionInjectOnCollideComponent component, ref StartCollideEvent args)
|
||||
private void HandleInjection(Entity<SolutionInjectOnCollideComponent> ent, ref StartCollideEvent args)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
var target = args.OtherEntity;
|
||||
|
||||
if (!args.OtherBody.Hard ||
|
||||
!EntityManager.TryGetComponent<BloodstreamComponent>(target, out var bloodstream) ||
|
||||
!_solutionsSystem.TryGetInjectableSolution(component.Owner, out var solution)) return;
|
||||
!_solutionsSystem.TryGetInjectableSolution(ent, out var solution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.BlockSlots != 0x0 && TryComp<InventoryComponent>(target, out var inventory))
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Spawners;
|
||||
using Content.Shared.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
@@ -16,7 +15,7 @@ using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
|
||||
using Robust.Shared.Spawners;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
@@ -57,19 +56,19 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(VaporComponent vapor, TransformComponent vaporXform, Vector2 dir, float speed, MapCoordinates target, float aliveTime, EntityUid? user = null)
|
||||
public void Start(Entity<VaporComponent> vapor, TransformComponent vaporXform, Vector2 dir, float speed, MapCoordinates target, float aliveTime, EntityUid? user = null)
|
||||
{
|
||||
vapor.Active = true;
|
||||
var despawn = EnsureComp<TimedDespawnComponent>(vapor.Owner);
|
||||
vapor.Comp.Active = true;
|
||||
var despawn = EnsureComp<TimedDespawnComponent>(vapor);
|
||||
despawn.Lifetime = aliveTime;
|
||||
|
||||
// Set Move
|
||||
if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
|
||||
if (EntityManager.TryGetComponent(vapor, out PhysicsComponent? physics))
|
||||
{
|
||||
_physics.SetLinearDamping(physics, 0f);
|
||||
_physics.SetAngularDamping(physics, 0f);
|
||||
|
||||
_throwing.TryThrow(vapor.Owner, dir, speed, user: user);
|
||||
_throwing.TryThrow(vapor, dir, speed, user: user);
|
||||
|
||||
var distance = (target.Position - vaporXform.WorldPosition).Length();
|
||||
var time = (distance / physics.LinearVelocity.Length());
|
||||
@@ -77,41 +76,40 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
internal bool TryAddSolution(VaporComponent vapor, Solution solution)
|
||||
internal bool TryAddSolution(Entity<VaporComponent> vapor, Solution solution)
|
||||
{
|
||||
if (solution.Volume == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, VaporComponent.SolutionName,
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor, VaporComponent.SolutionName,
|
||||
out var vaporSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _solutionContainerSystem.TryAddSolution(vapor.Owner, vaporSolution, solution);
|
||||
return _solutionContainerSystem.TryAddSolution(vapor, vaporSolution, solution);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var (vaporComp, solution, xform) in EntityManager
|
||||
.EntityQuery<VaporComponent, SolutionContainerManagerComponent, TransformComponent>())
|
||||
var query = EntityQueryEnumerator<VaporComponent, SolutionContainerManagerComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out var vaporComp, out var solution, out var xform))
|
||||
{
|
||||
foreach (var (_, value) in solution.Solutions)
|
||||
{
|
||||
Update(frameTime, vaporComp, value, xform);
|
||||
Update(frameTime, (uid, vaporComp), value, xform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(float frameTime, VaporComponent vapor, Solution contents, TransformComponent xform)
|
||||
private void Update(float frameTime, Entity<VaporComponent> ent, Solution contents, TransformComponent xform)
|
||||
{
|
||||
var (entity, vapor) = ent;
|
||||
if (!vapor.Active)
|
||||
return;
|
||||
|
||||
var entity = vapor.Owner;
|
||||
|
||||
vapor.ReactTimer += frameTime;
|
||||
|
||||
if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out MapGridComponent? gridComp))
|
||||
@@ -133,7 +131,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
reaction = reagentQuantity.Quantity;
|
||||
}
|
||||
|
||||
_solutionContainerSystem.RemoveReagent(vapor.Owner, contents, reagentQuantity.Reagent, reaction);
|
||||
_solutionContainerSystem.RemoveReagent(entity, contents, reagentQuantity.Reagent, reaction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user