Skip to content

Commit

Permalink
Merge branch 'wowsims:master' into enh_itemswap_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Horatio27 authored Sep 4, 2023
2 parents 3db5a7f + 17c5186 commit 931b9d8
Show file tree
Hide file tree
Showing 22 changed files with 395 additions and 215 deletions.
Binary file modified assets/database/db.bin
Binary file not shown.
1 change: 1 addition & 0 deletions assets/database/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -12958,6 +12958,7 @@
{"id":67383,"name":"Unholy Force","icon":"spell_shadow_unholystrength"},
{"id":67839,"name":"Mind Amplification Dish","icon":"trade_engineering"},
{"id":68051,"name":"Overpower Ready!","icon":"ability_rogue_hungerforblood"},
{"id":68055,"name":"Judgements of the Just","icon":"spell_holy_righteousfury"},
{"id":70164,"name":"Rune of the Nerubian Carapace","icon":"inv_sword_61"},
{"id":70550,"name":"Leggings of Woven Death","icon":"inv_pants_cloth_34"},
{"id":70551,"name":"Deathfrost Boots","icon":"inv_boots_cloth_25"},
Expand Down
7 changes: 6 additions & 1 deletion proto/apl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message APLListItem {
APLAction action = 3; // The action to be performed.
}

// NextIndex: 13
// NextIndex: 15
message APLAction {
APLValue condition = 1; // If set, action will only execute if value is true or != 0.

Expand All @@ -49,6 +49,7 @@ message APLAction {
APLActionCancelAura cancel_aura = 10;
APLActionTriggerICD trigger_icd = 11;
APLActionWait wait = 4;
APLActionWaitUntil wait_until = 14;
}
}

Expand Down Expand Up @@ -188,6 +189,10 @@ message APLActionWait {
APLValue duration = 1;
}

message APLActionWaitUntil {
APLValue condition = 1;
}

