-
Notifications
You must be signed in to change notification settings - Fork 28
/
target_ai.go
148 lines (124 loc) · 3.42 KB
/
target_ai.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
package core
import (
"log"
"github.com/wowsims/sod/sim/core/proto"
)
type TargetAI interface {
Initialize(*Target, *proto.Target)
Reset(*Simulation)
ExecuteCustomRotation(*Simulation)
}
func (target *Target) initialize(config *proto.Target) {
if config == nil {
return
}
if target.CurrentTarget != nil {
if config.SwingSpeed > 0 {
aaOptions := AutoAttackOptions{
MainHand: Weapon{
BaseDamageMin: config.MinBaseDamage,
SwingSpeed: config.SwingSpeed,
SpellSchool: SpellSchoolFromProto(config.SpellSchool),
},
AutoSwingMelee: true,
}
if config.DualWield {
aaOptions.OffHand = aaOptions.MainHand
if !config.DualWieldPenalty {
target.PseudoStats.DisableDWMissPenalty = true
}
}
target.EnableAutoAttacks(target, aaOptions)
}
}
if target.AI != nil {
target.AI.Initialize(target, config)
target.gcdAction = &PendingAction{
Priority: ActionPriorityGCD,
OnAction: func(sim *Simulation) {
target.Rotation.DoNextAction(sim)
},
}
}
}
// Empty Agent interface functions.
func (target *Target) AddRaidBuffs(_ *proto.RaidBuffs) {}
func (target *Target) AddPartyBuffs(_ *proto.PartyBuffs) {}
func (target *Target) ApplyTalents() {}
func (target *Target) ApplyRunes() {}
func (target *Target) GetCharacter() *Character { return nil }
func (target *Target) Initialize() {}
func (target *Target) ExecuteCustomRotation(sim *Simulation) {
if target.AI != nil {
target.AI.ExecuteCustomRotation(sim)
}
}
type AIFactory func() TargetAI
type PresetTarget struct {
// String in folder-structure format identifying a category for this unit, e.g. "Black Temple/Bosses".
PathPrefix string
Config *proto.Target
AI AIFactory
}
func (pt PresetTarget) Path() string {
return pt.PathPrefix + "/" + pt.Config.Name
}
func (pt PresetTarget) ToProto() *proto.PresetTarget {
// CHECKME might need cloning
return &proto.PresetTarget{
Path: pt.Path(),
Target: pt.Config,
}
}
var presetTargets []*PresetTarget
var PresetEncounters []*proto.PresetEncounter
func AddPresetTarget(newPreset *PresetTarget) {
for _, preset := range presetTargets {
if preset.Path() == newPreset.Path() {
log.Fatalf("Preset Target with path %s already added!", newPreset.Path())
}
}
presetTargets = append(presetTargets, newPreset)
}
func GetPresetTargetWithPath(path string) *PresetTarget {
for _, preset := range presetTargets {
if preset.Path() == path {
return preset
}
}
return nil
}
func GetPresetTargetWithID(id int32) *PresetTarget {
for _, preset := range presetTargets {
if preset.Config.Id == id {
return preset
}
}
return nil
}
func AddPresetEncounter(name string, targetPaths []string) {
if len(targetPaths) == 0 {
log.Fatalf("Encounter must have targets!")
}
var path string
targetProtos := make([]*proto.PresetTarget, len(targetPaths))
for i, targetPath := range targetPaths {
presetTarget := GetPresetTargetWithPath(targetPath)
if presetTarget == nil {
log.Fatalf("No preset target with path: %s", targetPath)
}
targetProtos[i] = presetTarget.ToProto()
if i == 0 {
path = presetTarget.PathPrefix + "/" + name
}
}
for _, preset := range PresetEncounters {
if preset.Path == path {
log.Fatalf("Preset Encounter with path %s already added!", path)
}
}
PresetEncounters = append(PresetEncounters, &proto.PresetEncounter{
Path: path,
Targets: targetProtos,
})
}