198 lines
5.4 KiB
Lua
Executable File
198 lines
5.4 KiB
Lua
Executable File
local addonName, addon = ...
|
|
local childName = addon['childName']
|
|
local child = addon[childName]
|
|
local events = child['events']
|
|
local db, player
|
|
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
|
|
LibStub("zzHelper"):Embed(child)
|
|
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
|
|
addon['callbacks']:Fire(format("Init%s", childName))
|
|
end
|
|
|
|
local slotNames = {
|
|
"HeadSlot","NeckSlot","ShoulderSlot","BackSlot","ChestSlot","ShirtSlot","TabardSlot",
|
|
"WristSlot","HandsSlot","WaistSlot","LegsSlot","FeetSlot","Finger0Slot","Finger1Slot",
|
|
"Trinket0Slot","Trinket1Slot","MainHandSlot","SecondaryHandSlot",
|
|
"Bag0Slot","Bag1Slot","Bag2Slot","Bag3Slot"
|
|
}
|
|
local function getGBLimit()
|
|
local amount = GetGuildBankWithdrawMoney()
|
|
local guildBankMoney = GetGuildBankMoney()
|
|
if ( amount == -1 ) then
|
|
amount = guildBankMoney
|
|
else
|
|
amount = min(amount, guildBankMoney)
|
|
end
|
|
return amount
|
|
end
|
|
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()
|
|
local gbr = false
|
|
if(db['guildbankrepair']) then
|
|
if(CanGuildBankRepair()) then
|
|
gbr = true
|
|
end
|
|
end
|
|
if(r > 0 and (m > r or gbr) and db['autorepair']) then
|
|
if(gbr) then
|
|
if(getGBLimit() >= r) then
|
|
RepairAllItems(1)
|
|
print(L['repaircostgb'](r))
|
|
else
|
|
if(m > r) then
|
|
RepairAllItems()
|
|
print(L['repaircost'](r))
|
|
else
|
|
print(child:colorize(L['Money low'],"ff0000"))
|
|
end
|
|
end
|
|
else
|
|
RepairAllItems()
|
|
print(L['repaircost'](r))
|
|
end
|
|
db['repairstats'] = db['repairstats'] or {}
|
|
db['repairstats'][player] = db['repairstats'][player] or 0
|
|
db['repairstats'][player] = db['repairstats'][player] + r
|
|
end
|
|
end
|
|
if(db['sellgrey']) then
|
|
CheckGrey()
|
|
end
|
|
end
|
|
function child:pickColor(v)
|
|
local col = 'ffffff'
|
|
if(v > 90) then
|
|
col = '00ff00' -- grün
|
|
elseif(v > 40) then
|
|
col = 'ffff00' -- gelb
|
|
elseif(v > 0) then
|
|
col = 'ff9900' -- orange
|
|
else
|
|
col = 'ff0000' -- rot
|
|
end
|
|
return col
|
|
end
|
|
function events:UPDATE_INVENTORY_DURABILITY()
|
|
local percent = 0
|
|
local total = 0
|
|
local cur = 0
|
|
local lowest = 100
|
|
|
|
local statusItem = child['statusItem']
|
|
wipe(statusItem)
|
|
for k,v in pairs(slotNames) do
|
|
local current, maximum = GetInventoryItemDurability(GetInventorySlotInfo(v))
|
|
if(maximum) then
|
|
total = total + maximum
|
|
cur = cur + current
|
|
statusItem[v] = child:round(current / (maximum/100),0)
|
|
lowest = min(statusItem[v], lowest)
|
|
end
|
|
end
|
|
|
|
if(db['showlowest']) then
|
|
percent = lowest
|
|
else
|
|
percent = child:round(cur / (total/100),0)
|
|
end
|
|
percent = child:colorize(percent, child:pickColor(percent))
|
|
child:OnText(childName, format("%s %%", percent))
|
|
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,
|
|
['cfg'] = true,
|
|
['cfgReset'] = prepareDB,
|
|
['ldb'] = child['ldb'],
|
|
['defaults'] = {
|
|
['profile'] = {
|
|
[childName] = {
|
|
["autorepair"] = true,
|
|
["listall"] = true,
|
|
["showlowest"] = true,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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(...) |