Differenze tra le versioni di "Modulo:EffTipi"

1 616 byte aggiunti ,  01:50, 9 set 2013
nessun oggetto della modifica
m
-- Calcolo efficacia tipi, ad uso esclusivamente interno
 
local et = {}
 
-- esterno: attaccante, interno: difensore
local b = require("Module:Boxtipo")
-- tutti i -1 sono placeholder per i folletti (solo informazioni certe)
local w = require("Module:Wikilib")
local t = mw.loadData('Modulo:Poké/data')
local c = mw.loadData('Modulo:Colore/data')
 
local eff = {}
-- TODO: gestione dell'abbreviazione "coleot" senza scassare gli indici
local nomieff.normale = {["Normale"]normale = 1, ["Fuoco"]fuoco = 21, ["Acqua"]acqua = 31, ["Elettro"]elettro = 41, ["Erba"]erba = 51, ["Ghiaccio"]ghiaccio = 61, lotta = 1, veleno = 1, terra = 1,
["Lotta"] volante = 71, ["Veleno"]psico = 81, ["Terra"]coleottero = 91, ["Volante"]roccia = 100.5, ["Psico"]spettro = 110, ["Coleottero"]drago = 121, buio = 1, acciaio = 0.5, folletto = -1}
eff.fuoco = {normale = 1, fuoco = 0.5, acqua = 0.5, elettro = 1, erba = 2, ghiaccio = 2, lotta = 1, veleno = 1, terra = 1,
["Roccia"] = 13, ["Spettro"] = 14, ["Drago"] = 15, ["Buio"] = 16, ["Acciaio"] = 17, ["Folletto"] = 18}
volante = 1, psico = 1, coleottero = 2, roccia = 0.5, spettro = 1, drago = 0.5, buio = 1, acciaio = 2, folletto = -1}
eff.acqua = {normale = 1, fuoco = 2, acqua = 0.5, elettro = 1, erba = 0.5, ghiaccio = 1, lotta = 1, veleno = 1, terra = 2,
volante = 1, psico = 1, coleottero = 1, roccia = 2, spettro = 1, drago = 0.5, buio = 1, acciaio = 1, folletto = -1}
eff.elettro = {normale = 1, fuoco = 1, acqua = 2, elettro = 0.5, erba = 0.5, ghiaccio = 1, lotta = 1, veleno = 1, terra = 0,
volante = 1, psico = 1, coleottero = 1, roccia = 1, spettro = 1, drago = 0.5, buio = 1, acciaio = 1, folletto = -1}
eff.erba = {normale = 1, fuoco = 0.5, acqua = 2, elettro = 1, erba = 0.5, ghiaccio = 1, lotta = 1, veleno = 0.5, terra = 2,
volante = 0.5, psico = 1, coleottero = 0.5, roccia = 2, spettro = 1, drago = 0.5, buio = 1, acciaio = 0.5, folletto = -1}
eff.ghiaccio = {normale = 1, fuoco = 0.5, acqua = 0.5, elettro = 1, erba = 2, ghiaccio = 0.5, lotta = 1, veleno = 1, terra = 2,
volante = 2, psico = 1, coleottero = 1, roccia = 1, spettro = 1, drago = 2, buio = 1, acciaio = 0.5, folletto = -1}
eff.lotta = {normale = 2, fuoco = 1, acqua = 1, elettro = 1, erba = 1, ghiaccio = 2, lotta = 1, veleno = 0.5, terra = 1,
volante = 0.5, psico = 0.5, coleottero = 0.5, roccia = 2, spettro = 0, drago = 1, buio = 2, acciaio = 2, folletto = -1}
eff.veleno = {normale = 1, fuoco = 1, acqua = 1, elettro = 1, erba = 2, ghiaccio = 1, lotta = 1, veleno = 0.5, terra = 0.5,
volante = 1, psico = 1, coleottero = 1, roccia = 0.5, spettro = 0.5, drago = 1, buio = 1, acciaio = 0, folletto = -1}
eff.terra = {normale = 1, fuoco = 2, acqua = 1, elettro = 2, erba = 0.5, ghiaccio = 1, lotta = 1, veleno = 2, terra = 1,
volante = 0, psico = 1, coleottero = 0.5, roccia = 2, spettro = 1, drago = 1, buio = 1, acciaio = 2, folletto = -1}
eff.volante = {normale = 1, fuoco = 1, acqua = 1, elettro = 0.5, erba = 2, ghiaccio = 1, lotta = 2, veleno = 1, terra = 1,
volante = 1, psico = 1, coleottero = 2, roccia = 0.5, spettro = 1, drago = 1, buio = 1, acciaio = 0.5, folletto = -1}
eff.psico = {normale = 1, fuoco = 1, acqua = 1, elettro = 1, erba = 1, ghiaccio = 1, lotta = 2, veleno = 2, terra = 1,
volante = 1, psico = 0.5, coleottero = 1, roccia = 1, spettro = 1, drago = 1, buio = 0, acciaio = 0.5, folletto = -1}
eff.coleottero = {normale = 1, fuoco = 0.5, acqua = 1, elettro = 1, erba = 2, ghiaccio = 1, lotta = 0.5, veleno = 0.5, terra = 1,
volante = 0.5, psico = 2, coleottero = 1, roccia = 1, spettro = 0.5, drago = 1, buio = 2, acciaio = 0.5, folletto = -1}
eff.roccia = {normale = 1, fuoco = 2, acqua = 1, elettro = 1, erba = 1, ghiaccio = 2, lotta = 0.5, veleno = 1, terra = 0.5,
volante = 2, psico = 1, coleottero = 2, roccia = 1, spettro = 1, drago = 1, buio = 1, acciaio = 0.5, folletto = -1}
eff.spettro = {normale = 0, fuoco = 1, acqua = 1, elettro = 1, erba = 1, ghiaccio = 1, lotta = 1, veleno = 1, terra = 1,
volante = 1, psico = 2, coleottero = 1, roccia = 1, spettro = 2, drago = 1, buio = 0.5, acciaio = 0.5, folletto = -1}
eff.drago = {normale = 1, fuoco = 1, acqua = 1, elettro = 1, erba = 1, ghiaccio = 1, lotta = 1, veleno = 1, terra = 1,
volante = 1, psico = 1, coleottero = 1, roccia = 1, spettro = 1, drago = 2, buio = 1, acciaio = 0.5, folletto = -1}
eff.buio = {normale = 1, fuoco = 1, acqua = 1, elettro = 1, erba = 1, ghiaccio = 1, lotta = 0.5, veleno = 1, terra = 1,
volante = 1, psico = 2, coleottero = 1, roccia = 1, spettro = 2, drago = 1, buio = 0.5, acciaio = 0.5, folletto = -1}
eff.acciaio = {normale = 1, fuoco = 0.5, acqua = 0.5, elettro = 0.5, erba = 1, ghiaccio = 2, lotta = 1, veleno = 1, terra = 1,
volante = 1, psico = 1, coleottero = 1, roccia = 2, spettro = 1, drago = 1, buio = 1, acciaio = 0.5, folletto = -1}
eff.folletto = {normale = -1, fuoco = -1, acqua = -1, elettro = -1, erba = -1, ghiaccio = -1, lotta = -1, veleno = -1, terra = -1,
volante = -1, psico = -1, coleottero = -1, roccia = -1, spettro = -1, drago = 2, buio = -1, acciaio = -1, folletto = -1}
eff.coleot = eff.coleottero
for a in pairs(eff) do
eff[a].coleot = eff[a].coleot
end
 
