Files
tbd-station-14/Content.Shared/_Offbrand/Wounds/ThresholdHelpers.cs
Janet Blackquill 5fa17e22a1 De-MPL Offbrand
2025-09-27 22:43:24 -04:00

59 lines
1.5 KiB
C#

using System.Linq;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.Mobs;
using Robust.Shared.Prototypes;
namespace Content.Shared._Offbrand.Wounds;
public static class ThresholdHelpers
{
public static TValue? HighestMatch<TKey, TValue>(this SortedDictionary<TKey, TValue> dictionary, TKey value) where TKey : IComparable<TKey> where TValue : struct
{
foreach (var (threshold, data) in dictionary.Reverse())
{
if (value.CompareTo(threshold) < 0)
continue;
return data;
}
return null;
}
public static TValue? LowestMatch<TKey, TValue>(this SortedDictionary<TKey, TValue> dictionary, TKey value) where TKey : IComparable<TKey> where TValue : struct
{
foreach (var (threshold, data) in dictionary)
{
if (value.CompareTo(threshold) > 0)
continue;
return data;
}
return null;
}
public static FixedPoint2 Count(IEnumerable<ProtoId<DamageTypePrototype>> types, DamageSpecifier specifier)
{
var accumulator = FixedPoint2.Zero;
foreach (var type in types)
{
if (specifier.DamageDict.TryGetValue(type, out var amount))
accumulator += amount;
}
return accumulator;
}
public static MobState Max(MobState a, MobState b)
{
if ((byte)a > (byte)b)
return a;
else
return b;
}
}