Fix SetMobStateThreshold and MobThresholdsComponent networking (#16840)
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Shared.Alert;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Mobs.Systems;
|
||||
|
||||
@@ -14,12 +15,38 @@ public sealed class MobThresholdSystem : EntitySystem
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MobThresholdsComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<MobThresholdsComponent, ComponentHandleState>(OnHandleState);
|
||||
|
||||
SubscribeLocalEvent<MobThresholdsComponent, ComponentShutdown>(MobThresholdShutdown);
|
||||
SubscribeLocalEvent<MobThresholdsComponent, ComponentStartup>(MobThresholdStartup);
|
||||
SubscribeLocalEvent<MobThresholdsComponent, DamageChangedEvent>(OnDamaged);
|
||||
SubscribeLocalEvent<MobThresholdsComponent, UpdateMobStateEvent>(OnUpdateMobState);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, MobThresholdsComponent component, ref ComponentGetState args)
|
||||
{
|
||||
var thresholds = new Dictionary<FixedPoint2, MobState>();
|
||||
foreach (var (key, value) in component.Thresholds)
|
||||
{
|
||||
thresholds.Add(key, value);
|
||||
}
|
||||
args.State = new MobThresholdsComponentState(thresholds,
|
||||
component.TriggersAlerts,
|
||||
component.CurrentThresholdState,
|
||||
component.AllowRevives);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, MobThresholdsComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not MobThresholdsComponentState state)
|
||||
return;
|
||||
component.Thresholds = new SortedDictionary<FixedPoint2, MobState>(state.UnsortedThresholds);
|
||||
component.TriggersAlerts = state.TriggersAlerts;
|
||||
component.CurrentThresholdState = state.CurrentThresholdState;
|
||||
component.AllowRevives = state.AllowRevives;
|
||||
}
|
||||
|
||||
#region Public API
|
||||
|
||||
/// <summary>
|
||||
@@ -222,7 +249,16 @@ public sealed class MobThresholdSystem : EntitySystem
|
||||
if (!Resolve(target, ref threshold))
|
||||
return;
|
||||
|
||||
// create a duplicate dictionary so we don't modify while enumerating.
|
||||
var thresholds = new Dictionary<FixedPoint2, MobState>(threshold.Thresholds);
|
||||
foreach (var (damageThreshold, state) in thresholds)
|
||||
{
|
||||
if (state != mobState)
|
||||
continue;
|
||||
threshold.Thresholds.Remove(damageThreshold);
|
||||
}
|
||||
threshold.Thresholds[damage] = mobState;
|
||||
Dirty(threshold);
|
||||
VerifyThresholds(target, threshold);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user