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;
}
removedSolution.DoEntityReaction(target, ReactionMethod.Injection);
removedSolution.DoEntityReaction(target.Uid, ReactionMethod.Injection);
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(target.Uid, targetSolution, removedSolution);

View File

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

View File

@@ -46,7 +46,7 @@ namespace Content.Server.Chemistry.Components
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
{
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);

View File

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

View File

@@ -36,7 +36,7 @@ namespace Content.Server.Chemistry.EntitySystems
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

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Map;
namespace Content.Server.Fluids.Components
{
// TODO: Kill these with fire
public static class SpillExtensions
{
/// <summary>
@@ -31,6 +32,25 @@ namespace Content.Server.Fluids.Components
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>
/// Spills the specified solution at the entity's location if possible.
/// </summary>

View File

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

View File

@@ -4,6 +4,7 @@ using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Examine;
@@ -29,6 +30,7 @@ namespace Content.Server.Nutrition.EntitySystems
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
@@ -104,7 +106,7 @@ namespace Content.Server.Nutrition.EntitySystems
if (args.Target == null)
return;
if (TryUseDrink(uid, args.User, args.Target, true, component))
if (TryUseDrink(uid, args.User.Uid, args.Target.Uid, true, component))
args.Handled = true;
}
@@ -126,7 +128,7 @@ namespace Content.Server.Nutrition.EntitySystems
return;
}
if (TryUseDrink(uid, args.User, args.User, false, component))
if (TryUseDrink(uid, args.User.Uid, args.User.Uid, false, component))
args.Handled = true;
}
@@ -184,7 +186,7 @@ namespace Content.Server.Nutrition.EntitySystems
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))
return false;
@@ -193,7 +195,7 @@ namespace Content.Server.Nutrition.EntitySystems
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;
}
@@ -202,20 +204,20 @@ namespace Content.Server.Nutrition.EntitySystems
{
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;
}
if (!EntityManager.TryGetComponent(target.Uid, out SharedBodyComponent? body) ||
if (!EntityManager.TryGetComponent(targetUid, out SharedBodyComponent? body) ||
!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;
}
if (user != target && !user.InRangeUnobstructed(target, popup: true))
if (userUid != targetUid && !userUid.InRangeUnobstructed(targetUid, popup: true))
return false;
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.
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))
{
drain.SpillAt(target, "PuddleSmear");
drain.SpillAt(targetUid, "PuddleSmear");
return false;
}
@@ -237,13 +239,13 @@ namespace Content.Server.Nutrition.EntitySystems
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.
drain.DoEntityReaction(target, ReactionMethod.Ingestion);
drain.DoEntityReaction(targetUid, ReactionMethod.Ingestion);
firstStomach.TryTransferSolution(drain);

View File

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