Module:Arm

From Empire of Dragons
Revision as of 09:54, 19 June 2024 by Oberoten (talk | contribs)
Jump to navigation Jump to search
No SoakHalf SoakNormalNo DamPenetration
312 mm
156234312390 mm of Armour


thispicture
File:thispicture
file:thispicture

p={}

function p.countargs( frame )
local frame = mw.getCurrentFrame() -- get the current frame object
local num_args = 0 -- initialize the number of arguments to zero

   for k, v in pairs(frame.args) do
    num_args = num_args + 1 -- increment the number of arguments for each argument in the frame
   end
 return "I counted " .. num_args
end

function p.virtuesflaws(frame)
  local result 
  local frames = mw.getCurrentFrame() -- get the current frame object
  local num_args = 0 -- initialize the number of arguments to zero

	for k, v in pairs(frames.args) do
    	num_args = num_args + 1 -- increment the number of arguments for each argument in the frame
	end
  local num_skills = math.floor(num_args / 2)
  --result = "<Br>This is " .. num_skills .. " skills worth </br> out of " ..num_args 
  result = [===[<table><tr><td class'skills'>''' ''Virtue/Flaw'' '''</td><td class='spacer'></td><td >''' ''Level'' '''</td></tr>]===]
  for i = 1, num_skills do
    local name = frame.args[(i-1)*2+1]
    local level = frame.args[(i-1)*2+2] or 0
    
          result = result ..  "<tr><td>" .. name.. " </td><td class='spacer'></td><td >" .. level .. "</td></tr>" 
    
    end
  result=result .. "</table>"
  return result
end

function p.personalities(frame)
  local result 
  local frames = mw.getCurrentFrame() -- get the current frame object
  local num_args = 0 -- initialize the number of arguments to zero

	for k, v in pairs(frames.args) do
    	num_args = num_args + 1 -- increment the number of arguments for each argument in the frame
	end
  local num_skills = math.floor(num_args / 2)
  --result = "<Br>This is " .. num_skills .. " skills worth </br> out of " ..num_args 
  result = "<table><tr><td class'skills'>''' ''Personality traits'' '''</td><td class='spacer'></td><td >''' ''Level'' '''</td></tr>"
  for i = 1, num_skills do
    local name = frame.args[(i-1)*2+1]
    local level = frame.args[(i-1)*2+2]
    result = result .. [==[<tr><td class='skills'>]==] .. name .. [==[</td><td class='spacer'></td><td class='th-shaded'>]==] ..level.. [==[</td></tr>]==]
    --result = result .. "<p>" .. name.. "  " .. level .. " " .. cost .. "</p>"  
    end
  result=result .. "</table>"
  return result
end

function p.skills(frame)
  local result
  local frames = mw.getCurrentFrame()
  local num_args = 0

  -- Count the number of arguments
  for k, v in pairs(frames.args) do
    num_args = num_args + 1
  end

  local num_skills = math.floor(num_args / 3)
  local skills = {} -- Table to store skills

  -- Populate the skills table
  for i = 1, num_skills do
    local name = frame.args[(i - 1) * 3 + 1]
    local level = frame.args[(i - 1) * 3 + 2]
    local cost = frame.args[(i - 1) * 3 + 3]

    table.insert(skills, {name = name, level = level, cost = cost})
  end

  -- Sort the skills table based on the 3rd field (cost)
  
  table.sort(skills, function(a, b) return a.name < b.name end)

  -- Generate the HTML table
  result = "<table><tr><td class='skills'>Skill</td><td class='spacer'></td><td>Level</td><td class='spacer'></td><td class='cost'>Cost</td></tr>"
  for _, skill in ipairs(skills) do
    result = result .. string.format("<tr><td class='skills'>%s</td><td class='spacer'></td><td class='rd'>%s</td><td class='spacer'></td><td class='rd'>%s</td></tr>",
      skill.name, skill.level, skill.cost)
  end
  result = result .. "</table>"

  return result
end

function p.hello(frame)
    return 'Hello, my ' .. frame.args[1] .. ' is ' .. frame.args[2]
end

function p.level(frame)
    local xp = 0
    local cost = tonumber(frame.args[2]) or 1
    local level = tonumber(frame.args[1])
    xp = cost*((level^2)/2 + (level/2))
    return "Level " .. level .. " costs " .. xp

end

