Advent of Ascension Wiki

1.7.10版本的玩家请注意,本Mod的1.7.10版本在此wiki上正式停止支持。这也意味着,在绝大多数页面上,关于1.7.10版本的内容会被移除。如果您需要关于1.7.10版本的信息,您可以尝试翻阅相应页面在2019年2月之前的历史版本(点击页面右上角的“历史”标签可以查看所有历史版本)
如果您希望评论、询问相关信息,或是表达自己的顾虑,请至官方Discord服务器或移步社区主页

了解更多

Advent of Ascension Wiki
Advertisement

此模块生效于Template:LootTable


local p = {}

function p.lootTable(frame)
	-- pass args into the module
	args = frame:getParent().args
	
	translationStrings = mw.loadData('Module:Atc/data')

	local tableColors = {
		'#EEEEEE',
		'#feefcd',
		'#e8f3d8',
		'#eae9e1',
		'#f9e6ff',
		'#f6ffcc',
		'#e6ffee',
		'#ffe6e6',
		'#e6fcff',
		'#f2f2f2'
	}
	local numberColumns = 5
	
	local output = {}  -- list of strings to be concatenated into final output
	local poolWeights = {}  -- stores weights for each pool separately
	local allPools = {}  -- stores each pool as a nested table
	
	table.insert(output, '{| class = "wikitable"\n|-')

	local title = ''
	local centerColumn = ''
	
	if (args.type == 'chest') then
		title = '箱子战利品'
		centerColumn = '幸运'
	else
		title = '独特掉落'
		centerColumn = frame:expandTemplate{title = 'tooltip', args = {'抢夺', '带有抢夺魔咒会增加物品获得数量。'}}
	end
	
	if args.title then
		title = args.title
	end
	
	if args.otherlooting then
		centerColumn = args.otherlooting
	end

	table.insert(output, '! colspan = ' .. numberColumns .. ' | ' .. title)
	table.insert(output, '|-\n! 物品 !! 数量 !! ' .. centerColumn .. ' !! 概率 !! 注释\n|-')

	
	-- parse actual loot info; currently supports up to 10 "pool=" arguments
	for poolNumber=1, 10 do
		local poolArg = args['pool'..poolNumber]
		if poolArg then
			local currentPool = {}
			currentPool.items = {}
			currentPool.poolNumber = poolNumber
			currentPool.rolls = args['rolls'..poolNumber]
			currentPool.bonusRolls = args['bonusrolls'..poolNumber] or '0'
			
			poolArg = poolArg .. '\n'  -- allow last line to be matched like the rest
			
			-- parse input of pool parameter
			for line in mw.ustring.gmatch(poolArg, '[^\r\n]+[\r\n]') do  -- split on newline
				--local splitLine = {}
				local currentItem = {}
				for key, value in mw.ustring.gmatch(line, '([%a]+)%s*:%s*(.-)%s*[;\r\n]') do
					if value ~= '' then
						currentItem[key:lower()] = value
					end
				end
				
				-- translate item name to Chinese if translation exists
				if currentItem.item then
					-- set image to English name png if not already specified
					if not currentItem.image then
						currentItem.image = currentItem.item .. '.png'	
					end
					currentItem.item = translationStrings[currentItem.item]	or currentItem.item
				end
				
				if not currentItem.quantity then
					currentItem.quantity = 'style="text-align:center;" | –'
				end
				
				if currentItem.looting then
					currentItem.looting = '+' .. currentItem.looting .. ' 每级'
				else
					currentItem.looting = 'style="text-align:center;" | –'
				end
				
				local weight
				if currentItem.weight then
					weight = tonumber(currentItem.weight)
					currentItem.weight = weight
				end
				
				if weight then
					if not poolWeights[poolNumber] then
						poolWeights[poolNumber] = weight
					else
						poolWeights[poolNumber] = poolWeights[poolNumber] + weight
					end
				end
				
				if not currentItem.notes then
					currentItem.notes = ''	
				end
				
				table.insert(currentPool.items, currentItem)
			end
			table.insert(allPools, currentPool)
		end
	end

	-- create output from parsed input
	for _, currentPool in ipairs(allPools) do
		local poolNumber = currentPool.poolNumber
		local color = tableColors[poolNumber]
		if not color then
			color = ''
		else
			color = ' style="background-color:' .. color .. ';"'
		end
		
		for _, currentItem in ipairs(currentPool.items) do
			local itemLink = ''
	
			if currentItem.item == '' or not currentItem.item or mw.ustring.lower(currentItem.item) == 'nothing' then
				itemLink = '无'
			else
				local itemName = currentItem.item
				
				-- strip "mcw:" from imagelink and displayed name, while allowing article link to work normally
				if itemName:sub(1, 4) == 'mcw:' then
					itemName = itemName:sub(5)	
				end
				
				local image = currentItem.image
				
				local imagesize = '32px'
				if currentItem.imagesize then
					imagesize = currentItem.imagesize
				end
				
				local imageLink = '[[File:' .. image .. '|' .. imagesize .. ']] '
				if currentItem.image and currentItem.image:lower() == 'none' then
					imageLink = ''	
				end
				
				itemLink = imageLink .. '[['.. currentItem.item ..'|' .. itemName .. ']]'
			end
		
			local chance = 'style="text-align:center;" | –'
			-- quantity, looting and group stay as is
			if currentItem.weight and poolWeights[poolNumber] then  -- weight exists and is not 0
				chance = string.format("%.1f", (currentItem.weight / poolWeights[poolNumber]) * 100) .. '%'
			end
			
			table.insert(output, '|-' .. color)
			table.insert(output, '| ' .. itemLink .. ' || ' .. currentItem.quantity .. ' || '
				.. currentItem.looting .. ' || ' .. chance .. ' || ' .. currentItem.notes)
		end
		
		-- display info about pool rolls at the bottom of each pool
		if currentPool.rolls then
			table.insert(output, '|-' .. color)
			local poolText = '上述随机池将随机选取'
			
			if currentPool.rolls == '1' then
				poolText = poolText .. '1次'
			else
				poolText = poolText .. currentPool.rolls .. '次'
			end
			
			if currentPool.bonusRolls ~= '0' then
				poolText = poolText .. ',同时每级幸运额外随机选取'
				if currentPool.bonusRolls == '1' then 
					poolText = poolText .. '1次'
				else
					poolText = poolText .. currentPool.bonusRolls .. '次'	
				end
			end
			table.insert(output, '| colspan = ' .. numberColumns .. ' | ' .. poolText .. '。')
		end
	end
	-- footer
	table.insert(output, '|}')
	
	return table.concat(output, '\n')
end

return p;
Advertisement