2021-09-06 15:49:44 +02:00
|
|
|
|
using Content.Server.Chemistry.Components;
|
2021-10-29 13:40:15 +01:00
|
|
|
|
using Content.Server.Chemistry.Components.SolutionManager;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-11-03 16:48:03 -07:00
|
|
|
|
using Content.Shared.FixedPoint;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
using Content.Shared.Physics;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
using Content.Shared.Vapor;
|
2020-12-08 11:56:10 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
|
using Robust.Shared.Physics.Dynamics;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-08-08 14:33:36 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Chemistry.EntitySystems
|
2020-08-08 14:33:36 +02:00
|
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
|
[UsedImplicitly]
|
2021-07-21 22:26:09 +10:00
|
|
|
|
internal sealed class VaporSystem : EntitySystem
|
2020-08-08 14:33:36 +02:00
|
|
|
|
{
|
2021-07-21 22:26:09 +10:00
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
|
|
|
|
|
|
private const float ReactTime = 0.125f;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
SubscribeLocalEvent<VaporComponent, StartCollideEvent>(HandleCollide);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleCollide(EntityUid uid, VaporComponent component, StartCollideEvent args)
|
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
|
if (!EntityManager.TryGetComponent(uid, out SolutionContainerManagerComponent? contents)) return;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
|
foreach (var (_, value) in contents.Solutions)
|
|
|
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
|
value.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch);
|
2021-09-06 15:49:44 +02:00
|
|
|
|
}
|
2021-07-21 22:26:09 +10:00
|
|
|
|
|
|
|
|
|
|
// Check for collision with a impassable object (e.g. wall) and stop
|
|
|
|
|
|
if ((args.OtherFixture.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && args.OtherFixture.Hard)
|
|
|
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
|
EntityManager.QueueDeleteEntity(uid);
|
2021-07-21 22:26:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Start(VaporComponent vapor, Vector2 dir, float speed, EntityCoordinates target, float aliveTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
vapor.Active = true;
|
|
|
|
|
|
vapor.Target = target;
|
|
|
|
|
|
vapor.AliveTime = aliveTime;
|
|
|
|
|
|
// Set Move
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
|
|
|
|
|
physics.BodyStatus = BodyStatus.InAir;
|
|
|
|
|
|
physics.ApplyLinearImpulse(dir * speed);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal bool TryAddSolution(VaporComponent vapor, Solution solution)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (solution.TotalVolume == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, SharedVaporComponent.SolutionName,
|
2021-09-15 12:48:07 +02:00
|
|
|
|
out var vaporSolution))
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
|
return _solutionContainerSystem.TryAddSolution(vapor.Owner, vaporSolution, solution);
|
2021-07-21 22:26:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-08 14:33:36 +02:00
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
|
foreach (var (vaporComp, solution) in EntityManager
|
2021-10-18 14:58:34 +02:00
|
|
|
|
.EntityQuery<VaporComponent, SolutionContainerManagerComponent>())
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
|
foreach (var (_, value) in solution.Solutions)
|
|
|
|
|
|
{
|
|
|
|
|
|
Update(frameTime, vaporComp, value);
|
|
|
|
|
|
}
|
2021-07-21 22:26:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
|
private void Update(float frameTime, VaporComponent vapor, Solution contents)
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
|
|
|
|
|
if (!vapor.Active)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var entity = vapor.Owner;
|
|
|
|
|
|
|
|
|
|
|
|
vapor.Timer += frameTime;
|
|
|
|
|
|
vapor.ReactTimer += frameTime;
|
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (vapor.ReactTimer >= ReactTime && EntityManager.GetComponent<TransformComponent>(vapor.Owner).GridID.IsValid())
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
|
|
|
|
|
vapor.ReactTimer = 0;
|
2021-12-08 13:00:43 +01:00
|
|
|
|
var mapGrid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(entity).GridID);
|
2021-07-21 22:26:09 +10:00
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
|
var tile = mapGrid.GetTileRef(EntityManager.GetComponent<TransformComponent>(entity).Coordinates.ToVector2i(EntityManager, _mapManager));
|
2021-09-06 15:49:44 +02:00
|
|
|
|
foreach (var reagentQuantity in contents.Contents.ToArray())
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
2021-11-03 16:48:03 -07:00
|
|
|
|
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
var reagent = _protoManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
|
2021-12-03 15:53:09 +01:00
|
|
|
|
_solutionContainerSystem.TryRemoveReagent(vapor.Owner, contents, reagentQuantity.ReagentId,
|
2021-09-06 15:49:44 +02:00
|
|
|
|
reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
|
2021-07-21 22:26:09 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check if we've reached our target.
|
2021-09-06 15:49:44 +02:00
|
|
|
|
if (!vapor.Reached &&
|
2021-12-08 13:00:43 +01:00
|
|
|
|
vapor.Target.TryDistance(EntityManager, EntityManager.GetComponent<TransformComponent>(entity).Coordinates, out var distance) &&
|
2021-09-06 15:49:44 +02:00
|
|
|
|
distance <= 0.5f)
|
2021-07-21 22:26:09 +10:00
|
|
|
|
{
|
|
|
|
|
|
vapor.Reached = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (contents.CurrentVolume == 0 || vapor.Timer > vapor.AliveTime)
|
2020-08-08 14:33:36 +02:00
|
|
|
|
{
|
2021-07-21 22:26:09 +10:00
|
|
|
|
// Delete this
|
2021-12-08 13:00:43 +01:00
|
|
|
|
EntityManager.QueueDeleteEntity(entity);
|
2020-08-08 14:33:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|