Merge branch 'master' into replace-sounds-with-sound-specifier
# Conflicts: # Content.Server/Actions/Actions/DisarmAction.cs # Content.Server/Actions/Actions/ScreamAction.cs # Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs # Content.Server/Damage/Components/DamageOnHighSpeedImpactComponent.cs # Content.Server/Explosion/Components/FlashExplosiveComponent.cs # Content.Server/Physics/Controllers/MoverController.cs # Content.Server/Portal/Components/PortalComponent.cs # Content.Server/Portal/Components/TeleporterComponent.cs # Content.Server/Projectiles/Components/ProjectileComponent.cs # Content.Server/Singularity/Components/EmitterComponent.cs # Content.Server/Sound/EmitSoundSystem.cs # Content.Server/Stunnable/Components/StunbatonComponent.cs # Content.Server/Tools/Components/MultitoolComponent.cs # Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs # Content.Shared/Gravity/GravityComponent.cs # Content.Shared/Light/Component/SharedExpendableLightComponent.cs # Content.Shared/Maps/ContentTileDefinition.cs # Content.Shared/Slippery/SlipperyComponent.cs # Content.Shared/Standing/StandingStateComponent.cs # Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
This commit is contained in:
53
Content.Server/Damage/DamageOnHighSpeedImpactSystem.cs
Normal file
53
Content.Server/Damage/DamageOnHighSpeedImpactSystem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Damage
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class DamageOnHighSpeedImpactSystem: EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DamageOnHighSpeedImpactComponent, StartCollideEvent>(HandleCollide);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (component.SoundHit.TryGetSound(out var soundHit))
|
||||
SoundSystem.Play(Filter.Pvs(otherBody), soundHit, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user