Vapor tweaks (#9638)

This commit is contained in:
metalgearsloth
2022-07-15 12:45:21 +10:00
committed by GitHub
parent 786c8a7c79
commit 9608005db0
4 changed files with 36 additions and 59 deletions

View File

@@ -5,17 +5,15 @@ using Robust.Shared.Map;
namespace Content.Server.Chemistry.Components namespace Content.Server.Chemistry.Components
{ {
[RegisterComponent] [RegisterComponent]
internal sealed class VaporComponent : SharedVaporComponent public sealed class VaporComponent : Component
{ {
public const string SolutionName = "vapor";
[ViewVariables] [ViewVariables]
[DataField("transferAmount")] [DataField("transferAmount")]
internal FixedPoint2 TransferAmount = FixedPoint2.New(0.5); public FixedPoint2 TransferAmount = FixedPoint2.New(0.5);
internal bool Reached; public float ReactTimer;
internal float ReactTimer; public bool Active;
internal float Timer;
internal MapCoordinates Target;
internal bool Active;
internal float AliveTime;
} }
} }

View File

@@ -4,6 +4,8 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent; using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Physics; using Content.Shared.Physics;
using Content.Shared.Spawners.Components;
using Content.Shared.Throwing;
using Content.Shared.Vapor; using Content.Shared.Vapor;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -18,6 +20,7 @@ namespace Content.Server.Chemistry.EntitySystems
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!; [Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
private const float ReactTime = 0.125f; 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.Active = true;
vapor.Target = target; var despawn = EnsureComp<TimedDespawnComponent>(vapor.Owner);
vapor.AliveTime = aliveTime; despawn.Lifetime = aliveTime;
// Set Move // Set Move
if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics)) if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
{ {
physics.BodyStatus = BodyStatus.InAir; physics.LinearDamping = 0f;
physics.ApplyLinearImpulse(dir * speed); 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; return false;
} }
if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, SharedVaporComponent.SolutionName, if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, VaporComponent.SolutionName,
out var vaporSolution)) out var vaporSolution))
{ {
return false; return false;
@@ -74,32 +84,29 @@ namespace Content.Server.Chemistry.EntitySystems
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
foreach (var (vaporComp, solution) in EntityManager foreach (var (vaporComp, solution, xform) in EntityManager
.EntityQuery<VaporComponent, SolutionContainerManagerComponent>()) .EntityQuery<VaporComponent, SolutionContainerManagerComponent, TransformComponent>())
{ {
foreach (var (_, value) in solution.Solutions) 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) if (!vapor.Active)
return; return;
var entity = vapor.Owner; var entity = vapor.Owner;
var xform = Transform(entity);
vapor.Timer += frameTime;
vapor.ReactTimer += frameTime; vapor.ReactTimer += frameTime;
if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out IMapGridComponent? gridComp)) if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out IMapGridComponent? gridComp))
{ {
vapor.ReactTimer = 0; vapor.ReactTimer = 0;
var tile = gridComp.Grid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager)); var tile = gridComp.Grid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager));
foreach (var reagentQuantity in contents.Contents.ToArray()) foreach (var reagentQuantity in contents.Contents.ToArray())
{ {
@@ -110,14 +117,7 @@ namespace Content.Server.Chemistry.EntitySystems
} }
} }
// Check if we've reached our target. if (contents.CurrentVolume == 0)
if (!vapor.Reached &&
(vapor.Target.Position - xform.MapPosition.Position).LengthSquared <= 0.25f)
{
vapor.Reached = true;
}
if (contents.CurrentVolume == 0 || vapor.Timer > vapor.AliveTime)
{ {
// Delete this // Delete this
EntityManager.QueueDeleteEntity(entity); EntityManager.QueueDeleteEntity(entity);

View File

@@ -18,11 +18,10 @@ namespace Content.Server.Fluids.EntitySystems;
public sealed class SpraySystem : EntitySystem public sealed class SpraySystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly VaporSystem _vaporSystem = default!; [Dependency] private readonly VaporSystem _vaporSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -58,22 +57,10 @@ public sealed class SpraySystem : EntitySystem
return; return;
} }
var userXform = Transform(args.User); var xformQuery = GetEntityQuery<TransformComponent>();
var userXform = xformQuery.GetComponent(args.User);
// The grid/map entity to attach the vapor to.
EntityUid vaporSpawnEntityUid;
if (userXform.GridUid != null)
vaporSpawnEntityUid = userXform.GridUid.Value;
else if (userXform.MapUid != null)
vaporSpawnEntityUid = userXform.MapUid.Value;
else
return;
var gridMapXform = Transform(vaporSpawnEntityUid);
var gridMapInvMatrix = gridMapXform.InvWorldMatrix;
var userMapPos = userXform.MapPosition; var userMapPos = userXform.MapPosition;
var clickMapPos = args.ClickLocation.ToMap(EntityManager); var clickMapPos = args.ClickLocation.ToMap(EntityManager);
var diffPos = clickMapPos.Position - userMapPos.Position; var diffPos = clickMapPos.Position - userMapPos.Position;
@@ -110,9 +97,11 @@ public sealed class SpraySystem : EntitySystem
break; break;
// Spawn the vapor cloud onto the grid/map the user is present on. Offset the start position based on how far the target destination is. // Spawn the vapor cloud onto the grid/map the user is present on. Offset the start position based on how far the target destination is.
var vaporPos = userMapPos.Offset(distance < 1 ? quarter : threeQuarters).Position; var vaporPos = userMapPos.Offset(distance < 1 ? quarter : threeQuarters);
var vapor = Spawn(component.SprayedPrototype, new EntityCoordinates(vaporSpawnEntityUid, gridMapInvMatrix.Transform(vaporPos))); var vapor = Spawn(component.SprayedPrototype, vaporPos);
Transform(vapor).WorldRotation = rotation; var vaporXform = xformQuery.GetComponent(vapor);
vaporXform.WorldRotation = rotation;
if (TryComp(vapor, out AppearanceComponent? appearance)) if (TryComp(vapor, out AppearanceComponent? appearance))
{ {
@@ -126,11 +115,7 @@ public sealed class SpraySystem : EntitySystem
// impulse direction is defined in world-coordinates, not local coordinates // impulse direction is defined in world-coordinates, not local coordinates
var impulseDirection = rotation.ToVec(); var impulseDirection = rotation.ToVec();
_vaporSystem.Start(vaporComponent, impulseDirection, component.SprayVelocity, target, component.SprayAliveTime); _vaporSystem.Start(vaporComponent, vaporXform, impulseDirection, component.SprayVelocity, target, component.SprayAliveTime, args.User);
// Apply the reaction force to the user.
if (component.Impulse > 0f && TryComp(args.User, out PhysicsComponent? body))
body.ApplyLinearImpulse(-impulseDirection * component.Impulse);
} }
SoundSystem.Play(component.SpraySound.GetSound(), Filter.Pvs(uid), uid, AudioHelpers.WithVariation(0.125f)); SoundSystem.Play(component.SpraySound.GetSound(), Filter.Pvs(uid), uid, AudioHelpers.WithVariation(0.125f));

View File

@@ -2,12 +2,6 @@
namespace Content.Shared.Vapor namespace Content.Shared.Vapor
{ {
[Virtual]
public class SharedVaporComponent : Component
{
public const string SolutionName = "vapor";
}
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum VaporVisuals public enum VaporVisuals
{ {