Difference between revisions of "Module:Monster"
(Use roman numerals; clear div style after each spell set) |
(Clear div style only every other spell set) |
||
Line 134: | Line 134: | ||
ret = ret .. table.concat(flags, ", ") .. "\n" | ret = ret .. table.concat(flags, ", ") .. "\n" | ||
end | end | ||
− | ret = ret .. | + | ret = ret .. "|-\n|}</div>" |
+ | if i % 2 == 0 then | ||
+ | ret = ret .. '<div style="clear:both;"></div>' | ||
+ | end | ||
+ | end | ||
+ | if #monster.Spellsets % 2 == 1 then | ||
+ | ret = ret .. '<div style="clear:both;"></div>' | ||
end | end | ||
return ret | return ret |
Revision as of 01:07, 11 December 2015
Documentation for this module may be created at Module:Monster/doc
local p = {} local data = mw.loadData('Module: Table of monsters') -- Taken from max_corpse_chunks in mon-util.cc local max_corpse_chunks = { Tiny = 1, Little = 2, Small = 3, Medium = 4, Large = 9, Big = 10, Giant = 12, } function p.monster_info(frame) local name = frame.args[1] if not name or name == "" then name = mw.title.getCurrentTitle().text end local monster = data[name] or data[name:lower()] if not monster then return name end local args = {} args.name = monster.Name args.glyph = frame:expandTemplate{title = monster.Colour, args = {monster.Glyph}} local flags = {} for i, v in ipairs(monster.Flags) do flags[i] = frame:expandTemplate{title = v} end args.flags = table.concat(flags, "<br>") local resistances = {} for i, v in ipairs(monster.Resistances) do resistances[i] = frame:expandTemplate{title = v} end if #resistances == 0 then args.resistances = "None" else args.resistances = table.concat(resistances, "<br>") end local vulnerabilities = {} for i, v in ipairs(monster.Vulnerabilities) do vulnerabilities[i] = frame:expandTemplate{title = v} end if #vulnerabilities == 0 then args.vulnerabilities = "None" else args.vulnerabilities = table.concat(vulnerabilities, "<br>") end if monster.Corpse ~= "No" then args.max_chunks = max_corpse_chunks[monster.Size] or 0 else args.max_chunks = 0 end args.meat = frame:expandTemplate{title = monster.Corpse .. " corpse"} args.xp = monster.XP args.holiness = frame:expandTemplate{title = monster.Holiness} args.magic_resistance = monster.MR local hp_min = monster.HD*monster["Base HP"] + monster["Fixed HP"] local hp_max = monster.HD*(monster["Base HP"]+monster["Rand HP"])+monster["Fixed HP"] if hp_min == hp_max then args.hp_range = hp_min else args.hp_range = ("%d-%d"):format(hp_min, hp_max) end args.avg_hp = (hp_min + hp_max)/2 args.armour_class = monster.AC args.evasion = monster.EV args.habitat = monster.Habitat args.speed = monster.Speed args.size = frame:expandTemplate{title = monster.Size} local item_use = {} for i, v in ipairs(monster["Item Use"]) do item_use[i] = frame:expandTemplate{title = v} end args.item_use = table.concat(item_use, "<br>") for i = 1, 4 do local attack = monster.Attacks[i] if attack then local typ = frame:expandTemplate{title = attack.Type .. " type"} local flavour = frame:expandTemplate{title = attack.Flavour .. " flavour"} args["attack" .. i] = ("%d (%s: %s)"):format(attack.Damage, typ, flavour) else args["attack" .. i] = "" end end args.hit_dice = monster.HD args.base_hp = monster["Base HP"] args.extra_hp = monster["Rand HP"] args.fixed_hp = monster["Fixed HP"] args.intelligence = frame:expandTemplate{title = monster.Intelligence .. " intelligence"} args.genus = monster.Genus args.species = monster.Species local infobox = frame:expandTemplate{title = "monster", args = args} local flavour = monster.Description if monster.Quote then flavour = flavour .. "\n----\n" .. monster.Quote:gsub("\n", "<br>") end flavour = frame:expandTemplate{title = "flavour", args = {flavour}} return infobox .. "\n" .. flavour end local roman = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"} function p.monster_spells(frame) local name = frame.args[1] if not name or name == "" then name = mw.title.getCurrentTitle().text end local monster = data[name] or data[name:lower()] local ret = "==Spells==\n[[Category:Spellcaster]]" for i, spells in ipairs(monster.Spellsets) do ret = ret .. [=[<div style="margin: 1.0em; margin-top:0; margin-right:0; padding: 0px; float: left; border:none;"> {| class="prettytable" style="border:none; margin:0; padding:0; width:16em;" ! colspan="3" style="font-size:larger;" | Spell set ]=] .. roman[i] .. "\n" for j, spell in ipairs(spells) do ret = ret .. '|-\n! align="left" | Slot<sup>' .. j .. '</sup>\n| ' .. spell.Spell .. '\n| ' local flags = {} for i, v in ipairs(spell.Flags) do flags[i] = frame:expandTemplate{title = v .. " slot flag"} end ret = ret .. table.concat(flags, ", ") .. "\n" end ret = ret .. "|-\n|}</div>" if i % 2 == 0 then ret = ret .. '<div style="clear:both;"></div>' end end if #monster.Spellsets % 2 == 1 then ret = ret .. '<div style="clear:both;"></div>' end return ret end return p