-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMobInfo2.lua
2411 lines (2115 loc) · 79.5 KB
/
MobInfo2.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
--
-- MobInfo.lua
--
-- Main module of MobInfo-2 AddOn
miVersionNo = '1.0.0'
-- stub for now to return power
function UnitMana(unitId)
return UnitPower(unitId)
end
-- stub for now to return power max
function UnitManaMax(unitId)
return UnitPowerMax(unitId)
end
-- stub for now to return 0,0
function GetPlayerMapPosition(...)
return 0,0
end
--
-- MobInfo-2 is a World of Warcraft AddOn that provides you with useful
-- additional information about Mobs (ie. opponents/monsters). It adds
-- new information to the game's Tooltip when you hover with your mouse
-- over a mob. It also adds a numeric display of the Mobs health
-- and mana (current and max) to the Mob target frame.
--
-- MobInfo-2 is the continuation of the original "MobInfo" by Dizzarian,
-- combined with the original "MobHealth2" by Wyv. Both Dizzarian and
-- Wyv sadly no longer play WoW and stopped maintaining their AddOns.
-- I have "inhereted" MobInfo from Dizzarian and MobHealth-2 from Wyv
-- and now continue to update and improve the united result.
--
-- library pointers
local libPeriodicTable = LibStub("LibPeriodicTable-3.1")
-- metadata
local ADDON_NAME = ...
local ADDON_TITLE = GetAddOnMetadata(ADDON_NAME, "Title")
local ADDON_VERSION = GetAddOnMetadata(ADDON_NAME, "Version")
local ADDON_AUTHOR = GetAddOnMetadata(ADDON_NAME, "Author")
local ADDON_NOTES = GetAddOnMetadata(ADDON_NAME, "Notes")
-- debugging
local GREEN = "|cFF33FF99"
local debugging = true
local _, fh = DEFAULT_CHAT_FRAME:GetFont()
local fontHeight = math.ceil(fh) -- avoid bizarre -ve numbers
local icon = "\124TInterface\\Addons\\" .. ADDON_NAME .. "\\icon:" .. fontHeight .. "\124t"
local HEADER = string.format("%s%s%s|r : ", GREEN, icon, ADDON_NAME)
function printf(...)
if (DEFAULT_CHAT_FRAME) then
DEFAULT_CHAT_FRAME:AddMessage(HEADER .. string.format(...))
end
end
function printfd(...) if (debugging) then printf("DEBUG: ".. string.format(...)) end end
function serialize(...) return DataDumper(...) end
-- global vars
MI2_Debug = 0 -- 0=no debug info, 1=activate debug info
MI2_DebugItems = 0 -- 0=no item debug info, 1=show item ID and item value in tooltip
MI2_DebugEvents = 0 -- 0=no item event info, 1=show decoded events, 2=show all incoming events
MI2_DB_VERSION = 9
MI2_DB_SV = 2
MI2_IMPORT_DB_VERSION = 7
local MI2_RecentLoots, MI2_MobCache, MI2_MobCacheIdx, MI2_XRefItemTable
local MI2_NewCorpseIdx = 0
local MI2_CurrentCorpseIndex = nil
local MI2_RecentLoots = {}
local MI2_SpellToSchool = {}
local MI2_CACHE_SIZE = 30
local GetSpellName = GetSpellName or GetSpellBookItemName
local GetDifficultyColor = GetDifficultyColor or GetQuestDifficultyColor
-- PTR code
local _, _, _, tocVersion = GetBuildInfo()
local miClamContents = {
["4655"] = "Giant Clam Meat",
["5503"] = "Clam Meat",
["5504"] = "Tangy Clam Meat",
["7974"] = "Zesty Clam Meat",
["15924"] = "Soft-shelled Clam Meat",
["24477"] = "Jaggal Clam Meat",
["36782"] = "Succulent Clam Meat",
["62791"] = "Blood Shrimp",
}
local MI2_CollapseList = {
[2725]=2725, [2728]=2725, [2730]=2725, [2732]=2725,
[2734]=2725, [2735]=2725, [2738]=2725, [2740]=2725, [2742]=2725,
[2745]=2725, [2748]=2725, [2749]=2725, [2750]=2725, [2751]=2725 }
-- global MobInfo color constansts
MI_Red = "|cffff1010"
MI_Green = "|cff00ff00"
MI_Blue = "|cff0000ff"
MI_White = "|cffffffff"
MI_Gray = "|cff888888"
MI_Yellow = "|cffffff00"
MI_Cyan = "|cff00ffff"
MI_Orange = "|cffff7000"
MI_Gold = "|cffffcc00"
MI_Mageta = "|cffe040ff"
MI_ItemBlue = "|cff2060ff"
MI_LightBlue = "|cff00e0ff"
MI_LightGreen = "|cff60ff60"
MI_LightRed = "|cffff5050"
MI_SubWhite = "|cffbbbbbb"
MI2_QualityColor = { MI_Gray, MI_White, MI_Green, MI_ItemBlue, MI_Mageta, MI_Orange, MI_Red }
-----------------------------------------------------------------------------
-- MI2_GetMobData( mobName, mobLevel [, unitId] )
--
-- Get and return all the data that MobInfo knows about a given mob.
-- This is an externally available interface function that can be
-- called by other AddOns to access MobInfo data. It should be fast,
-- efficient, and easy to use
--
-- The data describing a Mob is returned in table form as described below.
--
-- To identify the mob you must supply its name and level. You can
-- optionally supply a "unitId" to get additional info:
-- mobName : name of mob, eg. "Forest Lurker"
-- mobLevel : mob level as integer number
-- unitId : optional WoW unit identification, should be either
-- "target" or "mouseover"
--
-- Examples:
-- A. mobData = MI2_GetMobData( "Forest Lurker", 10 )
-- B. mobData = MI2_GetMobData( "Forest Lurker", 10, "target" )
--
-- Return Value:
-- The return value is a LUA table with one table entry for each value that
-- MobInfo can know about a Mob. Note that table entries exist ONLY if the
-- corresponding value has actually been collected for the given Mob.
-- Unrecorded values do NOT exist in the table and thus evaluate to a NIL
-- expression.
--
-- Values you can get without "unitId" (as per Example A above):
-- mobData.healthMax : health maximum
-- mobData.xp : experience value
-- mobData.kills : number of times current player has killed this mob
-- mobData.minDamage : minimum damage done by mob
-- mobData.maxDamage : maximum damage done by mob
-- mobData.dps : dps of Mon against current player
-- mobData.loots : number of times this mob has been looted
-- mobData.emptyLoots : number of times this mob gave empty loot
-- mobData.clothCount : number of times this mob gave cloth loot
-- mobData.copper : total money loot of this mob as copper amount
-- mobData.itemValue : total item value loot of this mob as copper amount
-- mobData.mobType : mob type for special mobs: 1=normal, 2=rare/elite, 3=boss
-- mobData.r1 : number of rarity 1 loot items (grey)
-- mobData.r2 : number of rarity 2 loot items (white)
-- mobData.r3 : number of rarity 3 loot items (green)
-- mobData.r4 : number of rarity 4 loot items (blue)
-- mobData.r5 : number of rarity 5 loot items (purple)
-- mobData.itemList : table that lists all recorded items looted from this mob
-- table entry index gives WoW item ID,
-- table entry value gives item amount
--
-- Additional values you will get with "unitId" (as per Example B above):
-- mobData.class : class of mob as localized text
-- mobData.healthCur : current health of given unit
-- mobData.manaCur : current mana of given unit
-- mobData.manaMax : maximum mana for given unit
-- mobData.GUID : unique 16-character hex string to identify mob [Speedwaystar]
--
-- Code Example:
--
-- local mobData = MI2_GetMobData( "Forest Lurker", 10 )
--
-- if mobData.xp then
-- DEFAULT_CHAT_FRAME:AddMessage( "XP = "..mobData.xp )
-- end
--
-- if mobData.copper and mobData.loots then
-- local avgLoot = mobData.copper / mobData.loots
-- DEFAULT_CHAT_FRAME:AddMessage( "average loot = "..avgLoot )
-- end
--
function MI2_GetMobData( mobName, mobLevel, unitId )
if not mobName or not mobLevel then return end
local mobData = {}
local mobIndex = mobName..":"..mobLevel
-- decode unit specific mob data that is not recorded in mob database
if unitId then
MI2_GetUnitBasedMobData( mobIndex, mobData, unitId, mobLevel )
end
-- access Mob database and decode the data
local mobInfo = MobInfoDB[mobIndex]
if mobInfo then
MI2_GetMobDataFromMobInfo( mobInfo, mobData )
end
return mobData
end -- MI2_GetMobData()
-----------------------------------------------------------------------------
-- MI2_InitOptions()
--
-- initialize MobInfo configuration options
-- this takes into account new options that have been added to MobInfo
-- in the course of developement
--
function MI2_InitOptions()
-- defaults for all MobInfo config options
local MI2_OptDefaults = {
ShowHealth=1, ShowMana=0, ShowXp=1, ShowNo2lev=1, ShowKills=0, ShowLoots=1, ShowTotal=1,
ShowCoin=0, ShowIV=0, ShowEmpty=0, ShowLowHpAction=1, ShowCloth=1, ShowDamage=1,
ShowDps=1, ShowLocation=1, ShowQuality=1, ShowResists=1, ShowImmuns=1, ShowItems=1,
ShowClothSkin=1, MouseTooltip=1, SaveBasicInfo=1, KeypressMode = 0, SavePlayerHp = 0,
ShowMobInfo=1, ShowItemInfo=1, ShowTargetInfo=1, ShowMMButton=1, MMButtonPos=257,
TooltipMode=4, SmallFont=1, OtherTooltip=1, ShowLowHpAction=1, ShowItems=1,
ShowClothSkin=1, TargetFontSize=10, TargetHealth=1, TargetMana=1, HealthPercent=1,
ManaPercent=1, HealthPosX=-7, HealthPosY=11, ManaPosX=-7, ManaPosY=11, TargetFont=2,
CompactMode=1, SaveItems=1, SaveCharData=1, ItemsQuality=2, ItemTooltip=1,
ItemFilter="", ImportOnlyNew=1, SaveResist=1, ShowItemPrice = 0, CombinedMode = 0,
UseGameTT=0, HideAnchor=0, ShowIGrey=0, ShowIWhite=1, ShowIGreen=1, ShowIBlue=1, ShowIPurple=1 }
-- initialize MobInfoConfig
if not MobInfoConfig then
MobInfoConfig = { }
end
-- make the 2 column layout active by default
if MobInfoConfig.ShowBlankLines then MobInfoConfig.CompactMode = 1 end
if MobInfoConfig.MMButtonPos == 20 then MobInfoConfig.MMButtonPos = 356 end
-- config values that no longer exist
MobInfoConfig.OptStableMax = nil -- removed in 3.20
MobInfoConfig.DisableMobInfo = nil -- removed in 3.40
MobInfoConfig.ShowBlankLines = nil -- removed in 3.40
MobInfoConfig.ShowCombined = nil -- removed in 3.40
--if not MobInfoConfig.ShowCombined then MobInfoConfig.ShowCombined = 1 end
--MobInfoConfig.ShowCombined = 0
-- initial defaults for all config options
local idx, opt, name
for idx,def in pairs(MI2_OptDefaults) do
if not MobInfoConfig[idx] then
MobInfoConfig[idx] = def
end
end
end -- MI2_InitOptions()
-- MI2_GetMobDataFromMobInfo()
--
-- Extract all data describing a specific mob from a given mob database
-- record (called "mobInfo"). The mobInfo data is in a compressed format
-- that requires decoding to make it usable.
--
function MI2_GetMobDataFromMobInfo( mobInfo, mobData )
MI2_DecodeBasicMobData( mobInfo, mobData )
MI2_DecodeCharData( mobInfo, mobData, MI2_PlayerName )
MI2_DecodeQualityOverview( mobInfo, mobData )
MI2_DecodeMobLocation( mobInfo, mobData )
MI2_DecodeItemList( mobInfo, mobData )
MI2_DecodeResists( mobInfo, mobData )
end -- MI2_GetMobDataFromMobInfo()
-----------------------------------------------------------------------------
-- MI2_GetUnitBasedMobData()
--
-- Obtain and store all unit specific mob data.
--
function MI2_GetUnitBasedMobData( mobIndex, mobData, unitId )
-- get mobs PPP and calculate max health (can be done without unitId)
if not unitId then
mobData.healthText = "0/"..(mobData.healthMax or "???")
else
local mobPPP = MobHealth_PPP(mobIndex)
if mobPPP <= 0 then mobPPP = 1 end
mobData.healthMax = floor(mobPPP * 100 + 0.5)
-- obtain unit specific values if unitId is given
if UnitHealthMax(unitId) == 100 then
mobData.healthCur = floor(mobPPP * UnitHealth(unitId) + 0.5)
else
mobData.healthCur = UnitHealth(unitId)
end
-- why is the above necessary? just use values from the server
--mobData.healthMax = UnitHealthMax( unitId )
--mobData.healthCur = UnitHealth( unitId )
mobData.manaCur = UnitMana( unitId )
mobData.manaMax = UnitManaMax( unitId )
mobData.healthText = mobData.healthCur.."/"..mobData.healthMax
if mobData.manaMax > 0 then
mobData.manaText = mobData.manaCur.."/"..mobData.manaMax
end
local mobType = UnitClassification(unitId)
if mobType == "rare" then
mobData.mobType = 2
elseif mobType == "worldboss" then
mobData.mobType = 3
elseif mobType == "elite" then
mobData.mobType = 4
elseif mobType == "rareelite" then
mobData.mobType = 6
else
mobData.mobType = 1
end
-- globally unique identifier
mobData.GUID = UnitGUID(unitId)
end
end -- MI2_GetUnitBasedMobData()
-----------------------------------------------------------------------------
-- MI2_FetchMobData()
--
-- Internal function for accessing a mobData record
-- This function implements a caching mechanism for faster access
-- to database records. The cache stores the last 30 Mob records.
-- Data returned by "MI2_FetchMobData()" should NOT be modified because
-- modifications are written back into the main database file.
--
function MI2_FetchMobData( mobIndex, unit )
local mobData = MI2_MobCache[mobIndex]
if mobIndex and not mobData then
local mobInfo = MobInfoDB[mobIndex]
mobData = { mobType=1, resists={} }
if mobInfo then
MI2_GetMobDataFromMobInfo( mobInfo, mobData )
end
MI2_MobCache[mobIndex] = mobData
local oldMob = MI2_MobCache[MI2_MobCacheIdx]
if oldMob then
MI2_MobCache[oldMob] = nil
end
MI2_MobCache[MI2_MobCacheIdx] = mobIndex
MI2_MobCacheIdx = MI2_MobCacheIdx + 1
if MI2_MobCacheIdx > MI2_CACHE_SIZE then
MI2_MobCacheIdx = 1
end
end
if mobData then
MI2_GetUnitBasedMobData( mobIndex, mobData, unit )
end
return mobData
end -- MI2_FetchMobData()
-----------------------------------------------------------------------------
-- MI2_FetchCombinedMob()
--
-- handle combined Mob mode : try to find the other Mobs with same
-- name but differing level, add their data to the tooltip data
--
function MI2_FetchCombinedMob( mobName, mobLevel, unit )
local combined = {}
local minL, maxL = mobLevel, mobLevel
if MobInfoConfig.CombinedMode == 1 and mobLevel > 0 then
for level = mobLevel-4, mobLevel+4, 1 do
if level ~= mobLevel then
local mobIndex = mobName..":"..level
if MobInfoDB[mobIndex] then
local dataToCombine = MI2_FetchMobData( mobIndex )
MI2_AddTwoMobs( combined, dataToCombine )
minL = min( minL, level )
maxL = max( maxL, level )
end
end
end
end
local mobIndex = mobName..":"..mobLevel
local mobData = MI2_FetchMobData( mobName..":"..mobLevel )
MI2_AddTwoMobs( combined, mobData )
MI2_GetUnitBasedMobData( mobIndex, combined, unit )
combined.levelInfo = minL
if minL ~= maxL then
combined.levelInfo = minL.."-"..maxL
end
return combined
end
-----------------------------------------------------------------------------
-- MI2_DecodeBasicMobData()
--
-- Decode the basic mob data. This function is used by the public
-- "MI2_GetMobData()" and also by the Mob search routines.
--
function MI2_DecodeBasicMobData( mobInfo, mobData, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
-- decode mob basic info: loots, empty loots, experience, cloth count, money looted, item value looted, mob type
if mobInfo.bi then
local a,b,lt,el,cp,iv,cc,c,mt,sc = string.find( mobInfo.bi, "(%d*)/(%d*)/(%d*)/(%d*)/(%d*)/(%d*)/(%d*)/(%d*)")
a = tonumber(a) or 0
b = tonumber(b) or 0
mobData.loots = tonumber(lt) or 0
mobData.emptyLoots = tonumber(el) or 0
mobData.copper = tonumber(cp) or 0
mobData.itemValue = tonumber(iv) or 0
mobData.clothCount = tonumber(cc) or 0
c = tonumber(c) or 0
mobData.mobType = tonumber(mt) or 0
mobData.skinCount = tonumber(sc) or 0
--printf("bi: %s, loots %d, empty %d, copper %d, value %d, cloth %d, type %d, skins %d", mobInfo.bi, mobData.loots, mobData.emptyLoots, mobData.copper, mobData.itemValue, mobData.clothCount, mobData.mobType, mobData.skinCount)
end
if mobData.mobType and mobData.mobType > 10 then
mobData.lowHpAction = floor(mobData.mobType / 10)
mobData.mobType = mobData.mobType - mobData.lowHpAction * 10
end
end -- MI2_DecodeBasicMobData()
-----------------------------------------------------------------------------
-- MI2_DecodeMobLocation()
--
-- Decode mob location info, skip invalid location data
-- The location is encoded in the mob record entry "ml".
-- The decoded data is stored in the given "mobData" structure.
--
function MI2_DecodeMobLocation( mobInfo, mobData, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
if mobInfo.ml then
local a,b,x1,y1,x2,y2,c,z = string.find( mobInfo.ml, "(%d*)/(%d*)/(%d*)/(%d*)/(%d*)/(%d*)")
mobData.location = {}
mobData.location.x1 = tonumber(x1) or 0
mobData.location.y1 = tonumber(y1) or 0
mobData.location.x2 = tonumber(x2) or 0
mobData.location.y2 = tonumber(y2) or 0
mobData.location.c = tonumber(c) or 0
mobData.location.z = (tonumber(z) or 0)
if not mobData.location.x1 or not mobData.location.x2 or
not mobData.location.y1 or not mobData.location.y2 or
mobData.location.z == 0 then
mobData.location = nil
end
end
end -- MI2_DecodeMobLocation()
-----------------------------------------------------------------------------
-- MI2_DecodeQualityOverview()
--
-- Decode item quality data: loot count per item rarity category
-- The loot items quality overview is encoded in the mob record entry "qi".
-- The decoded data is stored in the given "mobData" structure.
--
function MI2_DecodeQualityOverview( mobInfo, mobData, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
if mobInfo.qi then
local a,b,r1,r2,r3,r4,r5 = string.find( mobInfo.qi, "(%d*)/(%d*)/(%d*)/(%d*)/(%d*)")
mobData.r1 = tonumber(r1) or 0
mobData.r2 = tonumber(r2) or 0
mobData.r3 = tonumber(r3) or 0
mobData.r4 = tonumber(r4) or 0
mobData.r5 = tonumber(r5) or 0
end
end -- MI2_DecodeQualityOverview
-----------------------------------------------------------------------------
-- MI2_DecodeCharData()
--
-- Decode char specific data: number of kills, min damage, max damage, dps, xp
-- Player specific data is encoded in mob record entries starting with
-- the lowercase letter "c" plus a player name index number, eg. "c7",
-- this is called the player ID code. The playerName parameter must give
-- the player ID code for the player data to decode.
-- The decoded data is stored in the given "mobData" structure.
-----------------------------------------------------------------------------
function MI2_DecodeCharData( mobInfo, mobData, playerName, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
--printf("MI2_DecodeCharData '%s' for playerName '%s'",mobInfo[playerName] or 'nil', playerName or 'nil')
if mobInfo[playerName] then
local a,b,kl,mind,maxd,dps,xp = string.find( mobInfo[playerName], "(%d*)/(%d*)/(%d*)/(%d*)/*(%d*)")
mobData.kills = tonumber(kl) or 0
mobData.minDamage = tonumber(mind) or 0
mobData.maxDamage = tonumber(maxd) or 0
mobData.dps = tonumber(dps) or 0
mobData.xp = tonumber(xp) or 0
mobData.skinCount = tonumber(sc) or 0
end
end -- MI2_DecodeCharData
-----------------------------------------------------------------------------
-- MI2_DecodeResists()
--
-- Decode mob resistances and immunities info
-- The location is encoded in the mob record entry "re".
-- The decoded data is stored in the given "mobData" structure.
--
function MI2_DecodeResists( mobInfo, mobData, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
if mobInfo.re then
local a,b,ar,arHits,fi,fiHits,fr,frHits,ho,hoHits,na,naHits,sh,shHits = string.find( mobInfo.re, "(%-?%d*),(%-?%d*)/(%-?%d*),(%-?%d*)/(%-?%d*),(%-?%d*)/(%-?%d*),(%-?%d*)/(%-?%d*),(%-?%d*)/(%-?%d*),(%-?%d*)")
mobData.resists = {}
mobData.resists.ar = tonumber(ar) or 0
mobData.resists.fi = tonumber(fi) or 0
mobData.resists.fr = tonumber(fr) or 0
mobData.resists.ho = tonumber(ho) or 0
mobData.resists.na = tonumber(na) or 0
mobData.resists.sh = tonumber(sh) or 0
mobData.resists.arHits = tonumber(arHits) or 0
mobData.resists.fiHits = tonumber(fiHits) or 0
mobData.resists.frHits = tonumber(frHits) or 0
mobData.resists.hoHits = tonumber(hoHits) or 0
mobData.resists.naHits = tonumber(naHits) or 0
mobData.resists.shHits = tonumber(shHits) or 0
end
end -- MI2_DecodeMobLocation()
-----------------------------------------------------------------------------
-- MI2_DecodeItemList()
--
-- Decode the item list encoded in the "il" string of a mobInfo database
-- record. The result is stored in the given mobData record as a new
-- record field called "itemList".
--
function MI2_DecodeItemList( mobInfo, mobData, mobIndex )
if mobIndex then
mobInfo = MobInfoDB[mobIndex]
end
if mobInfo.il then
local lootItems = mobInfo.il
local s,e, item, amount = string.find( lootItems, "(%d+)[:]?(%d*)" )
if e then mobData.itemList = {} end
while e do
mobData.itemList[tonumber(item)] = tonumber(amount) or 1
s,e, item, amount = string.find( lootItems, "/(%d+)[:]?(%d*)", e+1 )
end
end
end -- MI2_DecodeItemList()
-----------------------------------------------------------------------------
-- MI2_StoreBasicInfo()
--
-- Store the mob basic info in the mob database. Basic info includes the
-- mob loot quality overview counters.
--
local function MI2_StoreBasicInfo( mobIndex, mobData )
local mobInfo = MobInfoDB[mobIndex]
if not mobInfo then
mobInfo = {}
MobInfoDB[mobIndex] = mobInfo
end
-- encode the mobs low hp action within the mob type value
local mobType = mobData.mobType
if mobData.lowHpAction then
mobType = (mobType or 1) + mobData.lowHpAction * 10
end
-- no need to store a mobType of 1 (normal mobs)
if mobType == 1 then
mobType = nil
end
local basicInfo = (mobData.loots or "").."/"..
(mobData.emptyLoots or "").."/"..
(mobData.copper or "").."/"..
(mobData.itemValue or "").."/"..
(mobData.clothCount or "").."//"..
(mobType or "").."/"..
(mobData.skinCount or "")
if basicInfo ~= "///////" then
mobInfo.bi = basicInfo
end
local qualityInfo = (mobData.r1 or "").."/"..
(mobData.r2 or "").."/"..
(mobData.r3 or "").."/"..
(mobData.r4 or "").."/"..
(mobData.r5 or "")
if qualityInfo ~= "////" then
mobInfo.qi = qualityInfo
end
end -- MI2_StoreBasicInfo()
-----------------------------------------------------------------------------
-- MI2_StoreLocation()
--
-- Store the mob location data in the mob database.
--
function MI2_StoreLocation( mobIndex, loc )
if not loc then return end
local mobInfo = MobInfoDB[mobIndex]
if not mobInfo then
mobInfo = {}
MobInfoDB[mobIndex] = mobInfo
end
local locationInfo = (loc.x1 or "").."/"..
(loc.y1 or "").."/"..
(loc.x2 or "").."/"..
(loc.y2 or "").."//"..
(loc.z or "")
if locationInfo ~= "/////" then
mobInfo.ml = locationInfo
end
end -- MI2_StoreLocation()
-----------------------------------------------------------------------------
-- MI2_StoreCharData()
--
-- Store the char specific mob data in the mob database.
--
local function MI2_StoreCharData( mobIndex, mobData, playerName )
local mobInfo = MobInfoDB[mobIndex]
if not mobInfo then
mobInfo = {}
MobInfoDB[mobIndex] = mobInfo
end
local playerInfo = (mobData.kills or "").."/"..
(mobData.minDamage or "").."/"..
(mobData.maxDamage or "").."/"..
(mobData.dps or "").."/"..
(mobData.xp or "")
if playerInfo ~= "////" then
mobInfo[playerName] = playerInfo
end
--printf("playerInfo = %s, playerName = %s", playerInfo or 'nil', playerName or 'nil')
end -- MI2_StoreCharData()
-----------------------------------------------------------------------------
-- MI2_StoreLootItems()
--
-- Store a mobs loot items list in mob database.
--
local function MI2_StoreLootItems( mobIndex, mobData )
local mobInfo = MobInfoDB[mobIndex]
if not mobInfo then
mobInfo = {}
MobInfoDB[mobIndex] = mobInfo
end
-- create loot item list string for database
local itemList = ""
if mobData.itemList then
local prefix = ""
for itemID, amount in pairs(mobData.itemList) do
itemList = itemList..prefix..itemID
if amount > 1 then
itemList = itemList..":"..amount
end
prefix = "/"
end
end
if itemList ~= "" then
mobInfo.il = itemList
end
end -- MI2_StoreLootItems()
-----------------------------------------------------------------------------
-- MI2_StoreResistData()
--
-- Store resist data for mob in mob database. Data will only be saved if
-- resistances exist.
--
function MI2_StoreResistData( mobIndex )
local mobData = MI2_FetchMobData( mobIndex )
resData = mobData.resists
-- store only if resistances exist
if resData.ar or resData.fi or resData.fr or resData.ho or resData.na or resData.sh then
local mobInfo = MobInfoDB[mobIndex]
if not mobInfo then
mobInfo = {}
MobInfoDB[mobIndex] = mobInfo
end
local resistString =
(resData.ar or "")..","..(resData.arHits or "").."/"..
(resData.fi or "")..","..(resData.fiHits or "").."/"..
(resData.fr or "")..","..(resData.frHits or "").."/"..
(resData.ho or "")..","..(resData.hoHits or "").."/"..
(resData.na or "")..","..(resData.naHits or "").."/"..
(resData.sh or "")..","..(resData.shHits or "")
mobInfo.re = resistString
end
end -- MI2_StoreResistData()
-----------------------------------------------------------------------------
-- MI2_StoreAllMobData()
--
-- Store all recorded data for a given mob in the mob database.
--
function MI2_StoreAllMobData( mobData, mobName, mobLevel, playerName, mobIndex )
if not mobIndex then
mobIndex = mobName..":"..mobLevel
end
if MobInfoConfig.SaveBasicInfo == 1 then
MI2_StoreBasicInfo( mobIndex, mobData )
MI2_StoreLocation( mobIndex, mobData.location )
end
if MobInfoConfig.SaveCharData == 1 then
MI2_StoreCharData( mobIndex, mobData, MI2_PlayerName )
end
if MobInfoConfig.SaveItems == 1 then
MI2_StoreLootItems( mobIndex, mobData )
end
if MobInfoConfig.SaveResist == 1 then
MI2_StoreResistData( mobIndex )
end
end -- MI2_StoreAllMobData()
-----------------------------------------------------------------------------
-- MI2_RemoveCharData()
--
-- Remove all char specific data from the given Mob database record.
--
function MI2_RemoveCharData( mobInfo )
for entryName, entryData in pairs(mobInfo) do
if entryName ~= "bi" and entryName ~= "qi" and entryName ~= "il" and entryName ~= "ml" and entryName ~= "ver" then
mobInfo[entryName] = nil
end
end
end -- MI2_RemoveCharData()
-----------------------------------------------------------------------------
-- MI2_DeleteMobData()
--
-- Delete data for a specific Mob from database and current target table.
--
function MI2_DeleteMobData( mobIndex, deleteHealth )
if mobIndex then
MobInfoDB[mobIndex] = nil
MI2_MobCache[mobIndex] = nil
if deleteHealth then
MobHealthDB[mobIndex] = nil
end
if mobIndex == MI2_Target.mobIndex then
MI2_Target = {}
MobHealth_Display()
end
end
end -- MI2_DeleteMobData()
-----------------------------------------------------------------------------
-- MI2_DeleteItemFromDB()
--
-- Delete data for a specific Mob from database and current target table.
--
function MI2_DeleteItemFromDB( itemID )
for mobIndex, mobInfo in pairs(MobInfoDB) do
local mobData = {}
MI2_DecodeItemList( mobInfo, mobData )
if mobData.itemList then
mobData.itemList[itemID] = nil
MI2_StoreLootItems( mobIndex, mobData )
end
end
MI2_ItemNameTable[itemID] = nil
end -- MI2_DeleteItemFromDB()
-----------------------------------------------------------------------------
-- MI2_SetPlayerName()
--
-- Set the global MobInfo player name. This is the abbreviated player name
-- that is just an index into the MobInfo player name table, where the real
-- name of the player is stored.
--
function MI2_SetPlayerName()
local charName = GetRealmName()..':'..UnitName("player")
if not MI2_CharTable[charName] then
MI2_CharTable.charCount = MI2_CharTable.charCount + 1
MI2_CharTable[charName] = "c"..MI2_CharTable.charCount
end
MI2_PlayerName = MI2_CharTable[charName]
end -- MI2_SetPlayerName()
-----------------------------------------------------------------------------
-- MI2_ClearMobCache()
--
-- Empty oput the mob data cache
--
function MI2_ClearMobCache()
MI2_MobCache = {}
MI2_MobCacheIdx = 1
end -- MI2_ClearMobCache
-----------------------------------------------------------------------------
-- MI2_DeleteAllMobData()
--
-- Delete entire Mob database and all related data tables
--
function MI2_DeleteAllMobData()
MobInfoDB = { ["DatabaseVersion:0"] = { ver = MI2_DB_VERSION, loc=MI2_Locale, sv=MI2_DB_SV } }
MI2_CharTable = { charCount = 0 }
MI2_ItemNameTable = {}
MI2_XRefItemTable = {}
MI2_SetPlayerName()
MI2_ClearMobCache()
MI2_ZoneTable = { cnt = 1 }
end -- MI2_DeleteAllMobData()
-----------------------------------------------------------------------------
-- chattext()
--
-- spits out msg to the chat channel.
--
function chattext(txt)
if( DEFAULT_CHAT_FRAME ) then
DEFAULT_CHAT_FRAME:AddMessage( MI_LightBlue.."<MI2> "..txt)
end
end -- chattext()
-----------------------------------------------------------------------------
-- midebug()
--
-- add debug message to chat channel, handle debug detail level if given
--
function midebug( txt, dbgLevel )
if DEFAULT_CHAT_FRAME then
if dbgLevel then
if dbgLevel <= MI2_Debug then
DEFAULT_CHAT_FRAME:AddMessage( MI_LightBlue.."[MI2DBG] "..txt)
end
else
DEFAULT_CHAT_FRAME:AddMessage( MI_LightBlue.."<MI2DBG> "..txt)
end
end
end -- midebug()
-----------------------------------------------------------------------------
-- MI2_IndexComponents()
--
-- Return the component parts of a mob index: mob name, mob level
--
function MI2_GetIndexComponents( mobIndex )
local a, b, mobName, mobLevel = string.find(mobIndex, "(.+):(.+)$")
mobLevel = tonumber(mobLevel) or 0
return mobName, mobLevel
end -- MI2_IndexComponents()
-----------------------------------------------------------------------------
-- MI2_UpdateDatabaseV7ToV8()
--
-- update database from V7 to V8 : add all zones to the MobInfo
-- zone table and give them new zone IDs, index the zone table
-- by ID instead of name
--
local function MI2_UpdateDatabaseV7ToV8()
local zoneName, zoneId, mobIndex, mobInfo, newZoneTable
-- swap index with name in zone table
newZoneTable = {}
MI2_ZoneTable.cnt = nil
for zoneName, zoneId in pairs(MI2_ZoneTable) do
newZoneTable[zoneId] = zoneName
end
MI2_ZoneTable = newZoneTable
MI2_ZoneTable.cnt = 0
-- add names of ALL zones to zone table and store
-- the new zone ID in mob data
for mobIndex, mobInfo in pairs(MobInfoDB) do
local mobData = {}
MI2_DecodeMobLocation( mobInfo, mobData )
if mobData.location then
local zone = mobData.location.z
if zone < 100 then
-- remove old style V7 zone IDs because after WoW 2.0 it has
-- become impossible to correctly convert them
mobInfo.ml = nil
end
end
end
end -- MI2_UpdateDatabaseV7ToV8()
-----------------------------------------------------------------------------
-- MI2_UpdateDatabaseV8ToV9()
--
-- update database from V8 to V9 : health percent values 100 and 200 now
-- have special meaning, so make sure they do not occur in old health data
--
local function MI2_UpdateDatabaseV8ToV9( cleanupMode )
for idx, hpData in pairs(MobHealthDB) do
if type(hpData) == "string" then
local _,_, pts, pct = string.find( hpData, "^(%d+)/(%d+)$")
pts = tonumber(pts) or 0
pct = tonumber(pct) or 0
if not pct or not pts or pct <= 0 or pts <= 0 then
MobHealthDB[idx] = nil
else
local newPts = floor( (pts / pct) * 75.0 )
MobHealthDB[idx] = newPts.."/"..75
end
else
MobHealthDB[idx] = nil
end
end
end
-----------------------------------------------------------------------------
-- MI2_CheckAndCleanDatabases()
--
-- Cleanup for MobInfo database. This function corrects bugs in the
-- MobInfo database and applies changes that have been made to the
-- format of the actual database entires.
--
function MI2_CheckAndCleanDatabases()
local mobIndex, mobInfo
local dbVerInfo = MobInfoDB["DatabaseVersion:0"] or { ver=0 }
local version = dbVerInfo.ver
-- check : mob database version must exist
if MobInfoDB and version == 0 then
StaticPopupDialogs["MOBINFO_SHOWMESSAGE"].text = MI_Red..MI_TXT_WRONG_DBVER
local dialog = StaticPopup_Show( "MOBINFO_SHOWMESSAGE", "")
MI2_DeleteAllMobData()
return
end
-- check mob database locale against WoW client locale (must match)
if dbVerInfo.loc and dbVerInfo.loc ~= MI2_Locale then
StaticPopupDialogs["MOBINFO_SHOWMESSAGE"].text = MI_Red..MI_TXT_WRONG_LOC
local dialog = StaticPopup_Show( "MOBINFO_SHOWMESSAGE", "")
return
end
-- Initialise all database tables that do not exist
MobInfoDB = MobInfoDB or {}
-- Take MI3 database tables, instead of MI2 databas tables, if present
if MI3_CharTable then
MI2_CharTable = MI3_CharTable
MI2_ItemNameTable = MI3_ItemNameTable
MI2_ZoneTable = MI3_ZoneTable
end
if MI3_XRefItemTable then
MI2_XRefItemTable = MI3_XRefItemTable
end
MI2_CharTable = MI2_CharTable or { charCount = 0 }
MI2_ItemNameTable = MI2_ItemNameTable or {}
MI2_XRefItemTable = MI2_XRefItemTable or {}
MI2_ZoneTable = MI2_ZoneTable or { cnt = 1 }
MobHealthDB = MobHealthDB or {}
MobHealthPlayerDB = MobHealthPlayerDB or {}
MI2_SetPlayerName()