diff --git a/Scrap.toc b/Scrap.toc index 661ba10..09fee86 100644 --- a/Scrap.toc +++ b/Scrap.toc @@ -1,5 +1,5 @@ -## Interface: 11305 -## Title: |cffFFDE73Scrap|r +## Interface: 90002 +## Title: Scrap ## Notes: Sells all your junk at the merchant. ## Author: Jaliborc (João Cardoso) diff --git a/addons/merchant/button.lua b/addons/merchant/button.lua index f05a8f3..3b9ff1f 100644 --- a/addons/merchant/button.lua +++ b/addons/merchant/button.lua @@ -15,7 +15,7 @@ along with the addon. If not, see . This file is part of Scrap. --]] -local Button = Scrap:NewModule('Merchant', CreateFrame('Button', nil, MerchantBuyBackItem), 'MutexDelay-1.0') +local Button = Scrap:NewModule('Merchant', CreateFrame('Button', nil, MerchantBuyBackItem)) local L = LibStub('AceLocale-3.0'):GetLocale('Scrap') @@ -68,20 +68,12 @@ function Button:OnMerchant() Scrap.Tutorials:Start() end - self:RegisterEvent('BAG_UPDATE_DELAYED', 'OnBagUpdate') + self:RegisterEvent('BAG_UPDATE_DELAYED', 'UpdateState') self:RegisterSignal('LIST_CHANGED', 'UpdateState') self:UpdatePosition() self:UpdateState() end -function Button:OnBagUpdate() - if self.saleTotal then - self:Delay(0.3, 'Sell') - else - self:UpdateState() - end -end - function Button:OnClose() self:UnregisterEvent('BAG_UPDATE_DELAYED') self:UnregisterSignal('LIST_CHANGED') @@ -190,36 +182,38 @@ end --[[ Actions ]]-- function Button:Sell() - self.saleTotal = self.saleTotal or self:GetReport() - + local total = self:GetReport() local count = 0 + + print("Selling your scraps. This might take a few seconds.") + for bag, slot, id in Scrap:IterateJunk() do - local _, _, locked = GetContainerItemInfo(bag, slot) - if not locked then - local value = select(11, GetItemInfo(id)) or 0 - if value > 0 then - UseContainerItem(bag, slot) - elseif Scrap.sets.destroy then - PickupContainerItem(bag, slot) - DeleteCursorItem() - end - - if count < 11 then - count = count + 1 - else - break - end + if not Scrap.sets.safe or count < 200 then + count = count + 1 + else + break end - end - local remaining = self:GetReport() - if remaining == 0 or Scrap.sets.safe then - if count > 0 then - Scrap:PrintMoney(L.SoldJunk, self.saleTotal - remaining) + local value = select(11, GetItemInfo(id)) or 0 + if value > 0 then + -- Selling after modulo 12 delay based on count (number of calls/sec divided by 12 ? + C_Timer.After(count%14, function() UseContainerItem(bag, slot) end) + + -- Selling after a random delay + --C_Timer.After(math.random() * 6, function() UseContainerItem(bag, slot) end) + + -- Selling as fast as possible + --UseContainerItem(bag, slot) + elseif Scrap.sets.destroy then + PickupContainerItem(bag, slot) + DeleteCursorItem() end - - self.saleTotal = nil + end + + --if count > 0 then + --Scrap:PrintMoney(L.SoldJunk, total - self:GetReport()) + --end end function Button:GetReport() @@ -228,9 +222,11 @@ function Button:GetReport() for bag, slot, id in Scrap:IterateJunk() do local _, count, locked, quality = GetContainerItemInfo(bag, slot) + local value = select(11, GetItemInfo(id)) or 0 + if not locked then qualities[quality] = (qualities[quality] or 0) + count - total = total + count * (select(11, GetItemInfo(id)) or 0) + total = total + value * count end end