Module:Creature Mutation Query: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 5: Line 5:


function p.main()  
function p.main()  
local mutation = ""
local mutation = "Poison Gas Generation"
local ego = 16  --[default, is 0 modifier]
local ego = 16  --[default, is 0 modifier]
local level = 1
local level = 1
Line 38: Line 38:
   if isDefect then
   if isDefect then
     parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
     parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
   elseif (cost ~= nil) or (cost > 1) then
   elseif (cost == nil or cost > 1) then
    parentheses = '<b><span style="color:#b1c9c3;">&nbsp;(<span style="color:#77bfcf;">' .. level .. '</span>'
      parentheses = '<b><span style="color:#b1c9c3;">&nbsp;(<span style="color:#77bfcf;">' .. level .. '</span>'
    if isMental then
      if isMental then
      local bonus = ""
        local bonus = ""
      if modifier > 0 then
        if modifier > 0 then
         bonus = "<span style = \"color:#00c420\">+" .. tostring(modifier) .. '</span>'
         bonus = "<span style = \"color:#00c420\">+" .. tostring(modifier) .. '</span>'
      elseif modifier < 0 then
        elseif modifier < 0 then
        bonus = "<span style = \"color:#d74200\">" .. tostring(modifier) .. '</span>'
          bonus = "<span style = \"color:#d74200\">" .. tostring(modifier) .. '</span>'
      end
        end
      parentheses = parentheses .. bonus
        parentheses = parentheses .. bonus
     
     end
     end
   parentheses = parentheses .. ")</span></b>"
   parentheses = parentheses .. ")</span></b>"

Revision as of 15:37, 19 January 2023


local util_args = require('Module:Args Utility')
local util_cargo = require('Module:Cargo Utility')

local p = {}

function p.main() 
local mutation = "Poison Gas Generation"
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;">&nbsp;(</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;">&nbsp;(<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