Revert 'Revert 'Solution Entities'' (#23168)
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
using System.Numerics;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Cooldown;
|
||||
using Content.Server.Extinguisher;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Server.Gravity;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Vapor;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
@@ -40,23 +39,23 @@ public sealed class SpraySystem : EntitySystem
|
||||
SubscribeLocalEvent<SprayComponent, AfterInteractEvent>(OnAfterInteract, after: new[] { typeof(FireExtinguisherSystem) });
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, SprayComponent component, AfterInteractEvent args)
|
||||
private void OnAfterInteract(Entity<SprayComponent> entity, ref AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (!_solutionContainer.TryGetSolution(uid, SprayComponent.SolutionName, out var solution))
|
||||
if (!_solutionContainer.TryGetSolution(entity.Owner, SprayComponent.SolutionName, out var soln, out var solution))
|
||||
return;
|
||||
|
||||
var ev = new SprayAttemptEvent(args.User);
|
||||
RaiseLocalEvent(uid, ev);
|
||||
RaiseLocalEvent(entity, ev);
|
||||
if (ev.Cancelled)
|
||||
return;
|
||||
|
||||
var curTime = _gameTiming.CurTime;
|
||||
if (TryComp<ItemCooldownComponent>(uid, out var cooldown)
|
||||
if (TryComp<ItemCooldownComponent>(entity, out var cooldown)
|
||||
&& curTime < cooldown.CooldownEnd)
|
||||
{
|
||||
return;
|
||||
@@ -64,8 +63,7 @@ public sealed class SpraySystem : EntitySystem
|
||||
|
||||
if (solution.Volume <= 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("spray-component-is-empty-message"), uid,
|
||||
args.User);
|
||||
_popupSystem.PopupEntity(Loc.GetString("spray-component-is-empty-message"), entity.Owner, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,9 +80,9 @@ public sealed class SpraySystem : EntitySystem
|
||||
var diffNorm = diffPos.Normalized();
|
||||
var diffLength = diffPos.Length();
|
||||
|
||||
if (diffLength > component.SprayDistance)
|
||||
if (diffLength > entity.Comp.SprayDistance)
|
||||
{
|
||||
diffLength = component.SprayDistance;
|
||||
diffLength = entity.Comp.SprayDistance;
|
||||
}
|
||||
|
||||
var diffAngle = diffNorm.ToAngle();
|
||||
@@ -93,8 +91,8 @@ public sealed class SpraySystem : EntitySystem
|
||||
var threeQuarters = diffNorm * 0.75f;
|
||||
var quarter = diffNorm * 0.25f;
|
||||
|
||||
var amount = Math.Max(Math.Min((solution.Volume / component.TransferAmount).Int(), component.VaporAmount), 1);
|
||||
var spread = component.VaporSpread / amount;
|
||||
var amount = Math.Max(Math.Min((solution.Volume / entity.Comp.TransferAmount).Int(), entity.Comp.VaporAmount), 1);
|
||||
var spread = entity.Comp.VaporSpread / amount;
|
||||
// TODO: Just use usedelay homie.
|
||||
var cooldownTime = 0f;
|
||||
|
||||
@@ -108,18 +106,18 @@ public sealed class SpraySystem : EntitySystem
|
||||
.Offset((diffNorm + rotation.ToVec()).Normalized() * diffLength + quarter);
|
||||
|
||||
var distance = (target.Position - userMapPos.Position).Length();
|
||||
if (distance > component.SprayDistance)
|
||||
target = userMapPos.Offset(diffNorm * component.SprayDistance);
|
||||
if (distance > entity.Comp.SprayDistance)
|
||||
target = userMapPos.Offset(diffNorm * entity.Comp.SprayDistance);
|
||||
|
||||
var adjustedSolutionAmount = component.TransferAmount / component.VaporAmount;
|
||||
var newSolution = _solutionContainer.SplitSolution(uid, solution, adjustedSolutionAmount);
|
||||
var adjustedSolutionAmount = entity.Comp.TransferAmount / entity.Comp.VaporAmount;
|
||||
var newSolution = _solutionContainer.SplitSolution(soln.Value, adjustedSolutionAmount);
|
||||
|
||||
if (newSolution.Volume <= FixedPoint2.Zero)
|
||||
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.
|
||||
var vaporPos = userMapPos.Offset(distance < 1 ? quarter : threeQuarters);
|
||||
var vapor = Spawn(component.SprayedPrototype, vaporPos);
|
||||
var vapor = Spawn(entity.Comp.SprayedPrototype, vaporPos);
|
||||
var vaporXform = xformQuery.GetComponent(vapor);
|
||||
|
||||
_transform.SetWorldRotation(vaporXform, rotation);
|
||||
@@ -137,22 +135,21 @@ public sealed class SpraySystem : EntitySystem
|
||||
|
||||
// impulse direction is defined in world-coordinates, not local coordinates
|
||||
var impulseDirection = rotation.ToVec();
|
||||
var time = diffLength / component.SprayVelocity;
|
||||
var time = diffLength / entity.Comp.SprayVelocity;
|
||||
cooldownTime = MathF.Max(time, cooldownTime);
|
||||
|
||||
_vapor.Start(ent, vaporXform, impulseDirection * diffLength, component.SprayVelocity, target, time, args.User);
|
||||
_vapor.Start(ent, vaporXform, impulseDirection * diffLength, entity.Comp.SprayVelocity, target, time, args.User);
|
||||
|
||||
if (TryComp<PhysicsComponent>(args.User, out var body))
|
||||
{
|
||||
if (_gravity.IsWeightless(args.User, body))
|
||||
_physics.ApplyLinearImpulse(args.User, -impulseDirection.Normalized() * component.PushbackAmount, body: body);
|
||||
_physics.ApplyLinearImpulse(args.User, -impulseDirection.Normalized() * entity.Comp.PushbackAmount, body: body);
|
||||
}
|
||||
}
|
||||
|
||||
_audio.PlayPvs(component.SpraySound, uid, component.SpraySound.Params.WithVariation(0.125f));
|
||||
_audio.PlayPvs(entity.Comp.SpraySound, entity, entity.Comp.SpraySound.Params.WithVariation(0.125f));
|
||||
|
||||
RaiseLocalEvent(uid,
|
||||
new RefreshItemCooldownEvent(curTime, curTime + TimeSpan.FromSeconds(cooldownTime)), true);
|
||||
RaiseLocalEvent(entity, new RefreshItemCooldownEvent(curTime, curTime + TimeSpan.FromSeconds(cooldownTime)), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user