« Module:Infobox/Arme gamebryo » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
mAucun résumé des modifications
Kharmitch (discussion | contributions)
Aucun résumé des modifications
Ligne 6 : Ligne 6 :
--------------------------------------------------------
--------------------------------------------------------


-- Récupère un paramètre en forçant à 0
-- Récupère un paramètre au format number
-- si nil ou n'est pas nombre
-- Force à 0 si nil ou s'il n'est pas un nombre
function forceNumber(data)
function forceNumber(data)
return tonumber(data) or 0
return tonumber(data) or 0
end
end


function formatData(data, round)
-- Formatage du nombre pour l'affichage
-- local formattedData
function formatNumber(data, round)
-- if data and data > 0 then
-- formattedData = string.format(round, data)
-- end
return string.format(round or "%.1f", data)
return string.format(round or "%.1f", data)
end
end
Ligne 25 : Ligne 22 :


-- Type d'arme
-- Type d'arme
local weaponCompletType = localdata["type"] or ""
local weaponCompletType = (localdata['type'] or ''):lower()
local weaponType = weaponCompletType:gsub(" unique", "")
local weaponType = weaponCompletType:gsub(' unique', '')
local isUnique = weaponCompletType:find(' unique')
local isUnique = weaponCompletType:find(' unique') ~= nil


-- Dégâts
-- Nombre d'attaques par seconde
local attacksPerSec = forceNumber(localdata["attack shots/sec"])
local attacksPerSec = forceNumber(localdata["attack shots/sec"])


-- Augmentation des dégâts via les aptitudes
-- Durée du rechargement
-- Les aptitudes agissent comme un coefficient multiplicateur
local reloadTime = 0
local perksAttacksPerSec = 0
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
 
    reloadTime = forceNumber(localdata["reload time"])
for i = 1, 9 do
    local perkAttsecMult = forceNumber(localdata["perk" .. i .. " attsec mult"])
    perksAttacksPerSec = perksAttacksPerSec + (attacksPerSec * perkAttsecMult)
end
 
local perksAttacksPerSecTotal = attacksPerSec + perksAttacksPerSec
 
-- Multiplicateur de critique
local critChance = forceNumber(localdata["crit % mult"])
 
local critChanceModified = 0
if weaponType == 'gunautomatic' and perksAttacksPerSecTotal > 0 then
    critChanceModified = critChance / perksAttacksPerSecTotal
end
end


-- Nombre de projectiles
-- Nombre de projectiles par attaque
local proj = 1
local proj = 1
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
     proj = forceNumber(localdata["projectiles"])
     proj = forceNumber(localdata["projectiles"])
     if proj == 0 then proj = 1 end
     if proj == 0 then proj = 1 end -- on force à 1 si projectile non renseigné
end
end


local clipRounds = forceNumber(localdata["clip rounds"])
-- Taille du magasin
local ammoUse = forceNumber(localdata["ammo use"])
local clipRounds = forceNumber(localdata["clip rounds"])  


local shotsPerReload = 0
-- Nombre de cartouches par attaque
local ammoUse = forceNumber(localdata["ammo use"])
 
-- Nombre d'attaques par rechargement
local attacksPerReload = 0
if ammoUse > 0 then
if ammoUse > 0 then
     shotsPerReload = math.floor(clipRounds / ammoUse)
     attacksPerReload = math.floor(clipRounds / ammoUse)
end
end


-- Durée de rechargement
-- Dégâts par type : balistique, explosif, effet
local reloadTime = 0
 
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
local dmgNormTotal = forceNumber(localdata["damage"])
    reloadTime = forceNumber(localdata["reload time"])
local dmgNormProj = dmgNormTotal / proj
end
 
local dmgEffProj = forceNumber(localdata["effect damage"])
local dmgEffTotal = dmgEffProj * proj
 
local dmgExplProj = forceNumber(localdata["explosion damage"])
local dmgExplTotal = dmgExplProj * proj


-- Durée de rechargement en prenant en compte les aptitudes
-- Effets des aptitudes sur les dégâts
local perksAttacksPerSec = 0
local perksDmgNorm = 0
local perksDmgEff = 0
local perksDmgExpl = 0
local perksReloadTime = 0
local perksReloadTime = 0
local perksAttacksPerSecItems = ''
local perksDmgItems = ''
local perksReloadTimeItems = ''


for i = 1, 9 do
for i = 1, 9 do
     local perkReloadTime = forceNumber(localdata["perk" .. i .. " reload mult"])
     local perk = localdata["perk" .. i]
    perksReloadTime = perksReloadTime + (reloadTime * perkReloadTime)
end


