/Tukui/modules/loot/merchant.lua

http://github.com/Asphyxia/Tukui · Lua · 88 lines · 84 code · 3 blank · 1 comment · 28 complexity · 9b99fcb51e23ac53aa04142c78aaef82 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. local filter = {
  3. [6289] = true, -- Raw Longjaw Mud Snapper
  4. [6291] = true, -- Raw Brilliant Smallfish
  5. [6308] = true, -- Raw Bristle Whisker Catfish
  6. [6309] = true, -- 17 Pound Catfish
  7. [6310] = true, -- 19 Pound Catfish
  8. [41808] = true, -- Bonescale Snapper
  9. [42336] = true, -- Bloodstone Band
  10. [42337] = true, -- Sun Rock Ring
  11. [43244] = true, -- Crystal Citrine Necklace
  12. [43571] = true, -- Sewer Carp
  13. [43572] = true, -- Magic Eater
  14. [53062] = true, -- Sharptooth
  15. [53069] = true, -- Murglesnout
  16. }
  17. local f = CreateFrame("Frame")
  18. f:SetScript("OnEvent", function()
  19. if C["merchant"].sellgrays or C["merchant"].sellmisc then
  20. local c = 0
  21. for b=0,4 do
  22. for s=1,GetContainerNumSlots(b) do
  23. local l,lid = GetContainerItemLink(b, s), GetContainerItemID(b, s)
  24. if l and lid then
  25. local p = select(11, GetItemInfo(l))*select(2, GetContainerItemInfo(b, s))
  26. if C["merchant"].sellgrays and select(3, GetItemInfo(l))==0 and p > 0 then
  27. UseContainerItem(b, s)
  28. PickupMerchantItem()
  29. c = c+p
  30. end
  31. if C["merchant"].sellmisc and filter[ lid ] then
  32. UseContainerItem(b, s)
  33. PickupMerchantItem()
  34. c = c+p
  35. end
  36. end
  37. end
  38. end
  39. if c>0 then
  40. local g, s, c = math.floor(c/10000) or 0, math.floor((c%10000)/100) or 0, c%100
  41. DEFAULT_CHAT_FRAME:AddMessage(L.merchant_trashsell.." |cffffffff"..g..L.goldabbrev.." |cffffffff"..s..L.silverabbrev.." |cffffffff"..c..L.copperabbrev..".",255,255,0)
  42. end
  43. end
  44. if not IsShiftKeyDown() then
  45. if CanMerchantRepair() and C["merchant"].autorepair then
  46. local cost, possible = GetRepairAllCost()
  47. if C["merchant"].guildrepair then
  48. if (IsInGuild()) and (CanGuildBankRepair()) then
  49. if cost <= GetGuildBankWithdrawMoney() then
  50. guildRepairFlag = 1
  51. end
  52. end
  53. end
  54. if cost>0 then
  55. if possible then
  56. local c = cost%100
  57. local s = math.floor((cost%10000)/100)
  58. local g = math.floor(cost/10000)
  59. if guildRepairFlag == 1 then
  60. RepairAllItems(1)
  61. DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Repaired using guild bank.|r")
  62. else
  63. RepairAllItems()
  64. DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Repaired using personal funds.|r")
  65. end
  66. DEFAULT_CHAT_FRAME:AddMessage(L.merchant_repaircost.." |cffffffff"..g..L.goldabbrev.." |cffffffff"..s..L.silverabbrev.." |cffffffff"..c..L.copperabbrev..".",255,255,0)
  67. else
  68. DEFAULT_CHAT_FRAME:AddMessage(L.merchant_repairnomoney,255,0,0)
  69. end
  70. end
  71. end
  72. end
  73. end)
  74. f:RegisterEvent("MERCHANT_SHOW")
  75. -- buy max number value with alt
  76. local savedMerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick
  77. function MerchantItemButton_OnModifiedClick(self, ...)
  78. if ( IsAltKeyDown() ) then
  79. local maxStack = select(8, GetItemInfo(GetMerchantItemLink(self:GetID())))
  80. if ( maxStack and maxStack > 1 ) then
  81. BuyMerchantItem(self:GetID(), GetMerchantItemMaxStack(self:GetID()))
  82. end
  83. end
  84. savedMerchantItemButton_OnModifiedClick(self, ...)
  85. end