2022-02-20 06:15:57 +11:00
|
|
|
using Content.Shared.DoAfter;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.Hands.Components;
|
2021-02-14 05:07:03 +11:00
|
|
|
using Robust.Client.Graphics;
|
2022-05-12 21:18:38 +10:00
|
|
|
using Robust.Client.Player;
|
2022-08-13 23:01:23 +10:00
|
|
|
using Robust.Shared.Prototypes;
|
2020-08-09 02:16:13 +10:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
namespace Content.Client.DoAfter;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles events that need to happen after a certain amount of time where the event could be cancelled by factors
|
|
|
|
|
/// such as moving.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class DoAfterSystem : SharedDoAfterSystem
|
2020-08-09 02:16:13 +10:00
|
|
|
{
|
2023-02-24 19:01:25 -05:00
|
|
|
[Dependency] private readonly IOverlayManager _overlay = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
2023-04-03 13:13:48 +12:00
|
|
|
[Dependency] private readonly MetaDataSystem _metadata = default!;
|
2020-08-09 02:16:13 +10:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2023-04-03 13:13:48 +12:00
|
|
|
_overlay.AddOverlay(new DoAfterOverlay(EntityManager, _prototype, GameTiming));
|
2023-02-24 19:01:25 -05:00
|
|
|
}
|
2020-08-09 02:16:13 +10:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
_overlay.RemoveOverlay<DoAfterOverlay>();
|
|
|
|
|
}
|
2022-08-13 14:32:23 +10:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
public override void Update(float frameTime)
|
2023-02-24 19:01:25 -05:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
// Currently this only predicts do afters initiated by the player.
|
2022-02-20 06:15:57 +11:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
// TODO maybe predict do-afters if the local player is the target of some other players do-after? Specifically
|
|
|
|
|
// ones that depend on the target not moving, because the cancellation of those do afters should be readily
|
|
|
|
|
// predictable by clients.
|
2020-08-09 02:16:13 +10:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
var playerEntity = _player.LocalPlayer?.ControlledEntity;
|
2022-02-20 06:15:57 +11:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (!TryComp(playerEntity, out ActiveDoAfterComponent? active))
|
2023-02-24 19:01:25 -05:00
|
|
|
return;
|
2022-02-20 06:15:57 +11:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (_metadata.EntityPaused(playerEntity.Value))
|
2023-02-24 19:01:25 -05:00
|
|
|
return;
|
2022-02-20 06:15:57 +11:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
var time = GameTiming.CurTime;
|
|
|
|
|
var comp = Comp<DoAfterComponent>(playerEntity.Value);
|
|
|
|
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
2023-04-07 11:21:12 -07:00
|
|
|
var handsQuery = GetEntityQuery<HandsComponent>();
|
2023-04-03 13:13:48 +12:00
|
|
|
Update(playerEntity.Value, active, comp, time, xformQuery, handsQuery);
|
2020-08-09 02:16:13 +10:00
|
|
|
}
|
2020-08-12 20:44:18 +02:00
|
|
|
}
|