Add destructible component threshold triggers (#3080)
* WIP changes * Fix tests, merge conflict and trigger once behavior * Update yml * Change test strings to be consts * Fix total damage types and classes triggers * Simplify damage trigger logic, move state to Threshold * Update outdated code and docs * Change the name of IBehavior back to IThresholdBehavior * Change human gibbing to trigger at 400 brute damage * Change gibbing from brute to blunt damage * Fix one (1) typo * Add damage class trigger test * Add missing nullable enable to thresholds
This commit is contained in:
@@ -22,22 +22,15 @@ namespace Content.Server.GameObjects.Components.Destructible
|
||||
|
||||
public override string Name => "Destructible";
|
||||
|
||||
[ViewVariables]
|
||||
private SortedDictionary<int, Threshold> _lowestToHighestThresholds = new();
|
||||
[ViewVariables] private List<Threshold> _thresholds = new();
|
||||
|
||||
[ViewVariables] private int PreviousTotalDamage { get; set; }
|
||||
|
||||
public IReadOnlyDictionary<int, Threshold> LowestToHighestThresholds => _lowestToHighestThresholds;
|
||||
public IReadOnlyList<Threshold> Thresholds => _thresholds;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"thresholds",
|
||||
new Dictionary<int, Threshold>(),
|
||||
thresholds => _lowestToHighestThresholds = new SortedDictionary<int, Threshold>(thresholds),
|
||||
() => new Dictionary<int, Threshold>(_lowestToHighestThresholds));
|
||||
serializer.DataField(ref _thresholds, "thresholds", new List<Threshold>());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -60,32 +53,17 @@ namespace Content.Server.GameObjects.Components.Destructible
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var (damage, threshold) in _lowestToHighestThresholds)
|
||||
foreach (var threshold in _thresholds)
|
||||
{
|
||||
if (threshold.Triggered)
|
||||
if (threshold.Reached(msg.Damageable, _destructibleSystem))
|
||||
{
|
||||
if (threshold.TriggersOnce)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PreviousTotalDamage >= damage)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.Damageable.TotalDamage >= damage)
|
||||
{
|
||||
var thresholdMessage = new DestructibleThresholdReachedMessage(this, threshold, msg.Damageable.TotalDamage, damage);
|
||||
var thresholdMessage = new DestructibleThresholdReachedMessage(this, threshold);
|
||||
SendMessage(thresholdMessage);
|
||||
|
||||
threshold.Trigger(Owner, _destructibleSystem);
|
||||
threshold.Execute(Owner, _destructibleSystem);
|
||||
}
|
||||
}
|
||||
|
||||
PreviousTotalDamage = msg.Damageable.TotalDamage;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user