Maybe fix do_after getting stuck (#3196)
* Maybe fix do_after getting stuck IDK it's 5AM I tried. * Update Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -54,7 +54,7 @@ namespace Content.Client.GameObjects.Components
|
|||||||
if (Gui != null && !Gui.Disposed)
|
if (Gui != null && !Gui.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Gui = new DoAfterGui {AttachedEntity = Owner};
|
Gui = new DoAfterGui {AttachedEntity = Owner, FirstDraw = true};
|
||||||
|
|
||||||
foreach (var (_, doAfter) in _doAfters)
|
foreach (var (_, doAfter) in _doAfters)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Client.GameObjects.Components;
|
|||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Client.Graphics;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -25,6 +26,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
* DoAfterComponent handles network messages inbound as well as storing the DoAfter data.
|
* DoAfterComponent handles network messages inbound as well as storing the DoAfter data.
|
||||||
* It'll also handle overall cleanup when one is removed (i.e. removing it from DoAfterGui).
|
* It'll also handle overall cleanup when one is removed (i.e. removing it from DoAfterGui).
|
||||||
*/
|
*/
|
||||||
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,10 +34,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const float ExcessTime = 0.5f;
|
public const float ExcessTime = 0.5f;
|
||||||
|
|
||||||
// Each component in range will have its own vBox which we need to keep track of so if they go out of range or
|
|
||||||
// come into range it needs altering
|
|
||||||
private readonly HashSet<DoAfterComponent> _knownComponents = new();
|
|
||||||
|
|
||||||
private IEntity? _attachedEntity;
|
private IEntity? _attachedEntity;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -54,40 +52,37 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
var currentTime = _gameTiming.CurTime;
|
var currentTime = _gameTiming.CurTime;
|
||||||
var foundComps = new HashSet<DoAfterComponent>();
|
|
||||||
|
|
||||||
// Can't see any I guess?
|
// Can't see any I guess?
|
||||||
if (_attachedEntity == null || _attachedEntity.Deleted)
|
if (_attachedEntity == null || _attachedEntity.Deleted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
|
||||||
|
|
||||||
foreach (var comp in ComponentManager.EntityQuery<DoAfterComponent>(true))
|
foreach (var comp in ComponentManager.EntityQuery<DoAfterComponent>(true))
|
||||||
{
|
{
|
||||||
if (!_knownComponents.Contains(comp))
|
|
||||||
{
|
|
||||||
_knownComponents.Add(comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
var doAfters = comp.DoAfters.ToList();
|
var doAfters = comp.DoAfters.ToList();
|
||||||
|
var compPos = comp.Owner.Transform.WorldPosition;
|
||||||
|
|
||||||
if (doAfters.Count == 0)
|
if (doAfters.Count == 0 ||
|
||||||
|
comp.Owner.Transform.MapID != _attachedEntity.Transform.MapID ||
|
||||||
|
!viewbox.Contains(compPos))
|
||||||
{
|
{
|
||||||
if (comp.Gui != null)
|
comp.Disable();
|
||||||
comp.Gui.FirstDraw = true;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var range = (comp.Owner.Transform.WorldPosition - _attachedEntity.Transform.WorldPosition).Length + 0.01f;
|
var range = (compPos - _attachedEntity.Transform.WorldPosition).Length +
|
||||||
|
0.01f;
|
||||||
|
|
||||||
if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded(
|
if (comp.Owner != _attachedEntity &&
|
||||||
|
!ExamineSystemShared.InRangeUnOccluded(
|
||||||
_attachedEntity.Transform.MapPosition,
|
_attachedEntity.Transform.MapPosition,
|
||||||
comp.Owner.Transform.MapPosition, range,
|
comp.Owner.Transform.MapPosition, range,
|
||||||
entity => entity == comp.Owner || entity == _attachedEntity))
|
entity => entity == comp.Owner || entity == _attachedEntity))
|
||||||
{
|
{
|
||||||
if (comp.Gui != null)
|
comp.Disable();
|
||||||
comp.Gui.FirstDraw = true;
|
continue;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
comp.Enable();
|
comp.Enable();
|
||||||
@@ -108,7 +103,9 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
|
|
||||||
// Don't predict cancellation if it's already finished.
|
// Don't predict cancellation if it's already finished.
|
||||||
if (elapsedTime > doAfter.Delay)
|
if (elapsedTime > doAfter.Delay)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Predictions
|
// Predictions
|
||||||
if (doAfter.BreakOnUserMove)
|
if (doAfter.BreakOnUserMove)
|
||||||
@@ -122,7 +119,9 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
|
|
||||||
if (doAfter.BreakOnTargetMove)
|
if (doAfter.BreakOnTargetMove)
|
||||||
{
|
{
|
||||||
if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) && !targetEntity.Transform.Coordinates.InRange(EntityManager, doAfter.TargetGrid, doAfter.MovementThreshold))
|
if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) &&
|
||||||
|
!targetEntity.Transform.Coordinates.InRange(EntityManager, doAfter.TargetGrid,
|
||||||
|
doAfter.MovementThreshold))
|
||||||
{
|
{
|
||||||
comp.Cancel(id, currentTime);
|
comp.Cancel(id, currentTime);
|
||||||
continue;
|
continue;
|
||||||
@@ -140,18 +139,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
|
|||||||
comp.Remove(cancelled.Message);
|
comp.Remove(cancelled.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any components that we no longer need to track
|
|
||||||
foundComps.Add(comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var comp in foundComps)
|
|
||||||
{
|
|
||||||
if (!_knownComponents.Contains(comp))
|
|
||||||
{
|
|
||||||
_knownComponents.Remove(comp);
|
|
||||||
comp.Disable();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user