FANDOM


local p = {}
 
local formatNum = require( 'Module:FormatNum' ).formatNum
 
-- Add a record here in the order you wish the troops to appear
p.troops = {
   'barbarian',
   'pumpkinbarbarian',
   'archer',
   'giant',
   'battleram',
   'giantskeleton',
   'goblin',
   'wallbreaker',
   'balloon',
   'wizard',
   'icewizard',
   'healer',
   'dragon',
   'pekka',
   'babydragon',
   'miner',
   'electrodragon',
   'yeti',
   'minion',
   'hogrider',
   'valkyrie',
   'golem',
   'witch',
   'lavahound',
   'bowler',
   'icegolem'
}
 
p.troopData = {
   ['barbarian'] = {
      ['name']          = 'Barbarian',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6,       7,   8 },
      ['hitpoints']     = { 45,    54,     65,     78,      95,     110,     145,   205 },
      ['dps']           = {  8,    11,     14,     18,      23,      26,      30,   34 },
      ['training cost'] = { 25,    40,     60,    100,     150,     200,     250,   300 },
      ['research cost'] = {  0, 50000, 150000, 500000, 1500000, 4500000, 6000000,   8000000 },
      },
    ['pumpkinbarbarian'] = {
      ['name']          = 'Pumpkin Barbarian',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      1,      1,       1,       1,       1 },
      ['hitpoints']     = { 60,    72,     87,     104,      127,     146,     167 },
      ['dps']           = {  8,    11,     14,     18,      23,      26,      30 },
      ['training cost'] = { 25,    40,     60,    100,     150,     200,     250 },
      ['research cost'] = {  0,     0,  0,  0,  0,  0,  0 },
      },
   ['archer'] = {
      ['name']          = 'Archer',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6,       7,   8 },
      ['hitpoints']     = { 20,    23,     28,     33,      40,      44,      48,   52 },
      ['dps']           = {  7,     9,     12,     16,      20,      22,      25,   28 },
      ['training cost'] = { 50,    80,    120,    200,     300,     400,     500,   600 },
      ['research cost'] = {  0, 50000, 250000, 750000, 2250000, 6000000, 7500000,   9000000 },
   },
   ['giant'] = {
      ['name']          = 'Giant',
      ['resource']      = 'Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {   1,      1,      3,      3,       5,       6,       7,       8,    9 },
      ['hitpoints']     = { 300,    360,    430,    520,     670,     940,    1280,    1500,    1850 },
      ['dps']           = {  11,     14,     19,     24,      31,      43,      50,      57,    64 },
      ['training cost'] = { 250,    750,   1250,   1750,    2250,    3000,    3500,    4000,    4500 },
      ['research cost'] = {   0, 100000, 250000, 750000, 2250000, 5000000, 6000000, 9500000,    12000000 },
      },
    ['battleram'] = {
      ['name']          = 'Battle Ram',
      ['resource']      = 'Elixir',
      ['housing space'] = 4,
      ['imagenum']      = {1,1,1,1,1,1,1,1,1,1,1},
      ['hitpoints']     = {90,111,132,153,174,195,216,237,258,279,300},
      ['dps']           = {115,142,168,195,222,249,276,303,330,357,384},
      ['training cost'] = {250,250,250,250,250,250,250,250,250,250,250},
      ['research cost'] = {0,0,0,0,0,0,0,0,0,0,0},
   },
   ['giantskeleton'] = {
      ['name']          = 'Giant Skeleton',
      ['resource']      = 'Elixir',
      ['housing space'] = 25,
      ['imagenum']      = {   1,      1,      1,      1,       1,       1,       1,       1 },
      ['hitpoints']     = { 750,    900,    1075,    1300,     1675,     2350,    2750,    3150 },
      ['dps']           = {  11,     14,     19,     24,      31,      43,      50,      57 },
      ['training cost'] = { 250,    750,   1250,   1750,    2250,    3000,    3500,    4000 },
      ['research cost'] = {   0, 0, 0,  0,  0,  0,  0,  0},
      },
   ['goblin'] = {
      ['name']          = 'Goblin',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6,        7 },
      ['hitpoints']     = { 25,    30,     36,     46,      56,      76,       101 },
      ['dps']           = { 11,    14,     19,     24,      32,      42,       52 },
      ['training cost'] = { 25,    40,     60,     80,     100,     150,      200 },
      ['research cost'] = {  0, 50000, 250000, 750000, 2250000, 4500000,  6750000 },
   },
   ['wallbreaker'] = {
      ['name']          = 'Wall Breaker',
      ['resource']      = 'Elixir',
      ['housing space'] = 2,
      ['imagenum']      = {    1,      1,      3,      3,       5,       6,     7,  7,  9 },
      ['hitpoints']     = {   20,     24,     29,     35,      53,      72,     82, 92, 112 },
      ['dps']           = {   12,     16,     24,     32,      46,      60,     78, 100,    120 },
      ['training cost'] = { 600,   800,   1000,   1200,    1400,    1600,     1800, 2000,   2200 },
      ['research cost'] = {    0, 100000, 250000, 750000, 2000000, 6000000,     9000000,    12000000, 14000000 },
   },
   ['balloon'] = {
      ['name']          = 'Balloon',
      ['resource']      = 'Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {    1,      1,      3,       3,       5,       6,       7,   8,  9 },
      ['hitpoints']     = {  150,    180,    216,     280,     390,     545,     690,   840,    940 },
      ['dps']           = {   25,     32,     48,      72,     108,     162,     198,   236,    256 },
      ['training cost'] = { 1750,   2250,   2750,    3500,    4000,    4500,    5000,   5500,   6000 },
      ['research cost'] = {    0, 150000, 450000, 1350000, 2500000, 6000000, 9500000,   12000000, 14000000 },
   },
   ['wizard'] = {
      ['name']          = 'Wizard',
      ['resource']      = 'Elixir',
      ['housing space'] = 4,
      ['imagenum']      = {    1,      1,      3,       3,       5,       6,       7,       8,  9 },
      ['hitpoints']     = {   75,     90,    108,     130,     156,     175,     190,        210, 230 },
      ['dps']           = {   50,     70,     90,     125,     170,     185,     200,        215, 230 },
      ['training cost'] = { 1000,   1400,   1800,    2200,    2600,    3000,    3400,        3800, 4200 },
      ['research cost'] = {    0, 150000, 450000, 1350000, 2500000, 5000000, 7000000,        9000000,  11000000 },
   },
   ['icewizard'] = {
      ['name']          = 'Ice Wizard',
      ['resource']      = 'Elixir',
      ['housing space'] = 4,
      ['imagenum']      = {    1,       1,      1,      1,      1,      1,      1,  1,  1 },
      ['hitpoints']     = {  47,    63, 84, 109,    133,    155,    184,    216,    230 },
      ['dps']           = {  34,    42, 65, 95, 112,    131,    151,    172,    184 },
      ['training cost'] = { 1120,   1440,   1760,   2080,   2400,   2720,   3040,   3380,   3380},
      ['research cost'] = {    0,   0,  0,  0,  0,  0,  0,  0,  0 },
   },
   ['healer'] = {
      ['name']          = 'Healer',
      ['resource']      = 'Elixir',
      ['housing space'] = 14,
      ['imagenum']      = {    1,      1,       3,       4,     5,  6 },
      ['hitpoints']     = {  500,    600,     840,    1200,     1500,   1600 },
      ['dps']           = {    0,      0,       0,       0,     0,  0 },
      ['training cost'] = { 5000,   6000,    8000,   10000,     14000,  17000 },
      ['research cost'] = {    0, 750000, 1500000, 3000000,     9500000,    14500000 },
   },
   ['dragon'] = {
      ['name']          = 'Dragon',
      ['resource']      = 'Elixir',
      ['housing space'] = 20,
      ['imagenum']      = {     1,       2,       3,       4,       5,       6, 7,  8 },
      ['hitpoints']     = {  1900,    2100,    2300,    2600,    3100,    3400, 3900,   4200 },
      ['dps']           = {   140,     160,     180,     210,     240,     270, 310,    330 },
      ['training cost'] = { 10000,   12000,   14000,   16000,   18000,   20000, 22000,  24000 },
      ['research cost'] = {     0, 2000000, 3000000, 5000000, 7000000, 9000000, 11000000,   15000000 },
   },
   ['pekka'] = {
      ['name']          = 'P.E.K.K.A',
      ['resource']      = 'Elixir',
      ['housing space'] = 25,
      ['imagenum']      = {     1,       2,       3,       4,       5,      6,  7,  8 },
      ['hitpoints']     = {  2800,    3100,    3500,    4000,    4700,      5200,   5700,   6300 },
      ['dps']           = {   240,     270,     310,     360,     410,      470,    540,    610 },
      ['training cost'] = { 14000,   16000,   18000,   20000,   22500,      25000,  27500,  30000 },
      ['research cost'] = {     0, 3000000, 5000000, 6000000, 7500000,      8500000,    10000000, 12000000 },
   },
  ['babydragon'] = {
      ['name']          = 'Baby Dragon/Home Village',
      ['resource']      = 'Elixir',
      ['housing space'] = 10,
      ['imagenum']      = {     1,       1,       3,       4,       5,  6 },
      ['hitpoints']     = {  1200,    1300,    1400,    1500,    1600,  1700 },
      ['dps']           = {    75,      85,      95,     105,     115,  125 },
      ['training cost'] = { 5000,   6000,   7000,   8000,   9000,   10000 },
      ['research cost'] = {     0, 5000000, 6000000, 7000000, 8000000,  9000000 },
   },
   ['miner'] = {
      ['name']          = 'Miner',
      ['resource']      = 'Elixir',
      ['housing space'] = 6,
      ['imagenum']      = {     1,       1,       3,       3,       5,  6,  7 },
      ['hitpoints']     = {   550,     610,     670,     730,       800,    900,    1000 },
      ['dps']           = {    80,      88,      96,     104,       112,    120,    128 },
      ['training cost'] = {  4200,    4800,    5200,    5600,       6000,   6400,   6800 },
      ['research cost'] = {     0, 6000000, 7000000, 8000000, 9500000,  11000000,   14000000 },
   },
   ['electrodragon'] = {
      ['name']          = 'Electro Dragon',
      ['resource']      = 'Elixir',
      ['housing space'] = 30,
      ['imagenum']      = {     1,       1,       1,    1 },
      ['hitpoints']     = {   3200,     3700,     4200,     4500 },
      ['dps']           = {    240,      270,      300,     330 },
      ['training cost'] = {  28000,    32000,    36000,    40000 },
      ['research cost'] = {     0, 9000000,  11000000,   16000000 },
   },
   ['yeti'] = {
      ['name']          = 'Yeti',
      ['resource']      = 'Elixir',
      ['housing space'] = 18,
      ['imagenum']      = {     1,       2,       3},
      ['hitpoints']     = {   2900,     3200,     3500 },
      ['dps']           = {    230,      250,      270 },
      ['training cost'] = {  19000,    21000,    23000 },
      ['research cost'] = {     0, 11000000,   15000000 },
   },
   ['minion'] = {
      ['name']          = 'Minion',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 2,
      ['imagenum']      = {  1,     1,     3,     3,     5,      6,      7, 8 },
      ['hitpoints']     = { 55,    60,    66,    72,    78,     84,     90, 96 },
      ['dps']           = { 35,    38,    42,    46,    50,     54,     58, 62 },
      ['training cost'] = {  4, 5,  6,     7,     8,     9,    10,     11 },
      ['research cost'] = {  0, 10000, 20000, 30000, 40000, 100000, 140000, 180000 },
   },
   ['hogrider'] = {
      ['name']          = 'Hog Rider',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {   1,     1,     3,     3,     5,      6,      7,    8,  9,  10 },
      ['hitpoints']     = { 270,   312,   360,   415,   480,    590,    700,    810,    890,    970 },
      ['dps']           = {  60,    70,    80,    92,   105,    118,    135,    148,    161,    174 },
      ['training cost'] = {  30,    34,    38,    42,    48,     60,    80, 100,    120,    140 },
      ['research cost'] = {   0, 20000, 30000, 40000, 50000, 100000, 150000,    200000, 240000, 280000 },
   },
   ['valkyrie'] = {
      ['name']          = 'Valkyrie',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 8,
      ['imagenum']      = {   1,     1,     3,     3,      5,   6,  7 },
      ['hitpoints']     = { 750,   800,   850,   900,   1100,   1200,   1450 },
      ['dps']           = {  94,   106,   119,   133,    148,   163,    178 },
      ['training cost'] = {  50,   65,  80, 100,   130,   160,    190 },
      ['research cost'] = {   0, 50000, 60000, 70000, 110000,   150000, 190000 },
   },
   ['golem'] = {
      ['name']          = 'Golem',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 30,
      ['imagenum']      = {    1,     1,     3,     3,     5,      6,   7,  8,  9 },
      ['hitpoints']     = { 5100,  5400,  5700,  6000,  6300,   6600,   6900,   7200,   7500 },
      ['dps']           = {   35,    40,    45,    50,    55,     60,   65, 70, 75 },
      ['training cost'] = {  200,   250,   300,   350,   425,    500,   600,    700,    800 },
      ['research cost'] = {    0, 60000, 70000, 80000, 90000, 150000,   200000, 200000, 220000 },
   },
   ['witch'] = {
      ['name']          = 'Witch',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 12,
      ['imagenum']      = {   1,     1,      3, 3,  5 },
      ['hitpoints']     = { 300,   320,    400, 440,    480 },
      ['dps']           = {  100,    110,     140,  160,    180 },
      ['training cost'] = { 125,   150,    175, 225,    275 },
      ['research cost'] = {   0, 75000, 120000, 160000, 200000 },
   },
   ['lavahound'] = {
      ['name']          = 'Lava Hound',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 30,
      ['imagenum']      = {    1,     1,     3,      4, 5 },
      ['hitpoints']     = { 6100,  6500,  6800,   7200, 7600 },
      ['dps']           = {   10,    12,    14,     16, 18 },
      ['training cost'] = {  390,   450,   510,    570, 630 },
      ['research cost'] = {    0, 60000, 70000, 150000, 200000 },
   },
