return false;
DoContactInteraction(user, used, activateMsg);
- if (delayComponent != null)
- _useDelay.TryResetDelay((used, delayComponent));
+ // Still need to call this even without checkUseDelay in case this gets relayed from Activate.
+ _useDelay.TryResetDelay(used, component: delayComponent);
if (!activateMsg.WasLogged)
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
return true;
/// Can support additional, separate cooldown timers on the object by passing a unique ID with the system methods.
/// </summary>
[RegisterComponent]
-[NetworkedComponent, AutoGenerateComponentState]
+[NetworkedComponent]
[Access(typeof(UseDelaySystem))]
public sealed partial class UseDelayComponent : Component
{
- [DataField, AutoNetworkedField]
+ [DataField]
public Dictionary<string, UseDelayInfo> Delays = [];
/// <summary>
public TimeSpan Delay = TimeSpan.FromSeconds(1);
}
+[Serializable, NetSerializable]
+public sealed class UseDelayComponentState : IComponentState
+{
+ public Dictionary<string, UseDelayInfo> Delays = new();
+}
+
[Serializable, NetSerializable]
[DataDefinition]
public sealed partial class UseDelayInfo
using System.Diagnostics.CodeAnalysis;
+using Robust.Shared.GameStates;
using Robust.Shared.Timing;
namespace Content.Shared.Timing;
SubscribeLocalEvent<UseDelayComponent, MapInitEvent>(OnMapInit);
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)