function p.xp(frame)
   local xp = frame.args[1] 	
   local cost = frame.args[2] or 1
   -- =0,5*ROT(8*D12/C12+1)-0,5
   local level = math.floor(0.5*math.sqrt(8*xp/cost+1)-0.5)
   local levelc = cost*((level^2)/2 + (level/2))
   local remains = xp - levelc
   
   return xp .. "Xp at skill-cost ".. cost .. " gives you level " .. level .. " in a skill with " .. remains .. " Xp leftover"
end

--[[style='background-color:green; color:black;']]
--[[style='background-color:yellow; color:black;']]
--[[style='background-color:orange; color:black;']]
--[[style='background-color:red; color:black;']]


function p.pen(frame)
   local pen = frame.args[1] or 0
   if pen == "--"  then
   	return
   	end
   pen = pen:gsub("[^%d.]", "")
   pen = tonumber(pen)
   local top= "<div style='text-align:center;'><table style='text-align:center; font-size: 66%;' border='thin 000'><tr><td>No Soak</td><td>Half Soak</td><td>Normal</td><td>No Dam</td><td>Penetration <br>".. tonumber(pen) .." mm</td></tr><tr style='font-weight: bold;'>" 
   local bottom ="</tr></table></div>"
   local msg = " <td width='50px' style='font-size: 90%; background-color:red; color:black;'>" .. (0.5*tonumber(pen)) .. "</td><td width='50px' style='background-color:orange; font-size: 90%; color:black;'>" .. (0.75*pen) .. "</td><td width='50px' style='font-size: 90%; background-color:yellow; color:black;'>" .. pen .."</td><td width='50px' style='font-size: 90%; background-color:green; color:black;'>" .. (pen*1.25) .. "</td><td style='font-size: 66%; text-align:left;'> mm of Armour</td>"
   return top .. msg .. bottom
end

function p.midships(frame)
	local name = frame.args[1] 
    local size = frame.args[2] 
    local accbonus = frame.args[3]	
    local manbonus = frame.args[4]	
    local hullsoak = frame.args[5]	
    local Abonus = frame.args[6] 
    local Ibonus = frame.args[7] 
    local thickness = frame.args[8] 
    local shield = frame.args[9] 
    local hyperfactor = frame.args[10] 
    
	local ship = [==[
	<table style="border: 2px solid #000; border-width: thin thick thick thin;" width="60%">
<tr>
<td style="border: 1px solid #000;" width="75%" colspan="4">]==].. name ..[==[</td><td  width="15%">Size : </td><td style="text-align: right;" >]==]..size..[==[</td>
</tr>
<tr>
<td>Acc+</td><td>]==] .. accbonus .. [==[</td><td>Man+</td><td>]==] .. manbonus .. [==[ </td><td>HullSoak</td><td style="text-align: right;" >]==] .. hullsoak .. [==[</td>
</tr>
<tr>
<td>A+</td><td>]==] .. Abonus  .. [==[</td><td>I+</td><td>]==] .. Ibonus .. [==[</td><td>Hull Thickness<td><td style="text-align: right;" >]==] .. thickness .. [==[  mm</td>
</tr>
<tr>
<td>Shield</td><td>]==] .. shield .. [==[</td><td>Hyperspace</td><td>]==] .. hyperfactor .. [==[</td>
</tr>
</table>]==]  
	 
  return ship	
end

function p.midships2(frame)
	local name = frame.args[1] 
    local size = frame.args[2] 
    local accbonus = frame.args[3]	
    local manbonus = frame.args[4]	
    local hullsoak = frame.args[5]	
    local Abonus = frame.args[6] 
    local Ibonus = frame.args[7] 
    local thickness = frame.args[8] 
    local shield = frame.args[9] 
    local hyperfactor = frame.args[10] 
    
	local ship = [==[

<tr>
<td style="border: 1px solid #000;" width="75%" colspan="4">]==].. name ..[==[</td><td  width="15%">Size : </td><td style="text-align: right;" >]==]..size..[==[</td>
</tr>
<tr>
<td>Acc+</td><td>]==] .. accbonus .. [==[</td><td>Man+</td><td>]==] .. manbonus .. [==[ </td><td>HullSoak</td><td style="text-align: right;" >]==] .. hullsoak .. [==[</td>
</tr>
<tr>
<td>A+</td><td>]==] .. Abonus  .. [==[</td><td>I+</td><td>]==] .. Ibonus .. [==[</td><td>Hull Thickness<td><td style="text-align: right;" >]==] .. thickness .. [==[  mm</td>
</tr>
<tr>
<td >Shield</td><td>]==] .. shield .. [==[</td><td>Hyperspace</td><td>]==] .. hyperfactor .. [==[</td>
</tr>
<tr>
<td style='border-bottom-style: solid;' colspan='7'></td>
</tr>
]==]  
	 
  return ship	
