Reset melee cd on hand selected (#11709)
This commit is contained in:
@@ -42,6 +42,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<MeleeWeaponComponent, ComponentGetState>(OnGetState);
|
SubscribeLocalEvent<MeleeWeaponComponent, ComponentGetState>(OnGetState);
|
||||||
SubscribeLocalEvent<MeleeWeaponComponent, ComponentHandleState>(OnHandleState);
|
SubscribeLocalEvent<MeleeWeaponComponent, ComponentHandleState>(OnHandleState);
|
||||||
SubscribeLocalEvent<MeleeWeaponComponent, HandDeselectedEvent>(OnMeleeDropped);
|
SubscribeLocalEvent<MeleeWeaponComponent, HandDeselectedEvent>(OnMeleeDropped);
|
||||||
|
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnMeleeSelected);
|
||||||
|
|
||||||
SubscribeAllEvent<LightAttackEvent>(OnLightAttack);
|
SubscribeAllEvent<LightAttackEvent>(OnLightAttack);
|
||||||
SubscribeAllEvent<StartHeavyAttackEvent>(OnStartHeavyAttack);
|
SubscribeAllEvent<StartHeavyAttackEvent>(OnStartHeavyAttack);
|
||||||
@@ -51,6 +52,22 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
|
|||||||
SubscribeAllEvent<StopAttackEvent>(OnStopAttack);
|
SubscribeAllEvent<StopAttackEvent>(OnStopAttack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMeleeSelected(EntityUid uid, MeleeWeaponComponent component, HandSelectedEvent args)
|
||||||
|
{
|
||||||
|
if (component.AttackRate.Equals(0f))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If someone swaps to this weapon then reset its cd.
|
||||||
|
var curTime = Timing.CurTime;
|
||||||
|
var minimum = curTime + TimeSpan.FromSeconds(1 / component.AttackRate);
|
||||||
|
|
||||||
|
if (minimum < component.NextAttack)
|
||||||
|
return;
|
||||||
|
|
||||||
|
component.NextAttack = minimum;
|
||||||
|
Dirty(component);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMeleeDropped(EntityUid uid, MeleeWeaponComponent component, HandDeselectedEvent args)
|
private void OnMeleeDropped(EntityUid uid, MeleeWeaponComponent component, HandDeselectedEvent args)
|
||||||
{
|
{
|
||||||
if (component.WindUpStart == null)
|
if (component.WindUpStart == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user