forked from Lexiebean/BetterCharacterStats
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBetterCharacterStats.lua
1512 lines (1284 loc) · 45.2 KB
/
BetterCharacterStats.lua
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
BCS = BCS or {}
BCSConfig = BCSConfig or {}
local L, IndexLeft, IndexRight
L = BCS.L
local AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0")
-- Tree of Life aura bonus from other players, your own is calculated in GetHealingPower()
local aura = .0
BCS.PLAYERSTAT_DROPDOWN_OPTIONS = {
"PLAYERSTAT_BASE_STATS",
"PLAYERSTAT_MELEE_COMBAT",
"PLAYERSTAT_MELEE_BOSS",
"PLAYERSTAT_RANGED_COMBAT",
"PLAYERSTAT_SPELL_COMBAT",
"PLAYERSTAT_SPELL_SCHOOLS",
"PLAYERSTAT_DEFENSES",
"PLAYERSTAT_DEFENSES_BOSS",
}
BCS.PaperDollFrame = PaperDollFrame
BCS.Debug = false
BCS.DebugStack = {}
function BCS:DebugTrace(start, limit)
BCS.Debug = nil
local length = getn(BCS.DebugStack)
if not start then
start = 1
end
if start > length then
start = length
end
if not limit then
limit = start + 30
end
BCS:Print("length: " .. length)
BCS:Print("start: " .. start)
BCS:Print("limit: " .. limit)
for i = start, length, 1 do
BCS:Print("[" .. i .. "] Event: " .. BCS.DebugStack[i].E)
BCS:Print(format(
"[%d] `- Arguments: %s, %s, %s, %s, %s",
i,
BCS.DebugStack[i].arg1,
BCS.DebugStack[i].arg2,
BCS.DebugStack[i].arg3,
BCS.DebugStack[i].arg4,
BCS.DebugStack[i].arg5
))
if i >= limit then
i = length
end
end
end
function BCS:Print(message)
ChatFrame2:AddMessage("[BCS] " .. message, 0.63, 0.86, 1.0)
end
function BCS:OnLoad()
CharacterAttributesFrame:Hide()
PaperDollFrame:UnregisterEvent('UNIT_DAMAGE')
PaperDollFrame:UnregisterEvent('PLAYER_DAMAGE_DONE_MODS')
PaperDollFrame:UnregisterEvent('UNIT_ATTACK_SPEED')
PaperDollFrame:UnregisterEvent('UNIT_RANGEDDAMAGE')
PaperDollFrame:UnregisterEvent('UNIT_ATTACK')
PaperDollFrame:UnregisterEvent('UNIT_STATS')
PaperDollFrame:UnregisterEvent('UNIT_ATTACK_POWER')
PaperDollFrame:UnregisterEvent('UNIT_RANGED_ATTACK_POWER')
self.Frame = BCSFrame
self.needUpdate = nil
self.Frame:RegisterEvent("ADDON_LOADED")
self.Frame:RegisterEvent("CHARACTER_POINTS_CHANGED") -- fires when learning talent
self.Frame:RegisterEvent("PLAYER_AURAS_CHANGED") -- buffs/warrior stances
self.Frame:RegisterEvent("CHAT_MSG_SKILL") --gaining weapon skill
self.Frame:RegisterEvent("CHAT_MSG_ADDON") --needed to recieve aura bonuses from other people
AceEvent:RegisterBucketEvent("UNIT_INVENTORY_CHANGED", 0.3, function(args)
if args["player"] then
BCS.needScanGear = true
BCS.needScanSkills = true
if BCS.PaperDollFrame:IsVisible() then
BCS:UpdateStats()
else
BCS.needUpdate = true
end
end
end)
end
local function PostHookFunction(original, hook)
return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
original(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
hook(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
end
end
-- there is less space for player character model with this addon, zoom out and move it up slightly
local z, x, y = -0.2, 0, 0.1
function BCS_PaperDollFrame_OnEvent(event, unit)
if (event == "PLAYER_ENTERING_WORLD") then
CharacterModelFrame:SetPosition(0, 0, 0)
CharacterModelFrame:SetUnit("player")
CharacterModelFrame:SetPosition(z, x, y)
return
end
if (unit and unit == "player") then
if (event == "UNIT_MODEL_CHANGED") then
CharacterModelFrame:SetPosition(0, 0, 0)
CharacterModelFrame:SetUnit("player")
CharacterModelFrame:SetPosition(z, x, y)
return
end
end
end
function BCS_PaperDollFrame_OnShow()
CharacterModelFrame:SetPosition(0, 0, 0)
CharacterModelFrame:SetUnit("player")
CharacterModelFrame:SetPosition(z, x, y)
end
PaperDollFrame_OnShow = PostHookFunction(PaperDollFrame_OnShow, BCS_PaperDollFrame_OnShow)
PaperDollFrame_OnEvent = PostHookFunction(PaperDollFrame_OnEvent, BCS_PaperDollFrame_OnEvent)
local function strsplit(delimiter, subject)
if not subject then
return nil
end
local delimiter, fields = delimiter or ":", {}
local pattern = string.format("([^%s]+)", delimiter)
string.gsub(subject, pattern, function(c)
fields[table.getn(fields) + 1] = c
end)
return unpack(fields)
end
-- Scan stuff depending on event, but make sure to scan everything when addon is loaded
function BCS:OnEvent()
--[[if BCS.Debug then
local t = {
E = event,
arg1 = arg1 or "nil",
arg2 = arg2 or "nil",
arg3 = arg3 or "nil",
arg4 = arg4 or "nil",
arg5 = arg5 or "nil",
}
tinsert(BCS.DebugStack, t)
end]]
if event == "CHAT_MSG_ADDON" and arg1 == "bcs" then
BCS.needScanAuras = true
local type, player, amount = strsplit(",", arg2)
if type and player and amount then
if player ~= UnitName("player") then
amount = tonumber(amount)
if type == "TREE" then
--BCS:Print("got tree response amount="..amount)
if amount >= aura then
aura = amount
if BCS.PaperDollFrame:IsVisible() then
BCS:UpdateStats()
else
BCS.needUpdate = true
end
end
end
end
end
elseif event == "PLAYER_AURAS_CHANGED" then
BCS.needScanAuras = true
if not BCS:GetPlayerAura("Tree of Life Aura") then
aura = 0
end
if BCS.PaperDollFrame:IsVisible() then
BCS:UpdateStats()
else
BCS.needUpdate = true
end
elseif event == "CHARACTER_POINTS_CHANGED" then
BCS.needScanTalents = true
if BCS.PaperDollFrame:IsVisible() then
BCS:UpdateStats()
else
BCS.needUpdate = true
end
elseif event == "CHAT_MSG_SKILL" then
BCS.needScanSkills = true
if BCS.PaperDollFrame:IsVisible() then
BCS:UpdateStats()
else
BCS.needUpdate = true
end
elseif event == "ADDON_LOADED" and arg1 == "BetterCharacterStats" then
BCSFrame:UnregisterEvent("ADDON_LOADED")
local _, race = UnitRace("player")
if race == "Gnome" then
y = 0
elseif race == "Dwarf" then
y = 0.05
elseif race == "Troll" then
y = 0.15
end
BCS.needScanGear = true
BCS.needScanTalents = true
BCS.needScanAuras = true
BCS.needScanSkills = true
IndexLeft = BCSConfig["DropdownLeft"] or BCS.PLAYERSTAT_DROPDOWN_OPTIONS[1]
IndexRight = BCSConfig["DropdownRight"] or BCS.PLAYERSTAT_DROPDOWN_OPTIONS[2]
UIDropDownMenu_SetSelectedValue(PlayerStatFrameLeftDropDown, IndexLeft)
UIDropDownMenu_SetSelectedValue(PlayerStatFrameRightDropDown, IndexRight)
end
end
--sending messages
local sender = CreateFrame("Frame", "BCSsender")
sender:RegisterEvent("PLAYER_AURAS_CHANGED")
sender:RegisterEvent("CHAT_MSG_ADDON")
sender:SetScript("OnEvent", function()
if not (UnitInParty("player") or UnitInRaid("player")) then
return
end
if event then
local player = UnitName("player")
if event == "PLAYER_AURAS_CHANGED" then
if BCS:GetPlayerAura("Tree of Life Aura") then
SendAddonMessage("bcs", "TREE"..","..player, "PARTY")
--BCS:Print("sent tree request")
end
end
if event == "CHAT_MSG_ADDON" and arg1 == "bcs" then
local type, name, amount = strsplit(",", arg2)
if name ~= player then
local _, treebonus = BCS:GetHealingPower()
if not amount and type == "TREE" and treebonus then
SendAddonMessage("bcs", "TREE"..","..player..","..treebonus, "PARTY")
--BCS:Print("sent tree response, amount="..treebonus)
end
end
end
end
end)
function BCS:OnShow()
if BCS.needUpdate then
BCS.needUpdate = nil
BCS:UpdateStats()
end
end
-- debugging / profiling
--local avgV = {}
--local avg = 0
function BCS:UpdateStats()
--[[if BCS.Debug then
local e = event or "nil"
BCS:Print("Update due to " .. e)
end
local beginTime = debugprofilestop()]]
BCS:UpdatePaperdollStats("PlayerStatFrameLeft", IndexLeft)
BCS:UpdatePaperdollStats("PlayerStatFrameRight", IndexRight)
BCS.needScanGear = false
BCS.needScanTalents = false
BCS.needScanAuras = false
BCS.needScanSkills = false
--[[local timeUsed = debugprofilestop()-beginTime
table.insert(avgV, timeUsed)
avg = 0
for i,v in ipairs(avgV) do
avg = avg + v
end
avg = avg / getn(avgV)
BCS:Print(format("Average: %d (%d results), Exact: %d", avg, getn(avgV), timeUsed))]]
end
local function BCS_AddTooltip(statFrame, tooltipExtra)
if statFrame.tooltip then
statFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText(this.tooltip)
GameTooltip:AddLine(this.tooltipSubtext, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
if tooltipExtra then
GameTooltip:AddLine(tooltipExtra)
end
GameTooltip:Show()
end)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
end
local function BCS_AddDamageTooltip(damageText, statFrame, speed, offhandSpeed, ranged)
local rangedAttackSpeed, minDamage, maxDamage, physicalBonusPos, physicalBonusNeg, percent
local minOffHandDamage, maxOffHandDamage
if ranged then
rangedAttackSpeed, minDamage, maxDamage, physicalBonusPos, physicalBonusNeg, percent = UnitRangedDamage("player")
speed = rangedAttackSpeed
else
minDamage, maxDamage, minOffHandDamage, maxOffHandDamage, physicalBonusPos, physicalBonusNeg, percent = UnitDamage("player")
end
local displayMin = max(floor(minDamage), 1)
local displayMax = max(ceil(maxDamage), 1)
minDamage = (minDamage / percent) - physicalBonusPos - physicalBonusNeg
maxDamage = (maxDamage / percent) - physicalBonusPos - physicalBonusNeg
local baseDamage = (minDamage + maxDamage) * 0.5
local fullDamage = (baseDamage + physicalBonusPos + physicalBonusNeg) * percent
local totalBonus = (fullDamage - baseDamage)
local damagePerSecond = (max(fullDamage, 1) / speed)
local damageTooltip = max(floor(minDamage), 1) .. " - " .. max(ceil(maxDamage), 1)
local green = "|cff20ff20"
local red = "|cffff2020"
if (totalBonus == 0) then
if ((displayMin < 100) and (displayMax < 100)) then
damageText:SetText(displayMin .. " - " .. displayMax)
else
damageText:SetText(displayMin .. "-" .. displayMax)
end
else
local color
if (totalBonus > 0) then
color = green
else
color = red
end
if ((displayMin < 100) and (displayMax < 100)) then
damageText:SetText(color .. displayMin .. " - " .. displayMax .. "|r")
else
damageText:SetText(color .. displayMin .. "-" .. displayMax .. "|r")
end
if (physicalBonusPos > 0) then
damageTooltip = damageTooltip .. green .. " +" .. physicalBonusPos .. "|r"
end
if (physicalBonusNeg < 0) then
damageTooltip = damageTooltip .. red .. " " .. physicalBonusNeg .. "|r"
end
if (percent > 1) then
damageTooltip = damageTooltip .. green .. " x" .. floor(percent * 100 + 0.5) .. "%|r"
elseif (percent < 1) then
damageTooltip = damageTooltip .. red .. " x" .. floor(percent * 100 + 0.5) .. "%|r"
end
end
statFrame.damage = damageTooltip
statFrame.attackSpeed = speed
statFrame.dps = damagePerSecond
-- If there's an offhand speed then add the offhand info to the tooltip
if (offhandSpeed) then
minOffHandDamage = (minOffHandDamage / percent) - physicalBonusPos - physicalBonusNeg
maxOffHandDamage = (maxOffHandDamage / percent) - physicalBonusPos - physicalBonusNeg
local offhandBaseDamage = (minOffHandDamage + maxOffHandDamage) * 0.5
local offhandFullDamage = (offhandBaseDamage + physicalBonusPos + physicalBonusNeg) * percent
local offhandDamagePerSecond = (max(offhandFullDamage, 1) / offhandSpeed)
local offhandDamageTooltip = max(floor(minOffHandDamage), 1) .. " - " .. max(ceil(maxOffHandDamage), 1)
if (physicalBonusPos > 0) then
offhandDamageTooltip = offhandDamageTooltip .. green .. " +" .. physicalBonusPos .. "|r"
end
if (physicalBonusNeg < 0) then
offhandDamageTooltip = offhandDamageTooltip .. red .. " " .. physicalBonusNeg .. "|r"
end
if (percent > 1) then
offhandDamageTooltip = offhandDamageTooltip .. green .. " x" .. floor(percent * 100 + 0.5) .. "%|r"
elseif (percent < 1) then
offhandDamageTooltip = offhandDamageTooltip .. red .. " x" .. floor(percent * 100 + 0.5) .. "%|r"
end
statFrame.offhandDamage = offhandDamageTooltip
statFrame.offhandAttackSpeed = offhandSpeed
statFrame.offhandDps = offhandDamagePerSecond
else
statFrame.offhandAttackSpeed = nil
end
if ranged then
statFrame:SetScript("OnEnter", CharacterRangedDamageFrame_OnEnter)
else
statFrame:SetScript("OnEnter", CharacterDamageFrame_OnEnter)
end
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
function BCS:SetStat(statFrame, statIndex)
local label = getglobal(statFrame:GetName() .. "Label")
local text = getglobal(statFrame:GetName() .. "StatText")
local statIndexTable = {
"STRENGTH",
"AGILITY",
"STAMINA",
"INTELLECT",
"SPIRIT",
}
statFrame:SetScript("OnEnter", function()
PaperDollStatTooltip("player", statIndexTable[statIndex])
end)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
label:SetText(TEXT(getglobal("SPELL_STAT" .. (statIndex - 1) .. "_NAME")) .. ":")
local stat, effectiveStat, posBuff, negBuff = UnitStat("player", statIndex)
-- Set the tooltip text
local tooltipText = HIGHLIGHT_FONT_COLOR_CODE .. getglobal("SPELL_STAT" .. (statIndex - 1) .. "_NAME") .. " "
if ((posBuff == 0) and (negBuff == 0)) then
text:SetText(effectiveStat)
statFrame.tooltip = tooltipText .. effectiveStat .. FONT_COLOR_CODE_CLOSE
else
tooltipText = tooltipText .. effectiveStat
if (posBuff > 0 or negBuff < 0) then
tooltipText = tooltipText .. " (" .. (stat - posBuff - negBuff) .. FONT_COLOR_CODE_CLOSE
end
if (posBuff > 0) then
tooltipText = tooltipText .. FONT_COLOR_CODE_CLOSE .. GREEN_FONT_COLOR_CODE .. "+" .. posBuff .. FONT_COLOR_CODE_CLOSE
end
if (negBuff < 0) then
tooltipText = tooltipText .. RED_FONT_COLOR_CODE .. " " .. negBuff .. FONT_COLOR_CODE_CLOSE
end
if (posBuff > 0 or negBuff < 0) then
tooltipText = tooltipText .. HIGHLIGHT_FONT_COLOR_CODE .. ")" .. FONT_COLOR_CODE_CLOSE
end
statFrame.tooltip = tooltipText
-- If there are any negative buffs then show the main number in red even if there are
-- positive buffs. Otherwise show in green.
if (negBuff < 0) then
text:SetText(RED_FONT_COLOR_CODE .. effectiveStat .. FONT_COLOR_CODE_CLOSE)
else
text:SetText(GREEN_FONT_COLOR_CODE .. effectiveStat .. FONT_COLOR_CODE_CLOSE)
end
end
end
function BCS:SetArmor(statFrame)
local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player")
local label = getglobal(statFrame:GetName() .. "Label")
local text = getglobal(statFrame:GetName() .. "StatText")
PaperDollFormatStat(ARMOR, base, posBuff, negBuff, statFrame, text)
label:SetText(TEXT(ARMOR_COLON))
local playerLevel = UnitLevel("player")
local armorReduction = effectiveArmor / ((85 * playerLevel) + 400)
armorReduction = 100 * (armorReduction / (armorReduction + 1))
statFrame.tooltipSubtext = format(ARMOR_TOOLTIP, playerLevel, armorReduction)
BCS_AddTooltip(statFrame)
end
function BCS:GetMissChanceRaw(wepSkill)
local _, ver = pcall(GetBuildInfo)
local diff = wepSkill - 315
local miss = 5
if ver == "1.17.2" then
miss = miss - (diff * 0.2) - BCS:GetHitRating()
else
if diff < -10 then
miss = miss - diff * 0.2;
else
miss = miss - diff * 0.1;
end
local hitChance = BCS:GetHitRating()
-- if skill diff < -10 then subtract one from +hit, if there is any +hit
if (diff < -10) and (hitChance > 0) then
hitChance = hitChance - 1
end
miss = miss - hitChance
end
return miss
end
function BCS:GetMissChance(wepSkill)
return max(0, min(BCS:GetMissChanceRaw(wepSkill), 60))
end
function BCS:GetDualWieldMissChance(wepSkill)
return max(0, min(BCS:GetMissChanceRaw(wepSkill) + 19, 60))
end
function BCS:GetGlanceChance(wepSkill)
return 10 + 15 * 2;
end
function BCS:GetGlanceReduction(wepSkill)
local _, ver = pcall(GetBuildInfo)
if ver == "1.17.2" then
return 65 + (wepSkill - 300) * 2
else
local diff = 315 - wepSkill;
local low = math.max(math.min(1.3 - 0.05 * diff, 0.91), 0.01);
local high = math.max(math.min(1.2 - 0.03 * diff, 0.99), 0.2);
return 100 * ((high - low) / 2 + low);
end
end
function BCS:GetDodgeChance(wepSkill)
return math.max(5 + (315 - wepSkill) * 0.1, 0);
end
function BCS:GetDualWieldCritCap(wepSkill)
local cap = 100 - self:GetDualWieldMissChance(wepSkill) - self:GetGlanceChance(wepSkill) - self:GetDodgeChance(wepSkill);
if (cap > 100) then
cap = 100;
end
if (cap < 0) then
cap = 0;
end
return cap;
end
function BCS:GetCritCap(wepSkill)
local cap = 100 - self:GetMissChance(wepSkill) - self:GetGlanceChance(wepSkill) - self:GetDodgeChance(wepSkill);
if (cap > 100) then
cap = 100;
end
if (cap < 0) then
cap = 0;
end
return cap;
end
function BCS:GetEffectiveBlockChance(leveldiff)
local block = GetBlockChance() - ((5 * leveldiff) * 0.04)
if block < 0 then
block = 0
end
return block
end
function BCS:GetEffectiveParryChance(leveldiff)
local parry = GetParryChance() - ((5 * leveldiff) * 0.04)
if parry < 0 then
parry = 0
end
return parry
end
function BCS:GetEffectiveDodgeChance(leveldiff)
local dodge = GetDodgeChance() - ((5 * leveldiff) * 0.04)
if dodge < 0 then
dodge = 0
end
return dodge
end
function BCS:SetDamage(statFrame)
local damageText = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local speed, offhandSpeed = UnitAttackSpeed("player")
BCS_AddDamageTooltip(damageText, statFrame, speed, offhandSpeed)
label:SetText(TEXT(DAMAGE_COLON))
end
function BCS:SetAttackSpeed(statFrame)
local damageText = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local speed, offhandSpeed = UnitAttackSpeed("player")
speed = format("%.2f", speed)
if (offhandSpeed) then
offhandSpeed = format("%.2f", offhandSpeed)
end
local text
if (offhandSpeed) then
text = speed .. " | " .. offhandSpeed
else
text = speed
end
BCS_AddDamageTooltip(damageText, statFrame, speed, offhandSpeed)
label:SetText(TEXT(SPEED) .. ":")
damageText:SetText(text)
end
function BCS:SetAttackPower(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local tooltipText = HIGHLIGHT_FONT_COLOR_CODE .. MELEE_ATTACK_POWER .. " "
local base, posBuff, negBuff = UnitAttackPower("player")
local effectiveStat = base + posBuff + negBuff
if ((posBuff == 0) and (negBuff == 0)) then
text:SetText(effectiveStat)
statFrame.tooltip = tooltipText .. base .. FONT_COLOR_CODE_CLOSE
else
tooltipText = tooltipText .. effectiveStat
if (posBuff > 0 or negBuff < 0) then
tooltipText = tooltipText .. " (" .. (base - posBuff - negBuff) .. FONT_COLOR_CODE_CLOSE
end
if (posBuff > 0) then
tooltipText = tooltipText .. FONT_COLOR_CODE_CLOSE .. GREEN_FONT_COLOR_CODE .. "+" .. posBuff .. FONT_COLOR_CODE_CLOSE
end
if (negBuff < 0) then
tooltipText = tooltipText .. RED_FONT_COLOR_CODE .. " " .. negBuff .. FONT_COLOR_CODE_CLOSE
end
if (posBuff > 0 or negBuff < 0) then
tooltipText = tooltipText .. HIGHLIGHT_FONT_COLOR_CODE .. ")" .. FONT_COLOR_CODE_CLOSE
end
statFrame.tooltip = tooltipText
if (negBuff < 0) then
text:SetText(RED_FONT_COLOR_CODE .. effectiveStat .. FONT_COLOR_CODE_CLOSE)
else
text:SetText(GREEN_FONT_COLOR_CODE .. effectiveStat .. FONT_COLOR_CODE_CLOSE)
end
end
label:SetText(TEXT(ATTACK_POWER_COLON))
PaperDollFormatStat(MELEE_ATTACK_POWER, base, posBuff, negBuff, statFrame, text)
statFrame.tooltipSubtext = format(MELEE_ATTACK_POWER_TOOLTIP, max((base + posBuff + negBuff), 0) / ATTACK_POWER_MAGIC_NUMBER)
BCS_AddTooltip(statFrame)
end
function BCS:SetSpellPower(statFrame, school)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local green = "|cff20ff20"
if school then
local base, _, _, dmgOnly = BCS:GetSpellPower()
local fromSchool = BCS:GetSpellPower(school)
base = base + dmgOnly
local output = base + fromSchool
if fromSchool > 0 then
output = green .. output .. "|r"
end
label:SetText(L["SPELL_SCHOOL_" .. strupper(school)])
text:SetText(output)
if fromSchool > 0 then
statFrame.tooltip = format(L.SPELL_SCHOOL_SECONDARY_TOOLTIP, school, base + fromSchool, base, fromSchool)
else
statFrame.tooltip = format(L.SPELL_SCHOOL_TOOLTIP, school, base)
end
statFrame.tooltipSubtext = format(L.SPELL_SCHOOL_TOOLTIP_SUB, strlower(school))
else
local damageAndHealing, secondaryPower, secondaryName, damageOnly = BCS:GetSpellPower()
local total = damageAndHealing + damageOnly
label:SetText(L.SPELL_POWER_COLON)
if secondaryPower > 0 then
text:SetText(green .. total + secondaryPower)
else
text:SetText(total + secondaryPower)
end
if secondaryPower ~= 0 then
statFrame.tooltip = format(L.SPELL_POWER_SECONDARY_TOOLTIP, (total + secondaryPower), total, secondaryPower, secondaryName)
statFrame.tooltipSubtext = format(L.SPELL_POWER_SECONDARY_TOOLTIP_SUB)
else
statFrame.tooltip = format(L.SPELL_POWER_TOOLTIP, total)
statFrame.tooltipSubtext = format(L.SPELL_POWER_TOOLTIP_SUB)
end
end
BCS_AddTooltip(statFrame)
end
function BCS:SetHitRating(statFrame, ratingType)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local _, class = UnitClass("player")
label:SetText(L.MELEE_HIT_RATING_COLON)
if ratingType == "MELEE" then
local rating = BCS:GetHitRating()
rating = rating .. "%"
text:SetText(rating)
statFrame.tooltip = (L.MELEE_HIT_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_HIT_TOOLTIP_SUB)
elseif ratingType == "RANGED" then
-- If no ranged attack then set to n/a
if UnitHasRelicSlot("player") or not (GetInventoryItemLink("player", 18)) then
text:SetText(NOT_APPLICABLE)
return
end
local rating = BCS:GetRangedHitRating()
rating = rating .. "%"
text:SetText(rating)
statFrame.tooltip = (L.RANGED_HIT_TOOLTIP)
statFrame.tooltipSubtext = format(L.RANGED_HIT_TOOLTIP_SUB)
elseif ratingType == "SPELL" then
local spell_hit, spell_hit_fire, spell_hit_frost, spell_hit_arcane, spell_hit_shadow, spell_hit_holy = BCS:GetSpellHitRating()
text:SetText(spell_hit .. "%")
statFrame.tooltip = format(L.SPELL_HIT_TOOLTIP)
statFrame.tooltipSubtext = format(L.SPELL_HIT_TOOLTIP_SUB)
if statFrame.tooltip then
statFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText(this.tooltip)
GameTooltip:AddLine(this.tooltipSubtext, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
if spell_hit_fire > 0 then
GameTooltip:AddLine(format(L.SPELL_SCHOOL_FIRE .. " spells: %.f%%", spell_hit + spell_hit_fire))
end
if spell_hit_frost > 0 then
GameTooltip:AddLine(format(L.SPELL_SCHOOL_FROST .. " spells: %.f%%", spell_hit + spell_hit_frost))
end
if spell_hit_arcane > 0 then
GameTooltip:AddLine(format(L.SPELL_SCHOOL_ARCANE .. " spells: %.f%%", spell_hit + spell_hit_arcane))
end
if spell_hit_shadow > 0 then
if class == "WARLOCK" then
GameTooltip:AddLine(format("Affliction spells: %.f%%", spell_hit + spell_hit_shadow))
else
GameTooltip:AddLine(format(L.SPELL_SCHOOL_SHADOW .. " spells: %.f%%", spell_hit + spell_hit_shadow))
end
end
if spell_hit_holy > 0 then
GameTooltip:AddLine(format(L.SPELL_SCHOOL_HOLY .. " and Discipline spells: %.f%%", spell_hit + spell_hit_holy))
end
GameTooltip:Show()
end)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
end
if ratingType ~= "SPELL" then
BCS_AddTooltip(statFrame)
end
end
function BCS:SetMeleeCritChance(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.MELEE_CRIT_COLON)
text:SetText(format("%.2f%%", BCS:GetCritChance()))
statFrame.tooltip = (L.MELEE_CRIT_TOOLTIP)
statFrame.tooltipSubtext = (L.MELEE_CRIT_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetWeaponSkill(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.WEAPON_SKILL_COLON)
if OffhandHasWeapon() == 1 then
text:SetText(format("%d | %d", BCS:GetMHWeaponSkill(), BCS:GetOHWeaponSkill()))
else
text:SetText(format("%d", BCS:GetMHWeaponSkill()))
end
statFrame.tooltip = format(L.MELEE_WEAPON_SKILL_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_WEAPON_SKILL_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetRangedWeaponSkill(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.WEAPON_SKILL_COLON)
-- If no ranged attack then set to n/a
if UnitHasRelicSlot("player") or not (GetInventoryItemLink("player", 18)) then
text:SetText(NOT_APPLICABLE)
return
end
text:SetText(format("%d", BCS:GetRangedWeaponSkill()))
statFrame.tooltip = format(L.RANGED_WEAPON_SKILL_TOOLTIP)
statFrame.tooltipSubtext = format(L.RANGED_WEAPON_SKILL_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetBossMissChance(statFrame)
local frame = statFrame
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.MISS_CHANCE_COLON)
local mh_miss = BCS:GetMissChance(BCS:GetMHWeaponSkill())
if OffhandHasWeapon() == 1 then
text:SetText(format("%.1f%% | %.1f%%",
BCS:GetDualWieldMissChance(BCS:GetMHWeaponSkill()),
BCS:GetDualWieldMissChance(BCS:GetOHWeaponSkill())))
else
text:SetText(format("%.1f%%", mh_miss))
end
statFrame.tooltip = format(L.MELEE_MISS_VS_BOSS_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_MISS_VS_BOSS_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetBossGlanceReduction(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.GLANCE_REDUCTION_COLON)
if OffhandHasWeapon() == 1 then
text:SetText(format("%d%% | %d%%",
BCS:GetGlanceReduction(BCS:GetMHWeaponSkill()),
BCS:GetGlanceReduction(BCS:GetOHWeaponSkill())))
else
text:SetText(format("%d%%", BCS:GetGlanceReduction(BCS:GetMHWeaponSkill())))
end
statFrame.tooltip = format(L.MELEE_GLANCE_VS_BOSS_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_GLANCE_VS_BOSS_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetBossDodgeChance(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.DODGE_CHANCE_COLON)
if OffhandHasWeapon() == 1 then
text:SetText(format("%.1f%% | %.1f%%",
BCS:GetDodgeChance(BCS:GetMHWeaponSkill()),
BCS:GetDodgeChance(BCS:GetOHWeaponSkill())))
else
text:SetText(format("%.1f%%", BCS:GetDodgeChance(BCS:GetMHWeaponSkill())))
end
statFrame.tooltip = format(L.MELEE_DODGE_VS_BOSS_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_DODGE_VS_BOSS_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetBossCritCap(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.CRIT_CAP_COLON)
if OffhandHasWeapon() == 1 then
text:SetText(format("%.1f%% | %.1f%%",
BCS:GetDualWieldCritCap(BCS:GetMHWeaponSkill()),
BCS:GetDualWieldCritCap(BCS:GetOHWeaponSkill())))
else
text:SetText(format("%.1f%%", BCS:GetCritCap(BCS:GetMHWeaponSkill())))
end
BCS_AddTooltip(statFrame)
end
function BCS:SetEffectiveBossCrit(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
label:SetText(L.BOSS_CRIT_COLON)
local critChance = BCS:GetCritChance() - 3 -- 3 % crit reduction vs lvl 63
if OffhandHasWeapon() == 1 then
text:SetText(format("%.1f%% | %.1f%%",
math.min(critChance, BCS:GetDualWieldCritCap(BCS:GetMHWeaponSkill())),
math.min(critChance, BCS:GetDualWieldCritCap(BCS:GetOHWeaponSkill()))
))
else
text:SetText(format("%.1f%%", math.min(critChance, BCS:GetCritCap(BCS:GetMHWeaponSkill()))))
end
statFrame.tooltip = format(L.MELEE_EFF_CRIT_VS_BOSS_TOOLTIP)
statFrame.tooltipSubtext = format(L.MELEE_EFF_CRIT_VS_BOSS_TOOLTIP_SUB)
BCS_AddTooltip(statFrame)
end
function BCS:SetSpellCritChance(statFrame)
local text = getglobal(statFrame:GetName() .. "StatText")
local label = getglobal(statFrame:GetName() .. "Label")
local _, class = UnitClass("player")
label:SetText(L.SPELL_CRIT_COLON)
local generic = BCS:GetSpellCritChance()
local spell1, spell2, spell3, spell4, spell5, spell6 = BCS:GetSpellCritFromClass(class)
local total1 = generic + spell1
local total2 = generic + spell2
local total3 = generic + spell3
local total4 = generic + spell4
local total5 = generic + spell5
local total6 = generic + spell6
if total1 > 100 then
total1 = 100
end
if total2 > 100 then
total2 = 100
end
if total3 > 100 then
total3 = 100
end
if total4 > 100 then
total4 = 100
end
if total5 > 100 then
total5 = 100
end
if total6 > 100 then
total6 = 100
end
text:SetText(format("%.2f%%", generic))
-- warlock spells that can crit are all destruction so just add this to generic
if class == "WARLOCK" and spell1 > 0 then
text:SetText(format("%.2f%%", generic + spell1))
-- if priest have both talents add lowest to generic cos there will be no more spells left that can crit
elseif class == "PRIEST" and spell3 > 0 and spell2 > 0 then
if spell2 < spell3 then
text:SetText(format("%.2f%%", generic + spell2))
elseif spell2 >= spell3 then
text:SetText(format("%.2f%%", generic + spell3))
end
end
statFrame.tooltip = format(L.SPELL_CRIT_TOOLTIP)
statFrame.tooltipSubtext = format(L.SPELL_CRIT_TOOLTIP_SUB)
statFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText(this.tooltip)
GameTooltip:AddLine(this.tooltipSubtext, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
if class == "DRUID" then
if spell1 > 0 then
GameTooltip:AddLine(format("Moonfire: %.2f%%", total1))
end
if spell2 > 0 then
GameTooltip:AddLine(format("Regrowth: %.2f%%", total2))
end
elseif class == "PALADIN" then
if spell1 > 0 then
GameTooltip:AddLine(format("Holy Light: %.2f%%", total1))
end
if spell2 > 0 then
GameTooltip:AddLine(format("Flash of Light: %.2f%%", total2))
end
if spell3 > 0 then
GameTooltip:AddLine(format("Holy Shock: %.2f%%", total3))
end
elseif class == "WARLOCK" then
if spell2 > 0 and spell2 ~= spell1 then
GameTooltip:AddLine(format("Searing Pain: %.2f%%", total2))
end
elseif class == "PRIEST" then
-- all healing spells are holy, change tooltip if player have both talents
if spell1 > 0 then
if spell3 > 0 then
GameTooltip:AddLine(format("Healing spells: %.2f%%", total1))
end
GameTooltip:AddLine(format("Holy spells: %.2f%%", total1 + spell3))
end