end

function p.calculateArmorPenetrationDepth(K, V, R, n)
local K = 5.54
local V = 838
local R = 7850
local n = 0.746


    local D = K * math.pow(V/R, n)
    D= D .. "mm"


return D 
end

function p.addition(f)
 local foul = f.args
 local A = foul.A
 local B = foul.B
 local tot = A + B
 return tot
end

p.helloName = function( f )
	local args = f.args
	return 'Hello, ' .. args.name .. '!'
end

function p.forceforms (f)
local Fo = f.args
-- Techniques

local CrSt, SeKn, CoAl,DeWe = Fo.CrSt, Fo.SeKn, Fo.CoAl, Fo.DeWe
local Mi, Bo, Ma, En = Fo.Mi, Fo.Bo, Fo.Ma, Fo.En

-- Grid
local CrStMi, CrStBo, CrStMa, CrStEn = CrSt+Mi, CrSt+Bo,CrSt+Ma,CrSt+En
local SeKnMi, SeKnBo, SeKnMa, SeKnEn = SeKn+Mi, SeKn+Bo,SeKn+Ma,SeKn+En
local CoAlMi, CoAlBo, CoAlMa, CoAlEn = CoAl+Mi, CoAl+Bo,CoAl+Ma,CoAl+En
local DeWeMi, DeWeBo, DeWeMa, DeWeEn = DeWe+Mi, DeWe+Bo,DeWe+Ma,DeWe+En


local formtable= [==[
<table class="charsheet3" width='60%'>
<tr>
<td></td>
<td></br>lvl </td>
<td>Body</br>]==] .. Bo .. [==[</td>
<td>Mind</br>]==] .. Mi .. [==[</td>
<td>Matter </br>]==] .. Ma .. [==[</td>
<td>Energy</br>]==] .. En .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Create/Strengthen</td><td> ]==] .. CrSt .. [==[</td>
<td>]==] .. CrStBo .. [==[</td>
<td>]==] .. CrStMi .. [==[</td>
<td>]==] .. CrStMa .. [==[</td>
<td>]==] .. CrStEn .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Sense/Know</td><td> ]==] .. SeKn .. [==[</td>
<td>]==] .. SeKnBo .. [==[</td>
<td>]==] .. SeKnMi .. [==[</td>
<td>]==] .. SeKnMa .. [==[</td>
<td>]==] .. SeKnEn .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Control/Alter</td><td>]==] .. CoAl .. [==[</td>
<td>]==] .. CoAlBo .. [==[</td>
<td>]==] .. CoAlMi .. [==[</td>
<td>]==] .. CoAlMa .. [==[</td>
<td>]==] .. CoAlEn .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Destroy/Weaken</td><td>]==] .. DeWe .. [==[</td>
<td>]==] .. DeWeBo .. [==[</td>
<td>]==] .. DeWeMi .. [==[</td>
<td>]==] .. DeWeMa .. [==[</td>
<td>]==] .. DeWeEn .. [==[</td>
</tr>

</table>
]==]
return formtable
end

function p.armforms (f)
local Fo = f.args
-- Techniques
local Cr, In, Mu, Pe, Re = Fo.Cr, Fo.In, Fo.Mu, Fo.Pe, Fo.Re

local An = Fo.An 
local Aq = Fo.Aq
local Au = Fo.Au
local Co = Fo.Co
local He = Fo.He
local Ig, Im, Me, Te, Vi = 	Fo.Ig, Fo.Im, Fo.Me, Fo.Te, Fo.Vi

-- Grid
local CrAn,CrAq, CrAu,CrCo,CrHe, CrIg,CrIm,CrMe,CrTe,CrVi = Cr+An,Cr+Aq,Cr+Au,Cr+Co,Cr+He,Cr+Ig,Cr+Im,Cr+Me,Cr+Te,Cr+Vi
local InAn,InAq, InAu,InCo,InHe, InIg,InIm,InMe,InTe,InVi = In+An,In+Aq,In+Au,In+Co,In+He,In+Ig,In+Im,In+Me,In+Te,In+Vi
local MuAn,MuAq, MuAu,MuCo,MuHe, MuIg,MuIm,MuMe,MuTe,MuVi = Mu+An,Mu+Aq,Mu+Au,Mu+Co,Mu+He,Mu+Ig,Mu+Im,Mu+Me,Mu+Te,Mu+Vi
local PeAn,PeAq, PeAu,PeCo,PeHe, PeIg,PeIm,PeMe,PeTe,PeVi = Pe+An,Pe+Aq,Pe+Au,Pe+Co,Pe+He,Pe+Ig,Pe+Im,Pe+Me,Pe+Te,Pe+Vi
local ReAn,ReAq, ReAu,ReCo,ReHe, ReIg,ReIm,ReMe,ReTe,ReVi = Re+An,Re+Aq,Re+Au,Re+Co,Re+He,Re+Ig,Re+Im,Re+Me,Re+Te,Re+Vi

