-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStats.lua
2932 lines (2583 loc) · 104 KB
/
Stats.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
local _, L = ...;
----------------------------------------------------------------------------------
------------------------------ STATS PANE FUNCTIONS ------------------------------
----------------------------------------------------------------------------------
local STATCATEGORY_PADDING = 4;
local STATCATEGORY_MOVING_INDENT = 4;
local STRIPE_COLOR = {r=0.9, g=0.9, b=1};
local StatCategoryFrames = {};
-- Creating StatsPane
function MCF_CreateStatsFrame(frame)
frame.StatsPane = CreateFrame("ScrollFrame", "CharacterStatsPane", frame, "MCF-CharacterStatsPaneTemplate");
end
function MCF_PaperDollFrame_CollapseStatCategory(categoryFrame)
if (not categoryFrame.collapsed) then
categoryFrame.collapsed = true;
local index = 1;
while (_G[categoryFrame:GetName().."Stat"..index]) do
_G[categoryFrame:GetName().."Stat"..index]:Hide();
index = index + 1;
end
categoryFrame.CollapsedIcon:Show();
categoryFrame.ExpandedIcon:Hide();
categoryFrame:SetHeight(18);
MCF_PaperDollFrame_UpdateStatScrollChildHeight();
categoryFrame.BgMinimized:Show();
categoryFrame.BgTop:Hide();
categoryFrame.BgMiddle:Hide();
categoryFrame.BgBottom:Hide();
end
end
function MCF_PaperDollFrame_ExpandStatCategory(categoryFrame)
if (categoryFrame.collapsed) then
categoryFrame.collapsed = false;
categoryFrame.CollapsedIcon:Hide();
categoryFrame.ExpandedIcon:Show();
MCF_PaperDollFrame_UpdateStatCategory(categoryFrame);
MCF_PaperDollFrame_UpdateStatScrollChildHeight();
categoryFrame.BgMinimized:Hide();
categoryFrame.BgTop:Show();
categoryFrame.BgMiddle:Show();
categoryFrame.BgBottom:Show();
end
end
-- /run MCF_PaperDoll_InitStatCategories(MCF_PAPERDOLL_STATCATEGORY_DEFAULTORDER, "statCategoryOrder", "statCategoriesCollapsed", "player");
function MCF_PaperDoll_InitStatCategories(defaultOrder, orderCVarName, collapsedCVarName, unit)
local category;
local order = defaultOrder;
-- Load order from cvar
if (orderCVarName) then
local orderString = MCF_GetSettings(orderCVarName);
local savedOrder = {};
if (orderString and orderString ~= "") then
for i in gmatch(orderString, "%d+,?") do
i = gsub(i, ",", "");
i = tonumber(i);
if (i) then
local categoryName = MCF_PaperDoll_FindCategoryById(i);
if (categoryName) then
tinsert(savedOrder, categoryName);
end
end
end
-- Validate the saved order
local valid = true;
if (#savedOrder == #defaultOrder) then
for i, category1 in next, defaultOrder do
local found = false;
for j, category2 in next, savedOrder do
if (category1 == category2) then
found = true;
break;
end
end
if (not found) then
valid = false;
break;
end
end
else
valid = false;
end
if (valid) then
order = savedOrder;
else
MCF_SetSettings(orderCVarName, "");
end
end
end
-- Initialize stat frames
table.wipe(StatCategoryFrames);
for index=1, #order do
local frame = _G["CharacterStatsPaneCategory"..index];
assert(frame);
tinsert(StatCategoryFrames, frame);
frame.Category = order[index];
frame:Show();
-- Expand or collapse
local categoryInfo = MCF_PAPERDOLL_STATCATEGORIES[frame.Category];
if (categoryInfo and collapsedCVarName and MCF_GetSettings(collapsedCVarName, categoryInfo.id)) then
MCF_PaperDollFrame_CollapseStatCategory(frame);
else
MCF_PaperDollFrame_ExpandStatCategory(frame);
end
end
-- Hide unused stat frames
local index = #order+1;
while(_G["CharacterStatsPaneCategory"..index]) do
_G["CharacterStatsPaneCategory"..index]:Hide();
_G["CharacterStatsPaneCategory"..index].Category = nil;
index = index + 1;
end
-- Set up stats data
CharacterStatsPane.defaultOrder = defaultOrder;
CharacterStatsPane.orderCVarName = orderCVarName;
CharacterStatsPane.collapsedCVarName = collapsedCVarName;
CharacterStatsPane.unit = unit;
-- Update
MCF_PaperDoll_UpdateCategoryPositions();
MCF_PaperDollFrame_UpdateStats();
end
function MCF_PaperDoll_FindCategoryById(id)
for categoryName, category in pairs(MCF_PAPERDOLL_STATCATEGORIES) do
if (category.id == id) then
return categoryName;
end
end
return nil;
end
function MCF_PaperDollFrame_UpdateStatCategory(categoryFrame)
if (not categoryFrame.Category) then
categoryFrame:Hide();
return;
end
local categoryInfo = MCF_PAPERDOLL_STATCATEGORIES[categoryFrame.Category];
categoryFrame.NameText:SetText(_G["STAT_CATEGORY_"..categoryFrame.Category]);
if (categoryFrame.collapsed) then
return;
end
local stat;
local totalHeight = categoryFrame.NameText:GetHeight() + 10;
local numVisible = 0;
if (categoryInfo) then
local prevStatFrame = nil;
for index, stat in next, categoryInfo.stats do
local statInfo = MCF_PAPERDOLL_STATINFO[stat];
if (statInfo) then
local statFrame = _G[categoryFrame:GetName().."Stat"..numVisible+1];
if (not statFrame) then
statFrame = CreateFrame("FRAME", categoryFrame:GetName().."Stat"..numVisible+1, categoryFrame, "MCF-StatFrameTemplate");
if (prevStatFrame) then
statFrame:SetPoint("TOPLEFT", prevStatFrame, "BOTTOMLEFT", 0, 0);
statFrame:SetPoint("TOPRIGHT", prevStatFrame, "BOTTOMRIGHT", 0, 0);
end
end
statFrame:Show();
-- Reset tooltip script in case it's been changed
statFrame:SetScript("OnEnter", MCF_PaperDollStatTooltip);
statFrame.tooltip = nil;
statFrame.tooltip2 = nil;
statFrame.UpdateTooltip = nil;
statFrame:SetScript("OnUpdate", nil);
statInfo.updateFunc(statFrame, CharacterStatsPane.unit);
if (statFrame:IsShown()) then
numVisible = numVisible+1;
totalHeight = totalHeight + statFrame:GetHeight();
prevStatFrame = statFrame;
-- Update Tooltip
if (GameTooltip:GetOwner() == statFrame) then
statFrame.changed = true;
statFrame:GetScript("OnEnter")(statFrame);
end
end
end
end
end
local i;
for index=1, numVisible do
if (index%2 == 0) then
local statFrame = _G[categoryFrame:GetName().."Stat"..index];
if (not statFrame.Bg) then
statFrame.Bg = statFrame:CreateTexture(statFrame:GetName().."Bg", "BACKGROUND");
statFrame.Bg:SetPoint("LEFT", categoryFrame, "LEFT", 1, 0);
statFrame.Bg:SetPoint("RIGHT", categoryFrame, "RIGHT", 0, 0);
statFrame.Bg:SetPoint("TOP");
statFrame.Bg:SetPoint("BOTTOM");
statFrame.Bg:SetColorTexture(STRIPE_COLOR.r, STRIPE_COLOR.g, STRIPE_COLOR.b);
statFrame.Bg:SetAlpha(0.1);
end
end
end
-- Hide all other stats
local index = numVisible + 1;
while (_G[categoryFrame:GetName().."Stat"..index]) do
_G[categoryFrame:GetName().."Stat"..index]:Hide();
index = index + 1;
end
-- Hack to fix category frames that only have 1 item in them
if (totalHeight < 44) then
categoryFrame.BgBottom:SetHeight(totalHeight - 2);
else
categoryFrame.BgBottom:SetHeight(46);
end
categoryFrame:SetHeight(totalHeight);
end
function MCF_PaperDollFrame_UpdateStats()
local index = 1;
while(_G["CharacterStatsPaneCategory"..index]) do
MCF_PaperDollFrame_UpdateStatCategory(_G["CharacterStatsPaneCategory"..index]);
index = index + 1;
end
MCF_PaperDollFrame_UpdateStatScrollChildHeight();
end
function MCF_PaperDollFrame_UpdateStatScrollChildHeight()
local index = 1;
local totalHeight = 0;
while(_G["CharacterStatsPaneCategory"..index]) do
if (_G["CharacterStatsPaneCategory"..index]:IsShown()) then
totalHeight = totalHeight + _G["CharacterStatsPaneCategory"..index]:GetHeight() + STATCATEGORY_PADDING;
end
index = index + 1;
end
CharacterStatsPaneScrollChild:SetHeight(totalHeight+10-(CharacterStatsPane.initialOffsetY or 0));
end
function MCF_PaperDollFrame_SetLabelAndText(statFrame, label, text, isPercentage)
_G[statFrame:GetName().."Label"]:SetText(format(STAT_FORMAT, label));
if ( isPercentage ) then
text = format("%.2F%%", text);
end
_G[statFrame:GetName().."StatText"]:SetText(text);
end
function MCF_PaperDollStatTooltip(self)
if (MOVING_STAT_CATEGORY ~= nil) then return; end
if ( not self.tooltip ) then
return;
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(self.tooltip);
if ( self.tooltip2 ) then
GameTooltip:AddLine(self.tooltip2, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1);
end
GameTooltip:Show();
end
function MCF_PaperDoll_SaveStatCategoryOrder()
if (not CharacterStatsPane.orderCVarName) then
return;
end
-- Check if the current order matches the default order
if (CharacterStatsPane.defaultOrder and #CharacterStatsPane.defaultOrder == #StatCategoryFrames) then
local same = true;
for index=1, #StatCategoryFrames do
if (StatCategoryFrames[index].Category ~= CharacterStatsPane.defaultOrder[index]) then
same = false;
break;
end
end
if (same) then
MCF_SetSettings(CharacterStatsPane.orderCVarName, "");
return;
end
end
local cvarString = "";
for index=1, #StatCategoryFrames do
if (index ~= #StatCategoryFrames) then
cvarString = cvarString..MCF_PAPERDOLL_STATCATEGORIES[StatCategoryFrames[index].Category].id..",";
else
cvarString = cvarString..MCF_PAPERDOLL_STATCATEGORIES[StatCategoryFrames[index].Category].id;
end
end
MCF_SetSettings(CharacterStatsPane.orderCVarName, cvarString);
end
function MCF_PaperDoll_UpdateCategoryPositions()
local prevFrame = nil;
for index = 1, #StatCategoryFrames do
local frame = StatCategoryFrames[index];
frame:ClearAllPoints();
end
for index = 1, #StatCategoryFrames do
local frame = StatCategoryFrames[index];
-- Indent the one we are currently dragging
local xOffset = 0;
if (frame == MOVING_STAT_CATEGORY) then
xOffset = STATCATEGORY_MOVING_INDENT;
elseif (prevFrame and prevFrame == MOVING_STAT_CATEGORY) then
xOffset = -STATCATEGORY_MOVING_INDENT;
end
if (prevFrame) then
frame:SetPoint("TOPLEFT", prevFrame, "BOTTOMLEFT", 0+xOffset, -STATCATEGORY_PADDING);
else
frame:SetPoint("TOPLEFT", 1+xOffset, -STATCATEGORY_PADDING+(CharacterStatsPane.initialOffsetY or 0));
end
prevFrame = frame;
end
end
function MCF_PaperDoll_MoveCategoryUp(self)
for index = 2, #StatCategoryFrames do
if (StatCategoryFrames[index] == self) then
tremove(StatCategoryFrames, index);
tinsert(StatCategoryFrames, index-1, self);
break;
end
end
MCF_PaperDoll_UpdateCategoryPositions();
MCF_PaperDoll_SaveStatCategoryOrder();
end
function MCF_PaperDoll_MoveCategoryDown(self)
for index = 1, #StatCategoryFrames-1 do
if (StatCategoryFrames[index] == self) then
tremove(StatCategoryFrames, index);
tinsert(StatCategoryFrames, index+1, self);
break;
end
end
MCF_PaperDoll_UpdateCategoryPositions();
MCF_PaperDoll_SaveStatCategoryOrder();
end
function MCF_PaperDollStatCategory_OnDragUpdate(self)
local _, cursorY = GetCursorPosition();
cursorY = cursorY*GetScreenHeightScale();
local myIndex = nil;
local insertIndex = nil;
local closestPos;
-- Find position that will put the dragged frame closest to the cursor
for index=1, #StatCategoryFrames+1 do -- +1 is to check the very last position at the bottom
if (StatCategoryFrames[index] == self) then
myIndex = index;
end
local frameY;
if (index <= #StatCategoryFrames) then
frameY = StatCategoryFrames[index]:GetTop();
else
frameY = StatCategoryFrames[#StatCategoryFrames]:GetBottom();
end
frameY = frameY - 8; -- compensate for height of the toolbar area
if (myIndex and index > myIndex) then
-- Remove height of the dragged frame, since it's going to be moved out of it's current position
frameY = frameY + self:GetHeight();
end
if (not closestPos or abs(cursorY - frameY)<closestPos) then
insertIndex = index;
closestPos = abs(cursorY-frameY);
end
end
if (insertIndex > myIndex) then
insertIndex = insertIndex - 1;
end
if ( myIndex ~= insertIndex) then
tremove(StatCategoryFrames, myIndex);
tinsert(StatCategoryFrames, insertIndex, self);
MCF_PaperDoll_UpdateCategoryPositions();
end
end
function MCF_PaperDollStatCategory_OnDragStart(self)
MOVING_STAT_CATEGORY = self;
MCF_PaperDoll_UpdateCategoryPositions();
GameTooltip:Hide();
self:SetScript("OnUpdate", MCF_PaperDollStatCategory_OnDragUpdate);
local i;
local frame;
for i, frame in next, StatCategoryFrames do
if (frame ~= self) then
frame:SetAlpha(0.6);
end
end
end
function MCF_PaperDollStatCategory_OnDragStop(self)
MOVING_STAT_CATEGORY = nil;
MCF_PaperDoll_UpdateCategoryPositions();
self:SetScript("OnUpdate", nil);
local i;
local frame;
for i, frame in next, StatCategoryFrames do
if (frame ~= self) then
frame:SetAlpha(1);
end
end
MCF_PaperDoll_SaveStatCategoryOrder();
end
function MCF_ColorPaperDollStat(base, posBuff, negBuff)
local stat;
local effective = max(0,base + posBuff + negBuff);
if ( ( posBuff == 0 ) and ( negBuff == 0 ) ) then
stat = effective;
else
-- if there is a negative buff then show the main number in red, even if there are
-- positive buffs. Otherwise show the number in green
if ( negBuff < 0 ) then
stat = RED_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE;
else
stat = GREEN_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE;
end
end
return stat;
end
function MCF_PaperDollFormatStat(name, base, posBuff, negBuff, frame, textString, result)
local effective = max(0,base + posBuff + negBuff);
local text = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT,name).." "..effective;
if ( ( posBuff == 0 ) and ( negBuff == 0 ) ) then
text = text..FONT_COLOR_CODE_CLOSE;
if (not result) then
textString:SetText(effective);
end
else
if ( posBuff > 0 or negBuff < 0 ) then
text = text.." ("..base..FONT_COLOR_CODE_CLOSE;
end
if ( posBuff > 0 ) then
text = text..FONT_COLOR_CODE_CLOSE..GREEN_FONT_COLOR_CODE.."+"..posBuff..FONT_COLOR_CODE_CLOSE;
end
if ( negBuff < 0 ) then
text = text..RED_FONT_COLOR_CODE.." "..negBuff..FONT_COLOR_CODE_CLOSE;
end
if ( posBuff > 0 or negBuff < 0 ) then
text = text..HIGHLIGHT_FONT_COLOR_CODE..")"..FONT_COLOR_CODE_CLOSE;
end
-- if there is a negative buff then show the main number in red, even if there are
-- positive buffs. Otherwise show the number in green
if ( negBuff < 0 ) then
if (not result) then
textString:SetText(RED_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE);
else
effective = RED_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE;
end
else
if (not result) then
textString:SetText(GREEN_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE);
else
effective = GREEN_FONT_COLOR_CODE..effective..FONT_COLOR_CODE_CLOSE;
end
end
end
if (not result) then
frame.tooltip = text;
else
return effective, text;
end
end
function MCF_ComputePetBonus(stat, value)
local temp, unitClass = UnitClass("player");
unitClass = strupper(unitClass);
if( unitClass == "WARLOCK" ) then
if( WARLOCK_PET_BONUS[stat] ) then
return value * WARLOCK_PET_BONUS[stat];
else
return 0;
end
elseif( unitClass == "HUNTER" ) then
if( HUNTER_PET_BONUS[stat] ) then
return value * HUNTER_PET_BONUS[stat];
else
return 0;
end
end
return 0;
end
function MCF_CalculateAverageItemLevel()
local avgItemLevel, sumItemLevel, itemCount = 0, 0, 0;
for i=1, 18 do
if ( (i ~= 4) and GetInventoryItemID("player", i) ) then
local id, _ = GetInventoryItemID("player", i);
local ilvl = GetDetailedItemLevelInfo(id) or 0; -- Attempt to fix error when item isn't loaded at first open
sumItemLevel = sumItemLevel + ilvl;
itemCount = itemCount + 1;
end
end
if itemCount ~= 0 then
avgItemLevel = sumItemLevel/itemCount;
end
return avgItemLevel;
end
-- Check if player has specific talents. Returns dict
-- /run for i=1, GetNumTalents(1) do local name = GetTalentInfo(1, i); print(i, name); end
function MCF_CheckHitTalents(class, hit_type)
if ( not MCF_TALENTS_FOR_HIT[class] ) then
return;
end
local result = {};
for tableIndex, talent in pairs(MCF_TALENTS_FOR_HIT[class]) do
local requiredHitType = false;
if (talent.hit_types == "all") then
requiredHitType = true;
else
for _, v in pairs(talent.hit_types) do
if (v == hit_type) then
requiredHitType = true;
end
end
end
if (requiredHitType) then
local _, _, _, _, rank = GetTalentInfo(talent.tab, talent.index);
if (rank > 0) then
local schools = {};
if ( not talent.all_schools ) then
for i=3, #talent.schools do
if talent.schools[i] then
table.insert(schools, i-1);
end
end
else
schools = nil;
end
local plusHit = rank * talent.increment;
table.insert(result, {all_schools = talent.all_schools,
schools = schools,
plusHit = plusHit,
tab = talent.tab,
index = talent.index,
icon = talent.icon});
end
end
end
if (#result ~= 0) then
return result
end
end
----------------------------------------------------------------------------------
-------------------------------- STATS ON UPDATE ---------------------------------
----------------------------------------------------------------------------------
function MCF_MovementSpeed_OnUpdate(statFrame, elapsedTime)
local unit = statFrame.unit;
local _, runSpeed, flightSpeed, swimSpeed = GetUnitSpeed(unit);
runSpeed = runSpeed/BASE_MOVEMENT_SPEED*100;
flightSpeed = flightSpeed/BASE_MOVEMENT_SPEED*100;
swimSpeed = swimSpeed/BASE_MOVEMENT_SPEED*100;
-- Pets seem to always actually use run speed
if (unit == "pet") then
swimSpeed = runSpeed;
end
-- Determine whether to display running, flying, or swimming speed
local speed = runSpeed;
local swimming = IsSwimming(unit);
if (swimming) then
speed = swimSpeed;
elseif (IsFlying(unit)) then
speed = flightSpeed;
end
-- Hack so that your speed doesn't appear to change when jumping out of the water
if (IsFalling(unit)) then
if (statFrame.wasSwimming) then
speed = swimSpeed;
end
else
statFrame.wasSwimming = swimming;
end
statFrame.Value:SetFormattedText("%d%%", speed+0.5);
statFrame.speed = speed;
statFrame.runSpeed = runSpeed;
statFrame.flightSpeed = flightSpeed;
statFrame.swimSpeed = swimSpeed;
end
----------------------------------------------------------------------------------
------------------------------- GET STAT FUNCTIONS -------------------------------
----------------------------------------------------------------------------------
function MCF_GetMeleeMissChance(levelOffset, talentHit, special)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = MCF_BASE_MISS_CHANCE_PHYSICAL[levelOffset];
chance = chance - GetCombatRatingBonus(CR_HIT_MELEE) - talentHit;--[[ - GetHitModifier(); ]] --MCFFIX this function gives another result
if (IsDualWielding() and not special) then
chance = chance + MCF_DUAL_WIELD_HIT_PENALTY;
end
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
return chance;
end
function MCF_GetRangedMissChance(levelOffset, talentHit, special)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = MCF_BASE_MISS_CHANCE_PHYSICAL[levelOffset];
chance = chance - GetCombatRatingBonus(CR_HIT_RANGED) - talentHit;--[[ - GetHitModifier(); ]] --MCFFIX this function gives another result
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
return chance;
end
function MCF_GetSpellMissChance(levelOffset, talentHit, special)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = MCF_BASE_MISS_CHANCE_SPELL[levelOffset];
chance = chance - GetCombatRatingBonus(CR_HIT_SPELL) - talentHit;--[[ - GetSpellHitModifier(); ]] --MCFFIX this function gives another result
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
return chance;
end
function MCF_PaperDollFrame_GetArmorReduction(armor, attackerLevel)
local levelModifier = attackerLevel;
if ( levelModifier > 80 ) then
levelModifier = levelModifier + (4.5 * (levelModifier-59)) + (20 * (levelModifier - 80));
elseif ( 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 temp*100;
end
function MCF_GetCritHitTakenChance(levelOffset, special)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = 5 + levelOffset * 0.04 * 5; -- Base crit hit taken chance (5, 5.2, 5.4, 5.6)
local defSkill, currentModifier = UnitDefense("player");
local currentDefTotal = defSkill + currentModifier;
local defDifference = currentDefTotal - UnitLevel("player") * 5;
local critChanceFromResilience = GetCombatRatingBonus(CR_RESILIENCE_CRIT_TAKEN);
local _, class = UnitClass("player");
local specialTalentPercent = 0;
if (class == "DRUID") then
local _,_,_,_, rank = GetTalentInfo(2, 18);
specialTalentPercent = rank * 2;
end
if (class == "WARLOCK") then
local _,_,_,_, rank = GetTalentInfo(2, 20);
specialTalentPercent = rank;
end
chance = chance - defDifference * 0.04 - critChanceFromResilience - specialTalentPercent;
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
return chance;
end
function MCF_GetEnemyDodgeChance(levelOffset)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = MCF_BASE_ENEMY_DODGE_CHANCE[levelOffset];
local offhandChance = MCF_BASE_ENEMY_DODGE_CHANCE[levelOffset];
local expertisePct, offhandExpertisePct = GetExpertisePercent();
chance = chance - expertisePct;
offhandChance = offhandChance - offhandExpertisePct;
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
if (offhandChance < 0) then
offhandChance = 0;
elseif (offhandChance > 100) then
offhandChance = 100;
end
return chance, offhandChance;
end
function MCF_GetEnemyParryChance(levelOffset)
if (levelOffset < 0 or levelOffset > 3) then
return 0;
end
local chance = MCF_BASE_ENEMY_PARRY_CHANCE[levelOffset];
local offhandChance = MCF_BASE_ENEMY_PARRY_CHANCE[levelOffset];
local expertisePct, offhandExpertisePct = GetExpertisePercent();
chance = chance - expertisePct;
offhandChance = offhandChance - offhandExpertisePct;
if (chance < 0) then
chance = 0;
elseif (chance > 100) then
chance = 100;
end
if (offhandChance < 0) then
offhandChance = 0;
elseif (offhandChance > 100) then
offhandChance = 100;
end
return chance, offhandChance;
end
local ITEM_SLOTS_WITH_DURABILITY = {
[1] = _G.INVTYPE_HEAD,
[3] = _G.INVTYPE_SHOULDER,
[5] = _G.INVTYPE_CHEST,
[6] = _G.INVTYPE_WAIST,
[7] = _G.INVTYPE_LEGS,
[8] = _G.INVTYPE_FEET,
[9] = _G.INVTYPE_WRIST,
[10] = _G.INVTYPE_HAND,
[16] = _G.INVTYPE_WEAPONMAINHAND,
[17] = _G.INVTYPE_WEAPONOFFHAND,
[18] = _G.INVTYPE_RANGED,
};
function MCF_GetTotalRepairCostAndDurability()
local repair_cost_total = 0;
local current_durability = 0;
local total_durability = 0;
for slot_id in pairs(ITEM_SLOTS_WITH_DURABILITY) do
MCF_ScanTooltip:ClearLines();
local repair_item_cost = select(3, MCF_ScanTooltip:SetInventoryItem("player", slot_id));
repair_cost_total = repair_cost_total + (repair_item_cost or 0);
local current_item_durability, total_item_durability = GetInventoryItemDurability(slot_id);
current_durability = current_durability + (current_item_durability or 0);
total_durability = total_durability + (total_item_durability or 0);
end
local durability_percent = 0;
if total_durability ~= 0 then
durability_percent = current_durability / total_durability * 100;
end
return repair_cost_total, durability_percent;
end
----------------------------------------------------------------------------------
------------------------------- SET STAT FUNCTIONS -------------------------------
----------------------------------------------------------------------------------
-- GENERAL
function MCF_PaperDollFrame_SetHealth(statFrame, unit)
if (not unit) then
unit = "player";
end
local health = UnitHealthMax(unit);
MCF_PaperDollFrame_SetLabelAndText(statFrame, HEALTH, health, false);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, HEALTH).." "..health..FONT_COLOR_CODE_CLOSE;
if (unit == "player") then
statFrame.tooltip2 = STAT_HEALTH_TOOLTIP;
elseif (unit == "pet") then
statFrame.tooltip2 = STAT_HEALTH_PET_TOOLTIP;
end
statFrame:Show();
end
function MCF_PaperDollFrame_SetPower(statFrame, unit)
if (not unit) then
unit = "player";
end
local powerType, powerToken = UnitPowerType(unit);
local power = UnitPowerMax(unit) or 0;
if (powerToken and _G[powerToken]) then
MCF_PaperDollFrame_SetLabelAndText(statFrame, _G[powerToken], power, false);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, _G[powerToken]).." "..power..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = _G["STAT_"..powerToken.."_TOOLTIP"];
statFrame:Show();
else
statFrame:Hide();
end
end
function MCF_PaperDollFrame_SetDruidMana(statFrame, unit)
if (not unit) then
unit = "player";
end
local _, class = UnitClass(unit);
if (class ~= "DRUID") then
statFrame:Hide();
return;
end
local powerType, powerToken = UnitPowerType(unit);
if (powerToken == "MANA") then
statFrame:Hide();
return;
end
local power = UnitPowerMax(unit, 0);
MCF_PaperDollFrame_SetLabelAndText(statFrame, MANA, power, false);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, MANA).." "..power..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = _G["STAT_MANA_TOOLTIP"];
statFrame:Show();
end
function MCF_PaperDollFrame_SetItemLevel(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
_G[statFrame:GetName().."Label"]:SetText(format(STAT_FORMAT, L["MCF_STAT_AVERAGE_ITEM_LEVEL"]));
local text = _G[statFrame:GetName().."StatText"];
local avgItemLevel, avgItemLevelEquipped = GetAverageItemLevel();
avgItemLevel = floor(avgItemLevel);
avgItemLevelEquipped = floor(avgItemLevelEquipped);
--[[ text:SetText(avgItemLevelEquipped .. " / " .. avgItemLevel);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, L["MCF_STAT_AVERAGE_ITEM_LEVEL"]).." "..avgItemLevel;
if (avgItemLevelEquipped ~= avgItemLevel) then
statFrame.tooltip = statFrame.tooltip .. " " .. format(L["MCF_STAT_AVERAGE_ITEM_LEVEL_EQUIPPED"], avgItemLevelEquipped);
end ]]
--local avgItemLevelEquipped = MCF_CalculateAverageItemLevel();
if avgItemLevelEquipped == 0 then
statFrame:Hide();
return;
end
--avgItemLevelEquipped = floor(avgItemLevelEquipped);
if ( IsAddOnLoaded("TacoTip") and MCF_GetSettings("TT_IntegrationEnabled") ) then
local personalGS, _ = TT_GS:GetScore("player");
local textType = MCF_GetSettings("TT_IntegrationType");
local colorGS = "";
if ( MCF_GetSettings("TT_IntegrationColorEnabled") ) then
local r, g, b, _ = TT_GS:GetQuality(personalGS);
if ( personalGS == 0 ) then
r, g, b = 0.55, 0.55, 0.55;
end
local tempColor = CreateColor(r, g, b);
colorGS = tempColor:GenerateHexColorMarkup();
end
if ( textType == 2 ) then
text:SetText(avgItemLevelEquipped .. " (" .. (colorGS..(personalGS or NOT_APPLICABLE)..FONT_COLOR_CODE_CLOSE) .. ")");
elseif ( textType == 3 ) then
_G[statFrame:GetName().."Label"]:SetText(format(STAT_FORMAT, L["MCF_STAT_GEARSCORE_LABEL"]));
text:SetText(colorGS..(personalGS or NOT_APPLICABLE)..FONT_COLOR_CODE_CLOSE);
else
text:SetText(avgItemLevelEquipped .. " / " .. (colorGS..(personalGS or NOT_APPLICABLE)..FONT_COLOR_CODE_CLOSE));
end
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, L["MCF_STAT_AVERAGE_ITEM_LEVEL"]).." "..avgItemLevelEquipped;
statFrame.tooltip = statFrame.tooltip .. " " .. format(L["MCF_STAT_GEARSCORE"], (personalGS or NOT_APPLICABLE));
else
text:SetText(avgItemLevelEquipped);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, L["MCF_STAT_AVERAGE_ITEM_LEVEL"]).." "..avgItemLevelEquipped;
end
statFrame.tooltip = statFrame.tooltip .. FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = STAT_AVERAGE_ITEM_LEVEL_TOOLTIP;
end
function MCF_PaperDollFrame_SetMovementSpeed(statFrame, unit)
statFrame.Label:SetText(format(STAT_FORMAT, L["MCF_STAT_MOVEMENT_SPEED"]));
statFrame.wasSwimming = nil;
statFrame.unit = unit;
MCF_MovementSpeed_OnUpdate(statFrame);
statFrame:SetScript("OnEnter", MCF_MovementSpeed_OnEnter);
statFrame:SetScript("OnUpdate", MCF_MovementSpeed_OnUpdate);
end
function MCF_PaperDollFrame_SetRepairCost(statFrame, unit)
if MCF_GetSettings("showRepairCost") == false then
statFrame:Hide();
return;
end
if (not unit) then
unit = "player";
end
local repairCost, durability_percent = MCF_GetTotalRepairCostAndDurability();
local repairCostShort = repairCost;
if repairCost == 0 then
statFrame:Hide();
return;
elseif repairCost > 999999 then
repairCostShort = floor((repairCost + 500000) / 1000000) * 1000000;
elseif repairCost > 9999 then
repairCostShort = floor((repairCost + 5000) / 10000) * 10000;
elseif repairCost > 99 then
repairCostShort = floor((repairCost + 50) / 100) * 100;
end
local repairCostString = GetMoneyString(repairCostShort);
local REPAIR_COST_STR = gsub(REPAIR_COST, ":", "");
MCF_PaperDollFrame_SetLabelAndText(statFrame, REPAIR_COST_STR, repairCostString, false);
statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, REPAIR_COST_STR).." "..GetMoneyString(repairCost)..FONT_COLOR_CODE_CLOSE;
statFrame.tooltip2 = L["MCF_STAT_REPAIR"].."\n"..DURABILITY..": "..floor(durability_percent).."%";
statFrame:Show();
end
-- ATTRIBUTES
-- NEEDS INTELLECT REWORK
function MCF_PaperDollFrame_SetStat(statFrame, unit, statIndex)
local label = _G[statFrame:GetName().."Label"];
local text = _G[statFrame:GetName().."StatText"];
local stat;
local effectiveStat;
local posBuff;
local negBuff;
stat, effectiveStat, posBuff, negBuff = UnitStat(unit, statIndex);
local statName = _G["SPELL_STAT"..statIndex.."_NAME"];
label:SetText(format(STAT_FORMAT, statName));
-- Set the tooltip text
local tooltipText = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, statName).." ";
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
statFrame.tooltip2 = L["MCF_DEFAULT_STAT"..statIndex.."_TOOLTIP"];