local name, addon = ... |
local parentName = addon['parentName'] or "BrokerPack" |
local childName = "zz_AltMail" |
local LibBabble = LibStub("LibBabble-Inventory-3.0") |
local LibBabbleDB = LibBabble:GetLookupTable() |
local LibBabbleDBR = LibBabble:GetReverseLookupTable() |
local defaults = { |
} |
|
local options = { |
} |
|
local db |
local realm = GetRealmName() |
|
local function GetUName() |
local name = UnitName("player") |
return name.."-"..realm |
end |
local sendouttable = { |
['Tirion'] = { |
['Trade Goods'] = { |
['Leather'] = { |
['Rilgalyco-Tirion'] = { |
['order'] = 1, |
['skip'] = {"Rilgamon-Tirion"}, |
}, |
}, |
['Cloth'] = { |
['Ritalein-Tirion'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Elemental'] = { |
['Rilgana-Tirion'] = { |
['order'] = 1, |
['skip'] = {"Ritalein-Tirion"}, |
}, |
}, |
['Cooking'] = { |
['Rilgana-Tirion'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Enchanting'] = { |
['Rilgana-Tirion'] = { |
['order'] = 1, |
['skip'] = {"Ritalein-Tirion","Rilgalyco-Tirion"}, |
}, |
}, |
}, |
['Armor'] = { |
['Plate'] = { |
['Drilane-Durotan'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Cloth'] = { |
['Drilane-Durotan'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Leather'] = { |
['Drilane-Durotan'] = { |
['order'] = 1, |
['skip'] = {"Rilgalyco-Tirion"}, |
}, |
}, |
['Miscellaneous'] = { |
['Rilgana-Tirion'] = { |
['order'] = 1, |
['skip'] = {"Ritalein-Tirion"}, |
}, |
}, |
} |
}, |
['Thrall'] = { |
['Trade Goods'] = { |
['Cloth'] = { |
['Rosander-Thrall'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Enchanting'] = { |
['Gurnsey-Thrall'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Cooking'] = { |
['Rosander-Thrall'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
}, |
}, |
['Arygos'] = { |
['Trade Goods'] = { |
['Elemental'] = { |
['Pastorella-Arygos'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Cloth'] = { |
['Pastorella-Arygos'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Cooking'] = { |
['Pastorella-Arygos'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
}, |
['Armor'] = { |
['Plate'] = { |
['Pastorella-Arygos'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
['Cloth'] = { |
['Pastorella-Arygos'] = { |
['order'] = 1, |
['skip'] = {}, |
}, |
}, |
|
} |
} |
} |
local cTip = CreateFrame("GameTooltip",name.."Tooltip",nil,"GameTooltipTemplate") |
local function IsSoulbound(bag, slot) |
cTip:SetOwner(UIParent, "ANCHOR_NONE") |
cTip:SetBagItem(bag, slot) |
cTip:Show() |
for i = 1,cTip:NumLines() do |
if(_G[name.."TooltipTextLeft"..i]:GetText()==ITEM_SOULBOUND) then |
cTip:Hide() |
return true |
end |
end |
cTip:Hide() |
return false |
end |
local function GetDestination(bag,slot) |
if(IsSoulbound(bag, slot)) then return end |
local texture, itemCount, locked, quality, readable, lootable, itemLink, isFiltered = GetContainerItemInfo(bag, slot) |
if(itemLink and quality<4 and quality>0) then |
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemLink) |
if(itemName) then |
itemType = LibBabbleDBR[itemType] |
itemSubType = LibBabbleDBR[itemSubType] |
if(sendouttable[realm] and sendouttable[realm][itemType] and sendouttable[realm][itemType][itemSubType]) then |
local tmp = sendouttable[realm][itemType][itemSubType] |
sort(tmp, function(a,b) |
return (a['order'] or 0) < (b['order'] or 0) |
end) |
for dest,destInfo in pairs(tmp) do |
local doSkip = false |
for _,skip in ipairs(destInfo['skip']) do |
if(skip == GetUName()) then doSkip=true end |
end |
if(not doSkip) then |
return dest |
end |
end |
end |
end |
end |
end |
local function GetNumMailboxItems() |
local count = 0 |
for i = 1, ATTACHMENTS_MAX_SEND do |
local name, texture, count, quality = GetInboxItem(i) |
if(name) then |
count = count + 1 |
end |
end |
return count |
end |
local function sout(target) |
SendMail(target, "Post",nil) |
SELECTED_CHAT_FRAME:AddMessage("Sending "..target) |
end |
local sf_new = function() |
if(not SendMailFrame:IsVisible()) then return end |
local a,b = 0,0 |
local tab = {} |
while(a<=NUM_BAG_SLOTS) do |
b = 1 |
while(b<=GetContainerNumSlots(a)) do |
local texture, itemCount, locked, quality, readable, lootable, itemLink, isFiltered = GetContainerItemInfo(a, b) |
if(itemLink) then |
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, |
itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemLink) |
if(itemName) then |
tab[itemType] = tab[itemType] or {} |
tab[itemType][itemSubType] = tab[itemType][itemSubType] or {} |
tab[itemType][itemSubType][#tab[itemType][itemSubType] + 1] = { |
['bag'] = a, |
['slot'] = b, |
} |
end |
end |
b = b + 1 |
end |
a = a + 1 |
end |
local mailout = {} |
for k,v in pairs(tab) do |
local t = LibBabbleDBR[k] |
if(t) then |
for c,d in pairs(v) do |
local target |
local count = 0 |
local s = LibBabbleDBR[c] |
if(s) then |
db['itemdb'][realm] = db['itemdb'][realm] or {} |
db['itemdb'][realm][t] = db['itemdb'][realm][t] or { |
['default'] = { |
[GetUName()] = { |
['order'] = 1, |
['skip'] = {}, |
} |
} |
} |
db['itemdb'][realm][t][s] = db['itemdb'][realm][t][s] or CopyTable(db['itemdb'][realm][t]['default']) |
if(sendouttable[realm]) then |
if(sendouttable[realm][t]) then |
if(sendouttable[realm][t][s]) then |
for g,h in pairs(d) do |
target = GetDestination(tonumber(h['bag']),tonumber(h['slot'])) |
if(target) then |
mailout[target] = mailout[target] or {} |
mailout[target][#mailout[target] + 1] = { |
['bag'] = h['bag'], |
['slot'] = h['slot'] |
} |
end |
end |
end |
end |
end |
end |
end |
end |
end |
mailout[GetUName()] = nil |
for k,v in pairs(mailout) do |
local c = 0 |
for a,b in pairs(v) do |
c = c + 1 |
UseContainerItem(tonumber(b['bag']),tonumber(b['slot'])) |
if(c >= 12) then |
break |
end |
end |
if(c > 0) then |
sout(k) |
break |
end |
end |
end |
SendMailFrame:HookScript("OnShow", function() |
C_Timer.After(0.25, sf_new) |
end) |
|
local function OnEvent(self, event, arg1, ...) |
if(event == "MAIL_SEND_SUCCESS") then |
C_Timer.After(1,sf_new) |
end |
end |
local function OnText(message) |
addon['OnText'](childName, message) |
end |
|
local function getPref(pref) |
return db[pref[#pref]] |
end |
|
local function setPref(pref,value) |
db[pref[#pref]] = value |
end |
local function getPrefI(pref) |
return db['itemdb'][realm][pref[#pref-2]][pref[#pref-1]][pref[#pref]] |
end |
|
local function setPrefI(pref,value) |
db['itemdb'][realm][pref[#pref-2]][pref[#pref-1]][pref[#pref]] = value |
end |
local function updatePrefs() |
local p = addon['options']['args']['Types']['args'] |
for k, v in pairs(db['itemdb'][realm]) do |
p[k] = { |
['type'] = 'group', |
['childGroups'] = 'tree', |
['name'] = k, |
['args'] = {}, |
} |
for a,b in pairs(v) do |
p[k]['args'][a]={ |
['type'] = 'group', |
['name'] = a, |
['get'] = getPrefI, |
['set'] = setPrefI, |
['args'] = {}, |
} |
local c = p[k]['args'][a]['args'] |
for d,e in pairs(b) do |
c[d] = { |
['name'] = d, |
['type'] = "group", |
['args'] = {}, |
} |
local f = c[d]['args'] |
|
end |
end |
end |
end |
local function init() |
realm = GetRealmName() |
options = addon['InitConfig'](addon, childName, true, { |
['type'] = "data source", |
}, getPref, setPref) |
db = addon['db']['profile'][childName] |
db['itemdb'] = db['itemdb'] or {} |
db['itemdb'][realm] = db['itemdb'][realm] or {} |
addon['AddConfigMenu'](addon,{ |
['name'] = "Types", |
['order'] = 2, |
['childGroups'] = 'tree', |
['menuGet'] = getPref, |
['menuSet'] = setPref, |
}, addon['options']) |
updatePrefs() |
end |
addon['startup'](addon, name, childName, init, true, defaults) |
addon['RegisterFunc']({'MAIL_SEND_SUCCESS'},"OnEvent", OnEvent) |