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

@@ -0,0 +1,65 @@
using Content.Shared.Mobs;
using Robust.Client.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.DamageState;
public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
{
protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
{
var sprite = args.Sprite;
if (sprite == null || !args.Component.TryGetData(MobStateVisuals.State, out MobState data))
{
return;
}
if (!component.States.TryGetValue(data, out var layers))
{
return;
}
if (component.Rotate)
{
sprite.NoRotation = data switch
{
MobState.Critical => false,
MobState.Dead => false,
_ => true
};
}
// Brain no worky rn so this was just easier.
foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
{
if (!sprite.LayerMapTryGet(key, out _)) continue;
sprite.LayerSetVisible(key, false);
}
foreach (var (key, state) in layers)
{
// Inheritance moment.
if (!sprite.LayerMapTryGet(key, out _)) continue;
sprite.LayerSetVisible(key, true);
sprite.LayerSetState(key, state);
}
// So they don't draw over mobs anymore
if (data == MobState.Dead)
{
if (sprite.DrawDepth > (int) DrawDepth.FloorObjects)
{
component.OriginalDrawDepth = sprite.DrawDepth;
sprite.DrawDepth = (int) DrawDepth.FloorObjects;
}
}
else if (component.OriginalDrawDepth != null)
{
sprite.DrawDepth = component.OriginalDrawDepth.Value;
component.OriginalDrawDepth = null;
}
}
}