local perksReloadTimeTotal = reloadTime - perksReloadTime
    if perk then
        -- Calcul de chaque donnée
        local perkAttacksPerSec = attacksPerSec * forceNumber(localdata["perk" .. i .. " attsec mult"])
        local perkDmgNorm = (dmgNormTotal * forceNumber(localdata["perk" .. i .. " mult"])) + forceNumber(localdata["perk" .. i .. " add"])
        local perkDmgEff = (dmgEffTotal * forceNumber(localdata["perk" .. i .. " eff mult"])) + forceNumber(localdata["perk" .. i .. " eff add"])
        local perkDmgExpl = (dmgExplTotal * forceNumber(localdata["perk" .. i .. " expl mult"])) + forceNumber(localdata["perk" .. i .. " expl add"])
        local perkReloadTime = reloadTime * forceNumber(localdata["perk" .. i .. " reload mult"])


-- Dégâts par type (simple, explosif, poison)
        -- Somme des effets et gestion
        -- de l'affichage de la table Effets des aptitudes


local damNormTotal = forceNumber(localdata["damage"])
        if perkAttacksPerSec > 0 then
local damNormProj = damNormTotal / proj
            perksAttacksPerSec = perksAttacksPerSec + perkAttacksPerSec
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">+ ' .. formatNumber(perkAttacksPerSec) .. '</div></li>'
        end


local damEffProj = forceNumber(localdata["effect damage"])
        if perkDmgNorm > 0 or perkDmgEff > 0 or perkDmgExpl > 0 then
local damEffTotal = damEffProj * proj
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">'


local damExplProj = forceNumber(localdata["explosion damage"])
            if perkDmgNorm > 0 then
local damExplTotal = damExplProj * proj
                perksDmgNorm = perksDmgNorm + perkDmgNorm
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgNorm)
            end


local perksDamNorm = 0
            if perkDmgExpl > 0 then
 
                perksDmgExpl = perksDmgExpl + perkDmgExpl
for i = 1, 9 do
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgExpl) .. ' ' .. icon.build( 'explosion' )
    local perkDamNormMult = forceNumber(localdata["perk" .. i .. " mult"])
            end
    local perkDamNormAdd  = forceNumber(localdata["perk" .. i .. " add"])
    perksDamNorm = perksDamNorm + (damNormTotal * perkDamNormMult) + perkDamNormAdd
end


local perksDamNormProj = perksDamNorm / proj
            if perkDmgEff > 0 then
local perksDamNormTotal = damNormTotal + perksDamNorm
                perksDmgEff = perksDmgEff + perkDmgEff
local perksDamNormProjTotal = damNormProj + perksDamNormProj
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgEff) .. ' ' .. icon.build( 'effect' )
            end


local perksDamEff = 0
            perksDmgItems = perksDmgItems .. '</div></li>'
        end


for i = 1, 9 do
        if perkReloadTime > 0 then
    local perkDamEffMult = forceNumber(localdata["perk" .. i .. " eff mult"])
            perksReloadTime = perksReloadTime + perkReloadTime
    local perkDamEffAdd  = forceNumber(localdata["perk" .. i .. " eff add"])
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">- ' .. formatNumber(perkReloadTime) .. ' s</div></li>'
     perksDamEff = perksDamEff + (damEffProj * perkDamEffMult) + perkDamEffAdd
        end
    else
        break
     end
end
end


local perksDamEffProj = perksDamEff / proj
local perksAttacksPerSecTotal = attacksPerSec + perksAttacksPerSec
local perksDamEffTotal = damEffTotal + perksDamEff
local perksDamEffProjTotal = damEffProj + perksDamEffProj


local perksDamExpl = 0
local perksDmgNormProj = perksDmgNorm / proj
local perksDmgNormTotal = dmgNormTotal + perksDmgNorm
local perksDmgNormProjTotal = dmgNormProj + perksDmgNormProj


for i = 1, 9 do
local perksDmgEffProj = perksDmgEff / proj
    local perkDamExplMult = forceNumber(localdata["perk" .. i .. " expl mult"])
local perksDmgEffTotal = dmgEffTotal + perksDmgEff
    local perkDamExplAdd  = forceNumber(localdata["perk" .. i .. " expl add"])
local perksDmgEffProjTotal = dmgEffProj + perksDmgEffProj
    perksDamExpl = perksDamExpl + (damExplTotal * perkDamExplMult) + perkDamExplAdd
end


local perksDamExplProj = perksDamExpl / proj
local perksDmgExplProj = perksDmgExpl / proj
local perksDamExplTotal = damExplTotal + perksDamExpl
local perksDmgExplTotal = dmgExplTotal + perksDmgExpl
local perksDamExplProjTotal = damExplTotal + perksDamExplProj
local perksDmgExplProjTotal = dmgExplTotal + perksDmgExplProj


