PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/backup/chartmaker.php

https://github.com/rissole/Pokemon-Showdown-Client
PHP | 405 lines | 321 code | 50 blank | 34 comment | 53 complexity | 989d408ff492dd80e91833e5c122b9f2 MD5 | raw file
  1. <?php
  2. include 'persist.lib.php';
  3. $BattleAliases = array(
  4. // formes
  5. "shaymins" => "Shaymin-Sky",
  6. "rotomh" => "Rotom-Heat",
  7. "rotomw" => "Rotom-Wash",
  8. "rotomf" => "Rotom-Frost",
  9. "rotoms" => "Rotom-Fan",
  10. "rotomc" => "Rotom-Mow",
  11. "meloettas" => "Meloetta-Pirouette",
  12. "meloettap" => "Meloetta-Pirouette",
  13. "giratinao" => "Giratina-Origin",
  14. "wormadamg" => "Wormadam-Sandy",
  15. "wormadams" => "Wormadam-Trash",
  16. "wormadamground" => "Wormadam-Sandy",
  17. "wormadamsteel" => "Wormadam-Trash",
  18. "deoxysa" => "Deoxys-Attack",
  19. "deoxyss" => "Deoxys-Speed",
  20. "deoxysd" => "Deoxys-Defense",
  21. "deoxysdefence" => "Deoxys-Defense",
  22. "basculinb" => "Basculin-Blue",
  23. "darmanitanzenmode" => "Darmanitan-Zen",
  24. "cherrimsunny" => "Cherrim-Sunshine",
  25. "cherrims" => "Cherrim-Sunshine",
  26. "castforms" => "Castform-Sunny",
  27. "castformr" => "Castform-Rainy",
  28. "castformh" => "Castform-Snowy",
  29. "castformfire" => "Castform-Sunny",
  30. "castformwater" => "Castform-Rainy",
  31. "castformice" => "Castform-Snowy",
  32. // base formes
  33. "nidoranfemale" => "Nidoran-F",
  34. "nidoranmale" => "Nidoran-M",
  35. "giratinaaltered" => "Giratina",
  36. "giratinaa" => "Giratina",
  37. "cherrimovercast" => "Cherrim",
  38. "cherrimo" => "Cherrim",
  39. "meloettaaria" => "Meloetta",
  40. "meloettaa" => "Meloetta",
  41. "basculinred" => "Basculin",
  42. "basculinr" => "Basculin",
  43. // items
  44. "cb" => "Choice Band",
  45. "band" => "Choice Band",
  46. "lefties" => "Leftovers",
  47. "lo" => "Life Orb",
  48. // pokemon
  49. "dnite" => "Dragonite",
  50. "ttar" => "Tyranitar",
  51. "rank" => "Reuniclus",
  52. "ferry" => "Ferrothorn",
  53. "forry" => "Forretress",
  54. "luke" => "Lucario",
  55. "poryz" => "Porygon-Z",
  56. "pz" => "Porygon-Z",
  57. "pory2" => "Porygon2",
  58. "p2" => "Porygon2",
  59. // moves
  60. "sd" => "Swords Dance",
  61. "dd" => "Dragon Dance",
  62. "hjk" => "Hi Jump Kick",
  63. "cc" => "Close Combat",
  64. "np" => "Nasty Plot",
  65. "sr" => "Stealth Rock",
  66. "tr" => "Trick Room",
  67. "tbolt" => "Thunderbolt",
  68. "wow" => "Will-O-Wisp",
  69. "qd" => "Quiver Dance",
  70. "tspikes" => "Toxic Spikes",
  71. "twave" => "Thunder Wave",
  72. "eq" => "Earthquake",
  73. "cm" => "Calm Mind",
  74. "se" => "Stone Edge",
  75. // Japanese names
  76. "birijion" => "Virizion",
  77. "terakion" => "Terrakion",
  78. "agirudaa" => "Accelgor",
  79. "randorosu" => "Landorus",
  80. "urugamosu" => "Volcarona",
  81. "erufuun" => "Whimsicott",
  82. "doryuuzu" => "Excadrill",
  83. "burungeru" => "Jellicent",
  84. "nattorei" => "Ferrothorn",
  85. "shandera" => "Chandelure",
  86. "roobushin" => "Conkeldurr",
  87. "ononokusu" => "Haxorus",
  88. "sazandora" => "Hydreigon",
  89. "chirachiino" => "Cinccino",
  90. "kyuremu" => "Kyurem",
  91. "jarooda" => "Serperior",
  92. "zoroaaku" => "Zoroark",
  93. "shinboraa" => "Sigilyph",
  94. "barujiina" => "Mandibuzz",
  95. "rankurusu" => "Reuniclus",
  96. "borutorosu" => "Thundurus"
  97. // there's no need to type out the other Japanese names
  98. // I'll autogenerate them at some point
  99. );
  100. if (isset($_REQUEST['1']))
  101. {
  102. $file = file('data/pokedex.csv');
  103. $BattlePokemon = array();
  104. $BattlePokemonByNumber = array();
  105. $jp = false;
  106. $TableMaleOnly = array('32'=> 1,'33'=> 1,'34'=> 1,'106'=> 1,'107'=> 1,'128'=> 1,'236'=> 1,'237'=> 1,'313'=> 1,'381'=> 1,'414'=> 1,'475'=> 1,'538'=> 1,'539'=> 1,'627'=> 1,'628'=> 1,'641'=> 1,'642'=> 1,'645'=> 1,);
  107. $TableFemaleOnly = array('-2'=> 1,'29'=> 1,'30'=> 1,'31'=> 1,'113'=> 1,'115'=> 1,'124'=> 1,'238'=> 1,'241'=> 1,'242'=> 1,'314'=> 1,'380'=> 1,'413'=> 1,'416'=> 1,'440'=> 1,'478'=> 1,'488'=> 1,'548'=> 1,'549'=> 1,'629'=> 1,'630'=> 1,);
  108. $TableGenderless = array('-55'=> 1,'81'=> 1,'82'=> 1,'100'=> 1,'101'=> 1,'120'=> 1,'121'=> 1,'132'=> 1,'137'=> 1,'144'=> 1,'145'=> 1,'146'=> 1,'150'=> 1,'150'=> 1,'201'=> 1,'233'=> 1,'243'=> 1,'244'=> 1,'245'=> 1,'249'=> 1,'250'=> 1,'251'=> 1,'292'=> 1,'337'=> 1,'338'=> 1,'343'=> 1,'344'=> 1,'374'=> 1,'375'=> 1,'376'=> 1,'377'=> 1,'378'=> 1,'379'=> 1,'382'=> 1,'383'=> 1,'384'=> 1,'385'=> 1,'386'=> 1,'436'=> 1,'437'=> 1,'462'=> 1,'474'=> 1,'479'=> 1,'480'=> 1,'481'=> 1,'482'=> 1,'483'=> 1,'484'=> 1,'486'=> 1,'487'=> 1,'489'=> 1,'490'=> 1,'491'=> 1,'492'=> 1,'493'=> 1,'494'=> 1,'599'=> 1,'600'=> 1,'601'=> 1,'615'=> 1,'622'=> 1,'638'=> 1,'639'=> 1,'640'=> 1,'643'=> 1,'644'=> 1,'646'=> 1,'647'=> 1,'648'=> 1,'649'=> 1,);
  109. foreach ($file as $line)
  110. {
  111. $args = explode(',',$line);
  112. $negative = false;
  113. if (substr($args[0],0,1) === '-')
  114. {
  115. $args[0] = substr($args[0],1);
  116. $negative = true;
  117. }
  118. if (!ctype_digit($args[0])) continue;
  119. while (substr($args[0],0,1)==='0') $args[0] = substr($args[0],1);
  120. $num = intval($args[0]);
  121. if ($negative) $num = -$num;
  122. $species = $args[1];
  123. $speciesid = preg_replace('/[^a-z0-9]+/', '', strtolower($species));
  124. if ($BattlePokemon[$species] && $jp) continue;
  125. $forme = '';
  126. $formeletter = '';
  127. $spriteid = $speciesid;
  128. $basespecies = $species;
  129. if ($loc = strrpos($species,'-') && $species !== 'Ho-Oh' && $species !== 'Ho-oh' && $species !== 'Porygon-Z')
  130. {
  131. $loc = strrpos($species,'-');
  132. $basespecies = substr($species, 0, $loc);
  133. $forme = substr($species, $loc+1);
  134. $basespeciesid = preg_replace('/[^a-z0-9]+/', '', strtolower($basespecies));
  135. $formeid = preg_replace('/[^a-z0-9]+/', '', strtolower($forme));
  136. $spriteid = $basespeciesid.'-'.$formeid;
  137. $formeletter = substr($forme,0,1);
  138. if ($speciesid === 'rotommow') $formeletter = 'C';
  139. if ($speciesid === 'rotomfan') $formeletter = 'S';
  140. if ($speciesid === 'wormadamsandy') $formeletter = 'G';
  141. if ($speciesid === 'wormadamtrash') $formeletter = 'S';
  142. if ($speciesid === 'castformsunny') $formeletter = 'F';
  143. if ($speciesid === 'castformrainy') $formeletter = 'W';
  144. if ($speciesid === 'castformsnowy') $formeletter = 'I';
  145. }
  146. $types = array($args[2]);
  147. if ($args[3]) $types[] = $args[3];
  148. $baseStats = array(
  149. 'hp' => intval($args[4]),
  150. 'atk' => intval($args[5]),
  151. 'def' => intval($args[6]),
  152. 'spa' => intval($args[7]),
  153. 'spd' => intval($args[8]),
  154. 'spe' => intval($args[9]),
  155. );
  156. $abilities = array(0 => $args[29],1=>$args[30],'DW'=>$args[31]);
  157. $BattlePokemon[$speciesid] = array(
  158. 'name' => $species,
  159. 'id' => $speciesid,
  160. 'species' => $species,
  161. 'speciesid' => $speciesid,
  162. 'basespecies' => $basespecies,
  163. 'forme' => $forme,
  164. 'formeletter' => $formeletter,
  165. 'spriteid' => $spriteid,
  166. 'num' => $num,
  167. 'types' => $types,
  168. 'baseStats' => $baseStats,
  169. 'abilities' => $abilities,
  170. 'height' => $args[40+5],
  171. 'heightm' => floatval(substr($args[40+5],0,-2)),
  172. 'weight' => $args[41+5],
  173. 'weightkg' => floatval(substr($args[41+5],0,-3)),
  174. 'nfe' => false,
  175. 'gender' => '',
  176. 'prevo' => '',
  177. //'jp' => $jp,
  178. );
  179. if ($TableMaleOnly[''.$num]) $BattlePokemon[$speciesid]['gender'] = 'M';
  180. if ($TableFemaleOnly[''.$num]) $BattlePokemon[$speciesid]['gender'] = 'F';
  181. if ($TableGenderless[''.$num]) $BattlePokemon[$speciesid]['gender'] = 'N';
  182. if (!$BattlePokemonByNumber[$num]) $BattlePokemonByNumber[$num] = $speciesid;
  183. if ($species === 'Genesect')
  184. {
  185. $jp = true;
  186. break;
  187. }
  188. }
  189. persist_save('BattlePokemon', 'data/pokedex.inc.php');
  190. persist_save('BattlePokemonByNumber', 'data/pokedex_numlookup.inc.php');
  191. echo '<a href="chartmaker.php?2">next</a><br /><br />';
  192. var_export($BattlePokemon['necturna']);
  193. }
  194. else if (isset($_REQUEST['2']))
  195. {
  196. include 'data/pokedex.inc.php';
  197. include 'data/pokedex_numlookup.inc.php';
  198. // prevos
  199. $file = file('data/po_evos.txt');
  200. foreach ($file as $line)
  201. {
  202. if (!$line) continue;
  203. $args = explode(' ', $line);
  204. $poke = $BattlePokemonByNumber[intval($args[0])];
  205. $args = array_splice($args,1);
  206. $BattlePokemon[$poke]['nfe'] = true;
  207. foreach ($args as $arg)
  208. {
  209. $BattlePokemon[$BattlePokemonByNumber[intval($args[0])]]['prevo'] = $poke;
  210. }
  211. }
  212. persist_save('BattlePokemon', 'data/pokedex.inc.php');
  213. //file_put_contents('data/pokedex.js', 'exports.BattlePokedex = '.json_encode($BattlePokemon));
  214. echo '<a href="chartmaker.php?3">next</a><br /><br />';
  215. var_export($BattlePokemon['ivysaur']);
  216. }
  217. else if (isset($_REQUEST['3']))
  218. {
  219. include 'data/pokedex.inc.php';
  220. include 'data/typechart.inc.php';
  221. $file = file('data/movesets.csv');
  222. foreach ($file as $line)
  223. {
  224. $args = explode(',',$line);
  225. if (!ctype_digit($args[3])) continue;
  226. $species = $args[0];
  227. $speciesid = preg_replace('/[^a-z0-9]+/', '', strtolower($species));
  228. if ($BattleAliases[$speciesid])
  229. {
  230. //echo $species." to ".$BattleAliases[$speciesid]." | ";
  231. $species = $BattleAliases[$speciesid];
  232. $speciesid = preg_replace('/[^a-z0-9]+/', '', strtolower($species));
  233. }
  234. if (!$speciesid) continue;
  235. if (!$BattlePokemon[$speciesid]['viablemoves']) $BattlePokemon[$speciesid]['viablemoves'] = array();
  236. for ($i=10; $i<19; $i++)
  237. {
  238. $move = $args[$i];
  239. $moveid = preg_replace('/[^a-z0-9]+/', '', strtolower($move));
  240. if (substr($moveid, 0, strlen('hiddenpower')) === 'hiddenpower') $moveid = 'hiddenpower';
  241. if ($moveid === 'none' || !$moveid) continue;
  242. $BattlePokemon[$speciesid]['viablemoves'][$moveid] = $move;
  243. $BattlePokemon[$speciesid]['viable'] = true;
  244. }
  245. }
  246. file_put_contents('data/pokedex.js', 'exports.BattlePokedex = '.json_encode($BattlePokemon));
  247. echo '<a href="chartmaker.php?4">next</a><br /><br />';
  248. var_export($BattlePokemon['weavile']);
  249. }
  250. else if (isset($_REQUEST['4']))
  251. {
  252. include 'data/pokedex.inc.php';
  253. $fp = fopen('data/pokedex-mini.js','w');
  254. fwrite($fp, "BattlePokemonSprites = {\n");
  255. /*
  256. $remap = array(
  257. 'wormadam-ground' => 'wormadam-sandy',
  258. 'wormadam-steel' => 'wormadam-trash',
  259. );
  260. foreach ($remap as $from => $to)
  261. {
  262. rename('sprites/bwani/'.$from.'.gif', 'sprites/bwani/'.$to.'.gif');
  263. rename('sprites/bwani-shiny/'.$from.'.gif', 'sprites/bwani-shiny/'.$to.'.gif');
  264. rename('sprites/bwani-back/'.$from.'.gif', 'sprites/bwani-back/'.$to.'.gif');
  265. rename('sprites/bwani-back-shiny/'.$from.'.gif', 'sprites/bwani-back-shiny/'.$to.'.gif');
  266. rename('sprites/bwani/'.$from.'-f.gif', 'sprites/bwani/'.$to.'-f.gif');
  267. rename('sprites/bwani-shiny/'.$from.'-f.gif', 'sprites/bwani-shiny/'.$to.'-f.gif');
  268. rename('sprites/bwani-back/'.$from.'-f.gif', 'sprites/bwani-back/'.$to.'-f.gif');
  269. rename('sprites/bwani-back-shiny/'.$from.'-f.gif', 'sprites/bwani-back-shiny/'.$to.'-f.gif');
  270. }
  271. die();
  272. */
  273. foreach($BattlePokemon as $poke)
  274. {
  275. if ($poke['jp']) break;
  276. //$filename = str_pad(''.$poke['num'], 3, "0", STR_PAD_LEFT);
  277. //if (!file_exists('sprites/ani-src/'.$filename.'.gif')) $filename = str_replace('_','-',$filename);
  278. //if (substr($filename,0,2)==='0-') $filename = '-0'.substr($filename,2);
  279. //if ($poke['forme']) $filename = $filename.'-'.strtolower($poke['forme']);
  280. $filename = $poke['spriteid'];
  281. $size = @getimagesize('sprites/bwani/'.$filename.'.gif');
  282. if ($size)
  283. {
  284. if (!$BattlePokemon[$poke['speciesid']]['sprite']) $BattlePokemon[$poke['speciesid']]['sprite'] = array();
  285. $BattlePokemon[$poke['speciesid']]['sprite']['ani'] = array(
  286. 'w' => $size[0],
  287. 'h' => $size[1]
  288. );
  289. }
  290. $size = @getimagesize('sprites/bwani-back/'.$filename.'.gif');
  291. if ($size)
  292. {
  293. $BattlePokemon[$poke['speciesid']]['sprite']['backani'] = array(
  294. 'w' => $size[0],
  295. 'h' => $size[1]
  296. );
  297. }
  298. $size = @getimagesize('sprites/bwani/'.$filename.'-f.gif');
  299. if ($size)
  300. {
  301. $BattlePokemon[$poke['speciesid']]['sprite']['anif'] = array(
  302. 'w' => $size[0],
  303. 'h' => $size[1]
  304. );
  305. }
  306. $size = @getimagesize('sprites/bwani-back/'.$filename.'-f.gif');
  307. if ($size)
  308. {
  309. $BattlePokemon[$poke['speciesid']]['sprite']['backanif'] = array(
  310. 'w' => $size[0],
  311. 'h' => $size[1]
  312. );
  313. }
  314. }
  315. foreach($BattlePokemon as $poke)
  316. {
  317. if ($poke['sprite']['ani'])
  318. {
  319. fwrite($fp, " \"{$poke['speciesid']}\": {");
  320. if ($poke['num'])
  321. {
  322. fwrite($fp, "num:{$poke['num']}, ");
  323. }
  324. fwrite($fp, "front:{ani:{w: {$poke['sprite']['ani']['w']}, h: {$poke['sprite']['ani']['h']}}");
  325. if ($poke['sprite']['anif'])
  326. {
  327. fwrite($fp, ", anif:{w: {$poke['sprite']['anif']['w']}, h: {$poke['sprite']['anif']['h']}}");
  328. }
  329. fwrite($fp, "}");
  330. if ($poke['sprite']['backani'])
  331. {
  332. fwrite($fp, ",back:{ani:{w: {$poke['sprite']['backani']['w']}, h: {$poke['sprite']['backani']['h']}}");
  333. if ($poke['sprite']['backanif'])
  334. {
  335. fwrite($fp, ", anif:{w: {$poke['sprite']['backanif']['w']}, h: {$poke['sprite']['backanif']['h']}}");
  336. }
  337. fwrite($fp, "}");
  338. }
  339. if ($poke['sprite']['f'])
  340. {
  341. fwrite($fp, ",f:1");
  342. }
  343. fwrite($fp, "},\n");
  344. }
  345. else if ($poke['num'])
  346. {
  347. fwrite($fp, " \"{$poke['speciesid']}\": {");
  348. fwrite($fp, "num:{$poke['num']}");
  349. fwrite($fp, "},\n");
  350. }
  351. }
  352. fwrite($fp, " done:null\n};\n");
  353. fclose($fp);
  354. var_export($BattlePokemon['bulbasaur']);
  355. }