Módulo:Combat level
Ir para navegação
Ir para pesquisar
Documentação do módulo
Esta documentação é transcluída de Predefinição:Sem documentação/doc. [editar] [atualizar]
Este módulo não possui nenhuma documentação. Por favor, considere adicionar uma documentação em Módulo:Combat level/doc. [editar]
-- <nowiki>
--
-- Implements {{Template:Calculator/Combat level}}
--
local p = {}
function p.calc( frame )
local args = frame:getParent().args
local attack = tonumber(args.attack or 1)
local strength = tonumber(args.strength or 1)
local defence = tonumber(args.defence or 1)
local ranged = tonumber(args.ranged or 1)
local magic = tonumber(args.magic or 1)
local constitution = tonumber(args.constitution or 10)
local prayer = tonumber(args.prayer or 1)
local summoning = tonumber(args.summoning or 1)
return p._calc( attack, strength, defence, ranged, magic, constitution, prayer, summoning )
end
function p._calc ( attack, strength, defence, ranged, magic, constitution, prayer, summoning )
-- This will be used several times:
local attstr = attack + strength
-- Used formula, with every subcalculation being floored:
-- 1/4 * [1.3 * Max(Att+Str, 2*Mag, 2*Rng) + Def + Hp + Pray/2 + Summ/2]
local lvl = ( math.max( attstr, magic * 2, ranged * 2 ) * 1.3 + defence + constitution + math.floor( prayer * 0.5 ) + math.floor( summoning *0.5 ) ) * 0.25
-- Calculate what's needed for another combat level
-- formula: 1 - (current level - floor(current level)) / weight
-- The weight of pray/summ for example is 1/8, that of def/hp is 1/4 etc.
local HpDef = math.ceil( ( 1 - ( lvl % 1 ) ) * 4 )
local PraySumm = math.ceil( ( 1 - ( lvl % 1 ) ) * 8 )
local AttStr, Mage, Range
local cbtype
if attstr >= 2*magic and attstr >= 2*ranged then
cbtype = 'corpo a corpo'
AttStr = math.ceil ( ( 1 - ( lvl % 1 ) ) / 0.325 )
Mage = math.ceil( ( attstr - magic * 2 ) / 2 + ( 1 - ( lvl % 1 ) ) / 0.65 )
Range = math.ceil( ( attstr - ranged * 2 ) / 2 + ( 1 - ( lvl % 1 ) ) / 0.65 )
else
-- calculate att/str levels needed for combat level up:
-- first calculate how many levels to get to make your combat melee-based, then add the amount of levels needed from there.
AttStr = math.max( ranged, magic ) * 2 - attstr + math.ceil( ( 1 - ( lvl % 1 ) ) / 0.325 )
-- store this value in variable Mage first: assume mage-based combat first
Mage = math.ceil( ( 1 - ( lvl % 1 ) ) / 0.65 )
if ranged > magic then
cbtype = 'comabate à distância'
-- move the calculated value to variable Range: the combat is range-based
Range = Mage
-- same logic for melee: amount of levels to get mage-based combat PLUS levels to another cb from there
Mage = ranged - magic + Range
else
cbtype = 'magia'
-- same logic again
Range = magic - ranged + Mage
end
end
function plural(level)
if level == 1 then
text = ' nível'
else
text = ' níveis'
end
return text
end
local level = 'Seu nível de combate é <b>' .. math.floor( lvl ) .. '</b>, baseado em ' .. cbtype .. '.'
local tips = ' Para o nível ' .. ( math.floor( lvl ) + 1 ) .. ', você vai precisar de:\n*' ..
HpDef .. plural(HpDef) ..' em [[Condição Física]] ou [[Defesa]],\n*' ..
(prayer % 2 == 0 and PraySumm+1 or PraySumm) .. plural(PraySumm) ..' em [[Oração]],\n*' ..
(summoning % 2 == 0 and PraySumm+1 or PraySumm) .. plural(PraySumm) .. ' em [[Evocação]],\n*' ..
AttStr .. plural(AttStr) ..' em [[Ataque]] ou [[Força]],\n*' ..
Mage .. plural(Mage) ..' em [[Magia]],\n*' ..
Range .. plural(Range) ..' em [[Combate à Distância]]\n'
return level .. tips
end
return p