-- Calcul du DPS
-- Dégâts par seconde
local DPS = (damNormTotal + damExplTotal) * attacksPerSec
local dps = (dmgNormTotal + dmgExplTotal) * attacksPerSec
local DPSPerks = (perksDamNormTotal + perksDamExplTotal) * perksAttacksPerSecTotal
local perksDps = (perksDmgNormTotal + perksDmgExplTotal) * perksAttacksPerSecTotal


-- Calcul du DPS en prenant en compte la durée de rechargement
-- Dégâts par seconde en prenant en compte la durée du rechargement
local DPSReload = 0
local dpsReload = 0
local DPSReloadPerks = 0
local perksDpsReload = 0


local coeff = 1
local coeff = 1
Ligne 144 : Ligne 154 :
if shotsPerReload > 0 then
if shotsPerReload > 0 then
     if attacksPerSec > 0 then
     if attacksPerSec > 0 then
         DPSReload = ((damNormTotal + damExplTotal) * shotsPerReload) /
         dpsReload = ((dmgNormTotal + dmgExplTotal) * shotsPerReload) /
             ((shotsPerReload / attacksPerSec) + reloadTime * coeff)
             ((shotsPerReload / attacksPerSec) + reloadTime * coeff)
     end
     end
      
      
     if perksAttacksPerSecTotal > 0 then
     if perksAttacksPerSecTotal > 0 then
         DPSReloadPerks = ((perksDamNormTotal + perksDamExplTotal) * shotsPerReload) /
         perksDpsReload = ((perksDmgNormTotal + perksDmgExplTotal) * shotsPerReload) /
             ((shotsPerReload / perksAttacksPerSecTotal) + perksReloadTimeTotal * coeff)
             ((shotsPerReload / perksAttacksPerSecTotal) + perksReloadTimeTotal * coeff)
     end
     end
end
end
 
-- Multiplicateur des chances de critique
local critChanceMult = forceNumber(localdata["crit % mult"])
if weaponType == 'gunautomatic' and perksAttacksPerSecTotal > 0 then
    -- Pour les armes automatiques, on divise par le nombre d'attaques par seconde
    critChanceMult = critChanceMult / perksAttacksPerSecTotal
end


--------------------------------------------------------
--------------------------------------------------------
Ligne 158 : Ligne 175 :
--------------------------------------------------------
--------------------------------------------------------


local damagePerAttackCell = formatData(damNormTotal)
local dmgPerAttackCell = formatNumber(dmgNormTotal)
if perksDamNorm > 0 then damagePerAttackCell = damagePerAttackCell .. ' (' .. formatData(perksDamNormTotal) .. ')' end
if perksDmgNorm > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgNormTotal) .. ')' end
if damExplTotal > 0 then
if dmgExplTotal > 0 then
     damagePerAttackCell = damagePerAttackCell .. ' + ' .. formatData(damExplTotal)
     dmgPerAttackCell = dmgPerAttackCell .. ' + ' .. formatNumber(dmgExplTotal)
     if perksDamExpl > 0 then damagePerAttackCell = damagePerAttackCell .. ' (' .. formatData(perksDamExplTotal) .. ')' end
     if perksDmgExpl > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgExplTotal) .. ')' end
     damagePerAttackCell = damagePerAttackCell .. ' ' .. icon.build({ 'explosion' })
     dmgPerAttackCell = dmgPerAttackCell .. ' ' .. icon.build({ 'explosion' })
end
end
if damEffTotal > 0 then
if dmgEffTotal > 0 then
     local effectDuration = localdata["effect duration"] or "1"
     local effectDuration = localdata["effect duration"] or "1"
     damagePerAttackCell = damagePerAttackCell .. ' + ' .. formatData(damEffTotal)
     dmgPerAttackCell = dmgPerAttackCell .. ' + ' .. formatNumber(dmgEffTotal)
     if perksDamEff > 0 then damagePerAttackCell = damagePerAttackCell .. ' (' .. formatData(perksDamEffTotal) .. ')' end
     if perksDmgEff > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgEffTotal) .. ')' end
     damagePerAttackCell = damagePerAttackCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
     dmgPerAttackCell = dmgPerAttackCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
end
end


local damagePerProjCell = formatData(damNormProj)
local dmgPerProjCell = formatNumber(dmgNormProj)
if perksDamNormProj > 0 then damagePerProjCell = damagePerProjCell .. ' (' .. formatData(perksDamNormProj) .. ')' end
if perksDmgNormProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgNormProj) .. ')' end
if damExplProj > 0 then
if dmgExplProj > 0 then
     damagePerProjCell = damagePerProjCell .. ' + ' .. formatData(damExplProj)
     dmgPerProjCell = dmgPerProjCell .. ' + ' .. formatNumber(dmgExplProj)
     if perksDamExplProj > 0 then damagePerProjCell = damagePerProjCell .. ' (' .. formatData(perksDamExplProjTotal) .. ')' end
     if perksDmgExplProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgExplProjTotal) .. ')' end
     damagePerProjCell = damagePerProjCell .. ' ' .. icon.build({ 'explosion' })
     dmgPerProjCell = dmgPerProjCell .. ' ' .. icon.build({ 'explosion' })
