-
Notifications
You must be signed in to change notification settings - Fork 28
/
apl_actions_sequences.go
165 lines (152 loc) · 5 KB
/
apl_actions_sequences.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
package core
import (
"fmt"
"strings"
"github.com/wowsims/sod/sim/core/proto"
)
type APLActionSequence struct {
defaultAPLActionImpl
unit *Unit
name string
subactions []*APLAction
curIdx int
}
func (rot *APLRotation) newActionSequence(config *proto.APLActionSequence) APLActionImpl {
subactions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction {
return rot.newAPLAction(action)
})
subactions = FilterSlice(subactions, func(action *APLAction) bool { return action != nil })
if len(subactions) == 0 {
return nil
}
return &APLActionSequence{
unit: rot.unit,
name: config.Name,
subactions: subactions,
}
}
func (action *APLActionSequence) GetInnerActions() []*APLAction {
return Flatten(MapSlice(action.subactions, func(action *APLAction) []*APLAction { return action.GetAllActions() }))
}
func (action *APLActionSequence) Finalize(rot *APLRotation) {
for _, subaction := range action.subactions {
subaction.impl.Finalize(rot)
}
}
func (action *APLActionSequence) Reset(*Simulation) {
action.curIdx = 0
}
func (action *APLActionSequence) IsReady(sim *Simulation) bool {
return action.curIdx < len(action.subactions) && action.subactions[action.curIdx].IsReady(sim)
}
func (action *APLActionSequence) Execute(sim *Simulation) {
action.subactions[action.curIdx].Execute(sim)
action.curIdx++
}
func (action *APLActionSequence) String() string {
return "Sequence(" + strings.Join(MapSlice(action.subactions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")"
}
type APLActionResetSequence struct {
defaultAPLActionImpl
name string
sequence *APLActionSequence
}
func (rot *APLRotation) newActionResetSequence(config *proto.APLActionResetSequence) APLActionImpl {
if config.SequenceName == "" {
rot.ValidationWarning("Reset Sequence must provide a sequence name")
return nil
}
return &APLActionResetSequence{
name: config.SequenceName,
}
}
func (action *APLActionResetSequence) Finalize(rot *APLRotation) {
for _, otherAction := range rot.allAPLActions() {
if sequence, ok := otherAction.impl.(*APLActionSequence); ok && sequence.name == action.name {
action.sequence = sequence
return
}
}
rot.ValidationWarning("No sequence with name: '%s'", action.name)
}
func (action *APLActionResetSequence) IsReady(sim *Simulation) bool {
return action.sequence != nil && action.sequence.curIdx != 0
}
func (action *APLActionResetSequence) Execute(sim *Simulation) {
action.sequence.curIdx = 0
}
func (action *APLActionResetSequence) String() string {
return fmt.Sprintf("Reset Sequence(name = '%s')", action.name)
}
type APLActionStrictSequence struct {
defaultAPLActionImpl
unit *Unit
subactions []*APLAction
curIdx int
subactionSpells []*Spell
}
func (rot *APLRotation) newActionStrictSequence(config *proto.APLActionStrictSequence) APLActionImpl {
subactions := MapSlice(config.Actions, func(action *proto.APLAction) *APLAction {
return rot.newAPLAction(action)
})
subactions = FilterSlice(subactions, func(action *APLAction) bool { return action != nil })
if len(subactions) == 0 {
return nil
}
return &APLActionStrictSequence{
unit: rot.unit,
subactions: subactions,
}
}
func (action *APLActionStrictSequence) GetInnerActions() []*APLAction {
return Flatten(MapSlice(action.subactions, func(action *APLAction) []*APLAction { return action.GetAllActions() }))
}
func (action *APLActionStrictSequence) Finalize(rot *APLRotation) {
for _, subaction := range action.subactions {
subaction.impl.Finalize(rot)
action.subactionSpells = append(action.subactionSpells, subaction.GetAllSpells()...)
}
}
func (action *APLActionStrictSequence) Reset(*Simulation) {
action.curIdx = 0
}
func (action *APLActionStrictSequence) IsReady(sim *Simulation) bool {
if !action.unit.GCD.IsReady(sim) {
return false
}
if !action.subactions[0].IsReady(sim) {
return false
}
for _, spell := range action.subactionSpells {
if !spell.IsReady(sim) {
return false
}
}
return true
}
func (action *APLActionStrictSequence) Execute(sim *Simulation) {
action.unit.Rotation.pushControllingAction(action)
}
func (action *APLActionStrictSequence) GetNextAction(sim *Simulation) *APLAction {
if action.subactions[action.curIdx].IsReady(sim) {
nextAction := action.subactions[action.curIdx]
action.curIdx++
if action.curIdx == len(action.subactions) {
action.curIdx = 0
action.unit.Rotation.popControllingAction(action)
}
return nextAction
} else if action.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.
action.curIdx = 0
action.unit.Rotation.popControllingAction(action)
return action.unit.Rotation.getNextAction(sim)
} else {
// Return nil to wait for the GCD to become ready.
return nil
}
}
func (action *APLActionStrictSequence) String() string {
return "Strict Sequence(" + strings.Join(MapSlice(action.subactions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")"
}