Module:Creature Mutation Query: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(dont crash if there is no mut type specified) |
||
Line 8: | Line 8: | ||
local ego = 16 --[default, is 0 modifier] | local ego = 16 --[default, is 0 modifier] | ||
local level = 1 | local level = 1 | ||
local isDefect = false | |||
local isMental = false | |||
frame=mw.getCurrentFrame() | frame=mw.getCurrentFrame() | ||
Line 27: | Line 29: | ||
} | } | ||
local cost, type = tonumber(util_cargo.queryAndCast(query)[1]["Cost"]), util_cargo.queryAndCast(query)[1]["Type"] | local cost, type = tonumber(util_cargo.queryAndCast(query)[1]["Cost"]), util_cargo.queryAndCast(query)[1]["Type"] | ||
local isDefect = string.match(type,"defect") ~= nil | if type ~= nil then | ||
local isDefect = string.match(type,"defect") ~= nil | |||
local isMental = string.match(type,"Mental") ~= nil | |||
end | |||
local modifier = math.floor((ego-16)/2) | local modifier = math.floor((ego-16)/2) | ||
local parentheses = "" | local parentheses = "" |
Revision as of 15:11, 19 January 2023
local util_args = require('Module:Args Utility')
local util_cargo = require('Module:Cargo Utility')
local p = {}
function p.main()
local mutation = ""
local ego = 16 --[default, is 0 modifier]
local level = 1
local isDefect = false
local isMental = false
frame=mw.getCurrentFrame()
if frame.args ~= nil and frame.args ~= '' then
if frame.args[1] ~= nil and frame.args[1] ~= '' then
mutation = mw.text.trim(frame:preprocess(frame.args[1]))
level = tonumber(mw.text.trim(frame:preprocess(frame.args[2])))
end
if frame.args[3] ~= nil and frame.args[3] ~= '' then
ego = tonumber(mw.text.trim(frame:preprocess(frame.args[3])))
end
end
local query = {
tables = { 'Mutations' },
fields = {'Cost, Type'},
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
limit= '1'
}
local cost, type = tonumber(util_cargo.queryAndCast(query)[1]["Cost"]), util_cargo.queryAndCast(query)[1]["Type"]
if type ~= nil then
local isDefect = string.match(type,"defect") ~= nil
local isMental = string.match(type,"Mental") ~= nil
end
local modifier = math.floor((ego-16)/2)
local parentheses = ""
if isDefect then
parentheses ='<b><span style="color:#b1c9c3;"> (</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
elseif (cost > 1) then
parentheses = '<b><span style="color:#b1c9c3;"> (<span style="color:#77bfcf;">' .. level .. '</span>'
if isMental then
local bonus = ""
if modifier > 0 then
bonus = "<span style = \"color:#00c420\">+" .. tostring(modifier) .. '</span>'
elseif modifier < 0 then
bonus = "<span style = \"color:#d74200\">" .. tostring(modifier) .. '</span>'
end
parentheses = parentheses .. bonus
end
parentheses = parentheses .. ")</span></b>"
end
local mutationString = mw.html.create('div')
mutationString
:addClass('qud-mutation-entry')
:wikitext('[[' .. mutation .. '|'.. mutation .. parentheses .. ']]')
return mutationString
end
return p