mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-02-15 03:31:44 +01:00
Use map coordinates for spraying (#9505)
This commit is contained in:
@@ -22,6 +22,7 @@ public sealed class SpraySystem : EntitySystem
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly VaporSystem _vaporSystem = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -52,48 +53,66 @@ public sealed class SpraySystem : EntitySystem
|
||||
|
||||
if (solution.CurrentVolume <= 0)
|
||||
{
|
||||
_popupSystem.PopupEntity( Loc.GetString("spray-component-is-empty-message"),uid,
|
||||
_popupSystem.PopupEntity(Loc.GetString("spray-component-is-empty-message"), uid,
|
||||
Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
var playerPos = Transform(args.User).Coordinates;
|
||||
var userXform = Transform(args.User);
|
||||
|
||||
if (args.ClickLocation.GetGridUid(EntityManager) != playerPos.GetGridUid(EntityManager))
|
||||
// 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 direction = (args.ClickLocation.Position - playerPos.Position).Normalized;
|
||||
var threeQuarters = direction * 0.75f;
|
||||
var quarter = direction * 0.25f;
|
||||
var gridMapXform = Transform(vaporSpawnEntityUid);
|
||||
var gridMapInvMatrix = gridMapXform.InvWorldMatrix;
|
||||
|
||||
var userMapPos = userXform.MapPosition;
|
||||
|
||||
var clickMapPos = args.ClickLocation.ToMap(EntityManager);
|
||||
|
||||
var diffPos = clickMapPos.Position - userMapPos.Position;
|
||||
if (diffPos == Vector2.Zero || diffPos == Vector2.NaN)
|
||||
return;
|
||||
|
||||
var diffLength = diffPos.Length;
|
||||
var diffNorm = diffPos.Normalized;
|
||||
var diffAngle = diffNorm.ToAngle();
|
||||
|
||||
// Vectors to determine the spawn offset of the vapor clouds.
|
||||
var threeQuarters = diffNorm * 0.75f;
|
||||
var quarter = diffNorm * 0.25f;
|
||||
|
||||
var amount = Math.Max(Math.Min((solution.CurrentVolume / component.TransferAmount).Int(), component.VaporAmount), 1);
|
||||
|
||||
var spread = component.VaporSpread / amount;
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
var rotation = new Angle(direction.ToAngle() + Angle.FromDegrees(spread * i) -
|
||||
var rotation = new Angle(diffAngle + Angle.FromDegrees(spread * i) -
|
||||
Angle.FromDegrees(spread * (amount - 1) / 2));
|
||||
|
||||
var (_, diffPos) = args.ClickLocation - playerPos;
|
||||
var diffNorm = diffPos.Normalized;
|
||||
var diffLength = diffPos.Length;
|
||||
|
||||
var target = Transform(args.User).Coordinates
|
||||
// Calculate the destination for the vapor cloud. Limit to the maximum spray distance.
|
||||
var target = userMapPos
|
||||
.Offset((diffNorm + rotation.ToVec()).Normalized * diffLength + quarter);
|
||||
|
||||
if (target.TryDistance(EntityManager, playerPos, out var distance) && distance > component.SprayDistance)
|
||||
target = Transform(args.User).Coordinates
|
||||
.Offset(diffNorm * component.SprayDistance);
|
||||
var distance = target.Position.Length;
|
||||
if (distance > component.SprayDistance)
|
||||
target = userMapPos.Offset(diffNorm * component.SprayDistance);
|
||||
|
||||
var newSolution = _solutionContainerSystem.SplitSolution(uid, solution, component.TransferAmount);
|
||||
|
||||
if (newSolution.TotalVolume <= FixedPoint2.Zero)
|
||||
break;
|
||||
|
||||
var vapor = Spawn(component.SprayedPrototype,
|
||||
playerPos.Offset(distance < 1 ? quarter : threeQuarters));
|
||||
Transform(vapor).LocalRotation = rotation;
|
||||
// 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 vapor = Spawn(component.SprayedPrototype, new EntityCoordinates(vaporSpawnEntityUid, gridMapInvMatrix.Transform(vaporPos)));
|
||||
Transform(vapor).WorldRotation = rotation;
|
||||
|
||||
if (TryComp(vapor, out AppearanceComponent? appearance))
|
||||
{
|
||||
@@ -106,9 +125,10 @@ public sealed class SpraySystem : EntitySystem
|
||||
_vaporSystem.TryAddSolution(vaporComponent, newSolution);
|
||||
|
||||
// impulse direction is defined in world-coordinates, not local coordinates
|
||||
var impulseDirection = Transform(vapor).WorldRotation.ToVec();
|
||||
var impulseDirection = rotation.ToVec();
|
||||
_vaporSystem.Start(vaporComponent, impulseDirection, component.SprayVelocity, target, component.SprayAliveTime);
|
||||
|
||||
// Apply the reaction force to the user.
|
||||
if (component.Impulse > 0f && TryComp(args.User, out PhysicsComponent? body))
|
||||
body.ApplyLinearImpulse(-impulseDirection * component.Impulse);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user