end
end


if damEffProj > 0 then
if dmgEffProj > 0 then
     local effectDuration = localdata["effect duration"] or "1"
     local effectDuration = localdata["effect duration"] or "1"
     damagePerProjCell = damagePerProjCell .. ' + ' .. formatData(damEffProj)
     dmgPerProjCell = dmgPerProjCell .. ' + ' .. formatNumber(dmgEffProj)
     if perksDamEffProj > 0 then damagePerProjCell = damagePerProjCell .. ' (' .. formatData(perksDamEffProjTotal) .. ')' end
     if perksDmgEffProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgEffProjTotal) .. ')' end
     damagePerProjCell = damagePerProjCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
     dmgPerProjCell = dmgPerProjCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
end
end


local dpsCell = formatData(DPS)
local dpsCell = formatNumber(dps)
if DPSPerks > 0 then dpsCell = dpsCell .. ' ('.. formatData(DPSPerks) .. ')' end
if perksDps > 0 then dpsCell = dpsCell .. ' ('.. formatNumber(perksDps) .. ')' end
if damEffTotal > 0 then
if dmgEffTotal > 0 then
     dpsCell = dpsCell .. ' + ' .. formatData(damEffTotal)
     dpsCell = dpsCell .. ' + ' .. formatNumber(dmgEffTotal)
     if perksDamEff > 0 then dpsCell = dpsCell .. ' (' .. perksDamEffTotal .. ')' end
     if perksDmgEff > 0 then dpsCell = dpsCell .. ' (' .. perksDmgEffTotal .. ')' end
     dpsCell = dpsCell .. ' ' .. icon.build({ 'effet' })
     dpsCell = dpsCell .. ' ' .. icon.build({ 'effet' })
end
end


local dpsReloadCell = formatData(DPSReload)
local dpsReloadCell = formatNumber(dpsReload)
if DPSReloadPerks > 0 then dpsReloadCell = dpsReloadCell .. ' ('.. formatData(DPSReloadPerks) .. ')' end
if perksDpsReload > 0 then dpsReloadCell = dpsReloadCell .. ' ('.. formatNumber(perksDpsReload) .. ')' end
if damEffTotal > 0 then
if dmgEffTotal > 0 then
     dpsReloadCell = dpsReloadCell .. ' + ' .. formatData(damEffTotal)
     dpsReloadCell = dpsReloadCell .. ' + ' .. formatNumber(dmgEffTotal)
     if perksDamEff > 0 then dpsReloadCell = dpsReloadCell .. ' (' .. formatData(perksDamEffTotal) .. ')' end
     if perksDmgEff > 0 then dpsReloadCell = dpsReloadCell .. ' (' .. formatNumber(perksDmgEffTotal) .. ')' end
     dpsReloadCell = dpsReloadCell .. ' ' .. icon.build({ 'effet' })
     dpsReloadCell = dpsReloadCell .. ' ' .. icon.build({ 'effet' })
end
end


local critMultCell = critChance
local critMultCell = 'x ' .. formatNumber(critChanceMult, "%.2f")
if critChanceModified > 0 then critMultCell = critChanceModified end
critMultCell = 'x ' .. formatData(critMultCell, "%.2f")


local attackPerSecondCell = formatData(attacksPerSec)
local attackPerSecCell = formatNumber(attacksPerSec)
if perksAttacksPerSec > 0 then attackPerSecondCell = attackPerSecondCell .. ' (' .. formatData(perksAttacksPerSecTotal) .. ')' end
if perksAttacksPerSec > 0 then attackPerSecCell = attackPerSecCell .. ' (' .. formatNumber(perksAttacksPerSecTotal) .. ')' end


local reloadTimeCell = formatData(reloadTime)
local reloadTimeCell = formatNumber(reloadTime)
if perksReloadTime > 0 then reloadTimeCell = reloadTimeCell .. ' (' .. formatData(perksReloadTimeTotal) .. ')' end
if perksReloadTime > 0 then reloadTimeCell = reloadTimeCell .. ' (' .. formatNumber(perksReloadTimeTotal) .. ')' end
 
-- Effets des aptitudes
if #perksAttacksPerSecItems > 0 then
    perksAttacksPerSecItems = '<ul class="avt-simple-list">' .. perksAttacksPerSecItems .. '</ul>'
else
    perksAttacksPerSecItems = nil
end
if #perksDmgItems > 0 then
    perksDmgItems = '<ul class="avt-simple-list">' .. perksDmgItems .. '</ul>'
else
    perksDmgItems = nil
end
if #perksReloadTimeItems > 0 then
    perksReloadTimeItems = '<ul class="avt-simple-list">' .. perksReloadTimeItems .. '</ul>'
