-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMelee.lua
More file actions
executable file
·307 lines (253 loc) · 8.73 KB
/
Melee.lua
File metadata and controls
executable file
·307 lines (253 loc) · 8.73 KB
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
local GetBuffDataByIndex = C_UnitAuras.GetBuffDataByIndex
local GetInventoryItemID = GetInventoryItemID
local GetInventoryItemLink = GetInventoryItemLink
local pairs = pairs
---@class Data
local Data = ECSLoader:ImportModule("Data")
---@type DataUtils
local DataUtils = ECSLoader:ImportModule("DataUtils")
---@type Utils
local Utils = ECSLoader:ImportModule("Utils")
local _Melee = {}
local _, _, classId = UnitClass("player")
local DEMON = Data.CreatureType.DEMON
local UNDEAD = Data.CreatureType.UNDEAD
---@return number
function Data:GetMeleeAttackPower()
local melee, posBuff, negBuff = UnitAttackPower("player")
return melee + posBuff + negBuff
end
---@return table<CreatureType,number>
function Data:GetMeleeAttackPowerVsCreature()
local dmg = {0,0,0,0,0,0,0,0,0}
-- auras
local j = 1
repeat
local aura = GetBuffDataByIndex("player", j)
j = j + 1
if aura and aura.spellId then
for _,type in pairs(Data.CreatureType) do
if Data.Aura.AttackPowerVsCreature[type] then
dmg[type] = dmg[type] + (Data.Aura.AttackPowerVsCreature[type][aura.spellId] or 0)
end
if Data.Aura.PhysicalDamageVsCreature[type] then
dmg[type] = dmg[type] + (Data.Aura.PhysicalDamageVsCreature[type][aura.spellId] or 0)
end
end
end
until (not aura)
for i = 1, 18 do
-- items
local id, _ = GetInventoryItemID("player", i)
for _,type in pairs(Data.CreatureType) do
if Data.Item.PhysicalDamageVsCreature[type] then
dmg[type] = dmg[type] + (Data.Item.PhysicalDamageVsCreature[type][id] or 0)
end
end
-- enchants
local itemLink = GetInventoryItemLink("player", i)
if itemLink then
local enchant = DataUtils:GetEnchantFromItemLink(itemLink)
if enchant then
for _,type in pairs(Data.CreatureType) do
if Data.Enchant.PhysicalDamageVsCreature[type] then
dmg[type] = dmg[type] + (Data.Enchant.PhysicalDamageVsCreature[type][enchant] or 0)
end
end
end
end
end
-- sets
if Data:HasUndeadSlayer15() then dmg[UNDEAD] = dmg[UNDEAD] + 15 end
if Data:HasDemonSlaying200() then dmg[DEMON] = dmg[DEMON] + 200 end
return dmg
end
---@return string
function Data:GetMeleeAttackSpeedMainHand()
local mainHand, _ = UnitAttackSpeed("player")
return DataUtils:Round(mainHand, 2)
end
---@return number
function Data:GetMeleeAttackSpeedOffHand()
local _, offHand = UnitAttackSpeed("player")
return DataUtils:Round(offHand, 2)
end
---@return string
function Data:MeleeCrit()
return DataUtils:Round(GetCritChance(), 2) .. "%"
end
---@return string
function Data:MeleeHitBonus()
return DataUtils:Round(_Melee:GetHitRatingBonus(), 2) .. "%"
end
---@return number
function Data:MeleeHitRating()
if (not CR_HIT_MELEE) then
return 0
end
return GetCombatRating(CR_HIT_MELEE)
end
---@return number
function _Melee:GetHitRatingBonus()
local hit = _Melee:GetHitTalentBonus() + _Melee.GetHitFromRunes()
if CR_HIT_MELEE then
hit = hit + GetCombatRatingBonus(CR_HIT_MELEE)
end
-- GetHitModifier returns nil on dungeon entering/teleport
return hit + (GetHitModifier() or 0)
end
---In TBC and WotLK clients, if a talent spell has the "Apply Aura: Mod Melee & Ranged Hit Chance %", then GetHitModifier() already accounts for it and we don't need to handle it here.
---@return number
function _Melee:GetHitTalentBonus()
local mod = 0
if ECS.IsClassic then
if classId == Data.SHAMAN then
-- Nature's Guidance
mod = 1 * DataUtils:GetActiveTalentSpell({16180,16196,16198})
elseif classId == Data.ROGUE then
-- precision
mod = 1 * DataUtils:GetActiveTalentSpell({13705,13832,13843,13844,13845})
end
end
return mod
end
---@return number
function _Melee.GetHitFromRunes()
local mod = 0
if (not ECS.IsSoD) then
return mod
end
local finger1Rune = DataUtils.GetRuneForEquipSlot(Utils.CHAR_EQUIP_SLOTS.Finger1)
local finger2Rune = DataUtils.GetRuneForEquipSlot(Utils.CHAR_EQUIP_SLOTS.Finger2)
if classId == Data.DRUID and (finger1Rune == 7520 or finger2Rune == 7520) and DataUtils:IsShapeshifted() then
mod = mod + 3 -- 3% from Feral Combat Specialization Rune
end
return mod
end
---@return string
function Data:MeleeHitMissChanceSameLevel()
local mainBase, mainMod, _, _ = UnitAttackBothHands("player")
local playerLevel = UnitLevel("player")
local enemyDefenseValue = playerLevel * 5
local missChance
if DataUtils:IsShapeshifted() then
missChance = 5
else
missChance = DataUtils.GetMissChanceByDifference(mainBase + mainMod, enemyDefenseValue)
end
if Data:GetMeleeAttackSpeedOffHand() > 0 then
missChance = missChance + 19;
end
local hitValue = _Melee:GetHitRatingBonus()
missChance = missChance - hitValue
if missChance < 0 then
missChance = 0
elseif missChance > 100 then
missChance = 100
end
return DataUtils:Round(missChance, 2) .. "%"
end
---@return string
function Data:MeleeHitMissChanceBossLevel()
local mainBase, mainMod, _, _ = UnitAttackBothHands("player")
local playerLevel = UnitLevel("player")
local enemyDefenseValue = (playerLevel + 3) * 5
local missChance
if DataUtils:IsShapeshifted() then
missChance = ECS.IsWotlk and 8 or 9
else
missChance = DataUtils.GetMissChanceByDifference(mainBase + mainMod, enemyDefenseValue)
end
if Data:GetMeleeAttackSpeedOffHand() > 0 then
missChance = missChance + 19;
end
local hitValue = _Melee:GetHitRatingBonus()
missChance = missChance - hitValue
if missChance < 0 then
missChance = 0
elseif missChance > 100 then
missChance = 100
end
return DataUtils:Round(missChance, 2) .. "%"
end
function Data:GlanceHitChanceSameLevel()
return Data:GlanceHitChanceByLevel(0)
end
function Data:GlanceHitChanceBossLevel()
return Data:GlanceHitChanceByLevel(3)
end
---@return string
function Data:GlanceHitChanceByLevel(level)
local mainBase, mainMod, _, _ = UnitAttackBothHands("player")
local playerLevel = UnitLevel("player")
local enemyDefenseValue = (playerLevel + level) * 5
local glancingChance = DataUtils:GetGlancingChanceByDifference(playerLevel, mainBase + mainMod, enemyDefenseValue)
return DataUtils:Round(glancingChance*100, 2) .. "%"
end
---@return string
function Data:GlanceDamageSameLevel()
return Data:GlanceDamageByLevel(0)
end
---@return string
function Data:GlanceDamageBossLevel()
return Data:GlanceDamageByLevel(3)
end
---@return string
function Data:GlanceDamageByLevel(level)
local mainBase, mainMod, _, _ = UnitAttackBothHands("player")
local playerLevel = UnitLevel("player")
local enemyDefenseValue = (playerLevel + level) * 5
local glancePenalty = DataUtils:GetGlancingDamage(mainBase + mainMod, enemyDefenseValue)
return DataUtils:Round(glancePenalty*100, 2) .. "%"
end
---@return number
function Data:GetExpertise()
local expertise, _ = GetExpertise()
return DataUtils:Round(expertise, 0)
end
---@return number
function Data:GetExpertiseRating()
if (not CR_EXPERTISE) then
return 0
end
local expertiseRating = GetCombatRating(CR_EXPERTISE)
return DataUtils:Round(expertiseRating, 0)
end
---@return string
function Data:GetArmorPenetration()
local armorPenetration = GetArmorPenetration()
if ECS.IsWotlk and classId == Data.WARRIOR then
local _, isActive = GetShapeshiftFormInfo(1)
if isActive then
armorPenetration = armorPenetration + 10 -- 10% from Battle Stance
end
end
if classId == Data.DEATHKNIGHT then
armorPenetration = armorPenetration + 2 * DataUtils:GetActiveTalentSpell({61274,61275,61276,61277,61278}) -- Blood Gorged
end
return DataUtils:Round(armorPenetration, 2) .. "%"
end
---@return number
function Data:GetArmorPenetrationRating()
if (not CR_ARMOR_PENETRATION) then
return 0
end
local armorPenetrationRating = GetCombatRating(CR_ARMOR_PENETRATION)
return DataUtils:Round(armorPenetrationRating, 0)
end
---@return number
function Data:GetMeleeHasteRating()
if (not CR_HASTE_MELEE) then
return 0
end
local hasteRating = GetCombatRating(CR_HASTE_MELEE)
return DataUtils:Round(hasteRating, 0)
end
---@return string
function Data:GetMeleeHasteBonus()
if (not CR_HASTE_MELEE) then
return "0%"
end
local hasteBonus = GetCombatRatingBonus(CR_HASTE_MELEE)
return DataUtils:Round(hasteBonus, 2) .. "%"
end