Add damage cooldown to DamageOnHighSpeedImpactComponent.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
@@ -7,6 +8,7 @@ using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -17,6 +19,7 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
public class DamageOnHighSpeedImpactComponent : Component, ICollideBehavior
|
||||
{
|
||||
[Dependency] private IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private IGameTiming _gameTiming = default!;
|
||||
|
||||
public override string Name => "DamageOnHighSpeedImpact";
|
||||
|
||||
@@ -27,7 +30,9 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
public string SoundHit { get; set; } = "";
|
||||
public float StunChance { get; set; } = 0.25f;
|
||||
public int StunMinimumDamage { get; set; } = 10;
|
||||
public float StunSeconds { get; set; }
|
||||
public float StunSeconds { get; set; } = 1f;
|
||||
public float DamageCooldown { get; set; } = 2f;
|
||||
private TimeSpan _lastHit = TimeSpan.Zero;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
@@ -40,6 +45,7 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
serializer.DataField(this, x => SoundHit, "soundHit", "");
|
||||
serializer.DataField(this, x => StunChance, "stunChance", 0.25f);
|
||||
serializer.DataField(this, x => StunSeconds, "stunSeconds", 1f);
|
||||
serializer.DataField(this, x => DamageCooldown, "damageCooldown", 2f);
|
||||
serializer.DataField(this, x => StunMinimumDamage, "stunMinimumDamage", 10);
|
||||
}
|
||||
|
||||
@@ -51,11 +57,16 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
|
||||
if (speed < MinimumSpeed) return;
|
||||
|
||||
var damage = (int) (BaseDamage * (speed / MinimumSpeed) * Factor);
|
||||
|
||||
if(!string.IsNullOrEmpty(SoundHit))
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, collidedWith, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
||||
|
||||
if ((_gameTiming.CurTime - _lastHit).TotalSeconds < DamageCooldown)
|
||||
return;
|
||||
|
||||
_lastHit = _gameTiming.CurTime;
|
||||
|
||||
var damage = (int) (BaseDamage * (speed / MinimumSpeed) * Factor);
|
||||
|
||||
if (Owner.TryGetComponent(out StunnableComponent stun) && _robustRandom.Prob(StunChance))
|
||||
stun.Stun(StunSeconds);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user