[AutoNetworkedField]
public float FireRate = 8f;
+ /// <summary>
+ /// Starts fire cooldown when equipped if true.
+ /// </summary>
+ [ViewVariables(VVAccess.ReadWrite), DataField("resetOnHandSelected")]
+ public bool ResetOnHandSelected = true;
+
/// <summary>
/// How fast the projectile moves.
/// </summary>
using Content.Shared.Actions;
using Content.Shared.Examine;
+using Content.Shared.Hands;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Utility;
{
SelectFire(uid, component, args.Mode, args.Performer);
}
+
+ private void OnGunSelected(EntityUid uid, GunComponent component, HandSelectedEvent args)
+ {
+ var fireDelay = 1f / component.FireRate;
+ if (fireDelay.Equals(0f))
+ return;
+
+ if (!component.ResetOnHandSelected)
+ return;
+
+ if (Paused(uid))
+ return;
+
+ // If someone swaps to this weapon then reset its cd.
+ var curTime = Timing.CurTime;
+ var minimum = curTime + TimeSpan.FromSeconds(fireDelay);
+
+ if (minimum < component.NextFire)
+ return;
+
+ component.NextFire = minimum;
+ Dirty(uid, component);
+ }
}
using Content.Shared.Damage;
using Content.Shared.Examine;
using Content.Shared.Gravity;
+using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
SubscribeLocalEvent<GunComponent, GetVerbsEvent<AlternativeVerb>>(OnAltVerb);
SubscribeLocalEvent<GunComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<GunComponent, CycleModeEvent>(OnCycleMode);
+ SubscribeLocalEvent<GunComponent, HandSelectedEvent>(OnGunSelected);
SubscribeLocalEvent<GunComponent, EntityUnpausedEvent>(OnGunUnpaused);
#if DEBUG