Damage masks (#9402)

This commit is contained in:
metalgearsloth
2022-07-06 17:58:14 +10:00
committed by GitHub
parent 0bbdd0c1a3
commit a2a5df1990
55 changed files with 1160 additions and 930 deletions

View File

@@ -0,0 +1,16 @@
using Content.Shared.StatusEffect;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void EnterCritState(EntityUid uid)
{
base.EnterCritState(uid);
if (HasComp<StatusEffectsComponent>(uid))
{
Status.TryRemoveStatusEffect(uid, "Stun");
}
}
}

View File

@@ -0,0 +1,19 @@
using Content.Shared.Alert;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void EnterDeadState(EntityUid uid)
{
base.EnterDeadState(uid);
Alerts.ShowAlert(uid, AlertType.HumanDead);
if (HasComp<StatusEffectsComponent>(uid))
{
Status.TryRemoveStatusEffect(uid, "Stun");
}
}
}

View File

@@ -0,0 +1,29 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.MobState.Components;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void UpdateNormState(EntityUid entity, FixedPoint2 threshold)
{
base.UpdateNormState(entity, threshold);
if (!TryComp<DamageableComponent>(entity, out var damageable))
return;
if (!TryComp<MobStateComponent>(entity, out var stateComponent))
return;
short modifier = 0;
if (TryGetEarliestIncapacitatedState(stateComponent, threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0)
{
modifier = (short)(damageable.TotalDamage / (earliestThreshold / 5) + 1);
}
Alerts.ShowAlert(entity, AlertType.HumanHealth, modifier);
}
}

View File

@@ -0,0 +1,19 @@
using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
using Robust.Shared.GameStates;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem : SharedMobStateSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MobStateComponent, ComponentGetState>(OnMobGetState);
}
private void OnMobGetState(EntityUid uid, MobStateComponent component, ref ComponentGetState args)
{
args.State = new MobStateComponentState(component.CurrentThreshold);
}
}

View File

@@ -1,18 +0,0 @@
using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState.States
{
public sealed class CriticalMobState : SharedCriticalMobState
{
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
if (entityManager.TryGetComponent(uid, out StatusEffectsComponent? stun))
{
EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(uid, "Stun");
}
}
}
}

View File

@@ -1,21 +0,0 @@
using Content.Shared.Alert;
using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState.States
{
public sealed class DeadMobState : SharedDeadMobState
{
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
EntitySystem.Get<AlertsSystem>().ShowAlert(uid, AlertType.HumanDead);
if (entityManager.TryGetComponent(uid, out StatusEffectsComponent? stun))
{
EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(uid, "Stun");
}
}
}
}

View File

@@ -1,34 +0,0 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.MobState.Components;
using Content.Shared.MobState.State;
namespace Content.Server.MobState.States
{
public sealed class NormalMobState : SharedNormalMobState
{
public override void UpdateState(EntityUid entity, FixedPoint2 threshold, IEntityManager entityManager)
{
base.UpdateState(entity, threshold, entityManager);
if (!entityManager.TryGetComponent(entity, out DamageableComponent? damageable))
{
return;
}
if (!entityManager.TryGetComponent(entity, out MobStateComponent? stateComponent))
{
return;
}
short modifier = 0;
if (stateComponent.TryGetEarliestIncapacitatedState(threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0)
{
modifier = (short)(damageable.TotalDamage / (earliestThreshold / 5) + 1);
}
EntitySystem.Get<AlertsSystem>().ShowAlert(entity, AlertType.HumanHealth, modifier);
}
}
}