potions module
This commit is contained in:
parent
9c668e3454
commit
3a2e046a41
2 changed files with 232 additions and 357 deletions
|
@ -68,20 +68,11 @@ local defaults = {
|
|||
guildXPMarks = { },
|
||||
}
|
||||
}
|
||||
local potList = {
|
||||
["a"] = 58146, -- Golemblood
|
||||
["b"] = 58145, -- Tol'vir
|
||||
["c"] = 58090, -- Earthen
|
||||
["d"] = 58091, -- Volcanic
|
||||
["e"] = 57194, -- Concentration
|
||||
["f"] = 57192, -- Mythical
|
||||
}
|
||||
|
||||
core.guildList = {}
|
||||
core.rollTally = {}
|
||||
core.rollTimer = false
|
||||
core.hallowBuff = nil
|
||||
core.mailQueue = {} -- used in /atlt pots
|
||||
|
||||
function core:OnInitialize()
|
||||
self.db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
|
||||
|
@ -123,38 +114,18 @@ function core:OnEnable()
|
|||
if (self.db.profile.officerPhone) then
|
||||
self:RegisterEvent("CHAT_MSG_OFFICER");
|
||||
end
|
||||
self:RegisterEvent("MAIL_SHOW", "MailQueueCheck");
|
||||
self:RegisterEvent("MAIL_SUCCESS", "MailQueueCheck");
|
||||
self:RegisterEvent("PLAYER_ENTERING_WORLD", "ZoneChange");
|
||||
self:RegisterEvent("ZONE_CHANGED", "ZoneChange");
|
||||
self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "ZoneChange");
|
||||
self:RegisterEvent("PLAYER_DIFFICULTY_CHANGED", "ZoneChange");
|
||||
self:RegisterEvent("CHAT_MSG_LOOT")
|
||||
self:RegisterEvent("UNIT_AURA")
|
||||
self:RegisterEvent('GUILDBANKFRAME_OPENED')
|
||||
|
||||
self:SecureHook("TargetUnit")
|
||||
|
||||
if RaidBuffStatus then
|
||||
self:SecureHook(RaidBuffStatus, "SetupFrames", "SetupRBS")
|
||||
end
|
||||
|
||||
if Prat then
|
||||
self:SetupPrat()
|
||||
end
|
||||
|
||||
-- self:ScheduleTimer("SetupAddonDebug", 3)
|
||||
end
|
||||
|
||||
function core:OnDisable()
|
||||
self:UnregisterAllEvents()
|
||||
self:UnhookAll()
|
||||
self.guildHook = false
|
||||
self.achieveHook = false
|
||||
self.eotsHook = false
|
||||
self.consolidateHook = false
|
||||
end
|
||||
|
||||
function core:SlashProcess(msg)
|
||||
if msg == "debug" then
|
||||
self:BugInit()
|
||||
|
@ -188,41 +159,6 @@ function core:SlashProcess(msg)
|
|||
self:RaidDump("---")
|
||||
elseif msg == "combatlog" or msg == "cl" then
|
||||
CombatLogClearEntries()
|
||||
elseif msg:match("^pots ") then
|
||||
-- get all guild members
|
||||
for i=1,GetNumGuildMembers() do
|
||||
local name, rank = GetGuildRosterInfo(i)
|
||||
name = name:lower()
|
||||
if rank == "Member" or rank == "Officer" or rank == "Guild Master" then
|
||||
if self.mailQueue[name] == nil then
|
||||
self.mailQueue[name] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
-- parse
|
||||
msg:gsub("([^%d%s]+)(%d+)(%w)", function(name, ct, type)
|
||||
local typeRef = potList[type]
|
||||
name = name:lower()
|
||||
ct = tonumber(ct)
|
||||
if typeRef and ct then
|
||||
for i,_ in pairs(self.mailQueue) do
|
||||
if i:match("^"..name) then
|
||||
self.mailQueue[i][typeRef] = ct
|
||||
print(format("Queued %dx |Hitem:%d|h[%s]|h for %s", ct, typeRef, GetItemInfo("item:"..typeRef), i))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
-- cleanup array
|
||||
for name,data in pairs(self.mailQueue) do
|
||||
local ct = 0
|
||||
for i,v in pairs(data) do
|
||||
ct = ct + v
|
||||
end
|
||||
if ct == 0 then
|
||||
self.mailQueue[name] = nil
|
||||
end
|
||||
end
|
||||
elseif msg == "markxp" then
|
||||
-- write all current
|
||||
local db = self.db.profile.guildXPMarks
|
||||
|
@ -502,22 +438,6 @@ function core:CHAT_MSG_SYSTEM(_, message, source)
|
|||
end
|
||||
|
||||
|
||||
function core:FlaskCheck()
|
||||
local now = GetTime()
|
||||
for i=1,GetNumRaidMembers() do
|
||||
for j=1,32 do
|
||||
local player = UnitName("raid"..i)
|
||||
name, _, _, _, _, _, expires = UnitAura("raid"..i, j)
|
||||
if name and name:find("Flask ") then
|
||||
local time = expires - now
|
||||
if time<990 and time>0 then
|
||||
SendChatMessage(format("%s %d:%02d", player, floor(time/60), time%60), "raid")
|
||||
-- SendChatMessage(format("Flask ending in %d:%02d", UnitName(r), floor(time/60), time%60), "whipser", nil, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function core:RollFinish()
|
||||
|
@ -646,283 +566,6 @@ function core:TargetUnit(name)
|
|||
end
|
||||
end
|
||||
|
||||
--[[ Things to do here still:
|
||||
- remove debug
|
||||
- consumables.php: group names together in slash args
|
||||
- consumables.php: split slash by pots?
|
||||
- if we don't have mats for this player, move to end of queue
|
||||
- use a flag of sorts to keep track of who was moved and who was not; reset flags on... mailbox close? this way we don't keep going through the queue over and over at the end
|
||||
- change data structure to numerical array (so we can move to the end)
|
||||
- change subject line to include amount
|
||||
- the lowercase first letter bugs me
|
||||
- do check when parsing slash command to make sure there are no ambiguous targets (Eternal/Eternity)
|
||||
- compress slash command more:
|
||||
limit to first 4 letters (chir40d, chir->chira)? 3 may be possible but has higher collisions
|
||||
allow for chaining (chira40d2e6f - 40d, 2e, 6f)?
|
||||
include length of name after characters *in hex* (chi540d - "chira" has length of 5)
|
||||
- re-consolidate stacks at the end of the queue
|
||||
- add a command to display how much left of each is needed vs how much you have
|
||||
]]
|
||||
local mailQueueTimer
|
||||
function core:MailQueueCheck(caller, passData)
|
||||
local name,data = next(self.mailQueue)
|
||||
if not data then
|
||||
return -- no need to process queue
|
||||
end
|
||||
|
||||
local delay = 0.5
|
||||
if caller == "MAIL_SUCCESS" then
|
||||
-- MAIL_SUCCESS fires on open too, so going to make sure we're looking at a Send Mail screen
|
||||
if MailFrame.selectedTab ~= 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
if mailQueueTimer then
|
||||
self:CancelTimer(mailQueueTimer, true)
|
||||
end
|
||||
-- slight pause to allow for items to disappear
|
||||
mailQueueTimer = self:ScheduleTimer(function()
|
||||
do
|
||||
self:Print(caller)
|
||||
-- return
|
||||
end
|
||||
|
||||
-- find all slots for splitting onto
|
||||
local emptySlots = {}
|
||||
for bag=0,NUM_BAG_SLOTS do
|
||||
local free = GetContainerFreeSlots(bag)
|
||||
for _,slot in ipairs(free) do
|
||||
table.insert(emptySlots, bag*100+slot)
|
||||
end
|
||||
end
|
||||
|
||||
-- need to keep track of what to push to Send Mail window when the item lock clears
|
||||
local pushQueue = {}
|
||||
local checkItemLock = function(_, bagID, slotID)
|
||||
local globalID = bagID*100+slotID
|
||||
self:Print("ITEM_LOCK_CHANGED fired", globalID)
|
||||
if pushQueue[globalID] then
|
||||
local _, _, locked = GetContainerItemInfo(bagID, slotID)
|
||||
if not locked then
|
||||
PickupContainerItem(bagID, slotID)
|
||||
ClickSendMailItemButton()
|
||||
pushQueue[globalID] = nil
|
||||
|
||||
-- if our queue is empty
|
||||
if not next(pushQueue) then
|
||||
self:UnregisterEvent("ITEM_LOCK_CHANGED")
|
||||
self:Print("Unregistering ITEM_LOCK_CHANGED")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local initializeQueue = function()
|
||||
self:RegisterEvent("ITEM_LOCK_CHANGED", checkItemLock)
|
||||
self:Print("Registering ITEM_LOCK_CHANGED")
|
||||
end
|
||||
|
||||
-- swap tabs if we need to
|
||||
if MailFrame.selectedTab ~= 2 then
|
||||
MailFrameTab_OnClick(MailFrame, 2)
|
||||
end
|
||||
ClearSendMail()
|
||||
|
||||
-- set name
|
||||
SendMailNameEditBox:SetText(name)
|
||||
|
||||
-- fill out shit
|
||||
for item,ct in pairs(data) do
|
||||
print("--------- NEXT ITEM:", item)
|
||||
if ct > 0 then
|
||||
local inv = GetItemCount(item)
|
||||
print("Checking item count:", inv, ct, inv<ct)
|
||||
if inv < ct then
|
||||
-- we don't have enough. abort.
|
||||
core:Print(format("We don't have enough |Hitem:%d|h[%s]|h for %s. Needed %d; have %d.", item, GetItemInfo("item:"..item), name, ct, inv))
|
||||
ClearSendMail()
|
||||
return
|
||||
end
|
||||
|
||||
-- find container slot with item
|
||||
for bag=0,NUM_BAG_SLOTS do
|
||||
-- check if we're done
|
||||
if ct > 0 then
|
||||
for slot=1,GetContainerNumSlots(bag) do
|
||||
-- make sure the item we want is this slot
|
||||
if GetContainerItemID(bag, slot) == item then
|
||||
local _, slotCt, locked = GetContainerItemInfo(bag, slot)
|
||||
print("LOOP", GetItemInfo("item:"..item), slotCt, "/", ct, locked)
|
||||
if locked then
|
||||
-- the item is locked for whatever reason. abort?
|
||||
self:Message("|Hitem:%d|h[%s]|h in bag %d, slot %d is locked.", item, GetItemInfo("item:"..item), bag, slot)
|
||||
return
|
||||
else
|
||||
-- if item too many; find empty spot to dump extras
|
||||
if slotCt > ct then
|
||||
-- check to make sure we can split
|
||||
if #emptySlots == 0 then
|
||||
print("Not enough bag space to split. Aborting.")
|
||||
ClearSendMail()
|
||||
core:CancelAllTimers()
|
||||
return
|
||||
end
|
||||
-- pop empty slot off the list
|
||||
local extraSpace = table.remove(emptySlots)
|
||||
local extraBag, extraSlot = floor(extraSpace/100), extraSpace % 100
|
||||
-- split and place
|
||||
print("splitting", bag, slot, slotCt-ct)
|
||||
SplitContainerItem(bag, slot, slotCt-ct)
|
||||
print("extras at", extraBag, extraSlot)
|
||||
PickupContainerItem(extraBag, extraSlot) -- place
|
||||
|
||||
-- check when lock is clear
|
||||
if not next(pushQueue) then
|
||||
initializeQueue()
|
||||
end
|
||||
pushQueue[bag*100+slot] = true -- register source as push target
|
||||
ct = 0
|
||||
break
|
||||
else
|
||||
-- item should have enough
|
||||
print("adding to mail", bag, slot, ct, slotCt, ct-slotCt)
|
||||
PickupContainerItem(bag, slot)
|
||||
ClickSendMailItemButton()
|
||||
ct = ct - slotCt
|
||||
print("and after", ct)
|
||||
if ct == 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- click send
|
||||
self.mailQueue[name] = nil
|
||||
-- self:ScheduleTimer(function()
|
||||
-- self.mailQueue[name] = nil
|
||||
-- ClearSendMail()
|
||||
-- self:MailQueueCheck()
|
||||
-- end, 5)
|
||||
|
||||
mailQueueTimer = nil
|
||||
end, delay)
|
||||
end
|
||||
|
||||
local didSetup = false
|
||||
function core:SetupRBS()
|
||||
if didSetup or not RaidBuffStatus or not RaidBuffStatus.frame then
|
||||
return
|
||||
end
|
||||
didSetup = true
|
||||
|
||||
-- register new buttons
|
||||
self:NewRBSButton("Flask", function()
|
||||
self:FlaskCheck()
|
||||
end, 45, "TOPLEFT", "BOTTOMLEFT", 7, 5)
|
||||
self:NewRBSButton("Count", function()
|
||||
self:Countdown()
|
||||
end, 45, "TOP", "BOTTOM", 0, 5)
|
||||
self:NewRBSButton("Loot", function()
|
||||
self:MasterLoot()
|
||||
end, 45, "TOPRIGHT", "BOTTOMRIGHT", -7, 5)
|
||||
|
||||
-- reposition old ones
|
||||
RaidBuffStatus.readybutton:SetWidth(45)
|
||||
RaidBuffStatus.readybutton:SetText("Ready")
|
||||
|
||||
-- hook old show/hide
|
||||
local rbShow = RaidBuffStatus.readybutton.Show
|
||||
RaidBuffStatus.readybutton.Show = function(...)
|
||||
RaidBuffStatus.FlaskButton:Show()
|
||||
RaidBuffStatus.CountButton:Show()
|
||||
RaidBuffStatus.LootButton:Show()
|
||||
return rbShow(...)
|
||||
end
|
||||
local rbHide = RaidBuffStatus.readybutton.Hide
|
||||
RaidBuffStatus.readybutton.Hide = function(...)
|
||||
RaidBuffStatus.FlaskButton:Hide()
|
||||
RaidBuffStatus.CountButton:Hide()
|
||||
RaidBuffStatus.LootButton:Hide()
|
||||
return rbHide(...)
|
||||
end
|
||||
|
||||
--[[ fix height
|
||||
local heightFix = 25
|
||||
RaidBuffStatus.frame:SetHeight(RaidBuffStatus.frame:GetHeight() + heightFix)
|
||||
|
||||
-- fix future height
|
||||
RaidBuffStatus.frame:SetScript("OnSizeChanged", function(self, width, height)
|
||||
-- since this will cause OnSizeChanged to fire again immediately, we use a flag to determine which call it was
|
||||
if self.heightFlag then
|
||||
self.heightFlag = nil
|
||||
else
|
||||
self.heightFlag = true
|
||||
self:SetHeight(height + heightFix)
|
||||
end
|
||||
end)]]
|
||||
end
|
||||
|
||||
function core:NewRBSButton(label, func, width, anchorFrom, anchorTo, anchorX, anchorY)
|
||||
local button = CreateFrame("Button", "", RaidBuffStatus.frame, "OptionsButtonTemplate")
|
||||
button:SetText(label)
|
||||
button:SetWidth(width)
|
||||
button:SetPoint(anchorFrom, RaidBuffStatus.frame, anchorTo, anchorX, anchorY)
|
||||
button:SetScript("OnClick", func)
|
||||
button:Show()
|
||||
RaidBuffStatus[label.."Button"] = button
|
||||
end
|
||||
|
||||
|
||||
|
||||
function core:SetupPrat()
|
||||
local module = Prat.Addon:GetModule('AltNames')
|
||||
Prat.RegisterMessageItem('ALTNAMES', 'PLAYER')
|
||||
module.padfmt = '||%s'
|
||||
module.setMainPos = function() end
|
||||
|
||||
-- Prevent dropdown menu option from being displayed
|
||||
module.menusAdded = true
|
||||
|
||||
-- /run Prat.Addon:ChatFrame_MessageEventHandler(ChatFrame1, "CHAT_MSG_SYSTEM", "Batche has gone offline.", "", "", "", "", "", 0, 0, "", 0, 3991, "", 0, true, false)
|
||||
-- PreAddMessage hook to limit main print to 3 characters and make sure player is added for logouts
|
||||
local PreAddMessage = module.Prat_PreAddMessage
|
||||
module.Prat_PreAddMessage = function(self, e, message, frame, event, ...)
|
||||
-- check to see if we have a log off
|
||||
if event == "CHAT_MSG_SYSTEM" then
|
||||
-- .MESSAGE contains modified message with color, .OUTPUT contains raw
|
||||
local p, m = message.OUTPUT:match("(%S+)( has gone offline.*)")
|
||||
if p then
|
||||
local class = Prat.Addon:GetModule('PlayerNames'):GetData(p)
|
||||
-- inline coloring won't work (fires before) so we do it manually
|
||||
-- set PLAYERLINK for AltNames to read
|
||||
message.MESSAGE, message.PLAYER, message.PLAYERLINK = m, Prat.CLR:Player(p, p:lower(), class), p
|
||||
end
|
||||
end
|
||||
|
||||
-- call normal
|
||||
PreAddMessage(self, e, message, frame, event, ...)
|
||||
|
||||
-- unset PLAYERLINK if we have a log off so as not to have it display
|
||||
if not message.lL or message.lL == "" then
|
||||
message.PLAYERLINK = nil
|
||||
end
|
||||
|
||||
-- limit to 3 characters in the main
|
||||
if message.ALTNAMES and message.ALTNAMES ~= "" then
|
||||
-- 12 characters of color padding; so sub(1, 12+length)
|
||||
self.ALTNAMES = self.ALTNAMES:sub(1, 15).."|r"
|
||||
message.ALTNAMES = self.ALTNAMES
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local chatEvents = {
|
||||
"CHAT_MSG_ACHIEVEMENT",
|
||||
"CHAT_MSG_ADDON",
|
||||
|
|
232
modules/potions.lua
Normal file
232
modules/potions.lua
Normal file
|
@ -0,0 +1,232 @@
|
|||
local core = LibStub("AceAddon-3.0"):GetAddon("AllTheLittleThings")
|
||||
local mod = core:NewModule("Potion Mail", "AceEvent-3.0")
|
||||
local db = core.db.profile[mod:GetName()]
|
||||
|
||||
local defaults = {
|
||||
}
|
||||
local options = {
|
||||
}
|
||||
|
||||
local potList = {
|
||||
["a"] = 58146, -- Golemblood
|
||||
["b"] = 58145, -- Tol'vir
|
||||
["c"] = 58090, -- Earthen
|
||||
["d"] = 58091, -- Volcanic
|
||||
["e"] = 57194, -- Concentration
|
||||
["f"] = 57192, -- Mythical
|
||||
}
|
||||
local mailQueue = {} -- used in /atlt pots
|
||||
|
||||
function mod:OnInitialize()
|
||||
core:RegisterSlashCommand("AddPotions", "pots")
|
||||
self:RegisterEvent("MAIL_SHOW", "MailQueueCheck");
|
||||
self:RegisterEvent("MAIL_SUCCESS", "MailQueueCheck");
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
end
|
||||
|
||||
function mod:AddPotions()
|
||||
-- get all guild members
|
||||
for i=1,GetNumGuildMembers() do
|
||||
local name, rank = GetGuildRosterInfo(i)
|
||||
name = name:lower()
|
||||
if rank == "Member" or rank == "Officer" or rank == "Guild Master" then
|
||||
if mailQueue[name] == nil then
|
||||
mailQueue[name] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
-- parse
|
||||
msg:gsub("([^%d%s]+)(%d+)(%w)", function(name, ct, type)
|
||||
local typeRef = potList[type]
|
||||
name = name:lower()
|
||||
ct = tonumber(ct)
|
||||
if typeRef and ct then
|
||||
for i,_ in pairs(mailQueue) do
|
||||
if i:match("^"..name) then
|
||||
mailQueue[i][typeRef] = ct
|
||||
print(format("Queued %dx |Hitem:%d|h[%s]|h for %s", ct, typeRef, GetItemInfo("item:"..typeRef), i))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
-- cleanup array
|
||||
for name,data in pairs(mailQueue) do
|
||||
local ct = 0
|
||||
for i,v in pairs(data) do
|
||||
ct = ct + v
|
||||
end
|
||||
if ct == 0 then
|
||||
mailQueue[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Things to do here still:
|
||||
- remove debug
|
||||
- consumables.php: group names together in slash args
|
||||
- consumables.php: split slash by pots?
|
||||
- if we don't have mats for this player, move to end of queue
|
||||
- use a flag of sorts to keep track of who was moved and who was not; reset flags on... mailbox close? this way we don't keep going through the queue over and over at the end
|
||||
- change data structure to numerical array (so we can move to the end)
|
||||
- change subject line to include amount
|
||||
- the lowercase first letter bugs me
|
||||
- do check when parsing slash command to make sure there are no ambiguous targets (Eternal/Eternity)
|
||||
- compress slash command more:
|
||||
limit to first 4 letters (chir40d, chir->chira)? 3 may be possible but has higher collisions
|
||||
allow for chaining (chira40d2e6f - 40d, 2e, 6f)?
|
||||
include length of name after characters *in hex* (chi540d - "chira" has length of 5)
|
||||
- re-consolidate stacks at the end of the queue
|
||||
- add a command to display how much left of each is needed vs how much you have
|
||||
]]
|
||||
local mailQueueTimer
|
||||
function core:MailQueueCheck(caller, passData)
|
||||
local name,data = next(mailQueue)
|
||||
if not data then
|
||||
return -- no need to process queue
|
||||
end
|
||||
|
||||
local delay = 0.5
|
||||
if caller == "MAIL_SUCCESS" then
|
||||
-- MAIL_SUCCESS fires on open too, so going to make sure we're looking at a Send Mail screen
|
||||
if MailFrame.selectedTab ~= 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
if mailQueueTimer then
|
||||
self:CancelTimer(mailQueueTimer, true)
|
||||
end
|
||||
-- slight pause to allow for items to disappear
|
||||
mailQueueTimer = self:ScheduleTimer(function()
|
||||
do
|
||||
self:Print(caller)
|
||||
-- return
|
||||
end
|
||||
|
||||
-- find all slots for splitting onto
|
||||
local emptySlots = {}
|
||||
for bag=0,NUM_BAG_SLOTS do
|
||||
local free = GetContainerFreeSlots(bag)
|
||||
for _,slot in ipairs(free) do
|
||||
table.insert(emptySlots, bag*100+slot)
|
||||
end
|
||||
end
|
||||
|
||||
-- need to keep track of what to push to Send Mail window when the item lock clears
|
||||
local pushQueue = {}
|
||||
local checkItemLock = function(_, bagID, slotID)
|
||||
local globalID = bagID*100+slotID
|
||||
self:Print("ITEM_LOCK_CHANGED fired", globalID)
|
||||
if pushQueue[globalID] then
|
||||
local _, _, locked = GetContainerItemInfo(bagID, slotID)
|
||||
if not locked then
|
||||
PickupContainerItem(bagID, slotID)
|
||||
ClickSendMailItemButton()
|
||||
pushQueue[globalID] = nil
|
||||
|
||||
-- if our queue is empty
|
||||
if not next(pushQueue) then
|
||||
self:UnregisterEvent("ITEM_LOCK_CHANGED")
|
||||
self:Print("Unregistering ITEM_LOCK_CHANGED")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local initializeQueue = function()
|
||||
self:RegisterEvent("ITEM_LOCK_CHANGED", checkItemLock)
|
||||
self:Print("Registering ITEM_LOCK_CHANGED")
|
||||
end
|
||||
|
||||
-- swap tabs if we need to
|
||||
if MailFrame.selectedTab ~= 2 then
|
||||
MailFrameTab_OnClick(MailFrame, 2)
|
||||
end
|
||||
ClearSendMail()
|
||||
|
||||
-- set name
|
||||
SendMailNameEditBox:SetText(name)
|
||||
|
||||
-- fill out shit
|
||||
for item,ct in pairs(data) do
|
||||
print("--------- NEXT ITEM:", item)
|
||||
if ct > 0 then
|
||||
local inv = GetItemCount(item)
|
||||
print("Checking item count:", inv, ct, inv<ct)
|
||||
if inv < ct then
|
||||
-- we don't have enough. abort.
|
||||
core:Print(format("We don't have enough |Hitem:%d|h[%s]|h for %s. Needed %d; have %d.", item, GetItemInfo("item:"..item), name, ct, inv))
|
||||
ClearSendMail()
|
||||
return
|
||||
end
|
||||
|
||||
-- find container slot with item
|
||||
for bag=0,NUM_BAG_SLOTS do
|
||||
-- check if we're done
|
||||
if ct > 0 then
|
||||
for slot=1,GetContainerNumSlots(bag) do
|
||||
-- make sure the item we want is this slot
|
||||
if GetContainerItemID(bag, slot) == item then
|
||||
local _, slotCt, locked = GetContainerItemInfo(bag, slot)
|
||||
print("LOOP", GetItemInfo("item:"..item), slotCt, "/", ct, locked)
|
||||
if locked then
|
||||
-- the item is locked for whatever reason. abort?
|
||||
self:Message("|Hitem:%d|h[%s]|h in bag %d, slot %d is locked.", item, GetItemInfo("item:"..item), bag, slot)
|
||||
return
|
||||
else
|
||||
-- if item too many; find empty spot to dump extras
|
||||
if slotCt > ct then
|
||||
-- check to make sure we can split
|
||||
if #emptySlots == 0 then
|
||||
print("Not enough bag space to split. Aborting.")
|
||||
ClearSendMail()
|
||||
core:CancelAllTimers()
|
||||
return
|
||||
end
|
||||
-- pop empty slot off the list
|
||||
local extraSpace = table.remove(emptySlots)
|
||||
local extraBag, extraSlot = floor(extraSpace/100), extraSpace % 100
|
||||
-- split and place
|
||||
print("splitting", bag, slot, slotCt-ct)
|
||||
SplitContainerItem(bag, slot, slotCt-ct)
|
||||
print("extras at", extraBag, extraSlot)
|
||||
PickupContainerItem(extraBag, extraSlot) -- place
|
||||
|
||||
-- check when lock is clear
|
||||
if not next(pushQueue) then
|
||||
initializeQueue()
|
||||
end
|
||||
pushQueue[bag*100+slot] = true -- register source as push target
|
||||
ct = 0
|
||||
break
|
||||
else
|
||||
-- item should have enough
|
||||
print("adding to mail", bag, slot, ct, slotCt, ct-slotCt)
|
||||
PickupContainerItem(bag, slot)
|
||||
ClickSendMailItemButton()
|
||||
ct = ct - slotCt
|
||||
print("and after", ct)
|
||||
if ct == 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- click send
|
||||
mailQueue[name] = nil
|
||||
-- self:ScheduleTimer(function()
|
||||
-- self.mailQueue[name] = nil
|
||||
-- ClearSendMail()
|
||||
-- self:MailQueueCheck()
|
||||
-- end, 5)
|
||||
|
||||
mailQueueTimer = nil
|
||||
end, delay)
|
||||
end
|
||||
|
Loading…
Reference in a new issue