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

@@ -14,30 +14,30 @@ namespace Content.Shared.Chemistry
{
[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)
{
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.
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)
{
if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive))
if (!EntityManager.TryGetComponent(uid, out ReactiveComponent? reactive))
return;
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.
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...
if (source != null && !source.ContainsReagent(reagent.ID))

View File

@@ -28,7 +28,7 @@ namespace Content.Shared.Chemistry.Components
[ViewVariables]
[DataField("reagents")]
public List<ReagentQuantity> Contents = new(2);
/// <summary>
/// The calculated total volume of all reagents in the solution (ex. Total volume of liquid in beaker).
/// </summary>
@@ -332,13 +332,13 @@ namespace Content.Shared.Chemistry.Components
return newSolution;
}
public void DoEntityReaction(IEntity entity, ReactionMethod method)
public void DoEntityReaction(EntityUid uid, ReactionMethod method)
{
var chemistry = EntitySystem.Get<ChemistrySystem>();
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
{
// TODO: Kill these with fire.
public static class SharedUnobstructedExtensions
{
private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get<SharedInteractionSystem>();
@@ -26,6 +27,22 @@ namespace Content.Shared.Interaction.Helpers
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(
this IEntity origin,
IComponent other,