-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKiwiFarm.lua
More file actions
2643 lines (2525 loc) · 100 KB
/
Copy pathKiwiFarm.lua
File metadata and controls
2643 lines (2525 loc) · 100 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
-- ============================================================================
-- KiwiFarm (C) 2019 MiCHaEL
-- ============================================================================
local addonName = ...
-- main frame
local addon = CreateFrame('Frame', "KiwiFarm", UIParent, BackdropTemplateMixin and "BackdropTemplate")
-- locale
local L = LibStub('AceLocale-3.0'):GetLocale('KiwiFarm', true)
-- game version
local VERSION = select(4,GetBuildInfo())
local VANILA = VERSION<30000
local CLASSIC = VERSION<90000
local RETAIL = VERSION>=90000
-- midnight stuff
local SECRETS = VERSION>=120000
local issecretvalue = issecretvalue or function() return false end
local canaccessvalue = canaccessvalue or function() return true end
-- addon version
local GetAddOnInfo = C_AddOns and C_AddOns.GetAddOnInfo or GetAddOnInfo
local GetAddOnMetadata = C_AddOns and C_AddOns.GetAddOnMetadata or GetAddOnMetadata
local versionToc = GetAddOnMetadata(addonName, "Version")
local versionStr = (versionToc=='\@project-version\@' and 'Dev' or versionToc)
-- player GUID
local playerGUID = UnitGUID("player")
-- addon icon
local iconTexture = "Interface\\AddOns\\KiwiFarm\\KiwiFarm.tga"
-- database keys
local serverKey = GetRealmName()
local charKey = UnitName("player") .. " - " .. serverKey
-- max player level by exapansion (not using game table because does not exist in Shadowlands)
local MAX_PLAYER_LEVEL_TABLE = {
[0] = 60, -- Vanilla
[1] = 70, -- TBC
[2] = 80, -- Wotlk
[3] = 85, -- Cataclism
[4] = 90, -- MoP
[5] = 100, -- WoD
[6] = 110, -- Legion
[7] = 120, -- BoA,
[8] = 60, -- ShadowLands
[9] = 70, -- Dragonflight
[10] = 80, -- TWW
[11] = 90, -- Midnight
}
local isPlayerLeveling
do
-- local isSoD = C_Seasons and C_Seasons.GetActiveSeason and C_Seasons.GetActiveSeason()==2 -- season of discovery
local level = UnitLevel('player')
local levelMax = (MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()] or 0)
isPlayerLeveling = level < levelMax
end
-- default values
local RESET_MAX = VANILA and 5 or 10
local RESET_DAY = 30
local COLOR_WHITE = { 1,1,1,1 }
local COLOR_TRANSPARENT = { 0,0,0,0 }
local ITEM_QUALITY_COLORS = ITEM_QUALITY_COLORS
local FONTS = (GetLocale() == 'zhCN') and {
Arial = 'Fonts\\ARHei.TTF',
FrizQT = 'Fonts\\ARHei.TTF',
Morpheus = 'Fonts\\ARHei.TTF',
Skurri = 'Fonts\\ARHei.TTF',
} or {
Arial = 'Fonts\\ARIALN.TTF',
FrizQT = 'Fonts\\FRIZQT__.TTF',
Morpheus = 'Fonts\\MORPHEUS.TTF',
Skurri = 'Fonts\\SKURRI.TTF',
}
local SOUNDS = {
["Auction Window Open"] = 567482,
["Auction Window Close"] = 567499,
["Coin" ] = 567428,
["Money"] = 567483,
["Level Up"] = 569593,
["Pick Up Gems"] = 567568,
["Player Invite"] = 567451,
["Put Down Gems"] = 567574,
["PvP Enter Queue"] = 568587,
["PvP Through Queue"] = 568011,
["Raid Warning"] =567397,
["Ready Check"] = 567478,
["Quest List Open"] = 567504,
}
local BORDERS = {
["None"] = [[]],
["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]],
["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]],
["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]],
["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]],
["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]],
["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]],
}
local DEFROOT = {
profilePerChar = {},
}
local DEFSERVER = {
leveling = {}, -- leveling info per character
resetData = VANILA and {}, -- reset data per character for classic
resets = (not VANILA) and {count=0,countd=0}, -- reset data per server for retail
resetsd = (not VANILA) and {}, -- reset data per server for retail
}
local DEFRESET = {
resets = {count=0,countd=0}, -- resets per hour
resetsd = {}, -- resets per day (max 30, only for classic)
}
local DEFDATA = {
-- money
moneyCash = 0,
moneyItems = 0,
moneyQuests = 0,
moneyByQuality = {},
-- items
countItems = 0,
countByQuality = {},
lootedItems = {},
-- mobs
countMobs = 0,
killedMobs = {},
}
-- database defaults
local DEFCONFIG = {
-- data/stats
session = {},
total = {},
daily = {},
zone = {},
-- fields blacklists
collect = { total = {}, daily = {}, zone = {} },
-- reset chat notification
resetsNotify = {},
-- prices
priceByItem = {},
priceByQuality = { [0]={vendor=true}, [1]={vendor=true}, [2]={vendor=true}, [3]={vendor=true}, [4]={vendor=true}, [5]={vendor=true} },
ignoreEnchantingMats = nil,
-- loot notification
notifyArea = nil,
notify = { [1]={chat=0}, [2]={chat=0}, [3]={chat=0}, [4]={chat=0}, [5]={chat=0}, sound={} },
-- session control, farming zones
farmZones = nil,
farmDisableZones = nil,
farmAutoStart = nil,
farmAutoFinish = nil,
-- appearance
visible = true, -- main frame visibility
moneyFmt = nil,
disabled = { quality=true }, -- disabled text sections
backColor = { 0, 0, 0, .4 },
borderColor = { 1, 1, 1, 1 },
borderTexture = nil,
fontName = nil,
fontsize = nil,
frameMargin = 4,
frameStrata = nil,
framePos = { anchor = 'TOPLEFT', x = 0, y = 0 },
-- minimap icon
minimapIcon = { hide = false },
}
-- local references
local time = time
local date = date
local type = type
local next = next
local print = print
local pairs = pairs
local ipairs = ipairs
local unpack = unpack
local tinsert = tinsert
local tremove = tremove
local tonumber = tonumber
local gsub = gsub
local strfind = strfind
local strlower = strlower
local max = math.max
local floor = math.floor
local format = string.format
local band = bit.band
local strmatch = strmatch
local GetZoneText = GetZoneText
local IsInInstance = IsInInstance
local GetInstanceInfo = GetInstanceInfo
local GetItemInfo = GetItemInfo or C_Item.GetItemInfo
local UnitXP = UnitXP
local UnitXPMax = UnitXPMax
local COPPER_PER_GOLD = COPPER_PER_GOLD
local COPPER_PER_SILVER = COPPER_PER_SILVER
-- database references
local root -- root database table for all servers and chars
local server -- database realtm table
local config -- char-server data table
local session -- config.session
local disabled -- config.disabled texts table
local notify -- config.notify notifications table
local collect -- config.collect
local leveling -- server.leveling[charKey] leveling info
local resets -- server.resets | server.resetData[charKey].resets instance resets table
local resetsd -- server.resetsd | server.resetData[charKey].resetsd instance resets table
-- miscellaneous variables
local inInstance
local curZoneName = ''
local combatActive
local combatCurKills = 0
local combatPreKills = 0
local timeLootedItems = 0 -- track changes in config.lootedItems table
local combatStartXP = 0
local enemyGUIDS = {}
-- main frame elements
local textl -- left text
local textr -- right text
local timer -- update timer
-- ============================================================================
-- utils & misc functions
-- ============================================================================
local function InitDB(dst, src, reset, norecurse)
if type(dst)~='table' then
dst = {}
elseif reset then
wipe(dst)
end
if src then
for k,v in pairs(src) do
if type(v)=="table" and not norecurse then
dst[k] = InitDB(dst[k] or {}, v)
elseif dst[k]==nil then
dst[k] = v
end
end
end
return dst
end
local function InitKeyDB(db, key, src, reset, norecurse)
if db[key]==nil then db[key] = {}; end
return InitDB( db[key], src, reset, norecurse )
end
local function CreateDB()
local root = InitKeyDB( _G, "KiwiFarmDB", DEFROOT)
local server = InitKeyDB( root, serverKey, DEFSERVER)
local config = InitKeyDB( root, root.profilePerChar[charKey] and charKey or serverKey, DEFCONFIG, false, true)
InitDB(config.session, DEFDATA)
InitDB(config.total, DEFDATA)
if VANILA then -- move resets per realm to resets per char (due to blizzard hotfix) but only in classic version
local char = InitKeyDB( server.resetData, charKey, DEFRESET )
char.resetsd = server.resetsd or char.resetsd
char.resets = server.resets or char.resets
char.resets.count = char.resets.count or 0
char.resets.countd = char.resets.countd or 0
server.resets = nil
server.resetsd = nil
end
if not config.__version then
for k,v in pairs(config.zone) do
v.moneyQuests = v.moneyQuests or 0
end
for k,v in pairs(config.daily) do
v.moneyQuests = v.moneyQuests or 0
end
config.__version = 1
end
return root, server, config
end
local function AddDB(dst, src, blacklist)
if dst then
for k,v in pairs(src) do
if not (blacklist and blacklist[k]) then
local typ = type(v)
if typ=="table" then
dst[k] = AddDB(dst[k] or {}, v)
elseif typ=='number' then
dst[k] = (dst[k] or 0) + v
end
end
end
return dst
end
end
local function GetZoneDB(key)
key = key or curZoneName
if key and key~='' then
local data = config.zone[key]
if not data then
data = InitDB({ _type = 'zone', _key = key }, DEFDATA)
config.zone[key] = data
end
return data
end
end
local function GetDailyDB(datetime)
local key = date("%Y/%m/%d", datetime)
local data = config.daily[key]
if not data then
data = InitDB({ _type = 'daily', _key = key }, DEFDATA)
config.daily[key] = data
end
return data
end
local function IsDungeon()
local _,typ = GetInstanceInfo()
return typ=='party' or typ=='raid'
end
local ZoneTitle
do
local strcut
if GetLocale() == "enUS" or GetLocale() == "enGB" then -- standard cut
local strsub = strsub
strcut = function(s,c)
return strsub(s,1,c)
end
else -- utf8 cut
local strbyte = string.byte
strcut = function(s, c)
local l, i = #s, 1
while c>0 and i<=l do
local b = strbyte(s, i)
if b < 192 then i = i + 1
elseif b < 224 then i = i + 2
elseif b < 240 then i = i + 3
else i = i + 4
end
c = c - 1
end
return s:sub(1, i-1)
end
end
ZoneTitle = setmetatable( {}, { __index = function(t,k) local v=strcut(k,18); t[k]=v; return v; end } )
end
local function GetSessionGeneralStats()
local curtime = time()
local duration = curtime - (session.startTime or curtime) + (session.duration or 0)
local total = session.moneyCash+session.moneyItems+session.moneyQuests
local hourly = duration>0 and floor(total*3600/duration) or 0
local m0, s0 = floor(duration/60), duration%60
local h0, m0 = floor(m0/60), m0%60
return total, hourly, session.moneyCash, session.moneyItems, session.moneyQuests, h0, m0, s0
end
-- text format functions
local function strfirstword(str)
return strmatch(str, "^(.-) ") or str
end
local function GetItemQualityColorHex(i)
local color = ITEM_QUALITY_COLORS[i]
return color and color.hex or '|cFFffffff'
end
local function FmtQuality(i)
return format( "%s%s|r", GetItemQualityColorHex(i), _G['ITEM_QUALITY'..i..'_DESC'] )
end
local function FmtDuration(seconds)
local m,s = floor(seconds/60), seconds%60
local h,m = floor(m/60), m%60
local d,h = floor(h/24), h%24
if d>0 then
return format("%dd %dh %dm %ds",d,h,m,s)
elseif h>0 then
return format("%dh %dm %ds",h,m,s)
else
return format("%dm %ds",m,s)
end
end
local function FmtMoney(money)
money = money or 0
local gold = floor( money / COPPER_PER_GOLD )
local silver = floor( (money % COPPER_PER_GOLD) / COPPER_PER_SILVER )
local copper = floor( money % COPPER_PER_SILVER )
return format( config.moneyFmt or "%d|cffffd70ag|r %d|cffc7c7cfs|r %d|cffeda55fc|r", gold, silver, copper)
end
local function FmtMoneyPlain(money)
money = money or 0
local gold = floor( money / COPPER_PER_GOLD )
local silver = floor( (money % COPPER_PER_GOLD) / COPPER_PER_SILVER )
local copper = floor( money % COPPER_PER_SILVER )
return format( config.moneyFmt or "%dg %ds %dc", gold, silver, copper)
end
local function FmtMoneyShort(money)
local str = ''
local gold = floor( money / COPPER_PER_GOLD )
local silver = floor( (money % COPPER_PER_GOLD) / COPPER_PER_SILVER )
local copper = floor( money % COPPER_PER_SILVER )
if silver>0 then str = format( "%s %d|cffc7c7cfs|r", str, silver) end
if copper>0 then str = format( "%s %d|cffeda55fc|r", str, copper) end
if gold>0 or str=='' then str = format( "%d|cffffd70ag|r%s", gold, str) end
return strtrim(str)
end
local function FmtMoneyPlain(money)
if money then
local gold = floor( money / COPPER_PER_GOLD )
local silver = floor( (money % COPPER_PER_GOLD) / COPPER_PER_SILVER )
local copper = floor( money % COPPER_PER_SILVER )
return format( "%dg %ds %dc", gold, silver, copper)
end
end
local function String2Copper(str)
str = strlower(gsub(str,' ',''))
if str~='' then
local c,s,g = tonumber(strmatch(str,"([%d,.]+)c")), tonumber(strmatch(str,"([%d,.]+)s")), tonumber(strmatch(str,"([%d,.]+)g"))
if not (c or s or g) then
g = tonumber(str)
end
return floor( (c or 0) + (s or 0)*100 + (g or 0)*10000 )
end
end
-- fonts
local function SetTextFont(widget, name, size, flags)
widget:SetFont(name or FONTS.Arial or STANDARD_TEXT_FONT, size or 14, flags or 'OUTLINE')
if not widget:GetFont() then
widget:SetFont(STANDARD_TEXT_FONT, size or 14, flags or 'OUTLINE')
end
end
-- group or raid members unit
local GetGroupRaidMembers
do
local party = { 'party1', 'party2', 'party3', 'party4' }
local raid = {}
for i=1,40 do raid[#raid+1] = 'raid'..i; end
function GetGroupRaidMembers()
if IsInRaid() then
return raid
elseif GetNumGroupMembers()>0 then
return party
end
end
end
-- dialogs
do
local DUMMY = function() end
StaticPopupDialogs["KIWIFARM_DIALOG"] = { timeout = 0, whileDead = 1, hideOnEscape = 1, button1 = ACCEPT, button2 = CANCEL }
function addon:ShowDialog(message, textDefault, funcAccept, funcCancel, textAccept, textCancel)
local t = StaticPopupDialogs["KIWIFARM_DIALOG"]
t.OnShow = function (self) if textDefault then (self.editBox or self:GetEditBox()):SetText(textDefault) end; self:SetFrameStrata("TOOLTIP") end
t.OnHide = function(self) self:SetFrameStrata("DIALOG") end
t.hasEditBox = textDefault and true or nil
t.text = message
t.button1 = funcAccept and (textAccept or ACCEPT) or nil
t.button2 = funcCancel and (textCancel or CANCEL) or nil
t.OnCancel = funcCancel
t.OnAccept = funcAccept and function (self) funcAccept( textDefault and (self.editBox or self:GetEditBox()):GetText() ) end or nil
StaticPopup_Show ("KIWIFARM_DIALOG")
end
function addon:MessageDialog(message, funcAccept)
addon:ShowDialog(message, nil, funcAccept or DUMMY)
end
function addon:ConfirmDialog(message, funcAccept, funcCancel, textAccept, textCancel)
self:ShowDialog(message, nil, funcAccept, funcCancel or DUMMY, textAccept, textCancel )
end
function addon:EditDialog(message, text, funcAccept, funcCancel)
self:ShowDialog(message, text or "", funcAccept, funcCancel or DUMMY)
end
end
-- ============================================================================
-- addon specific functions
-- ============================================================================
-- send message to group
local function SendMessageToHomeGroup()
local cfg = config.resetsNotify
if cfg.message and IsInGroup(LE_PARTY_CATEGORY_HOME) then
local channel
if IsInRaid(LE_PARTY_CATEGORY_HOME) then
if cfg['RAID_WARNING'] and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
channel = (select(2, GetRaidRosterInfo(UnitInRaid("player") or 1)))>0 and 'RAID_WARNING'
end
if not channel then
channel = cfg['RAID'] and 'RAID'
end
else
channel = cfg['PARTY'] and 'PARTY'
end
if channel then
SendChatMessage(cfg.message, channel)
end
end
end
-- notification functions
local Notify, NotifyEnd
do
local function fmtLoot(itemLink, quantity, money, pref )
local prefix = pref and '|cFF7FFF72KiwiFarm:|r ' or ''
if itemLink then
return format("%s%sx%d %s", prefix, itemLink, quantity, FmtMoneyShort(money) )
else
return format(L["%sYou loot %s"], prefix, FmtMoneyShort(money) )
end
end
local notified = {}
local channels = {
chat = function(itemLink, quantity, money)
local m = fmtLoot(itemLink, quantity, money, true)
local f = config.chatFrame and _G['ChatFrame'..config.chatFrame]
if f then
f:AddMessage(m)
else
print(m)
end
end,
combat = function(itemLink, quantity, money)
if CombatText_AddMessage then
local text = fmtLoot(itemLink, quantity, money)
CombatText_AddMessage(text, COMBAT_TEXT_SCROLL_FUNCTION, 1, 1, 1)
else
print(L['|cFF7FFF72KiwiFarm:|r Warning, Blizzard Floating Combat Text is not enabled, change the notifications setup or goto Interface Options>Combat to enable this feature.'])
end
end,
crit = function(itemLink, quantity, money)
if CombatText_AddMessage then
local text = fmtLoot(itemLink, quantity, money)
CombatText_AddMessage(text, COMBAT_TEXT_SCROLL_FUNCTION, 1, 1, 1, 'crit')
else
print(L['|cFF7FFF72KiwiFarm:|r Warning, Blizzard Floating Combat Text is not enabled, change the notifications setup or goto Interface Options>Combat to enable this feature.'])
end
end,
msbt = function(itemLink, quantity, money)
if MikSBT then
local text = fmtLoot(itemLink, quantity, money)
MikSBT.DisplayMessage(text, config.notifyArea or MikSBT.DISPLAYTYPE_NOTIFICATION, false, 255, 255, 255)
else
print(L['|cFF7FFF72KiwiFarm:|r Warning, MikScrollingCombatText addon is not installed, change the notifications setup or install MSBT.'])
end
end,
parrot = function(itemLink, quantity, money)
if Parrot then
local text = fmtLoot(itemLink, quantity, money)
Parrot:ShowMessage(text, config.notifyArea or "Notification")
else
print(L['|cFF7FFF72KiwiFarm:|r Warning, Parrot2 addon is not installed, change the notifications setup or install Parrot2.'])
end
end,
sound = function(_, _, _, groupKey)
local sound = notify.sound[groupKey]
if sound then PlaySoundFile(sound, "master") end
end,
}
function Notify(groupKey, itemLink, quantity, money)
for channel,v in pairs(notify[groupKey]) do
if not notified[channel] then
local func = channels[channel]
if func and money>=v then
func(itemLink, quantity, money, groupKey)
notified[channel] = true
end
end
end
end
function NotifyEnd()
wipe(notified)
end
end
-- items & price functions
local IsEnchantingMat
if VERSION<30000 then -- Vanilla or Burning Crusade
local ENCHANTING = {
[10940] = true, [11134] = true, [16203] = true, [11135] = true, [11174] = true, [14344] = true,
[11082] = true, [11137] = true, [11083] = true, [10998] = true, [20725] = true, [11138] = true,
[11084] = true, [11139] = true, [11178] = true, [10938] = true, [11176] = true, [14343] = true,
[11177] = true, [10939] = true, [10978] = true, [16204] = true, [16202] = true, [11175] = true,
}
function IsEnchantingMat(itemID)
return ENCHANTING[itemID]
end
else
function IsEnchantingMat(_, class, subClass)
return class==7 and subClass==12
end
end
-- calculate item price
local GetItemPrice
do
-- auctionator addon
local Auctionator_GetMarketPrice, Auctionator_GetDisenchantPrice, ItemUpgradeInfo
local function InitAuctionator()
if VANILA and Atr_GetAuctionPrice and Atr_CalcDisenchantPrice then -- auctionator ClassicFix (GepyFix)
ItemUpgradeInfo = LibStub('LibItemUpgradeInfo-1.0',true)
Auctionator_GetMarketPrice = function(name, itemID)
return Atr_GetAuctionPrice(name)
end
Auctionator_GetDisenchantPrice = function(itemLink, class, rarity)
return Atr_CalcDisenchantPrice(class, rarity, ItemUpgradeInfo:GetUpgradedItemLevel(itemLink)) -- Atr_GetDisenchantValue() is bugged cannot be used
end
elseif Auctionator and Auctionator.API and Auctionator.API.v1 then -- Auctionator original version for retail or classic
local GetAuctionPriceByItemID = Auctionator.API.v1.GetAuctionPriceByItemID
local GetDisenchantAuctionPrice = Auctionator.API.v1.GetDisenchantPriceByItemLink
ItemUpgradeInfo = true
Auctionator_GetMarketPrice = function(_, itemID)
return GetAuctionPriceByItemID('KiwiFarm',itemID)
end
Auctionator_GetDisenchantPrice = function(itemLink)
return GetDisenchantAuctionPrice('KiwiFarm', itemLink)
end
end
end
-- aux addon
local AuxHistory, AuxInfo, AuxDisenchant
local function InitAuxAddon()
if _G.require and _G.aux_frame then
AuxHistory = _G.require('aux.core.history')
AuxInfo = _G.require('aux.util.info')
AuxDisenchant = _G.require('aux.core.disenchant')
end
end
local function GenAuxItemKey(itemLink)
local item_id, suffix_id = AuxInfo.parse_link(itemLink)
return item_id .. ':'.. suffix_id
end
-- common code
local function GetValue(source, itemLink, itemID, name, class, rarity, vendorPrice, userPrice)
local price
if source == 'user' then
price = userPrice
elseif source == 'vendor' then
price = vendorPrice
elseif source == 'Atr:DBMarket' and ItemUpgradeInfo then -- Auctionator: market
price = Auctionator_GetMarketPrice(name, itemID)
elseif source == 'Atr:Destroy' and ItemUpgradeInfo then -- Auctionator: disenchant
price = Auctionator_GetDisenchantPrice(itemLink, class, rarity)
elseif source == 'Aux:Market' and AuxHistory then
price = AuxHistory.market_value( GenAuxItemKey(itemLink) )
elseif source == 'Aux:MinBuyout' and AuxHistory then
price = AuxHistory.value( GenAuxItemKey(itemLink) )
elseif source == 'Aux:Disenchant' and AuxDisenchant then
local item = AuxInfo.item(itemID)
price = item and AuxDisenchant.value(item.item_id, item.slot, item.quality, item.level)
elseif source == 'REC:Market' and RECrystallize_PriceCheck then
price = RECrystallize_PriceCheck(itemLink)
elseif TSM_API and TSM_API.GetCustomPriceValue then -- TSM sources
price = TSM_API.GetCustomPriceValue(source, "i:"..itemID)
end
return price or 0
end
function GetItemPrice(itemLink)
InitAuxAddon()
InitAuctionator()
GetItemPrice = function(itemLink)
local itemID = tonumber(strmatch(itemLink, "item:(%d+):"))
if itemID~=nil then
local name, _, rarity, _, _, _, _, _, _, _, vendorPrice, class, subClass = GetItemInfo(itemLink)
if not (config.ignoreEnchantingMats and IsEnchantingMat(itemID, class, subClass)) then
local price, sources = 0, config.priceByItem[itemLink] or config.priceByQuality[rarity or 0] or {}
for src, user in pairs(sources) do
price = max( price, GetValue(src, itemLink, itemID, name, class, rarity, vendorPrice, user) )
end
return price, rarity, name
end
end
end
return GetItemPrice(itemLink)
end
end
-- lock&resets management
local LockAddReset, LockAddInstance, LockDel, LockResetAll
do
local function LockAddCharReset(zone, ctime, resets, resetsd)
if VANILA then
resetsd[#resetsd+1] = ctime -- classic to track 30/24h limit
end
resets.count = resets.count + 1
for i=#resets,1,-1 do
if resets[i].zone==zone and not resets[i].reseted then
resets[i].time = ctime
resets[i].reseted = ctime
resets.countd = resets.countd - 1
resets[zone] = nil
return
end
end
resets[#resets+1] = { zone = zone, time = ctime, reseted = ctime}
end
local function CheckPartyAlts(zone, ctime) -- reset of alts in party/raid for classic
if VANILA then
local units = GetGroupRaidMembers()
if units then
for _,unit in ipairs(units) do
if not UnitExists(unit) then break end
local nameKey = UnitName(unit) .. " - " .. serverKey
if charKey~=nameKey then
local resetChar = server.resetData[nameKey]
if resetChar then
LockAddCharReset(zone, ctime, resetChar.resets, resetChar.resetsd, true)
end
end
end
end
end
end
-- register instance reset
function LockAddReset(zone)
local ctime = time()
LockAddCharReset(zone, ctime, resets, resetsd) -- current char reset
CheckPartyAlts(zone, ctime)
end
-- add used instance
function LockAddInstance(zone)
resets[zone] = true
resets.countd = resets.countd + 1
resets[#resets+1] = { zone = zone, time = time() }
end
-- delete instance
function LockDel(i)
if resets[i].reseted then
resets.count = resets.count - 1
else
resets[ resets[i].zone ] = nil
resets.countd = resets.countd - 1
end
tremove(resets,i)
end
-- reset all used/dirty instances
function LockResetAll()
local ctime = time()
local i, expire = #resets, ctime-3600
while i>0 and resets[i].time>expire do
if not resets[i].reseted and (not inInstance or resets[i].zone~=curZoneName) then
resets[i].time = ctime
resets[i].reseted = ctime
resets.count = resets.count + 1
resets[ resets[i].zone ] = nil
resets.countd = resets.countd - 1
if VANILA then
resetsd[#resetsd+1] = ctime -- classic to track 30/24h limit
end
end
i = i - 1
end
end
end
-- display farming info
local PrepareText, RefreshText
do
local text_header
local text_mask
local data = {}
-- prepare text
function PrepareText()
-- header & session duration
text_header = L["|cFF7FFF72KiwiFarm:|r\nSession:\n"]
text_mask = "|cFF7FFF72%s|r\n" -- zone
text_mask = text_mask .. "%s%02d:%02d:%02d|r\n" -- session duration
-- instance reset & lock info
if not disabled.reset then
text_header = text_header .. L["Resets:\n"]
if VANILA then
text_mask = text_mask .. "%s%d|r||%s%d|r||%s%02d:%02d|r\n" -- last reset
else
text_mask = text_mask .. "%s%d|r||%s%02d:%02d|r\n" -- last reset
end
end
-- count data
if not disabled.count then
-- mobs killed
text_header = text_header .. L["Mobs killed:\n"]
text_mask = text_mask .. "%d||%d\n"
-- items looted
text_header = text_header .. L["Items looted:\n"]
text_mask = text_mask .. "%d\n"
end
-- gold cash & items
if not disabled.gold then
if not disabled.quests then
text_header = text_header .. L["Gold quests:\n"]
text_mask = text_mask .. "%s\n" -- money quests
end
text_header = text_header .. L["Gold cash:\nGold items:\n"]
text_mask = text_mask .. "%s\n" -- money cash
text_mask = text_mask .. "%s\n" -- money items
-- gold by item quality
if not disabled.quality then
for i=0,5 do -- gold by qualities (poor to legendary)
text_header = text_header .. format(" %s\n",FmtQuality(i))
text_mask = text_mask .. "%s\n"
end
end
-- gold hour & total
text_header = text_header .. L["Gold/hour:\nGold total:\n"]
text_mask = text_mask .. "%s\n" -- money per hour
text_mask = text_mask .. "%s\n" -- money total
end
-- leveling xp
if isPlayerLeveling and not disabled.experience then
text_header = text_header .. L["XP/hour:\nXP remaining:\nXP last pull:\nXP level up:\n"]
text_mask = text_mask .. "%.1fk\n" -- xp/hour
text_mask = text_mask .. "%.1fk\n" -- xp remain
text_mask = text_mask .. "%d\n" -- xp last pull
text_mask = text_mask .. "%s\n" -- xp ding time
end
textl:SetText(text_header)
end
-- refresh text
function RefreshText()
local curtime = time()
local xpEnabled = isPlayerLeveling and not disabled.experience
-- delete old data
local exptime = curtime - 3600
while (#resets>0 and resets[1].time<exptime) or #resets>RESET_MAX do -- remove old resets(>1hour)
LockDel(1)
end
if VANILA then
local exptime = curtime - 86400
while (#resetsd>0 and resetsd[1]<exptime) or #resets>RESET_DAY do -- remove old daily resets for classic (>24hour)
tremove(resetsd,1)
end
end
-- reset old data
wipe(data)
-- zone text
data[#data+1] = ZoneTitle[curZoneName]
-- session duration
local sSession
if session.startTime or session.duration then
sSession = curtime - (session.startTime or curtime) + (session.duration or 0)
data[#data+1] = (session.startTime and '|cFF00ff00') or (session.duration and '|cFFff8000') or '|cFFff0000'
elseif xpEnabled then
sSession = curtime - (leveling.startTime or curtime) + (leveling.duration or 0)
data[#data+1] = '|cFF00ffff'
else
sSession = 0
data[#data+1] = '|cFFff0000'
end
local m0, s0 = floor(sSession/60), sSession%60
local h0, m0 = floor(m0/60), m0%60
data[#data+1] = h0
data[#data+1] = m0
data[#data+1] = s0
-- reset data
if not disabled.reset then
local dirtyC = resets.countd>0 and '|cFFff8000' or '|cFF00ff00'
local remain = RESET_MAX-resets.count
local timeLock = #resets>0 and resets[1].time+3600 or nil
local sUnlock = timeLock and timeLock-curtime or 0
if VANILA then
local remaind = math.max( RESET_DAY - #resetsd, 0 )
data[#data+1] = (remaind>5 and '|cFF00ff00') or (remaind>0 and '|cFFff8000') or '|cFFff0000'
data[#data+1] = remaind
end
-- resets remain
data[#data+1] = (remain>resets.countd and '|cFF00ff00') or (remain>0 and '|cFFff8000') or '|cFFff0000'
data[#data+1] = remain
-- unlock time if all resets are spent
data[#data+1] = (remain<=0 and '|cFFff0000') or dirtyC
data[#data+1] = floor(sUnlock/60)
data[#data+1] = sUnlock%60
end
-- count data
if not disabled.count then
-- mob kills
data[#data+1] = combatCurKills or combatPreKills
data[#data+1] = session.countMobs
-- items looted
data[#data+1] = session.countItems
end
-- gold info
if not disabled.gold then
if not disabled.quests then
data[#data+1] = FmtMoney(session.moneyQuests)
end
data[#data+1] = FmtMoney(session.moneyCash)
data[#data+1] = FmtMoney(session.moneyItems)
if not disabled.quality then
for i=0,5 do
data[#data+1] = FmtMoney(session.moneyByQuality[i] or 0)
end
end
local total = session.moneyCash+session.moneyItems+session.moneyQuests
data[#data+1] = FmtMoney(sSession>0 and floor(total*3600/sSession) or 0)
data[#data+1] = FmtMoney(total)
end
-- leveling xp info
if xpEnabled then
local xpMax = UnitXPMax("player")
local xpCur = UnitXP("player")
if xpMax>0 then -- workaround to blizzard bug, xp functions return 0 for an instant when player is dead and click Release Spirit
if xpCur<leveling.xpLastXP then
leveling.xpFromXP = leveling.xpFromXP-leveling.xpMaxXP
leveling.xpMaxXP = xpMax
end
leveling.xpLastXP = xpCur
local xpDuration = curtime - leveling.startTime + (leveling.duration or 0)
local xpPerHour = (xpCur - leveling.xpFromXP) / xpDuration * 3600
local xpRemain = xpMax - xpCur
local minutes = xpPerHour>0 and xpRemain / xpPerHour * 60 or 0
data[#data+1] = xpPerHour / 1000 -- xp/hour
data[#data+1] = xpRemain / 1000 -- remain xp to level up
data[#data+1] = leveling.xpLastPull or 0 -- xp last pull
data[#data+1] = minutes>=60 and format("%dh %02dm", minutes/60, minutes%60) or format("%dm", minutes)
else -- game returned wrong data, set all zero
data[#data+1] = 0
data[#data+1] = 0
data[#data+1] = 0
data[#data+1] = 0
end
end
-- set text
textr:SetFormattedText( text_mask, unpack(data) )
-- update timer status
local stopped = (#resets==0 and not session.startTime) and (not xpEnabled)
if stopped ~= not timer:IsPlaying() then
if stopped then
timer:Stop()
else
timer:Play()
end
end
end
end
-- adjust the money stats of a looted item whose price was changed by the user.
local function AdjustLootedItemMoneyStats(itemLink)
local data = session.lootedItems[itemLink]
if data then
local money, quantity = data[1], data[2]
local newPrice, quality = GetItemPrice(itemLink)
if newPrice then
local newMoney = newPrice * quantity
local moneyDiff = newMoney - money
if moneyDiff ~= 0 then
session.lootedItems[itemLink] = { money+moneyDiff, quantity }
session.moneyItems = math.max(0, session.moneyItems + moneyDiff)
session.moneyByQuality[quality] = math.max(0, session.moneyByQuality[quality] + moneyDiff)
RefreshText()
end
end
end
end
-- session start
local function SessionStart(refresh)
if not session.startTime or refresh then
session.startTime = session.startTime or time()
session.endTime = nil
addon:RegisterEvent("CHAT_MSG_LOOT")
addon:RegisterEvent("CHAT_MSG_MONEY")
addon:RegisterEvent("QUEST_TURNED_IN")
RefreshText()
end
end
-- session stop
local function SessionStop()
if session.startTime then
local curTime = time()
session.duration = (session.duration or 0) + (curTime - (session.startTime or curTime))
session.startTime = nil
session.endTime = curTime
addon:UnregisterEvent("CHAT_MSG_LOOT")
addon:UnregisterEvent("CHAT_MSG_MONEY")
addon:UnregisterEvent("QUEST_TURNED_IN")
return curTime
end
return session.endTime or time()
end
-- session finish
local function SessionFinish()