local formtable= [==[
<table class="formstable">
<tr>
<td></td>
<td></br>lvl</td>
<td>Animal</br> ]==] .. An .. [==[ </td>
<td>Aquam </br> ]==] .. Au .. [==[ </td>
<td>Auram </br> ]==] .. Aq .. [==[ </td>
<td>Corpus</br> ]==] .. Co .. [==[ </td>
<td>Herbam</br> ]==] .. He .. [==[ </td>
<td>Ignem </br> ]==] .. Ig .. [==[ </td>
<td>Imagonem</br> ]==] .. Im .. [==[ </td>
<td>Mentem</br> ]==] .. Me .. [==[ </td>
<td>Terram</br> ]==] .. Te .. [==[ </td>
<td>Vim</br> ]==] .. Vi .. [==[ </td>
</tr>
<tr>
<td style="text-align: left;">Creo</td><td> ]==] .. Cr .. [==[</td>
<td>]==] .. CrAn .. [==[</td>
<td>]==] .. CrAu .. [==[</td>
<td>]==] .. CrAq .. [==[</td>
<td>]==] .. CrCo .. [==[</td>
<td>]==] .. CrHe .. [==[</td>
<td>]==] .. CrIg .. [==[</td>
<td>]==] .. CrIm .. [==[</td>
<td>]==] .. CrMe .. [==[</td>
<td>]==] .. CrTe .. [==[</td>
<td>]==] .. CrVi .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Intelligo</td><td> ]==] .. In .. [==[</td>
<td>]==] .. InAn .. [==[</td>
<td>]==] .. InAu .. [==[</td>
<td>]==] .. InAq .. [==[</td>
<td>]==] .. InCo .. [==[</td>
<td>]==] .. InHe .. [==[</td>
<td>]==] .. InIg .. [==[</td>
<td>]==] .. InIm .. [==[</td>
<td>]==] .. InMe .. [==[</td>
<td>]==] .. InTe .. [==[</td>
<td>]==] .. InVi .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Muto</td><td> ]==] .. Mu .. [==[</td>
<td>]==] .. MuAn .. [==[</td>
<td>]==] .. MuAu .. [==[</td>
<td>]==] .. MuAq .. [==[</td>
<td>]==] .. MuCo .. [==[</td>
<td>]==] .. MuHe .. [==[</td>
<td>]==] .. MuIg .. [==[</td>
<td>]==] .. MuIm .. [==[</td>
<td>]==] .. MuMe .. [==[</td>
<td>]==] .. MuTe .. [==[</td>
<td>]==] .. MuVi .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Perdo</td><td> ]==] .. Pe .. [==[</td>
<td>]==] .. PeAn .. [==[</td>
<td>]==] .. PeAu .. [==[</td>
<td>]==] .. PeAq .. [==[</td>
<td>]==] .. PeCo .. [==[</td>
<td>]==] .. PeHe .. [==[</td>
<td>]==] .. PeIg .. [==[</td>
<td>]==] .. PeIm .. [==[</td>
<td>]==] .. PeMe .. [==[</td>
<td>]==] .. PeTe .. [==[</td>
<td>]==] .. PeVi .. [==[</td>
</tr>
<tr>
<td style="text-align: left;">Rego</td><td> ]==] .. Re .. [==[</td>
<td>]==] .. ReAn .. [==[</td>
<td>]==] .. ReAu .. [==[</td>
<td>]==] .. ReAq .. [==[</td>
<td>]==] .. ReCo .. [==[</td>
<td>]==] .. ReHe .. [==[</td>
<td>]==] .. ReIg .. [==[</td>
<td>]==] .. ReIm .. [==[</td>
<td>]==] .. ReMe .. [==[</td>
<td>]==] .. ReTe .. [==[</td>
<td>]==] .. ReVi .. [==[</td>
</tr>
</table>
]==]
return formtable
end

