Destructible spawning fix redux (#2892)

* Fix SpawnEntitiesBehavior crash and add test

* Fix comparer, add duplicated behavior

Turns out this isn't Java

* Threshold behaviors are now "linearly" executed

* Fixes YAML threshold behaviors to be linear

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Vera Aguilera Puerto
2021-01-02 20:06:00 +01:00
committed by GitHub
parent cc4669244d
commit 85add420b0
13 changed files with 223 additions and 103 deletions

View File

@@ -11,10 +11,12 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds
{
public class Threshold : IExposeData
{
private List<IThresholdBehavior> _behaviors = new();
/// <summary>
/// Whether or not this threshold has already been triggered.
/// </summary>
[ViewVariables] public bool Triggered;
[ViewVariables] public bool Triggered { get; private set; }
/// <summary>
/// Whether or not this threshold only triggers once.
@@ -22,18 +24,18 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds
/// and then damaged to reach this threshold once again.
/// It will not repeatedly trigger as damage rises beyond that.
/// </summary>
[ViewVariables] public bool TriggersOnce;
[ViewVariables] public bool TriggersOnce { get; set; }
/// <summary>
/// Behaviors to activate once this threshold is triggered.
/// </summary>
[ViewVariables] public List<IThresholdBehavior> Behaviors = new();
[ViewVariables] public IReadOnlyList<IThresholdBehavior> Behaviors => _behaviors;
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref Triggered, "triggered", false);
serializer.DataField(ref TriggersOnce, "triggersOnce", false);
serializer.DataField(ref Behaviors, "behaviors", new List<IThresholdBehavior>());
serializer.DataField(this, x => x.Triggered, "triggered", false);
serializer.DataField(this, x => x.TriggersOnce, "triggersOnce", false);
serializer.DataField(ref _behaviors, "behaviors", new List<IThresholdBehavior>());
}
/// <summary>
@@ -50,6 +52,10 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds
foreach (var behavior in Behaviors)
{
// The owner has been deleted. We stop execution of behaviors here.
if (owner.Deleted)
return;
behavior.Trigger(owner, system);
}
}