else
    perksReloadTimeItems = nil
end


--------------------------------------------------------
--------------------------------------------------------
Ligne 221 : Ligne 253 :
{ type = 'title', value = 'nom', subtitle = 'sous-titre', icon = 'icône', subhead = { games = 'jeux', subject = 'Arme', link = 'Armes' }},
{ type = 'title', value = 'nom', subtitle = 'sous-titre', icon = 'icône', subhead = { games = 'jeux', subject = 'Arme', link = 'Armes' }},
{ type = 'images', imageparameters = { 'image', 'image2', 'image3', 'image4', 'image5' }, captionparameter = { 'légende', 'image desc' }},
{ type = 'images', imageparameters = { 'image', 'image2', 'image3', 'image4', 'image5' }, captionparameter = { 'légende', 'image desc' }},
{ type = 'table', title = 'Conditions d\'utilisation', rows = {
{ type = 'row', label = 'Compétence', value = 'skill' },
{ type = 'row', label = 'Force', value = 'strength req' }
}},
{ type = 'table', title = 'Statistiques de combat', collapseparameters = { collapsible = true, collapsed = true }, rows = {
{ type = 'table', title = 'Statistiques de combat', collapseparameters = { collapsible = true, collapsed = true }, rows = {
        { type = 'row', label = 'Dégâts par attaque', value = function() return damagePerAttackCell end },
        { type = 'row', label = 'Dégâts par attaque', value = function() return dmgPerAttackCell end },
        { type = 'row', label = 'Dégâts par projectile', value = function() return damagePerProjCell end },
        { type = 'row', label = 'Dégâts par projectile', value = function() return dmgPerProjCell end },
        { type = 'row', label = 'Dégâts par seconde', value = function() return dpsCell end },
        { type = 'row', label = 'Dégâts par seconde', value = function() return dpsCell end },
        { type = 'row', label = 'Dégâts par seconde (avec rechargement)', value = function() return dpsReloadCell end },
        { type = 'row', label = 'Dégâts par seconde (avec rechargement)', value = function() return dpsReloadCell end },
        { type = 'row', label = 'Dégâts critiques', value = 'crit dmg' },
        { type = 'row', label = 'Dégâts critiques', value = 'crit dmg' },
        { type = 'row', label = 'Multiplicateur de critique', value = function() return critMultCell end },
        { type = 'row', label = 'Multiplicateur de critique', value = function() return critMultCell end },
        { type = 'row', label = 'Attaques par seconde', value = function() return attackPerSecondCell end },
        { type = 'row', label = 'Attaques par seconde', value = function() return attackPerSecCell end },
        { type = 'row', label = 'Points d\'action', value = 'ap' },
        { type = 'row', label = 'Points d\'action', value = 'ap' },
        { type = 'row', label = 'Projectiles', value = 'projectiles' },
        { type = 'row', label = 'Projectiles', value = 'projectiles' },
Ligne 238 : Ligne 274 :
        { type = 'row', label = 'Type de munitions', value = 'ammo' },
        { type = 'row', label = 'Type de munitions', value = 'ammo' },
        { type = 'row', label = 'Projectiles par tir', value = 'ammo use' },
        { type = 'row', label = 'Projectiles par tir', value = 'ammo use' },
        { type = 'row', label = 'Tirs par magasin', function() return formatData(shotsPerReload) end },
        { type = 'row', label = 'Tirs par magasin', function() return formatNumber(shotsPerReload) end },
        { type = 'row', label = 'Capacité', value = 'clip rounds' },
        { type = 'row', label = 'Capacité', value = 'clip rounds' },
        { type = 'row', label = 'Durée de rechargement', value = function() return reloadTimeCell end }
        { type = 'row', label = 'Durée de rechargement', value = function() return reloadTimeCell end }
    }},
    }},
{ type = 'table', title = 'Effets des aptitudes', rows = {
{ type = 'table', title = 'Effets des aptitudes', rows = {
-- TODO
{ type = 'row', label = 'Dégâts', value = function() return perksDmgItems end },
{ type = 'row', label = 'Attaques par seconde', value = function() return perksAttacksPerSecItems end },
{ type = 'row', label = 'Rechargement', value = function() return perksReloadTimeItems end }
}},
}},
{ type = 'table', title = 'Autres propriétés', rows = {
{ type = 'table', title = 'Autres propriétés', rows = {

Version du 31 juillet 2021 à 00:50

Documentation du module

Ce module contient le paramétrage de l'infobox {{Infobox arme gamebryo}}.

Documentation transclues de Module:Infobox/Arme gamebryo/doc.
local localdata = require( 'Module:Infobox/Localdata' )
local icon = require( 'Module:Icône' )

--------------------------------------------------------
-----             Fonctions communes               -----
--------------------------------------------------------

-- Récupère un paramètre au format number
-- Force à 0 si nil ou s'il n'est pas un nombre
function forceNumber(data)
	return tonumber(data) or 0
end

-- Formatage du nombre pour l'affichage
function formatNumber(data, round)
	return string.format(round or "%.1f", data)
end

--------------------------------------------------------
-----              Calcul des dégâts               -----
--------------------------------------------------------

-- Type d'arme
local weaponCompletType = (localdata['type'] or ''):lower()
local weaponType = weaponCompletType:gsub(' unique', '')
local isUnique = weaponCompletType:find(' unique') ~= nil

-- Nombre d'attaques par seconde
local attacksPerSec = forceNumber(localdata["attack shots/sec"])

-- Durée du rechargement
local reloadTime = 0
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
    reloadTime = forceNumber(localdata["reload time"])
end

-- Nombre de projectiles par attaque
local proj = 1
if weaponType == "gun" or weaponType == "gunautomatic" or weaponType == "gunhandload" then
    proj = forceNumber(localdata["projectiles"])
    if proj == 0 then proj = 1 end -- on force à 1 si projectile non renseigné
end

-- Taille du magasin
local clipRounds = forceNumber(localdata["clip rounds"]) 

-- Nombre de cartouches par attaque
local ammoUse = forceNumber(localdata["ammo use"]) 

-- Nombre d'attaques par rechargement
local attacksPerReload = 0
if ammoUse > 0 then
    attacksPerReload = math.floor(clipRounds / ammoUse)
end

-- Dégâts par type : balistique, explosif, effet

local dmgNormTotal = forceNumber(localdata["damage"])
local dmgNormProj = dmgNormTotal / proj

local dmgEffProj = forceNumber(localdata["effect damage"])
local dmgEffTotal = dmgEffProj * proj

local dmgExplProj = forceNumber(localdata["explosion damage"])
local dmgExplTotal = dmgExplProj * proj

-- Effets des aptitudes sur les dégâts
local perksAttacksPerSec = 0
local perksDmgNorm = 0
local perksDmgEff = 0
local perksDmgExpl = 0
local perksReloadTime = 0

local perksAttacksPerSecItems = ''
local perksDmgItems = ''
local perksReloadTimeItems = ''

for i = 1, 9 do
    local perk = localdata["perk" .. i]

    if perk then
        -- Calcul de chaque donnée
        local perkAttacksPerSec = attacksPerSec * forceNumber(localdata["perk" .. i .. " attsec mult"])
        local perkDmgNorm = (dmgNormTotal * forceNumber(localdata["perk" .. i .. " mult"])) + forceNumber(localdata["perk" .. i .. " add"])
        local perkDmgEff = (dmgEffTotal * forceNumber(localdata["perk" .. i .. " eff mult"])) + forceNumber(localdata["perk" .. i .. " eff add"])
        local perkDmgExpl = (dmgExplTotal * forceNumber(localdata["perk" .. i .. " expl mult"])) + forceNumber(localdata["perk" .. i .. " expl add"])
        local perkReloadTime = reloadTime * forceNumber(localdata["perk" .. i .. " reload mult"])

        -- Somme des effets et gestion
        -- de l'affichage de la table Effets des aptitudes

        if perkAttacksPerSec > 0 then
            perksAttacksPerSec = perksAttacksPerSec + perkAttacksPerSec
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">+ ' .. formatNumber(perkAttacksPerSec) .. '</div></li>'
        end

        if perkDmgNorm > 0 or perkDmgEff > 0 or perkDmgExpl > 0 then
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">'

            if perkDmgNorm > 0 then
                perksDmgNorm = perksDmgNorm + perkDmgNorm
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgNorm)
            end

            if perkDmgExpl > 0 then
                perksDmgExpl = perksDmgExpl + perkDmgExpl
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgExpl) .. ' ' .. icon.build( 'explosion' )
            end

            if perkDmgEff > 0 then
                perksDmgEff = perksDmgEff + perkDmgEff
                perksAttacksPerSecItems = perksAttacksPerSecItems .. ' + ' .. formatNumber(perkDmgEff) .. ' ' .. icon.build( 'effect' )
            end

            perksDmgItems = perksDmgItems .. '</div></li>'
        end

        if perkReloadTime > 0 then
            perksReloadTime = perksReloadTime + perkReloadTime
            perksAttacksPerSecItems = perksAttacksPerSecItems .. '<li>' .. perk .. '<div style="float:right;">- ' .. formatNumber(perkReloadTime) .. ' s</div></li>'
        end
    else
        break
    end
end

local perksAttacksPerSecTotal = attacksPerSec + perksAttacksPerSec

local perksDmgNormProj = perksDmgNorm / proj
local perksDmgNormTotal = dmgNormTotal + perksDmgNorm
local perksDmgNormProjTotal = dmgNormProj + perksDmgNormProj

local perksDmgEffProj = perksDmgEff / proj
local perksDmgEffTotal = dmgEffTotal + perksDmgEff
local perksDmgEffProjTotal = dmgEffProj + perksDmgEffProj

local perksDmgExplProj = perksDmgExpl / proj
local perksDmgExplTotal = dmgExplTotal + perksDmgExpl
local perksDmgExplProjTotal = dmgExplTotal + perksDmgExplProj

-- Dégâts par seconde
local dps = (dmgNormTotal + dmgExplTotal) * attacksPerSec
local perksDps = (perksDmgNormTotal + perksDmgExplTotal) * perksAttacksPerSecTotal

-- Dégâts par seconde en prenant en compte la durée du rechargement
local dpsReload = 0
local perksDpsReload = 0

local coeff = 1
if weaponType == "gunhandload" then
    coeff = shotsPerReload
end

if shotsPerReload > 0 then
    if attacksPerSec > 0 then
        dpsReload = ((dmgNormTotal + dmgExplTotal) * shotsPerReload) /
            ((shotsPerReload / attacksPerSec) + reloadTime * coeff)
    end
    
    if perksAttacksPerSecTotal > 0 then
        perksDpsReload = ((perksDmgNormTotal + perksDmgExplTotal) * shotsPerReload) /
            ((shotsPerReload / perksAttacksPerSecTotal) + perksReloadTimeTotal * coeff)
    end
end

-- Multiplicateur des chances de critique
local critChanceMult = forceNumber(localdata["crit % mult"])
if weaponType == 'gunautomatic' and perksAttacksPerSecTotal > 0 then
    -- Pour les armes automatiques, on divise par le nombre d'attaques par seconde
    critChanceMult = critChanceMult / perksAttacksPerSecTotal
end

--------------------------------------------------------
-----            Formatage des données             -----
--------------------------------------------------------

local dmgPerAttackCell = formatNumber(dmgNormTotal)
if perksDmgNorm > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgNormTotal) .. ')' end
if dmgExplTotal > 0 then
    dmgPerAttackCell = dmgPerAttackCell .. ' + ' .. formatNumber(dmgExplTotal)
    if perksDmgExpl > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgExplTotal) .. ')' end
    dmgPerAttackCell = dmgPerAttackCell .. ' ' .. icon.build({ 'explosion' })
