From bbc888b8259839363dc316c12ff75167b0806758 Mon Sep 17 00:00:00 2001 From: Josh DM Date: Fri, 20 Oct 2023 00:23:39 -0400 Subject: [PATCH] fix APL oom detection --- sim/core/apl.go | 7 ++++++- sim/core/mana.go | 5 +++++ sim/core/spell.go | 8 ++++++++ sim/core/unit.go | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sim/core/apl.go b/sim/core/apl.go index 2147b945cb..8f8a687b85 100644 --- a/sim/core/apl.go +++ b/sim/core/apl.go @@ -193,6 +193,8 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) { i := 0 apl.inLoop = true + apl.unit.StartAPLLoop(sim) + for nextAction := apl.getNextAction(sim); nextAction != nil; i, nextAction = i+1, apl.getNextAction(sim) { if i > 1000 { panic(fmt.Sprintf("[USER_ERROR] Infinite loop detected, current action:\n%s", nextAction)) @@ -206,11 +208,14 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) { apl.unit.Log(sim, "No available actions!") } - if apl.unit.GCD.IsReady(sim) { + gcdReady := apl.unit.GCD.IsReady(sim) + if gcdReady { apl.unit.WaitUntil(sim, sim.CurrentTime+time.Millisecond*50) } else { apl.unit.DoNothing() } + + apl.unit.DoneAPLLoop(sim, gcdReady) } func (apl *APLRotation) getNextAction(sim *Simulation) *APLAction { diff --git a/sim/core/mana.go b/sim/core/mana.go index 3c2134fcfb..29cab3520e 100644 --- a/sim/core/mana.go +++ b/sim/core/mana.go @@ -262,9 +262,14 @@ func (sim *Simulation) initManaTickAction() { for _, player := range playersWithManaBars { char := player.GetCharacter() char.ManaTick(sim) + if char.OnManaTick != nil { // Only execute APL actions after mana ticks once pre-pull has completed. if char.IsUsingAPL && sim.CurrentTime > 0 { + if char.IsWaitingForMana() && !char.DoneWaitingForMana(sim) { + continue + } + char.Rotation.DoNextAction(sim) } else { char.OnManaTick(sim) diff --git a/sim/core/spell.go b/sim/core/spell.go index c3bb6ffc42..ae62dbff57 100644 --- a/sim/core/spell.go +++ b/sim/core/spell.go @@ -506,6 +506,14 @@ func (spell *Spell) CanCast(sim *Simulation, target *Unit) bool { //if sim.Log != nil { // sim.Log("Cant cast because of resource cost") //} + _, isManaCost := spell.Cost.(*ManaCost) + if isManaCost && spell.CurCast.Cost > 0 { + if spell.Unit.ManaRequired > 0 { + spell.Unit.ManaRequired = min(spell.Unit.ManaRequired, spell.CurCast.Cost) + } else { + spell.Unit.ManaRequired = spell.CurCast.Cost + } + } return false } } diff --git a/sim/core/unit.go b/sim/core/unit.go index e8cd51bfc9..e4855536c0 100644 --- a/sim/core/unit.go +++ b/sim/core/unit.go @@ -159,6 +159,8 @@ type Unit struct { // The currently-channeled DOT spell, otherwise nil. ChanneledDot *Dot + + ManaRequired float64 } // Units can be disabled for several reasons: @@ -561,3 +563,16 @@ func (unit *Unit) GetMetadata() *proto.UnitMetadata { return metadata } + +func (unit *Unit) StartAPLLoop(sim *Simulation) { + if unit.HasManaBar() { + unit.ManaRequired = 0 + } +} + +func (unit *Unit) DoneAPLLoop(sim *Simulation, usedGCD bool) { + if unit.HasManaBar() && !usedGCD && unit.ManaRequired > 0 { + unit.WaitForMana(sim, unit.ManaRequired) + unit.ManaRequired = 0 + } +}