private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, StartCollideEvent args)
        {
            if (!EntityManager.HasComponent <DamageableComponent>(uid))
            {
                return;
            }

            var otherBody = args.OtherFixture.Body.Owner;
            var speed     = args.OurFixture.Body.LinearVelocity.Length;

            if (speed < component.MinimumSpeed)
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(otherBody), component.SoundHit.GetSound(), otherBody, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));

            if ((_gameTiming.CurTime - component.LastHit).TotalSeconds < component.DamageCooldown)
            {
                return;
            }

            component.LastHit = _gameTiming.CurTime;

            if (_robustRandom.Prob(component.StunChance))
            {
                _stunSystem.TryStun(uid, TimeSpan.FromSeconds(component.StunSeconds), true);
            }

            var damageScale = (speed / component.MinimumSpeed) * component.Factor;

            _damageableSystem.TryChangeDamage(uid, component.Damage * damageScale);
        }
Beispiel #2
0
        private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, StartCollideEvent args)
        {
            if (!ComponentManager.TryGetComponent(uid, out IDamageableComponent? damageable))
            {
                return;
            }

            var otherBody = args.OtherFixture.Body.Owner;
            var speed     = args.OurFixture.Body.LinearVelocity.Length;

            if (speed < component.MinimumSpeed)
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(otherBody), component.SoundHit.GetSound(), otherBody, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));

            if ((_gameTiming.CurTime - component.LastHit).TotalSeconds < component.DamageCooldown)
            {
                return;
            }

            component.LastHit = _gameTiming.CurTime;

            var damage = (int)(component.BaseDamage * (speed / component.MinimumSpeed) * component.Factor);

            if (ComponentManager.TryGetComponent(uid, out StunnableComponent? stun) && _robustRandom.Prob(component.StunChance))
            {
                stun.Stun(component.StunSeconds);
            }

            damageable.ChangeDamage(component.Damage, damage, false, args.OtherFixture.Body.Owner);
        }