function p.MookSkillsOld(frame)
  local result 
  local frames = mw.getCurrentFrame() -- get the current frame object
  local num_args = 0 -- initialize the number of arguments to zero

	for k, v in pairs(frames.args) do
    	num_args = num_args + 1 -- increment the number of arguments for each argument in the frame
	end
  local num_skills = math.floor(num_args / 2)
  local colu =0
  --result = "<Br>This is " .. num_skills .. " skills worth </br> out of " ..num_args 
  
  result ="<table style='skills'><tr><td > Skills</td><td ></td><td > Level </td><td > Skills </td><td ></td><td > Level </td><td > Skills </td><td></td><td > Level </td><td> Skills </td><td></td><td > Level </td><td > Skills </td><td ></td><td > Level </td></tr><tr>"
  for i = 1, num_skills do
  	colu = colu +1
    local name = frame.args[(i-1)*2+1]
    local level = frame.args[(i-1)*2+2]
    if colu == 5 then 
    result = result .. [==[<td class='mskill'>]==] .. name .. [==[</td><td class='mspacer'></td><td>]==] ..level.. [==[</td></tr><tr>]==]
     else 
    result = result .. [==[<td class='mskill'>]==] .. name .. [==[</td><td class='mspacer'></td><td >]==] ..level.. [==[</td>]==]	
    end
    
    --result = result .. "<p>" .. name.. "  " .. level .. " " .. cost .. "</p>"  
    end
  result=result .. "</table>"
  return result
  
end


function p.MookSkills(frame)
  local result 
  local frames = mw.getCurrentFrame() -- get the current frame object
  local num_args = 0 -- initialize the number of arguments to zero

  for k, v in pairs(frames.args) do
    num_args = num_args + 1 -- increment the number of arguments for each argument in the frame
  end

  local num_skills = math.floor(num_args / 2)
  local colu = 0
  local skills = {} -- create a table to store skills and their levels

  -- Populate the skills table with name and level pairs
  for i = 1, num_skills do
    local name = frame.args[(i - 1) * 2 + 1]
    local level = frame.args[(i - 1) * 2 + 2]
    table.insert(skills, {name = name, level = level})
  end

  -- Sort the skills table based on the skill names
  table.sort(skills, function(a, b) return a.name < b.name end)

  -- Construct the HTML table
  result = "<table style='skills'><tr><td>Skills</td><td></td><td>Level</td></tr><tr>"

  for i, skill in ipairs(skills) do
    colu = colu + 1

    if colu == 5 then
      result = result .. "<td class='mskill'>" .. skill.name .. "</td><td class='mspacer'></td><td>" .. skill.level .. "</td></tr><tr>"
      colu = 0 -- reset the column counter for the new row
    else
      result = result .. "<td class='mskill'>" .. skill.name .. "</td><td class='mspacer'></td><td>" .. skill.level .. "</td>"
    end
  end

  result = result .. "</table>"
  return result
end


-- Define a function to process the 'image' parameter
function ProcessImage(frame)

    -- Get the value of the 'image' parameter
    local imageParam = frame.args['image'] or ''
    
    -- Check if the parameter starts with 'File:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'File:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Check if the parameter starts with 'file:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'file:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Add 'file:' to the beginning of the parameter
    imageParam = 'file:' .. imageParam
    
    -- Return the processed parameter
    return imageParam
end

-- Define a function to process the 'image' parameter
function processImage(frame)

    -- Get the value of the 'image' parameter
    local imageParam = frame.args['image'] or ''
    
    -- Check if the parameter starts with 'File:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'File:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Check if the parameter starts with 'file:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'file:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Add 'file:' to the beginning of the parameter
    imageParam = 'file:' .. imageParam
    
    -- Return the processed parameter
    return imageParam
end

function p.image(frame)
    -- Get the value of the 'image' parameter
    local imageParam = frame.args['image'] or ''
    
    -- Check if the parameter starts with 'File:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'File:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Check if the parameter starts with 'file:' (case insensitive)
    if mw.ustring.match(imageParam, '^[Ff][Ii][Ll][Ee]:') then
        -- Strip 'file:' from the beginning of the parameter
        imageParam = mw.ustring.sub(imageParam, 6)
    end
    
    -- Add 'file:' to the beginning of the parameter
    imageParam = 'file:' .. imageParam
    
    -- Return the processed parameter
    return imageParam
end


 return p