Vapor tweaks (#9638)
This commit is contained in:
@@ -4,6 +4,8 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Spawners.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Vapor;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
@@ -18,6 +20,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
|
||||
private const float ReactTime = 0.125f;
|
||||
|
||||
@@ -43,16 +46,23 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(VaporComponent vapor, Vector2 dir, float speed, MapCoordinates target, float aliveTime)
|
||||
public void Start(VaporComponent vapor, TransformComponent vaporXform, Vector2 dir, float speed, MapCoordinates target, float aliveTime, EntityUid? user = null)
|
||||
{
|
||||
vapor.Active = true;
|
||||
vapor.Target = target;
|
||||
vapor.AliveTime = aliveTime;
|
||||
var despawn = EnsureComp<TimedDespawnComponent>(vapor.Owner);
|
||||
despawn.Lifetime = aliveTime;
|
||||
|
||||
// Set Move
|
||||
if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
|
||||
{
|
||||
physics.BodyStatus = BodyStatus.InAir;
|
||||
physics.ApplyLinearImpulse(dir * speed);
|
||||
physics.LinearDamping = 0f;
|
||||
physics.AngularDamping = 0f;
|
||||
|
||||
_throwing.TryThrow(vapor.Owner, dir * speed, user: user, pushbackRatio: 50f);
|
||||
|
||||
var distance = (target.Position - vaporXform.WorldPosition).Length;
|
||||
var time = (distance / physics.LinearVelocity.Length);
|
||||
despawn.Lifetime = MathF.Min(aliveTime, time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +73,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, SharedVaporComponent.SolutionName,
|
||||
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, VaporComponent.SolutionName,
|
||||
out var vaporSolution))
|
||||
{
|
||||
return false;
|
||||
@@ -74,32 +84,29 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var (vaporComp, solution) in EntityManager
|
||||
.EntityQuery<VaporComponent, SolutionContainerManagerComponent>())
|
||||
foreach (var (vaporComp, solution, xform) in EntityManager
|
||||
.EntityQuery<VaporComponent, SolutionContainerManagerComponent, TransformComponent>())
|
||||
{
|
||||
foreach (var (_, value) in solution.Solutions)
|
||||
{
|
||||
Update(frameTime, vaporComp, value);
|
||||
Update(frameTime, vaporComp, value, xform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(float frameTime, VaporComponent vapor, Solution contents)
|
||||
private void Update(float frameTime, VaporComponent vapor, Solution contents, TransformComponent xform)
|
||||
{
|
||||
if (!vapor.Active)
|
||||
return;
|
||||
|
||||
var entity = vapor.Owner;
|
||||
var xform = Transform(entity);
|
||||
|
||||
vapor.Timer += frameTime;
|
||||
vapor.ReactTimer += frameTime;
|
||||
|
||||
if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out IMapGridComponent? gridComp))
|
||||
{
|
||||
vapor.ReactTimer = 0;
|
||||
|
||||
|
||||
var tile = gridComp.Grid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager));
|
||||
foreach (var reagentQuantity in contents.Contents.ToArray())
|
||||
{
|
||||
@@ -110,14 +117,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we've reached our target.
|
||||
if (!vapor.Reached &&
|
||||
(vapor.Target.Position - xform.MapPosition.Position).LengthSquared <= 0.25f)
|
||||
{
|
||||
vapor.Reached = true;
|
||||
}
|
||||
|
||||
if (contents.CurrentVolume == 0 || vapor.Timer > vapor.AliveTime)
|
||||
if (contents.CurrentVolume == 0)
|
||||
{
|
||||
// Delete this
|
||||
EntityManager.QueueDeleteEntity(entity);
|
||||
|
||||
Reference in New Issue
Block a user