Clash of Clans Wiki
Advertisement
Clash of Clans Wiki

Documentation for this module may be created at Module:TroopStatistics/doc

local p = {}

local formatNum = require( 'Module:FormatNum' ).formatNum

-- Add a record here in the order you wish the troops to appear
p.troops = {
   'barbarian',
   'archer',
   'goblin',
   'giant',
   'wallbreaker',
   'balloon',
   'wizard',
   'healer',
   'dragon',
   'pekka',
   'minion',
   'hogrider',
   'valkyrie',
   'golem',
   'witch',
   'lavahound',
}

p.troopData = {
   ['barbarian'] = {
      ['name']          = 'Barbarian',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6,       7 },
      ['hitpoints']     = { 45,    54,     65,     78,      95,     110,     125 },
      ['dps']           = {  8,    11,     14,     18,      23,      26,      30 },
      ['training cost'] = { 25,    40,     60,    100,     150,     200,     250 },
      ['research cost'] = {  0, 50000, 150000, 500000, 1500000, 4500000, 6000000 },
   },
   ['archer'] = {
      ['name']          = 'Archer',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6,       7 },
      ['hitpoints']     = { 20,    23,     28,     33,      40,      44,      48 },
      ['dps']           = {  7,     9,     12,     16,      20,      22,      25 },
      ['training cost'] = { 50,    80,    120,    200,     300,     400,     500 },
      ['research cost'] = {  0, 50000, 250000, 750000, 2250000, 6000000, 7500000 },
   },
   ['goblin'] = {
      ['name']          = 'Goblin',
      ['resource']      = 'Elixir',
      ['housing space'] = 1,
      ['imagenum']      = {  1,     1,      3,      3,       5,       6 },
      ['hitpoints']     = { 25,    30,     36,     43,      52,      68 },
      ['dps']           = { 11,    14,     19,     24,      32,      42 },
      ['training cost'] = { 25,    40,     60,     80,     100,     150 },
      ['research cost'] = {  0, 50000, 250000, 750000, 2250000, 4500000 },
   },
   ['giant'] = {
      ['name']          = 'Giant',
      ['resource']      = 'Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {   1,      1,      3,      3,       5,       6,       7 },
      ['hitpoints']     = { 300,    360,    430,    520,     670,     940,    1100 },
      ['dps']           = {  11,     14,     19,     24,      31,      43,      50 },
      ['training cost'] = { 250,    750,   1250,   1750,    2250,    3000,    3500 },
      ['research cost'] = {   0, 100000, 250000, 750000, 2250000, 6000000, 7000000 },
   },
   ['wallbreaker'] = {
      ['name']          = 'Wall Breaker',
      ['resource']      = 'Elixir',
      ['housing space'] = 2,
      ['imagenum']      = {    1,     1,       3,      3,       5,       6 },
      ['hitpoints']     = {   20,     24,     29,     35,      42,      54 },
      ['dps']           = {   12,     16,     24,     32,      46,      60 },
      ['training cost'] = { 1000,   1500,   2000,   2500,    3000,    3500 },
      ['research cost'] = {    0, 100000, 250000, 750000, 2250000, 6750000 },
   },
   ['balloon'] = {
      ['name']          = 'Balloon',
      ['resource']      = 'Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {    1,      1,      3,       3,       5,       6 },
      ['hitpoints']     = {  150,    180,    216,     280,     390,     545 },
      ['dps']           = {   25,     32,     48,      72,     108,     162 },
      ['training cost'] = { 2000,   2500,   3000,    3500,    4000,    4500 },
      ['research cost'] = {    0, 150000, 450000, 1350000, 2500000, 6000000 },
   },
   ['wizard'] = {
      ['name']          = 'Wizard',
      ['resource']      = 'Elixir',
      ['housing space'] = 4,
      ['imagenum']      = {    1,      1,      3,       3,       5,       6 },
      ['hitpoints']     = {   75,     90,    108,     130,     156,     164 },
      ['dps']           = {   50,     70,     90,     125,     170,     180 },
      ['training cost'] = { 1500,   2000,   2500,    3000,    3500,    4000 },
      ['research cost'] = {    0, 150000, 450000, 1350000, 2500000, 7500000 },
   },
   ['healer'] = {
      ['name']          = 'Healer',
      ['resource']      = 'Elixir',
      ['housing space'] = 14,
      ['imagenum']      = {    1,      1,       3,       3 },
      ['hitpoints']     = {  500,    600,     840,    1176 },
      ['dps']           = {    0,      0,       0,       0 },
      ['training cost'] = { 5000,   6000,    8000,   10000 },
      ['research cost'] = {    0, 750000, 1500000, 3000000 },
   },
   ['dragon'] = {
      ['name']          = 'Dragon',
      ['resource']      = 'Elixir',
      ['housing space'] = 20,
      ['imagenum']      = {     1,       2,       3,       4,       5 },
      ['hitpoints']     = {  1900,    2100,    2300,    2500,    2700 },
      ['dps']           = {   140,     160,     180,     200,     220 },
      ['training cost'] = { 25000,   29000,   33000,   37000,   42000 },
      ['research cost'] = {     0, 2000000, 3000000, 7000000, 8000000 },
   },
   ['pekka'] = {
      ['name']          = 'P.E.K.K.A',
      ['resource']      = 'Elixir',
      ['housing space'] = 25,
      ['imagenum']      = {     1,       2,       3,       4,       5 },
      ['hitpoints']     = {  2800,    3100,    3500,    4000,    4500 },
      ['dps']           = {   240,     270,     300,     340,     380 },
      ['training cost'] = { 28000,   32000,   36000,   40000,   45000 },
      ['research cost'] = {     0, 3000000, 6000000, 7000000, 8000000 },
   },
   ['minion'] = {
      ['name']          = 'Minion',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 2,
      ['imagenum']      = {  1,     1,     3,     3,     5,      6 },
      ['hitpoints']     = { 55,    60,    66,    72,    78,     84 },
      ['dps']           = { 35,    38,    42,    46,    50,     54 },
      ['training cost'] = {  6,     7,     8,     9,    10,     11 },
      ['research cost'] = {  0, 10000, 20000, 30000, 40000, 100000 },
   },
   ['hogrider'] = {
      ['name']          = 'Hog Rider',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 5,
      ['imagenum']      = {   1,     1,     3,     3,     5 },
      ['hitpoints']     = { 270,   312,   360,   415,   475 },
      ['dps']           = {  60,    70,    80,    92,   105 },
      ['training cost'] = {  40,    45,    52,    58,    65 },
      ['research cost'] = {   0, 20000, 30000, 40000, 50000 },
   },
   ['valkyrie'] = {
      ['name']          = 'Valkyrie',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 8,
      ['imagenum']      = {   1,     1,     3,     3 },
      ['hitpoints']     = { 900,  1000,  1100,  1200 },
      ['dps']           = {  88,    99,   111,   124 },
      ['training cost'] = {  70,   100,   130,   160 },
      ['research cost'] = {   0, 50000, 60000, 70000 },
   },
   ['golem'] = {
      ['name']          = 'Golem',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 30,
      ['imagenum']      = {    1,     1,     3,     3,     5 },
      ['hitpoints']     = { 4500,  5000,  5500,  6000,  6300 },
      ['dps']           = {   38,    42,    46,    50,    54 },
      ['training cost'] = {  450,   525,   600,   675,   750 },
      ['research cost'] = {    0, 60000, 70000, 80000, 90000 },
   },
   ['witch'] = {
      ['name']          = 'Witch',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 12,
      ['imagenum']      = {   1,     1 },
      ['hitpoints']     = {  75,   100 },
      ['dps']           = {  25,    30 },
      ['training cost'] = { 250,   350 },
      ['research cost'] = {   0, 75000 },
   },
   ['lavahound'] = {
      ['name']          = 'Lava Hound',
      ['resource']      = 'Dark Elixir',
      ['housing space'] = 30,
      ['imagenum']      = {    1,     1,     3 },
      ['hitpoints']     = { 5700,  6200,  6700 },
      ['dps']           = {   10,    12,    14 },
      ['training cost'] = {  390,   450,   510 },
      ['research cost'] = {    0, 60000, 70000 },
   },
}

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' )
   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 )
   else
      return '[[File:' .. name .. levels .. '.png|' ..
         ( size and size or '100px' ) .. '|link=' .. name .. ']]'
   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 statistic == 'image' then
      return frame:preprocess( p.troopImage( troopName, level, size ) )
   end
   
   return p.troopStatistics( troopName, statistic, level, format )
end

return p
Advertisement