This license DOES NOT extend to any other files of the Pokemon replay viewer. */ include_once 'persist.lib.php'; include_once 'replays.inc.php'; include_once 'data/pokedex.inc.php'; include_once 'data/typechart.inc.php'; function parseName($name) { $monthTable = array('january' => '01', 'february' => '02', 'march' => '03', 'april' => '04', 'may' => '05', 'june' => '06', 'july' => '07', 'august' => '08', 'september' => '09', 'october' => '10', 'november' => '11', 'december' => '12'); if (substr($name, -5) === '.html') $name = substr($name,0,-5); if (substr($name, -4) === '.htm') $name = substr($name,0,-4); if (preg_match('/^(.*)\-\-([0-9]+) ([A-Z][a-z]+) ([0-9]+) at ([0-9]+)h([0-9]+)$/', $name, $matches)) { $name = trim($matches[1]).'--'.$matches[4].'-'.$monthTable[strtolower($matches[3])].'-'.$matches[2]; } $name = str_replace(' ','-',$name); $name = preg_replace('/[^A-Za-z0-9-]+/', '', $name); return $name; } function startsRemove(&$str, $substr) { if (substr($str, 0, strlen($substr)) === $substr) { $str = substr($str, strlen($substr)); return true; } return false; } function endsRemove(&$str, $substr) { if (substr($str, -strlen($substr)) === $substr) { $str = substr($str, 0, -strlen($substr)); return true; } return false; } function startsWith($str, $substr) { return (substr($str, 0, strlen($substr)) === $substr); } function endsWith($str, $substr) { return (substr($str, -strlen($substr)) === $substr); } function uppercaseFirstLetter($str) { // I am raging at PO replays for this. return strtoupper(substr($str,0,1)).substr($str,1); } function lowercaseFirstLetter($str) { // I am raging at PO replays for this. return strtolower(substr($str,0,1)).substr($str,1); } $pokemontable = array('Bandier' => 'ally-Bandier(Dodrio)', 'Scarfy' => 'ally-Scarfy(Dodrio)'); function namePokemon($pokemon) { global $pokemontable, $allpokemon, $currentpokemon; $pokemonConv = $pokemon; $pos = strrpos($pokemon, '('); if ($pos) $pokemonConv = substr($pokemon, 0, $pos); $pokemonConv = str_replace(' ', '', $pokemonConv); $currentpokemon[$pokemonConv] = $pokemon; } function matchName($pokemon) { global $currentpokemon; foreach ($currentpokemon as $mpoke => $cpoke) { startsRemove($mpoke,'ally-'); startsRemove($mpoke,'foe-'); if ($pokemon === $mpoke) return $mpoke; else if ($pokemon === uppercaseFirstLetter($mpoke)) return $mpoke; } return $pokemon; } function resolvePokemon($pokemon) { global $convertNotDone, $allpokemon, $allyname, $playernames, $pokemontable, $lastPokemon, $returnNow, $currentpokemon; if ($pokemontable[$pokemon]) { $currentpokemon[$pokemontable[$pokemon]] = $pokemontable[$pokemon]; $lastPokemon = $pokemontable[$pokemon]; return $pokemontable[$pokemon]; } $pokeid = ''; // echo '['.$playernames[0].'|'.$pokemon.']'; if (startsRemove($pokemon, "The foe's ") || startsRemove($pokemon, "the foe's ")) { $pokeid = $pokemon; $pokemon = 'foe-'.$pokemon; } else if (startsRemove($pokemon, $playernames[0]."'s ") || startsRemove($pokemon, uppercaseFirstLetter($playernames[0])."'s ")) { $pokeid = $pokemon; $pokemon = 'ally-'.$pokemon; } else if (startsRemove($pokemon, $playernames[1]."'s ") || startsRemove($pokemon, uppercaseFirstLetter($playernames[1])."'s ")) { $pokeid = $pokemon; $pokemon = 'foe-'.$pokemon; } else { $pokeid = $pokemon; $pokemon = 'ally-'.matchName($pokemon); } $pokemon = str_replace(' ', '', $pokemon); if ($convertNotDone && $pokeid && $allpokemon[$pokeid]) { if (substr($pokemon,0,4) === 'foe-') { $allyname = 'foeof-'.$allpokemon[$pokeid]; $returnNow = true; return ''; } $allyname = $allpokemon[$pokeid]; $returnNow = true; return ''; } $lastPokemon = $pokemon; if ($GLOBALS['BattlePokemon'][getSpecies($pokemon)]['number'] >= 494) { $GLOBALS['gen'] = 5; } if ($GLOBALS['BattlePokemon'][getSpecies($pokemon)]['number'] >= 387 && $GLOBALS['gen'] < 4) { $GLOBALS['gen'] = 4; } if ($GLOBALS['BattlePokemon'][getSpecies($pokemon)]['number'] >= 252 && $GLOBALS['gen'] < 4) { $GLOBALS['gen'] = 3; } if ($GLOBALS['BattlePokemon'][getSpecies($pokemon)]['number'] >= 152 && $GLOBALS['gen'] < 4) { $GLOBALS['gen'] = 2; } return $pokemon; } function getSpecies($pokemon) { global $currentpokemon; if ($currentpokemon[$pokemon]) $pokemon = $currentpokemon[$pokemon]; if (substr($pokemon,0,4) === 'foe-') $pokemon = substr($pokemon,4); if (substr($pokemon,0,5) === 'ally-') $pokemon = substr($pokemon,5); $pos = strrpos($pokemon, '('); if ($pos) $pokemon = substr($pokemon, $pos+1, -1); if ($pokemon==='Ho-Oh') $pokemon = "Ho-oh"; return $pokemon; } function resolveMove($move) { return str_replace(' ', '', $move); } function resolveUsername($move) { return str_replace(' ', '', $move); } function resolveItem($move) { return str_replace(' ', '', $move); } function resolveAbility($move) { return str_replace(' ', '', $move); } function resolveStat($stat) { $table = array( 'attack' => 'atk', 'defense' => 'def', 'special attack' => 'spa', 'special defense' => 'spd', 'sp. att.' => 'spa', 'sp. def.' => 'spd', 'speed' => 'spe', ); $stat = strtolower($stat); if ($table[$stat]) return $table[$stat]; return $stat; } function isFoe($name) { return resolveUsername($name) !== $GLOBALS['allyname'] && resolveUsername($name) !== uppercaseFirstLetter($GLOBALS['allyname']); } function markLastDamage($out) { global $lastPokemon, $lastDamage; $lastDamage[$lastPokemon] = count($out)-1; } function markLastAttack($out) { global $lastPokemon, $lastAttack; $lastAttack[$lastPokemon] = count($out)-1; } function attrLastAttack(&$out, $attr) { global $lastPokemon, $lastAttack; if ($lastAttack[$lastPokemon]) { $out[$lastAttack[$lastPokemon]] .= ' '.$attr; } } function makeLastLethal(&$out) { global $lastPokemon, $lastDamage; if ($lastDamage[$lastPokemon] && !endsWith($out[$lastDamage[$lastPokemon]], ' (0.0)') && !endsWith($out[$lastDamage[$lastPokemon]], ' (0)')) { $out[$lastDamage[$lastPokemon]] .= ' (lethal)'; } } $logversion = ''; function pokeConvert($text) { global $convertNotDone, $logversion, $returnNow, $allpokemon, $out, $winner, $allyname, $playernames, $moveuser, $lastmove, $convertloopnum; $english = false; $GLOBALS['gen'] = 1; $switchcounter = 0; //echo "