📄 salesdb.lua
字号:
--[[ Auctioneer Addon for World of Warcraft(tm). Version: 3.5.0.0914 (Platypus) Revision: $Id: SalesDB.lua 914 2006-07-03 21:53:19Z vindicator $ SalesDB - manages the database of AH sales 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 addPendingAuction;local deletePendingAuction;local packPendingAuction;local unpackPendingAuction;local getPendingAuctionsTableForItem;local getPendingAuctionItems;local getPendingAuctionsForItem;local printPendingAuctions;local printPendingAuction;local addSuccessfulAuction;local addExpiredAuction;local addCanceledAuction;local addCompletedAuction;local deleteCompletedAuction;local packCompletedAuction;local unpackCompletedAuction;local getCompletedAuctionsTableForItem;local getCompletedAuctionsForItemlocal printCompletedAuctions;local printCompletedAuction;local addSale;local packSale;local unpackSale;local getSalesTableForItem;local getSoldItems;local getSalesForItem;local printSales;local printSale;local reconcileAuctions;local reconcileAuctionsByTime;local reconcileAuctionsByQuantityOrProceeds;local reconcileAuctionsByQuantity;local reconcileAuctionsByProceeds;local reconcileAuctionList;local reconcileMatchingAuctions;local compareMatchCount;local compareTime;local doesPendingAuctionMatchCompletedAuction;local doesPendingAuctionListMatch;local getPendingAuctionMatchCount;local debugPrint;--------------------------------------------------------------------------------- Data Members--------------------------------------------------------------------------------- Auction result constantslocal AUCTION_SOLD = 0;local AUCTION_EXPIRED = 1;local AUCTION_CANCELED = 2;-- Constantslocal AUCTION_OVERRUN_LIMIT = (2 * 60 * 60); -- 2 hourslocal AUCTION_DURATION_LIMIT = (24 * 60 * 60) + AUCTION_OVERRUN_LIMIT;--=============================================================================-- Pending Auctions functions--=============================================================================--------------------------------------------------------------------------------- Adds a pending auction to the database-------------------------------------------------------------------------------function addPendingAuction(timestamp, item, quantity, bid, buyout, runTime, deposit, consignmentPercent) if (item and quantity and bid and buyout) then -- Create a packed record. local pendingAuction = {}; pendingAuction.time = timestamp; pendingAuction.quantity = quantity; pendingAuction.bid = bid; pendingAuction.buyout = buyout; pendingAuction.runTime = runTime; pendingAuction.deposit = deposit; pendingAuction.consignmentPercent = consignmentPercent; pendingAuction.sellerId = getCurrentPlayerId(); local packedPendingAuction = packPendingAuction(pendingAuction); -- Add to the pending auctions table. local pendingAuctionsTable = getPendingAuctionsTableForItem(item, true); table.insert(pendingAuctionsTable, packedPendingAuction); -- Debugging noise. printPendingAuction(debugPrint, "Added pending auction: ", item, pendingAuction); else debugPrint("Invalid call to addPendingAuction()"); endend--------------------------------------------------------------------------------- Deletes a pending auction from the database.---- If pendingAuctions is provided, the pending auction will be removed from it.-------------------------------------------------------------------------------function deletePendingAuction(item, index, reason, pendingAuctions) -- Update the unpacked pending auction list, if provided local pendingAuction = nil; if (pendingAuctions) then -- Iterate in reverse since we will be removing the pending auction -- from the list when we find it. for pendingIndex = table.getn(pendingAuctions), 1, -1 do local auction = pendingAuctions[pendingIndex]; if (index == auction.index) then pendingAuction = auction; table.remove(pendingAuctions, pendingIndex); elseif (index < auction.index) then auction.index = auction.index - 1; end end end -- Grab the pending auctions table for the item. local pendingAuctionsTable = getPendingAuctionsTableForItem(item); if (pendingAuctionsTable) then -- Get the pending auction if we don't already have it. if (pendingAuction == nil) then pendingAuction = unpackPendingAuction(pendingAuctionsTable[index]); end -- Remove the pending auction from the table. table.remove(pendingAuctionsTable, index); if (table.getn(pendingAuctionsTable)) then getPendingAuctionsTableForItem(item); -- Deletes the table end -- Debug noise. printPendingAuction( debugPrint, "Deleted pending auction ("..nilSafeStringFromString(reason).."): ", item, pendingAuction); endend--------------------------------------------------------------------------------- Converts a pending auction into a ';' delimited string.-------------------------------------------------------------------------------function packPendingAuction(pendingAuction) return stringFromNumber(pendingAuction.time)..";".. stringFromNumber(pendingAuction.quantity)..";".. stringFromNumber(pendingAuction.bid)..";".. stringFromNumber(pendingAuction.buyout)..";".. stringFromNumber(pendingAuction.runTime)..";".. stringFromNumber(pendingAuction.deposit)..";".. stringFromNumber(pendingAuction.consignmentPercent)..";".. stringFromNumber(pendingAuction.sellerId);end--------------------------------------------------------------------------------- Converts a ';' delimited string into a pending auction.-------------------------------------------------------------------------------function unpackPendingAuction(packedPendingAuction) local pendingAuction = {}; _, _, pendingAuction.time, pendingAuction.quantity, pendingAuction.bid, pendingAuction.buyout, pendingAuction.runTime, pendingAuction.deposit, pendingAuction.consignmentPercent, pendingAuction.sellerId = string.find(packedPendingAuction, "(.+);(.+);(.+);(.+);(.+);(.+);(.+);(.+)"); pendingAuction.time = numberFromString(pendingAuction.time); pendingAuction.quantity = numberFromString(pendingAuction.quantity); pendingAuction.bid = numberFromString(pendingAuction.bid); pendingAuction.buyout = numberFromString(pendingAuction.buyout); pendingAuction.runTime = numberFromString(pendingAuction.runTime); pendingAuction.deposit = numberFromString(pendingAuction.deposit); pendingAuction.consignmentPercent = numberFromString(pendingAuction.consignmentPercent); pendingAuction.sellerId = numberFromString(pendingAuction.sellerId); return pendingAuction;end--------------------------------------------------------------------------------- Gets the pending auctions table for the specified item. The table contains-- packed records.-------------------------------------------------------------------------------function getPendingAuctionsTableForItem(item, create) local pendingAuctionsTable = BeanCounterRealmDB.pendingAuctions; if (pendingAuctionsTable == nil) then pendingAuctionsTable = {}; BeanCounterRealmDB.pendingAuctions = pendingAuctionsTable; end -- Get the table for the item. Create or delete if appropriate. local pendingAuctionsForItemTable = pendingAuctionsTable[item]; if (pendingAuctionsForItemTable == nil and create) then pendingAuctionsForItemTable = {}; pendingAuctionsTable[item] = pendingAuctionsForItemTable; elseif (pendingAuctionsForItemTable and table.getn(pendingAuctionsForItemTable) == 0 and not create) then pendingAuctionsTable[item] = nil; end return pendingAuctionsForItemTable;end--------------------------------------------------------------------------------- Gets the list of pending auction items.-------------------------------------------------------------------------------function getPendingAuctionItems() local items = {}; if (BeanCounterRealmDB.pendingAuctions) then for item in BeanCounterRealmDB.pendingAuctions do local pendingAuctionsTable = getPendingAuctionsTableForItem(item); if (pendingAuctionsTable and table.getn(pendingAuctionsTable) > 0) then table.insert(items, item); end end end return items;end--------------------------------------------------------------------------------- Gets the pending auctions (unpacked) for the specified item-------------------------------------------------------------------------------function getPendingAuctionsForItem(item, filterFunc) local pendingAuctions = {}; local pendingAuctionsTable = getPendingAuctionsTableForItem(item); if (pendingAuctionsTable) then for index in pendingAuctionsTable do local pendingAuction = unpackPendingAuction(pendingAuctionsTable[index]); pendingAuction.index = index; if (filterFunc == nil or filterFunc(pendingAuction)) then table.insert(pendingAuctions, pendingAuction); end end end return pendingAuctions;end--------------------------------------------------------------------------------- Prints the pending auctions.-------------------------------------------------------------------------------function printPendingAuctions() chatPrint("Pending Auctions:"); if (BeanCounterRealmDB.pendingAuctions) then for item in BeanCounterRealmDB.pendingAuctions do local pendingAuctionsTable = BeanCounterRealmDB.pendingAuctions[item]; for index = 1, table.getn(pendingAuctionsTable) do local pendingAuction = unpackPendingAuction(pendingAuctionsTable[index]); printPendingAuction(chatPrint, nil, pendingAuction); end end endend--------------------------------------------------------------------------------- Calls the specified print function for the pending auction.-------------------------------------------------------------------------------function printPendingAuction(printFunc, prefix, item, pendingAuction) if (prefix == nil) then prefix = ""; end printFunc( prefix.. date("%c", pendingAuction.time)..", ".. item..", ".. stringFromNumber(pendingAuction.quantity)..", ".. stringFromNumber(pendingAuction.bid)..", ".. stringFromNumber(pendingAuction.buyout)..", ".. stringFromNumber(pendingAuction.runTime)..", ".. stringFromNumber(pendingAuction.deposit)..", ".. stringFromNumber(pendingAuction.consignmentPercent)..", ".. nilSafeStringFromString(getPlayerName(pendingAuction.sellerId)));end--=============================================================================-- Completed Auctions functions--=============================================================================-------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -