Fix UseDelay issues (#27336)
* Fix UseDelay issues - Fix it not predicting properly by deep-copying the classes (realistically they should be structs). - Fix the `z` path not applying UseDelay similarly to the `e` path. * click
This commit is contained in:
@@ -973,8 +973,8 @@ namespace Content.Shared.Interaction
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
DoContactInteraction(user, used, activateMsg);
|
DoContactInteraction(user, used, activateMsg);
|
||||||
if (delayComponent != null)
|
// Still need to call this even without checkUseDelay in case this gets relayed from Activate.
|
||||||
_useDelay.TryResetDelay((used, delayComponent));
|
_useDelay.TryResetDelay(used, component: delayComponent);
|
||||||
if (!activateMsg.WasLogged)
|
if (!activateMsg.WasLogged)
|
||||||
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
|
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace Content.Shared.Timing;
|
|||||||
/// Can support additional, separate cooldown timers on the object by passing a unique ID with the system methods.
|
/// Can support additional, separate cooldown timers on the object by passing a unique ID with the system methods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[NetworkedComponent, AutoGenerateComponentState]
|
[NetworkedComponent]
|
||||||
[Access(typeof(UseDelaySystem))]
|
[Access(typeof(UseDelaySystem))]
|
||||||
public sealed partial class UseDelayComponent : Component
|
public sealed partial class UseDelayComponent : Component
|
||||||
{
|
{
|
||||||
[DataField, AutoNetworkedField]
|
[DataField]
|
||||||
public Dictionary<string, UseDelayInfo> Delays = [];
|
public Dictionary<string, UseDelayInfo> Delays = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,6 +27,12 @@ public sealed partial class UseDelayComponent : Component
|
|||||||
public TimeSpan Delay = TimeSpan.FromSeconds(1);
|
public TimeSpan Delay = TimeSpan.FromSeconds(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class UseDelayComponentState : IComponentState
|
||||||
|
{
|
||||||
|
public Dictionary<string, UseDelayInfo> Delays = new();
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
[DataDefinition]
|
[DataDefinition]
|
||||||
public sealed partial class UseDelayInfo
|
public sealed partial class UseDelayInfo
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Shared.Timing;
|
namespace Content.Shared.Timing;
|
||||||
@@ -16,6 +17,30 @@ public sealed class UseDelaySystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<UseDelayComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<UseDelayComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<UseDelayComponent, EntityUnpausedEvent>(OnUnpaused);
|
SubscribeLocalEvent<UseDelayComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||||
|
SubscribeLocalEvent<UseDelayComponent, ComponentGetState>(OnDelayGetState);
|
||||||
|
SubscribeLocalEvent<UseDelayComponent, ComponentHandleState>(OnDelayHandleState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDelayHandleState(Entity<UseDelayComponent> ent, ref ComponentHandleState args)
|
||||||
|
{
|
||||||
|
if (args.Current is not UseDelayComponentState state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ent.Comp.Delays.Clear();
|
||||||
|
|
||||||
|
// At time of writing sourcegen networking doesn't deep copy so this will mispredict if you try.
|
||||||
|
foreach (var (key, delay) in state.Delays)
|
||||||
|
{
|
||||||
|
ent.Comp.Delays[key] = new UseDelayInfo(delay.Length, delay.StartTime, delay.EndTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDelayGetState(Entity<UseDelayComponent> ent, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new UseDelayComponentState()
|
||||||
|
{
|
||||||
|
Delays = ent.Comp.Delays
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapInit(Entity<UseDelayComponent> ent, ref MapInitEvent args)
|
private void OnMapInit(Entity<UseDelayComponent> ent, ref MapInitEvent args)
|
||||||
|
|||||||
Reference in New Issue
Block a user