-- Calcola l'efficacia di un attacco (0 - 0.25 - 0.5 - 1 - 2 - 4)
-- riga: attaccante, colonna: difensore
-- si aspetta i nomi dei tipi, tutti in minuscolo
-- tutti i -1 sono placeholder per i folletti (solo informazioni certe)
local eff = {{1,1,1,1,1,1,1,1,1,1,1,1,0.5,0,1,1,0.5,-1},
{1,0.5,0.5,1,2,2,1,1,1,1,1,2,0.5,1,0.5,1,2,-1},
{1,2,0.5,1,0.5,1,1,1,2,1,1,1,2,1,0.5,1,1,-1},
{1,1,2,0.5,1,1,1,0,2,1,1,1,1,1,0.5,1,1,-1},
{1,0.5,2,1,0.5,1,1,0.5,2,0.5,1,0.5,2,1,0.5,1,0.5,-1},
{1,0.5,0.5,1,2,0.5,1,1,2,2,1,1,1,1,2,1,0.5,-1},
{2,1,1,1,1,2,1,0.5,1,0.5,0.5,0.5,2,0,1,2,2,-1},
{1,1,1,1,2,1,1,0.5,0.5,1,1,1,0.5,0.5,1,1,0,-1},
{1,2,1,2,0.5,1,1,2,1,0,1,0.5,2,1,1,1,2,-1},
{1,1,1,0.5,2,1,2,1,1,1,1,2,0.5,1,1,1,0.5,-1},
{1,1,1,1,1,1,2,2,1,1,0.5,1,1,1,1,0,0.5,-1},
{1,0.5,1,1,2,1,0.5,0.5,1,0.5,2,1,1,0.5,1,2,0.5,-1},
{1,2,1,1,1,2,0.5,1,0.5,2,1,2,1,1,1,1,0.5,-1},
{0,1,1,1,1,1,1,1,1,1,2,1,1,2,1,0.5,0.5,-1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,0.5,-1},
{1,1,1,1,1,1,0.5,1,1,1,2,1,1,2,1,0.5,0.5,-1},
{1,0.5,0.5,0.5,1,2,1,1,1,1,1,1,2,1,1,1,0.5,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,-1,-1,-1}}
 
