-
Notifications
You must be signed in to change notification settings - Fork 28
/
spell_resistances.go
184 lines (156 loc) · 6.09 KB
/
spell_resistances.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
package core
import (
"github.com/wowsims/sod/sim/core/stats"
)
func (result *SpellResult) applyResistances(sim *Simulation, spell *Spell, isPeriodic bool, attackTable *AttackTable) {
resistanceMultiplier, outcome := spell.ResistanceMultiplier(sim, isPeriodic, attackTable)
result.Damage *= resistanceMultiplier
result.Outcome |= outcome
result.ResistanceMultiplier = resistanceMultiplier
result.PreOutcomeDamage = result.Damage
}
// Modifies damage based on Armor or Magic resistances, depending on the damage type.
func (spell *Spell) ResistanceMultiplier(sim *Simulation, isPeriodic bool, attackTable *AttackTable) (float64, HitOutcome) {
if spell.Flags.Matches(SpellFlagIgnoreResists) {
return 1, OutcomeEmpty
}
if spell.SpellSchool.Matches(SpellSchoolPhysical) {
if spell.SchoolIndex == stats.SchoolIndexPhysical || MultiSchoolShouldUseArmor(spell, attackTable.Defender) {
// All physical dots (Bleeds) ignore armor.
if isPeriodic {
return 1, OutcomeEmpty
}
// Physical resistance (armor).
return attackTable.GetArmorDamageModifier(spell), OutcomeEmpty
}
}
// Magical resistance.
if spell.Flags.Matches(SpellFlagBinary) {
return 1, OutcomeEmpty
}
resistanceRoll := sim.RandomFloat("Partial Resist")
threshold00, threshold25, threshold50 := attackTable.GetPartialResistThresholds(spell, spell.Flags.Matches(SpellFlagPureDot))
//if sim.Log != nil {
// sim.Log("Resist thresholds: %0.04f, %0.04f, %0.04f", threshold00, threshold25, threshold50)
//}
if resistanceRoll > threshold00 {
// No partial resist.
return 1, OutcomeEmpty
} else if resistanceRoll > threshold25 {
return 0.75, OutcomePartial1_4
} else if resistanceRoll > threshold50 {
return 0.5, OutcomePartial2_4
} else {
return 0.25, OutcomePartial3_4
}
}
// Decide whether to use armor for physical multi school spells.
//
// TODO: This is most likely not accurate for the case: armor near resistance but not 0
//
// A short test showed that the game uses armor if it's far enough below resistance,
// but not simply if it's lower.
// 49 (and above) armor vs 57 res => used resistance
// 7 (and below) armor vs 57 res => used armor/no partials anymore
// If level based resist is used in this decission process is also not known as it was tested PvP.
//
// For most purposes this should work fine for now, but should be properly tested and fixed if
// spells using it become important and boss armor can actually go below (level based) resistance values.
func MultiSchoolShouldUseArmor(spell *Spell, target *Unit) bool {
resistance := 100000.0
lowestIsArmor := true
for _, baseSchoolIndex := range spell.SchoolBaseIndices {
resiVal := target.GetResistanceForSchool(baseSchoolIndex)
if resiVal < resistance {
resistance = resiVal
lowestIsArmor = baseSchoolIndex == stats.SchoolIndexPhysical
}
}
return lowestIsArmor
}
func (at *AttackTable) GetArmorDamageModifier(spell *Spell) float64 {
armorPenRating := at.Attacker.stats[stats.ArmorPenetration]
defenderArmor := max(at.Defender.Armor()-armorPenRating, 0.0)
return 1 - defenderArmor/(defenderArmor+400+85*float64(at.Attacker.Level))
}
func (at *AttackTable) GetPartialResistThresholds(spell *Spell, pureDot bool) (float64, float64, float64) {
return at.Defender.partialResistRollThresholds(spell, at.Attacker, pureDot)
}
func (at *AttackTable) GetBinaryHitChance(spell *Spell) float64 {
return at.Defender.binaryHitChance(spell, at.Attacker)
}
// Only for base schools!
func (unit *Unit) GetResistanceForSchool(schoolIndex stats.SchoolIndex) float64 {
switch schoolIndex {
case stats.SchoolIndexNone:
return 0
case stats.SchoolIndexPhysical:
return unit.GetStat(stats.Armor)
case stats.SchoolIndexArcane:
return unit.GetStat(stats.ArcaneResistance)
case stats.SchoolIndexFire:
return unit.GetStat(stats.FireResistance)
case stats.SchoolIndexFrost:
return unit.GetStat(stats.FrostResistance)
case stats.SchoolIndexHoly:
return 0 // Holy resistance doesn't exist.
case stats.SchoolIndexNature:
return unit.GetStat(stats.NatureResistance)
case stats.SchoolIndexShadow:
return unit.GetStat(stats.ShadowResistance)
default:
return 0
}
}
// All of the following calculations are based on this guide:
// https://royalgiraffe.github.io/resist-guide
func (unit *Unit) resistCoeff(spell *Spell, attacker *Unit, binary bool, pureDot bool) float64 {
if spell.SchoolIndex <= stats.SchoolIndexPhysical {
return 0
}
var resistance float64
if spell.SchoolIndex.IsMultiSchool() {
// Multi school: Choose the lowest resistance available.
resistance = 1000.0
for _, baseSchoolIndex := range spell.SchoolBaseIndices {
resiVal := unit.GetResistanceForSchool(baseSchoolIndex)
if resiVal < resistance {
resistance = resiVal
}
}
} else {
resistance = unit.GetResistanceForSchool(spell.SchoolIndex)
}
resistance = max(0, resistance-attacker.stats[stats.SpellPenetration])
resistanceCap := float64(attacker.Level * 5)
resistanceCoef := resistance / resistanceCap
// Pre-TBC all dots that don't have an initial damage component
// use a 1/10 of the resistance score
if pureDot {
resistanceCoef /= 10
}
if !binary && unit.Type == EnemyUnit && unit.Level > attacker.Level {
avgMitigationAdded := AverageMagicPartialResistPerLevelMultiplier * float64(unit.Level-attacker.Level)
// coef is scaled 0 to 1, not 0 to 0.75
resistanceCoef += avgMitigationAdded * 1 / 0.75
}
return min(1, resistanceCoef)
}
func (unit *Unit) binaryHitChance(spell *Spell, attacker *Unit) float64 {
resistCoeff := unit.resistCoeff(spell, attacker, true, false)
return 1 - 0.75*resistCoeff
}
// Roll threshold for each type of partial resist.
func (unit *Unit) partialResistRollThresholds(spell *Spell, attacker *Unit, pureDot bool) (float64, float64, float64) {
resistCoeff := unit.resistCoeff(spell, attacker, false, pureDot)
// Based on the piecewise linear regression estimates at https://royalgiraffe.github.io/partial-resist-table.
if val := resistCoeff * 3; val <= 1 {
return 0.76 * val, 0.21 * val, 0.03 * val
} else if val <= 2 {
val -= 1
return 0.76 + 0.24*val, 0.21 + 0.57*val, 0.03 + 0.19*val
} else {
val -= 2
return 1, 0.78 + 0.18*val, 0.22 + 0.58*val
}
}