-
Notifications
You must be signed in to change notification settings - Fork 28
/
apl_action.go
196 lines (165 loc) · 5.84 KB
/
apl_action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package core
import (
"fmt"
"github.com/wowsims/sod/sim/core/proto"
)
type APLAction struct {
condition APLValue
impl APLActionImpl
}
func (action *APLAction) Finalize(rot *APLRotation) {
action.impl.Finalize(rot)
for _, value := range action.GetAllAPLValues() {
value.Finalize(rot)
}
}
func (action *APLAction) IsReady(sim *Simulation) bool {
return (action.condition == nil || action.condition.GetBool(sim)) && action.impl.IsReady(sim)
}
func (action *APLAction) Execute(sim *Simulation) {
action.impl.Execute(sim)
}
// Returns this Action, along with all inner Actions.
func (action *APLAction) GetAllActions() []*APLAction {
actions := action.impl.GetInnerActions()
actions = append(actions, action)
return actions
}
// Returns all APLValues used by this action and all of its inner Actions.
func (action *APLAction) GetAllAPLValues() []APLValue {
var values []APLValue
for _, a := range action.GetAllActions() {
unprocessed := a.impl.GetAPLValues()
if a.condition != nil {
unprocessed = append(unprocessed, a.condition)
}
for len(unprocessed) > 0 {
next := unprocessed[len(unprocessed)-1]
unprocessed = unprocessed[:len(unprocessed)-1]
values = append(values, next)
unprocessed = append(unprocessed, next.GetInnerValues()...)
}
}
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)
} else {
return fmt.Sprintf("IF = %s\nACTION = %s", action.condition, action.impl)
}
}
type APLActionImpl interface {
// Returns all inner APL Actions.
GetInnerActions() []*APLAction
// Returns all APLValues used by this Action (but not by inner Actions).
GetAPLValues() []APLValue
// Performs optional post-processing.
Finalize(*APLRotation)
// Invoked before each sim iteration.
Reset(*Simulation)
// Whether this action is available to be used right now.
IsReady(*Simulation) bool
// 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
}
// Provides empty implementations for the action impl interface functions.
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) GetNextAction(*Simulation) *APLAction { return nil }
func (rot *APLRotation) newAPLAction(config *proto.APLAction) *APLAction {
if config == nil {
return nil
}
action := &APLAction{
condition: rot.coerceTo(rot.newAPLValue(config.Condition), proto.APLValueType_ValueTypeBool),
impl: rot.newAPLActionImpl(config),
}
if action.impl == nil {
return nil
} else {
return action
}
}
func (rot *APLRotation) newAPLActionImpl(config *proto.APLAction) APLActionImpl {
if config == nil {
return nil
}
customAction := rot.unit.Env.GetAgentFromUnit(rot.unit).NewAPLAction(rot, config)
if customAction != nil {
return customAction
}
switch config.Action.(type) {
// Casting
case *proto.APLAction_CastSpell:
return rot.newActionCastSpell(config.GetCastSpell())
case *proto.APLAction_ChannelSpell:
return rot.newActionChannelSpell(config.GetChannelSpell())
case *proto.APLAction_Multidot:
return rot.newActionMultidot(config.GetMultidot())
case *proto.APLAction_Multishield:
return rot.newActionMultishield(config.GetMultishield())
case *proto.APLAction_AutocastOtherCooldowns:
return rot.newActionAutocastOtherCooldowns(config.GetAutocastOtherCooldowns())
// Timing
case *proto.APLAction_Wait:
return rot.newActionWait(config.GetWait())
case *proto.APLAction_WaitUntil:
return rot.newActionWaitUntil(config.GetWaitUntil())
case *proto.APLAction_Schedule:
return rot.newActionSchedule(config.GetSchedule())
// Sequences
case *proto.APLAction_Sequence:
return rot.newActionSequence(config.GetSequence())
case *proto.APLAction_ResetSequence:
return rot.newActionResetSequence(config.GetResetSequence())
case *proto.APLAction_StrictSequence:
return rot.newActionStrictSequence(config.GetStrictSequence())
// Misc
case *proto.APLAction_ChangeTarget:
return rot.newActionChangeTarget(config.GetChangeTarget())
case *proto.APLAction_ActivateAura:
return rot.newActionActivateAura(config.GetActivateAura())
case *proto.APLAction_ActivateAuraWithStacks:
return rot.newActionActivateAuraWithStacks(config.GetActivateAuraWithStacks())
case *proto.APLAction_CancelAura:
return rot.newActionCancelAura(config.GetCancelAura())
case *proto.APLAction_TriggerIcd:
return rot.newActionTriggerICD(config.GetTriggerIcd())
case *proto.APLAction_ItemSwap:
return rot.newActionItemSwap(config.GetItemSwap())
case *proto.APLAction_Move:
return rot.newActionMove(config.GetMove())
case *proto.APLAction_CustomRotation:
return rot.newActionCustomRotation(config.GetCustomRotation())
case *proto.APLAction_AddComboPoints:
return rot.newActionAddComboPoints(config.GetAddComboPoints())
default:
return nil
}
}
// Default implementation of Agent.NewAPLAction so each spec doesn't need this boilerplate.
func (unit *Unit) NewAPLAction(rot *APLRotation, config *proto.APLAction) APLActionImpl {
return nil
}