Module:Creature Mutation Query
Revision as of 15:04, 19 January 2023 by Teamtoto (talk | contribs) (Created page with "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 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...")
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
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"]
local isDefect = string.match(type,"defect") ~= nil
local isMental = string.match(type,"Mental") ~= nil
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;"> (' .. level
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 .. ")</span></b>"
end
end
local mutationString = mw.html.create('div')
mutationString
:addClass('qud-mutation-entry')
:wikitext('[[' .. mutation .. '|'.. mutation .. parentheses .. ']]')
return mutationString
end
return p