From 4a5bab42116039f2069d5e14f4c2b14b467480af Mon Sep 17 00:00:00 2001 From: jarves Date: Wed, 21 Dec 2022 16:55:56 -0600 Subject: [PATCH] ee: dont overwrite same priority with less duration Signed-off-by: jarves --- sim/core/exclusive_effect.go | 2 +- sim/core/exclusive_effect_test.go | 56 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 sim/core/exclusive_effect_test.go diff --git a/sim/core/exclusive_effect.go b/sim/core/exclusive_effect.go index 5b6f5d6d7a..ad3bea3331 100644 --- a/sim/core/exclusive_effect.go +++ b/sim/core/exclusive_effect.go @@ -130,7 +130,7 @@ func (ee *ExclusiveEffect) Activate(sim *Simulation) bool { return true } - if ee.Category.SingleAura && ee.Category.activeEffect != nil && ee.Category.activeEffect != ee && ee.Category.activeEffect.Priority > ee.Priority { + if ee.Category.SingleAura && ee.Category.activeEffect != nil && ee.Category.activeEffect != ee && (ee.Category.activeEffect.Priority > ee.Priority || (ee.Priority == ee.Category.activeEffect.Priority && ee.Category.activeEffect.Aura.RemainingDuration(sim) > ee.Aura.Duration)) { return false } diff --git a/sim/core/exclusive_effect_test.go b/sim/core/exclusive_effect_test.go new file mode 100644 index 0000000000..29d767659f --- /dev/null +++ b/sim/core/exclusive_effect_test.go @@ -0,0 +1,56 @@ +package core + +import ( + "testing" + "time" +) + +func TestSingleAuraExclusiveDurationNoOverwrite(t *testing.T) { + sim := &Simulation{} + + target := Unit{ + Type: EnemyUnit, + Index: 0, + Level: 83, + auraTracker: newAuraTracker(), + } + mangle := MangleAura(&target) + trauma := MakePermanent(TraumaAura(&target, 2)) + + // Trauma in this case should *never* be overwritten + // as its duration from 'MakePermanent' should make it non overwritable by 1 min duration mangles + trauma.Activate(sim) + + sim.CurrentTime = 1 * time.Second + + mangle.Activate(sim) + + if !(trauma.IsActive() && !mangle.IsActive()) { + t.Fatalf("lower duration exclusive aura overwrote previous!") + } +} + +func TestSingleAuraExclusiveDurationOverwrite(t *testing.T) { + sim := &Simulation{} + + target := Unit{ + Type: EnemyUnit, + Index: 0, + Level: 83, + auraTracker: newAuraTracker(), + } + mangle := MangleAura(&target) + trauma := TraumaAura(&target, 2) + + trauma.Activate(sim) + + sim.CurrentTime = 1 * time.Second + + mangle.Activate(sim) + + // In this case mangle should overwrite trauma as mangle will give a greater duration + + if !(mangle.IsActive() && !trauma.IsActive()) { + t.Fatalf("longer duration exclusive aura failed to overwrite") + } +}