Module:Creature Mutation Query: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 28: | Line 28: | ||
limit= '1' | limit= '1' | ||
} | } | ||
-- Try to find a mutation with this name, if not, just return the name unlinked. | |||
result = util_cargo.queryAndCast(query)[1] | |||
local parentheses = "" | |||
if not next(result) then | |||
else | |||
local cost, type = tonumber(util_cargo.queryAndCast(result["Cost"])), result[1]["Type"] | |||
local isDefect = false | local isDefect = false | ||
local isMental = false | local isMental = false | ||
Line 36: | Line 42: | ||
end | end | ||
local modifier = math.floor((ego-16)/2) | local modifier = math.floor((ego-16)/2) | ||
if isDefect then | if isDefect then | ||
parentheses ='<b><span style="color:#b1c9c3;"> (</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>' | parentheses ='<b><span style="color:#b1c9c3;"> (</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>' | ||
Line 54: | Line 59: | ||
parentheses = parentheses .. ")</span></b>" | parentheses = parentheses .. ")</span></b>" | ||
end | end | ||
end | |||
-- formatting | |||
local mutationString = mw.html.create('div') | local mutationString = mw.html.create('div') | ||
mutationString | mutationString |
Revision as of 00:23, 1 June 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'
}
-- Try to find a mutation with this name, if not, just return the name unlinked.
result = util_cargo.queryAndCast(query)[1]
local parentheses = ""
if not next(result) then
else
local cost, type = tonumber(util_cargo.queryAndCast(result["Cost"])), result[1]["Type"]
local isDefect = false
local isMental = false
if type ~= nil then
isDefect = string.match(type,"defect") ~= nil
isMental = string.match(type,"Mental") ~= nil
end
local modifier = math.floor((ego-16)/2)
if isDefect then
parentheses ='<b><span style="color:#b1c9c3;"> (</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
elseif (cost == nil or 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
end
-- formatting
local mutationString = mw.html.create('div')
mutationString
:addClass('qud-mutation-entry')
:wikitext('[[' .. mutation .. '|'.. mutation .. parentheses .. ']]')
return mutationString
end
return p