diff --git a/Content.Shared/Alert/AlertsSystem.cs b/Content.Shared/Alert/AlertsSystem.cs index 5ba0bf3bcd..e2a2924630 100644 --- a/Content.Shared/Alert/AlertsSystem.cs +++ b/Content.Shared/Alert/AlertsSystem.cs @@ -16,6 +16,12 @@ public abstract class AlertsSystem : EntitySystem : null; } + public short GetSeverityRange(AlertType alertType) + { + var minSeverity = _typeToAlert[alertType].MinSeverity; + return (short)MathF.Min(minSeverity,_typeToAlert[alertType].MaxSeverity - minSeverity); + } + public short GetMaxSeverity(AlertType alertType) { return _typeToAlert[alertType].MaxSeverity; diff --git a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs index 6f56dfb584..a403b3e4be 100644 --- a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs +++ b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs @@ -24,6 +24,7 @@ public partial class MobStateSystem SubscribeLocalEvent(OnGettingStripped); SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(CheckAct); + SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(CheckAct); diff --git a/Content.Shared/Mobs/Systems/MobThresholdSystem.cs b/Content.Shared/Mobs/Systems/MobThresholdSystem.cs index 0560c3eabd..68583f5b81 100644 --- a/Content.Shared/Mobs/Systems/MobThresholdSystem.cs +++ b/Content.Shared/Mobs/Systems/MobThresholdSystem.cs @@ -5,9 +5,6 @@ using Content.Shared.Damage; using Content.Shared.FixedPoint; using Content.Shared.Mobs.Components; using Robust.Shared.GameStates; -using Robust.Shared.Prototypes; -using Robust.Shared.Utility; - namespace Content.Shared.Mobs.Systems; public sealed class MobThresholdSystem : EntitySystem @@ -17,8 +14,8 @@ public sealed class MobThresholdSystem : EntitySystem public override void Initialize() { - SubscribeLocalEvent(MobThresholdMapInit); SubscribeLocalEvent(MobThresholdShutdown); + SubscribeLocalEvent(MobThresholdStartup); SubscribeLocalEvent(OnDamaged); SubscribeLocalEvent(OnGetComponentState); SubscribeLocalEvent(OnHandleComponentState); @@ -246,6 +243,10 @@ public sealed class MobThresholdSystem : EntitySystem return; CheckThresholds(target, mobState, threshold, damageable); + + var ev = new MobThresholdChecked(target, mobState, threshold, damageable); + RaiseLocalEvent(target, ref ev, true); + UpdateAlerts(target, mobState.CurrentState, threshold, damageable); } #endregion @@ -255,29 +256,24 @@ public sealed class MobThresholdSystem : EntitySystem private void CheckThresholds(EntityUid target, MobStateComponent mobStateComponent, MobThresholdsComponent thresholdsComponent, DamageableComponent damageableComponent) { - foreach (var (threshold, mobState) in thresholdsComponent.Thresholds) + foreach (var (threshold, mobState) in thresholdsComponent.Thresholds.Reverse()) { if (damageableComponent.TotalDamage < threshold) continue; - TriggerThreshold(target, thresholdsComponent.CurrentThresholdState, mobState, mobStateComponent, - thresholdsComponent); + TriggerThreshold(target, mobState, mobStateComponent, thresholdsComponent); + break; } - - var ev = new MobThresholdChecked(target, mobStateComponent, thresholdsComponent, damageableComponent); - RaiseLocalEvent(target, ref ev, true); - UpdateAlerts(target, mobStateComponent.CurrentState, thresholdsComponent, damageableComponent); } private void TriggerThreshold( EntityUid target, - MobState oldState, MobState newState, MobStateComponent? mobState = null, MobThresholdsComponent? thresholds = null) { - if (oldState == newState || - !Resolve(target, ref mobState, ref thresholds)) + if (!Resolve(target, ref mobState, ref thresholds) || + mobState.CurrentState == newState) { return; } @@ -305,10 +301,12 @@ public sealed class MobThresholdSystem : EntitySystem var severity = _alerts.GetMinSeverity(AlertType.HumanHealth); if (TryGetIncapPercentage(target, damageable.TotalDamage, out var percentage)) { - severity = (short) MathF.Floor(percentage.Value.Float() * - _alerts.GetMaxSeverity(AlertType.HumanHealth)); - } + + severity = (short) MathF.Floor(percentage.Value.Float() * + _alerts.GetSeverityRange(AlertType.HumanHealth)); + severity += _alerts.GetMinSeverity(AlertType.HumanHealth); + } _alerts.ShowAlert(target, AlertType.HumanHealth, severity); break; } @@ -328,10 +326,14 @@ public sealed class MobThresholdSystem : EntitySystem } } - private void OnDamaged(EntityUid target, MobThresholdsComponent mobThresholdsComponent, DamageChangedEvent args) + private void OnDamaged(EntityUid target, MobThresholdsComponent thresholds, DamageChangedEvent args) { - var mobStateComp = EnsureComp(target); - CheckThresholds(target, mobStateComp, mobThresholdsComponent, args.Damageable); + if (!TryComp(target, out var mobState)) + return; + CheckThresholds(target, mobState, thresholds, args.Damageable); + var ev = new MobThresholdChecked(target, mobState, thresholds, args.Damageable); + RaiseLocalEvent(target, ref ev, true); + UpdateAlerts(target, mobState.CurrentState, thresholds, args.Damageable); } private void OnHandleComponentState(EntityUid target, MobThresholdsComponent component, @@ -350,19 +352,14 @@ public sealed class MobThresholdSystem : EntitySystem new Dictionary(component.Thresholds)); } - private void MobThresholdMapInit(EntityUid target, MobThresholdsComponent component, MapInitEvent args) + private void MobThresholdStartup(EntityUid target, MobThresholdsComponent thresholds, ComponentStartup args) { - // TODO remove when body sim is implemented - EnsureComp(target); - EnsureComp(target); - - if (!component.Thresholds.TryFirstOrNull(out var newState)) + if (!TryComp(target, out var mobState) || !TryComp(target, out var damageable)) return; - - component.CurrentThresholdState = newState.Value.Value; - - TriggerThreshold(target, MobState.Invalid, newState.Value.Value, thresholds: component); - UpdateAlerts(target, newState.Value.Value, component); + CheckThresholds(target, mobState, thresholds, damageable); + var ev = new MobThresholdChecked(target, mobState, thresholds, damageable); + RaiseLocalEvent(target, ref ev, true); + UpdateAlerts(target, mobState.CurrentState, thresholds, damageable); } private void MobThresholdShutdown(EntityUid target, MobThresholdsComponent component, ComponentShutdown args) diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index b9b8645669..218a583241 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -178,7 +178,7 @@ state: health7 name: alerts-health-name description: alerts-health-desc - minSeverity: 0 + minSeverity: 1 maxSeverity: 6 - type: alert