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:
DrSmugleaf
2021-02-09 12:57:21 +01:00
committed by GitHub
parent 205c787773
commit 15f05b565a
58 changed files with 284 additions and 188 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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)
{

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}