diff --git a/core.lua b/core.lua index 0f5b992..05cb9a4 100755 --- a/core.lua +++ b/core.lua @@ -5,7 +5,11 @@ local events = child['events'] local db, player local L = LibStub("AceLocale-3.0"):GetLocale(childName, true) LibStub("zzHelper"):Embed(child) -child['statusItem'] = {} +child['statusItem'] = {} +local NUM_BAG_SLOTS = NUM_BAG_SLOTS +local GetContainerItemLink = GetContainerItemLink +local GetContainerItemInfo = GetContainerItemInfo + local function prepareDB() db = addon['db']['profile'][childName] child['db'] = db @@ -28,7 +32,68 @@ local function getGBLimit() end return amount end -function events:MERCHANT_SHOW() +local function itemInfo(id) + local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id) + if(itemName) then + return { + ['itemId'] = id, + ['itemName'] = itemName, + ['itemLink'] = itemLink, + ['itemRarity'] = itemRarity, + ['itemLevel'] = itemLevel, + ['itemMinLevel'] = itemMinLevel, + ['itemType'] = itemType, + ['itemSubType'] = itemSubType, + ['itemStackCount'] = itemStackCount, + ['itemEquipLoc'] = itemEquipLoc, + ['itemTexture'] = itemTexture, + ['itemSellPrice'] = itemSellPrice + } + end +end +local function CheckGrey(dont) + local info,i = {},{} + local a = 0 + local numberOfSlots,link,id + local earnedMoney = 0 + while(a<=NUM_BAG_SLOTS) do + numberOfSlots = C_Container.GetContainerNumSlots(a) + local b = 1 + while(b<=numberOfSlots) do + local item = ItemLocation:CreateFromBagAndSlot(a, b) + if(item:IsValid()) then +-- link = C_Container.GetContainerItemLink(a, b) + id = C_Item.GetItemID(item) + info = itemInfo(id) + if(info) then + if(info['itemRarity'] == 0) then + if(info['itemSellPrice'] and info['itemSellPrice'] > 0) then + local cinfo = C_Container.GetContainerItemInfo(a, b) + if(cinfo['stackCount']) then + if(not dont) then + print(L['solditem'](C_Item.GetItemLink(item), info['itemSellPrice'])) + end + earnedMoney = earnedMoney + info['itemSellPrice'] * cinfo['stackCount'] + C_Container.PickupContainerItem(a, b) + PickupMerchantItem() + end + end + end + end + end + b = b + 1 + end + a = a + 1 + end + if(earnedMoney > 0 and not dont) then + print(L['earnedmoney'](earnedMoney)) + end + if(earnedMoney>0 and not dont) then + C_Timer.After(1,function() CheckGrey(true) end) + end +end + +local function MERCHANT_SHOW() if(CanMerchantRepair()) then local m = GetMoney() local r = GetRepairAllCost() @@ -60,6 +125,9 @@ function events:MERCHANT_SHOW() db['repairstats'][player] = db['repairstats'][player] + r end end + if(db['sellgrey']) then + CheckGrey() + end end function child:pickColor(v) local col = 'ffffff' @@ -102,6 +170,9 @@ function events:UPDATE_INVENTORY_DURABILITY() end events.UPDATE_INVENTORY_ALERTS = events.UPDATE_INVENTORY_DURABILITY events.UNIT_INVENTORY_CHANGED = events.UPDATE_INVENTORY_DURABILITY +local function MFOpen(...) + MERCHANT_SHOW() +end child['specs'] = { ['name'] = childName, ['sv'] = true, @@ -122,5 +193,6 @@ function events:PLAYER_ENTERING_WORLD(event) child:UnregisterEvent('PLAYER_ENTERING_WORLD') player = format("%s-%s", UnitFullName("player")) events.UPDATE_INVENTORY_DURABILITY() + child:RegisterOpen(5, MFOpen) end child:NewAddOn(...) \ No newline at end of file