Roller Skates fixes (#21542)

This commit is contained in:
brainfood1183
2023-11-09 01:43:27 +00:00
committed by GitHub
parent be8e5b7a8d
commit 8be97a20c5
8 changed files with 187 additions and 54 deletions

View File

@@ -1,38 +0,0 @@
using Content.Shared.Clothing;
using Content.Shared.Inventory.Events;
using Content.Shared.Movement.Systems;
using Content.Server.Damage.Systems;
namespace Content.Server.Clothing;
public sealed class SkatesSystem : EntitySystem
{
[Dependency] private readonly MovementSpeedModifierSystem _move = default!;
[Dependency] private readonly DamageOnHighSpeedImpactSystem _impact = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SkatesComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SkatesComponent, GotUnequippedEvent>(OnGotUnequipped);
}
public void OnGotUnequipped(EntityUid uid, SkatesComponent component, GotUnequippedEvent args)
{
if (args.Slot == "shoes")
{
_move.ChangeFriction(args.Equipee, 20f, null, 20f);
_impact.ChangeCollide(args.Equipee, 20f, 1f, 2f);
}
}
private void OnGotEquipped(EntityUid uid, SkatesComponent component, GotEquippedEvent args)
{
if (args.Slot == "shoes")
{
_move.ChangeFriction(args.Equipee, 5f, 5f, 20f);
_impact.ChangeCollide(args.Equipee, 4f, 1f, 2f);
}
}
}

View File

@@ -1,40 +0,0 @@
using Content.Server.Damage.Systems;
using Content.Shared.Damage;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Damage.Components;
/// <summary>
/// Should the entity take damage / be stunned if colliding at a speed above MinimumSpeed?
/// </summary>
[RegisterComponent, Access(typeof(DamageOnHighSpeedImpactSystem))]
public sealed partial class DamageOnHighSpeedImpactComponent : Component
{
[DataField("minimumSpeed"), ViewVariables(VVAccess.ReadWrite)]
public float MinimumSpeed = 20f;
[DataField("speedDamageFactor"), ViewVariables(VVAccess.ReadWrite)]
public float SpeedDamageFactor = 0.5f;
[DataField("soundHit", required: true), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier SoundHit = default!;
[DataField("stunChance"), ViewVariables(VVAccess.ReadWrite)]
public float StunChance = 0.25f;
[DataField("stunMinimumDamage"), ViewVariables(VVAccess.ReadWrite)]
public int StunMinimumDamage = 10;
[DataField("stunSeconds"), ViewVariables(VVAccess.ReadWrite)]
public float StunSeconds = 1f;
[DataField("damageCooldown"), ViewVariables(VVAccess.ReadWrite)]
public float DamageCooldown = 2f;
[DataField("lastHit", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LastHit = TimeSpan.Zero;
[DataField("damage", required: true), ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage = default!;
}

View File

@@ -1,67 +0,0 @@
using Content.Server.Damage.Components;
using Content.Server.Stunnable;
using Content.Shared.Damage;
using Content.Shared.Effects;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.Damage.Systems;
public sealed class DamageOnHighSpeedImpactSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly StunSystem _stun = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageOnHighSpeedImpactComponent, StartCollideEvent>(HandleCollide);
}
private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, ref StartCollideEvent args)
{
if (!args.OurFixture.Hard || !args.OtherFixture.Hard)
return;
if (!EntityManager.HasComponent<DamageableComponent>(uid))
return;
var speed = args.OurBody.LinearVelocity.Length();
if (speed < component.MinimumSpeed)
return;
if ((_gameTiming.CurTime - component.LastHit).TotalSeconds < component.DamageCooldown)
return;
component.LastHit = _gameTiming.CurTime;
if (_robustRandom.Prob(component.StunChance))
_stun.TryStun(uid, TimeSpan.FromSeconds(component.StunSeconds), true);
var damageScale = component.SpeedDamageFactor * speed / component.MinimumSpeed;
_damageable.TryChangeDamage(uid, component.Damage * damageScale);
_audio.PlayPvs(component.SoundHit, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(-0.125f));
_color.RaiseEffect(Color.Red, new List<EntityUid>() { uid }, Filter.Pvs(uid, entityManager: EntityManager));
}
public void ChangeCollide(EntityUid uid, float minimumSpeed, float stunSeconds, float damageCooldown, DamageOnHighSpeedImpactComponent? collide = null)
{
if (!Resolve(uid, ref collide, false))
return;
collide.MinimumSpeed = minimumSpeed;
collide.StunSeconds = stunSeconds;
collide.DamageCooldown = damageCooldown;
Dirty(uid, collide);
}
}