-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCharacterStatsTbcCore.lua
1480 lines (1196 loc) · 51.9 KB
/
CharacterStatsTbcCore.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
--[[
Util functions that wrap my interface and the Blizzard's WoW Classic lua API code for ease of use
]]
local CSC_ScanTooltip = CreateFrame("GameTooltip", "CSC_ScanTooltip", nil, "GameTooltipTemplate");
CSC_ScanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
local CSC_ScanTooltipPrefix = "CSC_ScanTooltip";
local g_lastSeenBaseManaRegen = 0;
local g_lastSeenCastingManaRegen = 0;
g_APFromADItems = 0;
local function CSC_GetMP5FromGear(unit)
local mp5 = 0;
for i=1,18 do
local itemLink = GetInventoryItemLink(unit, i);
if itemLink then
local stats = GetItemStats(itemLink);
if stats then
-- For some reason this returns (mp5 - 1) so I have to add 1 to the result
local statMP5 = stats["ITEM_MOD_POWER_REGEN0_SHORT"];
if (statMP5) then
mp5 = mp5 + statMP5 + 1;
end
end
end
end
local unitClassId = select(3, UnitClass(unit));
if (unitClassId == CSC_PRIEST_CLASS_ID) then
local zgEnchantMp5 = CSC_GetMp5FromPriestZGEnchants(unit);
if (zgEnchantMp5 > 0) then
mp5 = mp5 + zgEnchantMp5;
end
end
if (CSC_HasEnchant(unit, INVSLOT_WRIST, 2565)) then -- Mana Regen
mp5 = mp5 + 4;
end
if (CSC_HasEnchant(unit, INVSLOT_SHOULDER, 2715)) then -- Resilience of the Scourge
mp5 = mp5 + 5;
end
local tempMHEnchantId = select(4, GetWeaponEnchantInfo());
if (tempMHEnchantId == 2629) then -- Brilliant Mana Oil
mp5 = mp5 + 12;
end
return mp5;
end
local function CSC_GetSkillRankAndModifier(skillHeader, skillName)
local numSkills = GetNumSkillLines();
local skillIndex = 0;
local currentHeader = nil;
for i = 1, numSkills do
local currentSkillName = select(1, GetSkillLineInfo(i));
local isHeader = select(2, GetSkillLineInfo(i));
if isHeader ~= nil and isHeader then
currentHeader = currentSkillName;
else
if (currentHeader == skillHeader and currentSkillName == skillName) then
skillIndex = i;
break;
end
end
end
local skillRank = nil;
local skillModifier = nil;
if (skillIndex > 0) then
skillRank = select(4, GetSkillLineInfo(skillIndex));
skillModifier = select(6, GetSkillLineInfo(skillIndex));
end
return skillRank, skillModifier;
end
function CSC_GetPlayerWeaponSkill(unit, weaponSlotId)
local totalWeaponSkill = nil;
local unitClassId = select(3, UnitClass(unit));
-- Druid checks
local shapeIndex = -1;
if (unitClassId == CSC_DRUID_CLASS_ID) then
shapeIndex = CSC_GetShapeshiftForm();
end
if (unitClassId == CSC_DRUID_CLASS_ID) and (shapeIndex > 0) then
totalWeaponSkill = UnitLevel(unit) * 5;
else
local itemId = GetInventoryItemID(unit, weaponSlotId);
if (itemId) then
local itemSubtypeId = select(7, GetItemInfoInstant(itemId));
if itemSubtypeId then
local weaponString = g_WeaponStringByWeaponId[itemSubtypeId];
if weaponString then
local skillRank, skillModifier = CSC_GetSkillRankAndModifier(CSC_WEAPON_SKILLS_HEADER, weaponString);
if skillRank and skillModifier then
-- Weapon skill from racials should be already in skillRank
totalWeaponSkill = skillRank + skillModifier;
end
end
end
end
end
return totalWeaponSkill;
end
function CSC_GetPlayerMissChances(unit, playerHitChance)
local missChanceVsNPC = 5;
local missChanceVsBoss = 8;
local missChanceVsPlayer = 5;
local hitChance = playerHitChance;
local level = UnitLevel(unit);
local bossLevel = 73;
local playerWeaponSkill = level * 5;
local bossDefense = bossLevel * 5;
-- Boss (level 73)
if (bossDefense - playerWeaponSkill >= 11) then
missChanceVsBoss = 5 + (bossDefense - playerWeaponSkill) * 0.2;
end
if (bossDefense - playerWeaponSkill <= 10) then
missChanceVsBoss = 5 + (bossDefense - playerWeaponSkill) * 0.1;
end
missChanceVsBoss = missChanceVsBoss + 1; -- hit suppression
local dwMissChanceVsNpc = math.max(missChanceVsNPC + 19 - hitChance);
local dwMissChanceVsBoss = math.max(missChanceVsBoss + 19 - hitChance);
local dwMissChanceVsPlayer = math.max(missChanceVsPlayer + 19 - hitChance);
missChanceVsNPC = math.max(0, missChanceVsNPC - hitChance);
missChanceVsBoss = math.max(0, missChanceVsBoss - hitChance);
missChanceVsPlayer = math.max(0, missChanceVsPlayer - hitChance);
return missChanceVsNPC, missChanceVsBoss, missChanceVsPlayer, dwMissChanceVsNpc, dwMissChanceVsBoss, dwMissChanceVsPlayer;
end
function CSC_GetPlayerCritCap(unit, ratingIndex)
local hitChance = GetHitModifier();
if not hitChance then
hitChance = 0;
end
local hitRatingBonus = GetCombatRatingBonus(ratingIndex); -- hit rating in % (hit chance) (from gear sources, doesn't seem to include talents);
local totalHit = hitChance + hitRatingBonus;
local missChanceVsNPC, missChanceVsBoss, missChanceVsPlayer, dwMissChanceVsNpc, dwMissChanceVsBoss, dwMissChanceVsPlayer = CSC_GetPlayerMissChances(unit, totalHit);
local playerWeaponSkill = UnitLevel(unit) * 5;
local bossDefense = 73 * 5;
local critSuppression = 4.8;
local dodgeChance = 5 + (bossDefense - playerWeaponSkill) * 0,1;
local glancingChance = math.max(0, 6 + (bossDefense - playerWeaponSkill) * 1.2);
local critCap = 100 - missChanceVsBoss - dodgeChance - glancingChance + critSuppression;
local dwCritCap = 100 - dwMissChanceVsBoss - dodgeChance - glancingChance + critSuppression;
return critCap, dwCritCap;
end
function CSC_GetAttackPowerFromArgentDawnItems(unit)
local chestId = GetInventoryItemID(unit, INVSLOT_CHEST);
local glovesId = GetInventoryItemID(unit, INVSLOT_HAND);
local bracerId = GetInventoryItemID(unit, INVSLOT_WRIST);
local trinketFirst = GetInventoryItemID(unit, INVSLOT_TRINKET1);
local trinketSecond = GetInventoryItemID(unit, INVSLOT_TRINKET2);
local apVsUndead = 0;
if (g_ArgentDawnAPItems[chestId] ~= nil) then
apVsUndead = apVsUndead + g_ArgentDawnAPItems[chestId];
end
if (g_ArgentDawnAPItems[glovesId] ~= nil) then
apVsUndead = apVsUndead + g_ArgentDawnAPItems[glovesId];
end
if (g_ArgentDawnAPItems[bracerId] ~= nil) then
apVsUndead = apVsUndead + g_ArgentDawnAPItems[bracerId];
end
if (g_ArgentDawnAPItems[trinketFirst] ~= nil) then
apVsUndead = apVsUndead + g_ArgentDawnAPItems[trinketFirst];
end
if (g_ArgentDawnAPItems[trinketSecond] ~= nil) then
apVsUndead = apVsUndead + g_ArgentDawnAPItems[trinketSecond];
end
local tempMHEnchantId = select(4, GetWeaponEnchantInfo());
if (tempMHEnchantId == 2684) then -- Consecrated Sharpening Stone
apVsUndead = apVsUndead + 100;
end
local tempOHEnchantId = select(8, GetWeaponEnchantInfo());
if (tempOHEnchantId == 2684) then -- Consecrated Sharpening Stone
apVsUndead = apVsUndead + 100;
end
return apVsUndead;
end
function CSC_GetSpellkPowerFromArgentDawnItems(unit)
local chestId = GetInventoryItemID(unit, INVSLOT_CHEST);
local glovesId = GetInventoryItemID(unit, INVSLOT_HAND);
local bracerId = GetInventoryItemID(unit, INVSLOT_WRIST);
local trinketFirst = GetInventoryItemID(unit, INVSLOT_TRINKET1);
local trinketSecond = GetInventoryItemID(unit, INVSLOT_TRINKET2);
local spVsUndead = 0;
if (g_ArgentDawnSPItems[chestId] ~= nil) then
spVsUndead = spVsUndead + g_ArgentDawnSPItems[chestId];
end
if (g_ArgentDawnSPItems[glovesId] ~= nil) then
spVsUndead = spVsUndead + g_ArgentDawnSPItems[glovesId];
end
if (g_ArgentDawnSPItems[bracerId] ~= nil) then
spVsUndead = spVsUndead + g_ArgentDawnSPItems[bracerId];
end
if (g_ArgentDawnSPItems[trinketFirst] ~= nil) then
spVsUndead = spVsUndead + g_ArgentDawnSPItems[trinketFirst];
end
if (g_ArgentDawnSPItems[trinketSecond] ~= nil) then
spVsUndead = spVsUndead + g_ArgentDawnSPItems[trinketSecond];
end
local tempMHEnchantId = select(4, GetWeaponEnchantInfo());
if (tempMHEnchantId == 2685) then -- Blessed Wizard Oil
spVsUndead = spVsUndead + 60;
end
local tempOHEnchantId = select(8, GetWeaponEnchantInfo());
if (tempOHEnchantId == 2685) then -- Blessed Wizard Oil
spVsUndead = spVsUndead + 60;
end
return spVsUndead;
end
function CSC_CacheAPFromADItems(unit)
g_APFromADItems = CSC_GetAttackPowerFromArgentDawnItems(unit);
end
function CSC_GetDefense(unit)
local numSkills = GetNumSkillLines();
local skillIndex = 0;
local currentHeader = nil;
local playerLevel = UnitLevel(unit);
for i = 1, numSkills do
local skillName = select(1, GetSkillLineInfo(i));
local isHeader = select(2, GetSkillLineInfo(i));
if isHeader ~= nil and isHeader then
currentHeader = skillName;
else
if (currentHeader == CSC_WEAPON_SKILLS_HEADER and skillName == CSC_DEFENSE) then
skillIndex = i;
break;
end
end
end
local skillRank, skillModifier;
if (skillIndex > 0) then
skillRank = select(4, GetSkillLineInfo(skillIndex));
skillModifier = select(6, GetSkillLineInfo(skillIndex));
else
-- Use this as a backup, just in case something goes wrong
skillRank, skillModifier = UnitDefense(unit); --Not working properly
end
return skillRank, skillModifier, playerLevel;
end
-- GENERAL UTIL FUNCTIONS END --
-- PRIMARY STATS --
function CSC_PaperDollFrame_SetPrimaryStats(statFrames, unit)
local statIndexTable = {
"STRENGTH",
"AGILITY",
"STAMINA",
"INTELLECT",
"SPIRIT",
}
-- Fix for classic (NUM_STATS instead of NUM_STATS-1)
for i=1, NUM_STATS, 1 do
local statIndex = i;
local frameText;
local stat;
local effectiveStat;
local posBuff;
local negBuff;
stat, effectiveStat, posBuff, negBuff = UnitStat(unit, statIndex);
local statName = getglobal("SPELL_STAT"..statIndex.."_NAME");
-- Set the tooltip text
local tooltipText = HIGHLIGHT_FONT_COLOR_CODE..statName.." ";
if ( ( posBuff == 0 ) and ( negBuff == 0 ) ) then
frameText = effectiveStat;
statFrames[statIndex].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
statFrames[statIndex].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
frameText = RED_FONT_COLOR_CODE..effectiveStat..FONT_COLOR_CODE_CLOSE;
else
frameText = GREEN_FONT_COLOR_CODE..effectiveStat..FONT_COLOR_CODE_CLOSE;
end
end
statFrames[statIndex].tooltip2 = getglobal("DEFAULT_STAT"..statIndex.."_TOOLTIP");
if ( statIndex == 1 ) then
local attackPower = GetAttackPowerForStat(statIndex,effectiveStat);
statFrames[statIndex].tooltip2 = format(statFrames[statIndex].tooltip2, attackPower);
local unitClassId = select(3, UnitClass(unit));
if ( unitClassId == CSC_WARRIOR_CLASS_ID or unitClassId == CSC_SHAMAN_CLASS_ID or unitClassId == CSC_PALADIN_CLASS_ID ) then
statFrames[statIndex].tooltip2 = statFrames[statIndex].tooltip2 .. "\n" .. format( STAT_BLOCK_TOOLTIP, effectiveStat*BLOCK_PER_STRENGTH );
end
elseif ( statIndex == 3 ) then
local baseStam = min(20, effectiveStat);
local moreStam = effectiveStat - baseStam;
statFrames[statIndex].tooltip2 = format(statFrames[statIndex].tooltip2, (baseStam + (moreStam*HEALTH_PER_STAMINA))*GetUnitMaxHealthModifier(unit));
local petStam = ComputePetBonus("PET_BONUS_STAM", effectiveStat );
if( petStam > 0 ) then
statFrames[statIndex].tooltip2 = statFrames[statIndex].tooltip2 .. "\n" .. format(PET_BONUS_TOOLTIP_STAMINA,petStam);
end
elseif ( statIndex == 2 ) then
local attackPower = GetAttackPowerForStat(statIndex,effectiveStat);
if ( attackPower > 0 ) then
statFrames[statIndex].tooltip2 = format(STAT_ATTACK_POWER, attackPower) .. format(statFrames[statIndex].tooltip2, GetCritChanceFromAgility(unit), effectiveStat*ARMOR_PER_AGILITY);
else
statFrames[statIndex].tooltip2 = format(statFrames[statIndex].tooltip2, GetCritChanceFromAgility(unit), effectiveStat*ARMOR_PER_AGILITY);
end
elseif ( statIndex == 4 ) then
local baseInt = min(20, effectiveStat);
local moreInt = effectiveStat - baseInt
if ( UnitHasMana(unit) ) then
statFrames[statIndex].tooltip2 = format(statFrames[statIndex].tooltip2, baseInt + moreInt*MANA_PER_INTELLECT, GetSpellCritChanceFromIntellect(unit));
else
statFrames[statIndex].tooltip2 = nil;
end
local petInt = ComputePetBonus("PET_BONUS_INT", effectiveStat );
if( petInt > 0 ) then
if ( not statFrames[statIndex].tooltip2 ) then
statFrames[statIndex].tooltip2 = "";
end
statFrames[statIndex].tooltip2 = statFrames[statIndex].tooltip2 .. "\n" .. format(PET_BONUS_TOOLTIP_INTELLECT,petInt);
end
elseif ( statIndex == 5 ) then
-- All mana regen stats are displayed as mana/5 sec.
statFrames[statIndex].tooltip2 = format(statFrames[statIndex].tooltip2, GetUnitHealthRegenRateFromSpirit(unit));
if ( UnitHasMana(unit) ) then
local regen = GetUnitManaRegenRateFromSpirit(unit);
regen = floor( regen * 5.0 );
statFrames[statIndex].tooltip2 = statFrames[statIndex].tooltip2.."\n"..format(MANA_REGEN_FROM_SPIRIT, regen);
end
end
CSC_PaperDollFrame_SetLabelAndText(statFrames[i], statName, frameText, false);
end
end
-- DAMAGE --
function CSC_PaperDollFrame_SetDamage(statFrame, unit, category)
if (category == PLAYERSTAT_RANGED_COMBAT) and not IsRangedWeapon() then
CSC_PaperDollFrame_SetLabelAndText(statFrame, DAMAGE, NOT_APPLICABLE, false);
return;
end
statFrame:SetScript("OnEnter", CSC_CharacterDamageFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local speed, offhandSpeed = CSC_GetAppropriateAttackSpeed(unit, category);
local minDamage, maxDamage, minOffHandDamage, maxOffHandDamage, physicalBonusPos, physicalBonusNeg, percentMod = CSC_GetAppropriateDamage(unit, category);
-- sometimes this is wrongly reported as 0
if percentMod == nil or percentMod == 0 then
percentMod = 1;
end
if speed == nil or speed == 0 then
speed = 1;
end
if (UISettingsCharacter.showStatsFromArgentDawnItems) then
local bonusDPS = g_APFromADItems / ATTACK_POWER_MAGIC_NUMBER;
local bonusDmgMainHand = speed * bonusDPS;
minDamage = minDamage + bonusDmgMainHand;
maxDamage = maxDamage + bonusDmgMainHand;
end
local displayMin = max(floor(minDamage),1);
local displayMax = max(ceil(maxDamage),1);
minDamage = (minDamage / percentMod) - physicalBonusPos - physicalBonusNeg;
maxDamage = (maxDamage / percentMod) - physicalBonusPos - physicalBonusNeg;
local baseDamage = (minDamage + maxDamage) * 0.5;
local fullDamage = (baseDamage + physicalBonusPos + physicalBonusNeg) * percentMod;
local totalBonus = (fullDamage - baseDamage);
local damagePerSecond = (max(fullDamage,1) / speed);
local damageTooltip = max(floor(minDamage),1).." - "..max(ceil(maxDamage),1);
local colorPos = "|cff20ff20";
local colorNeg = "|cffff2020";
-- epsilon check
if ( totalBonus < 0.1 and totalBonus > -0.1 ) then
totalBonus = 0.0;
end
local damageText;
if ( totalBonus == 0 ) then
if ( ( displayMin < 100 ) and ( displayMax < 100 ) ) then
damageText = displayMin.." - "..displayMax;
else
damageText = displayMin.."-"..displayMax;
end
else
-- set bonus color and display
local color;
if ( totalBonus > 0 ) then
color = colorPos;
else
color = colorNeg;
end
if ( ( displayMin < 100 ) and ( displayMax < 100 ) ) then
damageText = color..displayMin.." - "..displayMax.."|r";
else
damageText = color..displayMin.."-"..displayMax.."|r";
end
if ( physicalBonusPos > 0 ) then
damageTooltip = damageTooltip..colorPos.." +"..physicalBonusPos.."|r";
end
if ( physicalBonusNeg < 0 ) then
damageTooltip = damageTooltip..colorNeg.." "..physicalBonusNeg.."|r";
end
if ( percentMod > 1 ) then
damageTooltip = damageTooltip..colorPos.." x"..floor(percentMod*100+0.5).."%|r";
elseif ( percentMod < 1 ) then
damageTooltip = damageTooltip..colorNeg.." x"..floor(percentMod*100+0.5).."%|r";
end
end
CSC_PaperDollFrame_SetLabelAndText(statFrame, DAMAGE, damageText, false);
statFrame.damage = damageTooltip;
statFrame.attackSpeed = speed;
statFrame.dps = damagePerSecond;
statFrame.attackRating = CSC_GetAppropriateAttackRaiting(unit, category);
statFrame.TooltipMainTxt = INVTYPE_WEAPONMAINHAND;
if (category == PLAYERSTAT_RANGED_COMBAT) and IsRangedWeapon() then
statFrame.TooltipMainTxt = INVTYPE_RANGED;
end
-- If there's an offhand speed then add the offhand info to the tooltip
if ( offhandSpeed and category == PLAYERSTAT_MELEE_COMBAT) then
if offhandSpeed == 0 then
offhandSpeed = 1;
end
if (UISettingsCharacter.showStatsFromArgentDawnItems) then
local bonusDPS = g_APFromADItems / ATTACK_POWER_MAGIC_NUMBER;
local bonusDmgOffHand = offhandSpeed * bonusDPS;
minOffHandDamage = minOffHandDamage + bonusDmgOffHand;
maxOffHandDamage = maxOffHandDamage + bonusDmgOffHand;
end
minOffHandDamage = (minOffHandDamage / percentMod) - physicalBonusPos - physicalBonusNeg;
maxOffHandDamage = (maxOffHandDamage / percentMod) - physicalBonusPos - physicalBonusNeg;
local offhandBaseDamage = (minOffHandDamage + maxOffHandDamage) * 0.5;
local offhandFullDamage = (offhandBaseDamage + physicalBonusPos + physicalBonusNeg) * percentMod;
local offhandDamagePerSecond = (max(offhandFullDamage,1) / offhandSpeed);
local offhandDamageTooltip = max(floor(minOffHandDamage),1).." - "..max(ceil(maxOffHandDamage),1);
if ( physicalBonusPos > 0 ) then
offhandDamageTooltip = offhandDamageTooltip..colorPos.." +"..physicalBonusPos.."|r";
end
if ( physicalBonusNeg < 0 ) then
offhandDamageTooltip = offhandDamageTooltip..colorNeg.." "..physicalBonusNeg.."|r";
end
if ( percentMod > 1 ) then
offhandDamageTooltip = offhandDamageTooltip..colorPos.." x"..floor(percentMod*100+0.5).."%|r";
elseif ( percentMod < 1 ) then
offhandDamageTooltip = offhandDamageTooltip..colorNeg.." x"..floor(percentMod*100+0.5).."%|r";
end
statFrame.offhandDamage = offhandDamageTooltip;
statFrame.offhandAttackSpeed = offhandSpeed;
statFrame.offhandDps = offhandDamagePerSecond;
else
statFrame.offhandAttackSpeed = nil;
end
end
-- Note: while this function was historically named "BothHands",
-- it looks like it only ever displayed attack rating for the main hand.
function CSC_PaperDollFrame_SetAttackBothHands(statFrame, unit)
local mainHandAttackBase, mainHandAttackMod = UnitAttackBothHands(unit);
local attackWithModifier = mainHandAttackBase + mainHandAttackMod;
local attackText;
if( mainHandAttackMod == 0 ) then
attackText = mainHandAttackBase;
else
local color = RED_FONT_COLOR_CODE;
if( mainHandAttackMod > 0 ) then
color = GREEN_FONT_COLOR_CODE;
end
attackText = color..attackWithModifier..FONT_COLOR_CODE_CLOSE;
end
CSC_PaperDollFrame_SetLabelAndText(statFrame, DAMAGE, attackText, false);
statFrame.tooltip = ATTACK_TOOLTIP;
statFrame.tooltip2 = ATTACK_TOOLTIP_SUBTEXT;
end
function CSC_PaperDollFrame_SetMeleeAttackPower(statFrame, unit)
local base, posBuff, negBuff = UnitAttackPower(unit);
if (UISettingsCharacter.showStatsFromArgentDawnItems) then
posBuff = posBuff + g_APFromADItems;
end
local valueText, tooltipText = CSC_PaperDollFormatStat(MELEE_ATTACK_POWER, base, posBuff, negBuff);
local valueNum = max(0, base + posBuff + negBuff);
CSC_PaperDollFrame_SetLabelAndText(statFrame, ATTACK_POWER, valueText, false);
statFrame.tooltip = tooltipText;
statFrame.tooltip2 = format(MELEE_ATTACK_POWER_TOOLTIP, max((base+posBuff+negBuff), 0)/ATTACK_POWER_MAGIC_NUMBER);
end
function CSC_PaperDollFrame_SetRangedAttackPower(statFrame, unit)
if not IsRangedWeapon() then
CSC_PaperDollFrame_SetLabelAndText(statFrame, ATTACK_POWER, NOT_APPLICABLE, false);
return;
end
if ( HasWandEquipped() ) then
CSC_PaperDollFrame_SetLabelAndText(statFrame, ATTACK_POWER, NOT_APPLICABLE, false);
statFrame.tooltip = nil;
return;
end
local base, posBuff, negBuff = UnitRangedAttackPower(unit);
if (UISettingsCharacter.showStatsFromArgentDawnItems) then
posBuff = posBuff + g_APFromADItems;
end
local valueText, tooltipText = CSC_PaperDollFormatStat(RANGED_ATTACK_POWER, base, posBuff, negBuff);
local valueNum = max(0, base + posBuff + negBuff);
CSC_PaperDollFrame_SetLabelAndText(statFrame, ATTACK_POWER, valueText, false);
statFrame.tooltip = tooltipText;
statFrame.tooltip2 = format(RANGED_ATTACK_POWER_TOOLTIP, valueNum/ATTACK_POWER_MAGIC_NUMBER);
end
-- SECONDARY STATS --
function CSC_PaperDollFrame_SetCritChance(statFrame, unit)
statFrame:SetScript("OnEnter", CSC_CharacterMeleeCritFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local critChance = GetCritChance();
CSC_PaperDollFrame_SetLabelAndText(statFrame, MELEE_CRIT_CHANCE, critChance, true);
statFrame.critChance = critChance;
statFrame.unit = unit;
end
function CSC_PaperDollFrame_SetRangedCritChance(statFrame, unit)
if not IsRangedWeapon() then
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_CRITICAL_STRIKE, NOT_APPLICABLE, false);
return;
end
statFrame:SetScript("OnEnter", CSC_CharacterRangedCritFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local critChance = GetRangedCritChance();
statFrame.critChance = critChance;
statFrame.unit = unit;
CSC_PaperDollFrame_SetLabelAndText(statFrame, RANGED_CRIT_CHANCE, critChance, true);
end
function CSC_PaperDollFrame_SetSpellCritChance(statFrame, unit)
statFrame:SetScript("OnEnter", CSC_CharacterSpellCritFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local MAX_SPELL_SCHOOLS = 7;
local holySchool = 2;
-- Start at 2 to skip physical damage
local maxSpellCrit = GetSpellCritChance(holySchool);
for i=holySchool, MAX_SPELL_SCHOOLS do
local bonusCrit = GetSpellCritChance(i);
maxSpellCrit = max(maxSpellCrit, bonusCrit);
end
statFrame.holyCrit = GetSpellCritChance(2);
statFrame.fireCrit = GetSpellCritChance(3);
statFrame.natureCrit = GetSpellCritChance(4);
statFrame.frostCrit = GetSpellCritChance(5);
statFrame.shadowCrit = GetSpellCritChance(6);
statFrame.arcaneCrit = GetSpellCritChance(7);
local unitClassId = select(3, UnitClass(unit));
if (unitClassId == CSC_PRIEST_CLASS_ID) then
local priestHolyCrit = CSC_GetPriestCritStatsFromTalents();
priestHolyCrit = priestHolyCrit + CSC_GetHolyCritFromBenediction(unit);
if (priestHolyCrit > 0) then
statFrame.holyCrit = statFrame.holyCrit + priestHolyCrit;
-- set the new maximum
maxSpellCrit = max(maxSpellCrit, statFrame.holyCrit);
end
elseif (unitClassId == CSC_WARLOCK_CLASS_ID) then
local destructionCrit = CSC_GetWarlockCritStatsFromTalents();
if (destructionCrit > 0) then
statFrame.shadowCrit = statFrame.shadowCrit + destructionCrit;
statFrame.fireCrit = statFrame.fireCrit + destructionCrit;
local tmpMax = max(statFrame.shadowCrit, statFrame.fireCrit);
-- set the new maximum
maxSpellCrit = max(maxSpellCrit, tmpMax);
end
elseif (unitClassId == CSC_SHAMAN_CLASS_ID) then
statFrame.lightningCrit = statFrame.natureCrit;
local callOfThunderCrit = CSC_GetShamanCallOfThunderCrit();
if callOfThunderCrit > 0 then
statFrame.lightningCrit = statFrame.lightningCrit + callOfThunderCrit;
end
local tidalMastery = CSC_GetShamanTidalMasteryCrit();
if tidalMastery > 0 then
statFrame.lightningCrit = statFrame.lightningCrit + tidalMastery;
statFrame.natureCrit = statFrame.natureCrit + tidalMastery;
end
local tmpMax = max(statFrame.lightningCrit, statFrame.natureCrit);
-- set the new maximum
maxSpellCrit = max(maxSpellCrit, tmpMax);
end
statFrame.unitClassId = unitClassId;
CSC_PaperDollFrame_SetLabelAndText(statFrame, SPELL_CRIT_CHANCE, maxSpellCrit, true);
end
function CSC_PaperDollFrame_SetHitChance(statFrame, unit)
statFrame:SetScript("OnEnter", CSC_CharacterHitChanceFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local hitChance = GetHitModifier();
if not hitChance then
hitChance = 0;
end
local hitChanceText = hitChance;
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_HIT_CHANCE, hitChanceText, true);
statFrame.hitChance = hitChance;
end
function CSC_PaperDollFrame_SetHitRating(statFrame, unit, ratingIndex)
statFrame:SetScript("OnEnter", CSC_CharacterHitRatingFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local unitClassId = select(3, UnitClass(unit));
local statName = getglobal("COMBAT_RATING_NAME"..ratingIndex);
local rating = GetCombatRating(ratingIndex);
local ratingBonus = GetCombatRatingBonus(ratingIndex); -- hit rating in % (hit chance) (from gear sources, doesn't seem to include talents)
if ( ratingIndex == CR_HIT_MELEE ) then
local hitChance = GetHitModifier(); -- includes talents, doesn't include hit raiting from gear
local combatRatingMult = CSC_GetCombatRatingPerUnitBonus(unit, CSC_COMBAT_RATING_HIT);
if not hitChance then
hitChance = 0;
end
ratingBonus = ratingBonus + hitChance;
rating = rating + (combatRatingMult*hitChance);
elseif ( ratingIndex == CR_HIT_SPELL ) then
local spellHitChance = CSC_GetSpellHitModifier(unit);
local combatRatingMult = CSC_GetCombatRatingPerUnitBonus(unit, CSC_COMBAT_RATING_SPELL_HIT);
if not spellHitChance then
spellHitChance = 0;
end
--spellHitChance = spellHitChance / 7; -- BUG ON BLIZZARD's side. returns 7 for each 1% hit. Dirty fix for now
if (unitClassId == CSC_SHAMAN_CLASS_ID) then
local hitFromElementalPrecision = CSC_GetShamanHitFromElementalPrecision();
spellHitChance = spellHitChance + hitFromElementalPrecision;
end
ratingBonus = ratingBonus + spellHitChance;
statFrame.spellHitGearTalents = ratingBonus;
rating = rating + (combatRatingMult*spellHitChance);
end
rating = format("%.2f", rating);
statFrame.unit = unit;
statFrame.ratingIndex = ratingIndex;
statFrame.statName = statName;
statFrame.rating = rating;
statFrame.ratingBonus = ratingBonus;
CSC_PaperDollFrame_SetLabelAndText(statFrame, statName, rating);
end
function CSC_PaperDollFrame_SetExpertise(statFrame, unit)
local expertise, offhandExpertise = GetExpertise();
local speed, offhandSpeed = UnitAttackSpeed(unit);
local text;
if( offhandSpeed ) then
text = expertise.." / "..offhandExpertise;
else
text = expertise;
end
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_EXPERTISE, text);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..getglobal("COMBAT_RATING_NAME"..CR_EXPERTISE).." "..text..FONT_COLOR_CODE_CLOSE;
local expertisePercent, offhandExpertisePercent = GetExpertisePercent();
expertisePercent = format("%.2f", expertisePercent);
if( offhandSpeed ) then
offhandExpertisePercent = format("%.2f", offhandExpertisePercent);
text = expertisePercent.."% / "..offhandExpertisePercent.."%";
else
text = expertisePercent.."%";
end
statFrame.tooltip2 = format(CR_EXPERTISE_TOOLTIP, text, GetCombatRating(CR_EXPERTISE), GetCombatRatingBonus(CR_EXPERTISE));
end
local function CSC_GetHitFromBiznicksAccurascope(unit)
CSC_ScanTooltip:ClearLines();
local hitFromScope = 0;
local rangedIndex = 18;
local itemLink = GetInventoryItemLink(unit, rangedIndex);
if itemLink then
local itemId, enchantId = itemLink:match("item:(%d+):(%d*)");
if enchantId then
if tonumber(enchantId) == 2523 then
hitFromScope = 3;
end
end
end
return hitFromScope;
end
function CSC_PaperDollFrame_SetRangedHitChance(statFrame, unit)
if not IsRangedWeapon() then
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_HIT_CHANCE, NOT_APPLICABLE, false);
return;
end
statFrame:SetScript("OnEnter", CSC_CharacterRangedHitChanceFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local hitChance = GetHitModifier();
if not hitChance then
hitChance = 0;
end
local hitFromScope = CSC_GetHitFromBiznicksAccurascope(unit);
if (hitFromScope > 0) then
hitChance = hitChance + hitFromScope;
end
local hitChanceText = hitChance;
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_HIT_CHANCE, hitChanceText, true);
statFrame.hitChance = hitChance;
end
function CSC_PaperDollFrame_SetSpellHitChance(statFrame, unit)
statFrame:SetScript("OnEnter", CSC_CharacterSpellHitChanceFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local hitChance = GetSpellHitModifier();
if not hitChance then
hitChance = 0;
end
local unitClassId = select(3, UnitClass(unit));
if unitClassId == CSC_MAGE_CLASS_ID then
local arcaneHit, frostFireHit = CSC_GetMageSpellHitFromTalents();
statFrame.arcaneHit = arcaneHit;
statFrame.frostHit = frostFireHit;
statFrame.fireHit = frostFireHit;
elseif unitClassId == CSC_WARLOCK_CLASS_ID then
statFrame.afflictionHit = CSC_GetWarlockSpellHitFromTalents();
end
local hitChanceText = hitChance;
statFrame.hitChance = hitChance;
statFrame.unitClassId = unitClassId;
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_HIT_CHANCE, hitChanceText, true);
end
function CSC_PaperDollFrame_SetAttackSpeed(statFrame, unit)
local speed, offhandSpeed = UnitAttackSpeed(unit);
local displaySpeed = format("%.2F", speed);
if ( offhandSpeed ) then
offhandSpeed = format("%.2F", offhandSpeed);
end
if ( offhandSpeed ) then
displaySpeed = displaySpeed.." / ".. offhandSpeed;
else
displaySpeed = displaySpeed;
end
CSC_PaperDollFrame_SetLabelAndText(statFrame, WEAPON_SPEED, displaySpeed, false);
statFrame.tooltip = format(PAPERDOLLFRAME_TOOLTIP_FORMAT, ATTACK_SPEED).." "..displaySpeed;
statFrame.tooltip2 = format(CR_HASTE_RATING_TOOLTIP, GetCombatRating(CR_HASTE_MELEE), GetCombatRatingBonus(CR_HASTE_MELEE));
end
function CSC_PaperDollFrame_SetRangedAttackSpeed(statFrame, unit)
if not IsRangedWeapon() then
CSC_PaperDollFrame_SetLabelAndText(statFrame, WEAPON_SPEED, NOT_APPLICABLE, false);
return;
end
local attackSpeed, minDamage, maxDamage, bonusPos, bonusNeg, percent = UnitRangedDamage(unit);
local displaySpeed = format("%.2F", attackSpeed);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..ATTACK_SPEED.." "..displaySpeed..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = format(CR_HASTE_RATING_TOOLTIP, GetCombatRating(CR_HASTE_RANGED), GetCombatRatingBonus(CR_HASTE_RANGED));
CSC_PaperDollFrame_SetLabelAndText(statFrame, WEAPON_SPEED, displaySpeed, false);
end
-- DEFENSES --
function CSC_PaperDollFrame_GetArmorReduction(armor, attackerLevel)
local levelModifier = attackerLevel;
if ( levelModifier > 59 ) then
levelModifier = levelModifier + (4.5 * (levelModifier-59));
end
local temp = 0.1*armor/(8.5*levelModifier + 40);
temp = temp/(1+temp);
if ( temp > 0.75 ) then
return 75;
end
if ( temp < 0 ) then
return 0;
end
return format("%.2f", (temp*100));
end
function CSC_PaperDollFrame_SetArmor(statFrame, unit)
local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor(unit);
local armorReduction = PaperDollFrame_GetArmorReduction(effectiveArmor, UnitLevel(unit));
local valueText, tooltipText = CSC_PaperDollFormatStat(ARMOR, base, posBuff, negBuff);
local valueNum = max(0, base + posBuff + negBuff);
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_ARMOR, valueText, false);
statFrame.tooltip = tooltipText;
statFrame.tooltip2 = format(DEFAULT_STATARMOR_TOOLTIP, armorReduction);
local petBonus = ComputePetBonus("PET_BONUS_ARMOR", effectiveArmor );
if( petBonus > 0 ) then
statFrame.tooltip2 = statFrame.tooltip2 .. "\n" .. format(PET_BONUS_TOOLTIP_ARMOR, petBonus);
end
end
function CSC_PaperDollFrame_SetDefense(statFrame, unit)
statFrame:SetScript("OnEnter", CSC_CharacterDefenseFrame_OnEnter)
statFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local base, modifier = UnitDefense(unit);
local posBuff = 0;
local negBuff = 0;
local posBuff = 0;
local negBuff = 0;
if ( modifier > 0 ) then
posBuff = modifier;
elseif ( modifier < 0 ) then
negBuff = modifier;
end
local valueText, defenseText = CSC_PaperDollFormatStat(DEFENSE, base, posBuff, negBuff);
local valueNum = max(0, base + posBuff + negBuff);
statFrame.defense = defenseText;
CSC_PaperDollFrame_SetLabelAndText(statFrame, CSC_DEFENSE, valueText, false);
end
function CSC_PaperDollFrame_SetDodge(statFrame)
local chance = GetDodgeChance();
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_DODGE, chance, true);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..getglobal("DODGE_CHANCE").." "..string.format("%.02f", chance).."%"..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = format(CR_DODGE_TOOLTIP, GetCombatRating(CR_DODGE), GetCombatRatingBonus(CR_DODGE));
end
function CSC_PaperDollFrame_SetParry(statFrame)
local chance = GetParryChance();
CSC_PaperDollFrame_SetLabelAndText(statFrame, STAT_PARRY, chance, true);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..getglobal("PARRY_CHANCE").." "..string.format("%.02f", chance).."%"..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = format(CR_PARRY_TOOLTIP, GetCombatRating(CR_PARRY), GetCombatRatingBonus(CR_PARRY));
end
function CSC_GetBlockValue(unit)
CSC_ScanTooltip:ClearLines();
local blockValueFromItems = 0;
local firstItemslotIndex = 1;
local lastItemslotIndex = 18;
local blockValueIDs = { ITEM_MOD_BLOCK_RATING_SHORT, ITEM_MOD_BLOCK_RATING, ITEM_MOD_BLOCK_VALUE };
local equippedMightSetItems = 0;
for itemslot=firstItemslotIndex, lastItemslotIndex do
local hasItem = CSC_ScanTooltip:SetInventoryItem(unit, itemslot);
if hasItem then
local itemId = GetInventoryItemID(unit, itemslot);
if (itemId == g_BattlegearOfMightIds[itemId]) then
equippedMightSetItems = equippedMightSetItems + 1;
else
local maxLines = CSC_ScanTooltip:NumLines();