]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Mobs auto state handlers (#26957)
authorAlfred Baumann <93665570+CheesePlated@users.noreply.github.com>
Wed, 17 Apr 2024 10:00:05 +0000 (12:00 +0200)
committerGitHub <noreply@github.com>
Wed, 17 Apr 2024 10:00:05 +0000 (20:00 +1000)
* 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 <unconfigured@null.spigotmc.org>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Shared/Mobs/Components/MobStateComponent.cs
Content.Shared/Mobs/Systems/MobStateSystem.cs

index a2ff349e1333f24dd3638363080bb4d0a717a5f8..7cff0779cbe71fda18d52586fb25b898be03f418 100644 (file)
@@ -13,30 +13,21 @@ namespace Content.Shared.Mobs.Components
     /// </summary>
     [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<MobState> AllowedStates = new()
+        [DataField]
+        [AutoNetworkedField]
+        public HashSet<MobState> AllowedStates = new()
             {
                 MobState.Alive,
                 MobState.Critical,
                 MobState.Dead
             };
     }
-
-    [Serializable, NetSerializable]
-    public sealed class MobStateComponentState : ComponentState
-    {
-        public readonly MobState CurrentState;
-        public readonly HashSet<MobState> AllowedStates;
-
-        public MobStateComponentState(MobState currentState, HashSet<MobState> allowedStates)
-        {
-            CurrentState = currentState;
-            AllowedStates = allowedStates;
-        }
-    }
 }
index ff54c30aaf4f181e2ef4825de4ada60cebc957e6..a3886dd42e185657819bcdc8fb5e2fbb78e971a7 100644 (file)
@@ -25,8 +25,6 @@ public partial class MobStateSystem : EntitySystem
         _sawmill = _logManager.GetSawmill("MobState");
         base.Initialize();
         SubscribeEvents();
-        SubscribeLocalEvent<MobStateComponent, ComponentGetState>(OnGetComponentState);
-        SubscribeLocalEvent<MobStateComponent, ComponentHandleState>(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
 }