end
if dmgEffTotal > 0 then
    local effectDuration = localdata["effect duration"] or "1"
    dmgPerAttackCell = dmgPerAttackCell .. ' + ' .. formatNumber(dmgEffTotal)
    if perksDmgEff > 0 then dmgPerAttackCell = dmgPerAttackCell .. ' (' .. formatNumber(perksDmgEffTotal) .. ')' end
    dmgPerAttackCell = dmgPerAttackCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
end

local dmgPerProjCell = formatNumber(dmgNormProj)
if perksDmgNormProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgNormProj) .. ')' end
if dmgExplProj > 0 then
    dmgPerProjCell = dmgPerProjCell .. ' + ' .. formatNumber(dmgExplProj)
    if perksDmgExplProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgExplProjTotal) .. ')' end
    dmgPerProjCell = dmgPerProjCell .. ' ' .. icon.build({ 'explosion' })
end

if dmgEffProj > 0 then
    local effectDuration = localdata["effect duration"] or "1"
    dmgPerProjCell = dmgPerProjCell .. ' + ' .. formatNumber(dmgEffProj)
    if perksDmgEffProj > 0 then dmgPerProjCell = dmgPerProjCell .. ' (' .. formatNumber(perksDmgEffProjTotal) .. ')' end
    dmgPerProjCell = dmgPerProjCell .. ' sur ' .. effectDuration .. ' s ' .. icon.build({ 'effet' })
