Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some MobState Refactoring #1382

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions Content.Server/Traits/TraitSystem.Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ public sealed partial class TraitModifyMobThresholds : TraitFunction
[DataField, AlwaysPushInheritance]
public int CritThresholdModifier;

[DataField, AlwaysPushInheritance]
public int SoftCritThresholdModifier;

[DataField, AlwaysPushInheritance]
public int DeadThresholdModifier;

Expand All @@ -366,6 +369,13 @@ public override void OnPlayerSpawn(EntityUid uid,
thresholdSystem.SetMobStateThreshold(uid, critThreshold + CritThresholdModifier, MobState.Critical);
}

if (SoftCritThresholdModifier != 0)
{
var softCritThreshold = thresholdSystem.GetThresholdForState(uid, MobState.SoftCritical, threshold);
if (softCritThreshold != 0)
thresholdSystem.SetMobStateThreshold(uid, softCritThreshold + SoftCritThresholdModifier, MobState.SoftCritical);
}

if (DeadThresholdModifier != 0)
{
var deadThreshold = thresholdSystem.GetThresholdForState(uid, MobState.Dead, threshold);
Expand All @@ -375,6 +385,94 @@ public override void OnPlayerSpawn(EntityUid uid,
}
}

[UsedImplicitly]
public sealed partial class TraitModifyMobState : TraitFunction
{
// Three-State Booleans my beloved.
// :faridabirb.png:

[DataField, AlwaysPushInheritance]
public bool? AllowMovementWhileCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowMovementWhileSoftCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowMovementWhileDead;

[DataField, AlwaysPushInheritance]
public bool? AllowTalkingWhileCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowTalkingWhileSoftCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowTalkingWhileDead;

[DataField, AlwaysPushInheritance]
public bool? DownWhenCrit;

[DataField, AlwaysPushInheritance]
public bool? DownWhenSoftCrit;

[DataField, AlwaysPushInheritance]
public bool? DownWhenDead;

[DataField, AlwaysPushInheritance]
public bool? AllowHandInteractWhileCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowHandInteractWhileSoftCrit;

[DataField, AlwaysPushInheritance]
public bool? AllowHandInteractWhileDead;

public override void OnPlayerSpawn(EntityUid uid,
IComponentFactory factory,
IEntityManager entityManager,
ISerializationManager serializationManager)
{
if (!entityManager.TryGetComponent<MobStateComponent>(uid, out var mobStateComponent))
return;

if (AllowMovementWhileCrit is not null)
mobStateComponent.AllowMovementWhileCrit = AllowMovementWhileCrit.Value;

if (AllowMovementWhileSoftCrit is not null)
mobStateComponent.AllowHandInteractWhileSoftCrit = AllowMovementWhileSoftCrit.Value;

if (AllowMovementWhileDead is not null)
mobStateComponent.AllowMovementWhileDead = AllowMovementWhileDead.Value;

if (AllowTalkingWhileCrit is not null)
mobStateComponent.AllowTalkingWhileCrit = AllowTalkingWhileCrit.Value;

if (AllowTalkingWhileSoftCrit is not null)
mobStateComponent.AllowTalkingWhileSoftCrit = AllowTalkingWhileSoftCrit.Value;

if (AllowTalkingWhileDead is not null)
mobStateComponent.AllowTalkingWhileDead = AllowTalkingWhileDead.Value;

if (DownWhenCrit is not null)
mobStateComponent.DownWhenCrit = DownWhenCrit.Value;

if (DownWhenSoftCrit is not null)
mobStateComponent.DownWhenSoftCrit = DownWhenSoftCrit.Value;

if (DownWhenDead is not null)
mobStateComponent.DownWhenDead = DownWhenDead.Value;

if (AllowHandInteractWhileCrit is not null)
mobStateComponent.AllowHandInteractWhileCrit = AllowHandInteractWhileCrit.Value;

if (AllowHandInteractWhileSoftCrit is not null)
mobStateComponent.AllowHandInteractWhileSoftCrit = AllowHandInteractWhileSoftCrit.Value;

if (AllowHandInteractWhileDead is not null)
mobStateComponent.AllowHandInteractWhileDead = AllowHandInteractWhileDead.Value;
Comment on lines +438 to +472
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hate this, is there no better way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflection could

}
}

