Module:Creature Mutation Query: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 22: Line 22:
end
end


local query = {
 
result= doQuery(mutation)
if result ~= nil then
  return format(result["_pageName"], mutation, result["cost"], result["type"], level, ego)
else
  return format(mutation, mutation, nil, "", level, ego)
end
end
 
function doQuery(mutation)
    local query = {
tables = { 'Mutations' },
tables = { 'Mutations' },
fields = {'Cost, Type'},
fields = {'Cost, Type, _pageName'},
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
limit= '1'
limit= '1'
}
}
local cost, type = tonumber(util_cargo.queryAndCast(query)[1]["Cost"]), util_cargo.queryAndCast(query)[1]["Type"]
-- Try to find a mutation with this name, if not, just return the name unlinked.
     if type ~= nil then
    result = util_cargo.queryAndCast(query)
      local isDefect = string.match(type,"defect") ~= nil
     if not next(result) then
      local isMental = string.match(type,"Mental") ~= nil
        return nil
    else return result[1]
     end
     end
    local modifier = math.floor((ego-16)/2)
end
    local parentheses = ""


  if isDefect then
function formatBonus(modifier)
    parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
     if modifier > 0 then
  elseif (cost ~= nil) or (cost > 1) then
      c = "00c420\">+"
     parentheses = '<b><span style="color:#b1c9c3;">&nbsp;(<span style="color:#77bfcf;">' .. level .. '</span>'
    elseif modifier < 0 then
    if isMental then
      c= "d74200\">"
      local bonus = ""
return '<span style = \"color:#"=' .. c .. tostring(modifier) .. '</span>'
      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
     end
   parentheses = parentheses .. ")</span></b>"
end
 
function formatResult(page, name, formattedLevel, modifier, showBonus)
   parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#"' .. formattedLevel
  if showBonus then
        parentheses = parentheses .. formatBonus(modifier)
   end
   end
 
  parentheses = parentheses .. '</span><span style="color:#b1c9c3;">)</span></b>'
-- formatting
local mutationString = mw.html.create('div')
local mutationString = mw.html.create('div')
mutationString
mutationString
   :addClass('qud-mutation-entry')
   :addClass('qud-mutation-entry')
:wikitext('[[' .. mutation .. '|'.. mutation .. parentheses .. ']]')
:wikitext('[[' .. name.. '|'.. page .. parentheses .. ']]')
  return mutationString
end


return mutationString
 
function format(page, name, cost, type, level, ego)
    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)
    local parentheses = ""
  if isDefect then
      formattedLevel ='a64a2e;">D'
  elseif (cost == nil or cost > 1) then
      formattedLevel = '77bfcf;">' .. level
  end
 
  return formatResult(page, name, formattedLevel, modifier, isMental)
end
end


return p
return p

Navigation menu