end

local dpsCell = formatNumber(dps)
if perksDps > 0 then dpsCell = dpsCell .. ' ('.. formatNumber(perksDps) .. ')' end
if dmgEffTotal > 0 then
    dpsCell = dpsCell .. ' + ' .. formatNumber(dmgEffTotal)
    if perksDmgEff > 0 then dpsCell = dpsCell .. ' (' .. perksDmgEffTotal .. ')' end
    dpsCell = dpsCell .. ' ' .. icon.build({ 'effet' })
end

local dpsReloadCell = formatNumber(dpsReload)
if perksDpsReload > 0 then dpsReloadCell = dpsReloadCell .. ' ('.. formatNumber(perksDpsReload) .. ')' end
if dmgEffTotal > 0 then
    dpsReloadCell = dpsReloadCell .. ' + ' .. formatNumber(dmgEffTotal)
    if perksDmgEff > 0 then dpsReloadCell = dpsReloadCell .. ' (' .. formatNumber(perksDmgEffTotal) .. ')' end
    dpsReloadCell = dpsReloadCell .. ' ' .. icon.build({ 'effet' })
end

local critMultCell = 'x ' .. formatNumber(critChanceMult, "%.2f")

local attackPerSecCell = formatNumber(attacksPerSec)
if perksAttacksPerSec > 0 then attackPerSecCell = attackPerSecCell .. ' (' .. formatNumber(perksAttacksPerSecTotal) .. ')' end

