Add health overlay and a command to toggle it (#3278)
* Add health overlay bar and a command to toggle it * Remove empty line
This commit is contained in:
@@ -43,6 +43,8 @@ namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
[ViewVariables]
|
||||
public int? CurrentThreshold { get; private set; }
|
||||
|
||||
public IEnumerable<KeyValuePair<int, IMobState>> _highestToLowestStates => _lowestToHighestStates.Reverse();
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -175,16 +177,12 @@ namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
return true;
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage)
|
||||
private (IMobState state, int threshold)? GetEarliestState(int minimumDamage, Predicate<IMobState> predicate)
|
||||
{
|
||||
foreach (var (threshold, state) in _lowestToHighestStates)
|
||||
{
|
||||
if (!state.IsIncapacitated())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (threshold < minimumDamage)
|
||||
if (threshold < minimumDamage ||
|
||||
!predicate(state))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -195,6 +193,68 @@ namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
return null;
|
||||
}
|
||||
|
||||
private (IMobState state, int threshold)? GetPreviousState(int maximumDamage, Predicate<IMobState> predicate)
|
||||
{
|
||||
foreach (var (threshold, state) in _highestToLowestStates)
|
||||
{
|
||||
if (threshold > maximumDamage ||
|
||||
!predicate(state))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return (state, threshold);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestCriticalState(int minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsCritical());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsIncapacitated());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestDeadState(int minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsDead());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetPreviousCriticalState(int minimumDamage)
|
||||
{
|
||||
return GetPreviousState(minimumDamage, s => s.IsCritical());
|
||||
}
|
||||
|
||||
private bool TryGetState(
|
||||
(IMobState state, int threshold)? tuple,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
{
|
||||
if (tuple == null)
|
||||
{
|
||||
state = default;
|
||||
threshold = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
(state, threshold) = tuple.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetEarliestCriticalState(
|
||||
int minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
{
|
||||
var earliestState = GetEarliestCriticalState(minimumDamage);
|
||||
|
||||
return TryGetState(earliestState, out state, out threshold);
|
||||
}
|
||||
|
||||
public bool TryGetEarliestIncapacitatedState(
|
||||
int minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
@@ -202,15 +262,27 @@ namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
var earliestState = GetEarliestIncapacitatedState(minimumDamage);
|
||||
|
||||
if (earliestState == null)
|
||||
{
|
||||
state = default;
|
||||
threshold = default;
|
||||
return false;
|
||||
}
|
||||
return TryGetState(earliestState, out state, out threshold);
|
||||
}
|
||||
|
||||
(state, threshold) = earliestState.Value;
|
||||
return true;
|
||||
public bool TryGetEarliestDeadState(
|
||||
int minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
{
|
||||
var earliestState = GetEarliestDeadState(minimumDamage);
|
||||
|
||||
return TryGetState(earliestState, out state, out threshold);
|
||||
}
|
||||
|
||||
public bool TryGetPreviousCriticalState(
|
||||
int maximumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
{
|
||||
var earliestState = GetPreviousCriticalState(maximumDamage);
|
||||
|
||||
return TryGetState(earliestState, out state, out threshold);
|
||||
}
|
||||
|
||||
private void RemoveState(bool syncing = false)
|
||||
|
||||
Reference in New Issue
Block a user