-
Notifications
You must be signed in to change notification settings - Fork 36
/
target.go
274 lines (230 loc) · 9.01 KB
/
target.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package core
import (
"strconv"
"time"
"github.com/wowsims/cata/sim/core/proto"
"github.com/wowsims/cata/sim/core/stats"
)
type Encounter struct {
Duration time.Duration
DurationVariation time.Duration
Targets []*Target
ActiveTargets []*Target
TargetUnits []*Unit
ExecuteProportion_20 float64
ExecuteProportion_25 float64
ExecuteProportion_35 float64
ExecuteProportion_90 float64
EndFightAtHealth float64
// DamageTaken is used to track health fights instead of duration fights.
// Once primary target has taken its health worth of damage, fight ends.
DamageTaken float64
// In health fight: set to true until we get something to base on
DurationIsEstimate bool
// Value to multiply by, for damage spells which are subject to the aoe cap.
aoeCapMultiplier float64
}
func NewEncounter(options *proto.Encounter) Encounter {
options.ExecuteProportion_25 = max(options.ExecuteProportion_25, options.ExecuteProportion_20)
options.ExecuteProportion_35 = max(options.ExecuteProportion_35, options.ExecuteProportion_25)
encounter := Encounter{
Duration: DurationFromSeconds(options.Duration),
DurationVariation: DurationFromSeconds(options.DurationVariation),
ExecuteProportion_20: max(options.ExecuteProportion_20, 0),
ExecuteProportion_25: max(options.ExecuteProportion_25, 0),
ExecuteProportion_35: max(options.ExecuteProportion_35, 0),
ExecuteProportion_90: max(options.ExecuteProportion_90, 0),
Targets: []*Target{},
ActiveTargets: []*Target{},
}
for targetIndex, targetOptions := range options.Targets {
target := NewTarget(targetOptions, int32(targetIndex))
encounter.Targets = append(encounter.Targets, target)
encounter.ActiveTargets = append(encounter.ActiveTargets, target)
encounter.TargetUnits = append(encounter.TargetUnits, &target.Unit)
}
if len(encounter.Targets) == 0 {
// Add a dummy target. The only case where targets aren't specified is when
// computing character stats, and targets won't matter there.
target := NewTarget(&proto.Target{}, 0)
encounter.Targets = append(encounter.Targets, target)
encounter.ActiveTargets = append(encounter.ActiveTargets, target)
encounter.TargetUnits = append(encounter.TargetUnits, &target.Unit)
}
// If UseHealth is set, we use the sum of targets health. After creating the targets to make sure stat modifications are done
if options.UseHealth {
for _, t := range options.Targets {
encounter.EndFightAtHealth += t.Stats[stats.Health]
}
if encounter.EndFightAtHealth == 0 {
encounter.EndFightAtHealth = 1 // default to something so we don't instantly end without anything.
}
}
if encounter.EndFightAtHealth > 0 {
// Until we pre-sim set duration to 10m
encounter.Duration = time.Minute * 10
encounter.DurationIsEstimate = true
}
encounter.updateAOECapMultiplier()
return encounter
}
func (encounter *Encounter) AOECapMultiplier() float64 {
return encounter.aoeCapMultiplier
}
func (encounter *Encounter) updateAOECapMultiplier() {
encounter.aoeCapMultiplier = min(10/float64(len(encounter.Targets)), 1)
}
func (encounter *Encounter) doneIteration(sim *Simulation) {
for i := range encounter.Targets {
target := encounter.Targets[i]
target.doneIteration(sim)
}
}
func (encounter *Encounter) GetMetricsProto() *proto.EncounterMetrics {
metrics := &proto.EncounterMetrics{
Targets: make([]*proto.UnitMetrics, len(encounter.Targets)),
}
i := 0
for _, target := range encounter.Targets {
metrics.Targets[i] = target.GetMetricsProto()
i++
}
return metrics
}
// Target is an enemy/boss that can be the target of player attacks/spells.
type Target struct {
Unit
IsActive bool
AI TargetAI
}
func NewTarget(options *proto.Target, targetIndex int32) *Target {
unitStats := stats.Stats{}
if options.Stats != nil {
copy(unitStats[:], options.Stats)
}
target := &Target{
Unit: Unit{
Type: EnemyUnit,
Index: targetIndex,
Label: "Target " + strconv.Itoa(int(targetIndex)+1),
Level: options.Level,
MobType: options.MobType,
auraTracker: newAuraTracker(),
stats: unitStats,
PseudoStats: stats.NewPseudoStats(),
Metrics: NewUnitMetrics(),
StatDependencyManager: stats.NewStatDependencyManager(),
ReactionTime: time.Millisecond * 1620,
},
IsActive: true,
}
defaultRaidBossLevel := int32(CharacterLevel + 3)
target.GCD = target.NewTimer()
target.RotationTimer = target.NewTimer()
if target.Level == 0 {
target.Level = defaultRaidBossLevel
}
if target.stats[stats.MeleeCrit] == 0 {
// Treat any % crit buff an enemy would gain as though it was scaled with level 80 ratings
target.stats[stats.MeleeCrit] = UnitLevelFloat64(target.Level, 5.0, 5.2, 5.4, 5.6) * CritRatingPerCritChance
}
target.PseudoStats.CanBlock = true
target.PseudoStats.CanParry = true
target.PseudoStats.ParryHaste = options.ParryHaste
target.PseudoStats.InFrontOfTarget = true
target.PseudoStats.DamageSpread = options.DamageSpread
preset := GetPresetTargetWithID(options.Id)
if preset != nil && preset.AI != nil {
target.AI = preset.AI()
}
return target
}
func (target *Target) Reset(sim *Simulation) {
target.Unit.reset(sim, nil)
target.CurrentTarget = target.defaultTarget
target.SetGCDTimer(sim, 0)
if target.AI != nil {
target.AI.Reset(sim)
}
}
func (target *Target) NextTarget() *Target {
nextIndex := target.Index + 1
if nextIndex >= target.Env.GetNumTargets() {
nextIndex = 0
}
return target.Env.GetTarget(nextIndex)
}
func (target *Target) GetMetricsProto() *proto.UnitMetrics {
metrics := target.Metrics.ToProto()
metrics.Name = target.Label
metrics.UnitIndex = target.UnitIndex
metrics.Auras = target.auraTracker.GetMetricsProto()
return metrics
}
type DynamicDamageDoneByCaster func(sim *Simulation, spell *Spell, attackTable *AttackTable) float64
// Holds cached values for outcome/damage calculations, for a specific attacker+defender pair.
// These are updated dynamically when attacker or defender stats change.
type AttackTable struct {
Attacker *Unit
Defender *Unit
BaseMissChance float64
BaseSpellMissChance float64
BaseBlockChance float64
BaseDodgeChance float64
BaseParryChance float64
BaseGlanceChance float64
GlanceMultiplier float64
MeleeCritSuppression float64
SpellCritSuppression float64
DamageDealtMultiplier float64 // attacker buff, applied in applyAttackerModifiers()
DamageTakenMultiplier float64 // defender debuff, applied in applyTargetModifiers()
HauntSEDamageTakenMultiplier float64
HealingDealtMultiplier float64
IgnoreArmor bool // Ignore defender's armor for specifically this attacker's attacks
BonusCritRating float64 // crit rating modifier
// This is for "Apply Aura: Mod Damage Done By Caster" effects.
// If set, the damage taken multiplier is multiplied by the callbacks result.
DamageDoneByCasterMultiplier DynamicDamageDoneByCaster
// When you need more then 1 active, default to using the above one
// Used with EnableDamageDoneByCaster/DisableDamageDoneByCaster
DamageDoneByCasterExtraMultiplier []DynamicDamageDoneByCaster
}
func NewAttackTable(attacker *Unit, defender *Unit) *AttackTable {
table := &AttackTable{
Attacker: attacker,
Defender: defender,
DamageDealtMultiplier: 1,
DamageTakenMultiplier: 1,
HauntSEDamageTakenMultiplier: 1,
HealingDealtMultiplier: 1,
}
if defender.Type == EnemyUnit {
// Assumes attacker (the Player) is level 80.
table.BaseSpellMissChance = UnitLevelFloat64(defender.Level, 0.04, 0.05, 0.06, 0.17)
table.BaseMissChance = UnitLevelFloat64(defender.Level, 0.05, 0.055, 0.06, 0.08)
table.BaseBlockChance = 0.05
table.BaseDodgeChance = UnitLevelFloat64(defender.Level, 0.05, 0.055, 0.06, 0.065)
table.BaseParryChance = UnitLevelFloat64(defender.Level, 0.05, 0.055, 0.06, 0.14)
table.BaseGlanceChance = UnitLevelFloat64(defender.Level, 0.06, 0.12, 0.18, 0.24)
table.GlanceMultiplier = UnitLevelFloat64(defender.Level, 0.95, 0.95, 0.85, 0.75)
table.MeleeCritSuppression = UnitLevelFloat64(defender.Level, 0, 0.01, 0.02, 0.048)
table.SpellCritSuppression = UnitLevelFloat64(defender.Level, 0, 0, 0.003, 0.021)
} else {
// Assumes defender (the Player) is level 80.
table.BaseSpellMissChance = 0.05
table.BaseMissChance = UnitLevelFloat64(attacker.Level, 0.05, 0.048, 0.046, 0.044)
table.BaseBlockChance = UnitLevelFloat64(attacker.Level, 0.05, 0.048, 0.046, 0.044)
table.BaseDodgeChance = UnitLevelFloat64(attacker.Level, 0, -0.002, -0.004, -0.006)
table.BaseParryChance = UnitLevelFloat64(attacker.Level, 0, -0.002, -0.004, -0.006)
}
return table
}
func EnableDamageDoneByCaster(index int, maxIndex int, attackTable *AttackTable, handler DynamicDamageDoneByCaster) {
if attackTable.DamageDoneByCasterExtraMultiplier == nil {
attackTable.DamageDoneByCasterExtraMultiplier = make([]DynamicDamageDoneByCaster, maxIndex)
}
attackTable.DamageDoneByCasterExtraMultiplier[index] = handler
}
func DisableDamageDoneByCaster(index int, attackTable *AttackTable) {
attackTable.DamageDoneByCasterExtraMultiplier[index] = nil
}