-
Notifications
You must be signed in to change notification settings - Fork 28
/
rage.go
242 lines (201 loc) · 7.09 KB
/
rage.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
package core
import (
"fmt"
"time"
"github.com/wowsims/sod/sim/core/proto"
)
const MaxRage = 100.0
const ThreatPerRageGained = 5
// OnRageChange is called any time rage is increased.
type OnRageChange func(aura *Aura, sim *Simulation, metrics *ResourceMetrics)
type rageBar struct {
unit *Unit
startingRage float64
currentRage float64
RageRefundMetrics *ResourceMetrics
}
type RageBarOptions struct {
StartingRage float64
RageMultiplier float64
}
func GetRageConversion(attacker_level int32) float64 {
if attacker_level == 25 {
return 82.25 // Tested
} else if attacker_level == 40 {
return 140.5 // Tested
} else if attacker_level < 45 {
// Poor fit, but better then current formula below 45
return 0.0215*float64(attacker_level^2) + 2.66*float64(attacker_level) + 0.89
} else {
// Rage conversion is adjusted according to target stats (https://web.archive.org/web/20201118213002/https://blue.mmo-champion.com/topic/18325-the-new-rage-formula-by-kalgan/)\
// So this is probably only the base value formula and will be slightly wrong for most target
return 0.0091107836*float64(attacker_level^2) + 3.225598133*float64(attacker_level) + 4.2652911
}
}
func (unit *Unit) EnableRageBar(options RageBarOptions) {
rageFromDamageTakenMetrics := unit.NewRageMetrics(ActionID{OtherID: proto.OtherAction_OtherActionDamageTaken})
rageConversion := GetRageConversion(unit.Level)
unit.SetCurrentPowerBar(RageBar)
unit.RegisterAura(Aura{
Label: "RageBar",
Duration: NeverExpires,
OnReset: func(aura *Aura, sim *Simulation) {
aura.Activate(sim)
},
OnSpellHitDealt: func(aura *Aura, sim *Simulation, spell *Spell, result *SpellResult) {
if unit.GetCurrentPowerBar() != RageBar {
return
}
if result.Outcome.Matches(OutcomeMiss) {
return
}
if spell.ProcMask != ProcMaskMeleeMHAuto && spell.ProcMask != ProcMaskMeleeOHAuto {
return
}
damage := result.Damage
if result.Outcome.Matches(OutcomeDodge | OutcomeParry) {
// Rage is still generated for dodges/parries, based on the damage it WOULD have done.
damage = result.PreOutcomeDamage
}
generatedRage := damage * 7.5 / rageConversion
generatedRage *= options.RageMultiplier
var metrics *ResourceMetrics
if spell.Cost != nil {
metrics = spell.Cost.(*RageCost).ResourceMetrics
} else {
if spell.ResourceMetrics == nil {
spell.ResourceMetrics = spell.Unit.NewRageMetrics(spell.ActionID)
}
metrics = spell.ResourceMetrics
}
unit.AddRage(sim, generatedRage, metrics)
},
OnSpellHitTaken: func(aura *Aura, sim *Simulation, spell *Spell, result *SpellResult) {
if unit.GetCurrentPowerBar() != RageBar {
return
}
rageConversionDamageTaken := GetRageConversion(spell.Unit.Level)
generatedRage := result.Damage * 2.5 / rageConversionDamageTaken
unit.AddRage(sim, generatedRage, rageFromDamageTakenMetrics)
},
})
// Not a real spell, just holds metrics from rage gain threat.
unit.RegisterSpell(SpellConfig{
ActionID: ActionID{OtherID: proto.OtherAction_OtherActionRageGain},
})
unit.rageBar = rageBar{
unit: unit,
startingRage: max(0, min(options.StartingRage, MaxRage)),
RageRefundMetrics: unit.NewRageMetrics(ActionID{OtherID: proto.OtherAction_OtherActionRefund}),
}
}
func (unit *Unit) HasRageBar() bool {
return unit.rageBar.unit != nil
}
func (rb *rageBar) CurrentRage() float64 {
return rb.currentRage
}
func (rb *rageBar) AddRage(sim *Simulation, amount float64, metrics *ResourceMetrics) {
if amount < 0 {
panic("Trying to add negative rage!")
}
newRage := min(rb.currentRage+amount, MaxRage)
metrics.AddEvent(amount, newRage-rb.currentRage)
if sim.Log != nil {
rb.unit.Log(sim, "Gained %0.3f rage from %s (%0.3f --> %0.3f).", amount, metrics.ActionID, rb.currentRage, newRage)
}
rb.currentRage = newRage
if !sim.Options.Interactive {
rb.unit.Rotation.DoNextAction(sim)
}
StartDelayedAction(sim, DelayedActionOptions{
DoAt: sim.CurrentTime + time.Millisecond*1,
OnAction: func(sim *Simulation) {
rb.unit.OnRageChange(sim, metrics)
},
})
}
func (rb *rageBar) SpendRage(sim *Simulation, amount float64, metrics *ResourceMetrics) {
if amount < 0 {
panic("Trying to spend negative rage!")
}
newRage := rb.currentRage - amount
metrics.AddEvent(-amount, -amount)
if sim.Log != nil {
rb.unit.Log(sim, "Spent %0.3f rage from %s (%0.3f --> %0.3f).", amount, metrics.ActionID, rb.currentRage, newRage)
}
rb.currentRage = newRage
rb.unit.OnRageChange(sim, metrics)
}
func (rb *rageBar) reset(_ *Simulation) {
if rb.unit == nil {
return
}
rb.currentRage = rb.startingRage
}
func (rb *rageBar) doneIteration() {
if rb.unit == nil {
return
}
rageGainSpell := rb.unit.GetSpell(ActionID{OtherID: proto.OtherAction_OtherActionRageGain})
for _, resourceMetrics := range rb.unit.Metrics.resources {
if resourceMetrics.Type != proto.ResourceType_ResourceTypeRage {
continue
}
if resourceMetrics.ActionID.SameActionIgnoreTag(ActionID{OtherID: proto.OtherAction_OtherActionDamageTaken}) {
continue
}
if resourceMetrics.ActionID.SameActionIgnoreTag(ActionID{OtherID: proto.OtherAction_OtherActionRefund}) {
continue
}
if resourceMetrics.ActualGain <= 0 {
continue
}
// Need to exclude rage gained from white hits. Rather than have a manual list of all IDs that would
// apply here (autos, WF attack, sword spec procs, etc), just check if the effect caused any damage.
sourceSpell := rb.unit.GetSpell(resourceMetrics.ActionID)
if sourceSpell != nil && sourceSpell.SpellMetrics[0].TotalDamage > 0 {
continue
}
rageGainSpell.SpellMetrics[0].Casts += resourceMetrics.EventsForCurrentIteration()
rageGainSpell.ApplyAOEThreatIgnoreMultipliers(resourceMetrics.ActualGainForCurrentIteration() * ThreatPerRageGained)
}
}
type RageCostOptions struct {
Cost float64
Refund float64
RefundMetrics *ResourceMetrics // Optional, will default to unit.RageRefundMetrics if not supplied.
}
type RageCost struct {
Refund float64
RefundMetrics *ResourceMetrics
ResourceMetrics *ResourceMetrics
}
func newRageCost(spell *Spell, options RageCostOptions) *RageCost {
spell.DefaultCast.Cost = options.Cost
if options.Refund > 0 && options.RefundMetrics == nil {
options.RefundMetrics = spell.Unit.RageRefundMetrics
}
return &RageCost{
Refund: options.Refund * options.Cost,
RefundMetrics: options.RefundMetrics,
ResourceMetrics: spell.Unit.NewRageMetrics(spell.ActionID),
}
}
func (rc *RageCost) MeetsRequirement(_ *Simulation, spell *Spell) bool {
spell.CurCast.Cost = spell.ApplyCostModifiers(spell.CurCast.Cost)
return spell.Unit.CurrentRage() >= spell.CurCast.Cost
}
func (rc *RageCost) CostFailureReason(sim *Simulation, spell *Spell) string {
return fmt.Sprintf("not enough rage (Current Rage = %0.03f, Rage Cost = %0.03f)", spell.Unit.CurrentRage(), spell.CurCast.Cost)
}
func (rc *RageCost) SpendCost(sim *Simulation, spell *Spell) {
if spell.CurCast.Cost > 0 {
spell.Unit.SpendRage(sim, spell.CurCast.Cost, rc.ResourceMetrics)
}
}
func (rc *RageCost) IssueRefund(sim *Simulation, spell *Spell) {
if rc.Refund > 0 {
spell.Unit.AddRage(sim, rc.Refund, rc.RefundMetrics)
}
}