2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs;
|
2022-06-16 07:14:06 +03:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
|
|
|
|
|
2023-01-13 16:57:10 -08:00
|
|
|
namespace Content.Client.DamageState;
|
2022-06-16 07:14:06 +03:00
|
|
|
|
|
|
|
|
public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
|
|
|
|
|
{
|
|
|
|
|
protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
|
|
|
|
|
{
|
|
|
|
|
var sprite = args.Sprite;
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
if (sprite == null || !AppearanceSystem.TryGetData<MobState>(uid, MobStateVisuals.State, out var data, args.Component))
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!component.States.TryGetValue(data, out var layers))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (component.Rotate)
|
|
|
|
|
{
|
|
|
|
|
sprite.NoRotation = data switch
|
|
|
|
|
{
|
2023-01-13 16:57:10 -08:00
|
|
|
MobState.Critical => false,
|
|
|
|
|
MobState.Dead => false,
|
2022-06-16 07:14:06 +03:00
|
|
|
_ => true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Brain no worky rn so this was just easier.
|
2022-06-16 17:56:00 +10:00
|
|
|
foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
2022-06-16 17:56:00 +10:00
|
|
|
if (!sprite.LayerMapTryGet(key, out _)) continue;
|
|
|
|
|
|
|
|
|
|
sprite.LayerSetVisible(key, false);
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (key, state) in layers)
|
|
|
|
|
{
|
2022-06-16 16:14:59 +10:00
|
|
|
// Inheritance moment.
|
|
|
|
|
if (!sprite.LayerMapTryGet(key, out _)) continue;
|
|
|
|
|
|
2022-06-16 07:14:06 +03:00
|
|
|
sprite.LayerSetVisible(key, true);
|
|
|
|
|
sprite.LayerSetState(key, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// So they don't draw over mobs anymore
|
2023-01-13 16:57:10 -08:00
|
|
|
if (data == MobState.Dead)
|
2022-06-16 07:14:06 +03:00
|
|
|
{
|
2022-09-06 00:28:23 +10:00
|
|
|
if (sprite.DrawDepth > (int) DrawDepth.FloorObjects)
|
|
|
|
|
{
|
|
|
|
|
component.OriginalDrawDepth = sprite.DrawDepth;
|
|
|
|
|
sprite.DrawDepth = (int) DrawDepth.FloorObjects;
|
|
|
|
|
}
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
else if (component.OriginalDrawDepth != null)
|
|
|
|
|
{
|
|
|
|
|
sprite.DrawDepth = component.OriginalDrawDepth.Value;
|
2022-09-06 00:28:23 +10:00
|
|
|
component.OriginalDrawDepth = null;
|
2022-06-16 07:14:06 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|