local reloadTimeCell = formatNumber(reloadTime)
if perksReloadTime > 0 then reloadTimeCell = reloadTimeCell .. ' (' .. formatNumber(perksReloadTimeTotal) .. ')' end

-- Effets des aptitudes
if #perksAttacksPerSecItems > 0 then
    perksAttacksPerSecItems = '<ul class="avt-simple-list">' .. perksAttacksPerSecItems .. '</ul>'
else
    perksAttacksPerSecItems = nil
end
if #perksDmgItems > 0 then
    perksDmgItems = '<ul class="avt-simple-list">' .. perksDmgItems .. '</ul>'
else
    perksDmgItems = nil
end
if #perksReloadTimeItems > 0 then
    perksReloadTimeItems = '<ul class="avt-simple-list">' .. perksReloadTimeItems .. '</ul>'
else
    perksReloadTimeItems = nil
end

--------------------------------------------------------
-----          Construction de l'infobox           -----
--------------------------------------------------------

return {
	parts = {
		{ type = 'title', value = 'nom', subtitle = 'sous-titre', icon = 'icône', subhead = { games = 'jeux', subject = 'Arme', link = 'Armes' }},
		{ type = 'images', imageparameters = { 'image', 'image2', 'image3', 'image4', 'image5' }, captionparameter = { 'légende', 'image desc' }},
		{ type = 'table', title = 'Conditions d\'utilisation', rows = {
			{ type = 'row', label = 'Compétence', value = 'skill' },
			{ type = 'row', label = 'Force', value = 'strength req' }
		}},
		{ type = 'table', title = 'Statistiques de combat', collapseparameters = { collapsible = true, collapsed = true }, rows = {
	        { type = 'row', label = 'Dégâts par attaque', value = function() return dmgPerAttackCell end },
	        { type = 'row', label = 'Dégâts par projectile', value = function() return dmgPerProjCell end },
	        { type = 'row', label = 'Dégâts par seconde', value = function() return dpsCell end },
	        { type = 'row', label = 'Dégâts par seconde (avec rechargement)', value = function() return dpsReloadCell end },
	        { type = 'row', label = 'Dégâts critiques', value = 'crit dmg' },
	        { type = 'row', label = 'Multiplicateur de critique', value = function() return critMultCell end },
	        { type = 'row', label = 'Attaques par seconde', value = function() return attackPerSecCell end },
	        { type = 'row', label = 'Points d\'action', value = 'ap' },
	        { type = 'row', label = 'Projectiles', value = 'projectiles' },
	        { type = 'row', label = 'Dispersion', value = 'min spread' },
	        { type = 'row', label = 'Effet', value = 'other effect' },
	        { type = 'row', label = 'Effet critique', value = 'crit effect' }
	    }},
	    { type = 'table', title = 'Munitions et rechargement', collapseparameters = { collapsible = true, collapsed = true }, rows = {
	        { type = 'row', label = 'Type de munitions', value = 'ammo' },
	        { type = 'row', label = 'Projectiles par tir', value = 'ammo use' },
	        { type = 'row', label = 'Tirs par magasin', function() return formatNumber(shotsPerReload) end },
	        { type = 'row', label = 'Capacité', value = 'clip rounds' },
	        { type = 'row', label = 'Durée de rechargement', value = function() return reloadTimeCell end }
	    }},
		{ type = 'table', title = 'Effets des aptitudes', rows = {
			{ type = 'row', label = 'Dégâts', value = function() return perksDmgItems end },
			{ type = 'row', label = 'Attaques par seconde', value = function() return perksAttacksPerSecItems end },
			{ type = 'row', label = 'Rechargement', value = function() return perksReloadTimeItems end }
		}},
		{ type = 'table', title = 'Autres propriétés', rows = {
			{ type = 'row', label = 'Poids', value = 'poids' },
			{ type = 'row', label = 'Valeur', value = 'valeur' },
			{ type = 'row', label = 'Points de vie', 'hp' },
			{ type = 'row', label = 'Réparation', value = 'repair' },
			{ type = 'row', label = 'Quêtes', value = 'quêtes' }
		}},
		{ type = 'table', title = 'Technique', collapseparameters = { collapsible = true, collapsed = true }, rows = {
			{ type = 'row', label = '[[Form ID|Base ID]]', value = 'baseid' },
			{ type = 'row', label = 'Editor ID', value = 'editorid' }
		}},
		{ type = 'text', value = 'pied' }
	}
}