et.efficacia = function(a, d1, d2)
-- Calcola l'efficacia di un attacco (0 - 0.25 - 0.5 - 1 - 2 - 4)
local e = eff[a][d1]
-- si aspetta i nomi dei tipi, per ora tutti in minuscolo
if d2 ~= d1 then
local function attacca(attaccante, difensore1, difensore2)
e = e * eff[a][d2]
local a = first_uppercase(trim(attaccante))
local d1 = first_uppercase(trim(difensore1))
if (a=="Sconosciuto" or d1=="Sconosciuto") then return -1 end
local e = eff[nomi[a]][nomi[d1]]
if (difensore2) then
local d2 = first_uppercase(trim(difensore2))
if (not (d2=="Sconosciuto" or d2==d1)) then
e = e * eff[nomi[attaccante]][nomi[d2]]
end
end
return e
end
 
-- cerca tutti i tipi che soddisfano una condizione data
et.attacca = function(frame)
return attacca(frame.args[1],frame.args[2],frame.args[3])
end
 
local cerca_tipi = function(test)
-- cerca tutti i tipi che soddisfano una condizione data
local function cerca_tipi(test)
local t = {}
for k,v in pairs(nomieff) do
if (test(k)) then
table.insert(t,k)
 
-- trova tutti i tipi che attaccando tipo1,tipo2 hanno efficacia eff
local function attaccanti_con_eff(eff,tipo1,tipo2)
return cerca_tipi(function (x) return attacca(x,tipo1,tipo2)==tonumber(eff) end)
end
 
et.attaccanti_con_effdifesa = function(frameeff,tipo1,tipo2)
return cerca_tipi(function (x) return efficacia(x, tipo1, tipo2) == eff end)
return attaccanti_con_eff(frame.args[1],frame.args[2],frame.args[3])
end
 
-- trova tutti i tipi su cui tipo ha efficacia eff
local function attaccati_con_eff(tipo,eff)
return cerca_tipi(function (x) return attacca(tipo,x)==tonumber(eff) end)
end
 
et.attaccati_con_eff = function(frame)
return attaccati_con_eff(frame.args[1],frame.args[2])
end
 
et.box_attaccati = function(frame)
return b.box_lista(et.attaccati_con_eff(frame),frame.args[4])
end
 
et.box_attaccanti = function(frame)
return b.box_lista(et.attaccanti_con_eff(frame),frame.args[4])
end
 
et.tabattacco = function(frametipo,eff)
return cerca_tipi(function (x) return efficacia(tipo, x, x) == eff end)
local name = w.trim(frame.args[1]):lower() or 'Missingno.'
local tipo1 = t.pokedata
return w.interp([=[{| class="roundy" style="margin: auto; text-align: center; border: 3px solid #${bd}; background: #${bg}; width: 80%"
|-
| style="padding:0;" |
{| class="roundy" style="width: 100%; background: #${cells};"
|-
! class="roundyleft" style="width: 30%" | Debolezze
| style="padding:0;" |]=],
{
bd = "{{colore {{{tipo2|{{{tipo1|sconosciuto}}} dark}}}}}",
bg = "{{colore {{{tipo1|sconosciuto}}}}}",
cells = "{{colore {{{tipo1|sconosciuto}}} light}}"
})
end