[UsedImplicitly]
public sealed partial class TraitModifyStamina : TraitFunction
{
Expand Down
126 changes: 99 additions & 27 deletions Content.Shared/Mobs/Components/MobStateComponent.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,105 @@
using Content.Shared.Damage;
using Content.Shared.Mobs.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

namespace Content.Shared.Mobs.Components
namespace Content.Shared.Mobs.Components;

/// <summary>
/// When attached to an <see cref="DamageableComponent"/>,
/// this component will handle critical and death behaviors for mobs.
/// Additionally, it handles sending effects to clients
/// (such as blur effect for unconsciousness) and managing the health HUD.
/// </summary>
[RegisterComponent]
[NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class MobStateComponent : Component
{
/// <summary>
/// When attached to an <see cref="DamageableComponent"/>,
/// this component will handle critical and death behaviors for mobs.
/// Additionally, it handles sending effects to clients
/// (such as blur effect for unconsciousness) and managing the health HUD.
/// </summary>
[RegisterComponent]
[NetworkedComponent]
[AutoGenerateComponentState]
[Access(typeof(MobStateSystem), typeof(MobThresholdSystem))]
public sealed partial class MobStateComponent : Component
{
//default mobstate is always the lowest state level
[AutoNetworkedField, ViewVariables]
public MobState CurrentState { get; set; } = MobState.Alive;

[DataField]
[AutoNetworkedField]
public HashSet<MobState> AllowedStates = new()
{
MobState.Alive,
MobState.Critical,
MobState.Dead
};
}
/// Whether this mob will be allowed to issue movement commands when in the Critical MobState.
/// </summary>
[DataField]
public bool AllowMovementWhileCrit;

/// <summary>
/// Whether this mob will be allowed to issue movement commands when in the Soft-Crit MobState.
/// </summary>
[DataField]
public bool AllowMovementWhileSoftCrit;

/// <summary>
/// Whether this mob will be allowed to issue movement commands when in the Dead MobState.
/// This is provided for completeness sake, and *probably* shouldn't be used by default.
/// </summary>
[DataField]
public bool AllowMovementWhileDead;

/// <summary>
/// Whether this mob will be allowed to talk while in the Critical MobState.
/// </summary>
[DataField]
public bool AllowTalkingWhileCrit = true;

/// <summary>
/// Whether this mob will be allowed to talk while in the SoftCritical MobState.
/// </summary>
[DataField]
public bool AllowTalkingWhileSoftCrit = true;

/// <summary>
/// Whether this mob will be allowed to talk while in the Dead MobState.
/// This is provided for completeness sake, and *probably* shouldn't be used by default.
/// </summary>
[DataField]
public bool AllowTalkingWhileDead;

/// <summary>
/// Whether this mob is forced to be downed when entering the Critical MobState.
/// </summary>
[DataField]
public bool DownWhenCrit = true;

/// <summary>
/// Whether this mob is forced to be downed when entering the SoftCritical MobState.
/// </summary>
[DataField]
public bool DownWhenSoftCrit = true;

/// <summary>
/// Whether this mob is forced to be downed when entering the Dead MobState.
/// </summary>
[DataField]
public bool DownWhenDead = true;

/// <summary>
/// Whether this mob is allowed to perform hand interactions while in the Critical MobState.
/// </summary>
[DataField]
public bool AllowHandInteractWhileCrit;

/// <summary>
/// Whether this mob is allowed to perform hand interactions while in the SoftCritical MobState.
/// </summary>
[DataField]
public bool AllowHandInteractWhileSoftCrit;

/// <summary>
/// Whether this mob is allowed to perform hand interactions while in the Dead MobState.
/// This is provided for completeness sake, and *probably* shouldn't be used by default.
/// </summary>
[DataField]
public bool AllowHandInteractWhileDead;

//default mobstate is always the lowest state level
[AutoNetworkedField, ViewVariables]
public MobState CurrentState { get; set; } = MobState.Alive;

[DataField]
[AutoNetworkedField]
public HashSet<MobState> AllowedStates = new()
{
MobState.Alive,
MobState.Critical,
MobState.SoftCritical,
MobState.Dead
};
}
13 changes: 7 additions & 6 deletions Content.Shared/Mobs/Components/MobThresholdsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ namespace Content.Shared.Mobs.Components;
[Access(typeof(MobThresholdSystem))]
public sealed partial class MobThresholdsComponent : Component
{
[DataField("thresholds", required: true)]
[DataField(required: true)]
public SortedDictionary<FixedPoint2, MobState> Thresholds = new();

[DataField("triggersAlerts")]
[DataField]
public bool TriggersAlerts = true;

[DataField("currentThresholdState")]
[DataField]
public MobState CurrentThresholdState;

/// <summary>
/// The health alert that should be displayed for player controlled entities.
/// Used for alternate health alerts (silicons, for example)
/// </summary>
[DataField("stateAlertDict")]
[DataField]
public Dictionary<MobState, ProtoId<AlertPrototype>> StateAlertDict = new()
{
{MobState.Alive, "HumanHealth"},
{MobState.Critical, "HumanCrit"},
{MobState.SoftCritical, "HumanCrit"},
{MobState.Dead, "HumanDead"},
};

Expand All @@ -38,13 +39,13 @@ public sealed partial class MobThresholdsComponent : Component
/// <summary>
/// Whether or not this entity should display damage overlays (robots don't feel pain, black out etc.)
/// </summary>
[DataField("showOverlays")]
[DataField]
public bool ShowOverlays = true;

/// <summary>
/// Whether or not this entity can be revived out of a dead state.
/// </summary>
[DataField("allowRevives")]
[DataField]
public bool AllowRevives;
}

Expand Down
4 changes: 3 additions & 1 deletion Content.Shared/Mobs/MobState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public enum MobState : byte
Invalid = 0,
Alive = 1,
Critical = 2,
Dead = 3
SoftCritical = 3,
Dead = 4,

VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down
Loading
Loading