As discussed on the Discord, xenos are not humans (#1840)

* As discussed on the Discord, xenos are not humans

* Add living component for living beings without a defined body

* Merge LivingDamageable and Damageable components

* Fix ruinable and state manager inconsistencies

* Fix ruinable exposedata

* Fix new destructibles yamls

* Fix healing not healing

* Fix alive not being a valid state

* Fix valid state checking
This commit is contained in:
DrSmugleaf
2020-08-22 13:40:22 +02:00
committed by GitHub
parent f7c71b500f
commit bb923aa230
32 changed files with 175 additions and 108 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
@@ -11,15 +10,6 @@ namespace Content.Shared.GameObjects.Components.Body
public override string Name => "BodyManager";
public override uint? NetID => ContentNetIDs.BODY_MANAGER;
public override List<DamageState> SupportedDamageStates => new List<DamageState> {DamageState.Alive, DamageState.Critical, DamageState.Dead};
public override DamageState CurrentDamageState =>
CurrentDamageState = TotalDamage > 200
? DamageState.Dead
: TotalDamage > 100
? DamageState.Critical
: DamageState.Alive;
}
[Serializable, NetSerializable]

View File

@@ -27,15 +27,62 @@ namespace Content.Shared.GameObjects.Components.Damage
public override string Name => "Damageable";
public event Action<HealthChangedEventArgs> HealthChangedEvent = default!;
private DamageState _currentDamageState;
public event Action<HealthChangedEventArgs>? HealthChangedEvent;
/// <summary>
/// The threshold of damage, if any, above which the entity enters crit.
/// -1 means that this entity cannot go into crit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int? CriticalThreshold { get; set; }
/// <summary>
/// The threshold of damage, if any, above which the entity dies.
/// -1 means that this entity cannot die.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int? DeadThreshold { get; set; }
[ViewVariables] private ResistanceSet Resistance { get; set; } = default!;
[ViewVariables] private DamageContainer Damage { get; set; } = default!;
public virtual List<DamageState> SupportedDamageStates => new List<DamageState> {DamageState.Alive};
public virtual List<DamageState> SupportedDamageStates
{
get
{
var states = new List<DamageState> {DamageState.Alive};
public virtual DamageState CurrentDamageState { get; protected set; } = DamageState.Alive;
if (CriticalThreshold != null)
{
states.Add(DamageState.Critical);
}
if (DeadThreshold != null)
{
states.Add(DamageState.Dead);
}
return states;
}
}
public virtual DamageState CurrentDamageState
{
get => _currentDamageState;
set
{
var old = _currentDamageState;
_currentDamageState = value;
if (old != value)
{
EnterState(value);
}
}
}
[ViewVariables] public int TotalDamage => Damage.TotalDamage;
@@ -47,6 +94,18 @@ namespace Content.Shared.GameObjects.Components.Damage
{
base.ExposeData(serializer);
serializer.DataReadWriteFunction(
"criticalThreshold",
-1,
t => CriticalThreshold = t == -1 ? (int?) null : t,
() => CriticalThreshold ?? -1);
serializer.DataReadWriteFunction(
"deadThreshold",
-1,
t => DeadThreshold = t == -1 ? (int?) null : t,
() => DeadThreshold ?? -1);
if (serializer.Reading)
{
// Doesn't write to file, TODO?
@@ -75,6 +134,16 @@ namespace Content.Shared.GameObjects.Components.Damage
}
}
public override void Initialize()
{
base.Initialize();
foreach (var behavior in Owner.GetAllComponents<IOnHealthChangedBehavior>())
{
HealthChangedEvent += behavior.OnHealthChanged;
}
}
public bool TryGetDamage(DamageType type, out int damage)
{
return Damage.TryGetDamageValue(type, out damage);
@@ -218,10 +287,26 @@ namespace Content.Shared.GameObjects.Components.Damage
OnHealthChanged(args);
}
protected virtual void EnterState(DamageState state) { }
protected virtual void OnHealthChanged(HealthChangedEventArgs e)
{
if (DeadThreshold != -1 && TotalDamage > DeadThreshold)
{
CurrentDamageState = DamageState.Dead;
}
else if (CriticalThreshold != -1 && TotalDamage > CriticalThreshold)
{
CurrentDamageState = DamageState.Critical;
}
else
{
CurrentDamageState = DamageState.Alive;
}
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, e);
HealthChangedEvent?.Invoke(e);
Dirty();
}
}