///////////////////////////////////////////////////////////////////////////
// VALUES
///////////////////////////////////////////////////////////////////////////
Expand Down
30 changes: 6 additions & 24 deletions sim/core/apl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type APLRotation struct {
prepullActions []*APLAction
priorityList []*APLAction

// Current strict sequence
strictSequence *APLAction
// Action currently controlling this rotation (only used for certain actions, such as StrictSequence).
controllingAction APLActionImpl

// Used inside of actions/value to determine whether they will occur during the prepull or regular rotation.
parsingPrepull bool
Expand Down Expand Up @@ -143,7 +143,7 @@ func (rot *APLRotation) allPrepullActions() []*APLAction {
}

func (rot *APLRotation) reset(sim *Simulation) {
rot.strictSequence = nil
rot.controllingAction = nil
rot.inLoop = false
for _, action := range rot.allAPLActions() {
action.impl.Reset(sim)
Expand Down Expand Up @@ -174,37 +174,19 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) {
}

if apl.unit.GCD.IsReady(sim) {
apl.unit.WaitUntil(sim, sim.CurrentTime+time.Millisecond*500)
apl.unit.WaitUntil(sim, sim.CurrentTime+time.Millisecond*50)
} else {
apl.unit.DoNothing()
}
}

func (apl *APLRotation) getNextAction(sim *Simulation) *APLAction {
if sim.CurrentTime < apl.unit.waitUntilTime {
return nil
}

if apl.strictSequence != nil {
ss := apl.strictSequence.impl.(*APLActionStrictSequence)
if ss.actions[ss.curIdx].IsReady(sim) {
return apl.strictSequence
} else if apl.unit.GCD.IsReady(sim) {
// If the GCD is ready when the next subaction isn't, it means the sequence is bad
// so reset and exit the sequence.
ss.curIdx = 0
apl.strictSequence = nil
} else {
// Return nil to wait for the GCD to become ready.
return nil
}
if apl.controllingAction != nil {
return apl.controllingAction.GetNextAction(sim)
}

for _, action := range apl.priorityList {
if action.IsReady(sim) {
if _, ok := action.impl.(*APLActionStrictSequence); ok {
apl.strictSequence = action
}
return action
}
}
Expand Down
28 changes: 24 additions & 4 deletions sim/core/apl_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func (action *APLAction) GetAllAPLValues() []APLValue {
return FilterSlice(values, func(val APLValue) bool { return val != nil })
}

func (action *APLAction) GetAllSpells() []*Spell {
var spells []*Spell
for _, a := range action.GetAllActions() {
if impl, ok := a.impl.(*APLActionCastSpell); ok {
spells = append(spells, impl.spell)
} else if impl, ok := a.impl.(*APLActionMultidot); ok {
spells = append(spells, impl.spell)
} else if impl, ok := a.impl.(*APLActionMultishield); ok {
spells = append(spells, impl.spell)
}
}
return spells
}

func (action *APLAction) String() string {
if action.condition == nil {
return fmt.Sprintf("ACTION = %s", action.impl)
Expand Down Expand Up @@ -73,6 +87,9 @@ type APLActionImpl interface {
// Performs the action.
Execute(*Simulation)

// Called only while this action is controlling the rotation.
GetNextAction(sim *Simulation) *APLAction

// Pretty-print string for debugging.
String() string
}
Expand All @@ -81,10 +98,11 @@ type APLActionImpl interface {
type defaultAPLActionImpl struct {
}

func (impl defaultAPLActionImpl) GetInnerActions() []*APLAction { return nil }
func (impl defaultAPLActionImpl) GetAPLValues() []APLValue { return nil }
func (impl defaultAPLActionImpl) Finalize(*APLRotation) {}
func (impl defaultAPLActionImpl) Reset(*Simulation) {}
func (impl defaultAPLActionImpl) GetInnerActions() []*APLAction { return nil }
func (impl defaultAPLActionImpl) GetAPLValues() []APLValue { return nil }
func (impl defaultAPLActionImpl) Finalize(*APLRotation) {}
func (impl defaultAPLActionImpl) Reset(*Simulation) {}
func (impl defaultAPLActionImpl) GetNextAction(*Simulation) *APLAction { return nil }

func (rot *APLRotation) newAPLAction(config *proto.APLAction) *APLAction {
if config == nil {
Expand Down Expand Up @@ -138,6 +156,8 @@ func (rot *APLRotation) newAPLActionImpl(config *proto.APLAction) APLActionImpl
return rot.newActionTriggerICD(config.GetTriggerIcd())
case *proto.APLAction_Wait:
return rot.newActionWait(config.GetWait())
case *proto.APLAction_WaitUntil:
return rot.newActionWaitUntil(config.GetWaitUntil())
default:
return nil
}
Expand Down
73 changes: 64 additions & 9 deletions sim/core/apl_actions_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"
"time"

"github.com/wowsims/wotlk/sim/core/proto"
)
Expand Down Expand Up @@ -208,38 +209,92 @@ type APLActionWait struct {
defaultAPLActionImpl
unit *Unit
duration APLValue

curWaitTime time.Duration
}

func (rot *APLRotation) newActionWait(config *proto.APLActionWait) APLActionImpl {
unit := rot.unit
durationVal := rot.coerceTo(rot.newAPLValue(config.Duration), proto.APLValueType_ValueTypeDuration)
if durationVal == nil {
return nil
}

return &APLActionWait{
unit: unit,
duration: rot.coerceTo(rot.newAPLValue(config.Duration), proto.APLValueType_ValueTypeDuration),
duration: durationVal,
}
}
func (action *APLActionWait) GetAPLValues() []APLValue {
return []APLValue{action.duration}
}
func (action *APLActionWait) IsReady(sim *Simulation) bool {
return action.duration != nil
return true
}

func (action *APLActionWait) Execute(sim *Simulation) {
waitUntilTime := sim.CurrentTime + action.duration.GetDuration(sim)
action.unit.waitUntilTime = waitUntilTime
action.unit.Rotation.controllingAction = action
action.curWaitTime = sim.CurrentTime + action.duration.GetDuration(sim)

if waitUntilTime > action.unit.GCD.ReadyAt() {
action.unit.WaitUntil(sim, waitUntilTime)
return
}
pa := &PendingAction{
Priority: ActionPriorityLow,
OnAction: action.unit.gcdAction.OnAction,
NextActionAt: waitUntilTime,
NextActionAt: action.curWaitTime,
}
sim.AddPendingAction(pa)
}

func (action *APLActionWait) GetNextAction(sim *Simulation) *APLAction {
if sim.CurrentTime >= action.curWaitTime {
action.unit.Rotation.controllingAction = nil
return action.unit.Rotation.getNextAction(sim)
} else {
return nil
}
}

func (action *APLActionWait) String() string {
return fmt.Sprintf("Wait(%s)", action.duration)
}

type APLActionWaitUntil struct {
defaultAPLActionImpl
unit *Unit
condition APLValue
}

func (rot *APLRotation) newActionWaitUntil(config *proto.APLActionWaitUntil) APLActionImpl {
unit := rot.unit
conditionVal := rot.coerceTo(rot.newAPLValue(config.Condition), proto.APLValueType_ValueTypeBool)
if conditionVal == nil {
return nil
}

return &APLActionWaitUntil{
unit: unit,
condition: conditionVal,
}
}
func (action *APLActionWaitUntil) GetAPLValues() []APLValue {
return []APLValue{action.condition}
}
func (action *APLActionWaitUntil) IsReady(sim *Simulation) bool {
return !action.condition.GetBool(sim)
}

func (action *APLActionWaitUntil) Execute(sim *Simulation) {
action.unit.Rotation.controllingAction = action
}

func (action *APLActionWaitUntil) GetNextAction(sim *Simulation) *APLAction {
if action.condition.GetBool(sim) {
action.unit.Rotation.controllingAction = nil
return action.unit.Rotation.getNextAction(sim)
} else {
return nil
}
}

func (action *APLActionWaitUntil) String() string {
return fmt.Sprintf("WaitUntil(%s)", action.condition)
}
Loading

0 comments on commit 931b9d8

Please sign in to comment.