Mobstate Refactor (#13389)

Refactors mobstate and moves mob health thresholds to their own component

Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
Jezithyr
2023-01-13 16:57:10 -08:00
committed by GitHub
parent 97e4c477bd
commit eeb5b17b34
148 changed files with 1517 additions and 1290 deletions

View File

@@ -1,8 +1,7 @@
using Content.Shared.Damage;
using Content.Shared.MobState.EntitySystems;
using Content.Shared.MobState.Components;
using Content.Server.Damage.Components;
using Content.Shared.Damage.Components;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Physics.Components;
namespace Content.Server.Contests
@@ -16,10 +15,11 @@ namespace Content.Server.Contests
/// <1 = Advantage to target
/// Roller should be the entity with an advantage from being bigger/healthier/more skilled, etc.
/// </summary>
///
public sealed class ContestsSystem : EntitySystem
{
[Dependency] private readonly SharedMobStateSystem _mobStateSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
/// <summary>
/// Returns the roller's mass divided by the target's.
/// </summary>
@@ -46,20 +46,37 @@ namespace Content.Server.Contests
return 1f;
// First, we'll see what health they go into crit at.
float rollerThreshold = 100f;
float targetThreshold = 100f;
if (TryComp<MobStateComponent>(roller, out var rollerState) &&
_mobStateSystem.TryGetEarliestIncapacitatedState(rollerState, 10000, out _, out var rollerCritThreshold))
rollerThreshold = (float) rollerCritThreshold;
if (TryComp<MobStateComponent>(target, out var targetState) &&
_mobStateSystem.TryGetEarliestIncapacitatedState(targetState, 10000, out _, out var targetCritThreshold))
targetThreshold = (float) targetCritThreshold;
//TODO: refactor this entire system.... Why does this exist, this shouldn't be calculated off health
var rollerThreshold = 100f;
if (!_mobThresholdSystem.TryGetThresholdForState(roller, MobState.Critical, out var rollerCritThreshold))
{
if (_mobThresholdSystem.TryGetThresholdForState(roller, MobState.Critical,
out var rollerdeadThreshold))
{
rollerThreshold = rollerdeadThreshold.Value.Float();
}
}
else
{
rollerThreshold = rollerCritThreshold.Value.Float();
}
var targetThreshold = 100f;
if (!_mobThresholdSystem.TryGetThresholdForState(roller, MobState.Critical, out var targetCritThreshold))
{
if (_mobThresholdSystem.TryGetThresholdForState(roller, MobState.Critical,
out var targetdeadThreshold))
{
targetThreshold = targetdeadThreshold.Value.Float();
}
}
else
{
targetThreshold = targetCritThreshold.Value.Float();
}
// Next, we'll see how their damage compares
float rollerDamageScore = (float) rollerDamage.TotalDamage / rollerThreshold;
float targetDamageScore = (float) targetDamage.TotalDamage / targetThreshold;
var rollerDamageScore = (float) rollerDamage.TotalDamage / rollerThreshold;
var targetDamageScore = (float) targetDamage.TotalDamage / targetThreshold;
return DamageThresholdConverter(rollerDamageScore) / DamageThresholdConverter(targetDamageScore);
}