📄 purchasesdb.lua
字号:
--[[ Auctioneer Addon for World of Warcraft(tm). Version: 3.5.0.0914 (Platypus) Revision: $Id: PurchasesDB.lua 914 2006-07-03 21:53:19Z vindicator $ PurchasesDB - manages the database of AH purchases License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program(see GPL.txt); if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.--]]--------------------------------------------------------------------------------- Function Imports-------------------------------------------------------------------------------local chatPrint = BeanCounter.ChatPrint;local getPlayerName = BeanCounter.Database.GetPlayerName;local getCurrentPlayerId = BeanCounter.Database.GetCurrentPlayerId;local stringFromBoolean = BeanCounter.Database.StringFromBoolean;local booleanFromString = BeanCounter.Database.BooleanFromString;local stringFromNumber = BeanCounter.Database.StringFromNumber;local numberFromString = BeanCounter.Database.NumberFromString;local nilSafeStringFromString = BeanCounter.Database.NilSafeStringFromString;local stringFromNilSafeString = BeanCounter.Database.StringFromNilSafeString;--------------------------------------------------------------------------------- Function Prototypes-------------------------------------------------------------------------------local addPendingBid;local deletePendingBidBySignature;local deletePendingBidByIndex;local packPendingBid;local unpackPendingBid;local getPendingBidsTableForItem;local getPendingBidItems;local getPendingBidsForItem;local isPendingBid;local printPendingBids;local printPendingBid;local addSuccessfulBid;local addFailedBid;local addCompletedBid;local deleteCompletedBidByIndex;local packCompletedBid;local unpackCompletedBid;local getCompletedBidsTableForItem;local getCompletedBidsForItem;local printCompletedBids;local printCompletedBid;local addPurchase;local packPurchase;local unpackPurchase;local getPurchasesTableForItem;local getPurchasedItems;local getPurchasesForItem;local printPurchases;local printPurchase;local reconcileBids;local reconcileBidsByTime;local reconcileBidsByQuantityOrBids;local reconcileBidsByQuantity;local reconcileBidsByBid;local reconcileBidList;local reconcileMatchingBids;local doesPendingBidListMatch;local doesPendingBidMatchCompletedBid;local compareMatchCount;local compareTime;local getBidNonNilFieldCount;local compareBidsByNonNilFieldCount;local debugPrint;--------------------------------------------------------------------------------- Constants-------------------------------------------------------------------------------local NIL_VALUE = "<nil>";local AUCTION_OVERRUN_LIMIT = (2 * 60 * 60); -- 2 hourslocal AUCTION_DURATION_LIMIT = (24 * 60 * 60) + AUCTION_OVERRUN_LIMIT;local MAXIMUM_TIME_LEFT ={ [1] = 60 * 30, -- Short [2] = 60 * 60 * 2, -- Medium [3] = 60 * 60 * 8, -- Long [4] = 60 * 60 * 24, -- Very Long};local MINIMUM_TIME_LEFT ={ [1] = 0, -- Short [2] = 60 * 30, -- Medium [3] = 60 * 60 * 2, -- Long [4] = 60 * 60 * 8, -- Very Long};--=============================================================================-- Pending Bids functions--=============================================================================--------------------------------------------------------------------------------- Adds a pending bid to the database-------------------------------------------------------------------------------function addPendingBid(timestamp, item, quantity, bid, seller, isBuyout, timeLeft) if (item and quantity and bid and seller and timeLeft) then -- Create a packed record. local pendingBid = {}; pendingBid.time = timestamp; pendingBid.quantity = quantity; pendingBid.bid = bid; pendingBid.seller = seller; pendingBid.isBuyout = isBuyout; pendingBid.timeLeft = timeLeft; pendingBid.buyerId = getCurrentPlayerId(); local packedPendingBid = packPendingBid(pendingBid); -- Add the pending bid to the table. local pendingBidsTable = getPendingBidsTableForItem(item, true); table.insert(pendingBidsTable, packedPendingBid); -- Debugging noise. printPendingBid(debugPrint, "Added pending bid: ", item, pendingBid); else debugPrint("Invalid call to addPendingBid()"); endend--------------------------------------------------------------------------------- Deletes a pending bid from the database-------------------------------------------------------------------------------function deletePendingBidBySignature(item, quantity, bid, seller, isBuyout, timeLeft) if (item and quantity and bid and seller) then local pendingBidsTable = getPendingBidsTableForItem(item, true); for index = 1, table.getn(pendingBidsTable) do local pendingBid = unpackPendingBid(pendingBidsTable[index]); if (pendingBid.quantity == quantity and pendingBid.bid == bid and pendingBid.seller == seller and pendingBid.isBuyout == isBuyout) then -- Found it! Delete the pending bid table.remove(pendingBidsTable, index); printPendingBid(debugPrint, "Deleted pending bid (request): ", item, pendingBid); -- Remove the item's table if empty. This happens automatically -- when getting it via the built-in method. getPendingBidsTableForItem(item); return true; end end end debugPrint("No pending bid found to delete: "..item..", "..quantity..", "..bid..", "..nilSafeStringFromString(seller)..", "..stringFromBoolean(isBuyout)); return false;end--------------------------------------------------------------------------------- Deletes a pending bid from the database.---- If pendingBids is provided, the pending bid will be removed from it.-------------------------------------------------------------------------------function deletePendingBidByIndex(item, index, reason, pendingBids) -- Update the unpacked pending bid list, if provided local pendingBid = nil; if (pendingBids) then -- Iterate in reverse since we will be removing the pending bid -- from the list when we find it. for pendingIndex = table.getn(pendingBids), 1, -1 do local bid = pendingBids[pendingIndex]; if (index == bid.index) then pendingBid = bid; table.remove(pendingBids, pendingIndex); elseif (index < bid.index) then bid.index = bid.index - 1; end end end -- Grab the pending bids table for the item. local pendingBidsTable = getPendingBidsTableForItem(item); if (pendingBidsTable) then -- Get the pending bid if we don't already have it. if (pendingBid == nil) then pendingBid = unpackPendingBid(pendingBidsTable[index]); end -- Remove the pending bid from the table. table.remove(pendingBidsTable, index); if (table.getn(pendingBidsTable)) then getPendingBidsTableForItem(item); -- Deletes the table end -- Debug noise. printPendingBid( debugPrint, "Deleted pending bid ("..nilSafeStringFromString(reason).."): ", item, pendingBid); endend--------------------------------------------------------------------------------- Converts a pending bid into a ';' delimited string.-------------------------------------------------------------------------------function packPendingBid(pendingBid) return pendingBid.time..";".. stringFromNumber(pendingBid.quantity)..";".. stringFromNumber(pendingBid.bid)..";".. nilSafeStringFromString(pendingBid.seller)..";".. stringFromBoolean(pendingBid.isBuyout)..";".. stringFromNumber(pendingBid.timeLeft)..";".. stringFromNumber(pendingBid.buyerId);end--------------------------------------------------------------------------------- Converts a ';' delimited string into a pending bid.-------------------------------------------------------------------------------function unpackPendingBid(packedPendingBid) local pendingBid = {}; _, _, pendingBid.time, pendingBid.quantity, pendingBid.bid, pendingBid.seller, pendingBid.isBuyout, pendingBid.timeLeft, pendingBid.buyerId = string.find(packedPendingBid, "(.+);(.+);(.+);(.+);(.+);(.+);(.+)"); pendingBid.time = numberFromString(pendingBid.time); pendingBid.quantity = numberFromString(pendingBid.quantity); pendingBid.bid = numberFromString(pendingBid.bid); pendingBid.seller = stringFromNilSafeString(pendingBid.seller); pendingBid.isBuyout = booleanFromString(pendingBid.isBuyout); pendingBid.timeLeft = numberFromString(pendingBid.timeLeft); pendingBid.buyerId = numberFromString(pendingBid.buyerId); return pendingBid;end--------------------------------------------------------------------------------- Gets the pending bids table for the specified item. The table contains-- packed records.-------------------------------------------------------------------------------function getPendingBidsTableForItem(item, create) local pendingBidsTable = BeanCounterRealmDB.pendingBids; if (pendingBidsTable == nil) then pendingBidsTable = {}; BeanCounterRealmDB.pendingBids = pendingBidsTable; end -- Get the table for the item. Create or delete if appropriate. local pendingBidsForItemTable = pendingBidsTable[item]; if (pendingBidsForItemTable == nil and create) then pendingBidsForItemTable = {}; pendingBidsTable[item] = pendingBidsForItemTable; elseif (pendingBidsForItemTable and table.getn(pendingBidsForItemTable) == 0 and not create) then pendingBidsTable[item] = nil; end return pendingBidsForItemTable;end--------------------------------------------------------------------------------- Gets the list of pending bid items.-------------------------------------------------------------------------------function getPendingBidItems(item) local items = {}; if (BeanCounterRealmDB.pendingBids) then for item in BeanCounterRealmDB.pendingBids do local pendingBidsTable = getPendingBidsTableForItem(item); if (pendingBidsTable and table.getn(pendingBidsTable) > 0) then table.insert(items, item); end end end return items;end--------------------------------------------------------------------------------- Gets the pending bids (unpacked) for the specified item-------------------------------------------------------------------------------function getPendingBidsForItem(item, filterFunc) local pendingBids = {}; local pendingBidsTable = getPendingBidsTableForItem(item); if (pendingBidsTable) then for index in pendingBidsTable do local pendingBid = unpackPendingBid(pendingBidsTable[index]); pendingBid.index = index; if (filterFunc == nil or filterFunc(pendingBid)) then table.insert(pendingBids, pendingBid); end end end return pendingBids;end--------------------------------------------------------------------------------- Prints the pending bids.-------------------------------------------------------------------------------function printPendingBids() chatPrint("Pending Bids:"); if (BeanCounterRealmDB.pendingBids) then for item in BeanCounterRealmDB.pendingBids do local pendingBidsTable = BeanCounterRealmDB.pendingBids[item]; for index = 1, table.getn(pendingBidsTable) do local pendingBid = unpackPendingBid(pendingBidsTable[index]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -