Stamina damage (#9230)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Content.Server.Stunnable.Systems;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Timing;
|
||||
|
||||
@@ -8,21 +9,6 @@ namespace Content.Server.Stunnable.Components
|
||||
{
|
||||
public bool Activated = false;
|
||||
|
||||
/// <summary>
|
||||
/// What the <see cref="UseDelayComponent"/> is when the stun baton is active.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("activeCooldown")]
|
||||
public TimeSpan ActiveDelay = TimeSpan.FromSeconds(4);
|
||||
|
||||
/// <summary>
|
||||
/// Store what the <see cref="UseDelayComponent"/> was before being activated.
|
||||
/// </summary>
|
||||
public TimeSpan? OldDelay;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("paralyzeTime")]
|
||||
public float ParalyzeTime { get; set; } = 5f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("energyPerUse")]
|
||||
public float EnergyPerUse { get; set; } = 350;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Damage.Events;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.Events;
|
||||
using Content.Server.Speech.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction.Events;
|
||||
@@ -12,55 +13,48 @@ using Content.Shared.Item;
|
||||
using Content.Shared.Jittering;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Timing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Stunnable
|
||||
namespace Content.Server.Stunnable.Systems
|
||||
{
|
||||
public sealed class StunbatonSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly MeleeWeaponSystem _melee = default!;
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly StutteringSystem _stutteringSystem = default!;
|
||||
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<StunbatonComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, StunbatonComponent comp, MeleeHitEvent args)
|
||||
private void OnMeleeHit(EntityUid uid, StunbatonComponent component, MeleeHitEvent args)
|
||||
{
|
||||
if (!comp.Activated || !args.HitEntities.Any() || args.Handled || _useDelay.ActiveDelay(uid))
|
||||
return;
|
||||
if (!component.Activated) return;
|
||||
|
||||
if (!TryComp<BatteryComponent>(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse))
|
||||
return;
|
||||
// Don't apply damage if it's activated; just do stamina damage.
|
||||
args.BonusDamage -= args.BaseDamage;
|
||||
}
|
||||
|
||||
foreach (var entity in args.HitEntities)
|
||||
private void OnStaminaHitAttempt(EntityUid uid, StunbatonComponent component, ref StaminaDamageOnHitAttemptEvent args)
|
||||
{
|
||||
if (!component.Activated ||
|
||||
!TryComp<BatteryComponent>(uid, out var battery) || !battery.TryUseCharge(component.EnergyPerUse))
|
||||
{
|
||||
StunEntity(entity, comp);
|
||||
SendPowerPulse(entity, args.User, uid);
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_melee.SetAttackCooldown(uid, _timing.CurTime + comp.ActiveDelay);
|
||||
_useDelay.BeginDelay(uid);
|
||||
// No combat should occur if we successfully stunned.
|
||||
args.Handled = true;
|
||||
if (battery.CurrentCharge < component.EnergyPerUse)
|
||||
{
|
||||
SoundSystem.Play(component.SparksSound.GetSound(), Filter.Pvs(component.Owner, entityManager: EntityManager), uid, AudioHelpers.WithVariation(0.25f));
|
||||
TurnOff(component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)
|
||||
@@ -75,21 +69,6 @@ namespace Content.Server.Stunnable
|
||||
}
|
||||
}
|
||||
|
||||
private void OnThrowCollide(EntityUid uid, StunbatonComponent comp, ThrowDoHitEvent args)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
if (!TryComp<BatteryComponent>(uid, out var battery))
|
||||
return;
|
||||
|
||||
if (_robustRandom.Prob(comp.OnThrowStunChance) && battery.TryUseCharge(comp.EnergyPerUse))
|
||||
{
|
||||
SendPowerPulse(args.Target, args.User, uid);
|
||||
StunEntity(args.Target, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
|
||||
{
|
||||
var msg = comp.Activated
|
||||
@@ -101,24 +80,6 @@ namespace Content.Server.Stunnable
|
||||
("charge", (int)((battery.CurrentCharge/battery.MaxCharge) * 100))));
|
||||
}
|
||||
|
||||
private void StunEntity(EntityUid entity, StunbatonComponent comp)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(entity, out StatusEffectsComponent? status) || !comp.Activated) return;
|
||||
|
||||
SoundSystem.Play(comp.StunSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
_stunSystem.TryParalyze(entity, TimeSpan.FromSeconds(comp.ParalyzeTime), true, status);
|
||||
|
||||
var slowdownTime = TimeSpan.FromSeconds(comp.ParalyzeTime);
|
||||
_jitterSystem.DoJitter(entity, slowdownTime, true, status:status);
|
||||
_stutteringSystem.DoStutter(entity, slowdownTime, true, status);
|
||||
|
||||
if (!TryComp<BatteryComponent>(comp.Owner, out var battery) || !(battery.CurrentCharge < comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
SoundSystem.Play(comp.SparksSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
TurnOff(comp);
|
||||
}
|
||||
|
||||
private void TurnOff(StunbatonComponent comp)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
@@ -135,11 +96,6 @@ namespace Content.Server.Stunnable
|
||||
SoundSystem.Play(comp.SparksSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
|
||||
comp.Activated = false;
|
||||
if (TryComp<UseDelayComponent>(comp.Owner, out var useDelay) && comp.OldDelay != null)
|
||||
{
|
||||
useDelay.Delay = comp.OldDelay.Value;
|
||||
comp.OldDelay = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void TurnOn(StunbatonComponent comp, EntityUid user)
|
||||
@@ -147,13 +103,6 @@ namespace Content.Server.Stunnable
|
||||
if (comp.Activated)
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent<SpriteComponent?>(comp.Owner, out var sprite) &&
|
||||
EntityManager.TryGetComponent<SharedItemComponent?>(comp.Owner, out var item))
|
||||
{
|
||||
item.EquippedPrefix = "on";
|
||||
sprite.LayerSetState(0, "stunbaton_on");
|
||||
}
|
||||
|
||||
var playerFilter = Filter.Pvs(comp.Owner, entityManager: EntityManager);
|
||||
if (!TryComp<BatteryComponent>(comp.Owner, out var battery) || battery.CurrentCharge < comp.EnergyPerUse)
|
||||
{
|
||||
@@ -162,14 +111,15 @@ namespace Content.Server.Stunnable
|
||||
return;
|
||||
}
|
||||
|
||||
SoundSystem.Play(comp.SparksSound.GetSound(), playerFilter, comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
|
||||
comp.Activated = true;
|
||||
if (TryComp<UseDelayComponent>(comp.Owner, out var useDelay))
|
||||
if (EntityManager.TryGetComponent<SpriteComponent?>(comp.Owner, out var sprite) &&
|
||||
EntityManager.TryGetComponent<SharedItemComponent?>(comp.Owner, out var item))
|
||||
{
|
||||
comp.OldDelay = useDelay.Delay;
|
||||
useDelay.Delay = comp.ActiveDelay;
|
||||
item.EquippedPrefix = "on";
|
||||
sprite.LayerSetState(0, "stunbaton_on");
|
||||
}
|
||||
|
||||
SoundSystem.Play(comp.SparksSound.GetSound(), playerFilter, comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
comp.Activated = true;
|
||||
}
|
||||
|
||||
private void SendPowerPulse(EntityUid target, EntityUid? user, EntityUid used)
|
||||
Reference in New Issue
Block a user