Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
264 lines (236 loc) · 8.94 KB
/
Copy pathCore.lua
File metadata and controls
264 lines (236 loc) · 8.94 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
-- Wick's Stats
-- Core.lua: stat collection + event wiring
local ADDON, ns = ...
WicksStats = WicksStats or {}
local WS = WicksStats
ns.WS = WS
local _, playerClass = UnitClass("player")
WS.playerClass = playerClass
local MANA_CLASSES = {
PRIEST = true, MAGE = true, WARLOCK = true, PALADIN = true,
DRUID = true, SHAMAN = true, HUNTER = true,
}
local HEAL_CAPABLE = {
PRIEST = true, PALADIN = true, DRUID = true, SHAMAN = true,
}
local CAN_PARRY = {
WARRIOR = true, PALADIN = true, ROGUE = true, HUNTER = true, SHAMAN = true,
}
local CAN_BLOCK = {
WARRIOR = true, PALADIN = true, SHAMAN = true,
}
WS.showSpell = true
WS.showHeal = HEAL_CAPABLE[playerClass] or false
WS.showMana = MANA_CLASSES[playerClass] or false
WS.showParry = CAN_PARRY[playerClass] or false
WS.showBlock = CAN_BLOCK[playerClass] or false
local function safeCall(fn, ...)
if type(fn) ~= "function" then return 0 end
local ok, v = pcall(fn, ...)
if ok then return v or 0 end
return 0
end
local function attr(idx)
local _, eff, pos, neg = UnitStat("player", idx)
eff = eff or 0
pos = pos or 0
neg = neg or 0
return {
total = eff,
pos = pos,
neg = neg,
baseGear = eff - pos - neg,
}
end
function WS:Collect()
local s = {}
s.str = attr(1)
s.agi = attr(2)
s.sta = attr(3)
s.int = attr(4)
s.spi = attr(5)
s.hp = UnitHealthMax("player")
s.mp = UnitPowerMax("player", 0)
-- Melee
local apBase, apPos, apNeg = UnitAttackPower("player")
s.ap = apBase + (apPos or 0) + (apNeg or 0)
s.apBase = apBase
s.apPos = apPos or 0
s.apNeg = apNeg or 0
s.crit = safeCall(GetCritChance)
s.hitMelee = (safeCall(GetHitModifier)) + safeCall(GetCombatRatingBonus, CR_HIT_MELEE)
s.hitMeleeRating = safeCall(GetCombatRating, CR_HIT_MELEE)
s.expRating = safeCall(GetCombatRating, CR_EXPERTISE)
s.expertise = safeCall(GetExpertise)
s.haste = safeCall(GetCombatRatingBonus, CR_HASTE_MELEE)
s.hasteRating = safeCall(GetCombatRating, CR_HASTE_MELEE)
if UnitAttackBothHands then
local mhB, mhM, ohB, ohM = UnitAttackBothHands("player")
s.weaponSkillMH = (mhB or 0) + (mhM or 0)
s.weaponSkillOH = (ohB or 0) + (ohM or 0)
end
local mhSpeed, ohSpeed = UnitAttackSpeed("player")
s.atkSpeedMH = mhSpeed or 0
s.atkSpeedOH = ohSpeed
-- Ranged
local rapBase, rapPos, rapNeg = UnitRangedAttackPower("player")
s.rap = rapBase + (rapPos or 0) + (rapNeg or 0)
s.rapBase = rapBase
s.rapPos = rapPos or 0
s.rapNeg = rapNeg or 0
s.rcrit = safeCall(GetRangedCritChance)
s.rhit = (safeCall(GetHitModifier)) + safeCall(GetCombatRatingBonus, CR_HIT_RANGED)
s.rhitRating = safeCall(GetCombatRating, CR_HIT_RANGED)
s.rhaste = safeCall(GetCombatRatingBonus, CR_HASTE_RANGED)
-- Spell power per school (school index for spell APIs: 1=Phys 2=Holy 3=Fire 4=Nature 5=Frost 6=Shadow 7=Arcane)
s.spHoly = safeCall(GetSpellBonusDamage, 2)
s.spFire = safeCall(GetSpellBonusDamage, 3)
s.spNature = safeCall(GetSpellBonusDamage, 4)
s.spFrost = safeCall(GetSpellBonusDamage, 5)
s.spShadow = safeCall(GetSpellBonusDamage, 6)
s.spArcane = safeCall(GetSpellBonusDamage, 7)
s.healing = safeCall(GetSpellBonusHealing)
local bestCrit, bestSchool = 0, 2
for sch = 2, 7 do
local c = safeCall(GetSpellCritChance, sch)
if c > bestCrit then bestCrit = c; bestSchool = sch end
end
s.scrit = bestCrit
s.scritSchool = bestSchool
s.scritHoly = safeCall(GetSpellCritChance, 2)
s.scritFire = safeCall(GetSpellCritChance, 3)
s.scritNature = safeCall(GetSpellCritChance, 4)
s.scritFrost = safeCall(GetSpellCritChance, 5)
s.scritShadow = safeCall(GetSpellCritChance, 6)
s.scritArcane = safeCall(GetSpellCritChance, 7)
s.shitFlat = safeCall(GetSpellHitModifier)
s.shitRating = safeCall(GetCombatRating, CR_HIT_SPELL)
s.shit = s.shitFlat + safeCall(GetCombatRatingBonus, CR_HIT_SPELL)
s.shaste = safeCall(GetCombatRatingBonus, CR_HASTE_SPELL)
s.shasteRating = safeCall(GetCombatRating, CR_HASTE_SPELL)
s.spen = safeCall(GetSpellPenetration)
-- Defenses
local _, armorEff, armor, armorPos, armorNeg = UnitArmor("player")
s.armor = armorEff or 0
s.armorBaseGear = armor or 0
s.armorPos = armorPos or 0
s.armorNeg = armorNeg or 0
-- Damage reduction vs level 73 attacker (raid boss): armor / (armor + 11960)
s.armorReduction = (s.armor / (s.armor + 11960)) * 100
local defBase, defMod = UnitDefense("player")
s.defenseBase = defBase or 0
s.defenseMod = defMod or 0
s.defense = (defBase or 0) + (defMod or 0)
s.defRating = safeCall(GetCombatRating, CR_DEFENSE_SKILL)
s.dodge = safeCall(GetDodgeChance)
s.dodgeRating = safeCall(GetCombatRating, CR_DODGE)
s.parry = safeCall(GetParryChance)
s.parryRating = safeCall(GetCombatRating, CR_PARRY)
s.block = safeCall(GetBlockChance)
s.blockRating = safeCall(GetCombatRating, CR_BLOCK)
s.blockValue = safeCall(GetShieldBlock)
local CR_RESIL = COMBAT_RATING_RESILIENCE_CRIT_TAKEN or CR_RESILIENCE_CRIT_TAKEN
s.resilienceRating = safeCall(GetCombatRating, CR_RESIL)
s.resilienceCritReduce = safeCall(GetCombatRatingBonus, CR_RESIL)
-- Each defense point above 350 (level 70 base) reduces enemy crit chance by 0.04%
local defCritReduce = math.max(0, s.defense - 350) * 0.04
s.critReduction = s.resilienceCritReduce + defCritReduce
-- Resistances (UnitResistance school: 1=Holy 2=Fire 3=Nature 4=Frost 5=Shadow 6=Arcane)
local function resAt(idx)
local _, val = UnitResistance("player", idx)
return val or 0
end
s.resHoly = resAt(1)
s.resFire = resAt(2)
s.resNature = resAt(3)
s.resFrost = resAt(4)
s.resShadow = resAt(5)
s.resArcane = resAt(6)
-- Mana regen (per second, multiply by 5 for MP5 display)
local oFSR, iFSR = GetManaRegen()
s.mp5out = (oFSR or 0) * 5
s.mp5in = (iFSR or 0) * 5
-- Apply simulated raid buffs if the toggle is on (mutates s in place)
if WicksStatsSettings and WicksStatsSettings.simulateRaidBuffs and self.SimulateRaidBuffs then
self:SimulateRaidBuffs(s)
end
self.stats = s
return s
end
-- ====== EVENT WIRING ======
local f = CreateFrame("Frame")
WS.eventFrame = f
local EVENTS = {
"PLAYER_ENTERING_WORLD",
"PLAYER_LOGIN",
"UNIT_AURA",
"UNIT_INVENTORY_CHANGED",
"UNIT_DAMAGE",
"UNIT_RANGED_DAMAGE",
"UNIT_ATTACK_POWER",
"UNIT_RANGED_ATTACK_POWER",
"UNIT_ATTACK_SPEED",
"UNIT_RESISTANCES",
"UNIT_STATS",
"UNIT_DEFENSE",
"UNIT_MAXHEALTH",
"UNIT_MAXMANA",
"COMBAT_RATING_UPDATE",
"PLAYER_DAMAGE_DONE_MODS",
"SPELL_POWER_CHANGED",
"PLAYER_REGEN_DISABLED",
"PLAYER_REGEN_ENABLED",
}
for _, e in ipairs(EVENTS) do
pcall(f.RegisterEvent, f, e)
end
f:SetScript("OnEvent", function(self, event, arg1)
if event == "PLAYER_LOGIN" then
WicksStatsSettings = WicksStatsSettings or {}
if WS.OnLogin then WS:OnLogin() end
return
end
if event == "PLAYER_ENTERING_WORLD" then
-- First run: seed buffsEnabled from currently-active buffs
if WicksStatsSettings and not WicksStatsSettings._buffsSeeded then
if WS.MatchEnabledToCurrent then WS:MatchEnabledToCurrent() end
WicksStatsSettings._buffsSeeded = true
end
end
-- Unit-scoped events: ignore non-player units
if arg1 and type(arg1) == "string" and arg1 ~= "player" then
if event:sub(1,5) == "UNIT_" then return end
end
WS.dirty = true
end)
-- Slash command
SLASH_WICKSSTATS1 = "/wickstats"
SLASH_WICKSSTATS2 = "/wstats"
SlashCmdList.WICKSSTATS = function(input)
input = input or ""
local cmd, rest = input:match("^(%S*)%s*(.*)$")
cmd = (cmd or ""):lower()
if cmd == "snap" or cmd == "snapshot" then
if WS.HandleSnapshotCommand then WS:HandleSnapshotCommand(rest) end
elseif cmd == "spec" then
local spec = (rest or ""):gsub("^%s*(.-)%s*$", "%1")
if spec == "" or spec == "auto" then
WicksStatsSettings.specOverride = nil
print("|cff4FC778Wick's Stats|r: spec set to auto-detect")
else
WicksStatsSettings.specOverride = spec
print(string.format("|cff4FC778Wick's Stats|r: spec override set to |cffD4C8A1%s|r", spec))
end
WS.dirty = true
elseif cmd == "help" or cmd == "?" then
print("|cff4FC778Wick's Stats|r commands:")
print(" /wickstats toggle the panel")
print(" /wickstats snap save <name>")
print(" /wickstats snap list")
print(" /wickstats snap diff <name>")
print(" /wickstats snap rm <name>")
print(" /wickstats spec <name>|auto")
else
if WS.Toggle then WS:Toggle() end
end
end