2022-06-11 18:54:41 -07:00
|
|
|
using Content.Server.Chemistry.Components;
|
2023-09-05 09:55:10 +12:00
|
|
|
using Content.Shared.Chemistry;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
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;
|
2022-07-15 12:45:21 +10:00
|
|
|
using Content.Shared.Throwing;
|
2024-09-02 06:26:04 -05:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-07-21 22:26:09 +10:00
|
|
|
using Robust.Shared.Map;
|
2022-11-22 13:12:04 +11:00
|
|
|
using Robust.Shared.Map.Components;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
|
|
|
|
using Robust.Shared.Physics.Events;
|
2023-01-15 15:38:59 +11:00
|
|
|
using Robust.Shared.Physics.Systems;
|
2021-07-21 22:26:09 +10:00
|
|
|
using Robust.Shared.Prototypes;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Robust.Shared.Spawners;
|
2023-12-29 04:47:43 -08:00
|
|
|
using System.Numerics;
|
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 IPrototypeManager _protoManager = default!;
|
2024-03-20 21:59:56 -04:00
|
|
|
[Dependency] private readonly SharedMapSystem _map = default!;
|
2023-01-15 15:38:59 +11:00
|
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
2024-09-02 06:26:04 -05:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
2022-07-15 12:45:21 +10:00
|
|
|
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
2023-09-05 09:55:10 +12:00
|
|
|
[Dependency] private readonly ReactiveSystem _reactive = default!;
|
2024-08-06 04:02:01 -07:00
|
|
|
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
|
|
|
|
private const float ReactTime = 0.125f;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-03-17 21:30:27 +01:00
|
|
|
|
2021-07-21 22:26:09 +10:00
|
|
|
SubscribeLocalEvent<VaporComponent, StartCollideEvent>(HandleCollide);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void HandleCollide(Entity<VaporComponent> entity, ref StartCollideEvent args)
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!EntityManager.TryGetComponent(entity.Owner, out SolutionContainerManagerComponent? contents)) return;
|
2021-07-21 22:26:09 +10:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
foreach (var (_, soln) in _solutionContainerSystem.EnumerateSolutions((entity.Owner, contents)))
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
var solution = soln.Comp.Solution;
|
|
|
|
|
_reactive.DoEntityReaction(args.OtherEntity, solution, 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)
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
EntityManager.QueueDeleteEntity(entity);
|
2021-07-21 22:26:09 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
public void Start(Entity<VaporComponent> vapor, TransformComponent vaporXform, Vector2 dir, float speed, MapCoordinates target, float aliveTime, EntityUid? user = null)
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
vapor.Comp.Active = true;
|
|
|
|
|
var despawn = EnsureComp<TimedDespawnComponent>(vapor);
|
2022-07-15 12:45:21 +10:00
|
|
|
despawn.Lifetime = aliveTime;
|
|
|
|
|
|
2021-07-21 22:26:09 +10:00
|
|
|
// Set Move
|
2023-10-19 12:34:31 -07:00
|
|
|
if (EntityManager.TryGetComponent(vapor, out PhysicsComponent? physics))
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2024-03-25 02:37:25 -04:00
|
|
|
_physics.SetLinearDamping(vapor, physics, 0f);
|
|
|
|
|
_physics.SetAngularDamping(vapor, physics, 0f);
|
2022-07-15 12:45:21 +10:00
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
_throwing.TryThrow(vapor, dir, speed, user: user);
|
2022-07-15 12:45:21 +10:00
|
|
|
|
2024-08-06 04:02:01 -07:00
|
|
|
var distance = (target.Position - _transformSystem.GetWorldPosition(vaporXform)).Length();
|
2023-07-08 14:08:32 +10:00
|
|
|
var time = (distance / physics.LinearVelocity.Length());
|
2022-07-15 12:45:21 +10:00
|
|
|
despawn.Lifetime = MathF.Min(aliveTime, time);
|
2021-07-21 22:26:09 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
internal bool TryAddSolution(Entity<VaporComponent> vapor, Solution solution)
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2023-01-12 16:41:40 +13:00
|
|
|
if (solution.Volume == 0)
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, VaporComponent.SolutionName, out var vaporSolution))
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
return _solutionContainerSystem.TryAddSolution(vaporSolution.Value, solution);
|
2021-07-21 22:26:09 +10:00
|
|
|
}
|
|
|
|
|
|
2020-08-08 14:33:36 +02:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
var query = EntityQueryEnumerator<VaporComponent, SolutionContainerManagerComponent, TransformComponent>();
|
2023-12-29 04:47:43 -08:00
|
|
|
while (query.MoveNext(out var uid, out var vaporComp, out var container, out var xform))
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
foreach (var (_, soln) in _solutionContainerSystem.EnumerateSolutions((uid, container)))
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
Update(frameTime, (uid, vaporComp), soln, xform);
|
2021-09-06 15:49:44 +02:00
|
|
|
}
|
2021-07-21 22:26:09 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void Update(float frameTime, Entity<VaporComponent> ent, Entity<SolutionComponent> soln, TransformComponent xform)
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
var (entity, vapor) = ent;
|
2021-07-21 22:26:09 +10:00
|
|
|
if (!vapor.Active)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vapor.ReactTimer += frameTime;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
var contents = soln.Comp.Solution;
|
2022-11-04 10:12:25 +11:00
|
|
|
if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out MapGridComponent? gridComp))
|
2021-07-21 22:26:09 +10:00
|
|
|
{
|
|
|
|
|
vapor.ReactTimer = 0;
|
|
|
|
|
|
2024-03-20 21:59:56 -04:00
|
|
|
var tile = _map.GetTileRef(xform.GridUid.Value, gridComp, xform.Coordinates);
|
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;
|
2023-09-05 09:55:10 +12:00
|
|
|
var reagent = _protoManager.Index<ReagentPrototype>(reagentQuantity.Reagent.Prototype);
|
2023-05-18 01:02:07 +10:00
|
|
|
|
|
|
|
|
var reaction =
|
2024-08-09 01:27:27 +02:00
|
|
|
reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f, EntityManager, reagentQuantity.Reagent.Data);
|
2023-05-18 01:02:07 +10:00
|
|
|
|
|
|
|
|
if (reaction > reagentQuantity.Quantity)
|
|
|
|
|
{
|
2024-03-17 21:30:27 +01:00
|
|
|
Log.Error($"Tried to tile react more than we have for reagent {reagentQuantity}. Found {reaction} and we only have {reagentQuantity.Quantity}");
|
2023-05-18 01:02:07 +10:00
|
|
|
reaction = reagentQuantity.Quantity;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_solutionContainerSystem.RemoveReagent(soln, reagentQuantity.Reagent, reaction);
|
2021-07-21 22:26:09 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 16:41:40 +13:00
|
|
|
if (contents.Volume == 0)
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|