Damage masks (#9402)

This commit is contained in:
metalgearsloth
2022-07-06 17:58:14 +10:00
committed by GitHub
parent 0bbdd0c1a3
commit a2a5df1990
55 changed files with 1160 additions and 930 deletions

View File

@@ -187,8 +187,6 @@ namespace Content.Client.Entry
var overlayMgr = IoCManager.Resolve<IOverlayManager>(); var overlayMgr = IoCManager.Resolve<IOverlayManager>();
overlayMgr.AddOverlay(new ParallaxOverlay()); overlayMgr.AddOverlay(new ParallaxOverlay());
overlayMgr.AddOverlay(new SingularityOverlay()); overlayMgr.AddOverlay(new SingularityOverlay());
overlayMgr.AddOverlay(new CritOverlay()); //Hopefully we can cut down on this list... don't see why a death overlay needs to be instantiated here.
overlayMgr.AddOverlay(new CircleMaskOverlay());
overlayMgr.AddOverlay(new FlashOverlay()); overlayMgr.AddOverlay(new FlashOverlay());
overlayMgr.AddOverlay(new RadiationPulseOverlay()); overlayMgr.AddOverlay(new RadiationPulseOverlay());

View File

@@ -1,4 +1,5 @@
using Content.Client.IoC; using Content.Client.IoC;
using Content.Client.MobState;
using Content.Client.Resources; using Content.Client.Resources;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
@@ -86,11 +87,12 @@ namespace Content.Client.HealthOverlay.UI
return; return;
} }
var mobStateSystem = _entities.EntitySysManager.GetEntitySystem<MobStateSystem>();
FixedPoint2 threshold; FixedPoint2 threshold;
if (mobState.IsAlive()) if (mobState.IsAlive())
{ {
if (!mobState.TryGetEarliestCriticalState(damageable.TotalDamage, out _, out threshold)) if (!mobStateSystem.TryGetEarliestCriticalState(mobState, damageable.TotalDamage, out _, out threshold))
{ {
CritBar.Visible = false; CritBar.Visible = false;
HealthBar.Visible = false; HealthBar.Visible = false;
@@ -107,8 +109,8 @@ namespace Content.Client.HealthOverlay.UI
HealthBar.Ratio = 0; HealthBar.Ratio = 0;
HealthBar.Visible = false; HealthBar.Visible = false;
if (!mobState.TryGetPreviousCriticalState(damageable.TotalDamage, out _, out var critThreshold) || if (!mobStateSystem.TryGetPreviousCriticalState(mobState, damageable.TotalDamage, out _, out var critThreshold) ||
!mobState.TryGetEarliestDeadState(damageable.TotalDamage, out _, out var deadThreshold)) !mobStateSystem.TryGetEarliestDeadState(mobState, damageable.TotalDamage, out _, out var deadThreshold))
{ {
CritBar.Visible = false; CritBar.Visible = false;
return; return;

View File

@@ -0,0 +1,132 @@
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.MobState;
using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.GameStates;
namespace Content.Client.MobState;
public sealed partial class MobStateSystem : SharedMobStateSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
private Overlays.DamageOverlay _overlay = default!;
public const short Levels = 7;
public override void Initialize()
{
base.Initialize();
_overlay = new Overlays.DamageOverlay();
IoCManager.Resolve<IOverlayManager>().AddOverlay(_overlay);
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttach);
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetach);
SubscribeLocalEvent<MobStateComponent, ComponentHandleState>(OnMobHandleState);
}
public override void Shutdown()
{
base.Shutdown();
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(_overlay);
}
private void OnMobHandleState(EntityUid uid, MobStateComponent component, ref ComponentHandleState args)
{
if (args.Current is not MobStateComponentState state) return;
if (component.CurrentThreshold == state.CurrentThreshold)
return;
if (state.CurrentThreshold == null)
{
RemoveState(component);
}
else
{
UpdateState(component, state.CurrentThreshold.Value);
}
}
private void OnPlayerAttach(PlayerAttachedEvent ev)
{
if (TryComp<MobStateComponent>(ev.Entity, out var mobState) && TryComp<DamageableComponent>(ev.Entity, out var damageable))
{
SetLevel(mobState, damageable.TotalDamage);
}
}
private void OnPlayerDetach(PlayerDetachedEvent ev)
{
_overlay.State = DamageState.Alive;
_overlay.BruteLevel = 0f;
_overlay.OxygenLevel = 0f;
_overlay.CritLevel = 0f;
}
protected override void UpdateState(MobStateComponent component, DamageState? state, FixedPoint2 threshold)
{
base.UpdateState(component, state, threshold);
SetLevel(component, threshold);
}
private void SetLevel(MobStateComponent stateComponent, FixedPoint2 threshold)
{
var uid = stateComponent.Owner;
if (_playerManager.LocalPlayer?.ControlledEntity != uid) return;
_overlay.State = DamageState.Alive;
_overlay.BruteLevel = 0f;
_overlay.OxygenLevel = 0f;
_overlay.CritLevel = 0f;
if (!TryComp<DamageableComponent>(uid, out var damageable))
return;
switch (stateComponent.CurrentState)
{
case DamageState.Dead:
_overlay.State = DamageState.Dead;
return;
}
var bruteLevel = 0f;
var oxyLevel = 0f;
var critLevel = 0f;
if (TryGetEarliestIncapacitatedState(stateComponent, threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0)
{
if (damageable.DamagePerGroup.TryGetValue("Brute", out var bruteDamage))
{
bruteLevel = MathF.Min(1f, (bruteDamage / earliestThreshold).Float());
}
if (damageable.Damage.DamageDict.TryGetValue("Asphyxiation", out var oxyDamage))
{
oxyLevel = MathF.Min(1f, (oxyDamage / earliestThreshold).Float());
}
if (threshold >= earliestThreshold && TryGetEarliestDeadState(stateComponent, threshold, out _, out var earliestDeadHold))
{
critLevel = (float) Math.Clamp((damageable.TotalDamage - earliestThreshold).Double() / (earliestDeadHold - earliestThreshold).Double(), 0.1, 1);
}
}
// Don't show damage overlay if they're near enough to max.
if (bruteLevel < 0.05f)
{
bruteLevel = 0f;
}
_overlay.State = critLevel > 0f ? DamageState.Critical : DamageState.Alive;
_overlay.BruteLevel = bruteLevel;
_overlay.OxygenLevel = oxyLevel;
_overlay.CritLevel = critLevel;
}
}

View File

@@ -1,36 +0,0 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.MobState.Overlays
{
public sealed class CircleMaskOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _shader;
public CircleMaskOverlay()
{
IoCManager.InjectDependencies(this);
_shader = _prototypeManager.Index<ShaderPrototype>("CircleMask").Instance();
}
protected override void Draw(in OverlayDrawArgs args)
{
if (!CritOverlay.LocalPlayerHasState(_playerManager, false, true))
return;
var worldHandle = args.WorldHandle;
worldHandle.UseShader(_shader);
var viewport = args.WorldAABB;
worldHandle.DrawRect(viewport, Color.White);
}
}
}

View File

@@ -1,58 +0,0 @@
using Content.Shared.MobState.Components;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.MobState.Overlays
{
public sealed class CritOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entities = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _gradientCircleShader;
public CritOverlay()
{
IoCManager.InjectDependencies(this);
_gradientCircleShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").Instance();
}
public static bool LocalPlayerHasState(IPlayerManager pm, bool critical, bool dead, IEntityManager? entities = null) {
if (pm.LocalPlayer?.ControlledEntity is not {Valid: true} player)
{
return false;
}
IoCManager.Resolve(ref entities);
if (entities.TryGetComponent<MobStateComponent?>(player, out var mobState))
{
if (critical)
if (mobState.IsCritical())
return true;
if (dead)
if (mobState.IsDead())
return true;
}
return false;
}
protected override void Draw(in OverlayDrawArgs args)
{
if (!LocalPlayerHasState(_playerManager, true, false, _entities))
return;
var worldHandle = args.WorldHandle;
var viewport = args.WorldAABB;
worldHandle.UseShader(_gradientCircleShader);
worldHandle.DrawRect(viewport, Color.White);
}
}
}

View File

@@ -0,0 +1,224 @@
using Content.Shared.MobState;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.MobState.Overlays;
public sealed class DamageOverlay : Overlay
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
private readonly ShaderInstance _critShader;
private readonly ShaderInstance _oxygenShader;
private readonly ShaderInstance _bruteShader;
public DamageState State = DamageState.Alive;
/// <summary>
/// Handles the red pulsing overlay
/// </summary>
public float BruteLevel = 0f;
private float _oldBruteLevel = 0f;
/// <summary>
/// Handles the darkening overlay.
/// </summary>
public float OxygenLevel = 0f;
private float _oldOxygenLevel = 0f;
/// <summary>
/// Handles the white overlay when crit.
/// </summary>
public float CritLevel = 0f;
private float _oldCritLevel = 0f;
private float _deadLevel = 1f;
public DamageOverlay()
{
// TODO: Replace
IoCManager.InjectDependencies(this);
_oxygenShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").InstanceUnique();
_critShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").InstanceUnique();
_bruteShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").InstanceUnique();
}
protected override void Draw(in OverlayDrawArgs args)
{
/*
* Here's the rundown:
* 1. There's lerping for each level so the transitions are smooth.
* 2. There's 3 overlays, 1 for brute damage, 1 for oxygen damage (that also doubles as a crit overlay),
* and a white one during crit that closes in as you progress towards death. When you die it slowly disappears.
* The crit overlay also occasionally reduces its alpha as a "blink"
*/
var viewport = args.ViewportBounds;
var handle = args.ScreenHandle;
var distance = args.ViewportBounds.Width;
var lerpRate = 0.2f;
var time = (float) _timing.RealTime.TotalSeconds;
var lastFrameTime = (float) _timing.FrameTime.TotalSeconds;
// If they just died then lerp out the white overlay.
if (State != DamageState.Dead)
{
_deadLevel = 1f;
}
else if (!_deadLevel.Equals(0f))
{
var diff = -_deadLevel;
_deadLevel += GetDiff(diff, lerpRate, lastFrameTime);
}
if (!_oldBruteLevel.Equals(BruteLevel))
{
var diff = BruteLevel - _oldBruteLevel;
_oldBruteLevel += GetDiff(diff, lerpRate, lastFrameTime);
}
if (!_oldOxygenLevel.Equals(OxygenLevel))
{
var diff = OxygenLevel - _oldOxygenLevel;
_oldOxygenLevel += GetDiff(diff, lerpRate, lastFrameTime);
}
if (!_oldCritLevel.Equals(CritLevel))
{
var diff = CritLevel - _oldCritLevel;
_oldCritLevel += GetDiff(diff, lerpRate, lastFrameTime);
}
/*
* darknessAlphaOuter is the maximum alpha for anything outside of the larger circle
* darknessAlphaInner (on the shader) is the alpha for anything inside the smallest circle
*
* outerCircleRadius is what we end at for max level for the outer circle
* outerCircleMaxRadius is what we start at for 0 level for the outer circle
*
* innerCircleRadius is what we end at for max level for the inner circle
* innerCircleMaxRadius is what we start at for 0 level for the inner circle
*/
// Makes debugging easier don't @ me
float level = 0f;
level = _oldBruteLevel;
// TODO: Lerping
if (level > 0f && _oldCritLevel <= 0f)
{
var pulseRate = 3f;
var adjustedTime = time * pulseRate;
float outerMaxLevel = 2.0f * distance;
float outerMinLevel = 0.8f * distance;
float innerMaxLevel = 0.6f * distance;
float innerMinLevel = 0.2f * distance;
var outerRadius = outerMaxLevel - level * (outerMaxLevel - outerMinLevel);
var innerRadius = innerMaxLevel - level * (innerMaxLevel - innerMinLevel);
var pulse = MathF.Max(0f, MathF.Sin(adjustedTime));
_bruteShader.SetParameter("time", pulse);
_bruteShader.SetParameter("color", new Vector3(1f, 0f, 0f));
_bruteShader.SetParameter("darknessAlphaOuter", 0.8f);
_bruteShader.SetParameter("outerCircleRadius", outerRadius);
_bruteShader.SetParameter("outerCircleMaxRadius", outerRadius + 0.2f * distance);
_bruteShader.SetParameter("innerCircleRadius", innerRadius);
_bruteShader.SetParameter("innerCircleMaxRadius", innerRadius + 0.02f * distance);
handle.UseShader(_bruteShader);
handle.DrawRect(viewport, Color.White);
}
else
{
_oldBruteLevel = BruteLevel;
}
level = State != DamageState.Critical ? _oldOxygenLevel : 1f;
if (level > 0f)
{
float outerMaxLevel = 0.6f * distance;
float outerMinLevel = 0.06f * distance;
float innerMaxLevel = 0.02f * distance;
float innerMinLevel = 0.02f * distance;
var outerRadius = outerMaxLevel - level * (outerMaxLevel - outerMinLevel);
var innerRadius = innerMaxLevel - level * (innerMaxLevel - innerMinLevel);
float outerDarkness;
float critTime;
// If in crit then just fix it; also pulse it very occasionally so they can see more.
if (_oldCritLevel > 0f)
{
var adjustedTime = time * 2f;
critTime = MathF.Max(0, MathF.Sin(adjustedTime) + 2 * MathF.Sin(2 * adjustedTime / 4f) + MathF.Sin(adjustedTime / 4f) - 3f);
if (critTime > 0f)
{
outerDarkness = 1f - critTime / 1.5f;
}
else
{
outerDarkness = 1f;
}
}
else
{
outerDarkness = MathF.Min(0.98f, 0.3f * MathF.Log(level) + 1f);
}
_oxygenShader.SetParameter("time", 0.0f);
_oxygenShader.SetParameter("color", new Vector3(0f, 0f, 0f));
_oxygenShader.SetParameter("darknessAlphaOuter", outerDarkness);
_oxygenShader.SetParameter("innerCircleRadius", innerRadius);
_oxygenShader.SetParameter("innerCircleMaxRadius", innerRadius);
_oxygenShader.SetParameter("outerCircleRadius", outerRadius);
_oxygenShader.SetParameter("outerCircleMaxRadius", outerRadius + 0.2f * distance);
handle.UseShader(_oxygenShader);
handle.DrawRect(viewport, Color.White);
}
level = State != DamageState.Dead ? _oldCritLevel : _deadLevel;
if (level > 0f)
{
float outerMaxLevel = 2.0f * distance;
float outerMinLevel = 1.0f * distance;
float innerMaxLevel = 0.6f * distance;
float innerMinLevel = 0.02f * distance;
var outerRadius = outerMaxLevel - level * (outerMaxLevel - outerMinLevel);
var innerRadius = innerMaxLevel - level * (innerMaxLevel - innerMinLevel);
var pulse = MathF.Max(0f, MathF.Sin(time));
// If in crit then just fix it; also pulse it very occasionally so they can see more.
_critShader.SetParameter("time", pulse);
_critShader.SetParameter("color", new Vector3(1f, 1f, 1f));
_critShader.SetParameter("darknessAlphaOuter", 1.0f);
_critShader.SetParameter("innerCircleRadius", innerRadius);
_critShader.SetParameter("innerCircleMaxRadius", innerRadius + 0.005f * distance);
_critShader.SetParameter("outerCircleRadius", outerRadius);
_critShader.SetParameter("outerCircleMaxRadius", outerRadius + 0.2f * distance);
handle.UseShader(_critShader);
handle.DrawRect(viewport, Color.White);
}
}
private float GetDiff(float value, float lerpRate, float lastFrameTime)
{
return Math.Clamp(value, -1 * lerpRate * lastFrameTime, lerpRate * lastFrameTime);
}
}

View File

@@ -1,8 +0,0 @@
using Content.Shared.MobState.State;
namespace Content.Client.MobState.States
{
public sealed class CriticalMobState : SharedCriticalMobState
{
}
}

View File

@@ -1,19 +0,0 @@
using Content.Shared.MobState;
using Content.Shared.MobState.State;
using Robust.Shared.GameObjects;
namespace Content.Client.MobState.States
{
public sealed class DeadMobState : SharedDeadMobState
{
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
if (entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
}
}
}
}

