2020-12-07 14:52:55 +01:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Damage;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2022-07-06 17:58:14 +10:00
|
|
|
using Content.Shared.MobState.EntitySystems;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2020-12-07 14:52:55 +01:00
|
|
|
|
2021-06-28 14:17:37 +02:00
|
|
|
namespace Content.Shared.MobState.Components
|
2020-12-07 14:52:55 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-09-15 03:07:37 +10:00
|
|
|
/// When attached to an <see cref="DamageableComponent"/>,
|
2020-12-07 14:52:55 +01:00
|
|
|
/// 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>
|
2021-09-15 03:07:37 +10:00
|
|
|
[RegisterComponent]
|
2021-11-08 15:11:58 +01:00
|
|
|
[NetworkedComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class MobStateComponent : Component
|
2020-12-07 14:52:55 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-09-15 03:07:37 +10:00
|
|
|
/// States that this <see cref="MobStateComponent"/> mapped to
|
2020-12-07 14:52:55 +01:00
|
|
|
/// the amount of damage at which they are triggered.
|
|
|
|
|
/// A threshold is reached when the total damage of an entity is equal
|
|
|
|
|
/// to or higher than the int key, but lower than the next threshold.
|
|
|
|
|
/// Ordered from lowest to highest.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("thresholds")]
|
2022-07-06 17:58:14 +10:00
|
|
|
public readonly SortedDictionary<int, DamageState> _lowestToHighestStates = new();
|
2020-12-07 14:52:55 +01:00
|
|
|
|
|
|
|
|
// TODO Remove Nullability?
|
|
|
|
|
[ViewVariables]
|
2022-07-06 17:58:14 +10:00
|
|
|
public DamageState? CurrentState { get; set; }
|
2020-12-07 14:52:55 +01:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2022-07-06 17:58:14 +10:00
|
|
|
public FixedPoint2? CurrentThreshold { get; set; }
|
2020-12-07 14:52:55 +01:00
|
|
|
|
2022-07-06 17:58:14 +10:00
|
|
|
public IEnumerable<KeyValuePair<int, DamageState>> _highestToLowestStates => _lowestToHighestStates.Reverse();
|
2020-12-07 14:52:55 +01:00
|
|
|
|
2022-07-06 17:58:14 +10:00
|
|
|
[Obsolete("Use MobStateSystem")]
|
2020-12-07 14:52:55 +01:00
|
|
|
public bool IsAlive()
|
|
|
|
|
{
|
2022-07-06 17:58:14 +10:00
|
|
|
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
|
|
|
|
|
.IsAlive(Owner, this);
|
2020-12-07 14:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:58:14 +10:00
|
|
|
[Obsolete("Use MobStateSystem")]
|
2020-12-07 14:52:55 +01:00
|
|
|
public bool IsCritical()
|
|
|
|
|
{
|
2022-07-06 17:58:14 +10:00
|
|
|
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
|
|
|
|
|
.IsCritical(Owner, this);
|
2020-12-07 14:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:58:14 +10:00
|
|
|
[Obsolete("Use MobStateSystem")]
|
2020-12-07 14:52:55 +01:00
|
|
|
public bool IsDead()
|
|
|
|
|
{
|
2022-07-06 17:58:14 +10:00
|
|
|
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
|
|
|
|
|
.IsDead(Owner, this);
|
2020-12-07 14:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:58:14 +10:00
|
|
|
[Obsolete("Use MobStateSystem")]
|
2020-12-07 14:52:55 +01:00
|
|
|
public bool IsIncapacitated()
|
|
|
|
|
{
|
2022-07-06 17:58:14 +10:00
|
|
|
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
|
|
|
|
|
.IsIncapacitated(Owner, this);
|
2020-12-07 14:52:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|