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

📄 aucstatistic.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
	local lowestPrice = 0;	local nextLowest = 0;	local lows = Auctioneer_Lowests[auctKey][lowKey];	if (lows) then		lowSig = lows.lowSig;		nextSig = lows.nextSig;		lowestPrice = lows.lowestPrice or 0;		nextLowest = lows.nextLowest or 0;		itemCat = lows.cat;	end	return lowSig, lowestPrice, nextSig, nextLowest, itemCat;endfunction buildLowestCache(auctKey)	if (Auctioneer_Lowests == nil) then Auctioneer_Lowests = {}; end	Auctioneer_Lowests[auctKey] = {}	local id, rprop, enchant, name, count, min, buyout, uniq, lowKey, priceForOne, lowests;	if (AuctionConfig and AuctionConfig.snap and AuctionConfig.snap[auctKey]) then		for itemCat, cData in pairs(AuctionConfig.snap[auctKey]) do			for sig, sData in pairs(cData) do				id,rprop,enchant, name, count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(sig);				lowKey = id..":"..rprop;				if (not Auctioneer_Lowests[auctKey][lowKey]) then Auctioneer_Lowests[auctKey][lowKey] = {cat = itemCat} end				lowests = Auctioneer_Lowests[auctKey][lowKey]				if (Auctioneer.Util.NullSafe(buyout) > 0) then					priceForOne = Auctioneer.Util.PriceForOne(buyout, count)					if (lowests.lowestPrice == nil) or (priceForOne < lowests.lowestPrice) then						lowests.lowestPrice, lowests.nextLowest = priceForOne, lowests.lowestPrice						lowests.lowSig, lowests.nextSig = sig, lowests.lowSig					elseif (lowests.nextLowest == nil) or (priceForOne < lowests.nextLowest) then						lowests.nextLowest = priceForOne						lowests.nextSig = sig					end				end			end		end	endend-- execute the '/auctioneer low <itemName>' that returns the auction for an item with the lowest buyoutfunction doLow(link)	local auctKey = Auctioneer.Util.GetAuctionKey();	local items = Auctioneer.Util.GetItems(link);	local itemLinks = Auctioneer.Util.GetItemHyperlinks(link);	if (items) then		for pos,itemKey in pairs(items) do			local auctionSignature = findLowestAuctions(itemKey);			if (not auctionSignature) then				Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtNoauct'), itemLinks[pos]));			else				local itemCat = Auctioneer.Util.GetCatForKey(itemKey);				local auction = Auctioneer.Core.GetSnapshot(auctKey, itemCat, auctionSignature);				local x,x,x, x, count, x, buyout, x = Auctioneer.Core.GetItemSignature(auctionSignature);					Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtLowLine'), Auctioneer.Util.ColorTextWhite(count.."x")..auction.itemLink, EnhTooltip.GetTextGSC(buyout), Auctioneer.Util.ColorTextWhite(auction.owner), EnhTooltip.GetTextGSC(buyout / count), Auctioneer.Util.ColorTextWhite(percentLessThan(getUsableMedian(itemKey), buyout / count).."%")));			end		end	endendfunction doMedian(link)	local items = Auctioneer.Util.GetItems(link);	local itemLinks = Auctioneer.Util.GetItemHyperlinks(link);	if (items) then		for pos,itemKey in pairs(items) do			local median, count = getUsableMedian(itemKey);			if (not median) then				Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtMedianNoauct'), Auctioneer.Util.ColorTextWhite(itemName)));			else				if (not count) then count = 0 end				Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtMedianLine'), count, Auctioneer.Util.ColorTextWhite(itemName), EnhTooltip.GetTextGSC(median)));			end		end	endendfunction doHSP(link)	local items = Auctioneer.Util.GetItems(link);	local itemLinks = Auctioneer.Util.GetItemHyperlinks(link);	if (items) then		for pos,itemKey in pairs(items) do			local highestSellablePrice = getHSP(itemKey, Auctioneer.Util.GetAuctionKey());			Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtHspLine'), itemLinks[pos], EnhTooltip.GetTextGSC(Auctioneer.Util.NilSafeString(highestSellablePrice))));		end	endendfunction getBidBasedSellablePrice(itemKey,realm, avgMin,avgBuy,avgBid,bidPct,buyPct,avgQty,seenCount)	-- We can pass these values along if we have them.	if (seenCount == nil) then		avgMin,avgBuy,avgBid,bidPct,buyPct,avgQty,seenCount = getMeans(itemKey, realm);	end	local bidBasedSellPrice = 0;	local typicalBuyout = 0;	local medianBuyout = getUsableMedian(itemKey, realm);	if medianBuyout and avgBuy then		typicalBuyout = math.min(avgBuy, medianBuyout);	elseif medianBuyout then		typicalBuyout = medianBuyout;	else		typicalBuyout = avgBuy or 0;	end	if (avgBid) then		bidBasedSellPrice = math.floor((3*typicalBuyout + avgBid) / 4);	else		bidBasedSellPrice = typicalBuyout;	end	return bidBasedSellPrice;end-- returns the best market price - 0, if no market price could be calculatedfunction getMarketPrice(itemKey, realm, buyoutValues)	-- make sure to call this function with valid parameters! No check is being performed!	local buyoutMedian = Auctioneer.Util.NullSafe(getUsableMedian(itemKey, realm, buyoutValues))	local avgMin, avgBuy, avgBid, bidPct, buyPct, avgQty, meanCount = getMeans(itemKey, realm)	local commonBuyout = 0	-- assign the best common buyout	if buyoutMedian > 0 then		commonBuyout = buyoutMedian	elseif meanCount and meanCount > 0 then		-- if a usable median does not exist, use the average buyout instead		commonBuyout = avgBuy;	end	local playerMade, skill, level = Auctioneer.Core.IsPlayerMade(itemKey);	if Auctioneer.Core.Constants.BidBasedCategories[Auctioneer.Core.GetItemCategory(itemKey)] and not (playerMade and level < 250 and commonBuyout < 100000) then		-- returns bibasedSellablePrice for bidbaseditems, playermade items or if the buyoutprice is not present or less than 10g		return getBidBasedSellablePrice(itemKey,realm, avgMin,avgBuy,avgBid,bidPct,buyPct,avgQty,seenCount)	end	-- returns buyoutMedian, if present - returns avgBuy otherwise, if meanCount > 0 - returns 0 otherwise	return commonBuyoutend-- Returns market information relating to the HighestSellablePrice for one of the given items.-- If you use cached data it may be affected by buying/selling items.HSPCOUNT = 0; CACHECOUNT = 0;function getHSP(itemKey, realm, buyoutValues, itemCat)	if (itemKey == nil) then                                 -- make itemKey a required parameter		EnhTooltip.DebugPrint("ERROR: Calling Auctioneer.Statistic.GetHSP(itemKey, realm) - Function requires valid itemKey.");		return nil;	end	if (realm == nil) then		EnhTooltip.DebugPrint("WARNING: Auctioneer.Statistic.GetHSP(itemKey, realm) - Defaulting to player realm.");		EnhTooltip.DebugPrint("This is only some debugging code. THIS IS NO BUG!");		realm = Auctioneer.Util.GetAuctionKey();	end	if (not Auctioneer_HSPCache) then Auctioneer_HSPCache = {}; end	CACHECOUNT = CACHECOUNT + 1;	if (not Auctioneer_HSPCache[realm]) then Auctioneer_HSPCache[realm] = {} end	local cached = Auctioneer_HSPCache[realm][itemKey];	if (cached) then		local cache = Auctioneer.Util.Split(cached, ";");		return tonumber(cache[1]), tonumber(cache[2]), tonumber(cache[3]), cache[4], tonumber(cache[5]), cache[6];	end	HSPCOUNT = HSPCOUNT + 1;	local highestSellablePrice = 0;	local warn = _AUCT('FrmtWarnNodata');	EnhTooltip.DebugPrint("Getting HSP, calling GetMarketPrice", itemKey, realm);	if (not buyoutValues) then		local sbuy = Auctioneer.Core.GetSnapshotInfo(realm, itemKey);		if sbuy then			buyoutValues = sbuy.buyoutPrices;		end	end	local marketPrice = getMarketPrice(itemKey, realm, buyoutValues);	-- Get our user-set pricing parameters	local lowestAllowedPercentBelowMarket = tonumber(Auctioneer.Command.GetFilterVal('pct-maxless'));	local discountLowPercent              = tonumber(Auctioneer.Command.GetFilterVal('pct-underlow'));	local discountMarketPercent           = tonumber(Auctioneer.Command.GetFilterVal('pct-undermkt'));	local discountNoCompetitionPercent    = tonumber(Auctioneer.Command.GetFilterVal('pct-nocomp'));	local vendorSellMarkupPercent         = tonumber(Auctioneer.Command.GetFilterVal('pct-markup'));	local x, histCount = getUsableMedian(itemKey, realm, buyoutValues);	histCount = Auctioneer.Util.NullSafe(histCount);	local id = Auctioneer.Util.BreakItemKey(itemKey);	-- Get the snapshot sigs of the two lowest auctions	local currentLowestSig = nil;	local currentLowestBuyout = nil;	local currentLowestCount = nil;	local nextLowestSig = nil;	local nextLowestBuyout = nil;	local nextLowestCount = nil;	local lowSig, lowPrice, nextSig, nextPrice, itemCat = findLowestAuctions(itemKey, realm);	if lowSig then		currentLowestSig = lowSig;		currentLowestBuyout = lowPrice;		nextLowestSig = nextSig;		nextLowestBuyout = nextPrice;	end	if (not itemCat) then itemCat = Auctioneer.Util.GetCatForKey(itemKey) end	local hsp, market, warn = determinePrice(id, realm, marketPrice, currentLowestBuyout, currentLowestSig, lowestAllowedPercentBelowMarket, discountLowPercent, discountMarketPercent, discountNoCompetitionPercent, vendorSellMarkupPercent, itemCat);	local nexthsp, x, nextwarn = determinePrice(id, realm, marketPrice, nextLowestBuyout, nextLowestSig, lowestAllowedPercentBelowMarket, discountLowPercent, discountMarketPercent, discountNoCompetitionPercent, vendorSellMarkupPercent, itemCat);	if (not hsp) then		EnhTooltip.DebugPrint("Unable to calc HSP for",id, realm, marketPrice, currentLowestBuyout, currentLowestSig);		hsp = 0;		warn = "";	end	if (not nexthsp) then nexthsp = 0; nextwarn = ""; end	EnhTooltip.DebugPrint("Auction data: ", hsp, histCount, market, warn, nexthsp, nextwarn);	local cache = string.format("%d;%d;%d;%s;%d;%s", hsp,histCount,market,warn, nexthsp,nextwarn);	Auctioneer_HSPCache[realm][itemKey] = cache;	return hsp, histCount, market, warn, nexthsp, nextwarn;endfunction determinePrice(id, realm, marketPrice, currentLowestBuyout, currentLowestSig, lowestAllowedPercentBelowMarket, discountLowPercent, discountMarketPercent, discountNoCompetitionPercent, vendorSellMarkupPercent, itemCat)	local warn, highestSellablePrice, lowestBuyoutPriceAllowed;	if marketPrice and marketPrice > 0 then		if currentLowestBuyout and currentLowestBuyout > 0 then			lowestBuyoutPriceAllowed = subtractPercent(marketPrice, lowestAllowedPercentBelowMarket);			if (not itemCat) then itemCat = Auctioneer.Util.GetCatForSig(currentLowestSig) end			-- since we don't want to decode the full data unless there's a chance it belongs to the player			-- do a substring search for the players name first.			-- For some reason AuctionConfig.snap[realm][itemCat][currentLowestSig] sometimes doesn't			-- exist, even if currentLowestBuyout is set. Added a check for this as a workaround, but			-- the real cause should probably be tracked down - Thorarin			local snap;			if (AuctionConfig.snap[realm][itemCat][currentLowestSig] and string.find(AuctionConfig.snap[realm][itemCat][currentLowestSig], UnitName("player"), 1, true)) then				snap = Auctioneer.Core.GetSnapshot(realm, itemCat, currentLowestSig);			end			if snap and snap.owner == UnitName("player") then				highestSellablePrice = currentLowestBuyout; -- If I am the lowest seller use same low price				warn = _AUCT('FrmtWarnMyprice');			elseif (currentLowestBuyout < lowestBuyoutPriceAllowed) then				highestSellablePrice = subtractPercent(marketPrice, discountMarketPercent);				warn = _AUCT('FrmtWarnToolow');			else				if (currentLowestBuyout > marketPrice) then					highestSellablePrice = subtractPercent(marketPrice, discountNoCompetitionPercent);					warn = _AUCT('FrmtWarnAbovemkt');				end				-- Account for negative discountNoCompetitionPercent values				if (currentLowestBuyout <= marketPrice or highestSellablePrice >= currentLowestBuyout) then					-- set highest price to "Discount low"					highestSellablePrice = subtractPercent(currentLowestBuyout, discountLowPercent);					warn = string.format(_AUCT('FrmtWarnUndercut'), discountLowPercent);				end			end		else -- no low buyout, use discount no competition			-- set highest price to "Discount no competition"			highestSellablePrice = subtractPercent(marketPrice, discountNoCompetitionPercent);			warn = _AUCT('FrmtWarnNocomp');		end	else -- no market		-- Note: urentLowestBuyout is nil, incase the realm is not the current player's realm		if currentLowestBuyout and currentLowestBuyout > 0 then			-- set highest price to "Discount low"			EnhTooltip.DebugPrint("Discount low case 2");			highestSellablePrice = subtractPercent(currentLowestBuyout, discountLowPercent);			warn = string.format(_AUCT('FrmtWarnUndercut'), discountLowPercent);		else			local baseData;			if (Informant) then baseData = Informant.GetItem(id) end			if (baseData and baseData.sell) then				-- use vendor prices if no auction data available				local vendorSell = Auctioneer.Util.NullSafe(baseData.sell); -- use vendor prices				highestSellablePrice = addPercent(vendorSell, vendorSellMarkupPercent);				warn = string.format(_AUCT('FrmtWarnMarkup'), vendorSellMarkupPercent);			end		end	end	return highestSellablePrice, marketPrice, warn;endAuctioneer.Statistic = {	SubtractPercent = subtractPercent,	AddPercent = addPercent,	PercentLessThan = percentLessThan,	GetLowest = getLowest,	GetMedian = getMedian,	GetPercentile = getPercentile,	GetMeans = getMeans,	GetItemSnapshotMedianBuyout = getItemSnapshotMedianBuyout,	GetSnapMedian = getItemSnapshotMedianBuyout,	GetItemHistoricalMedianBuyout = getItemHistoricalMedianBuyout,	GetHistMedian = getItemHistoricalMedianBuyout,	GetUsableMedian = getUsableMedian,	GetCurrentBid = getCurrentBid,	IsBadResaleChoice = isBadResaleChoice,	ProfitComparisonSort = profitComparisonSort,	RoundDownTo95 = roundDownTo95,	FindLowestAuctions = findLowestAuctions,	BuildLowestCache = buildLowestCache,	DoLow = doLow,	DoMedian = doMedian,	DoHSP = doHSP,	GetBidBasedSellablePrice = getBidBasedSellablePrice,	GetMarketPrice = getMarketPrice,	GetHSP = getHSP,	DeterminePrice = determinePrice,}

⌨️ 快捷键说明

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