View File

@@ -1,11 +0,0 @@
using Content.Shared.MobState;
using Content.Shared.MobState.State;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Client.MobState.States
{
public sealed class NormalMobState : SharedNormalMobState
{
}
}

View File

@@ -1,24 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic;
using JetBrains.Annotations; using JetBrains.Annotations;
using Nett; using Nett;
using Content.Shared;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Client.Resources;
using Content.Client.IoC; using Content.Client.IoC;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.ContentPack; using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Utility;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

View File

@@ -1,4 +1,4 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.Body.Components; using Content.Server.Body.Components;
using Content.Server.Body.Systems; using Content.Server.Body.Systems;
@@ -27,7 +27,7 @@ namespace Content.IntegrationTests.Tests.Body
centerSlot: torso centerSlot: torso
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
- type: ThermalRegulator - type: ThermalRegulator
metabolismHeat: 5000 metabolismHeat: 5000
radiatedHeat: 400 radiatedHeat: 400

View File

@@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Client.MobState;
using Content.Server.Administration.Commands; using Content.Server.Administration.Commands;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes; using Content.Shared.Damage.Prototypes;
@@ -25,9 +26,9 @@ namespace Content.IntegrationTests.Tests.Commands
damageContainer: Biological damageContainer: Biological
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
100: !type:CriticalMobState {} 100: Critical
200: !type:DeadMobState {} 200: Dead
"; ";
[Test] [Test]
@@ -35,22 +36,19 @@ namespace Content.IntegrationTests.Tests.Commands
{ {
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes}); await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
var server = pairTracker.Pair.Server; var server = pairTracker.Pair.Server;
var entManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
await server.WaitAssertion(() => await server.WaitAssertion(() =>
{ {
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.CreateNewMapEntity(MapId.Nullspace); mapManager.CreateNewMapEntity(MapId.Nullspace);
var entityManager = IoCManager.Resolve<IEntityManager>(); var human = entManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace);
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace);
// Sanity check // Sanity check
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human, out DamageableComponent damageable)); Assert.True(entManager.TryGetComponent(human, out DamageableComponent damageable));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human, out MobStateComponent mobState)); Assert.True(entManager.TryGetComponent(human, out MobStateComponent mobState));
mobState.UpdateState(0);
Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsAlive, Is.True);
Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsCritical, Is.False);
Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsDead, Is.False);

View File

@@ -1,6 +1,5 @@
using System.Linq; using System.Linq;
using Content.Server.AI.Components; using Content.Server.AI.Components;
using Content.Server.MobState.States;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.MobState; using Content.Shared.MobState;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -121,11 +120,11 @@ namespace Content.Server.AI.EntitySystems
{ {
switch (args.CurrentMobState) switch (args.CurrentMobState)
{ {
case NormalMobState: case DamageState.Alive:
component.Awake = true; component.Awake = true;
break; break;
case CriticalMobState: case DamageState.Critical:
case DeadMobState: case DamageState.Dead:
component.Awake = false; component.Awake = false;
break; break;
} }

View File

@@ -5,6 +5,7 @@ using Content.Server.Body.Components;
using Content.Server.Body.Systems; using Content.Server.Body.Systems;
using Content.Server.Disease.Components; using Content.Server.Disease.Components;
using Content.Server.Disease; using Content.Server.Disease;
using Content.Server.MobState;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems; using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Administration; using Content.Shared.Administration;
@@ -57,7 +58,6 @@ namespace Content.Server.Administration.Commands
{ {
var targetUid = target; var targetUid = target;
var entMan = IoCManager.Resolve<IEntityManager>(); var entMan = IoCManager.Resolve<IEntityManager>();
entMan.GetComponentOrNull<MobStateComponent>(targetUid)?.UpdateState(0);
entMan.GetComponentOrNull<HungerComponent>(targetUid)?.ResetFood(); entMan.GetComponentOrNull<HungerComponent>(targetUid)?.ResetFood();
// TODO holy shit make this an event my man! // TODO holy shit make this an event my man!

View File

@@ -30,6 +30,7 @@ using Content.Shared.Disease;
using Content.Shared.Electrocution; using Content.Shared.Electrocution;
using Content.Shared.Interaction.Components; using Content.Shared.Interaction.Components;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.MobState;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.Movement.Components; using Content.Shared.Movement.Components;
using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.Components;

View File

@@ -7,6 +7,7 @@ using Content.Shared.Alert;
using Content.Shared.Buckle.Components; using Content.Shared.Buckle.Components;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Pulling.Components; using Content.Shared.Pulling.Components;
using Content.Shared.Standing; using Content.Shared.Standing;
@@ -323,7 +324,8 @@ namespace Content.Server.Buckle.Components
EntitySystem.Get<StandingStateSystem>().Stand(Owner); EntitySystem.Get<StandingStateSystem>().Stand(Owner);
} }
mobState?.CurrentState?.EnterState(Owner, _entMan); IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
.EnterState(mobState, mobState?.CurrentState);
UpdateBuckleStatus(); UpdateBuckleStatus();

View File

@@ -4,7 +4,6 @@ using Content.Server.Popups;
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.CharacterAppearance.Components; using Content.Shared.CharacterAppearance.Components;
using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components;
using Content.Shared.Damage;
using Content.Shared.MobState; using Content.Shared.MobState;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.Tag; using Content.Shared.Tag;
@@ -12,8 +11,6 @@ using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Player; using Robust.Shared.Player;
using System.Threading; using System.Threading;
using Content.Shared.MobState.State;
using Content.Shared.Doors.Components;
namespace Content.Server.Dragon namespace Content.Server.Dragon
{ {
@@ -24,7 +21,6 @@ namespace Content.Server.Dragon
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!; [Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -127,8 +123,8 @@ namespace Content.Server.Dragon
{ {
switch (targetState.CurrentState) switch (targetState.CurrentState)
{ {
case SharedCriticalMobState: case DamageState.Critical:
case SharedDeadMobState: case DamageState.Dead:
component.CancelToken = new CancellationTokenSource(); component.CancelToken = new CancellationTokenSource();
_doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.DevourTime, component.CancelToken.Token, target) _doAfterSystem.DoAfter(new DoAfterEventArgs(uid, component.DevourTime, component.CancelToken.Token, target)

View File

@@ -4,7 +4,6 @@ using Content.Server.Ghost.Components;
using Content.Server.Ghost.Roles.Components; using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.UI; using Content.Server.Ghost.Roles.UI;
using Content.Server.Mind.Components; using Content.Server.Mind.Components;
using Content.Server.MobState.States;
using Content.Server.Players; using Content.Server.Players;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.Database; using Content.Shared.Database;
@@ -57,14 +56,14 @@ namespace Content.Server.Ghost.Roles
{ {
switch (args.CurrentMobState) switch (args.CurrentMobState)
{ {
case NormalMobState: case DamageState.Alive:
{ {
if (!component.Taken) if (!component.Taken)
RegisterGhostRole(component); RegisterGhostRole(component);
break; break;
} }
case CriticalMobState: case DamageState.Critical:
case DeadMobState: case DamageState.Dead:
UnregisterGhostRole(component); UnregisterGhostRole(component);
break; break;
} }

View File

@@ -0,0 +1,16 @@
using Content.Shared.StatusEffect;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void EnterCritState(EntityUid uid)
{
base.EnterCritState(uid);
if (HasComp<StatusEffectsComponent>(uid))
{
Status.TryRemoveStatusEffect(uid, "Stun");
}
}
}

View File

@@ -0,0 +1,19 @@
using Content.Shared.Alert;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void EnterDeadState(EntityUid uid)
{
base.EnterDeadState(uid);
Alerts.ShowAlert(uid, AlertType.HumanDead);
if (HasComp<StatusEffectsComponent>(uid))
{
Status.TryRemoveStatusEffect(uid, "Stun");
}
}
}

View File

@@ -0,0 +1,29 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.MobState.Components;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem
{
public override void UpdateNormState(EntityUid entity, FixedPoint2 threshold)
{
base.UpdateNormState(entity, threshold);
if (!TryComp<DamageableComponent>(entity, out var damageable))
return;
if (!TryComp<MobStateComponent>(entity, out var stateComponent))
return;
short modifier = 0;
if (TryGetEarliestIncapacitatedState(stateComponent, threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0)
{
modifier = (short)(damageable.TotalDamage / (earliestThreshold / 5) + 1);
}
Alerts.ShowAlert(entity, AlertType.HumanHealth, modifier);
}
}

View File

@@ -0,0 +1,19 @@
using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
using Robust.Shared.GameStates;
namespace Content.Server.MobState;
public sealed partial class MobStateSystem : SharedMobStateSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MobStateComponent, ComponentGetState>(OnMobGetState);
}
private void OnMobGetState(EntityUid uid, MobStateComponent component, ref ComponentGetState args)
{
args.State = new MobStateComponentState(component.CurrentThreshold);
}
}

View File

@@ -1,18 +0,0 @@
using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState.States
{
public sealed class CriticalMobState : SharedCriticalMobState
{
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
if (entityManager.TryGetComponent(uid, out StatusEffectsComponent? stun))
{
EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(uid, "Stun");
}
}
}
}

View File

@@ -1,21 +0,0 @@
using Content.Shared.Alert;
using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
namespace Content.Server.MobState.States
{
public sealed class DeadMobState : SharedDeadMobState
{
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
EntitySystem.Get<AlertsSystem>().ShowAlert(uid, AlertType.HumanDead);
if (entityManager.TryGetComponent(uid, out StatusEffectsComponent? stun))
{
EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(uid, "Stun");
}
}
}
}

View File

@@ -1,34 +0,0 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.MobState.Components;
using Content.Shared.MobState.State;
namespace Content.Server.MobState.States
{
public sealed class NormalMobState : SharedNormalMobState
{
public override void UpdateState(EntityUid entity, FixedPoint2 threshold, IEntityManager entityManager)
{
base.UpdateState(entity, threshold, entityManager);
if (!entityManager.TryGetComponent(entity, out DamageableComponent? damageable))
{
return;
}
if (!entityManager.TryGetComponent(entity, out MobStateComponent? stateComponent))
{
return;
}
short modifier = 0;
if (stateComponent.TryGetEarliestIncapacitatedState(threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0)
{
modifier = (short)(damageable.TotalDamage / (earliestThreshold / 5) + 1);
}
EntitySystem.Get<AlertsSystem>().ShowAlert(entity, AlertType.HumanHealth, modifier);
}
}
}

View File

@@ -2,6 +2,7 @@ using System.Linq;
using Content.Shared.Damage.Prototypes; using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.MobState;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.Radiation.Events; using Content.Shared.Radiation.Events;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
@@ -256,7 +257,7 @@ namespace Content.Shared.Damage
int ent1DeadState = 0; int ent1DeadState = 0;
foreach (var state in oldstate._highestToLowestStates) foreach (var state in oldstate._highestToLowestStates)
{ {
if (state.Value.IsDead()) if (state.Value == DamageState.Dead)
{ {
ent1DeadState = state.Key; ent1DeadState = state.Key;
} }
@@ -265,7 +266,7 @@ namespace Content.Shared.Damage
int ent2DeadState = 0; int ent2DeadState = 0;
foreach (var state in newstate._highestToLowestStates) foreach (var state in newstate._highestToLowestStates)
{ {
if (state.Value.IsDead()) if (state.Value == DamageState.Dead)
{ {
ent2DeadState = state.Key; ent2DeadState = state.Key;
} }

View File

@@ -1,11 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.Alert;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.MobState.State; using Content.Shared.MobState.EntitySystems;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.MobState.Components namespace Content.Shared.MobState.Components
{ {
@@ -19,8 +16,6 @@ namespace Content.Shared.MobState.Components
[NetworkedComponent] [NetworkedComponent]
public sealed class MobStateComponent : Component public sealed class MobStateComponent : Component
{ {
[Dependency] private readonly IEntityManager _entMan = default!;
/// <summary> /// <summary>
/// States that this <see cref="MobStateComponent"/> mapped to /// States that this <see cref="MobStateComponent"/> mapped to
/// the amount of damage at which they are triggered. /// the amount of damage at which they are triggered.
@@ -30,294 +25,43 @@ namespace Content.Shared.MobState.Components
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
[DataField("thresholds")] [DataField("thresholds")]
private readonly SortedDictionary<int, IMobState> _lowestToHighestStates = new(); public readonly SortedDictionary<int, DamageState> _lowestToHighestStates = new();
// TODO Remove Nullability? // TODO Remove Nullability?
[ViewVariables] [ViewVariables]
public IMobState? CurrentState { get; private set; } public DamageState? CurrentState { get; set; }
[ViewVariables] [ViewVariables]
public FixedPoint2? CurrentThreshold { get; private set; } public FixedPoint2? CurrentThreshold { get; set; }
public IEnumerable<KeyValuePair<int, IMobState>> _highestToLowestStates => _lowestToHighestStates.Reverse(); public IEnumerable<KeyValuePair<int, DamageState>> _highestToLowestStates => _lowestToHighestStates.Reverse();
protected override void Startup()
{
base.Startup();
if (CurrentState != null && CurrentThreshold != null)
{
// Initialize with given states
SetMobState(null, (CurrentState, CurrentThreshold.Value));
}
else
{
// Initialize with some amount of damage, defaulting to 0.
UpdateState(_entMan.GetComponentOrNull<DamageableComponent>(Owner)?.TotalDamage ?? FixedPoint2.Zero);
}
}
protected override void OnRemove()
{
EntitySystem.Get<AlertsSystem>().ClearAlert(Owner, AlertType.HumanHealth);
base.OnRemove();
}
public override ComponentState GetComponentState()
{
return new MobStateComponentState(CurrentThreshold);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not MobStateComponentState state)
{
return;
}
if (CurrentThreshold == state.CurrentThreshold)
{
return;
}
if (state.CurrentThreshold == null)
{
RemoveState();
}
else
{
UpdateState(state.CurrentThreshold.Value);
}
}
[Obsolete("Use MobStateSystem")]
public bool IsAlive() public bool IsAlive()
{ {
return CurrentState?.IsAlive() ?? false; return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
.IsAlive(Owner, this);
} }
[Obsolete("Use MobStateSystem")]
public bool IsCritical() public bool IsCritical()
{ {
return CurrentState?.IsCritical() ?? false; return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
.IsCritical(Owner, this);
} }
[Obsolete("Use MobStateSystem")]
public bool IsDead() public bool IsDead()
{ {
return CurrentState?.IsDead() ?? false; return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
.IsDead(Owner, this);
} }
[Obsolete("Use MobStateSystem")]
public bool IsIncapacitated() public bool IsIncapacitated()
{ {
return CurrentState?.IsIncapacitated() ?? false; return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedMobStateSystem>()
} .IsIncapacitated(Owner, this);
public (IMobState state, FixedPoint2 threshold)? GetState(FixedPoint2 damage)
{
foreach (var (threshold, state) in _highestToLowestStates)
{
if (damage >= threshold)
{
return (state, threshold);
}
}
return null;
}
public bool TryGetState(
FixedPoint2 damage,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
var highestState = GetState(damage);
if (highestState == null)
{
state = default;
threshold = default;
return false;
}
(state, threshold) = highestState.Value;
return true;
}
private (IMobState state, FixedPoint2 threshold)? GetEarliestState(FixedPoint2 minimumDamage, Predicate<IMobState> predicate)
{
foreach (var (threshold, state) in _lowestToHighestStates)
{
if (threshold < minimumDamage ||
!predicate(state))
{
continue;
}
return (state, threshold);
}
return null;
}
private (IMobState state, FixedPoint2 threshold)? GetPreviousState(FixedPoint2 maximumDamage, Predicate<IMobState> predicate)
{
foreach (var (threshold, state) in _highestToLowestStates)
{
if (threshold > maximumDamage ||
!predicate(state))
{
continue;
}
return (state, threshold);
}
return null;
}
public (IMobState state, FixedPoint2 threshold)? GetEarliestCriticalState(FixedPoint2 minimumDamage)
{
return GetEarliestState(minimumDamage, s => s.IsCritical());
}
public (IMobState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(FixedPoint2 minimumDamage)
{
return GetEarliestState(minimumDamage, s => s.IsIncapacitated());
}
public (IMobState state, FixedPoint2 threshold)? GetEarliestDeadState(FixedPoint2 minimumDamage)
{
return GetEarliestState(minimumDamage, s => s.IsDead());
}
public (IMobState state, FixedPoint2 threshold)? GetPreviousCriticalState(FixedPoint2 minimumDamage)
{
return GetPreviousState(minimumDamage, s => s.IsCritical());
}
private bool TryGetState(
(IMobState state, FixedPoint2 threshold)? tuple,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
if (tuple == null)
{
state = default;
threshold = default;
return false;
}
(state, threshold) = tuple.Value;
return true;
}
public bool TryGetEarliestCriticalState(
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestCriticalState(minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetEarliestIncapacitatedState(
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestIncapacitatedState(minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetEarliestDeadState(
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestDeadState(minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetPreviousCriticalState(
FixedPoint2 maximumDamage,
[NotNullWhen(true)] out IMobState? state,
out FixedPoint2 threshold)
{
var earliestState = GetPreviousCriticalState(maximumDamage);
return TryGetState(earliestState, out state, out threshold);
}
private void RemoveState()
{
var old = CurrentState;
CurrentState = null;
CurrentThreshold = null;
SetMobState(old, null);
}
/// <summary>
/// Updates the mob state..
/// </summary>
public void UpdateState(FixedPoint2 damage)
{
if (!TryGetState(damage, out var newState, out var threshold))
{
return;
}
SetMobState(CurrentState, (newState, threshold));
}
/// <summary>
/// Sets the mob state and marks the component as dirty.
/// </summary>
private void SetMobState(IMobState? old, (IMobState state, FixedPoint2 threshold)? current)
{
var entMan = _entMan;
if (!current.HasValue)
{
old?.ExitState(Owner, entMan);
return;
}
var (state, threshold) = current.Value;
CurrentThreshold = threshold;
if (state == old)
{
state.UpdateState(Owner, threshold, entMan);
return;
}
old?.ExitState(Owner, entMan);
CurrentState = state;
state.EnterState(Owner, entMan);
state.UpdateState(Owner, threshold, entMan);
var message = new MobStateChangedEvent(this, old, state);
entMan.EventBus.RaiseLocalEvent(Owner, message, true);
Dirty();
}
}
[Serializable, NetSerializable]
public sealed class MobStateComponentState : ComponentState
{
public readonly FixedPoint2? CurrentThreshold;
public MobStateComponentState(FixedPoint2? currentThreshold)
{
CurrentThreshold = currentThreshold;
} }
} }
} }

View File

@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.MobState namespace Content.Shared.MobState
{ {
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum DamageStateVisuals public enum DamageStateVisuals : byte
{ {
State State
} }

View File

@@ -1,148 +0,0 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.MobState.Components;
using Content.Shared.MobState.State;
using Content.Shared.Movement;
using Content.Shared.Movement.Events;
using Content.Shared.Pulling.Events;
using Content.Shared.Speech;
using Content.Shared.Standing;
using Content.Shared.Throwing;
namespace Content.Shared.MobState.EntitySystems
{
public sealed class MobStateSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(OnChangeDirectionAttempt);
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(OnUseAttempt);
SubscribeLocalEvent<MobStateComponent, InteractionAttemptEvent>(OnInteractAttempt);
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(OnThrowAttempt);
SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<MobStateComponent, EmoteAttemptEvent>(OnEmoteAttempt);
SubscribeLocalEvent<MobStateComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
SubscribeLocalEvent<MobStateComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<MobStateComponent, PickupAttemptEvent>(OnPickupAttempt);
SubscribeLocalEvent<MobStateComponent, StartPullAttemptEvent>(OnStartPullAttempt);
SubscribeLocalEvent<MobStateComponent, DamageChangedEvent>(UpdateState);
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(OnStandAttempt);
SubscribeLocalEvent<MobStateChangedEvent>(OnStateChanged);
// Note that there's no check for Down attempts because if a mob's in crit or dead, they can be downed...
}
#region ActionBlocker
private void OnStateChanged(MobStateChangedEvent ev)
{
_blocker.UpdateCanMove(ev.Entity);
}
private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args)
{
switch (component.CurrentState)
{
case SharedDeadMobState:
case SharedCriticalMobState:
args.Cancel();
break;
}
}
private void OnChangeDirectionAttempt(EntityUid uid, MobStateComponent component, ChangeDirectionAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnUseAttempt(EntityUid uid, MobStateComponent component, UseAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnInteractAttempt(EntityUid uid, MobStateComponent component, InteractionAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnThrowAttempt(EntityUid uid, MobStateComponent component, ThrowAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnSpeakAttempt(EntityUid uid, MobStateComponent component, SpeakAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnEquipAttempt(EntityUid uid, MobStateComponent component, IsEquippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Equipee == uid)
CheckAct(uid, component, args);
}
private void OnEmoteAttempt(EntityUid uid, MobStateComponent component, EmoteAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnUnequipAttempt(EntityUid uid, MobStateComponent component, IsUnequippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Unequipee == uid)
CheckAct(uid, component, args);
}
private void OnDropAttempt(EntityUid uid, MobStateComponent component, DropAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnPickupAttempt(EntityUid uid, MobStateComponent component, PickupAttemptEvent args)
{
CheckAct(uid, component, args);
}
#endregion
private void OnStartPullAttempt(EntityUid uid, MobStateComponent component, StartPullAttemptEvent args)
{
if (component.IsIncapacitated())
args.Cancel();
}
public void UpdateState(EntityUid _, MobStateComponent component, DamageChangedEvent args)
{
component.UpdateState(args.Damageable.TotalDamage);
}
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args)
{
switch (component.CurrentState)
{
case SharedCriticalMobState:
case SharedDeadMobState:
args.Cancel();
return;
default:
return;
}
}
private void OnStandAttempt(EntityUid uid, MobStateComponent component, StandAttemptEvent args)
{
if (component.IsIncapacitated())
args.Cancel();
}
}
}

View File

@@ -0,0 +1,26 @@
using Content.Shared.Alert;
using Content.Shared.FixedPoint;
namespace Content.Shared.MobState.EntitySystems;
public abstract partial class SharedMobStateSystem
{
public virtual void EnterCritState(EntityUid uid)
{
Alerts.ShowAlert(uid, AlertType.HumanCrit);
Standing.Down(uid);
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
}
}
public virtual void ExitCritState(EntityUid uid)
{
Standing.Stand(uid);
}
public virtual void UpdateCritState(EntityUid entity, FixedPoint2 threshold) {}
}

View File

@@ -0,0 +1,36 @@
using Content.Shared.FixedPoint;
namespace Content.Shared.MobState.EntitySystems;
public abstract partial class SharedMobStateSystem
{
public virtual void EnterDeadState(EntityUid uid)
{
EnsureComp<CollisionWakeComponent>(uid);
Standing.Down(uid);
if (Standing.IsDown(uid) && TryComp<PhysicsComponent>(uid, out var physics))
{
physics.CanCollide = false;
}
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
}
}
public virtual void ExitDeadState(EntityUid uid)
{
RemComp<CollisionWakeComponent>(uid);
Standing.Stand(uid);
if (!Standing.IsDown(uid) && TryComp<PhysicsComponent>(uid, out var physics))
{
physics.CanCollide = true;
}
}
public virtual void UpdateDeadState(EntityUid entity, FixedPoint2 threshold) {}
}

View File

@@ -0,0 +1,20 @@
using Content.Shared.FixedPoint;
namespace Content.Shared.MobState.EntitySystems;
public abstract partial class SharedMobStateSystem
{
public virtual void EnterNormState(EntityUid uid)
{
Standing.Stand(uid);
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Alive);
}
}
public virtual void UpdateNormState(EntityUid entity, FixedPoint2 threshold) {}
public virtual void ExitNormState(EntityUid uid) {}
}

View File

@@ -0,0 +1,473 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.MobState.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Pulling.Events;
using Content.Shared.Speech;
using Content.Shared.Standing;
using Content.Shared.StatusEffect;
using Content.Shared.Throwing;
using Robust.Shared.Serialization;
namespace Content.Shared.MobState.EntitySystems
{
public abstract partial class SharedMobStateSystem : EntitySystem
{
[Dependency] protected readonly AlertsSystem Alerts = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] protected readonly StandingStateSystem Standing = default!;
[Dependency] protected readonly StatusEffectsSystem Status = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MobStateComponent, ComponentShutdown>(OnMobShutdown);
SubscribeLocalEvent<MobStateComponent, ComponentStartup>(OnMobStartup);
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(OnChangeDirectionAttempt);
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(OnUseAttempt);
SubscribeLocalEvent<MobStateComponent, InteractionAttemptEvent>(OnInteractAttempt);
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(OnThrowAttempt);
SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<MobStateComponent, EmoteAttemptEvent>(OnEmoteAttempt);
SubscribeLocalEvent<MobStateComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
SubscribeLocalEvent<MobStateComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<MobStateComponent, PickupAttemptEvent>(OnPickupAttempt);
SubscribeLocalEvent<MobStateComponent, StartPullAttemptEvent>(OnStartPullAttempt);
SubscribeLocalEvent<MobStateComponent, DamageChangedEvent>(UpdateState);
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(OnStandAttempt);
SubscribeLocalEvent<MobStateChangedEvent>(OnStateChanged);
// Note that there's no check for Down attempts because if a mob's in crit or dead, they can be downed...
}
private void OnMobStartup(EntityUid uid, MobStateComponent component, ComponentStartup args)
{
if (component.CurrentState != null && component.CurrentThreshold != null)
{
// Initialize with given states
SetMobState(component, null, (component.CurrentState.Value, component.CurrentThreshold.Value));
}
else
{
// Initialize with some amount of damage, defaulting to 0.
UpdateState(component, CompOrNull<DamageableComponent>(uid)?.TotalDamage ?? FixedPoint2.Zero);
}
}
private void OnMobShutdown(EntityUid uid, MobStateComponent component, ComponentShutdown args)
{
Alerts.ClearAlert(uid, AlertType.HumanHealth);
}
public bool IsAlive(EntityUid uid, MobStateComponent? component = null)
{
if (!Resolve(uid, ref component, false)) return false;
return component.CurrentState == DamageState.Alive;
}
public bool IsCritical(EntityUid uid, MobStateComponent? component = null)
{
if (!Resolve(uid, ref component, false)) return false;
return component.CurrentState == DamageState.Critical;
}
public bool IsDead(EntityUid uid, MobStateComponent? component = null)
{
if (!Resolve(uid, ref component, false)) return false;
return component.CurrentState == DamageState.Dead;
}
public bool IsIncapacitated(EntityUid uid, MobStateComponent? component = null)
{
if (!Resolve(uid, ref component, false)) return false;
return component.CurrentState is DamageState.Critical or DamageState.Dead;
}
#region ActionBlocker
private void OnStateChanged(MobStateChangedEvent ev)
{
_blocker.UpdateCanMove(ev.Entity);
}
private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args)
{
switch (component.CurrentState)
{
case DamageState.Dead:
case DamageState.Critical:
args.Cancel();
break;
}
}
private void OnChangeDirectionAttempt(EntityUid uid, MobStateComponent component, ChangeDirectionAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnUseAttempt(EntityUid uid, MobStateComponent component, UseAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnInteractAttempt(EntityUid uid, MobStateComponent component, InteractionAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnThrowAttempt(EntityUid uid, MobStateComponent component, ThrowAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnSpeakAttempt(EntityUid uid, MobStateComponent component, SpeakAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnEquipAttempt(EntityUid uid, MobStateComponent component, IsEquippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Equipee == uid)
CheckAct(uid, component, args);
}
private void OnEmoteAttempt(EntityUid uid, MobStateComponent component, EmoteAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnUnequipAttempt(EntityUid uid, MobStateComponent component, IsUnequippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Unequipee == uid)
CheckAct(uid, component, args);
}
private void OnDropAttempt(EntityUid uid, MobStateComponent component, DropAttemptEvent args)
{
CheckAct(uid, component, args);
}
private void OnPickupAttempt(EntityUid uid, MobStateComponent component, PickupAttemptEvent args)
{
CheckAct(uid, component, args);
}
#endregion
private void OnStartPullAttempt(EntityUid uid, MobStateComponent component, StartPullAttemptEvent args)
{
if (IsIncapacitated(uid, component))
args.Cancel();
}
public void UpdateState(EntityUid _, MobStateComponent component, DamageChangedEvent args)
{
UpdateState(component, args.Damageable.TotalDamage);
}
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args)
{
switch (component.CurrentState)
{
case DamageState.Critical:
case DamageState.Dead:
args.Cancel();
return;
default:
return;
}
}
private void OnStandAttempt(EntityUid uid, MobStateComponent component, StandAttemptEvent args)
{
if (IsIncapacitated(uid, component))
args.Cancel();
}
public virtual void RemoveState(MobStateComponent component)
{
var old = component.CurrentState;
component.CurrentState = null;
component.CurrentThreshold = null;
SetMobState(component, old, null);
}
public virtual void EnterState(MobStateComponent? component, DamageState? state)
{
// TODO: Thanks buckle
if (component == null) return;
switch (state)
{
case DamageState.Alive:
EnterNormState(component.Owner);
break;
case DamageState.Critical:
EnterCritState(component.Owner);
break;
case DamageState.Dead:
EnterDeadState(component.Owner);
break;
case null:
break;
default:
throw new NotImplementedException();
}
}
protected virtual void UpdateState(MobStateComponent component, DamageState? state, FixedPoint2 threshold)
{
switch (state)
{
case DamageState.Alive:
UpdateNormState(component.Owner, threshold);
break;
case DamageState.Critical:
UpdateCritState(component.Owner, threshold);
break;
case DamageState.Dead:
UpdateDeadState(component.Owner, threshold);
break;
case null:
break;
default:
throw new NotImplementedException();
}
}
protected virtual void ExitState(MobStateComponent component, DamageState? state)
{
switch (state)
{
case DamageState.Alive:
ExitNormState(component.Owner);
break;
case DamageState.Critical:
ExitCritState(component.Owner);
break;
case DamageState.Dead:
ExitDeadState(component.Owner);
break;
case null:
break;
default:
throw new NotImplementedException();
}
}
/// <summary>
/// Updates the mob state..
/// </summary>
public void UpdateState(MobStateComponent component, FixedPoint2 damage)
{
if (!TryGetState(component, damage, out var newState, out var threshold))
{
return;
}
SetMobState(component, component.CurrentState, (newState.Value, threshold));
}
/// <summary>
/// Sets the mob state and marks the component as dirty.
/// </summary>
private void SetMobState(MobStateComponent component, DamageState? old, (DamageState state, FixedPoint2 threshold)? current)
{
if (!current.HasValue)
{
ExitState(component, old);
return;
}
var (state, threshold) = current.Value;
component.CurrentThreshold = threshold;
if (state == old)
{
UpdateState(component, state, threshold);
return;
}
ExitState(component, old);
component.CurrentState = state;
EnterState(component, state);
UpdateState(component, state, threshold);
var message = new MobStateChangedEvent(component, old, state);
RaiseLocalEvent(component.Owner, message, true);
Dirty(component);
}
public (DamageState state, FixedPoint2 threshold)? GetState(MobStateComponent component, FixedPoint2 damage)
{
foreach (var (threshold, state) in component._highestToLowestStates)
{
if (damage >= threshold)
{
return (state, threshold);
}
}
return null;
}
public bool TryGetState(
MobStateComponent component,
FixedPoint2 damage,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
var highestState = GetState(component, damage);
if (highestState == null)
{
state = default;
threshold = default;
return false;
}
(state, threshold) = highestState.Value;
return true;
}
private (DamageState state, FixedPoint2 threshold)? GetEarliestState(MobStateComponent component, FixedPoint2 minimumDamage, Predicate<DamageState> predicate)
{
foreach (var (threshold, state) in component._lowestToHighestStates)
{
if (threshold < minimumDamage ||
!predicate(state))
{
continue;
}
return (state, threshold);
}
return null;
}
private (DamageState state, FixedPoint2 threshold)? GetPreviousState(MobStateComponent component, FixedPoint2 maximumDamage, Predicate<DamageState> predicate)
{
foreach (var (threshold, state) in component._highestToLowestStates)
{
if (threshold > maximumDamage ||
!predicate(state))
{
continue;
}
return (state, threshold);
}
return null;
}
public (DamageState state, FixedPoint2 threshold)? GetEarliestCriticalState(MobStateComponent component, FixedPoint2 minimumDamage)
{
return GetEarliestState(component, minimumDamage, s => s == DamageState.Critical);
}
public (DamageState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(MobStateComponent component, FixedPoint2 minimumDamage)
{
return GetEarliestState(component, minimumDamage, s => s is DamageState.Critical or DamageState.Dead);
}
public (DamageState state, FixedPoint2 threshold)? GetEarliestDeadState(MobStateComponent component, FixedPoint2 minimumDamage)
{
return GetEarliestState(component, minimumDamage, s => s == DamageState.Dead);
}
public (DamageState state, FixedPoint2 threshold)? GetPreviousCriticalState(MobStateComponent component, FixedPoint2 minimumDamage)
{
return GetPreviousState(component, minimumDamage, s => s == DamageState.Critical);
}
private bool TryGetState(
(DamageState state, FixedPoint2 threshold)? tuple,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
if (tuple == null)
{
state = default;
threshold = default;
return false;
}
(state, threshold) = tuple.Value;
return true;
}
public bool TryGetEarliestCriticalState(
MobStateComponent component,
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestCriticalState(component, minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetEarliestIncapacitatedState(
MobStateComponent component,
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestIncapacitatedState(component, minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetEarliestDeadState(
MobStateComponent component,
FixedPoint2 minimumDamage,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
var earliestState = GetEarliestDeadState(component, minimumDamage);
return TryGetState(earliestState, out state, out threshold);
}
public bool TryGetPreviousCriticalState(
MobStateComponent component,
FixedPoint2 maximumDamage,
[NotNullWhen(true)] out DamageState? state,
out FixedPoint2 threshold)
{
var earliestState = GetPreviousCriticalState(component, maximumDamage);
return TryGetState(earliestState, out state, out threshold);
}
[Serializable, NetSerializable]
protected sealed class MobStateComponentState : ComponentState
{
public readonly FixedPoint2? CurrentThreshold;
public MobStateComponentState(FixedPoint2? currentThreshold)
{
CurrentThreshold = currentThreshold;
}
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.MobState.State;
namespace Content.Shared.MobState namespace Content.Shared.MobState
{ {
@@ -7,8 +6,8 @@ namespace Content.Shared.MobState
{ {
public MobStateChangedEvent( public MobStateChangedEvent(
MobStateComponent component, MobStateComponent component,
IMobState? oldMobState, DamageState? oldMobState,
IMobState currentMobState) DamageState currentMobState)
{ {
Component = component; Component = component;
OldMobState = oldMobState; OldMobState = oldMobState;
@@ -19,8 +18,35 @@ namespace Content.Shared.MobState
public MobStateComponent Component { get; } public MobStateComponent Component { get; }
public IMobState? OldMobState { get; } public DamageState? OldMobState { get; }
public IMobState CurrentMobState { get; } public DamageState CurrentMobState { get; }
}
public static class A
{
[Obsolete("Just check for the enum value instead")]
public static bool IsAlive(this DamageState state)
{
return state == DamageState.Alive;
}
[Obsolete("Just check for the enum value instead")]
public static bool IsCritical(this DamageState state)
{
return state == DamageState.Critical;
}
[Obsolete("Just check for the enum value instead")]
public static bool IsDead(this DamageState state)
{
return state == DamageState.Dead;
}
[Obsolete("Just check for the enum value instead")]
public static bool IsIncapacitated(this DamageState state)
{
return state is DamageState.Dead or DamageState.Critical;
}
} }
} }

View File

@@ -1,36 +0,0 @@
using Content.Shared.FixedPoint;
namespace Content.Shared.MobState.State
{
[ImplicitDataDefinitionForInheritors]
public abstract class BaseMobState : IMobState
{
protected abstract DamageState DamageState { get; }
public virtual bool IsAlive()
{
return DamageState == DamageState.Alive;
}
public virtual bool IsCritical()
{
return DamageState == DamageState.Critical;
}
public virtual bool IsDead()
{
return DamageState == DamageState.Dead;
}
public virtual bool IsIncapacitated()
{
return IsCritical() || IsDead();
}
public virtual void EnterState(EntityUid uid, IEntityManager entityManager) { }
public virtual void ExitState(EntityUid uid, IEntityManager entityManager) { }
public virtual void UpdateState(EntityUid entity, FixedPoint2 threshold, IEntityManager entityManager) { }
}
}

View File

@@ -1,40 +0,0 @@
using Content.Shared.FixedPoint;
namespace Content.Shared.MobState.State
{
/// <summary>
/// Defines the blocking effects of an associated <see cref="DamageState"/>
/// (i.e. Normal, Critical, Dead) and what effects to apply upon entering or
/// exiting the state.
/// </summary>
public interface IMobState
{
bool IsAlive();
bool IsCritical();
bool IsDead();
/// <summary>
/// Checks if the mob is in a critical or dead state.
/// See <see cref="IsCritical"/> and <see cref="IsDead"/>.
/// </summary>
/// <returns>true if it is, false otherwise.</returns>
bool IsIncapacitated();
/// <summary>
/// Called when this state is entered.
/// </summary>
void EnterState(EntityUid uid, IEntityManager entityManager);
/// <summary>
/// Called when this state is left for a different state.
/// </summary>
void ExitState(EntityUid uid, IEntityManager entityManager);
/// <summary>
/// Called when this state is updated.
/// </summary>
void UpdateState(EntityUid entity, FixedPoint2 threshold, IEntityManager entityManager);
}
}

View File

@@ -1,34 +0,0 @@
using Content.Shared.Alert;
using Content.Shared.Standing;
namespace Content.Shared.MobState.State
{
/// <summary>
/// A state in which an entity is disabled from acting due to sufficient damage (considered unconscious).
/// </summary>
public abstract class SharedCriticalMobState : BaseMobState
{
protected override DamageState DamageState => DamageState.Critical;
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
EntitySystem.Get<AlertsSystem>().ShowAlert(uid, AlertType.HumanCrit); // TODO: combine humancrit-0 and humancrit-1 into a gif and display it
EntitySystem.Get<StandingStateSystem>().Down(uid);
if (entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
}
}
public override void ExitState(EntityUid uid, IEntityManager entityManager)
{
base.ExitState(uid, entityManager);
EntitySystem.Get<StandingStateSystem>().Stand(uid);
}
}
}

View File

@@ -1,44 +0,0 @@
using Content.Shared.Standing;
namespace Content.Shared.MobState.State
{
public abstract class SharedDeadMobState : BaseMobState
{
protected override DamageState DamageState => DamageState.Dead;
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
entityManager.EnsureComponent<CollisionWakeComponent>(uid);
var standingState = EntitySystem.Get<StandingStateSystem>();
standingState.Down(uid);
if (standingState.IsDown(uid) && entityManager.TryGetComponent(uid, out PhysicsComponent? physics))
{
physics.CanCollide = false;
}
if (entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
}
}
public override void ExitState(EntityUid uid, IEntityManager entityManager)
{
base.ExitState(uid, entityManager);
if (entityManager.HasComponent<CollisionWakeComponent>(uid))
{
entityManager.RemoveComponent<CollisionWakeComponent>(uid);
}
var standingState = EntitySystem.Get<StandingStateSystem>();
standingState.Stand(uid);
if (!standingState.IsDown(uid) && entityManager.TryGetComponent(uid, out PhysicsComponent? physics))
{
physics.CanCollide = true;
}
}
}
}

View File

@@ -1,24 +0,0 @@
using Content.Shared.Standing;
namespace Content.Shared.MobState.State
{
/// <summary>
/// The standard state an entity is in; no negative effects.
/// </summary>
public abstract class SharedNormalMobState : BaseMobState
{
protected override DamageState DamageState => DamageState.Alive;
public override void EnterState(EntityUid uid, IEntityManager entityManager)
{
base.EnterState(uid, entityManager);
EntitySystem.Get<StandingStateSystem>().Stand(uid);
if (entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Alive);
}
}
}
}

View File

@@ -68,7 +68,7 @@
- type: Actions - type: Actions
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
# criticalThreshold: 50 # criticalThreshold: 50
# deadThreshold: 120 # deadThreshold: 120

View File

@@ -95,9 +95,9 @@
- FlyingMobLayer - FlyingMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
5: !type:CriticalMobState {} 5: Critical
10: !type:DeadMobState {} 10: Dead
- type: Appearance - type: Appearance
- type: DamageStateVisuals - type: DamageStateVisuals
rotate: true rotate: true
@@ -310,9 +310,9 @@
- FlyingMobLayer - FlyingMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
5: !type:CriticalMobState {} 5: Critical
10: !type:DeadMobState {} 10: Dead
- type: RandomSpriteColor - type: RandomSpriteColor
state: butterfly state: butterfly
colors: colors:
@@ -763,9 +763,9 @@
- SmallMobLayer - SmallMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
10: !type:CriticalMobState {} 10: Critical
20: !type:DeadMobState {} 20: Dead
- type: MovementSpeedModifier - type: MovementSpeedModifier
baseWalkSpeed : 5 baseWalkSpeed : 5
baseSprintSpeed : 5 baseSprintSpeed : 5

View File

@@ -32,8 +32,8 @@
- type: MovementIgnoreGravity - type: MovementIgnoreGravity
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
150: !type:DeadMobState {} 150: Dead
- type: Appearance - type: Appearance
- type: DamageStateVisuals - type: DamageStateVisuals
states: states:

View File

@@ -37,9 +37,9 @@
- MobLayer - MobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
50: !type:CriticalMobState {} 50: Critical
100: !type:DeadMobState {} 100: Dead
- type: MovementIgnoreGravity - type: MovementIgnoreGravity
- type: Appearance - type: Appearance
- type: DamageStateVisuals - type: DamageStateVisuals

View File

@@ -37,9 +37,9 @@
- MobLayer - MobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
150: !type:CriticalMobState {} 150: Critical
200: !type:DeadMobState {} 200: Dead
- type: MeleeWeapon - type: MeleeWeapon
range: 1 range: 1
arcwidth: 0 arcwidth: 0
@@ -156,9 +156,9 @@
- SmallMobLayer - SmallMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
30: !type:CriticalMobState {} 30: Critical
60: !type:DeadMobState {} 60: Dead
- type: MeleeWeapon - type: MeleeWeapon
range: 1 range: 1
arcwidth: 0 arcwidth: 0

View File

@@ -92,9 +92,9 @@
Heat : 0.1 #per second, scales with temperature & other constants Heat : 0.1 #per second, scales with temperature & other constants
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
50: !type:CriticalMobState {} 50: Critical
100: !type:DeadMobState {} 100: Dead
- type: Destructible - type: Destructible
thresholds: thresholds:
- trigger: - trigger:

View File

@@ -36,8 +36,8 @@
- SmallMobLayer - SmallMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
15: !type:DeadMobState {} 15: Dead
- type: MovementIgnoreGravity - type: MovementIgnoreGravity
- type: Appearance - type: Appearance
- type: DamageStateVisuals - type: DamageStateVisuals

View File

@@ -50,8 +50,8 @@
- MobLayer - MobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
200: !type:DeadMobState {} 200: Dead
- type: Bloodstream - type: Bloodstream
bloodReagent: FluorosulfuricAcid bloodReagent: FluorosulfuricAcid
bloodlossDamage: bloodlossDamage:
@@ -121,8 +121,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
300: !type:DeadMobState {} 300: Dead
- type: SlowOnDamage - type: SlowOnDamage
speedModifierThresholds: speedModifierThresholds:
250: 0.7 250: 0.7
@@ -151,8 +151,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
200: !type:DeadMobState {} 200: Dead
- type: MovementSpeedModifier - type: MovementSpeedModifier
baseWalkSpeed : 3.0 baseWalkSpeed : 3.0
baseSprintSpeed : 5.5 baseSprintSpeed : 5.5
@@ -184,8 +184,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
1500: !type:DeadMobState {} 1500: Dead
- type: MovementSpeedModifier - type: MovementSpeedModifier
baseWalkSpeed : 2.8 baseWalkSpeed : 2.8
baseSprintSpeed : 3.8 baseSprintSpeed : 3.8
@@ -222,8 +222,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
550: !type:DeadMobState {} 550: Dead
- type: MovementSpeedModifier - type: MovementSpeedModifier
baseWalkSpeed : 2.3 baseWalkSpeed : 2.3
baseSprintSpeed : 4.2 baseSprintSpeed : 4.2
@@ -260,8 +260,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
250: !type:DeadMobState {} 250: Dead
- type: MovementSpeedModifier - type: MovementSpeedModifier
baseWalkSpeed : 2.7 baseWalkSpeed : 2.7
baseSprintSpeed : 6.0 baseSprintSpeed : 6.0
@@ -308,8 +308,8 @@
state: running state: running
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
300: !type:DeadMobState {} 300: Dead
- type: SlowOnDamage - type: SlowOnDamage
speedModifierThresholds: speedModifierThresholds:
250: 0.4 250: 0.4

View File

@@ -55,9 +55,9 @@
- FlyingMobLayer - FlyingMobLayer
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
450: !type:CriticalMobState {} 450: Critical
500: !type:DeadMobState {} 500: Dead
- type: Metabolizer - type: Metabolizer
solutionOnBody: false solutionOnBody: false
updateFrequency: 0.25 updateFrequency: 0.25

View File

@@ -56,9 +56,9 @@
interactFailureString: petting-failure-corrupted-corgi interactFailureString: petting-failure-corrupted-corgi
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
80: !type:CriticalMobState {} 80: Critical
160: !type:DeadMobState {} 160: Dead
- type: Grammar - type: Grammar
attributes: attributes:
gender: male gender: male

View File

@@ -50,7 +50,7 @@
damageContainer: Biological damageContainer: Biological
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
- type: HeatResistance - type: HeatResistance
- type: CombatMode - type: CombatMode
- type: Internals - type: Internals

View File

@@ -96,8 +96,8 @@
baseSprintSpeed : 5 baseSprintSpeed : 5
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
60: !type:DeadMobState {} 60: Dead
- type: Flashable - type: Flashable
- type: NoSlip - type: NoSlip
- type: StatusEffects - type: StatusEffects
@@ -190,8 +190,8 @@
baseSprintSpeed : 2 baseSprintSpeed : 2
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
1000: !type:DeadMobState {} 1000: Dead
- type: Sprite - type: Sprite
drawdepth: Mobs drawdepth: Mobs
netsync: false netsync: false

View File

@@ -235,9 +235,9 @@
- type: Internals - type: Internals
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
100: !type:CriticalMobState {} 100: Critical
200: !type:DeadMobState {} 200: Dead
- type: Destructible - type: Destructible
thresholds: thresholds:
- trigger: - trigger:
@@ -442,9 +442,9 @@
damageContainer: Biological damageContainer: Biological
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
100: !type:CriticalMobState {} 100: Critical
200: !type:DeadMobState {} 200: Dead
- type: Appearance - type: Appearance
visuals: visuals:
- type: RotationVisualizer - type: RotationVisualizer

View File

@@ -185,8 +185,8 @@
- type: Internals - type: Internals
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
100: !type:DeadMobState {} 100: Dead
- type: Destructible - type: Destructible
thresholds: thresholds:
- trigger: - trigger:

View File

@@ -47,7 +47,7 @@
# Note that the personal AI never "dies". # Note that the personal AI never "dies".
- type: MobState - type: MobState
thresholds: thresholds:
0: !type:NormalMobState {} 0: Alive
- type: Appearance - type: Appearance
visuals: visuals:
- type: GenericEnumVisualizer - type: GenericEnumVisualizer

View File

@@ -1,25 +1,36 @@
//This shader defines two circles - everything inside the inner circle will be darkened, while everything outside the outer circle // Has 2 circles, an inner one that is unaffected and an outer one. Anything past the outer one is full red
//will be full black. Between the inner and outer circle it LERPs from the inner darkness to full black. // and in-between is a gradient.
light_mode unshaded; light_mode unshaded;
const highp float darknessAlphaInner = 0.6; uniform highp vec3 color;
const highp float innerCircleRadius = 40.0; //Note: this is in pixels uniform highp float time;
const highp float outerCircleRadius = 80.0; // Uniforms because it makes testing way easier. If needed make it const.
uniform highp float outerCircleRadius;
uniform highp float outerCircleMaxRadius;
uniform highp float innerCircleRadius;
uniform highp float innerCircleMaxRadius;
uniform highp float darknessAlphaOuter;
const highp float darknessAlphaInner = 0.0;
void fragment() { void fragment() {
highp vec2 pixelSize = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); highp vec2 pixelSize = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y);
highp vec2 pixelCenter = pixelSize*0.5; highp vec2 pixelCenter = pixelSize*0.5;
highp float distance = length(FRAGCOORD.xy - pixelCenter); highp float distance = length(FRAGCOORD.xy - pixelCenter);
if(distance > outerCircleRadius){
COLOR = vec4(0.0, 0.0, 0.0, 1.0); highp float innerRadius = innerCircleRadius + time * (innerCircleMaxRadius - innerCircleRadius);
highp float outerRadius = outerCircleRadius + time * (outerCircleMaxRadius - outerCircleRadius);
if(distance > outerRadius) {
COLOR = vec4(color.x, color.y, color.z, darknessAlphaOuter);
} }
else if(distance < innerCircleRadius){ else if(distance < innerRadius) {
COLOR = vec4(0.0, 0.0, 0.0, darknessAlphaInner); COLOR = vec4(0.0, 0.0, 0.0, darknessAlphaInner);
} }
else{ else {
highp float intensity = (distance-innerCircleRadius)/(outerCircleRadius-innerCircleRadius); highp float ratio = (distance - innerRadius) / (outerRadius - innerRadius);
COLOR = vec4(0.0, 0.0, 0.0, (1.0-intensity)*darknessAlphaInner + intensity); highp float alpha = darknessAlphaInner + (darknessAlphaOuter - darknessAlphaInner) * ratio;
COLOR = vec4(color.x, color.y, color.z, alpha);
} }
} }