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

@@ -2,8 +2,6 @@ using System.Linq;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.MobState;
using Content.Shared.MobState.Components;
using Content.Shared.Radiation.Events;
using Content.Shared.Rejuvenate;
using Robust.Shared.GameStates;
@@ -283,45 +281,6 @@ namespace Content.Shared.Damage
DamageChanged(component, delta);
}
}
/// <summary>
/// Takes the damage from one entity and scales it relative to the health of another
/// </summary>
/// <param name="ent1">The entity whose damage will be scaled</param>
/// <param name="ent2">The entity whose health the damage will scale to</param>
/// <param name="damage">The newly scaled damage. Can be null</param>
public bool GetScaledDamage(EntityUid ent1, EntityUid ent2, out DamageSpecifier? damage)
{
damage = null;
if (!TryComp<DamageableComponent>(ent1, out var olddamage))
return false;
if (!TryComp<MobStateComponent>(ent1, out var oldstate) ||
!TryComp<MobStateComponent>(ent2, out var newstate))
return false;
int ent1DeadState = 0;
foreach (var state in oldstate._highestToLowestStates)
{
if (state.Value == DamageState.Dead)
{
ent1DeadState = state.Key;
}
}
int ent2DeadState = 0;
foreach (var state in newstate._highestToLowestStates)
{
if (state.Value == DamageState.Dead)
{
ent2DeadState = state.Key;
}
}
damage = (olddamage.Damage / ent1DeadState) * ent2DeadState;
return true;
}
}
/// <summary>