This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKarniCrap.lua
1362 lines (1130 loc) · 50.6 KB
/
KarniCrap.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
--[[ Karni's Crap Filter ]]--
---------------------------------------------------------------------------------
--
-- Karni's Crap Filter - A World of Warcraft addon
--
-- Copyright (C) 2008-2014 Karnifex
--
-- This file is part of Karni's Crap Filter.
--
-- Karni's Crap Filter is free software: you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- Karni's Crap Filter is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-------------------------------------------------------------------------------
--[[ Local Variables ]]--
local KARNICRAP_VERSION = GetAddOnMetadata( "KarniCrap", "Version" );
local debug = nil -- debug mode default setting (nil or 1)
local loot_all = nil -- variable to set next loot opened to loot all items
local justlooking = nil -- alt key will temporarily disable autolooting
local lasttab = 1 -- which tab the user was showing last
local unit_level = nil -- level of the corpse being skinned/engineered/mined/gathered
local using_tradeskill = nil -- player using tradeskill (used for preventing autodestroy)
local amount_poor = 0 -- totalled amount for poor filter
local amount_common = 0 -- totalled amount for common filter
local loot_threshold = 5 -- loot under threshold rarity will be autolooted (default is legendary
local playerlevel = nil -- tracks current player level
local questlist_items = {} -- a list that has all quest item names
local questlist_delay = 3 -- amount of delay before quest objectives are checked
--COLORS (Returns |cXXXXXX )
local _,_,_,poor_color = GetItemQualityColor(0) -- 0 Poor #9d9d9d
local _,_,_,common_color = GetItemQualityColor(1) -- 1 Common #ffffff
local _,_,_,uncommon_color = GetItemQualityColor(2) -- 2 Uncommon #1eff00
local _,_,_,rare_color = GetItemQualityColor(3) -- 3 Rare #0070dd
local _,_,_,epic_color = GetItemQualityColor(4) -- 4 Epic #a335ee
local _,_,_,legendary_color = GetItemQualityColor(5) -- 5 Legendary #ff8000
-- 6 Artifact
-- 7 Heirloom
local error_hex = "|cffff0000" -- red text for errors
local echo = KarniCrap_Echo -- localize the text output function
--[[ OnLoad Handler ]]--
function KarniCrap_OnLoad(self)
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("VARIABLES_LOADED")
self:RegisterEvent("LOOT_OPENED")
self:RegisterEvent("LOOT_CLOSED")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("RAID_ROSTER_UPDATE")
self:RegisterEvent("PLAYER_LEVEL_UP")
self:RegisterEvent("QUEST_FINISHED")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("MERCHANT_SHOW")
self:RegisterEvent("MERCHANT_CLOSED")
-- Register slash commands
SLASH_KARNICRAP1 = "/karnicrap"
SLASH_KARNICRAP2 = "/crap"
SlashCmdList["KARNICRAP"] = function(msg, editBox)
KarniCrap_CommandHandler(msg)
end
SLASH_KARNINOTCRAP1 = "/notcrap"
SlashCmdList["KARNINOTCRAP"] = function(msg)
KarniCrap_CommandHandlerNotCrap(msg)
end
end
--[[ Databroker ]]--
LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("KarniCrap", {
type = "launcher",
icon = "Interface\\Icons\\Spell_Frost_Stun",
OnClick = function(clickedframe, button)
KarniCrap_ToggleFrame()
end,
label = "Karni's Crap Filter" })
--[[ Inventory Update delay ]]--
local bagTimer = CreateFrame("Frame")
local total_time = 0
bagTimer:Hide()
-- used to prevent multiple executions of inventory updates on BAG_UPDATE
local function KarniCrap_BagUpdateDelay(self,elapsed)
total_time = total_time + elapsed
if total_time >= .1 then
KarniCrap_InventoryList()
KarniCrap_Scripts:RegisterEvent("BAG_UPDATE")
total_time = 0
self:Hide()
end
end
bagTimer:SetScript("OnUpdate", KarniCrap_BagUpdateDelay) -- set script after function exists
--[[ Slash Command Handler ]]--
function KarniCrap_CommandHandler(text)
link = text
text = text:lower()
if text == "help" then
echo(" ---[[ |cffffffffKarni's Crap Filter Help|r ]]---")
echo(" /crap or /karnicrap will open the options menu")
echo(" /crap [item] will add an item to the Never Loot list")
echo(" /notcrap [item] will add an item to the Always Loot list")
echo(" /crap off will disable the mod, /crap on will enable it")
-- debug settings
elseif text == "debug" then KarniCrap_ToggleDebug()
elseif text == "on" or text == "enable" then KarniCrap_Enable()
elseif text == "off" or text == "disable" then KarniCrap_Disable()
elseif text ~= "" then KarniCrap_AddLootToBlacklist(link)
else KarniCrap_ToggleFrame()
end
end
--[[ Toggle user debug mode ]]--
function KarniCrap_ToggleDebug()
if debug then
debug = nil
echo("KarniCrap: Debug mode off")
else
debug = 1
echo("KarniCrap: Debug mode on")
end
end
--[[ Toggle main window ]]--
function KarniCrap_ToggleFrame()
local frame = _G["KarniCrap"]
if frame then
-- if frame is visible, hide it and unregister BAG_UPDATE event
if frame:IsVisible() then
frame:Hide()
if KarniCrapConfig.Enabled == true then
KarniCrap_Scripts:UnregisterEvent("BAG_UPDATE")
end
-- if frame is hidden, show it and regist BAG_UPDATE event
else
if lasttab == 1 then KarniCrap_ShowTab1()
elseif lasttab == 2 then KarniCrap_ShowTab2()
else KarniCrap_ShowTab3() end
frame:Show()
if KarniCrapConfig.Enabled == true then
KarniCrap_Scripts:RegisterEvent("BAG_UPDATE")
end
end
end
end
--[[ Handles whitelist command "/notcrap" ]]--
function KarniCrap_CommandHandlerNotCrap(text)
if ( text ~= "" ) then
KarniCrap_AddLootToWhitelist(text)
else
echo("KarniCrap: /notcrap [itemlink] to add an item to the Always Loot list")
end
end
--[[ Get UnitID ]]--
function KarniCrap_GetUnitID()
local unitString = UnitGUID("mouseover")
local id = nil
local unitType = nil
if unitString then -- not a chest/object
if debug then echo("UnitGUID="..unitString) end
unitType, _, _, _, _, id, _ = strsplit("-", unitString);
if unitType == "Creature" then -- npc
-- if user has SkilledEnough option checked, get the target's level. Boss or unknown (too high) will return -1
if KarniCrapConfig.SkilledEnough then
unit_level = UnitLevel("mouseover") or nil
if unit_level == -1 then unit_level = nil end --boss or too high level. Attempt to use on Ony? or mineable boss in mana tombs?
end
if id then
if debug and unit_level then echo("Unit ID is "..id..", level is "..unit_level) end
return id
else
return nil
end
end
end
end
--[[ Get info of item in loot window slot ]]--
function KarniCrap_GetLootSlotInfo(i)
if GetLootSlotType(i) == LOOT_SLOT_CURRENCY then return nil end
local link = GetLootSlotLink(i)
local _, _, quantity = GetLootSlotInfo(i)
if link then
local _, _, id = string.find(link, "item:(%d+):")
local notcrap, details = CheckLoot(id)
-- notcrap will be true if item passed filters
local x = 'Item does not pass filters'
if notcrap then
x = 'Item passes filters'
end
x = "Lootslot("..i..")="..id..","..link..","..quantity..","..x.." ("..details..")"
if debug then echo(x) end
return notcrap, id, link, quantity, details
end
return nil
end
--[[ Function to loot everything in loot window when certain conditions are met ]]--
function KarniCrap_LootEverything(why)
why = why or "Looting everything" -- sets the reason to not be null if not passed (test!)
local destroy = KarniCrap_CheckDestroyConditions(using_tradeskill)
for i = 1, GetNumLootItems() do
-- to do: if inventory full then abort loot attempts with a warning (need to check for UI errors?)
local passed, id, link, quantity, details = KarniCrap_GetLootSlotInfo(i)
LootSlot(i)
-- check autodestroy settings
if destroy and not passed then
if debug then echo("destroy and not passed") end
KarniCrap_Scripts:RegisterEvent("BAG_UPDATE")
KarniCrap_AddToDestroyQueue(id, link, quantity, details)
end
end
if debug then echo("Looting everything ("..why..")") end
loot_all = nil
return true, why
end
-- Attempt to figure out the player's skill level for x skill
function KarniCrap_GetSkillLevel(skill)
local skill_level = nil
for i = 1, 6 do
profession = GetProfessions()[i]+
print("profession",profession or "nil")
if profession then
skillName, _, skillRank, maxRank, numSpells, spelloffset, skillLine, skillModifier, specializationIndex, specializationOffset = GetProfessionsInfo(profession)
if skillName == skill then
skill_level = skillRank + skillModifier
return skill_level
end
end
end
return skill_level
end
-- Compare mob level to skill level
function KarniCrap_HasEnoughSkill(skill)
skill_level = KarniCrap_GetSkillLevel(skill)
if not skill_level then skill_level = 0 end
if debug then echo("skill_level for "..skill.." is "..skill_level) end
if skill_level > 0 then
if skill_level < 100 then
max_unit_level = floor(skill_level/10) + 10
else
max_unit_level = floor(skill_level/5)
end
--if debug then echo("max unit "..skill.." level is "..max_unit_level) end
if max_unit_level >= unit_level then return true end
end
return nil
end
--[[ Event Handler ]]--
function KarniCrap_OnEvent(self, event, ...)
local arg1, arg2, arg3, arg4, arg5 = ...
local addon = ...
-- Delay scanning quest items until the PLAYER_LOGIN event fires and all addons are loaded
if event == "PLAYER_LOGIN" then
KarniCrap_InitializeUI()
KarniCrap_GetQuestItems()
elseif event == "ADDON_LOADED" then
if addon ~= "KarniCrap" then return end
self:UnregisterEvent("ADDON_LOADED")
echo("Karni's Crap Filter v"..KARNICRAP_VERSION.." loaded (/crap for options)");
KarniCrap_Loaded()
elseif event == "VARIABLES_LOADED" then
-- Show warning if Blizzard autoloot is enabled
local autolooting = GetCVar("autoLootDefault");
if GetCVar("autoLootDefault") == "1" then
echo(error_hex.."KarniCrap: Autolooting set to ON in Interface Settings, KarniCrap will not function!");
end
elseif event == "BAG_UPDATE" then
KarniCrap_Scripts:UnregisterEvent("BAG_UPDATE")
KarniCrap_InventoryScrollbarUpdate()
-- When an item goes to or leaves inventory, check to see if there is anything pending in the destroy queue
if KarniCrapConfig.Destroy == true then KarniCrap_DestroyQueue() end
-- only Re-register BAG_UPDATE if KarniCrap window is visible (i.e. updating inventory lists...)
if _G["KarniCrap"]:IsVisible() then
bagTimer:Show()
end
elseif event == "PLAYER_LEVEL_UP" then
playerlevel = tonumber(arg1)
elseif event == "GROUP_ROSTER_UPDATE" then
KarniCrapConfig.NumberInParty = GetNumGroupMembers()
KarniCrap_GetLootThreshold()
elseif event == "RAID_ROSTER_UPDATE" then
KarniCrapConfig.NumberInRaid = GetNumGroupMembers()
KarniCrap_GetLootThreshold()
elseif event == "QUEST_FINISHED" then
KarniCrap_TimerFrame:Show()
elseif event == "UNIT_SPELLCAST_SUCCEEDED" and arg1 == "player" then
-- arg1 = Unit casting spell
-- arg2 = Spell name
-- arg3 = Spell rank (deprecated)
-- arg4 = Spell lineID counter (?)
-- arg5 = Spell ID
-- Spellcast detection is used to determine if a tradeskill has been used
-- what happens when tradeskill doesn't trigger a loot window?
--[[ Tradeskills ]]--
-- Disenchanting, Inscription, Milling & Prospecting all "lock"
-- an item in your bag automatically forcing a "loot all" situation
-- The tradeskillList[] check should catch them anyway though.
using_tradeskill = nil
if tradeskillList[arg5] then -- check if the spell cast is a tradeskill
using_tradeskill = true
loot_all = true
else
loot_all = nil -- not in tradeskill list, don't loot everything
end
elseif event == "MERCHANT_SHOW" then
KarniCrap_MerchantOpen()
elseif event == "MERCHANT_CLOSED" then
KarniCrap_MerchantClosed()
elseif event == "LOOT_CLOSED" then
loot_all = nil
elseif event == "LOOT_OPENED" then
local link, itemID, quantity, looted = nil
if debug then echo("----- Looting ------") end
autodestroy_iteminfo = {} --should contain itemID, itemLink and itemQuantity
--[[ Just Looking (ALT modifier) ]]--
if IsAltKeyDown() then justlooking = true else justlooking = nil end
if arg1 == false and KarniCrapConfig.Enabled and not justlooking then
if loot_all then
looted = KarniCrap_LootEverything("Unknown")
else
if KarniCrap_IsLocked() then looted = KarniCrap_LootEverything("Container") end
if IsStealthed() and KarniCrapConfig.Pickpocketing == true then looted = KarniCrap_LootEverything("Pick Pocket") end
end
--[[ Fishing ]]--
if not looted and KarniCrapConfig.Fishing and IsFishingLoot() then
looted = KarniCrap_LootEverything("Fishing")
end
-- Get the source unit ID
local unitID = KarniCrap_GetUnitID();
-- if one of the gathering items is checked, check the mob type
if not looted and ( KarniCrapConfig.Skinnable or KarniCrapConfig.Gatherable or KarniCrapConfig.Minable or KarniCrapConfig.Engineerable ) then
local skill_level = ""
-- If cursor is over a corpse, check corpse settings and loot all if appropriate
if unitID then
if debug then echo("unit id="..unitID) end
local max_unit_level = 0
-- skinnable corpse
if KarniCrapConfig.Skinnable and mobsSkinnableList[unitID] then
if KarniCrapConfig.SkilledEnough then
if KarniCrap_HasEnoughSkill("Skinning") then looted = KarniCrap_LootEverything("Skinnable corpse") end
else
looted = KarniCrap_LootEverything("Skinnable corpse")
end
-- minable corpse
elseif KarniCrapConfig.Minable and mobsMinableList[unitID] then
if KarniCrapConfig.SkilledEnough then
if KarniCrap_HasEnoughSkill("Mining") then looted = KarniCrap_LootEverything("Minable corpse") end
else
looted = KarniCrap_LootEverything("Minable corpse")
end
-- gatherable corpse
elseif KarniCrapConfig.Gatherable and mobsGatherableList[unitID] then
if KarniCrapConfig.SkilledEnough then
if KarniCrap_HasEnoughSkill("Herb Gathering") then looted = KarniCrap_LootEverything("Gatherable corpse") end
else
looted = KarniCrap_LootEverything("Gatherable corpse")
end
-- engineerable corpse
elseif KarniCrapConfig.Engineerable and mobsEngineerableList[unitID] then
if KarniCrapConfig.SkilledEnough then
if KarniCrap_HasEnoughSkill("Engineering") then looted = KarniCrap_LootEverything("Engineerable corpse") end
else
looted = KarniCrap_LootEverything("Engineerable corpse")
end
end
end
end
-- Close loot window if nothing left
if GetNumLootItems() == 0 then
looted = true
CloseLoot()
end
-- If an attempt to loot everything hasn't been made, then do checks
if not looted then
local destroy = KarniCrap_CheckDestroyConditions()
for i = 1, GetNumLootItems() do
--[[ Money or Currency ]]--
if debug then echo("Loot slot "..i.." type = "..GetLootSlotType(i)) end
if (GetLootSlotType(i) == LOOT_SLOT_MONEY) or (GetLootSlotType(i) == LOOT_SLOT_CURRENCY) then
LootSlot(i)
-- TO DO --
-- if getnumlootitmes is 1 and the 1 is coins
-- Might need to do an items remaining check here to see if we can avoid lootslot taint errors
-- possible they will happen anyway if there is only coin and it gets looted
--[[ Item ]]--
else
local passed, id, link, quantity, details = KarniCrap_GetLootSlotInfo(i)
if passed then LootSlot(i)
if debug then echo("Looting "..link.."("..details..")") end
elseif not passed then
if destroy then
if debug then echo("Looting "..link.." to destroy ("..details..")") end
LootSlot(i)
-- TO DO: NEED TO MAKE SURE ITEM IS NOT ADDED TO DESTROY QUEUE IF USER COULD NOT LOOT IT (BAGS FULL)
KarniCrap_AddToDestroyQueue(id, link, quantity, details)
KarniCrap_Scripts:RegisterEvent("BAG_UPDATE")
else
if KarniCrapConfig.Echo then
echo("Not looting "..link.." because it's crap!");
end
end
end
end
end
if GetNumLootItems() == 0 then CloseLoot() end
end
end
end
end
function KarniCrap_GetLootThreshold()
if GetLootMethod() == "freeforall" then
loot_threshold = 5
else
loot_threshold = GetLootThreshold()
end
end
--[[ Check Loot ]]--
-- Loot = 1
-- Crap = nil
-- Ignore item = -1 (not marked as crap so auto-destroy won't catch it)
function CheckLoot(itemID)
if itemID == nil then return nil, "Blacklist" end
local lootName, lootLink, lootRarity, lootLevel, _, lootType, lootSubType, lootStackCount, _, _, lootValue = GetItemInfo(itemID)
if (not lootName) or (not lootLink) or (not lootRarity) or (not lootLevel) or (not lootType) or (not lootSubType) or (not lootStackCount) then return end
local temp
--[[ Blacklist ]]--
if KarniBlacklist[itemID] then return nil, "Blacklist" end
--[[ Whitelist, Currency & Quest type items ]]--
if KarniWhitelist[itemID] or lootType == "Quest" or lootType == "Currency" then
return true, "Whitelist, Currency or Quest item"
end
--[[ Quest Items ]]--
if ( lootRarity > 0 ) then
for key, value in pairs(questlist_items) do
if value == lootName then return true, "Quest Item" end
end
end
--[[ Quality ]]--
if ( ( KarniCrapConfig.Quality_Grouped == true and ( KarniCrapConfig.NumberInParty + KarniCrapConfig.NumberInRaid ) > 0 ) or KarniCrapConfig.Quality_Grouped == false ) then
if lootRarity == 0 and KarniCrapConfig.Quality_Poor then return -1, "Ignoring: Quality settings"
elseif lootRarity == 1 and KarniCrapConfig.Quality_Common then return -1, "Ignoring: Quality settings"
elseif lootRarity == 2 and KarniCrapConfig.Quality_Uncommon then return -1, "Ignoring: Quality settings"
elseif lootRarity == 3 and KarniCrapConfig.Quality_Rare then return -1, "Ignoring: Quality settings"
elseif lootRarity == 4 and KarniCrapConfig.Quality_Epic then return -1, "Ignoring: Quality settings" end
end
--[[ Loot Threshold ]]--
if ( lootRarity >= loot_threshold ) then return -1, "Ignoring: Over group loot threshold" end
--[[ Cooking ]]--
if ( KarniCrapConfig.Cooking and cookingList[itemID] ) then return true, "Cooking" end
--[[ Cloth ]]--
if itemID == "2589" then
if KarniCrapConfig.Cloth_Linen then return true, "Linen"
elseif KarniCrapConfig.Cloth_Linen_Never then return nil, "Linen" end
elseif itemID == "2592" then
if KarniCrapConfig.Cloth_Wool then return true, "Wool"
elseif KarniCrapConfig.Cloth_Wool_Never then return nil, "Wool" end
elseif itemID == "4306" then
if KarniCrapConfig.Cloth_Silk then return true, "Silk"
elseif KarniCrapConfig.Cloth_Silk_Never then return nil, "Silk" end
elseif itemID == "4338" then
if KarniCrapConfig.Cloth_Mageweave then return true, "Mageweave"
elseif KarniCrapConfig.Cloth_Mageweave_Never then return nil, "Mageweave" end
elseif itemID == "14047" then
if KarniCrapConfig.Cloth_Runecloth then return true, "Runecloth"
elseif KarniCrapConfig.Cloth_Runecloth_Never then return nil, "Runecloth" end
elseif itemID == "21877" then
if KarniCrapConfig.Cloth_Netherweave then return true, "Netherweave"
elseif KarniCrapConfig.Cloth_Netherweave_Never then return nil, "Netherweave" end
elseif itemID == "33470" then
if KarniCrapConfig.Cloth_Frostweave then return true, "Frostweave"
elseif KarniCrapConfig.Cloth_Frostweave_Never then return nil, "Frostweave" end
elseif itemID == "53010" then
if KarniCrapConfig.Cloth_Embersilk then return true, "Embersilk"
elseif KarniCrapConfig.Cloth_Embersilk_Never then return nil, "Embersilk" end
elseif itemID == "72988" then
if KarniCrapConfig.Cloth_Windwool then return true, "Windwool"
elseif KarniCrapConfig.Cloth_Windwool_Never then return nil, "Windwool" end
elseif itemID == "111557" then
if KarniCrapConfig.Cloth_SumptuousFur then return true, "Sumptuous Fur"
elseif KarniCrapConfig.Cloth_SumptuousFur_Never then return nil, "Sumptuous Fur" end
elseif itemID == "124437" then
if KarniCrapConfig.Cloth_ShaldoreiSilk then return true, "Shal'dorei Silk"
elseif KarniCrapConfig.Cloth_ShaldoreiSilk_Never then return nil, "Shal'dorei Silk" end
end
--[[ Scrolls ]]--
-- needs to loot all max level scroll types if only the max button is checked
if lootSubType == "Scroll" then
if KarniCrapConfig.Scroll_Agility and ScrollList_Agility[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Agility) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
elseif KarniCrapConfig.Scroll_Intellect and ScrollList_Intellect[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Intellect) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
elseif KarniCrapConfig.Scroll_Protection and ScrollList_Protection[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Protection) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
elseif KarniCrapConfig.Scroll_Spirit and ScrollList_Spirit[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Spirit) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
elseif KarniCrapConfig.Scroll_Stamina and ScrollList_Stamina[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Stamina) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
elseif KarniCrapConfig.Scroll_Strength and ScrollList_Strength[itemID] then
if KarniCrapConfig.ScrollMax then
if KarniCrap_CheckScroll(itemID, ScrollList_Strength) then return true
else return nil, "Scroll level too low" end
else return true, "Scroll type" end
end
end
--[[ Food ]]--
if KarniCrapConfig.AlwaysFood or KarniCrapConfig.NeverFood then
if foodList[itemID] then
if KarniCrapConfig.NeverFood then
return nil, "Food"
elseif KarniCrapConfig.AlwaysFood then
if KarniCrapConfig.FoodMax then
if foodList[itemID] > playerlevel - 10 then return true, "Food"
else return nil, "Food level too low" end
else
return true, "Food"
end
end
end
end
--[[ Water ]]--
if KarniCrapConfig.AlwaysWater or KarniCrapConfig.NeverWater then
if waterList[itemID] then
if KarniCrapConfig.NeverWater then
return nil, "Water"
elseif KarniCrapConfig.AlwaysWater then
if KarniCrapConfig.WaterMax then
if waterList[itemID] > playerlevel - 10 then return true, "Water"
else return nil, "Water level too low" end
else
return true, "Water"
end
end
end
end
--[[ Health Potions ]]--
if ( KarniCrapConfig.AlwaysHealth or KarniCrapConfig.NeverHealth ) and HealingPotionList[itemID] then
if KarniCrapConfig.NeverHealth then
details = "Health Potion" return nil
elseif KarniCrapConfig.AlwaysHealth then
if KarniCrapConfig.HealthMax then
if KarniCrap_CheckMaxPotion(itemID, HealingPotionList) then return true
else return nil, "Health Potion too low" end
else
return true, "Health Potion"
end
end
end
--[[ Mana Potions ]]--
if ( KarniCrapConfig.AlwaysMana or KarniCrapConfig.NeverMana ) and ManaPotionList[itemID] then
if KarniCrapConfig.NeverMana then
return nil, "Mana Potion"
elseif KarniCrapConfig.AlwaysMana then
if KarniCrapConfig.ManaMax then
if KarniCrap_CheckMaxPotion(itemID, ManaPotionList) then return true
else return nil, "Mana Potion too low" end
else
return true, "Mana Potion"
end
end
end
--[[ Price ]]--
if lootValue then
if lootValue == 0 then return true, "Unvendorable item" end
if KarniCrapConfig.UseStackValue then lootValue = lootValue * lootStackCount end
--[[ Poor Items ]]--
if lootRarity == 0 and KarniCrapConfig.Poor and amount_poor > 0 then
if lootValue then
if lootValue >= amount_poor then return true, "Price above threshold"
else return nil, "Price below threshold" end
end
--[[ Common Items ]]--
elseif ( lootRarity == 1 and KarniCrapConfig.Common and amount_common > 0 ) then
if lootValue then
--if debug then echo("Common price filter, item value "..lootValue.." vs threshold "..amount_common) end
if lootValue >= amount_common then return true, "Price above threshold"
else return nil, "Price below threshold" end
end
end
end
-- passed or didn't qualify for filters
return true, "Looting: No filters apply"
end -- CheckLoot()
-- Dims echo the input boxes if poor isn't checked
function KarniCrap_CheckButtonPoor()
if KarniCrap_CBPoor:GetChecked() then
KarniCrapConfig.Poor = true;
KarniCrap_Poor_GoldInputBox:Show();
KarniCrap_Poor_GoldTexture:SetAlpha(1);
KarniCrap_Poor_SilverInputBox:Show();
KarniCrap_Poor_SilverTexture:SetAlpha(1);
KarniCrap_Poor_CopperInputBox:Show();
KarniCrap_Poor_CopperTexture:SetAlpha(1);
else
KarniCrapConfig.Poor = false;
KarniCrap_Poor_GoldInputBox:Hide();
KarniCrap_Poor_GoldTexture:SetAlpha(0.3);
KarniCrap_Poor_SilverInputBox:Hide();
KarniCrap_Poor_SilverTexture:SetAlpha(0.3);
KarniCrap_Poor_CopperInputBox:Hide();
KarniCrap_Poor_CopperTexture:SetAlpha(0.3);
end
end
-- Dims echo the input boxes if common isn't checked
function KarniCrap_CheckButtonCommon()
if KarniCrap_Tab1_CBCommon:GetChecked() then
KarniCrapConfig.Common = true;
KarniCrap_Tab1_CBCommonDesc_GoldInputBox:Show();
KarniCrap_Tab1_CBCommonDesc_GoldTexture:SetAlpha(1);
KarniCrap_Tab1_CBCommonDesc_SilverInputBox:Show();
KarniCrap_Tab1_CBCommonDesc_SilverTexture:SetAlpha(1);
KarniCrap_Tab1_CBCommonDesc_CopperInputBox:Show();
KarniCrap_Tab1_CBCommonDesc_CopperTexture:SetAlpha(1);
else
KarniCrapConfig.Common = false;
KarniCrap_Tab1_CBCommonDesc_GoldInputBox:Hide();
KarniCrap_Tab1_CBCommonDesc_GoldTexture:SetAlpha(0.3);
KarniCrap_Tab1_CBCommonDesc_SilverInputBox:Hide();
KarniCrap_Tab1_CBCommonDesc_SilverTexture:SetAlpha(0.3);
KarniCrap_Tab1_CBCommonDesc_CopperInputBox:Hide();
KarniCrap_Tab1_CBCommonDesc_CopperTexture:SetAlpha(0.3);
end
end
function KarniCrap_CheckMaxPotion(itemID, potion_list)
local next_potion_level, previous_value = nil
local unsorted_list = {}
local sorted_list = {}
local potion_level = potion_list[itemID]
local temp_list = {}
-- gets the unique levels from the potion list and sorts it
for k, v in pairs(potion_list) do
unsorted_list[v] = true
end
for k, v in pairs(unsorted_list) do
table.insert(sorted_list,k)
end
--
table.insert(sorted_list, 100) -- add a high max level to the end of the array so it won't crash when doing index + 1
table.sort(sorted_list)
-- just get the next highest level of potion
for i = 1, # sorted_list do
if potion_level == sorted_list[i] then
next_potion_level = sorted_list[i + 1]
break
end
end
if potion_level >= playerlevel or ( playerlevel > potion_level and playerlevel <= next_potion_level ) then
return true
else
return nil
end
end
function KarniCrap_CheckScroll(itemID, scroll_list)
local next_scroll_level
local sorted_list = {}
local scroll_level = scroll_list[itemID]
for id, value in pairs(scroll_list) do table.insert(sorted_list, value) end
table.insert(sorted_list, 100) -- add a high value to the end of the array so it won't crash when doing index+1
table.sort(sorted_list)
-- get the level of the next highest scroll of that type
for i = 1, 6 do
if scroll_level == sorted_list[i] then
next_scroll_level = sorted_list[i + 1]
break
end
end
if scroll_level >= playerlevel or ( playerlevel > scroll_level and playerlevel <= next_scroll_level ) then
return true
else
return nil
end
end
function KarniCrap_ScrollLevels(list)
local level_string = ""
local last_index = 1
local i = 1
local sorted_list = {}
for id, value in pairs(list) do table.insert(sorted_list, value) end
table.insert(sorted_list, 100) -- add a high value to the end of the array so it won't crash when doing index+1
table.sort(sorted_list)
for index = 1, # Scrolllevel_List do
-- this will leave 1 level of overlap when looting scrolls, so when a character hits 70 you can still loot the level 5 scrolls
-- this was done since there are no level VI scrolls in BC checking 'max' would cause you not to loot any scrolls
if sorted_list[index] >= playerlevel or ( playerlevel > sorted_list[index] and playerlevel <= sorted_list[index + 1] ) then
if level_string == "" then
level_string = Scrolllevel_List[index]
else
level_string = level_string..","..Scrolllevel_List[index]
end
end
last_index = index
end
return level_string
end
function KarniCrap_CBMaxScrolls()
if (KarniCrap_Scrolls_CBMaxScrolls:GetChecked()) then
-- scrollmax should set the scrolls to be character level usable and above
-- if character is lvl 60, scrolls included should be IV-VI
KarniCrapConfig.ScrollMax = true
KarniCrap_Scrolls_CBScrollAgility_Text:SetText("Loot |cffffffff[Agility "..KarniCrap_ScrollLevels(ScrollList_Agility).."]|r")
KarniCrap_Scrolls_CBScrollIntellect_Text:SetText("Loot |cffffffff[Intellect "..KarniCrap_ScrollLevels(ScrollList_Intellect).."]|r")
KarniCrap_Scrolls_CBScrollProtection_Text:SetText("Loot |cffffffff[Protection "..KarniCrap_ScrollLevels(ScrollList_Protection).."]|r")
KarniCrap_Scrolls_CBScrollSpirit_Text:SetText("Loot |cffffffff[Spirit "..KarniCrap_ScrollLevels(ScrollList_Spirit).."]|r")
KarniCrap_Scrolls_CBScrollStamina_Text:SetText("Loot |cffffffff[Stamina "..KarniCrap_ScrollLevels(ScrollList_Stamina).."]|r")
KarniCrap_Scrolls_CBScrollStrength_Text:SetText("Loot |cffffffff[Strength "..KarniCrap_ScrollLevels(ScrollList_Strength).."]|r")
else
KarniCrapConfig.ScrollMax = false
KarniCrap_Scrolls_CBScrollAgility_Text:SetText("Loot |cffffffff[Agility I - VII]")
KarniCrap_Scrolls_CBScrollIntellect_Text:SetText("Loot |cffffffff[Intellect I - VII]")
KarniCrap_Scrolls_CBScrollProtection_Text:SetText("Loot |cffffffff[Protection I - VII]")
KarniCrap_Scrolls_CBScrollSpirit_Text:SetText("Loot |cffffffff[Spirit I - VII]")
KarniCrap_Scrolls_CBScrollStamina_Text:SetText("Loot |cffffffff[Stamina I - VII]")
KarniCrap_Scrolls_CBScrollStrength_Text:SetText("Loot |cffffffff[Strength I - VII]")
end
end
function KarniCrap_RBHealth()
if (KarniCrap_Potions_RBHealth1:GetChecked()) then
KarniCrapConfig.NeverHealth = true;
KarniCrapConfig.AlwaysHealth = false;
KarniCrap_Potions_RBHealth2:SetChecked(nil);
KarniCrap_Potions_CBHealthMax:SetAlpha(0.3);
KarniCrap_Potions_CBHealthMax:Disable();
KarniCrap_Potions_RBHealth1_Text:SetText("|cffffffffNever|r loot health potions (crap)");
KarniCrap_Potions_RBHealth2_Text:SetText("Always loot health potions");
elseif (KarniCrap_Potions_RBHealth2:GetChecked()) then
KarniCrapConfig.NeverHealth = false;
KarniCrapConfig.AlwaysHealth = true;
KarniCrap_Potions_RBHealth1:SetChecked(nil);
KarniCrap_Potions_CBHealthMax:SetAlpha(1);
KarniCrap_Potions_CBHealthMax:Enable();
KarniCrap_Potions_RBHealth1_Text:SetText("Never loot health potions (crap)");
KarniCrap_Potions_RBHealth2_Text:SetText("|cffffffffAlways|r loot health potions");
else
KarniCrapConfig.NeverHealth = false;
KarniCrapConfig.AlwaysHealth = false;
KarniCrap_Potions_CBHealthMax:SetAlpha(0.3);
KarniCrap_Potions_CBHealthMax:Disable();
KarniCrap_Potions_RBHealth1_Text:SetText("Never loot health potions (crap)");
KarniCrap_Potions_RBHealth2_Text:SetText("Always loot health potions");
end
end
function KarniCrap_RBMana()
if KarniCrap_Potions_RBMana1:GetChecked() then
KarniCrapConfig.NeverMana = true;
KarniCrapConfig.AlwaysMana = false;
KarniCrap_Potions_CBManaMax:SetAlpha(0.3);
KarniCrap_Potions_CBManaMax:Disable();
KarniCrap_Potions_RBMana1_Text:SetText("|cffffffffNever|r loot mana potions (crap)");
KarniCrap_Potions_RBMana2_Text:SetText("Always loot mana potions");
elseif KarniCrap_Potions_RBMana2:GetChecked() then
KarniCrapConfig.NeverMana = false;
KarniCrapConfig.AlwaysMana = true;
KarniCrap_Potions_CBManaMax:SetAlpha(1);
KarniCrap_Potions_CBManaMax:Enable();
KarniCrap_Potions_RBMana1_Text:SetText("Never loot mana potions (crap)");
KarniCrap_Potions_RBMana2_Text:SetText("|cffffffffAlways|r loot mana potions");
else
KarniCrapConfig.NeverMana = false;
KarniCrapConfig.AlwaysMana = false;
KarniCrap_Potions_CBManaMax:SetAlpha(0.3);
KarniCrap_Potions_CBManaMax:Disable();
KarniCrap_Potions_RBMana1_Text:SetText("Never loot mana potions (crap)");
KarniCrap_Potions_RBMana2_Text:SetText("Always loot mana potions");
end
end
-- Dims echo the food subselections if the checkbox isn't checked
function KarniCrap_RBFood()
if KarniCrap_Consumables_RBFood1:GetChecked() then
KarniCrapConfig.AlwaysFood = false;
KarniCrapConfig.NeverFood = true;
KarniCrap_Consumables_CBFoodMax:SetAlpha(0.3);
KarniCrap_Consumables_CBFoodMax:Disable();
KarniCrap_Consumables_RBFood1_Text:SetText("|cffffffffNever|r loot food (crap)");
KarniCrap_Consumables_RBFood2_Text:SetText("Always loot food");
elseif KarniCrap_Consumables_RBFood2:GetChecked() then
KarniCrapConfig.AlwaysFood = true;
KarniCrapConfig.NeverFood = false;
KarniCrap_Consumables_CBFoodMax:SetAlpha(1);
KarniCrap_Consumables_CBFoodMax:Enable();
KarniCrap_Consumables_RBFood1_Text:SetText("Never loot food (crap)");
KarniCrap_Consumables_RBFood2_Text:SetText("|cffffffffAlways|r loot food");
else
KarniCrapConfig.AlwaysFood = false;
KarniCrapConfig.NeverFood = false;
KarniCrap_Consumables_CBFoodMax:SetAlpha(0.3);
KarniCrap_Consumables_CBFoodMax:Disable();
KarniCrap_Consumables_RBFood1_Text:SetText("Never loot food (crap)");
KarniCrap_Consumables_RBFood2_Text:SetText("Always loot food");
end
end
-- Dims echo the water subselections if the checkbox isn't checked
function KarniCrap_RBWater()
if KarniCrap_Consumables_RBWater1:GetChecked() then
KarniCrapConfig.NeverWater = true;
KarniCrapConfig.AlwaysWater = false;
KarniCrap_Consumables_CBWaterMax:SetAlpha(0.3);
KarniCrap_Consumables_CBWaterMax:Disable();
KarniCrap_Consumables_RBWater1_Text:SetText("|cffffffffNever|r loot water (crap)");
KarniCrap_Consumables_RBWater2_Text:SetText("Always loot water");
elseif KarniCrap_Consumables_RBWater2:GetChecked() then
KarniCrapConfig.NeverWater = false;
KarniCrapConfig.AlwaysWater = true;
KarniCrap_Consumables_CBWaterMax:SetAlpha(1);
KarniCrap_Consumables_CBWaterMax:Enable();
KarniCrap_Consumables_RBWater1_Text:SetText("Never loot water (crap)");
KarniCrap_Consumables_RBWater2_Text:SetText("|cffffffffAlways|r loot water");
else
KarniCrapConfig.NeverWater = false;
KarniCrapConfig.AlwaysWater = false;
KarniCrap_Consumables_CBWaterMax:SetAlpha(0.3);
KarniCrap_Consumables_CBWaterMax:Disable();
KarniCrap_Consumables_RBWater1_Text:SetText("Never loot water (crap)");
KarniCrap_Consumables_RBWater2_Text:SetText("Always loot water");
end
end
function KarniCrap_CalcPoorThreshold()
amount_poor =
KarniCrapConfig.PoorThreshold_Gold * 10000 +
KarniCrapConfig.PoorThreshold_Silver * 100 +
KarniCrapConfig.PoorThreshold_Copper;
end