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

📄 enchantrixbarker.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
function Enchantrix_CreateBarker()	local availableEnchants = {};	local numAvailable = 0;	local temp = GetCraftSkillLine(1);	if Enchantrix_BarkerGetZoneText() ~= nil then		Enchantrix_ResetBarkerString();		Enchantrix_ResetPriorityList();		if (temp) then			for i=1, GetNumCrafts(),1 do				local craftName, craftSubSpellName, craftType, numEnchantsAvailable, isExpanded = GetCraftInfo(i);				if( ( numEnchantsAvailable > 0 ) and ( string.find( craftName, "Enchant" ) ~= nil ) ) then --have reagents and it is an enchant					--Enchantrix.Util.ChatPrint(""..craftName, 0.8, 0.8, 0.2);					local cost = 0;					for j=1,GetCraftNumReagents(i),1 do						local a,b,c = GetCraftReagentInfo(i,j);						reagent = GetCraftReagentItemLink(i,j);						--Enchantrix.Util.ChatPrint("Adding: "..reagent.." - "..Enchantrix_GetReagentHSP(reagent).." x "..c.." = " ..(Enchantrix_GetReagentHSP(reagent)*c/10000));						cost = cost + (Enchantrix_GetReagentHSP(reagent)*c);					end					local profit = cost * Enchantrix_BarkerGetConfig("profit_margin")*0.01;					if( profit > Enchantrix_BarkerGetConfig("highest_profit") ) then						profit = Enchantrix_BarkerGetConfig("highest_profit");					end					local price = Enchantrix_RoundPrice(cost + profit);					local enchant = {						index = i,						name = craftName,						type = craftType,						available = numEnchantsAvailable,						isExpanded = isExpanded,						cost = cost,						price = price,						profit = price - cost					};					availableEnchants[ numAvailable] = enchant;					--Enchantrix.Util.ChatPrint(GetCraftDescription(i));					--local p_gold,p_silver,p_copper = EnhTooltip.GetGSC(enchant.price);					--local pr_gold,pr_silver,pr_copper = EnhTooltip.GetGSC(enchant.profit);					--Enchantrix.Util.ChatPrint("Price: "..p_gold.."."..p_silver.."g, profit: "..pr_gold.."."..pr_silver.."g");					Enchantrix_AddEnchantToPriorityList( enchant )					--Enchantrix.Util.ChatPrint( "numReagents: "..GetCraftNumReagents(i) );					numAvailable = numAvailable + 1;				end			end			if numAvailable == 0 then				return nil			end			for i,element in ipairs(priorityList) do				--Enchantrix.Util.ChatPrint(""..element.enchant.name, 0.8, 0.8, 0.2);				Enchantrix_AddEnchantToBarker( element.enchant );			end			return Enchantrix_GetBarkerString();		else			Enchantrix.Util.ChatPrint("Enchant Window not open"); --TODO: Localize		end	end	return nilendfunction Enchantrix_ScoreEnchantPriority( enchant )	local score_item = 0;	if Enchantrix_BarkerGetConfig( Enchantrix_GetItemCategoryKey(enchant.index) ) then		score_item = Enchantrix_BarkerGetConfig( Enchantrix_GetItemCategoryKey(enchant.index) );		score_item = score_item * Enchantrix_BarkerGetConfig( 'factor_item' )*0.01;	end	local score_stat = 0;	if Enchantrix_BarkerGetConfig( Enchantrix_GetEnchantStat(enchant) ) then		score_stat = Enchantrix_BarkerGetConfig( Enchantrix_GetEnchantStat(enchant));	else		score_stat = Enchantrix_BarkerGetConfig( 'other' );	end	score_stat = score_stat * Enchantrix_BarkerGetConfig( 'factor_stat' )*0.01;	local score_price = 0;	local price_score_floor = Enchantrix_BarkerGetConfig("sweet_price");	local price_score_ceiling = Enchantrix_BarkerGetConfig("high_price");	if enchant.price < price_score_floor then		score_price = (price_score_floor - (price_score_floor - enchant.price))/price_score_floor * 100;	elseif enchant.price < price_score_ceiling then		range = (price_score_ceiling - price_score_floor);		score_price = (range - (enchant.price - price_score_floor))/range * 100;	end	score_price = score_price * Enchantrix_BarkerGetConfig( 'factor_price' )*0.01;	score_total = (score_item + score_stat + score_price);	return score_total * (1 - Enchantrix_BarkerGetConfig("randomise")*0.01) + math.random(300) * Enchantrix_BarkerGetConfig("randomise")*0.01;endfunction Enchantrix_ResetPriorityList()	priorityList = {};endfunction Enchantrix_AddEnchantToPriorityList(enchant)	local enchant_score = Enchantrix_ScoreEnchantPriority( enchant );	for i,priorityentry in ipairs(priorityList) do		if( priorityentry.score < enchant_score ) then			table.insert( priorityList, i, {score = enchant_score, enchant = enchant} );			return;		end	end	table.insert( priorityList, {score = enchant_score, enchant = enchant} );endfunction Enchantrix_RoundPrice( price )	local round	if( price < 5000 ) then		round = 1000;	elseif ( price < 20000 ) then		round = 2500;	else		round = 5000;	end	odd = math.mod(price,round);	price = price + (round - odd);	if( price < Enchantrix_BarkerGetConfig("lowest_price") ) then		price = Enchantrix_BarkerGetConfig("lowest_price");	end	return priceendfunction Enchantrix_GetReagentHSP( itemLink )	local itemID = Enchantrix.Util.GetItemIdFromLink(itemLink);	local itemKey = string.format("%s:0:0", itemID);	-- Work out what version if any of auctioneer is installed	local auctVerStr;	if (not Auctioneer) then		auctVerStr = AUCTIONEER_VERSION or "0.0.0";	else		auctVerStr = AUCTIONEER_VERSION or Auctioneer.Version or "0.0.0";	end	local auctVer = Enchantrix.Util.Split(auctVerStr, ".");	local major = tonumber(auctVer[1]) or 0;	local minor = tonumber(auctVer[2]) or 0;	local rev = tonumber(auctVer[3]) or 0;	if (auctVer[3] == "DEV") then rev = 0; minor = minor + 1; end	local hsp = nil;	if (major == 3 and minor == 0 and rev <= 11) then		--Enchantrix.Util.ChatPrint("Calling Auctioneer_GetHighestSellablePriceForOne");		if (rev == 11) then			hsp = Auctioneer_GetHighestSellablePriceForOne(itemKey, false, Auctioneer_GetAuctionKey());		else			if (Auctioneer_GetHighestSellablePriceForOne) then				hsp = Auctioneer_GetHighestSellablePriceForOne(itemKey, false);			elseif (getHighestSellablePriceForOne) then				hsp = getHighestSellablePriceForOne(itemKey, false);			end		end	elseif (major == 3 and (minor > 0 and minor <= 3) and (rev > 11 and rev < 675)) then		--Enchantrix.Util.ChatPrint("Calling GetHSP");		hsp = Auctioneer_GetHSP(itemKey, Auctioneer_GetAuctionKey());	elseif (major >= 3 and minor >= 3 and (rev >= 675 or rev == 0)) then		--Enchantrix.Util.ChatPrint("Calling Statistic.GetHSP");		hsp = Auctioneer.Statistic.GetHSP(itemKey, Auctioneer.Util.GetAuctionKey());	else		Enchantrix.Util.ChatPrint("Calling Nothing: "..major..", "..minor..", "..rev);	end	if hsp == nil then		hsp = 0;	end	return hsp;endlocal barkerString = '';local barkerCategories = {};function Enchantrix_ResetBarkerString()	barkerString = "("..Enchantrix_BarkerGetZoneText()..") Selling Enchants:"; --TODO: Localize	barkerCategories = {};endlocal short_location = {	Orgrimmar = 'Org',	['Thunder Bluff'] = 'TB',	Undercity = 'UC',	['Stormwind City'] = 'SW',	Darnassus = 'Dar',	['City of Ironforge'] = 'IF'};function Enchantrix_BarkerGetZoneText()	--Enchantrix.Util.ChatPrint(GetZoneText());	return short_location[GetZoneText()];endfunction Enchantrix_AddEnchantToBarker( enchant )	local currBarker = Enchantrix_GetBarkerString();	local category_key = Enchantrix_GetItemCategoryKey( enchant.index )	local category_string = "";	local test_category = {};	if barkerCategories[ category_key ] then		for i,element in ipairs(barkerCategories[category_key]) do			--Enchantrix.Util.ChatPrint("Inserting: "..i..", elem: "..element.index );			table.insert(test_category, element);		end	end	table.insert(test_category, enchant);	category_string = Enchantrix_GetBarkerCategoryString( test_category );	if string.len(currBarker) + string.len(category_string) > 255 then		return false;	end	if not barkerCategories[ category_key ] then		barkerCategories[ category_key ] = {};	end	table.insert( barkerCategories[ category_key ],enchant );	return true;endfunction Enchantrix_GetBarkerString()	local barker = ""..barkerString;	for index, key in ipairs(print_order) do		if( barkerCategories[key] ) then			barker = barker..Enchantrix_GetBarkerCategoryString( barkerCategories[key] )		end	end	return barker;endfunction Enchantrix_GetBarkerCategoryString( barkerCategory )	local barkercat = ""	barkercat = barkercat.." ["..Enchantrix_GetItemCategoryString(barkerCategory[1].index)..": ";	for j,enchant in ipairs(barkerCategory) do		if( j > 1) then			barkercat = barkercat..", "		end		barkercat = barkercat..Enchantrix_GetBarkerEnchantString(enchant);	end	barkercat = barkercat.."]"	return barkercatendfunction Enchantrix_GetBarkerEnchantString( enchant )	local p_gold,p_silver,p_copper = EnhTooltip.GetGSC(enchant.price);	enchant_barker = Enchantrix_GetShortDescriptor(enchant.index).." - ";	if( p_gold > 0 ) then		enchant_barker = enchant_barker..p_gold.."g";	end	if( p_silver > 0 ) then		enchant_barker = enchant_barker..p_silver.."s";	end	--enchant_barker = enchant_barker..", ";	return enchant_barkerendfunction Enchantrix_GetItemCategoryString( index )	local enchant = GetCraftInfo( index );	for key,category in pairs(categories) do		--Enchantrix.Util.ChatPrint( "cat key: "..key);		if( string.find( enchant, category.search ) ~= nil ) then			--Enchantrix.Util.ChatPrint( "cat key: "..key..", name: "..category.print..", enchant: "..enchant );			return category.print;		end	end	return 'Unknown';endfunction Enchantrix_GetItemCategoryKey( index )	local enchant = GetCraftInfo( index );	for key,category in pairs(categories) do		--Enchantrix.Util.ChatPrint( "cat key: "..key..", name: "..category );		if( string.find( enchant, category.search ) ~= nil ) then			return key;		end	end	return 'Unknown';endfunction EnchantrixBarker_GetCraftDescription( index )	return GetCraftDescription(index) or "";endfunction Enchantrix_GetShortDescriptor( index )	local long_str = string.lower(EnchantrixBarker_GetCraftDescription(index));	for index,attribute in ipairs(attributes) do		if( string.find( long_str, attribute ) ~= nil ) then			statvalue = string.sub(long_str ,string.find(long_str,'[0-9]+[^%%]'));			statvalue = string.sub(statvalue ,string.find(statvalue,'[0-9]+'));			return "+"..statvalue..' '..short_attributes[index];		end	end	local enchant = Enchantrix.Util.Split(GetCraftInfo(index), "-");	return enchant[table.getn(enchant)];endfunction Enchantrix_GetEnchantStat( enchant )	local index = enchant.index;	local long_str = string.lower(EnchantrixBarker_GetCraftDescription(index));	for index,attribute in ipairs(attributes) do		if( string.find( long_str, attribute ) ~= nil ) then			return short_attributes[index];		end	end	local enchant = Enchantrix.Util.Split(GetCraftInfo(index), "-");	return enchant[table.getn(enchant)];end

⌨️ 快捷键说明

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