DrinkSystem uses EntityUid instead of IEntity

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 11:28:27 +01:00
parent 0220551f72
commit 1a177f7479
12 changed files with 71 additions and 32 deletions

View File

@@ -106,7 +106,7 @@ namespace Content.Server.Chemistry.Components
return true; return true;
} }
removedSolution.DoEntityReaction(target, ReactionMethod.Injection); removedSolution.DoEntityReaction(target.Uid, ReactionMethod.Injection);
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(target.Uid, targetSolution, removedSolution); EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(target.Uid, targetSolution, removedSolution);

View File

@@ -201,11 +201,11 @@ namespace Content.Server.Chemistry.Components
// TODO: Account for partial transfer. // TODO: Account for partial transfer.
var bloodsStreamEntity = Owner.EntityManager.GetEntity(user.Uid); var bloodsStreamEntity = Owner.EntityManager.GetEntity(user.Uid);
removedSolution.DoEntityReaction(bloodsStreamEntity, ReactionMethod.Injection); removedSolution.DoEntityReaction(bloodsStreamEntity.Uid, ReactionMethod.Injection);
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(user.Uid, bloodstream, removedSolution); EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(user.Uid, bloodstream, removedSolution);
removedSolution.DoEntityReaction(targetBloodstream.Owner, ReactionMethod.Injection); removedSolution.DoEntityReaction(targetBloodstream.Owner.Uid, ReactionMethod.Injection);
Owner.PopupMessage(user, Owner.PopupMessage(user,
Loc.GetString("injector-component-inject-success-message", Loc.GetString("injector-component-inject-success-message",
@@ -236,7 +236,7 @@ namespace Content.Server.Chemistry.Components
// Move units from attackSolution to targetSolution // Move units from attackSolution to targetSolution
var removedSolution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, solution, realTransferAmount); var removedSolution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, solution, realTransferAmount);
removedSolution.DoEntityReaction(targetEntity, ReactionMethod.Injection); removedSolution.DoEntityReaction(targetEntity.Uid, ReactionMethod.Injection);
if (!asRefill) if (!asRefill)
{ {

View File

@@ -46,7 +46,7 @@ namespace Content.Server.Chemistry.Components
foreach (var reagentQuantity in transferSolution.Contents.ToArray()) foreach (var reagentQuantity in transferSolution.Contents.ToArray())
{ {
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue; if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
chemistry.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution); chemistry.ReactionEntity(entity.Uid, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution);
} }
bloodstream.TryTransferSolution(transferSolution); bloodstream.TryTransferSolution(transferSolution);

View File

@@ -143,7 +143,7 @@ namespace Content.Server.Chemistry.Components
// Touch every entity on the tile // Touch every entity on the tile
foreach (var entity in tile.GetEntitiesInTileFast().ToArray()) foreach (var entity in tile.GetEntitiesInTileFast().ToArray())
{ {
chemistry.ReactionEntity(entity, ReactionMethod.Touch, reagent, chemistry.ReactionEntity(entity.Uid, ReactionMethod.Touch, reagent,
reagentQuantity.Quantity * solutionFraction, solution); reagentQuantity.Quantity * solutionFraction, solution);
} }
} }

View File

@@ -36,7 +36,7 @@ namespace Content.Server.Chemistry.EntitySystems
foreach (var (_, value) in contents.Solutions) foreach (var (_, value) in contents.Solutions)
{ {
value.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch); value.DoEntityReaction(args.OtherFixture.Body.Owner.Uid, ReactionMethod.Touch);
} }
// Check for collision with a impassable object (e.g. wall) and stop // Check for collision with a impassable object (e.g. wall) and stop

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Map;
namespace Content.Server.Fluids.Components namespace Content.Server.Fluids.Components
{ {
// TODO: Kill these with fire
public static class SpillExtensions public static class SpillExtensions
{ {
/// <summary> /// <summary>
@@ -31,6 +32,25 @@ namespace Content.Server.Fluids.Components
return solution.SpillAt(entity.Transform.Coordinates, prototype, sound); return solution.SpillAt(entity.Transform.Coordinates, prototype, sound);
} }
/// <summary>
/// Spills the specified solution at the entity's location if possible.
/// </summary>
/// <param name="entity">
/// The entity to use as a location to spill the solution at.
/// </param>
/// <param name="solution">Initial solution for the prototype.</param>
/// <param name="prototype">The prototype to use.</param>
/// <param name="sound">Play the spill sound.</param>
/// <param name="entityManager"></param>
/// <returns>The puddle if one was created, null otherwise.</returns>
public static PuddleComponent? SpillAt(this Solution solution, EntityUid entity, string prototype,
bool sound = true, IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
return solution.SpillAt(entityManager.GetComponent<TransformComponent>(entity).Coordinates, prototype, sound);
}
/// <summary> /// <summary>
/// Spills the specified solution at the entity's location if possible. /// Spills the specified solution at the entity's location if possible.
/// </summary> /// </summary>

View File

@@ -176,7 +176,7 @@ namespace Content.Server.Nutrition.Components
// TODO: Account for partial transfer. // TODO: Account for partial transfer.
split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion); split.DoEntityReaction(trueTarget.Uid, ReactionMethod.Ingestion);
firstStomach.TryTransferSolution(split); firstStomach.TryTransferSolution(split);

View File

@@ -4,6 +4,7 @@ using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Fluids.Components; using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Body.Components; using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Reagent; using Content.Shared.Chemistry.Reagent;
using Content.Shared.Examine; using Content.Shared.Examine;
@@ -29,6 +30,7 @@ namespace Content.Server.Nutrition.EntitySystems
{ {
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -104,7 +106,7 @@ namespace Content.Server.Nutrition.EntitySystems
if (args.Target == null) if (args.Target == null)
return; return;
if (TryUseDrink(uid, args.User, args.Target, true, component)) if (TryUseDrink(uid, args.User.Uid, args.Target.Uid, true, component))
args.Handled = true; args.Handled = true;
} }
@@ -126,7 +128,7 @@ namespace Content.Server.Nutrition.EntitySystems
return; return;
} }
if (TryUseDrink(uid, args.User, args.User, false, component)) if (TryUseDrink(uid, args.User.Uid, args.User.Uid, false, component))
args.Handled = true; args.Handled = true;
} }
@@ -184,7 +186,7 @@ namespace Content.Server.Nutrition.EntitySystems
appearance.SetData(DrinkCanStateVisual.Opened, component.Opened); appearance.SetData(DrinkCanStateVisual.Opened, component.Opened);
} }
private bool TryUseDrink(EntityUid uid, IEntity user, IEntity target, bool forced, DrinkComponent? component = null) private bool TryUseDrink(EntityUid uid, EntityUid userUid, EntityUid targetUid, bool forced, DrinkComponent? component = null)
{ {
if(!Resolve(uid, ref component)) if(!Resolve(uid, ref component))
return false; return false;
@@ -193,7 +195,7 @@ namespace Content.Server.Nutrition.EntitySystems
if (!component.Opened) if (!component.Opened)
{ {
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-not-open", ("owner", owner))); _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open", ("owner", owner)), targetUid, Filter.Entities(userUid));
return false; return false;
} }
@@ -202,20 +204,20 @@ namespace Content.Server.Nutrition.EntitySystems
{ {
if (!forced) if (!forced)
{ {
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-is-empty", ("entity", owner))); _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty", ("entity", owner)), targetUid, Filter.Entities(userUid));
} }
return false; return false;
} }
if (!EntityManager.TryGetComponent(target.Uid, out SharedBodyComponent? body) || if (!EntityManager.TryGetComponent(targetUid, out SharedBodyComponent? body) ||
!body.TryGetMechanismBehaviors<StomachBehavior>(out var stomachs)) !body.TryGetMechanismBehaviors<StomachBehavior>(out var stomachs))
{ {
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-cannot-drink", ("owner", owner))); _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-cannot-drink", ("owner", owner)), targetUid, Filter.Entities(targetUid));
return false; return false;
} }
if (user != target && !user.InRangeUnobstructed(target, popup: true)) if (userUid != targetUid && !userUid.InRangeUnobstructed(targetUid, popup: true))
return false; return false;
var transferAmount = FixedPoint2.Min(component.TransferAmount, interactions.DrainAvailable); var transferAmount = FixedPoint2.Min(component.TransferAmount, interactions.DrainAvailable);
@@ -225,11 +227,11 @@ namespace Content.Server.Nutrition.EntitySystems
// All stomach are full or can't handle whatever solution we have. // All stomach are full or can't handle whatever solution we have.
if (firstStomach == null) if (firstStomach == null)
{ {
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-had-enough", ("owner", owner))); _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough", ("owner", owner)), targetUid, Filter.Entities(targetUid));
if (EntityManager.HasComponent<RefillableSolutionComponent>(uid)) if (EntityManager.HasComponent<RefillableSolutionComponent>(uid))
{ {
drain.SpillAt(target, "PuddleSmear"); drain.SpillAt(targetUid, "PuddleSmear");
return false; return false;
} }
@@ -237,13 +239,13 @@ namespace Content.Server.Nutrition.EntitySystems
return false; return false;
} }
SoundSystem.Play(Filter.Pvs(target), component.UseSound.GetSound(), target, AudioParams.Default.WithVolume(-2f)); SoundSystem.Play(Filter.Pvs(targetUid), component.UseSound.GetSound(), targetUid, AudioParams.Default.WithVolume(-2f));
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-success-slurp")); _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-success-slurp"), targetUid, Filter.Pvs(targetUid));
// TODO: Account for partial transfer. // TODO: Account for partial transfer.
drain.DoEntityReaction(target, ReactionMethod.Ingestion); drain.DoEntityReaction(targetUid, ReactionMethod.Ingestion);
firstStomach.TryTransferSolution(drain); firstStomach.TryTransferSolution(drain);

View File

@@ -98,7 +98,7 @@ namespace Content.Server.Nutrition.EntitySystems
!containerManager.Owner.TryGetComponent(out BloodstreamComponent? bloodstream)) !containerManager.Owner.TryGetComponent(out BloodstreamComponent? bloodstream))
continue; continue;
_chemistrySystem.ReactionEntity(containerManager.Owner, ReactionMethod.Ingestion, inhaledSolution); _chemistrySystem.ReactionEntity(containerManager.Owner.Uid, ReactionMethod.Ingestion, inhaledSolution);
bloodstream.TryTransferSolution(inhaledSolution); bloodstream.TryTransferSolution(inhaledSolution);
} }

View File

@@ -14,30 +14,30 @@ namespace Content.Shared.Chemistry
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public void ReactionEntity(IEntity entity, ReactionMethod method, Solution solution) public void ReactionEntity(EntityUid uid, ReactionMethod method, Solution solution)
{ {
foreach (var (id, quantity) in solution) foreach (var (id, quantity) in solution)
{ {
ReactionEntity(entity, method, id, quantity, solution); ReactionEntity(uid, method, id, quantity, solution);
} }
} }
public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, FixedPoint2 reactVolume, Solution? source) public void ReactionEntity(EntityUid uid, ReactionMethod method, string reagentId, FixedPoint2 reactVolume, Solution? source)
{ {
// We throw if the reagent specified doesn't exist. // We throw if the reagent specified doesn't exist.
ReactionEntity(entity, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source); ReactionEntity(uid, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source);
} }
public void ReactionEntity(IEntity entity, ReactionMethod method, ReagentPrototype reagent, public void ReactionEntity(EntityUid uid, ReactionMethod method, ReagentPrototype reagent,
FixedPoint2 reactVolume, Solution? source) FixedPoint2 reactVolume, Solution? source)
{ {
if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive)) if (!EntityManager.TryGetComponent(uid, out ReactiveComponent? reactive))
return; return;
foreach (var reaction in reactive.Reactions) foreach (var reaction in reactive.Reactions)
{ {
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified. // If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
reaction.React(method, entity.Uid, reagent, source?.GetReagentQuantity(reagent.ID) ?? reactVolume, source, EntityManager); reaction.React(method, uid, reagent, source?.GetReagentQuantity(reagent.ID) ?? reactVolume, source, EntityManager);
// Make sure we still have enough reagent to go... // Make sure we still have enough reagent to go...
if (source != null && !source.ContainsReagent(reagent.ID)) if (source != null && !source.ContainsReagent(reagent.ID))

View File

@@ -332,13 +332,13 @@ namespace Content.Shared.Chemistry.Components
return newSolution; return newSolution;
} }
public void DoEntityReaction(IEntity entity, ReactionMethod method) public void DoEntityReaction(EntityUid uid, ReactionMethod method)
{ {
var chemistry = EntitySystem.Get<ChemistrySystem>(); var chemistry = EntitySystem.Get<ChemistrySystem>();
foreach (var (reagentId, quantity) in Contents.ToArray()) foreach (var (reagentId, quantity) in Contents.ToArray())
{ {
chemistry.ReactionEntity(entity, method, reagentId, quantity, this); chemistry.ReactionEntity(uid, method, reagentId, quantity, this);
} }
} }

View File

@@ -8,6 +8,7 @@ using static Content.Shared.Interaction.SharedInteractionSystem;
namespace Content.Shared.Interaction.Helpers namespace Content.Shared.Interaction.Helpers
{ {
// TODO: Kill these with fire.
public static class SharedUnobstructedExtensions public static class SharedUnobstructedExtensions
{ {
private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get<SharedInteractionSystem>(); private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get<SharedInteractionSystem>();
@@ -26,6 +27,22 @@ namespace Content.Shared.Interaction.Helpers
ignoreInsideBlocker, popup); ignoreInsideBlocker, popup);
} }
public static bool InRangeUnobstructed(
this EntityUid origin,
EntityUid other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false,
IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
return InRangeUnobstructed(entityManager.GetEntity(origin), entityManager.GetEntity(other),
range, collisionMask, predicate, ignoreInsideBlocker, popup);
}
public static bool InRangeUnobstructed( public static bool InRangeUnobstructed(
this IEntity origin, this IEntity origin,
IComponent other, IComponent other,