/// </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;
- }
- }
}
_sawmill = _logManager.GetSawmill("MobState");
base.Initialize();
SubscribeEvents();
- SubscribeLocalEvent<MobStateComponent, ComponentGetState>(OnGetComponentState);
- SubscribeLocalEvent<MobStateComponent, ComponentHandleState>(OnHandleComponentState);
}
#region Public API
#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
}