['bowler'] = {
      ['name']          = 'Bowler',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 6,
      ['imagenum']      = {   1,      1,      3,    4,  5 },
      ['hitpoints']     = { 290,    310,    350,    390,    430 },
      ['dps']           = {  60,     70,     80,    90, 96 },
      ['training cost'] = { 70,    95,    115,  140,    175 },
      ['research cost'] = {   0, 120000, 160000,    200000, 280000 },
   },
['icegolem'] = {
      ['name']          = 'Ice Golem',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 15,
      ['imagenum']      = {   1,      1,      3,    3,  5 },
      ['hitpoints']     = { 2600,    2800,    3000,    3200,    3400 },
      ['dps']           = {  24,     28,     32,    36, 40 },
      ['training cost'] = { 220,    240,    260,  280,    300 },
      ['research cost'] = {   0, 80000, 120000, 160000,    200000 },
   },
}
 
function p.troopStatistics( troopName, statistic, level, format, raw )
   local retVal
 
   troopName = string.lower( troopName or '' )
   statistic = string.lower( statistic or '' )
   level     = level or 0
   format    = not ( not format )
 
   -- Remove spaces and punctuation from troop name
   troopName = string.gsub( string.gsub( troopName, '%s+', '' ), '%p+', '' )
 
   if not p.troopData[ troopName ] then
      retVal = ''
   elseif not p.troopData[ troopName ][ statistic ] then
      retVal = ''
   else
      retVal = p.troopData[ troopName ][ statistic ]
 
      if type( retVal ) == 'table' and level ~= 0 then
         if not retVal[ level ] then
            retVal = 0
         else
            retVal = retVal[ level ]
         end
      end
   end
 
   if type( retVal ) == 'number' then
      if format then
         retVal = formatNum( retVal )
      end
   elseif type ( retVal ) == 'table' then
      if raw then
         return retVal
      else
         retVal = '{' .. table.concat( retVal, ',' ) .. '}'
      end
   end
 
   return retVal
