Module:Creature Mutation Query: Difference between revisions

mNo edit summary
fix positive mutation ego bonuses not appearing
Line 3: Line 3:


local p = {}
local p = {}
function p.calculate(mutation, level, ego)
result= doQuery(mutation)
if result ~= nil then
  return format(result["_pageName"], result["Name"], result["Cost"], result["Type"], level, ego)
else
  return format(mutation, mutation, nil, "", level, ego)
end
end


function p.main()  
function p.main()  
Line 21: Line 30:
end
end
end
end
 
return p.calculate(mutation, level, ego)
 
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
end


function doQuery(mutation)
function doQuery(mutation)
-- TODO: edit QBE to remove P{{mutation ID to name}} so we can just query
-- the MutationID
     local query = {
     local query = {
tables = { 'Mutations' },
tables = { 'Mutations' },
fields = {'Cost, Type, _pageName'},
fields = {'Cost, Type, _pageName, MutationID, Name'},
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
where = '(_pageNamespace="14" OR _pageNamespace="0") AND Name="' .. mutation..'"',
limit= '1'
limit= '1'
}
}
Line 47: Line 51:


function formatBonus(modifier)
function formatBonus(modifier)
c = ""
     if modifier > 0 then
     if modifier > 0 then
       c = "00c420\">+"
       c = "00c420\">+"
     elseif modifier < 0 then
     elseif modifier < 0 then
       c= "d74200\">"
       c= "d74200\">"
return '<span style = \"color:#"=' .. c .. tostring(modifier) .. '</span>'
     end
     end
    return '<span style = \"color:#"=' .. c .. tostring(modifier) .. '</span>'
end
end


Line 78: Line 83:
     end
     end
     local modifier = math.floor((ego-16)/2)
     local modifier = math.floor((ego-16)/2)
    mw.log(modifier)
     local parentheses = ""
     local parentheses = ""
   if isDefect then
   if isDefect then
       formattedLevel ='a64a2e;">D'
       formattedLevel ='a64a2e;">D'
   elseif (cost == nil or cost > 1) then
   elseif (cost == nil or tonumber(cost) > 1) then
       formattedLevel = '77bfcf;">' .. level
       formattedLevel = '77bfcf;">' .. level
   end
   end
Line 88: Line 94:
end
end


function p.test()
return p.calculate("Teleportation", -2, 28)
end
return p
return p