Skip to content

Commit

Permalink
Merge pull request #2650 from lime-green/fix-prepull-pa
Browse files Browse the repository at this point in the history
allow prepull pending actions to run
  • Loading branch information
rosenrusinov authored Feb 13, 2023
2 parents 80b9ab1 + 091e80b commit 6a3e53f
Show file tree
Hide file tree
Showing 13 changed files with 1,000 additions and 965 deletions.
4 changes: 2 additions & 2 deletions sim/core/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (aa *AutoAttacks) startPull(sim *Simulation) {
}

func (aa *AutoAttacks) resetAutoSwing(sim *Simulation) {
if aa.autoSwingCancelled || (!aa.AutoSwingMelee && !aa.AutoSwingRanged) {
if aa.autoSwingCancelled || (!aa.AutoSwingMelee && !aa.AutoSwingRanged) || sim.CurrentTime < 0 {
return
}

Expand Down Expand Up @@ -440,8 +440,8 @@ func (aa *AutoAttacks) CancelAutoSwing(sim *Simulation) {
if aa.autoSwingAction != nil {
aa.autoSwingAction.Cancel(sim)
aa.autoSwingAction = nil
aa.autoSwingCancelled = true
}
aa.autoSwingCancelled = true
}

// Renables the auto swing action for the iteration
Expand Down
4 changes: 4 additions & 0 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ func (character *Character) initialize(agent Agent) {
character.gcdAction = &PendingAction{
Priority: ActionPriorityGCD,
OnAction: func(sim *Simulation) {
if sim.CurrentTime < 0 {
return
}

character.TryUseCooldowns(sim)
if character.GCD.IsReady(sim) {
agent.OnGCDReady(sim)
Expand Down
11 changes: 10 additions & 1 deletion sim/core/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ func (pet *Pet) Enable(sim *Simulation, petAgent PetAgent) {
pet.manaBar.reset()

pet.SetGCDTimer(sim, MaxDuration(0, sim.CurrentTime))
pet.AutoAttacks.EnableAutoSwing(sim)
if sim.CurrentTime >= 0 {
pet.AutoAttacks.EnableAutoSwing(sim)
} else {
sim.AddPendingAction(&PendingAction{
NextActionAt: 0,
OnAction: func(sim *Simulation) {
pet.AutoAttacks.EnableAutoSwing(sim)
},
})
}

pet.enabled = true

Expand Down
59 changes: 35 additions & 24 deletions sim/core/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,29 +312,7 @@ func (sim *Simulation) run() *proto.RaidSimResult {
return result
}

// RunOnce is the main event loop. It will run the simulation for number of seconds.
func (sim *Simulation) runOnce() {
sim.reset()

if len(sim.Environment.prepullActions) > 0 {
sim.CurrentTime = sim.Environment.prepullActions[0].DoAt

for _, prepullAction := range sim.Environment.prepullActions {
if prepullAction.DoAt > sim.CurrentTime {
sim.advance(prepullAction.DoAt - sim.CurrentTime)
}
prepullAction.Action(sim)
}

if sim.CurrentTime < 0 {
sim.advance(0 - sim.CurrentTime)
}
}

for _, unit := range sim.Environment.AllUnits {
unit.startPull(sim)
}

func (sim *Simulation) runPendingActions(max time.Duration) {
for {
last := len(sim.pendingActions) - 1
pa := sim.pendingActions[last]
Expand All @@ -353,7 +331,12 @@ func (sim *Simulation) runOnce() {
}

if pa.NextActionAt > sim.CurrentTime {
sim.advance(pa.NextActionAt - sim.CurrentTime)
if pa.NextActionAt < max {
sim.advance(pa.NextActionAt - sim.CurrentTime)
} else {
sim.pendingActions = append(sim.pendingActions, pa)
break
}
}
pa.consumed = true

Expand All @@ -362,6 +345,34 @@ func (sim *Simulation) runOnce() {
}
pa.OnAction(sim)
}
}

// RunOnce is the main event loop. It will run the simulation for number of seconds.
func (sim *Simulation) runOnce() {
sim.reset()

if len(sim.Environment.prepullActions) > 0 {
sim.CurrentTime = sim.Environment.prepullActions[0].DoAt

for _, prepullAction := range sim.Environment.prepullActions {
if prepullAction.DoAt > sim.CurrentTime {
sim.runPendingActions(prepullAction.DoAt)
sim.advance(prepullAction.DoAt - sim.CurrentTime)
}
prepullAction.Action(sim)
}

if sim.CurrentTime < 0 {
sim.runPendingActions(0)
sim.advance(0 - sim.CurrentTime)
}
}

for _, unit := range sim.Environment.AllUnits {
unit.startPull(sim)
}

sim.runPendingActions(NeverExpires)

// The last event loop will leave CurrentTime at some value close to but not
// quite at the Duration. Explicitly set this so that accesses to CurrentTime
Expand Down
4 changes: 3 additions & 1 deletion sim/deathknight/army_of_the_dead.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ func (dk *Deathknight) registerArmyOfTheDeadCD() {
ActionID: core.ActionID{SpellID: 42650},
Duration: time.Millisecond * 500 * 8,
OnGain: func(aura *core.Aura, sim *core.Simulation) {
dk.AutoAttacks.CancelAutoSwing(sim)
if sim.CurrentTime >= 0 {
dk.AutoAttacks.CancelAutoSwing(sim)
}
dk.CancelGCDTimer(sim)

ghoulIndex = 0
Expand Down
Loading

0 comments on commit 6a3e53f

Please sign in to comment.