forked from yutsuku/BetterCharacterStats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.lua
More file actions
1015 lines (848 loc) · 29.4 KB
/
helper.lua
File metadata and controls
1015 lines (848 loc) · 29.4 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
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 {}
local BCS_Tooltip = getglobal("BetterCharacterStatsTooltip") or CreateFrame("GameTooltip", "BetterCharacterStatsTooltip", nil, "GameTooltipTemplate")
local BCS_Prefix = "BetterCharacterStatsTooltip"
BCS_Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
local L = BCS["L"]
local strfind = strfind
local tonumber = tonumber
local tinsert = tinsert
local AURA_BUFF = "HELPFUL"
local AURA_DEBUFF = "HARMFUL"
function BCS:ColorText(colorCode, msg)
return colorCode .. msg .. FONT_COLOR_CODE_CLOSE
end
function BCS:ModifierColor(modifier, msg)
if modifier > 0 then
return BCS:ColorText(GREEN_FONT_COLOR_CODE, msg)
end
if modifier < 0 then
return BCS:ColorText(RED_FONT_COLOR_CODE, msg)
end
return ""..msg
end
function BCS:ModifierText(modifier, base, total)
if modifier > 0 then
return HIGHLIGHT_FONT_COLOR_CODE.."("..base..GREEN_FONT_COLOR_CODE.."+"..modifier..HIGHLIGHT_FONT_COLOR_CODE..") "..total
end
if modifier < 0 then
return HIGHLIGHT_FONT_COLOR_CODE.."("..base..RED_FONT_COLOR_CODE..modifier..HIGHLIGHT_FONT_COLOR_CODE..") "..total
end
return ""..base
end
function BCS:ModifierTextPercent(modifier, base, total)
if modifier > 0 then
return HIGHLIGHT_FONT_COLOR_CODE.."("..base.."%"..GREEN_FONT_COLOR_CODE.."+"..modifier.."%"..HIGHLIGHT_FONT_COLOR_CODE..") "..total.."%"
end
if modifier < 0 then
return HIGHLIGHT_FONT_COLOR_CODE.."("..base.."%"..RED_FONT_COLOR_CODE..modifier.."%"..HIGHLIGHT_FONT_COLOR_CODE..") "..total.."%"
end
return base.."%"
end
local function tContains(table, item)
local index = 1
while table[index] do
if (item == table[index]) then
return 1
end
index = index + 1
end
return nil
end
function BCS:GetPlayerAura(searchText, auraType)
if not auraType then
-- buffs
-- http://blue.cardplace.com/cache/wow-dungeons/624230.htm
-- 32 buffs max
for i = 0, 31 do
local index = GetPlayerBuff(i, 'HELPFUL')
if index > -1 then
BCS_Tooltip:SetPlayerBuff(index)
local MAX_LINES = BCS_Tooltip:NumLines()
for line = 1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local value = { strfind(left:GetText(), searchText) }
if value[1] then
return unpack(value)
end
end
end
end
end
elseif auraType == 'HARMFUL' then
for i = 0, 6 do
local index = GetPlayerBuff(i, auraType)
if index > -1 then
BCS_Tooltip:SetPlayerBuff(index)
local MAX_LINES = BCS_Tooltip:NumLines()
for line = 1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local value = { strfind(left:GetText(), searchText) }
if value[1] then
return unpack(value)
end
end
end
end
end
end
end
function BCS:GetHitRatings()
local melee_hit = 0
local ranged_hit = 0
local hit_debuff = 0;
local Hit_Set_Bonus = {}
BCS:IterateInventory(function(lineText, metaData)
local _,_, value = strfind(lineText, L["Equip: Improves your chance to hit by (%d)%%."])
if value then
melee_hit = melee_hit + tonumber(value)
ranged_hit = ranged_hit + tonumber(value)
end
_,_, value = strfind(lineText, L["/Hit %+(%d+)"])
if value then
melee_hit = melee_hit + tonumber(value)
ranged_hit = ranged_hit + tonumber(value)
end
local _,_, value = strfind(lineText, L["+(%d)%% Hit"]) -- Ranged hit from scope
if value and metaData.slot == 18 then
ranged_hit = ranged_hit + tonumber(value)
end
_,_, value = strfind(lineText, "(.+) %(%d/%d%)")
if value then
metaData.setName = value
end
_,_, value = strfind(lineText, L["^Set: Improves your chance to hit by (%d)%%."])
if value and metaData.setName and not tContains(Hit_Set_Bonus, metaData.setName) then
tinsert(Hit_Set_Bonus, metaData.setName)
melee_hit = melee_hit + tonumber(value)
ranged_hit = ranged_hit + tonumber(value)
end
end)
BCS:IterateAuras(AURA_BUFF, function(lineText)
-- Dark Desire
local _, _, hitFromAura = strfind(lineText, L["Chance to hit increased by (%d)%%."])
if hitFromAura then
melee_hit = melee_hit + tonumber(hitFromAura)
ranged_hit = ranged_hit + tonumber(hitFromAura)
end
_, _, hitFromAura = strfind(lineText, L["Improves your chance to hit by (%d+)%%."])
if hitFromAura then
melee_hit = melee_hit + tonumber(hitFromAura)
ranged_hit = ranged_hit + tonumber(hitFromAura)
end
_, _, hitFromAura = strfind(lineText, L["Increases attack power by %d+ and chance to hit by (%d+)%%."])
if hitFromAura then
melee_hit = melee_hit + tonumber(hitFromAura)
ranged_hit = ranged_hit + tonumber(hitFromAura)
end
end)
BCS:IterateAuras(AURA_DEBUFF, function(lineText)
local _, _, hitFromAura = strfind(lineText, L["Chance to hit reduced by (%d+)%%."])
if hitFromAura then
hit_debuff = hit_debuff + tonumber(hitFromAura)
end
_, _, hitFromAura = strfind(lineText, L["Chance to hit decreased by (%d+)%% and %d+ Nature damage every %d+ sec."])
if hitFromAura then
hit_debuff = hit_debuff + tonumber(hitFromAura)
end
hitFromAura = strfind(lineText, L["Lowered chance to hit."])
if hitFromAura then
hit_debuff = hit_debuff + 25
end
end)
if BCS.player.class == "HUNTER" then
local _, _, _, _, rank = GetTalentInfo(3, 11) -- Survival, Surefooted
melee_hit = melee_hit + rank
ranged_hit = ranged_hit + rank
end
if BCS.player.class == "ROGUE" then
local _, _, _, _, rank = GetTalentInfo(2, 6) -- Combat, Precision
melee_hit = melee_hit + rank
end
if BCS.player.class == "PALADIN" then
local _, _, _, _, rank = GetTalentInfo(2, 3) -- Protection, Precision
melee_hit = melee_hit + rank
end
if BCS.player.class == "SHAMAN" then
local _, _, _, _, rank = GetTalentInfo(3, 6) -- Restoration, Nature's Guidance
melee_hit = melee_hit + rank
end
return {
melee = melee_hit,
ranged = ranged_hit,
debuff = hit_debuff
}
end
function BCS:GetItemIDFromLink(itemLink)
if not itemLink then
return
end
local foundID, _, itemID = string.find(itemLink, "item:(%d+)")
if not foundID then
return
end
return tonumber(itemID)
end
function BCS:GetWeaponSkillNameForSlot(slotId)
local weaponType
if BCS.player.class == "DRUID" and slotId == 16 then
BCS:IterateAuras(AURA_BUFF, function(lineText)
local bearForm = strfind(lineText, L["Bear Form"]) -- also matches Dire Bear Form
local catForm = strfind(lineText, L["Cat Form"])
local aquaticForm = strfind(lineText, L["Aquatic Form"])
local travelForm = strfind(lineText, L["Travel Form"])
if bearForm or catForm or aquaticForm or travelForm then
weaponType = "Feral Combat"
end
end)
if weaponType then
return weaponType
end
end
local itemLink = GetInventoryItemLink("player", slotId)
if not itemLink then
return
end
local itemID = BCS:GetItemIDFromLink(itemLink)
local _, _, _, _, _, weaponType = GetItemInfo(itemID)
weaponType = string.gsub(weaponType, "^One%-Handed%s*", "")
if weaponType == "Fist Weapons" then
weaponType = "Unarmed"
end
if weaponType == "Fishing Pole" then
weaponType = "Fishing"
end
return weaponType
end
function BCS:GetWeaponSkills()
local main_hand_type = BCS:GetWeaponSkillNameForSlot(16)
if not main_hand_type then
main_hand_type = "Unarmed"
end
local off_hand_type = BCS:GetWeaponSkillNameForSlot(17)
local ranged_type = BCS:GetWeaponSkillNameForSlot(18)
local table = {}
local MAX_SKILLS = GetNumSkillLines()
for skill = 0, MAX_SKILLS do
local skillName, _, _, skillRank, numTempPoints, skillModifier = GetSkillLineInfo(skill)
if skillName and skillName == main_hand_type then
-- On official Classic servers Class Skills level up when you do.
-- In TBC Class skills was changed to always be gray and have a level of 1
-- Many private servers use this TBC core so this hack simulates the actual skill level
if skillName == "Feral Combat" and skillRank < 5 then
skillRank = BCS.player.level * 5
table.main_hand = {
type = main_hand_type,
skill = skillRank,
temp = 0,
modifier = 0,
total = skillRank
}
else
table.main_hand = {
type = main_hand_type,
skill = skillRank,
temp = numTempPoints,
modifier = skillModifier,
total = skillRank + numTempPoints + skillModifier
}
end
end
if skillName and skillName == off_hand_type then
table.off_hand = {
type = off_hand_type,
skill = skillRank,
temp = numTempPoints,
modifier = skillModifier,
total = skillRank + numTempPoints + skillModifier
}
end
if skillName and skillName == ranged_type then
table.ranged = {
type = ranged_type,
skill = skillRank,
temp = numTempPoints,
modifier = skillModifier,
total = skillRank + numTempPoints + skillModifier
}
end
end
-- Skinning Knife, Blacksmith Hammer, Mining Pick, Arclight Spanner
local skillRank = 1
if main_hand_type == "Miscellaneous" then
table.main_hand = {
type = main_hand_type,
skill = skillRank,
temp = 0,
modifier = 0,
total = skillRank
}
end
if off_hand_type == "Miscellaneous" then
table.main_hand = {
type = off_hand_type,
skill = skillRank,
temp = 0,
modifier = 0,
total = skillRank
}
end
-- Skipping ranged_type as Idols, Librams, Totems, and Egan's Blaster cannot be used as a ranged weapon
return table
end
local function getGlancingBlow(targetDefense, attackerSkill, attackerLevel)
local skillDiff = targetDefense - attackerSkill
local glanceChance = 10 + (targetDefense - math.min(attackerLevel * 5, attackerSkill)) * 2
local glanceLowEnd = 1.3 - 0.05 * skillDiff
local glanceHighEnd = 1.2 - 0.03 * skillDiff
glanceLowEnd = math.min(glanceLowEnd, 0.91)
glanceHighEnd = math.min(glanceHighEnd, 0.99)
glanceHighEnd = math.max(glanceHighEnd, 0.2)
local glancePenalty = (1 - (glanceHighEnd + glanceLowEnd) / 2) * 100
return glanceChance, glancePenalty
end
function BCS:GetGlancingBlows(weaponSkills)
local levelChance, levelPenalty = getGlancingBlow(BCS.player.levelDefense, weaponSkills.main_hand.total, BCS.player.level)
local bossChance, bossPenalty = getGlancingBlow(BCS.player.bossDefense, weaponSkills.main_hand.total, BCS.player.level)
local table = {}
table.main_hand = {
level = {
chance = levelChance,
penalty = levelPenalty,
},
boss = {
chance = bossChance,
penalty = bossPenalty,
},
}
if weaponSkills.off_hand then
local offHandLevelChance, offHandLevelPenalty = getGlancingBlow(BCS.player.levelDefense, weaponSkills.off_hand.total, BCS.player.level)
local offHandBossChance, offHandBossPenalty = getGlancingBlow(BCS.player.bossDefense, weaponSkills.off_hand.total, BCS.player.level)
table.off_hand = {
level = {
chance = offHandLevelChance,
penalty = offHandLevelPenalty
},
boss = {
chance = offHandBossChance,
penalty = offHandBossPenalty
}
}
end
return table
end
local function getMissChance(targetDefense, attackerSkill)
local targetMiss = 0
local hitSuppression = 0
local skillDiff = targetDefense - attackerSkill
if skillDiff > 10 then
targetMiss = 5 + skillDiff * 0.2
hitSuppression = (skillDiff - 10) * 0.2
end
if skillDiff <= 10 then
targetMiss = 5 + skillDiff * 0.1
end
return targetMiss, hitSuppression
end
function BCS:GetMissChances(weaponSkills, hitRatings)
local table = {}
local dualWieldPenalty = weaponSkills.off_hand and 19 or 0
local mainHandMiss = getMissChance(BCS.player.levelDefense, weaponSkills.main_hand.total)
local mainHandBossMiss, mainHandSuppression = getMissChance(BCS.player.bossDefense, weaponSkills.main_hand.total)
table.main_hand = {
yellowVsLevel = math.max(0, mainHandMiss + hitRatings.debuff - hitRatings.melee),
yellowVsBoss = math.max(0, mainHandBossMiss + hitRatings.debuff - math.max(0, hitRatings.melee - mainHandSuppression)),
autoVsLevel = math.max(0, mainHandMiss + hitRatings.debuff + dualWieldPenalty - hitRatings.melee),
autoVsBoss = math.max(0, mainHandBossMiss + hitRatings.debuff + dualWieldPenalty - math.max(0, hitRatings.melee - mainHandSuppression)),
bossSuppression = mainHandSuppression,
}
if weaponSkills.off_hand then
local offhandMiss = getMissChance(BCS.player.levelDefense, weaponSkills.off_hand.total)
local offHandBossMiss, offHandSuppression = getMissChance(BCS.player.bossDefense, weaponSkills.off_hand.total)
table.off_hand = {
autoVsLevel = math.max(0, offhandMiss + hitRatings.debuff + dualWieldPenalty - hitRatings.melee),
autoVsBoss = math.max(0, offHandBossMiss + hitRatings.debuff + dualWieldPenalty - math.max(0, hitRatings.melee - offHandSuppression)),
bossSuppression = offHandSuppression,
}
end
if weaponSkills.ranged then
local rangedMiss = getMissChance(BCS.player.levelDefense, weaponSkills.ranged.total)
local rangedBossMiss, rangedSuppression = getMissChance(BCS.player.bossDefense, weaponSkills.ranged.total)
table.ranged = {
yellowVsLevel = rangedMiss + hitRatings.debuff - hitRatings.ranged,
yellowVsBoss = rangedBossMiss + hitRatings.debuff - math.max(0, hitRatings.ranged - rangedSuppression),
bossSuppression = rangedSuppression,
}
end
return table
end
function BCS:GetSpellHitRating()
local hit = 0
local hit_fire = 0
local hit_frost = 0
local hit_arcane = 0
local hit_shadow = 0
local hit_Set_Bonus = {}
BCS:IterateInventory(function(lineText, metaData)
local _,_, value = strfind(lineText, L["Equip: Improves your chance to hit with spells by (%d)%%."])
if value then
hit = hit + tonumber(value)
end
local _,_, value = strfind(lineText, L["/Spell Hit %+(%d+)"])
if value then
hit = hit + tonumber(value)
end
local _,_, value = strfind(lineText, "(.+) %(%d/%d%)")
if value then
metaData.setName = value
end
local _, _, value = strfind(lineText, L["^Set: Improves your chance to hit with spells by (%d)%%."])
if value and metaData.setName and not tContains(hit_Set_Bonus, metaData.setName) then
tinsert(hit_Set_Bonus, metaData.setName)
hit = hit + tonumber(value)
end
end)
if BCS.player.class == "MAGE" then
local _, _, _, _, rank = GetTalentInfo(1, 2) -- Arcane, Arcane Focus
hit_arcane = hit_arcane + rank * 2
local _, _, _, _, rank = GetTalentInfo(3, 3) -- Frost, Elemental Precision
hit_fire = hit_fire + rank * 2
hit_frost = hit_frost + rank * 2
end
if BCS.player.class == "PRIEST" then
local _, _, _, _, rank = GetTalentInfo(3, 5) -- Shadow, Shadow Focus
hit_shadow = hit_shadow + rank * 2
end
if BCS.player.class == "SHAMAN" then
local _, _, _, _, rank = GetTalentInfo(3, 6) -- Restoration, Nature's Guidance
hit = hit + rank
end
-- buffs
local _, _, hitFromAura = BCS:GetPlayerAura(L["Spell hit chance increased by (%d+)%%."])
if hitFromAura then
hit = hit + tonumber(hitFromAura)
end
return hit, hit_fire, hit_frost, hit_arcane, hit_shadow
end
local function getSpellBookCrit()
local _, _, offset, numSpells = GetSpellTabInfo(1)
for spell = 1, numSpells do
local currentPage = ceil(spell / SPELLS_PER_PAGE)
local SpellID = spell + offset + (SPELLS_PER_PAGE * (currentPage - 1))
BCS_Tooltip:SetSpell(SpellID, BOOKTYPE_SPELL)
local MAX_LINES = BCS_Tooltip:NumLines()
for line = 1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local _, _, value = strfind(left:GetText(), L["([%d.]+)%% chance to crit"])
if value then
return tonumber(value)
end
end
end
end
end
local function getCritChance(baseCrit, weaponSkill)
local diffSkill = weaponSkill - BCS.player.levelDefense
if diffSkill > 0 then
return baseCrit + diffSkill * 0.04
end
if diffSkill < 0 then
return baseCrit + diffSkill * 0.2
end
return baseCrit
end
function BCS:GetCritChances(weaponSkills)
local spellBookCrit = getSpellBookCrit()
local table = {}
table.main_hand = spellBookCrit
-- calculating crit at max weapon skill for given level without bonuses
local weaponSkillCrit = getCritChance(spellBookCrit, weaponSkills.main_hand.total)
local baseCrit = spellBookCrit + (spellBookCrit - weaponSkillCrit)
if weaponSkills.off_hand then
table.off_hand = getCritChance(baseCrit, weaponSkills.off_hand.total)
end
if weaponSkills.ranged then
table.ranged = getCritChance(baseCrit, weaponSkills.ranged.total)
end
if BCS.player.class == 'HUNTER' then
local _, _, _, _, rank = GetTalentInfo(2, 4) -- Marksmanship, Lethal Shots
table.ranged = table.ranged + rank
end
return table
end
local function getBossCritSuppression(targetDefense, attackerSkill)
local baseSkill = math.min(BCS.player.level * 5, attackerSkill)
local diffSkill = baseSkill - targetDefense
local critSuppression = 0
if diffSkill < 0 then
critSuppression = critSuppression + diffSkill * 0.2 -- 3% suppression vs bosses
if diffSkill <= -15 then
critSuppression = critSuppression + diffSkill * 0.12 -- 1.8% suppression to auras vs bosses
end
if attackerSkill > baseSkill then
critSuppression = critSuppression + (baseSkill - attackerSkill) * 0.04 -- bonus weapon skill suppression
end
end
return critSuppression * -1
end
function BCS:GetBossCritSuppressions(weaponSkills)
local table = {}
table.main_hand = getBossCritSuppression(BCS.player.bossDefense, weaponSkills.main_hand.total)
if weaponSkills.off_hand then
table.off_hand = getBossCritSuppression(BCS.player.bossDefense, weaponSkills.off_hand.total)
end
return table
end
local function getTargetDodgeChance(targetDefense, attackerSkill)
return 5 + (targetDefense - attackerSkill) * 0.1
end
function BCS:GetTargetDodgeChances(weaponSkills)
local table = {}
table.main_hand = {
level = getTargetDodgeChance(BCS.player.levelDefense, weaponSkills.main_hand.total),
boss = getTargetDodgeChance(BCS.player.bossDefense, weaponSkills.main_hand.total),
}
if weaponSkills.off_hand then
table.off_hand = {
level = getTargetDodgeChance(BCS.player.levelDefense, weaponSkills.off_hand.total),
boss = getTargetDodgeChance(BCS.player.bossDefense, weaponSkills.off_hand.total),
}
end
return table
end
local function getTargetBlockChance(targetDefense, attackerSkill)
return math.min(5, 5 + (targetDefense - attackerSkill) * 0.1)
end
function BCS:GetTargetBlockChances(weaponSkills)
local table = {}
table.main_hand = {
level = getTargetBlockChance(BCS.player.levelDefense, weaponSkills.main_hand.total),
boss = getTargetBlockChance(BCS.player.bossDefense, weaponSkills.main_hand.total),
}
if weaponSkills.off_hand then
table.off_hand = {
level = getTargetBlockChance(BCS.player.levelDefense, weaponSkills.off_hand.total),
boss = getTargetBlockChance(BCS.player.bossDefense, weaponSkills.off_hand.total),
}
end
return table
end
local function getTargetParryChance(targetDefense, attackerSkill)
local diffSkill = targetDefense - attackerSkill
local parry = diffSkill * 0.1
if diffSkill >= 10 then
parry = parry + 7.5 -- boss parry chance is 14%
end
return parry
end
function BCS:GetTargetParryChanges(weaponSkills)
local table = {}
table.main_hand = {
level = getTargetParryChance(BCS.player.levelDefense, weaponSkills.main_hand.total),
boss = getTargetParryChance(BCS.player.bossDefense, weaponSkills.main_hand.total),
}
if weaponSkills.off_hand then
table.off_hand = {
level = getTargetParryChance(BCS.player.levelDefense, weaponSkills.off_hand.total),
boss = getTargetParryChance(BCS.player.bossDefense, weaponSkills.off_hand.total),
}
end
return table
end
function BCS:GetSpellCritChance()
-- school crit: most likely never
local Crit_Set_Bonus = {}
local spellCrit = 0;
local _, intellect = UnitStat("player", 4)
-- values from theorycraft / http://wow.allakhazam.com/forum.html?forum=21&mid=1157230638252681707
if BCS.player.class == "MAGE" then
spellCrit = 0.2 + (intellect / 59.5)
elseif BCS.player.class == "WARLOCK" then
spellCrit = 1.7 + (intellect / 60.6)
elseif BCS.player.class == "PRIEST" then
spellCrit = 0.8 + (intellect / 59.56)
elseif BCS.player.class == "DRUID" then
spellCrit = 1.8 + (intellect / 60)
elseif BCS.player.class == "SHAMAN" then
spellCrit = 1.8 + (intellect / 59.2)
elseif BCS.player.class == "PALADIN" then
spellCrit = intellect / 29.5
end
BCS:IterateInventory(function (lineText, metaData)
local _,_, value = strfind(lineText, L["Equip: Improves your chance to get a critical strike with spells by (%d)%%."])
if value then
spellCrit = spellCrit + tonumber(value)
end
_,_, value = strfind(lineText, "(.+) %(%d/%d%)")
if value then
metaData.setName = value
end
_, _, value = strfind(lineText, L["^Set: Improves your chance to get a critical strike with spells by (%d)%%."])
if value and metaData.setName and not tContains(Crit_Set_Bonus, metaData.setName) then
tinsert(Crit_Set_Bonus, metaData.setName)
spellCrit = spellCrit + tonumber(value)
end
end)
-- buffs
BCS:IterateAuras(AURA_BUFF, function(lineText)
local _, _, critFromAura = strfind(lineText, L["Chance for a critical hit with a spell increased by (%d+)%%."])
if critFromAura then
spellCrit = spellCrit + tonumber(critFromAura)
end
_, _, critFromAura = strfind(lineText, L["While active, target's critical hit chance with spells and attacks increases by 10%%."])
if critFromAura then
spellCrit = spellCrit + 10
end
_, _, critFromAura = strfind(lineText, L["Increases chance for a melee, ranged, or spell critical by (%d+)%% and all attributes by %d+."])
if critFromAura then
spellCrit = spellCrit + tonumber(critFromAura)
end
critFromAura = strfind(lineText, L["Increases critical chance of spells by 10%%, melee and ranged by 5%% and grants 140 attack power. 120 minute duration."])
if critFromAura then
spellCrit = spellCrit + 10
end
_, _, critFromAura = strfind(lineText, L["Critical strike chance with spells and melee attacks increased by (%d+)%%."])
if critFromAura then
spellCrit = spellCrit + tonumber(critFromAura)
end
end)
BCS:IterateAuras(AURA_DEBUFF, function(lineText)
local _, _, _, critFromAura = strfind(lineText, L["Melee critical-hit chance reduced by (%d+)%%.\r\nSpell critical-hit chance reduced by (%d+)%%."])
if critFromAura then
spellCrit = spellCrit - tonumber(critFromAura)
end
end)
return spellCrit
end
function BCS:GetSpellPower()
local spellPower = 0;
local damagePower = 0;
local SpellPower_Set_Bonus = {}
local SpellPower_Schools = {
["Arcane"] = 0,
["Fire"] = 0,
["Frost"] = 0,
["Holy"] = 0,
["Nature"] = 0,
["Shadow"] = 0,
}
BCS:IterateInventory(function(lineText, metaData)
local _,_, value = strfind(lineText, L["Equip: Increases damage and healing done by magical spells and effects by up to (%d+)."])
if value then
spellPower = spellPower + tonumber(value)
end
_,_, value = strfind(lineText, L["Spell Damage %+(%d+)"])
if value then
spellPower = spellPower + tonumber(value)
end
_,_, value = strfind(lineText, L["^%+(%d+) Spell Damage and Healing"])
if value then
spellPower = spellPower + tonumber(value)
end
_,_, value = strfind(lineText, L["^%+(%d+) Damage and Healing Spells"])
if value then
spellPower = spellPower + tonumber(value)
end
_,_, value = strfind(lineText, "(.+) %(%d/%d%)")
if value then
metaData.setName = value
end
_, _, value = strfind(lineText, L["^Set: Increases damage and healing done by magical spells and effects by up to (%d+)%."])
if value and metaData.setName and not tContains(SpellPower_Set_Bonus, metaData.setName) then
tinsert(SpellPower_Set_Bonus, metaData.setName)
spellPower = spellPower + tonumber(value)
end
-- Check specific school damage
for school, schoolPower in pairs(SpellPower_Schools) do
local _,_, value = strfind(lineText, L["Equip: Increases damage done by "..school.." spells and effects by up to (%d+)."])
if value then
SpellPower_Schools[school] = schoolPower + tonumber(value)
end
if L[school.." Damage %+(%d+)"] then
_,_, value = strfind(lineText, L[school.." Damage %+(%d+)"])
if value then
SpellPower_Schools[school] = schoolPower + tonumber(value)
end
end
if L["^%+(%d+) "..school.." Spell Damage"] then
_,_, value = strfind(lineText, L["^%+(%d+) "..school.." Spell Damage"])
if value then
SpellPower_Schools[school] = schoolPower + tonumber(value)
end
end
end
end)
BCS:IterateAuras(nil, function(lineText)
-- Very Berry Cream
local _, _, spellPowerFromAura = strfind(lineText, L["Magical damage dealt is increased by up to (%d+)."])
if spellPowerFromAura then
spellPower = spellPower + tonumber(spellPowerFromAura)
damagePower = damagePower + tonumber(spellPowerFromAura)
end
-- (Greater) Arcane Elixir
_, _, spellPowerFromAura = strfind(lineText, L["Magical damage dealt by spells and abilities is increased by up to (%d+)."])
if spellPowerFromAura then
spellPower = spellPower + tonumber(spellPowerFromAura)
damagePower = damagePower + tonumber(spellPowerFromAura)
end
-- Flask of Supreme power
_, _, spellPowerFromAura = strfind(lineText, L["Spell damage increased by up to (%d+)."])
if spellPowerFromAura then
spellPower = spellPower + tonumber(spellPowerFromAura)
damagePower = damagePower + tonumber(spellPowerFromAura)
end
-- Fire, Frost, Shadow power Elixir
for school, schoolPower in pairs(SpellPower_Schools) do
local _, _, schoolPowerFromAura = strfind(lineText, L[school.." damage dealt by spells and abilities is increased by up to (%d+)."])
if schoolPowerFromAura then
SpellPower_Schools[school] = schoolPower + tonumber(schoolPowerFromAura)
end
end
-- Blessing of Blackfathom debuff
local _, _, schoolPowerFromAura = strfind(lineText, L["Increases frost damage done by (%d+)"])
if schoolPowerFromAura then
SpellPower_Schools["Frost"] = SpellPower_Schools["Frost"] + tonumber(schoolPowerFromAura)
end
end)
if BCS.player.class == "PRIEST" then
local _, _, _, _, rank = GetTalentInfo(2, 14) -- Holy, Spiritual Guidance
local _, spirit = UnitStat("player", 5)
spellPower = spellPower + floor(rank * 0.05 * spirit)
end
return spellPower, SpellPower_Schools, damagePower
end
function BCS:GetHealingPower()
local healPower = 0;
local healPower_Set_Bonus = {}
BCS:IterateInventory(function(lineText, metaData)
local _,_, value = strfind(lineText, L["Equip: Increases healing done by spells and effects by up to (%d+)."])
if value then
healPower = healPower + tonumber(value)
end
_,_, value = strfind(lineText, L["Healing Spells %+(%d+)"])
if value then
healPower = healPower + tonumber(value)
end
_,_, value = strfind(lineText, L["^%+(%d+) Healing Spells"])
if value then
healPower = healPower + tonumber(value)
end
_,_, value = strfind(lineText, "(.+) %(%d/%d%)")
if value then
metaData.setName = value
end
_, _, value = strfind(lineText, L["^Set: Increases healing done by spells and effects by up to (%d+)%."])
if value and metaData.setName and not tContains(healPower_Set_Bonus, metaData.setName) then
tinsert(healPower_Set_Bonus, metaData.setName)
healPower = healPower + tonumber(value)
end
end)
-- Sweet Surprise
local _, _, healPowerFromAura = BCS:GetPlayerAura(L["Healing done by magical spells is increased by up to (%d+)."])
if healPowerFromAura then
healPower = healPower + tonumber(healPowerFromAura)
end
return healPower
end
function BCS:GetRegenMPPerSpirit()
local _, spirit = UnitStat("player", 5)
if BCS.player.class == "DRUID" then
return spirit / 5 + 15
end
if BCS.player.class == "HUNTER" then
return spirit / 5 + 15
end
if BCS.player.class == "MAGE" then
return spirit / 4 + 12.5
end
if BCS.player.class == "PALADIN" then
return spirit / 5 + 15
end
if BCS.player.class == "PRIEST" then
return spirit / 4 + 12.5
end
if BCS.player.class == "SHAMAN" then
return spirit / 5 + 17
end
if BCS.player.class == "WARLOCK" then
return spirit / 5 + 15
end
return 0
end
function BCS:GetManaRegen()
local power_regen = BCS:GetRegenMPPerSpirit()
local base = power_regen
local casting = power_regen / 100
local mp5 = 0;
BCS:IterateInventory(function(lineText, metaData)
local _,_, value = strfind(lineText, L["^Mana Regen %+(%d+)"])
if value then
mp5 = mp5 + tonumber(value)
end
_,_, value = strfind(lineText, L["Equip: Restores (%d+) mana per 5 sec."])
if value then
mp5 = mp5 + tonumber(value)
end
_,_, value = strfind(lineText, L["^%+(%d+) mana every 5 sec."])
if value then
mp5 = mp5 + tonumber(value)
end
end)
BCS:IterateAuras(AURA_BUFF, function(lineText)
local found = strfind(lineText, L["Increases hitpoints by 300. 15%% haste to melee attacks. 10 mana regen every 5 seconds."])
if found then
mp5 = mp5 + 10
end
local _, _, mp5FromAura = strfind(lineText, L["Restores (%d+) mana every 5 seconds."])
if mp5FromAura then
mp5 = mp5 + tonumber(mp5FromAura)
end
local _, _, mp2FromAura = strfind(lineText, L["Gain (%d+) mana every 2 seconds."])
if mp2FromAura then
mp5 = mp5 + tonumber(mp2FromAura) * 2.5
end
end)
return base, casting, mp5
end
local MAX_INVENTORY_SLOTS = 19
function BCS:IterateInventory(callbackFunc)
for slot=0, MAX_INVENTORY_SLOTS do
local hasItem = BCS_Tooltip:SetInventoryItem("player", slot)
if hasItem then
local MAX_LINES = BCS_Tooltip:NumLines()
local metaData = {
slot = slot,
setName = nil,
}
for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
local lineText = left:GetText()
if lineText then
callbackFunc(lineText, metaData)
end
end
end
end
end
function BCS:IterateAuras(buffFilter, callbackFunc)
if not buffFilter then
buffFilter = "HELPFUL|HARMFUL"
end
for i=0, 200 do
local index = GetPlayerBuff(i, buffFilter)
if index < 0 then