end
 
function p.troopImage( troopName, level, size )
   local name   = p.troopStatistics( troopName, 'name' )
 
   if name == '' then
      return ''
   end
 
   local levels = p.troopStatistics( troopName, 'imagenum', level, nil, true )
 
   if type( levels ) == 'table' then
      local images = {}
 
      for k, v in pairs( levels ) do
         table.insert( images, '[[File:' .. name .. v .. '.png|' ..
            ( size and size or '100px' ) .. '|link=' .. name .. ']]' )
      end
 
      return table.concat( images )
   elseif levels > 0 then
      return '[[File:' .. name .. levels .. '.png|' ..
         ( size and size or '100px' ) .. '|link=' .. name .. ']]'
   else
      return ''
   end
end
 
function p.main( frame )
   local troopName = frame.args[ 'troop' ] or frame.args[ 1 ]
   local statistic = frame.args[ 'stat' ] or frame.args[ 2 ]
   local level     = tonumber( frame.args[ 'level' ] ) or tonumber( frame.args[ 3 ] )
   local format    = frame.args[ 'format' ] or frame.args[ 4 ]
   local size      = frame.args[ 'size' ] or frame.args[ 4 ]
 
   if troopName == '' then troopName = nil end
   if statistic == '' then statistic = nil end
   if format == '' then format = nil end
   if size == '' then size = nil end
 
   if statistic == 'image' then
      return frame:preprocess( p.troopImage( troopName, level, size ) )
   end
 
   return p.troopStatistics( troopName, statistic, level, format )
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.