⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 purchasesdb.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 4 页
字号:
				printPendingBid(chatPrint, nil, item, pendingBid);			end		end	endend--------------------------------------------------------------------------------- Calls the specified print function for the pending bid.-------------------------------------------------------------------------------function printPendingBid(printFunc, prefix, item, pendingBid)	if (prefix == nil) then		prefix = "";	end	printFunc(		prefix..		date("%c", pendingBid.time)..", "..		item..", "..		pendingBid.quantity..", "..		pendingBid.bid..", "..		nilSafeStringFromString(pendingBid.seller)..", "..		stringFromNumber(pendingBid.timeLeft)..", "..		stringFromBoolean(pendingBid.isBuyout)..", "..		nilSafeStringFromString(getPlayerName(pendingBid.buyerId)));end--------------------------------------------------------------------------------- Checks if there is a potential pending bid.-------------------------------------------------------------------------------function isPendingBid(item, quantity, bid, seller, isBuyout, isSuccessful)	local pendingBids = getPendingBidsTableForItem(item);	if (pendingBids) then		for index = 1, table.getn(pendingBids) do			local pendingBid = unpackPendingBid(pendingBids[index]);			if ((quantity == nil or pendingBid.quantity == nil or quantity == pendingBid.quantity) and				(bid == nil or pendingBid.bid == nil or bid == pendingBid.bid) and				(seller == nil or pendingBid.seller == nil or seller == pendingBid.seller) and				(isBuyout == nil or pendingBid.isBuyout == nil or isBuyout == pendingBid.isBuyout) and				(isSuccessful == nil or pendingBid.isSuccessful == nil or isSuccessful == pendingBid.isSuccessful)) then				return true;			end		end	end	return false;end--=============================================================================-- Completed Bids functions--=============================================================================--------------------------------------------------------------------------------- Adds a successful bid to the database-------------------------------------------------------------------------------function addSuccessfulBid(timestamp, item, quantity, bid, seller, isBuyout)	addCompletedBid(timestamp, item, quantity, bid, seller, isBuyout, true);end--------------------------------------------------------------------------------- Adds a successful bid to the database-------------------------------------------------------------------------------function addFailedBid(timestamp, item, bid)	addCompletedBid(timestamp, item, nil, bid, nil, nil, false);end--------------------------------------------------------------------------------- Adds a completed bid to the database-------------------------------------------------------------------------------function addCompletedBid(timestamp, item, quantity, bid, seller, isBuyout, isSuccessful)	if (item and (quantity or bid)) then		-- Check if we have enough information to add the purchase now.		local isPurchaseRecorded = false;		if (quantity and bid and seller and isBuyout ~= nil and isSuccessful) then			addPurchase(timestamp, item, quantity, bid, seller, isBuyout, true);			isPurchaseRecorded = true;		end		-- Add the completed bid.		if (isPendingBid(item, quantity, bid, seller, isBuyout, isSuccessful)) then			-- Create a packed record.			local completedBid = {};			completedBid.time = timestamp;			completedBid.quantity = quantity;			completedBid.bid = bid;			completedBid.seller = seller;			completedBid.isBuyout = isBuyout;			completedBid.isSuccessful = isSuccessful;			completedBid.isPurchaseRecorded = isPurchaseRecorded;			completedBid.buyerId = getCurrentPlayerId();			local packedCompletedBid = packCompletedBid(completedBid);			-- Add the completed bid to the table.			local completedBids = getCompletedBidsTableForItem(item, true);			table.insert(completedBids, packedCompletedBid);			printCompletedBid(debugPrint, "Added completed bid: ", item, completedBid);			-- Attmept to reconcile bids for this item.			reconcileBidsByQuantityOrBids(item, quantity, bid);		end	else		debugPrint("Invalid call to addCompletedBid()");	endend--------------------------------------------------------------------------------- Deletes a completed bid from the database.---- If completedBids is provided, the completed bid will be removed from it.-------------------------------------------------------------------------------function deleteCompletedBidByIndex(item, index, reason, completedBids)	-- Update the unpacked completed bid list, if provided	local completedBid = nil;	if (completedBids) then		-- Iterate in reverse since we will be removing the completed bid		-- from the list when we find it.		for completedIndex = table.getn(completedBids), 1, -1 do			local bid = completedBids[completedIndex];			if (index == bid.index) then				completedBid = bid;				table.remove(completedBids, completedIndex);			elseif (index < bid.index) then				bid.index = bid.index - 1;			end		end	end	-- Grab the completed bids table for the item.	local completedBidsTable = getCompletedBidsTableForItem(item);	if (completedBidsTable) then		-- Get the completed bid if we don't already have it.		if (completedBid == nil) then			completedBid = unpackCompletedBid(completedBidsTable[index]);		end				-- Remove the completed bid from the table.		table.remove(completedBidsTable, index);		if (table.getn(completedBidsTable)) then			getCompletedBidsTableForItem(item); -- Deletes the table		end				-- Debug noise.		printCompletedBid(			debugPrint,			"Deleted completed bid ("..nilSafeStringFromString(reason).."): ",			item,			completedBid);	endend--------------------------------------------------------------------------------- Converts a completed bid into a ';' delimited string.-------------------------------------------------------------------------------function packCompletedBid(completedBid)	return 		completedBid.time..";"..		stringFromNumber(completedBid.quantity)..";"..		stringFromNumber(completedBid.bid)..";"..		nilSafeStringFromString(completedBid.seller)..";"..		stringFromBoolean(completedBid.isBuyout)..";"..		stringFromBoolean(completedBid.isSuccessful)..";"..		stringFromBoolean(completedBid.isPurchaseRecorded)..";"..		stringFromNumber(completedBid.buyerId);end--------------------------------------------------------------------------------- Converts a ';' delimited string into a completed bid.-------------------------------------------------------------------------------function unpackCompletedBid(packedCompletedBid)	local completedBid = {};	_, _, completedBid.time, completedBid.quantity, completedBid.bid, completedBid.seller, completedBid.isBuyout, completedBid.isSuccessful, completedBid.isPurchaseRecorded, completedBid.buyerId = string.find(packedCompletedBid, "(.+);(.+);(.+);(.+);(.+);(.+);(.+);(.+)");	completedBid.time = numberFromString(completedBid.time);	completedBid.quantity = numberFromString(completedBid.quantity);	completedBid.bid = numberFromString(completedBid.bid);	completedBid.seller = stringFromNilSafeString(completedBid.seller);	completedBid.isBuyout = booleanFromString(completedBid.isBuyout);	completedBid.isSuccessful = booleanFromString(completedBid.isSuccessful);	completedBid.isPurchaseRecorded = booleanFromString(completedBid.isPurchaseRecorded);	completedBid.buyerId = numberFromString(completedBid.buyerId);	return completedBid;end--------------------------------------------------------------------------------- Gets the completed bids table for the specified item. The table contains-- packed records.-------------------------------------------------------------------------------function getCompletedBidsTableForItem(item, create)	local completedBidsTable = BeanCounterRealmDB.completedBids;	if (completedBidsTable == nil) then		completedBidsTable = {};		BeanCounterRealmDB.completedBids = completedBidsTable;	end	-- Get the table for the item. Create or delete if appropriate.	local completedBidsForItemTable = completedBidsTable[item];	if (completedBidsForItemTable == nil and create) then		completedBidsForItemTable = {};		completedBidsTable[item] = completedBidsForItemTable;	elseif (completedBidsForItemTable and table.getn(completedBidsForItemTable) == 0 and not create) then		completedBidsTable[item] = nil;	end	return completedBidsForItemTable;end--------------------------------------------------------------------------------- Gets the completed bids (unpacked) for the specified item-------------------------------------------------------------------------------function getCompletedBidsForItem(item, filterFunc)	local completedBids = {};	local completedBidsTable = getCompletedBidsTableForItem(item);	if (completedBidsTable) then		for index in completedBidsTable do			local completedBid = unpackCompletedBid(completedBidsTable[index]);			completedBid.index = index;			if (filterFunc == nil or filterFunc(completedBid)) then				table.insert(completedBids, completedBid);			end		end	end	return completedBids;end--------------------------------------------------------------------------------- Prints the completed bids.-------------------------------------------------------------------------------function printCompletedBids()	chatPrint("Completed Bids:");	if (BeanCounterRealmDB.completedBids) then		for item in BeanCounterRealmDB.completedBids do			local completedBidsTable = BeanCounterRealmDB.completedBids[item];			for index = 1, table.getn(completedBidsTable) do				local completedBid = unpackCompletedBid(completedBidsTable[index]);				printCompletedBid(chatPrint, nil, item, completedBid);			end		end	endend--------------------------------------------------------------------------------- Calls the specified print function for the completed bid.-------------------------------------------------------------------------------function printCompletedBid(printFunc, prefix, item, completedBid)	if (prefix == nil) then		prefix = "";	end	printFunc(		prefix..		date("%c", completedBid.time)..", "..		item..", "..		stringFromNumber(completedBid.quantity)..", "..		stringFromNumber(completedBid.bid)..", "..		nilSafeStringFromString(completedBid.seller)..", "..		stringFromBoolean(completedBid.isBuyout)..", "..		stringFromBoolean(completedBid.isSuccessful)..", "..		stringFromBoolean(completedBid.isPurchaseRecorded)..", "..		nilSafeStringFromString(getPlayerName(completedBid.buyerId)));end--=============================================================================-- Purchases functions--=============================================================================--------------------------------------------------------------------------------- Adds a purchase to the database.-------------------------------------------------------------------------------function addPurchase(timestamp, item, quantity, cost, seller, isBuyout)	if (item and quantity and cost) then		-- Create a packed record.		local purchase = {};		purchase.time = timestamp;		purchase.quantity = quantity;		purchase.cost = cost;		purchase.seller = seller;		purchase.isBuyout = isBuyout;		purchase.buyerId = getCurrentPlayerId();		local packedPurchase = packPurchase(purchase);		-- Add the purchase to the table.		local purchasesTable = getPurchasesTableForItem(item, true);		table.insert(purchasesTable, packedPurchase);		-- Debugging noise.		printPurchase(debugPrint, "Added purchase: ", item, purchase);	else		debugPrint("Invalid call to addPurchase()");	endend--------------------------------------------------------------------------------- Converts a purchase into a ';' delimited string.-------------------------------------------------------------------------------function packPurchase(purchase)	return		purchase.time..";"..		stringFromNumber(purchase.quantity)..";"..		stringFromNumber(purchase.cost)..";"..		nilSafeStringFromString(purchase.seller)..";"..		stringFromBoolean(purchase.isBuyout)..";"..		stringFromNumber(purchase.buyerId);end--------------------------------------------------------------------------------- Converts a ';' delimited string into a purchase.-------------------------------------------------------------------------------function unpackPurchase(packedPurchase)	local purchase = {};	_, _, purchase.time, purchase.quantity, purchase.cost, purchase.seller, purchase.isBuyout, purchase.buyerId = string.find(packedPurchase, "(.+);(.+);(.+);(.+);(.+);(.+)");	purchase.time = numberFromString(purchase.time);	purchase.quantity = numberFromString(purchase.quantity);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -