fish-station/Content.Shared/_Sunrise/Boss/Systems/SharedHellSpawnInvincibilitySystem.cs
pacable 8f2445ea94
Адское Отродье - Босс для утилей (#1525)
Signed-off-by: pacable <igor.mamaev1@gmail.com>
2025-03-10 02:33:48 +03:00

86 lines
3 KiB
C#

using Content.Shared._Sunrise.Boss.Components;
using Content.Shared._Sunrise.Boss.Events;
using Content.Shared.Damage.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Robust.Shared.Timing;
namespace Content.Shared._Sunrise.Boss.Systems;
public abstract class SharedHellSpawnInvincibilitySystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
/// <inheritdoc />
public override void Initialize()
{
SubscribeLocalEvent<HellSpawnInvincibilityComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<HellSpawnInvincibilityComponent, HellSpawnInvincibilityActionEvent>(OnInvincibilityAction);
}
private void OnInit(Entity<HellSpawnInvincibilityComponent> ent, ref ComponentInit args)
{
if (TryComp<MovementSpeedModifierComponent>(ent.Owner, out var modifierComponent))
ent.Comp.BaseSprintSpeed = modifierComponent.BaseSprintSpeed;
}
private void OnInvincibilityAction(Entity<HellSpawnInvincibilityComponent> ent,
ref HellSpawnInvincibilityActionEvent args)
{
if (args.Handled)
return;
AddGodmode(ent.Owner);
Timer.Spawn(3000, () => RemoveGodmode(ent.Owner));
args.Handled = true;
}
private void AddGodmode(EntityUid uid, HellSpawnInvincibilityComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
if (!HasComp<GodmodeComponent>(uid))
{
AddComp<GodmodeComponent>(uid);
if (TryComp<MovementSpeedModifierComponent>(uid, out var modifierComponent) && comp.BaseSprintSpeed != null)
{
_movement.ChangeBaseSpeed(uid,
modifierComponent.BaseWalkSpeed,
comp.BaseSprintSpeed.Value * 2,
modifierComponent.Acceleration);
}
var ev = new HellSpawnInvincibilityToggledEvent { Enabled = true };
RaiseLocalEvent(uid, ev);
}
_movement.RefreshMovementSpeedModifiers(uid);
}
private void RemoveGodmode(EntityUid uid, HellSpawnInvincibilityComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
if (HasComp<GodmodeComponent>(uid))
{
RemComp<GodmodeComponent>(uid);
if (TryComp<MovementSpeedModifierComponent>(uid, out var modifierComponent) && comp.BaseSprintSpeed != null)
{
_movement.ChangeBaseSpeed(uid,
modifierComponent.BaseWalkSpeed,
comp.BaseSprintSpeed.Value,
modifierComponent.Acceleration);
}
var ev = new HellSpawnInvincibilityToggledEvent { Enabled = false };
RaiseLocalEvent(uid, ev);
}
_movement.RefreshMovementSpeedModifiers(uid);
}
}
public sealed class HellSpawnInvincibilityToggledEvent : EntityEventArgs
{
public bool Enabled;
}