From 5b8468c9d8463e68dbf4b40226895cfed7d7e143 Mon Sep 17 00:00:00 2001 From: Alfred Baumann <93665570+CheesePlated@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:00:05 +0200 Subject: [PATCH] Mobs auto state handlers (#26957) * Autogenerate MobStateComponentState * changed CurrentState to DataField, updated DataField attribute for AllowedStates * Update Content.Shared/Mobs/Components/MobStateComponent.cs * Update Content.Shared/Mobs/Components/MobStateComponent.cs --------- Co-authored-by: BuildTools Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- .../Mobs/Components/MobStateComponent.cs | 21 ++++++------------- Content.Shared/Mobs/Systems/MobStateSystem.cs | 21 ------------------- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Content.Shared/Mobs/Components/MobStateComponent.cs b/Content.Shared/Mobs/Components/MobStateComponent.cs index a2ff349e13..7cff0779cb 100644 --- a/Content.Shared/Mobs/Components/MobStateComponent.cs +++ b/Content.Shared/Mobs/Components/MobStateComponent.cs @@ -13,30 +13,21 @@ namespace Content.Shared.Mobs.Components /// [RegisterComponent] [NetworkedComponent] + [AutoGenerateComponentState] [Access(typeof(MobStateSystem), typeof(MobThresholdSystem))] public sealed partial class MobStateComponent : Component { //default mobstate is always the lowest state level - [ViewVariables] public MobState CurrentState { get; set; } = MobState.Alive; + [AutoNetworkedField, ViewVariables] + public MobState CurrentState { get; set; } = MobState.Alive; - [DataField("allowedStates")] public HashSet AllowedStates = new() + [DataField] + [AutoNetworkedField] + public HashSet AllowedStates = new() { MobState.Alive, MobState.Critical, MobState.Dead }; } - - [Serializable, NetSerializable] - public sealed class MobStateComponentState : ComponentState - { - public readonly MobState CurrentState; - public readonly HashSet AllowedStates; - - public MobStateComponentState(MobState currentState, HashSet allowedStates) - { - CurrentState = currentState; - AllowedStates = allowedStates; - } - } } diff --git a/Content.Shared/Mobs/Systems/MobStateSystem.cs b/Content.Shared/Mobs/Systems/MobStateSystem.cs index ff54c30aaf..a3886dd42e 100644 --- a/Content.Shared/Mobs/Systems/MobStateSystem.cs +++ b/Content.Shared/Mobs/Systems/MobStateSystem.cs @@ -25,8 +25,6 @@ public partial class MobStateSystem : EntitySystem _sawmill = _logManager.GetSawmill("MobState"); base.Initialize(); SubscribeEvents(); - SubscribeLocalEvent(OnGetComponentState); - SubscribeLocalEvent(OnHandleComponentState); } #region Public API @@ -100,24 +98,5 @@ public partial class MobStateSystem : EntitySystem #region Private Implementation - private void OnHandleComponentState(EntityUid uid, MobStateComponent component, ref ComponentHandleState args) - { - if (args.Current is not MobStateComponentState state) - return; - - component.CurrentState = state.CurrentState; - - if (!component.AllowedStates.SetEquals(state.AllowedStates)) - { - component.AllowedStates.Clear(); - component.AllowedStates.UnionWith(state.AllowedStates); - } - } - - private void OnGetComponentState(EntityUid uid, MobStateComponent component, ref ComponentGetState args) - { - args.State = new MobStateComponentState(component.CurrentState, component.AllowedStates); - } - #endregion } -- 2.52.0