UseDelay + ItemCooldown merge (#22502)
This commit is contained in:
@@ -9,7 +9,8 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Timing;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -18,7 +19,6 @@ namespace Content.Server.Fluids.EntitySystems;
|
||||
/// <inheritdoc/>
|
||||
public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly PopupSystem _popups = default!;
|
||||
@@ -27,6 +27,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
[Dependency] private readonly MapSystem _mapSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -106,14 +107,15 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
if (!_solutionContainerSystem.TryGetSolution(used, AbsorbentComponent.SolutionName, out var absorberSoln))
|
||||
return;
|
||||
|
||||
if (_useDelay.ActiveDelay(used))
|
||||
if (TryComp<UseDelayComponent>(used, out var useDelay)
|
||||
&& _useDelay.IsDelayed((used, useDelay)))
|
||||
return;
|
||||
|
||||
// If it's a puddle try to grab from
|
||||
if (!TryPuddleInteract(user, used, target, component, absorberSoln.Value))
|
||||
if (!TryPuddleInteract(user, used, target, component, useDelay, absorberSoln.Value))
|
||||
{
|
||||
// If it's refillable try to transfer
|
||||
if (!TryRefillableInteract(user, used, target, component, absorberSoln.Value))
|
||||
if (!TryRefillableInteract(user, used, target, component, useDelay, absorberSoln.Value))
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +123,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
/// <summary>
|
||||
/// Logic for an absorbing entity interacting with a refillable.
|
||||
/// </summary>
|
||||
private bool TryRefillableInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, Entity<SolutionComponent> absorbentSoln)
|
||||
private bool TryRefillableInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, UseDelayComponent? useDelay, Entity<SolutionComponent> absorbentSoln)
|
||||
{
|
||||
if (!TryComp(target, out RefillableSolutionComponent? refillable))
|
||||
return false;
|
||||
@@ -143,7 +145,8 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
}
|
||||
|
||||
_audio.PlayPvs(component.TransferSound, target);
|
||||
_useDelay.BeginDelay(used);
|
||||
if (useDelay != null)
|
||||
_useDelay.TryResetDelay((used, useDelay));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -264,7 +267,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
/// <summary>
|
||||
/// Logic for an absorbing entity interacting with a puddle.
|
||||
/// </summary>
|
||||
private bool TryPuddleInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent absorber, Entity<SolutionComponent> absorberSoln)
|
||||
private bool TryPuddleInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent absorber, UseDelayComponent? useDelay, Entity<SolutionComponent> absorberSoln)
|
||||
{
|
||||
if (!TryComp(target, out PuddleComponent? puddle))
|
||||
return false;
|
||||
@@ -297,17 +300,20 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
||||
var absorberSplit = absorberSolution.SplitSolutionWithOnly(puddleSplit.Volume, PuddleSystem.EvaporationReagents);
|
||||
|
||||
// Do tile reactions first
|
||||
var coordinates = Transform(target).Coordinates;
|
||||
if (_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
|
||||
var transform = Transform(target);
|
||||
var gridUid = transform.GridUid;
|
||||
if (TryComp(gridUid, out MapGridComponent? mapGrid))
|
||||
{
|
||||
_puddleSystem.DoTileReactions(mapGrid.GetTileRef(coordinates), absorberSplit);
|
||||
var tileRef = _mapSystem.GetTileRef(gridUid.Value, mapGrid, transform.Coordinates);
|
||||
_puddleSystem.DoTileReactions(tileRef, absorberSplit);
|
||||
}
|
||||
|
||||
_solutionContainerSystem.AddSolution(puddle.Solution.Value, absorberSplit);
|
||||
_solutionContainerSystem.AddSolution(absorberSoln, puddleSplit);
|
||||
|
||||
_audio.PlayPvs(absorber.PickupSound, target);
|
||||
_useDelay.BeginDelay(used);
|
||||
if (useDelay != null)
|
||||
_useDelay.TryResetDelay((used, useDelay));
|
||||
|
||||
var userXform = Transform(user);
|
||||
var targetPos = _transform.GetWorldPosition(target);
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
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.Cooldown;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Timing;
|
||||
using Content.Shared.Vapor;
|
||||
using Robust.Server.GameObjects;
|
||||
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;
|
||||
|
||||
public sealed class SpraySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly GravitySystem _gravity = default!;
|
||||
[Dependency] private readonly PhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
|
||||
[Dependency] private readonly VaporSystem _vapor = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -54,12 +52,9 @@ public sealed class SpraySystem : EntitySystem
|
||||
if (ev.Cancelled)
|
||||
return;
|
||||
|
||||
var curTime = _gameTiming.CurTime;
|
||||
if (TryComp<ItemCooldownComponent>(entity, out var cooldown)
|
||||
&& curTime < cooldown.CooldownEnd)
|
||||
{
|
||||
if (!TryComp<UseDelayComponent>(entity, out var useDelay)
|
||||
|| _useDelay.IsDelayed((entity, useDelay)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (solution.Volume <= 0)
|
||||
{
|
||||
@@ -70,7 +65,7 @@ public sealed class SpraySystem : EntitySystem
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var userXform = xformQuery.GetComponent(args.User);
|
||||
|
||||
var userMapPos = userXform.MapPosition;
|
||||
var userMapPos = _transform.GetMapCoordinates(userXform);
|
||||
var clickMapPos = args.ClickLocation.ToMap(EntityManager, _transform);
|
||||
|
||||
var diffPos = clickMapPos.Position - userMapPos.Position;
|
||||
@@ -149,7 +144,8 @@ public sealed class SpraySystem : EntitySystem
|
||||
|
||||
_audio.PlayPvs(entity.Comp.SpraySound, entity, entity.Comp.SpraySound.Params.WithVariation(0.125f));
|
||||
|
||||
RaiseLocalEvent(entity, new RefreshItemCooldownEvent(curTime, curTime + TimeSpan.FromSeconds(cooldownTime)), true);
|
||||
_useDelay.SetDelay((entity, useDelay), TimeSpan.FromSeconds(cooldownTime));
|
||||
_useDelay.TryResetDelay((entity, useDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user