Module:Sandbox/User:Rawny/Test: Difference between revisions
Jump to navigation
Jump to search
m (Update to current version of Module:Infobox Monster) |
m (1 revision imported) |
(No difference)
|
Latest revision as of 21:23, 4 November 2021
Documentation for this module may be created at Module:Sandbox/User:Rawny/Test/doc
-- <syntaxhighlight lang="lua">
--------------------------
-- Module for [[Template:Infobox Monster new]]
-- Please test changes to this module at [[Module:Infobox Monster/sandbox]] first
------------------------
local p = {}
-- "imports"
local onmain = require('Module:Mainonly').on_main
local paramtest = require('Module:Paramtest')
local yesno = require('Module:Yesno')
local commas = require('Module:Addcommas')._add
local infobox = require('Module:Infobox')
local attack_speed_bar = require('Module:Attack speed bar').monster
--[[
-- Mapping
--]]
local attack_styles = {
melee = { image = 'Attack-icon', link = 'Melee' },
ranged = { image = 'Ranged-icon', link = 'Ranged' },
magic = { image = 'Magic-icon', link = 'Magic' },
dragonfire = { image = 'Dragonfire icon', link = 'Dragonfire' },
na = { image = 'Zero weakness icon', link = '' },
typeless = { image = 'Zero weakness icon', link = '' }
}
local styles_map = {
melee = 'melee',
magic = 'magic',
mage = 'magic',
range = 'ranged',
ranged = 'ranged',
ranging = 'ranged',
dragonfire = 'dragonfire',
['dragon fire'] = 'dragonfire',
dragonbreath = 'dragonfire',
['dragon breath'] = 'dragonfire',
['n/a'] = 'na',
na = 'na',
none = 'na'
}
local slay_masters = {
turael = { text = '[[Turael]] or [[Spria]]', chathead = 'turael chathead', category = 'Monsters assigned by Turael or Spria' },
mazchna = { text = '[[Mazchna]] or [[Achtryn]]', chathead = 'mazchna chathead', category = 'Monsters assigned by Mazchna or Achtryn' },
chaeldar = { text = '[[Chaeldar]]', chathead = 'chaeldar chathead', category = 'Monsters assigned by Chaeldar' },
sumona = { text = '[[Sumona]]', chathead = 'sumona chathead', category = 'Monsters assigned by Sumona' },
vannaka = { text = '[[Vannaka]]', chathead = 'vannaka chathead', category = 'Monsters assigned by Vannaka' },
duradel = { text = '[[Duradel]] or [[Lapalok]]', chathead = 'duradel chathead', category = 'Monsters assigned by Duradel or Lapalok' },
kuradal = { text = '[[Kuradal]]', chathead = 'kuradal chathead', category = 'Monsters assigned by Kuradal' },
morvran = { text = '[[Morvran]]', chathead = 'morvran chathead', category = 'Monsters assigned by Morvran' },
mandrith = { text = '[[Mandrith]]', chathead = 'Mandrith chathead', category = 'Monsters assigned by Mandrith' },
}
local slay_masters_map = {
turael = 'turael',
spria = 'turael',
mazchna = 'mazchna',
achtryn = 'mazchna',
chaeldar = 'chaeldar',
sumona = 'sumona',
vannaka = 'vannaka',
duradel = 'duradel',
lapalok = 'duradel',
kuradal = 'kuradal',
morvran = 'morvran',
mandrith = 'mandrith',
no = 'none',
none = 'none',
['n/a'] = 'none'
}
local slay_masters_order = { 'turael', 'mazchna', 'chaeldar', 'sumona', 'vannaka', 'duradel', 'kuradal', 'morvran', 'mandrith' }
local speed_map = {
['1'] = 1,
['2'] = 2,
['3'] = 3,
['4'] = 4,
['5'] = 5,
['6'] = 6,
['7'] = 7,
['8'] = 8,
['9'] = 9,
['10'] = 10,
['n/a'] = 0,
['random'] = 'random',
['0'] = 0
}
-- load weaknesses instead of remapping
local weaknesses = mw.loadData('Module:Weakness clickpic/data')
-- location restriction
local restriction_map = {
surface = 'surface',
dungeoneering = 'dungeoneering',
dg = 'dungeoneering',
daemonheim = 'dungeoneering',
quest = 'quest',
minigame = 'minigame',
activity = 'minigame',
gone = 'removed',
removed = 'removed',
limited = 'limited'
}
-- Main function called with invokes
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
local yn_args = {
'aggressive'
}
local immune_args = {
'immune_to_poison', 'immune_to_deflect',
'immune_to_stun', 'immune_to_drain'
}
local num_args = {
'slaylvl', 'slayxp',
'attack', 'strength', 'defence', 'ranged', 'magic',
'max_melee', 'max_ranged', 'max_magic', 'max_spec',
'acc_melee', 'acc_ranged', 'acc_magic', 'armour',
'aff_melee', 'aff_ranged', 'aff_magic', 'thievelvl' } --aff_weakness has a special func
for _, v in ipairs(yn_args) do
ret:defineParams{ { name = v, func = { name = boolargs, params = { v, v }, flag = { 'p', 'r' } } }}
ret:defineParams{ { name = v..'_smw', func = { name = boolsmwargs, params = { v }, flag = { 'd' } } }}
end
for _, v in ipairs(immune_args) do
ret:defineParams{ { name = v, func = { name = immuneargs, params = { v, v }, flag = { 'p', 'r' } } }}
ret:defineParams{ { name = v..'_smw', func = { name = immunesmwargs, params = { v }, flag = { 'd' } } }}
end
for _, v in ipairs(num_args) do
ret:defineParams{
{ name = v, func = { name = numberargs, params = { v, v }, flag = { 'p', 'r' } } },
{ name = v..'_smw', func = { name = numargraw, params = { v }, flag = 'd' } }
}
end
ret:defineParams{
{ name = 'vanchor', func = { name = 'has_content', params = { 'version' }, flag = 'p' } },
{ name = 'poisonous', func = { name = poisonarg, params = { 'poisonous' }, flag = 'p' } },
{ name = 'poisonous_smw', func = { name = boolsmwargs, params = { 'poisonous' }, flag = 'd' } },
{ name = 'level', func = combatarg },
{ name = 'level_smw', func = { name = numargraw2, params = { 'level' }, flag = 'd' } },
{ name = 'style', func = stylearg },
{ name = 'styleimg', func = { name = styleimgarg, params = { 'style' }, flag = 'p', dupes = true } },
{ name = 'styletxt', func = { name = styletxtarg, params = { 'style' }, flag = 'p', dupes = true } },
{ name = 'lifepoints', func = numargcommas },
{ name = 'lpraw', func = { name = numargraw, params = { 'lifepoints' }, flag = 'p' } },
{ name = 'experience', func = numargcommas },
{ name = 'xpraw', func = { name = numargraw, params = { 'experience' }, flag = 'p' } },
{ name = 'hpxp', func = { name = hpxparg, params = { 'experience' } } },
{ name = 'wepxp2h', func = numargcommas },
{ name = 'wepxpmhandarmour', func = numargcommas },
{ name = 'wepxpoh', func = numargcommas },
{ name = 'wepxp', func = { name = wepxparg, params = { 'experience', 'wepxp2h', 'wepxpmhandarmour', 'wepxpoh' } } },
{ name = 'weakness', func = weaknessarg },
{ name = 'generalweakness', func = { name = generalweaknessarg, params = { 'aff_melee', 'aff_ranged', 'aff_magic' } } },
{ name = 'weaknessimg', func = { name = weaknessimgarg, params = { 'weakness' }, flag = 'p', dupes = true } },
{ name = 'weaknesstxt', func = { name = weaknesstxtarg, params = { 'weakness' }, flag = 'p', dupes = true } },
{ name = 'explicit_weakness', func = { name = explicitwkarg, params = { 'weakness' }, flag = 'p' } },
{ name = 'aff_weakness', func = { name = aff_weakness_arg , params = { 'aff_weakness', 'aff_weakness', 'weakness' }, flag = { 'p', 'r', 'p' } } },
{ name = 'aff_weakness_smw', func = { name = aff_weakness_smw_arg , params = { 'aff_weakness', }, flag = { 'd' } } },
{ name = 'abilities', func = abilarg },
{ name = 'abilities_sep', func = abilseparg },
{ name = 'assigned_by', func = slayerarg },
{ name = 'assigned_by_img', func = { name = slayerimgarg, params = { 'assigned_by' }, flag = 'p', dupes = true } },
{ name = 'not_assigned', func = { name = notassarg, params = { 'assigned_by' }, flag = 'p' } },
{ name = 'release', func = 'release' },
{ name = 'removal', func = 'removal' },
{ name = 'members', func = 'has_content' },
{ name = 'examine', func = 'has_content' },
{ name = 'speed', func = speedarg },
{ name = 'name', func = 'name' },
{ name = 'aka', func = 'has_content' },
{ name = 'image', func = 'image' },
{ name = 'chathead', func = 'image' },
{ name = 'slayercat', func = 'has_content' },
{ name = 'slayercat_smw', func = { name = slayercatsmwarg, params = { 'slayercat' }, flag='d' } },
{ name = 'restriction', func = restrictionarg },
{ name = 'restrictionsurface', func = { name = restrsurfarg , params = { 'restriction', 'restriction' }, flag = { 'd', 'p' } } },
-- not used; only for categories
{ name = 'id', func = 'numbers' },
{ name = 'id_smw', func = { name = idsmw, params = { 'id' }, flag = 'p' } },
{ name = 'rscid', func = 'numbers' },
{ name = 'SMWarg', func = { name = SMWarg, params = { 'name', 'version', 'id', 'members', 'release', 'removal', 'examine', 'level', 'style', 'lpraw', 'weakness', 'xpraw', 'slaylvl', 'slayxp', 'assigned_by', 'slayercat',
'poisonous', 'abilities_sep', 'restriction', 'aggressive', 'immune_to_stun', 'immune_to_drain', 'immune_to_poison', 'immune_to_deflect',
'attack', 'magic', 'ranged', 'defence', 'max_melee', 'max_magic', 'max_ranged', 'max_spec', 'acc_melee', 'acc_magic', 'acc_ranged', 'armour', 'aff_melee', 'aff_magic', 'aff_ranged', 'aff_weakness' }, flag = 'd', dupes = true } }
}
ret:useSMW({
id_smw = 'NPC ID',
level_smw = 'Combat level',
xpraw = 'Combat experience',
members = 'Is members only'
})
ret:useSMWSubobject({
id_smw = 'NPC ID',
name = 'Monster name',
vanchor = 'Version anchor',
level_smw = 'Combat level',
xpraw = 'Combat experience',
thievelvl_smw = 'Thieving level',
members = 'Is members only',
styleimg = 'NPC attack style',
styletxt = 'NPC attack style text',
lpraw = 'NPC life points',
weaknessimg = 'Weakness',
weaknesstxt = 'Weakness text',
generalweakness = 'Weakness by class',
slayercat_smw = 'Slayer category',
slaylvl_smw = 'Slayer level',
slayxp_smw = 'Slayer experience',
assigned_by_img = 'Assigned by',
restriction = 'Location restriction',
attack_smw = 'NPC Attack level',
magic_smw = 'NPC Magic level',
ranged_smw = 'NPC Ranged level',
defence_smw = 'NPC Defence level',
max_melee_smw = 'NPC melee max hit',
max_magic_smw = 'NPC magic max hit',
max_ranged_smw = 'NPC ranged max hit',
max_spec_smw = 'NPC special max hit',
acc_melee_smw = 'NPC melee accuracy',
acc_magic_smw = 'NPC magic accuracy',
acc_ranged_smw = 'NPC ranged accuracy',
armour_smw = 'NPC armour',
aff_melee_smw = 'NPC melee affinity',
aff_magic_smw = 'NPC magic affinity',
aff_ranged_smw = 'NPC ranged affinity',
aff_weakness_smw = 'NPC weakness affinity',
aggressive_smw = 'Is NPC aggressive',
poisonous_smw = 'Is NPC poisonous',
immune_to_poison_smw = 'NPC susceptible to poison',
immune_to_deflect_smw = 'NPC susceptible to deflect',
immune_to_stun_smw = 'NPC susceptible to stun',
immune_to_drain_smw = 'NPC susceptible to drain',
SMWarg = 'Monster JSON',
})
ret:defineLinks({
links = {
{ 'Template:%s/FAQ', 'FAQ' },
{ 'Template:%s/doc', 'doc' }
},
colspan = 12
})
ret:customButtonPlacement(true)
ret:create()
ret:cleanParams()
ret:addClass('infobox-monster')
ret:defineName('Infobox Monster')
-- use catargs
if onmain() then
local a2 = ret:categoryData()
if not a2['restriction'].all_defined then
ret:useSMWSubobject({
restrictionsurface = 'Location restriction'
})
end
end
ret:addButtonsRow{
colspan = 12
}
-- PARAMETER: chathead
if ret:paramDefined('chathead', 'all') then
ret:addRow{
{ tag = 'argd', content = 'chathead', class='infobox-image', colspan = '12' }
}
end
-- PARAMETER: image
ret:addRow{
{ tag = 'argd', content = 'image', class='infobox-image bordered-image', colspan = '12' }
}
ret:addRow{
{ tag = 'argh', content = 'name', class='infobox-header', colspan = '12' }
}
-- PARAMETER: release
-- (update included automatically by infobox)
ret:addRow{ { tag = 'th', content = 'Release', colspan = '3' },
{ tag = 'argd', content = 'release', css = { ['text-align'] = 'left' }, colspan = '9' } }
-- PARAMETER: removal
if ret:paramDefined('removal') then
ret:addRow{ { tag = 'th', content = 'Removal', colspan = '3' },
{ tag = 'argd', content = 'removal', css = { ['text-align'] = 'left' }, colspan = '9' } }
end
-- PARAMETER: aka
-- add only if it exists
if ret:paramDefined('aka') then
ret:addRow{ { tag = 'th', content = 'AKA', colspan = '3' },
{ tag = 'argd', content = 'aka', css = { ['text-align'] = 'left', ['max-width'] = '100px' }, colspan = '9' } }
end
-- PARAMETER: members
ret:addRow{ { tag = 'th', content = 'Members', colspan = '3' },
{ tag = 'argd', content = 'members', css = { ['text-align'] = 'left' }, colspan = '9' } }
:addRow{ { tag = 'th', content = 'Examine', class = 'infobox-subheader', colspan = '12' } }
-- PARAMETER: examine
:addRow{ { tag = 'argd', content = 'examine', css = { ['text-align'] = 'center', ['max-width'] = '250px' }, colspan = '12' } }
-- COMBAT INFO
:addRow{ { tag = 'th', content = 'Combat info', colspan = '12', class = 'combat-info-header infobox-subheader' } }
-- PARAMETER: level | lifepoints | experience | hpxp
:addRow{ { tag = 'th', content = '[[Combat level|Level]]', class = 'combat-subheader', colspan = '3' },
{ tag = 'th', content = '[[Life points|LP]]', class = 'combat-subheader', colspan = '3' },
{ tag = 'th', content = '[[File:Multicombat.png|link=|20px]] XP', class = 'combat-subheader', colspan = '3', title = 'Combat style experience' },
{ tag = 'th', content = '[[File:Constitution-icon.png|link=|20px]] XP', class = 'combat-subheader', colspan = '3', title = 'Constitution experience' } }
:addRow{ { tag = 'argd', content = 'level', colspan = '3' },
{ tag = 'argd', content = 'lifepoints', colspan = '3' },
{ tag = 'argd', class='mob-cb-xp', content = 'experience', colspan = '3' },
{ tag = 'argd', class='mob-hp-xp', content = 'hpxp', colspan = '3' } }
-- PARAMETER: wepxp
:addRow{ { tag = 'th', content = '[[Equipment level|Equipment XP]] (2H/MH & Armour/OH)', class = 'combat-subheader', colspan = '12' } }
:addRow{ { tag = 'argd', content = 'wepxp', class='mob-eq-xp', colspan = '12' } }
-- PARAMETER: aggressive | poisonous
:addRow{ { tag = 'th', content = '[[Aggressiveness|Aggressive]]', class = 'combat-subheader', colspan = '6' },
{ tag = 'th', content = 'Poisonous', class = 'combat-subheader', colspan = '6' } }
:addRow{ { tag = 'argd', content = 'aggressive', colspan = '6' },
{ tag = 'argd', content = 'poisonous', colspan = '6' } }
-- Slayer information
-- dynamic size, dependent on whether or not the monster is assigned
local slayer_level = ret:paramDefined('slaylvl','all')
local not_assigned = ret:param('not_assigned','f')
local _not_assigned = true
if not_assigned.d == false then
_not_assigned = false
elseif not_assigned.switches then
for _, v in ipairs(not_assigned.switches) do
if v == false then
_not_assigned = false
break
end
end
end
-- do slayer row if a monster is assigned, or has a required level
if _not_assigned == false or slayer_level == true then
-- PARAMETER: slaylvl | slayxp | slayercat
ret:addRow{ { tag = 'th', content = 'Slayer', class = 'slayer-header', colspan = '12' } }
:addRow{ { tag = 'th', content = 'Level', class = 'slayer-subheader', colspan = '3' },
{ tag = 'th', content = 'XP', class = 'slayer-subheader', colspan = '3' },
{ tag = 'th', content = 'Category', class = 'slayer-subheader', colspan = '6' } }
:addRow{ { tag = 'argd', content = 'slaylvl', colspan = '3' },
{ tag = 'argd', class='mob-slay-xp', content = 'slayxp', colspan = '3' },
{ tag = 'argd', content = 'slayercat', colspan = '6' } }
:addRow{ { tag = 'th', content = 'Assigned by', class = 'slayer-subheader', colspan = '12' } }
:addRow{ { tag = 'argd', content = 'assigned_by',colspan = '12' } }
end
----------------
-- OFFENSIVE STATS
local max_disc = 'This value is the standard, non-legacy value. The number reflects the BASE maximum hit used by the monster in damage calculations. Damage-boosting mechanics such as enrage are not taken into consideration.'
ret:addRow{ { tag = 'th', content = 'Offensive', class = 'offensive-header', colspan = '12' } }
:addRow{ { tag = 'th', content = '[[Maximum hit|Max hit]]', class = 'offensive-subheader', colspan = '12' } }
-- PARAMETER: max_melee | max_ranged | max_magic | max_spec
:addRow{ { tag = 'td', content = '[[File:Attack-icon.png|20px|link=]]', title = 'Maximum melee hit', colspan = '3' },
{ tag = 'td', content = '[[File:Ranged-icon.png|20px|link=]]', title = 'Maximum ranged hit', colspan = '3' },
{ tag = 'td', content = '[[File:Magic-icon.png|20px|link=]]', title = 'Maximum magic hit', colspan = '3' },
{ tag = 'td', content = '[[File:Weapon Special attack.png|20px|link=]]', title = 'Maximum typeless/special hit', colspan = '3' } }
:addRow{ { tag = 'argd', content = 'max_melee', title = max_disc, colspan = '3' },
{ tag = 'argd', content = 'max_ranged', title = max_disc, colspan = '3' },
{ tag = 'argd', content = 'max_magic', title = max_disc, colspan = '3' },
{ tag = 'argd', content = 'max_spec', title = max_disc, colspan = '3' } }
-- PARAMETER: style | speed
:addRow{ { tag = 'th', content = 'Style', class = 'offensive-subheader', colspan = '6' },
{ tag = 'th', content = '[[Attack speed|Speed]]', class = 'offensive-subheader', colspan = '6' } }
:addRow{ { tag = 'argd', content = 'style', colspan = '6' },
{ tag = 'argd', content = 'speed', colspan = '6' } }
-- PARAMETER: acc_melee | acc_ranged | acc_magic
:addRow{ { tag = 'th', content = 'Combat levels', class = 'offensive-subheader', colspan = '12' } }
-- Accuracy parameters
local levels_disc = "This is the monster's level in this combat skill. It functions in the same way a player's does - it affects the accuracy or armour in the same way (but not damage)."
ret:addRow {
{ tag = 'td', content = '[[File:Attack-icon.png|20px|link=]]', title = 'Attack level', colspan = '4' },
{ tag = 'td', content = '[[File:Ranged-icon.png|20px|link=]]', title = 'Ranged level', colspan = '4' },
{ tag = 'td', content = '[[File:Magic-icon.png|20px|link=]]', title = 'Magic level', colspan = '4' }
}
:addRow {
{ tag = 'argd', content = 'attack', title = levels_disc, colspan = '4' },
{ tag = 'argd', content = 'ranged', title = levels_disc, colspan = '4' },
{ tag = 'argd', content = 'magic', title = levels_disc, colspan = '4' }
}
:addRow {
{ tag = 'th', content = '[[Hit chance|Accuracy]]', class = 'offensive-subheader', colspan = '12' }
}
:addRow {
{ tag = 'td', content = '[[File:Attack-icon.png|20px|link=]]', title = 'Melee accuracy as a function of 2.5 * f(x)', colspan = '4' },
{ tag = 'td', content = '[[File:Ranged-icon.png|20px|link=]]', title = 'Ranged accuracy as a function of 2.5 * f(x)', colspan = '4' },
{ tag = 'td', content = '[[File:Magic-icon.png|20px|link=]]', title = 'Magic accuracy as a function of 2.5 * f(x)', colspan = '4' }
}
:addRow {
{ tag = 'argd', content = 'acc_melee', colspan = '4' },
{ tag = 'argd', content = 'acc_ranged', colspan = '4' },
{ tag = 'argd', content = 'acc_magic', colspan = '4' }
}
-- PARAMETER: abilities
-- only add if they exist
local abilities = ret:param('abilities','f')
local _abilities = false
if abilities.d and abilities.d ~= 'None' then
_abilities = true
end
if abilities.switches then
for _, v in ipairs(abilities.switches) do
if v ~= _nil then
_abilities = true
break
end
end
end
if _abilities then
ret:addRow{ { tag = 'th', content = 'Abilities used', class = 'offensive-subheader', colspan = '12' } }
:addRow{ { tag = 'argd', content = 'abilities', colspan = '12' } }
end
-- DEFENSIVE STATS
ret:addRow{ { tag = 'th', content = 'Defensive', class = 'defensive-header', colspan = '12' } }
-- PARAMETER: armour | defence | weakness
:addRow{ { tag = 'th', content = 'Armour', class = 'defensive-subheader', colspan = '3' },
{ tag = 'th', content = '[[File:Defence-icon.png|link=]]', class = 'defensive-subheader', title = 'Defence level', colspan = '3' },
{ tag = 'th', content = '[[Weakness]]', class = 'defensive-subheader', colspan = '6' } }
:addRow{ { tag = 'argd', content = 'armour', colspan = '3' },
{ tag = 'argd', content = 'defence', title = levels_disc, colspan = '3' },
{ tag = 'argd', content = 'weakness', colspan = '6' } }
-- PARAMETER: explicit_weakness
-- PARAMETER: aff_weakness | aff_melee | aff_ranged | aff_magic
:addRow{ { tag = 'th', content = '[[Affinity|Affinities]]', class = 'defensive-subheader', colspan = '12' } }
:addRow{ { tag = 'argd', content = 'explicit_weakness', title = 'Affinity value of the monster\'s explicit weakness', colspan = '3' },
{ tag = 'td', content = '[[File:Attack-icon.png|20px|link=]]', title = 'Affinity value of the monster against melee attacks', colspan = '3' },
{ tag = 'td', content = '[[File:Ranged-icon.png|20px|link=]]', title = 'Affinity value of the monster against ranged attacks', colspan = '3' },
{ tag = 'td', content = '[[File:Magic-icon.png|20px|link=]]', title = 'Affinity value of the monster against magic attacks', colspan = '3' } }
:addRow{ { tag = 'argd', content = 'aff_weakness', colspan = '3' },
{ tag = 'argd', content = 'aff_melee', colspan = '3' },
{ tag = 'argd', content = 'aff_ranged', colspan = '3' },
{ tag = 'argd', content = 'aff_magic', colspan = '3' } }
-- PARAMETER: immune_to_poison | immune_to_deflect | immune_to_stun | immune_to_drain
:addRow{ { tag = 'th', content = 'Immunities', class = 'defensive-subheader', colspan = '12' } }
:addRow{ { tag = 'td', content = '[[File:Poison immunity icon.png|27x27px|frameless|link=]]', title = 'Immune to poison?', colspan = '3' },
{ tag = 'td', content = '[[File:Deflect immunity icon.png|27x27px|frameless|link=]]', title = 'Immune to deflect?', colspan = '3' },
{ tag = 'td', content = '[[File:Stun immunity icon.png|27x27px|frameless|link=]]', title = 'Immune to stun?', colspan = '3' },
{ tag = 'td', content = '[[File:Drain immunity icon.png|27x27px|frameless|link=]]', title = "Immune to stat drain?", colspan = '3' } }
:addRow{ meta = { addClass = 'infobox-monster-immunites-row' },
{ tag = 'argd', content = 'immune_to_poison', colspan = '3' },
{ tag = 'argd', content = 'immune_to_deflect', colspan = '3' },
{ tag = 'argd', content = 'immune_to_stun', colspan = '3' },
{ tag = 'argd', content = 'immune_to_drain', colspan = '3' } }
ret:finish()
if onmain() then
local a1 = ret:param('all')
local a2 = ret:categoryData()
ret:wikitext(addcategories(a1,a2))
end
return ret:tostring()
end
-- For numerical args
function numberargs(arg,v)
local arg_v = (arg or ''):find('%S') and string.gsub(arg,',','') or -1
local arg_i
if arg_v == -1 then
arg_i = nil
elseif string.lower(arg_v) == 'n/a' then
arg_i = 'N/A'
elseif string.lower(arg_v) == 'varies' then
arg_i = 'Varies'
else
arg_i = tonumber(arg_v:gsub(',',''),10)
if not arg_i then
arg_i = badarg(v,'should be a single numerical value.')
end
end
return arg_i
end
-- For combat level
function combatarg(arg)
local arg_v = (arg or ''):find('%S') and string.gsub(arg,',','') or -1
local arg_i
if arg_v == -1 then
arg_i = nil
elseif string.lower(arg_v) == 'n/a' or tonumber(arg_v) == 0 then
arg_i = 'N/A'
else
arg_i = tonumber(arg_v:gsub(',',''),10)
if not arg_i then
arg_i = badarg('level','should be a single numerical value.')
end
end
return arg_i
end
-- For numbers (adds commas)
function numargcommas(arg)
local ret = numberargs(arg)
if type(ret) == 'number' then
return commas(ret)
else
return ret
end
end
-- For numbers
function numargraw(arg)
if not arg then return 0 end
if type(arg) ~= 'number' then
arg = tostring(arg)
arg = arg:gsub(',', '')
end
return tonumber(arg) or 0
end
function numargraw2(arg)
if not arg then return nil end
if type(arg) ~= 'number' then
arg = tostring(arg)
arg = arg:gsub(',', '')
end
return tonumber(arg)
end
-- For hp xp
function hpxparg(arg)
local xp = string.gsub(arg or '',',','')
if string.lower(xp) == 'n/a' then
return 'N/A'
else
xp = tonumber(xp)
end
if type(xp) == 'number' then
return commas(math.floor(xp*3.3)/10)
else
return nil
end
end
-- weapon xp
function wepxparg(combatxp, wepxp2h, wepxpmhandarmour, wepxpoh)
local xp = string.gsub(combatxp or '',',','')
local xp2h = string.gsub(wepxp2h or '',',','')
local xpmh = string.gsub(wepxpmhandarmour or '',',','')
local xpoh = string.gsub(wepxpoh or '',',','')
if string.lower(xp) == 'n/a' then
return 'N/A'
else
xp = tonumber(xp)
end
if string.lower(xp2h) ~= '' then
xp2h = tonumber(xp2h)
end
if string.lower(xpmh) ~= '' then
xpmh = tonumber(xpmh)
end
if string.lower(xpoh) ~= '' then
xpoh = tonumber(xpoh)
end
if type(xp) == 'number' then
local th,mh,oh
if type(xp2h) == 'number' then
th = xp2h
else
th = math.floor(xp * .06)
end
if type(xpmh) == 'number' then
mh = xpmh
else
mh = math.floor(xp * .04)
end
if type(xpoh) == 'number' then
oh = xpoh
else
oh = math.floor(xp * .02)
end
return string.format('%s / %s / %s',th,mh,oh)
else
return nil
end
end
-- For true/false
function boolargs(arg,argr)
local arg_v = (arg or ''):find('%S') and arg or -1
local arg_ret
if arg_v == -1 then
arg_ret = nil
else
arg_v = yesno(arg_v)
local argf = '<span title="This monster is%s %s.">%s</span>'
local f1,f3
local f2 = string.gsub(argr,'_',' ')
if arg_v then
f1 = ''
f3 = '[[File:Yes check.svg|20px|alt=Yes|link=]]'
else
f1 = ' not'
f3 = '[[File:X mark.svg|20px|alt=No|link=]]'
end
arg_ret = string.format(argf,f1,f2,f3)
end
return arg_ret
end
function boolsmwargs(arg)
if infobox.isDefined(arg) then
arg = string.lower(arg)
if arg:find('yes check') then
return 'true'
elseif arg:find('x mark') then
return 'false'
end
end
return nil
end
function immuneargs(arg,argr)
local arg_v = (arg or ''):find('%S') and arg or -1
local arg_ret
if arg_v == -1 then
arg_ret = nil
else
arg_v = yesno(arg_v)
local argf = '<span class="infobox-monster-%s infobox-monster-%s monster-%s-%s" title="This monster is%s %s.">%s</span>'
local f1,f3,f4
local f2 = string.gsub(argr,'_',' ')
local f5 = string.gsub(argr,'immune_to_','')
if arg_v then
f1 = ''
f3 = 'Immune'
f4 = 'immune'
else
f1 = ' not'
f3 = 'Not immune'
f4 = 'susceptible'
end
arg_ret = string.format(argf, f4, f5, f5, f4, f1, f2, f3)
end
return arg_ret
end
function immunesmwargs(arg)
if infobox.isDefined(arg) then
arg = string.lower(arg)
if arg:find('is not immune') then
return 'true'
elseif arg:find('is immune') then
return 'false'
end
end
return nil
end
-- Poison
function poisonarg(arg)
arg = string.gsub(arg or '',',','')
arg = string.lower(arg)
if arg == 'yes' then
arg = '<span title="This monster is poisonous but has no base value defined. Change the |poisonous parameter to a number.">[[File:Yes check.svg|20px|alt=Yes|link=]] ???</span>'
elseif tonumber(arg) then
arg = '<span title="This monster is poisonous. The number shown is the base value at which poison damage starts.">[[File:Yes check.svg|20px|alt=Yes|link=]] '..tonumber(arg)..'</span>'
else
arg = '<span title="This monster is not poisonous.">[[File:X mark.svg|20px|alt=No|link=]]</span>'
end
return arg
end
-- style
function stylearg(arg)
-- split by commas
local atts = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _atts = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(atts) do
local att_x = styles_map[v]
if att_x then
table.insert(_atts,attack_styles[att_x])
end
end
local p_att
if #_atts == 0 then
p_att = nil
else
p_att = {}
for _, v in ipairs(_atts) do
table.insert(p_att,string.format('[[File:%s.png|25px|link=%s]]',v.image,v.link))
end
p_att = table.concat(p_att,' ')
end
return p_att
end
function styleimgarg(arg)
-- split by commas
local atts = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _atts = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(atts) do
local att_x = styles_map[v]
if att_x then
table.insert(_atts,attack_styles[att_x])
end
end
local p_att = {}
if #_atts > 0 then
for _, v in ipairs(_atts) do
table.insert(p_att,string.format('File:%s.png',v.image))
end
end
return table.concat(p_att, '&&SPLITPOINT&&')
end
function styletxtarg(arg)
-- split by commas
local atts = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _atts = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(atts) do
local att_x = styles_map[v]
if att_x then
table.insert(_atts,att_x)
end
end
return table.concat(_atts, '&&SPLITPOINT&&')
end
-- weakness
function weaknessarg(arg)
-- split by commas
local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _wk = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(wk) do
local wk_x = weaknesses[v]
if wk_x then
table.insert(_wk,wk_x)
end
end
local p_wk
if #_wk == 0 then
p_wk = nil
else
p_wk = {}
for _, v in ipairs(_wk) do
table.insert(p_wk,string.format('[[File:%s|25px|link=%s]]',v.image,v.link))
end
p_wk = table.concat(p_wk,' ')
end
return p_wk
end
function weaknessimgarg(arg)
-- split by commas
local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _wk = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(wk) do
local wk_x = weaknesses[v]
if wk_x then
table.insert(_wk,wk_x)
end
end
local p_wk = {}
for _, v in ipairs(_wk) do
table.insert(p_wk,string.format('File:%s',v.image))
end
return table.concat(p_wk, '&&SPLITPOINT&&')
end
function weaknesstxtarg(arg)
-- split by commas
local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _wk = {}
-- remake the list as a table, remove anything that's blank/doesn't exist
for _, v in ipairs(wk) do
local wk_x = weaknesses[v]
if wk_x then
table.insert(_wk,v)
end
end
return table.concat(_wk, '&&SPLITPOINT&&')
end
-- Explicit weakness
-- weakness / explicit weakness
function explicitwkarg(arg)
-- split by commas
local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*')
local _wk = weaknesses[wk[1]]
if _wk then
return string.format('[[File:%s|20px|link=]]',_wk.image)
else
return nil
end
end
function aff_weakness_arg(aff,aff_r,weakness)
-- split by commas
local wk = mw.text.split(string.lower(weakness or ''),'%s*,%s*')
local _wk = weaknesses[wk[1]]
if _wk and _wk.text == 'Nothing' then
return '-'
else
return numberargs(aff,aff_r)
end
end
function aff_weakness_smw_arg(aff)
if tonumber(aff) then
return tonumber(aff)
end
return nil
end
-- generally weak to (class)
-- looks for the class that the mob is weakest to
-- if multiple equally weak, then none
function generalweaknessarg(aff_melee, aff_ranged, aff_magic)
aff_melee = tonumber(aff_melee) or 0
aff_ranged = tonumber(aff_ranged) or 0
aff_magic = tonumber(aff_magic) or 0
local max = math.max(aff_melee, aff_magic, aff_ranged)
if max == 0 then
return 'none'
end
local ret = {}
if aff_melee == max then
table.insert(ret, 'melee')
end
if aff_ranged == max then
table.insert(ret, 'ranged')
end
if aff_magic == max then
table.insert(ret, 'magic')
end
if #ret == 1 then
return ret[1]
end
return 'none'
end
function wkcats(arg,tbl)
for _, v in pairs(weaknesses) do
if arg:find(v.image) then
if v.category then
table.insert(tbl,v.category)
end
end
end
end
function slayercatsmwarg(cat)
if infobox.isDefined(cat) then
cat = string.lower(tostring(cat))
cat = string.gsub(cat, '[][]', '')
cat = string.gsub(cat, ',', '&&SPLITPOINT&&')
return cat
end
return nil
end
function slaycats(arg,tbl)
for _, v in pairs(slay_masters) do
if arg:find(v.chathead) then
if v.category then
table.insert(tbl,v.category)
end
end
end
end
-- Slayer assigners
function slayerarg(_arg)
local arg = _arg
if arg then
arg = mw.text.split(string.lower(arg),'%s*,%s*')
local slayer_master_list = {
turael = false,
spria = false,
mazchna = false,
achtryn = false,
vannaka = false,
chaeldar = false,
sumona = false,
duradel = false,
lapalok = false,
kuradal = false,
morvran = false,
mandrith = false,
none = false
}
for _, v in ipairs(arg) do
if slay_masters_map[v] then
slayer_master_list[slay_masters_map[v]] = true
end
end
if slayer_master_list.none then
arg = 'Not assigned'
else
arg = {}
for _, n in ipairs(slay_masters_order) do
local v = slayer_master_list[n]
if v then
--table.insert(params.assigned_by, slay_masters[n].text)
table.insert(arg, string.format('[[File:%s.png|30px|link=%s]]',slay_masters[n].chathead,n))
end
end
arg = table.concat(arg,' ')
end
else
arg = nil
end
return arg
end
function slayerimgarg(_arg)
local arg = _arg
if arg then
arg = mw.text.split(string.lower(arg),'%s*,%s*')
local slayer_master_list = {
turael = false,
spria = false,
mazchna = false,
achtryn = false,
vannaka = false,
chaeldar = false,
sumona = false,
duradel = false,
lapalok = false,
kuradal = false,
morvran = false,
mandrith = false,
none = false
}
for _, v in ipairs(arg) do
if slay_masters_map[v] then
slayer_master_list[slay_masters_map[v]] = true
end
end
if not slayer_master_list.none then
arg = {}
for _, n in ipairs(slay_masters_order) do
local v = slayer_master_list[n]
if v then
table.insert(arg, string.format('File:%s.png',slay_masters[n].chathead))
end
end
return table.concat(arg, '&&SPLITPOINT&&')
end
end
return ''
end
-- Not assigned
function notassarg(arg)
if arg then
if arg:find('%?action=edit') or not arg:find('%S') then
return true
end
arg = mw.text.split(string.lower(arg),'%s*,%s*')
for _, v in ipairs(arg) do
if slay_masters_map[v] == 'none' then
return true
end
end
end
return false
end
-- Abilities used
function abilarg(arg)
arg = paramtest.default_to(arg,false)
if not arg then
arg = 'None'
elseif arg:find('clickpic') then
arg = mw.getCurrentFrame():preprocess(arg)
else
arg = 'None'
end
return arg
end
function abilseparg(arg)
arg = paramtest.default_to(arg,false)
if not arg then
arg = ''
elseif arg:find('clickpic') then
arg = arg:gsub('{{[aA]bility clickpic|',''):gsub('}}',''):gsub('|',',')
else
arg = ''
end
return arg
end
-- Attacks speed
function speedarg(arg)
if paramtest.is_empty(arg) then
return nil
end
_,_,arg = string.find(arg:lower()..' ','^(.-)%s')
arg = tostring(attack_speed_bar(speed_map[arg])) or badarg('speed',' is not a valid attack speed')
return arg
end
function restrictionarg(arg)
if paramtest.is_empty(arg) then
return nil
end
return restriction_map[string.lower(arg)]
end
function restrsurfarg(cleaned, passed)
if infobox.isDefined(cleaned) then
return nil
end
return restriction_map.surface
end
function idsmw(id)
if infobox.isDefined(id) then
local r = string.gsub(id, ',', '&&SPLITPOINT&&')
return r
end
return nil
end
-- red ERR span with title hover for explanation
function badarg(argname, argmessage)
return '<span '..
'title="The parameter «'..argname..'» '..argmessage..'" '..
'style="color:red; font-weight:bold; cursor:help; border-bottom:1px dotted red;">'..
'ERR</span>'
end
-- SMW
-- 'name', 'version', 'id', 'members', 'release', 'removal', 'examine', 'level', 'style', 'lpraw', 'weakness', 'xpraw', 'slaylvl', 'slayxp', 'assigned_by', 'slayercat', 'restriction',
-- 'poisonous', 'abilities_sep', 'aggressive', 'immune_to_stun', 'immune_to_drain', 'immune_to_poison', 'immune_to_deflect',
-- 'attack', 'magic', 'ranged', 'defence', 'max_melee', 'max_magic', 'max_ranged', 'max_spec', 'acc_melee', 'acc_magic', 'acc_ranged', 'armour', 'aff_melee', 'aff_magic', 'aff_ranged', 'aff_weakness'
function SMWarg(name, version, id, members, release, removal, examine, level, style, lp, weakness, xp, slaylvl, slayxp, assignedby, slayercat, poisonous, abilities, restriction,
aggressive, immune_to_stun, immune_to_drain, immune_to_poison, immune_to_deflect,
attack, magic, ranged, defence, max_melee, max_magic, max_ranged, max_spec, acc_melee, acc_magic, acc_ranged, armour, aff_melee, aff_magic, aff_ranged, aff_weakness)
local toJSON = {
name = name,
version = version,
id = id,
members = members,
examine = examine,
level = level,
style = style:gsub('|', '¦'),
lifepoints = lp,
weakness = weakness:gsub('|', '¦'),
experience = xp,
slayer = slaylvl,
slayer_experience = slayxp,
assigned_by = assignedby:gsub('|', '¦'),
slayer_category = slayercat
}
local yn = {
aggressive = aggressive,
immune_to_stun = immune_to_stun,
immune_to_drain = immune_to_drain,
immune_to_poison = immune_to_poison,
immune_to_deflect = immune_to_deflect
}
local num = {
attack = attack,
magic = magic,
ranged = ranged,
defence = defence,
max_melee = max_melee,
max_magic = max_magic,
max_ranged = max_ranged,
max_spec = max_spec,
acc_melee = acc_melee,
acc_magic = acc_magic,
acc_ranged = acc_ranged,
armour = armour,
aff_melee = aff_melee,
aff_magic = aff_magic,
aff_ranged = aff_ranged,
aff_weakness = aff_weakness
}
for k,v in pairs(yn) do
if v:find('[Yy]es check') then
toJSON[k] = true
elseif v:find('[Xx] mark') then
toJSON[k] = false
end
end
for k,v in pairs(num) do
if type(v) == 'string' then
if v:lower() == 'n/a' or v:lower() == 'varies' then
toJSON[k] = v
end
elseif type(v) == 'number' then
toJSON[k] = v
end
end
if paramtest.is_empty(restriction) and tostring(restriction):find('action=edit') then
toJSON.restriction = restriction_map.surface
else
toJSON.restriction = restriction
end
if poisonous then
if poisonous:find('[Yy]es check') then
toJSON.poisonous = true
local m = poisonous:match(' (%d+)<')
if m then
toJSON.poison_damage = m
end
elseif poisonous:find('[Xx] mark') then
toJSON.poisonous = false
end
end
local rel, upd, rem, updr
rel, upd = release:match('(.-) %(%[%[Update:(.-)|Update%]%]%)')
if rel == nil then
rel = release:match('(.-) %(Update unknown%)')
end
if rel then
toJSON.release_date = rel:gsub('%[',''):gsub('%]','')
if upd then
toJSON.release_update_post = upd
end
end
rem, updr = removal:match('(.-) %(%[%[Update:(.-)|Update%]%]%)')
if rem == nil then
rem = removal:match('(.-) %(Update unknown%)')
end
if rem then
toJSON.removal_date = rem:gsub('%[',''):gsub('%]','')
if updr then
toJSON.removal_update_post = updr
end
end
for k,v in pairs(toJSON) do
if v == '' or (type(v) == 'string' and string.find(v,'action=edit')) then
toJSON[k] = nil
end
end
return mw.text.nowiki(mw.text.jsonEncode(toJSON))
end
function addcategories(args,catargs)
local ret = { 'Bestiary' }
local cat_map = {
-- Added if the parameter has content
defined = {
aka = 'Pages with AKA',
},
-- Added if the parameter has no content
notdefined = {
image = 'Needs image',
members = 'Needs members status',
release = 'Needs release date',
examine = 'Needs examine added',
level = 'Needs combat level',
experience = 'Needs XP per kill',
immune_to_stun = 'Missing stun immunity information',
immune_to_poison = 'Missing poison immunity information',
immune_to_deflect = 'Missing deflect immunity information',
immune_to_drain = 'Missing drain immunity information',
attack = 'Missing combat skill levels',
magic = 'Missing combat skill levels',
ranged = 'Missing combat skill levels',
defence = 'Missing combat skill levels',
id = 'Needs ID'
},
-- regex
grep = {
poisonous = { ['yes check%.svg'] = 'Poisonous monsters' },
aggressive = { ['yes check%.svg'] = 'Aggressive monsters' },
immune_to_stun = { ['is immune'] = 'Stun-immune monsters', ['is not immune'] = 'Stun-susceptible monsters' },
immune_to_poison = { ['is immune'] = 'Poison-immune monsters', ['is not immune'] = 'Poison-susceptible monsters' },
immune_to_deflect = { ['is immune'] = 'Deflect-immune monsters', ['is not immune'] = 'Deflect-susceptible monsters' },
immune_to_drain = { ['is immune'] = 'Drain-immune monsters', ['is not immune'] = 'Drain-susceptible monsters' },
},
}
-- Run and add mapped categories
for n, v in pairs(cat_map.defined) do
if catargs[n] and catargs[n].one_defined then
table.insert(ret,v)
end
end
for n, v in pairs(cat_map.notdefined) do
if catargs[n] and catargs[n].all_defined == false then
table.insert(ret,v)
end
end
-- searches
for n, v in pairs(cat_map.grep) do
for m, w in pairs(v) do
if args[n] then
if string.find(string.lower(tostring(args[n].d) or ''),m) then
table.insert(ret,w)
end
if args[n].switches then
for _, x in ipairs(args[n].switches) do
if string.find(string.lower(tostring(x)),m) then
table.insert(ret,w)
end
end
end
end
end
end
local levels = { args.level.d }
if args.level.switches then
for _, v in ipairs(args.level.switches) do
if v ~= infobox.nilParam() then
table.insert(levels,v)
end
end
end
for _, v in ipairs(levels) do
if v == 'N/A' then
table.insert(ret,'Monsters with no combat level')
elseif tonumber(v) then
table.insert(ret,string.format('Combat level %s monsters',v))
end
end
if args.members.d:find('[Nn]o') then
table.insert(ret,'F2P bestiary')
elseif args.members.switches then
for _, v in ipairs(args.members.switches) do
if v:find('[Nn]o') then
table.insert(ret,'F2P bestiary')
break
end
end
end
if args.members.d:find('[Yy]es') then
table.insert(ret,'P2P bestiary')
elseif args.members.switches then
for _, v in ipairs(args.members.switches) do
if v:find('[Yy]es') then
table.insert(ret,'P2P bestiary')
break
end
end
end
if args.abilities.d:find('clickpic') then
table.insert(ret,'Monsters that use abilities')
elseif args.abilities.switches then
for _, v in ipairs(args.abilities.switches) do
if v:find('clickpic') then
table.insert(ret,'Monsters that use abilities')
break
end
end
end
if args.weakness.d then
wkcats(args.weakness.d,ret)
end
if args.weakness.switches then
for _, v in ipairs(args.weakness.switches) do
if v ~= _nil then
wkcats(v,ret)
end
end
end
if args.assigned_by.d then
slaycats(args.assigned_by.d,ret)
end
if args.assigned_by.switches then
for _, v in ipairs(args.assigned_by.switches) do
if v ~= _nil then
slaycats(v,ret)
end
end
end
-- combine table and format category wikicode
for i, v in ipairs(ret) do
if (v ~= '') then
ret[i] = string.format('[[Category:%s]]',v)
end
end
return table.concat(ret,'')
end
return p
-- </syntaxhighlight>