Module:ListOfNPCs

local i18n = { en = { Id = 'ID', Image = 'Image', Name = 'Name', Health = 'Max Health', Damage = 'Damage', Defense = 'Defense', Kbresist = 'Knockback Resistance', AI = 'AI', Money = 'Money Dropped', Environment = 'Environment', Type = 'Type', Deprecated = '(Deprecated)',

type_townNPC = 'Town NPC', type_projectileNPC = 'Projectile', type_critter = 'Critter', type_friendly = 'Friendly', type_default = 'Enemy', },	fr = { Id = 'ID', Image = 'Image', Name = 'Nom', Health = 'Santé max', Damage = 'Dégâts', Defense = 'Défense', Kbresist = 'Résistance au RC', AI = 'IA', Money = 'Pièces lâchées', Environment = 'Environnement', Type = 'Type', Deprecated = '(Obsolète)', type_townNPC = 'PNJ de ville', type_projectileNPC = 'Projectile', type_critter = 'Créature', type_friendly = 'Amicale', type_default = 'Ennemi', },	pt = { Id = 'ID', Image = 'Imagem', Name = 'Nome', Health = 'Vida Máxima', Damage = 'Dano', Defense = 'Defesa', Kbresist = 'Resistência ao Recuo', AI = 'IA', Money = 'Dinheiro Solto', Environment = 'Ambiente', Type = 'Tipo', Deprecated = '(Descontinuado)', type_townNPC = 'NPC de Cidade', type_projectileNPC = 'Projétil', type_critter = 'Criaturnha', type_friendly = 'Amigável', type_default = 'Inimigo', },	ru = { Id = 'ID', Image = 'Изображение', Name = 'Название', Health = 'Макс. здоровья', Damage = 'Урон', Defense = 'Защита', Kbresist = 'Сопротивление отбрасыванию', AI = 'ИИ', Money = 'Количество выпадаемых монет', Environment = 'Биом', Type = 'Тип', Deprecated = '(не используется)',

type_townNPC = 'Житель', type_projectileNPC = 'Снаряд', type_critter = 'Живность', type_friendly = 'Дружественный', type_default = 'Противник', },	zh = { Id = 'ID', Image = '图像', Name = '名称', Health = '最大生命值', Damage = '伤害', Defense = '防御', Kbresist = '击退抗性', AI = 'AI', Money = '掉落金钱', Environment = '环境', Type = '类型', Deprecated = '(废弃)',

type_townNPC = '城镇 NPC', type_projectileNPC = '射弹', type_critter = '小动物', type_friendly = '友好', type_default = '敌怪', } }

local trim = mw.text.trim

local id_start, id_end = -65, 664 -- as in 1.4.1

local data={} local unused = require('Module:Npcinfo/idSets').getIdSet('Unused') local npcstat = require('Module:Npcinfo').stat

local last = id_start local output = mw.html.create('table'):addClass('terraria sortable lined aligncenter') local currentFrame local na

local lang = 'en' local function l10n(index) return i18n[lang] and i18n[lang][index] or i18n['en'][index] end

local function v(value) if value and trim(value) ~= '' then return value else return na	end end

function typeof(npcid) if npcstat(npcid, 'townNPC') then return l10n('type_townNPC') elseif npcstat(npcid, 'projectileNPC') then return l10n('type_projectileNPC') elseif npcstat(npcid, 'critter') then return l10n('type_critter') elseif npcstat(npcid, 'friendly') then return l10n('type_friendly') else return l10n('type_default') end end

function printNoCargoRow(id) local tr = output:tag('tr') tr:tag('td'):wikitext(id) if unused[id] then tr:tag('td'):attr('colspan', 10):tag('i'):addClass('note-text'):wikitext(l10n('Deprecated')) else tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') tr:tag('td'):wikitext('???') end

end

local ai_text = {} -- cache function printRow(row) local npcid = tonumber(row.npcid) if npcid == 0 then return end

if npcid > last + 1 then for id = last+1, npcid-1 do			printNoCargoRow(id) end end

local ai = v(row.ai) if not ai_text[ai] then ai_text[ai] = currentFrame:expandTemplate{title = 'tr', args = {ai}} end ai = ai_text[ai]

local tr = output:tag('tr') tr:tag('td'):wikitext(npcid) tr:tag('td'):wikitext(v(row.image)) tr:tag('td'):wikitext(v(row.name)) tr:tag('td'):wikitext(v(row.life)) tr:tag('td'):wikitext(v(row.damage)) tr:tag('td'):wikitext(v(row.defense)) tr:tag('td'):wikitext(v(row.knockback)) tr:tag('td'):wikitext(ai) tr:tag('td'):wikitext(v(row.money)) tr:tag('td'):wikitext(v(currentFrame:callParserFunction('#lstmaptemp',row.environment, 'npc_infobox/environment', '/', '&#32;/&#32;'))) tr:tag('td'):wikitext(typeof(npcid)) last = npcid end

return { main=function(frame) currentFrame = frame lang = frame:expandTemplate{title = 'lang'} na = frame:expandTemplate{title = 'na', args = {'-'}} local header = output:tag('tr') header:tag('th'):wikitext(l10n('Id')) header:tag('th'):wikitext(l10n('Image')) header:tag('th'):wikitext(l10n('Name')) header:tag('th'):wikitext(l10n('Health')) header:tag('th'):wikitext(l10n('Damage')) header:tag('th'):wikitext(l10n('Defense')) header:tag('th'):wikitext(l10n('Kbresist')) header:tag('th'):wikitext(l10n('AI')) header:tag('th'):wikitext(l10n('Money')) header:tag('th'):wikitext(l10n('Environment')) header:tag('th'):wikitext(l10n('Type'))

local result = mw.ext.cargo.query(		'NPCs',		'npcid,name,image,life,damage,defense,knockback,ai,money,environment',		{			groupBy = 'npcid',			orderBy = 'npcid',			where = 'npcid IS NOT NULL and npcid < 1000',			limit = 1000		}	) for _, row in ipairs(result) do		printRow(row) end

-- tails for id = last+1, id_end do		local tr = output:tag('tr') tr:tag('td'):wikitext(id) if unused[id] then tr:tag('td'):attr('colspan', 2):tag('i'):addClass('note-text'):wikitext(l10n('Deprecated')) else tr:tag('td'):wikitext('???') end end

return output end, }