Module:Necropolis packs: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
(show linked monster packs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:
local m_monsters = mw.loadData('Module:Monster_packs/data')
local m_monsters = mw.loadData('Module:Monster_packs/data')


local function _show_monsters(pack_ids)
local function _show_monsters(pack_ids, show_areas)
local result = {}
local result = {""}
-- #pack_ids doesn't work?
-- #pack_ids doesn't work?
if not pack_ids[1] then
if not pack_ids[1] then
Line 34: Line 34:
if pack.boss_chance ~= 0 then
if pack.boss_chance ~= 0 then
if pack.boss_count == 1 then
if pack.boss_count == 1 then
line = "** Leader (" .. pack.boss_chance .. "% chance): "
line = "** Leader"
else
else
line = "** " .. pack.boss_count .. " leaders (" .. pack.boss_chance .. "% chance): "
line = "** " .. pack.boss_count .. " leaders"
end
if pack.boss_chance == 100 then
line = line .. ": "
else
line = line .. " (" .. pack.boss_chance .. "% chance): "
end
end
for i, monster in ipairs(pack.boss_monsters) do
for i, monster in ipairs(pack.boss_monsters) do
Line 46: Line 51:
result[#result+1] = line
result[#result+1] = line
end
end
line = "** Areas: "
if show_areas then
for i, area in ipairs(pack.areas) do
line = "** Areas: "
if i ~= 1 then
for i, area in ipairs(pack.areas) do
line = line .. ", "
if i ~= 1 then
line = line .. ", "
end
line = line .. string.format("[[Area:%s|%s]] (%s)", string.gsub(area.area_id, "_", "~"), area.name, area.weight)
end
end
line = line .. string.format("[[Area:%s|%s]] (%s)", string.gsub(area.area_id, "_", "~"), area.name, area.weight)
result[#result+1] = line
end
end
result[#result+1] = line
end
end
return table.concat(result, '\n')
return table.concat(result, '\n')
Line 59: Line 66:


local function _expand_template(data)
local function _expand_template(data)
return m_util.string.strip(mw.getCurrentFrame():expandTemplate{
return m_util.string.trim(mw.getCurrentFrame():expandTemplate{
title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
args = {
args = {
Line 70: Line 77:


local function _render_pack(tpl_args)
local function _render_pack(tpl_args)
local ember = tpl_args and tpl_args.item_name
tpl_args = tpl_args or {}
local pack_id = tpl_args and tpl_args.pack_id
local pack_id = tpl_args.pack_id
if ember and not pack_id then
if tpl_args.item_name and not pack_id then
local found = m_lookup[ember]
local found = m_lookup[tpl_args.item_name]
if not found then
if not found then
return
return
Line 81: Line 88:
if pack_id then
if pack_id then
local data = m_data[pack_id]
local data = m_data[pack_id]
return mw.getCurrentFrame():preprocess(_expand_template(data))
if tpl_args.pack_composition and data.monster_pack_ids then
return mw.getCurrentFrame():preprocess(_expand_template(data) .. "\n" .. _show_monsters(data.monster_pack_ids, tpl_args.pack_areas))
else
return mw.getCurrentFrame():preprocess(_expand_template(data))
end
else
else
local all = {"==All known packs=="}
local all = {"==All known packs=="}
Line 89: Line 100:
all[#all+1] = _expand_template(data)
all[#all+1] = _expand_template(data)
if data.monster_pack_ids then
if data.monster_pack_ids then
all[#all+1] = _show_monsters(data.monster_pack_ids)
all[#all+1] = _show_monsters(data.monster_pack_ids, true)
end
end
end
end

Latest revision as of 01:27, 24 April 2024

Module documentation[view] [edit] [history] [purge]


Renders pack data for Template:Necropolis pack.

Usage

{{#invoke:Necropolis packs|function_name}}

require('Module:No globals')
local m_util = require('Module:Util')

local use_sandbox = m_util.misc.maybe_sandbox('Necropolis_packs')
local m_data = mw.loadData('Module:Necropolis_packs/data')
local m_lookup = mw.loadData('Module:Necropolis_pack_lookup/data')
local m_monsters = mw.loadData('Module:Monster_packs/data')

local function _show_monsters(pack_ids, show_areas)
	local result = {""}
	-- #pack_ids doesn't work?
	if not pack_ids[1] then
		return "No known monsters are associated with this pack."
	elseif not pack_ids[2] then
		result[#result+1] = "Pack composition (not visible through the lantern):"
	else
		result[#result+1] = "Pack composition (not visible through the lantern) - one of:"
	end
	for _, pack_id in ipairs(pack_ids) do
		local pack = m_monsters[pack_id]
		local line = "* Pack size: " .. pack.min_count .. '-' .. pack.max_count
		if pack.additional_count ~= 0 then
			line = line .. '+' .. pack.additional_count
		end
		result[#result+1] = line
		line = "** Monsters: "
		for i, monster in ipairs(pack.monsters) do
			if i ~= 1 then
				line = line .. ", "
			end
			line = line .. string.format("[[Monster:%s|%s]]", string.gsub(monster.monster_id, "_", "~"), monster.name)
		end
		result[#result+1] = line
		if pack.boss_chance ~= 0 then
			if pack.boss_count == 1 then
				line = "** Leader"
			else
				line = "** " .. pack.boss_count .. " leaders"
			end
			if pack.boss_chance == 100 then
				line = line .. ": "
			else
				line = line .. " (" .. pack.boss_chance .. "% chance): "
			end
			for i, monster in ipairs(pack.boss_monsters) do
				if i ~= 1 then
					line = line .. ", "
				end
				line = line .. string.format("[[Monster:%s|%s]]", string.gsub(monster.monster_id, "_", "~"), monster.name)
			end
			result[#result+1] = line
		end
		if show_areas then
			line = "** Areas: "
			for i, area in ipairs(pack.areas) do
				if i ~= 1 then
					line = line .. ", "
				end
				line = line .. string.format("[[Area:%s|%s]] (%s)", string.gsub(area.area_id, "_", "~"), area.name, area.weight)
			end
			result[#result+1] = line
		end
	end
	return table.concat(result, '\n')
end

local function _expand_template(data)
	return m_util.string.trim(mw.getCurrentFrame():expandTemplate{
		title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
		args = {
			name = data.name,
			description = data.description,
			leader = data.leader
		}
	})
end

local function _render_pack(tpl_args)
	tpl_args = tpl_args or {}
	local pack_id = tpl_args.pack_id
	if tpl_args.item_name and not pack_id then
		local found = m_lookup[tpl_args.item_name]
		if not found then
			return
		end
		pack_id = found.pack_id
	end
	if pack_id then
		local data = m_data[pack_id]
		if tpl_args.pack_composition and data.monster_pack_ids then
			return mw.getCurrentFrame():preprocess(_expand_template(data) .. "\n" .. _show_monsters(data.monster_pack_ids, tpl_args.pack_areas))
		else
			return mw.getCurrentFrame():preprocess(_expand_template(data))
		end
	else
		local all = {"==All known packs=="}
		for _, data in pairs(m_data) do
			if data.name and data.name ~= '' then
				all[#all+1] = "===" .. data.name .. "==="
				all[#all+1] = _expand_template(data)
				if data.monster_pack_ids then
					all[#all+1] = _show_monsters(data.monster_pack_ids, true)
				end
			end
		end
		return mw.getCurrentFrame():preprocess(table.concat(all, '\n'))
	end
end

local p = {}

p.render_pack = m_util.misc.invoker_factory(_render_pack)

return p