Add composite destructible thresholds (#3102)
* Add composite destructible thresholds * Reorder yaml properties * Update YAML * Fix YAML * Re-fix YAML * Add missing nullable enable * Go back window component is explosive * rider
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when all of its triggers have activated.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AndTrigger : IThresholdTrigger
|
||||
{
|
||||
public List<IThresholdTrigger> Triggers { get; set; } = new();
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Triggers, "triggers", new List<IThresholdTrigger>());
|
||||
}
|
||||
|
||||
public bool Reached(IDamageableComponent damageable, DestructibleSystem system)
|
||||
{
|
||||
foreach (var trigger in Triggers)
|
||||
{
|
||||
if (!trigger.Reached(damageable, system))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
@@ -10,39 +9,37 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when all of the damage types received
|
||||
/// are above the specified threshold.
|
||||
/// A trigger that will activate when the amount of damage received
|
||||
/// of the specified class is above the specified threshold.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TotalDamageTypesTrigger : IThresholdTrigger
|
||||
public class DamageClassTrigger : IThresholdTrigger
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of damage at which this threshold will trigger.
|
||||
/// The damage requirements of all <see cref="DamageType"/> must be met.
|
||||
/// The class to check the damage of.
|
||||
/// </summary>
|
||||
private Dictionary<DamageType, int> Damage { get; set; } = new();
|
||||
public DamageClass? Class { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of damage at which this threshold will trigger.
|
||||
/// </summary>
|
||||
public int Damage { get; set; }
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Damage, "damage", new Dictionary<DamageType, int>());
|
||||
serializer.DataField(this, x => x.Class, "class", null);
|
||||
serializer.DataField(this, x => x.Damage, "damage", 0);
|
||||
}
|
||||
|
||||
public bool Reached(IDamageableComponent damageable, DestructibleSystem system)
|
||||
{
|
||||
foreach (var (type, damageRequired) in Damage)
|
||||
if (Class == null)
|
||||
{
|
||||
if (!damageable.TryGetDamage(type, out var damageReceived))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (damageReceived < damageRequired)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return damageable.TryGetDamage(Class.Value, out var damageReceived) &&
|
||||
damageReceived >= Damage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,16 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when the amount of total damage received
|
||||
/// A trigger that will activate when the amount of damage received
|
||||
/// is above the specified threshold.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TotalDamageTrigger : IThresholdTrigger
|
||||
public class DamageTrigger : IThresholdTrigger
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of total damage at which this threshold will trigger.
|
||||
/// The amount of damage at which this threshold will trigger.
|
||||
/// </summary>
|
||||
public int Damage { get; private set; }
|
||||
public int Damage { get; set; }
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
@@ -0,0 +1,39 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when the amount of damage received
|
||||
/// of the specified type is above the specified threshold.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DamageTypeTrigger : IThresholdTrigger
|
||||
{
|
||||
public DamageType? Type { get; set; }
|
||||
|
||||
public int Damage { get; set; }
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Type, "type", null);
|
||||
serializer.DataField(this, x => x.Damage, "damage", 0);
|
||||
}
|
||||
|
||||
public bool Reached(IDamageableComponent damageable, DestructibleSystem system)
|
||||
{
|
||||
if (Type == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return damageable.TryGetDamage(Type.Value, out var damageReceived) &&
|
||||
damageReceived >= Damage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when any of its triggers have activated.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class OrTrigger : IThresholdTrigger
|
||||
{
|
||||
public List<IThresholdTrigger> Triggers { get; } = new();
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Triggers, "triggers", new List<IThresholdTrigger>());
|
||||
}
|
||||
|
||||
public bool Reached(IDamageableComponent damageable, DestructibleSystem system)
|
||||
{
|
||||
foreach (var trigger in Triggers)
|
||||
{
|
||||
if (trigger.Reached(damageable, system))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// A trigger that will activate when all of the damage classes received
|
||||
/// are above the specified threshold.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TotalDamageClassesTrigger : IThresholdTrigger
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of damage at which this threshold will trigger.
|
||||
/// The damage requirements of all <see cref="DamageClass"/> must be met.
|
||||
/// </summary>
|
||||
private Dictionary<DamageClass, int> Damage { get; set; } = new();
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Damage, "damage", new Dictionary<DamageClass, int>());
|
||||
}
|
||||
|
||||
public bool Reached(IDamageableComponent damageable, DestructibleSystem system)
|
||||
{
|
||||
foreach (var (type, damageRequired) in Damage)
|
||||
{
|
||||
if (!damageable.TryGetDamage(type, out var damageReceived))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (damageReceived < damageRequired)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
foreach (var threshold in destructible.Thresholds)
|
||||
{
|
||||
if (threshold.Trigger is not TotalDamageTrigger trigger)
|
||||
if (threshold.Trigger is not DamageTrigger trigger)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -65,12 +65,12 @@ namespace Content.Server.GameObjects.Components
|
||||
}
|
||||
|
||||
var damage = damageable.TotalDamage;
|
||||
TotalDamageTrigger? trigger = null;
|
||||
DamageTrigger? trigger = null;
|
||||
|
||||
// TODO: Pretend this does not exist until https://github.com/space-wizards/space-station-14/pull/2783 is merged
|
||||
foreach (var threshold in destructible.Thresholds)
|
||||
{
|
||||
if ((trigger = threshold.Trigger as TotalDamageTrigger) != null)
|
||||
if ((trigger = threshold.Trigger as DamageTrigger) != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user