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 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); } 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 "
started
"; if (strpos($text, '.*\/s', '', $text); { $headloc = strpos($text, ''); if ($headloc) { $logversion = substr($text, 0, $headloc); if ($versionloc = strpos($logversion, '(version ')) { $logversion = substr($logversion, $versionloc+9); $logversion = substr($logversion, 0, strpos($logversion, ')')); //if (isset($_REQUEST['dev'])) var_dump($logversion); } $text = substr($text, $headloc); } } $text = preg_replace('/.*?\<\/head\>/s', '', $text); $text = preg_replace('/\<\/?(\!DOCTYPE|html|body|p)[^>]*\>/', '', $text); $text = preg_replace('/\]*\>\]*\>/', '', $text); $text = str_replace("",'', $text); $text = str_replace("\n",'', $text); $text = str_replace("\r",'', $text); //var_export(htmlspecialchars($text)); if (strpos($text, '.-->')) { $text = str_replace("-->",'
-->', $text); } $text = explode('
', $text); $allyname = ''; $convertloopnum = 0; do { $convertNotDone = false; $returnNow = false; $out = pokeConvertInner($text); $convertloopnum++; } while ($convertNotDone && $convertloopnum < 3); //echo var_export($allpokemon); //echo "
$allyname
"; if ($convertNotDone) { return array('error This replay could not be processed.'); } return $out; } function pokeConvertInner($text) { global $convertNotDone, $returnNow, $currentpokemon, $allpokemon, $out, $winner, $allyname, $playernames, $moveuser, $lastmove, $oldlines, $oldlinesoffset, $convertloopnum; $allpokemon = array(); $oldlines = array(); $oldlinesoffset = 0; $out = array(); $winner = false; $moveuser = ''; $lastmove = ''; $currentpokemon = array(); $firstline = true; foreach ($text as $i => $line) { if ($firstline) { $firstline = false; } $line = str_replace('&', '&', $line); $line = preg_replace('/\]+) can\'t use ([^<>]+) after the taunt!\>$/', $line, $matches)) { $out[] = 'cant-move '.resolvePokemon($matches[1]).' taunt '.resolveMove($matches[2]); } else if (preg_match('/^([^<>]+) used \<([^<>]+)\>!$/', $line, $matches)) { $moveuser = resolvePokemon($matches[1]); $movetarget = 'foeof-'.resolvePokemon($matches[1]); $lastmove = resolveMove($matches[2]); $out[] = 'move '.$moveuser.' '.resolveMove($matches[2]).' ??'; markLastAttack($out); if ($matches[2] === 'Explosion' || $matches[2] === 'Selfdestruct' || $matches[2] === 'Lunar Dance' || $matches[2] === 'Healing Wish' || $matches[2] === 'Memento' || $matches[2] === 'Final Gambit') { markLastDamage($out); } } else if (preg_match('/^([^<>]+) sent out ([^<>]+)!( \([^<>]+\))?$/', $line, $matches)) { if ($allpokemon[$matches[2]] && $allpokemon[$matches[2]] != resolveUsername($matches[1])) { $allpokemon[$matches[2]] = false; } else if ($allpokemon[$matches[2]] !== false) { $allpokemon[$matches[2]] = resolveUsername($matches[1]); } $pokemon = (isFoe($matches[1])?'foe-':'ally-').$matches[2].$matches[3]; namePokemon($pokemon); $pokemon = str_replace(' ','',$pokemon); $out[] = 'switch-in switched-'.$pokemon; $lastmove = 'switch'; if ($switchcounter < 99) $switchcounter++; } else if (preg_match('/^\]+)\'s team!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' StealthRock'; } else if (preg_match('/^\]+)\'s team!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Spikes'; } else if (preg_match('/^\]+)\'s team!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' ToxicSpikes'; } else if (preg_match('/^\]+)\'s team!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Tailwind'; } else if (preg_match('/^\<([^<>]+)\'s team tailwind petered out!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = 'side-condition '.$side.' Tailwind end'; } else if (preg_match('/^\]+)\'s team defense!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Reflect'; } else if (preg_match('/^\<([^<>]+)\'s reflect wore off!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Reflect end'; } else if (preg_match('/^\<([^<>]+)\'s team became cloaked in a mystical veil!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Safeguard'; } else if (preg_match('/^\<([^<>]+)\'s team is no longer protected by Safeguard!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' Safeguard end'; } else if (preg_match('/^\]+)\'s team special defense!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' LightScreen'; } else if (preg_match('/^\<([^<>]+)\'s light screen wore off!\>?$/', $line, $matches)) { $side = (isFoe($matches[1])?'foe':'ally'); $out[] = '|-side-condition '.$side.' LightScreen end'; } else if (preg_match('/^\<([^<>]+) shattered ([^<>]+)\'s team protections!\>?$/', $line, $matches)) { $side = (isFoe($matches[2])?'foe':'ally'); $out[] = '|-shatter '.resolvePokemon($matches[1]).' '.$side; } else if (preg_match('/^([^<>]+)\'s Synchronize changes the status of ([^<>]+)!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-activate Synchronize '.resolvePokemon($matches[2]).''; } else if (preg_match('/^([^<>]+) called ([^<>]+) back!$/', $line, $matches)) { $pokemon = (isFoe($matches[1])?'foe-':'ally-').$matches[2]; $pokemon = str_replace(' ','',$pokemon); $out[] = 'switch-out '.$pokemon; } else if (preg_match('/^\]+) transformed into ([^<>]+)!\>?$/', $line, $matches)) { $out[] = '|-transform '.resolvePokemon($matches[1]).' '.resolveUsername($matches[2]).''; } else if (preg_match('/^\<([^<>]+) made ([^<>]+) feel drowsy!\>$/', $line, $matches)) { $out[] = '|-start|'.resolvePokemon($matches[2]).' drowsy start '.resolvePokemon($matches[1]).''; } else if (preg_match('/^([^<>]+) is hurt by ([^<>]+)\'s ([A-Za-z .\']+)!$/', $line, $matches)) { $out[] = '|-foe-item-damage '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' '.resolveItem($matches[3]).' ??'; resolvePokemon($matches[1]); // is the one taking the damage markLastDamage($out); } else if (preg_match('/^\<([^<>]+) was hurt by ([A-Za-z .\']+)!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' move-damage '.resolveItem($matches[2]).' ??'; markLastDamage($out); } else if (preg_match('/^([^<>]+) is hurt by its ([A-Za-z .\']+)!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' item-damage '.resolveItem($matches[2]).' ??'; markLastDamage($out); } else if (preg_match('/^([^<>]+) was hurt by Black Sludge!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' item-damage BlackSludge ??'; markLastDamage($out); } else if (preg_match('/^([^<>]+) restored its stats using ([A-Za-z .\']+)!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' item-restore '.resolveItem($matches[2]); } else if (preg_match('/^([^<>]+) restored a little HP using its ([A-Za-z .\']+)!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' item-heal '.resolveItem($matches[2]); } else if (preg_match('/^\<([^<>]+) restored HP using its ([A-Za-z .\']+)!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-heal '.resolveAbility($matches[2]); } else if (preg_match('/^([^<>]+) used its Mental Herb to come back to (his|her|its) senses!$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' item-customcure MentalHerb'; } else if (preg_match('/^\<([^<>]+)\'s Hydration heals its status!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-cure Hydration'; } else if (preg_match('/^\<([^<>]+)\'s Insomnia cures it!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-cure Insomnia'; } else if (preg_match('/^\<([^<>]+)\'s Shed Skin heals its status!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-cure ShedSkin'; } else if (preg_match('/^The attack of ([^<>]+) missed!$/', $line, $matches)) { $out[] = '|-miss '.resolvePokemon($matches[1]); attrLastAttack($out, 'miss'); } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) drastically fell!$/', $line, $matches)) { $out[] = '|-unboost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 3'; } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) sharply fell!$/', $line, $matches)) { $out[] = '|-unboost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 2'; } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) fell!$/', $line, $matches)) { $out[] = '|-unboost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 1'; } else if (preg_match('/^([^<>]+) lost ([0-9]+)% of its health!$/', $line, $matches)) { $out[] = '|-damage '.resolvePokemon($matches[1]).' '.$matches[2]; markLastDamage($out); } else if (preg_match('/^([^<>]+) lost ([0-9]+) HP! \(([0-9]+)% of its health\)$/', $line, $matches)) { $out[] = '|-damage '.resolvePokemon($matches[1]).' '.$matches[3]; markLastDamage($out); } else if (preg_match('/^([^<>]+) traced ([^<>]+)\'s ([A-Za-z ]+)!$/', $line, $matches)) { $out[] = '|-trace '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' '.resolveAbility($matches[3]); } else if (preg_match('/^\<([^<>]+) knocked off ([^<>]+)\'s ([A-Za-z ]+)!\>$/', $line, $matches)) { $out[] = '|-knock-off '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' '.resolveAbility($matches[3]); } else if (preg_match('/^\<([^<>]+) knocked ([^<>]+) on the ground!\>$/', $line, $matches)) { $out[] = '|-start|'.resolvePokemon($matches[2]).' grounded start '.resolvePokemon($matches[1]); } else if (preg_match('/^\<([^<>]+)\'s substitute blocked ([^<>]+)!\>$/', $line, $matches)) { $out[] = '|-sub-block '.resolvePokemon($matches[1]).' '.resolveMove($matches[2]); } else if (preg_match('/^\<(.+?): \>([^<>]+)$/', $line, $matches)) { $out[] = 'chat '.resolveUsername($matches[1]).' '.$matches[2]; } else if (preg_match('/^\<(.+?): \>\<([^<>]+)\>$/', $line, $matches)) { $out[] = 'chat '.resolveUsername($matches[1]).' '.$matches[2]; } else if (preg_match('/^\<(.+?)\>: ([^<>]+)$/', $line, $matches)) { $out[] = 'chat '.resolveUsername($matches[1]).' '.$matches[2]; } else if (preg_match('/^\<([^<>]+) flung its ([^<>]+)!\>$/', $line, $matches)) { $out[] = '|-fling '.resolvePokemon($matches[1]).' '.resolveItem($matches[2]); } else if (preg_match('/^([^<>]+) ate its ([^<>]+)!$/', $line, $matches)) { $out[] = '|-eat '.resolvePokemon($matches[1]).' '.resolveItem($matches[2]); } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .\']+) weakened ([^<>]+)\'s power!$/', $line, $matches)) { $out[] = '|-weaken '.resolvePokemon($matches[1]).' '.resolveMove($matches[3]).' '.resolveItem($matches[2]); } else if (preg_match('/^\<([^<>]+) stole and ate ([^<>]+)\'s ([^<>]+)!\>$/', $line, $matches)) { $out[] = '|-steal-eat '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' '.resolveItem($matches[3]); } else if (preg_match('/^\<([^<>]+)\'s Storm Drain raised its special attack!\>$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' spa 1 StormDrain'; } else if (preg_match('/^\]+)\'s Competitive Spirit sharply raised its Attack!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' atk 2 CompetitiveSpirit'; } else if (preg_match('/^\]+)\'s Lightningrod raised its (Special Attack|special attack)!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' spa 1 Lightningrod'; } else if (preg_match('/^\]+)\'s (Justified|Justice Heart) raised its attack!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' atk 1 Justified'; } else if (preg_match('/^\]+)\'s (Herbivore|Sap Sipper) raised its attack!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' atk 1 SapSipper'; } else if (preg_match('/^\]+)\'s Motor Drive raise(d|s) its speed!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' spe 1 MotorDrive'; } else if (preg_match('/^\]+)\'s (Steadfast|SteadFast) increases its speed!\>?$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' spe 1 Steadfast'; } else if (preg_match('/^([^<>]+)\'s Absorb Bulb raised its Sp. Att.!$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' spa 1 AbsorbBulb'; } else if (preg_match('/^([^<>]+)\'s (Moody|Inconsistent) sharply raises its ([a-zA-Z .\']+)!$/', $line, $matches)) { $out[] = '|-ability-boost '.resolvePokemon($matches[1]).' '.resolveStat($matches[3]).' 2 Moody'; } else if (preg_match('/^([^<>]+)\'s (Moody|Inconsistent) lowers its ([a-zA-Z .\']+)!$/', $line, $matches)) { $out[] = '|-ability-unboost '.resolvePokemon($matches[1]).' '.resolveStat($matches[3]).' 1 Moody'; } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .\']+) raised ([^<>]+)\'s power!$/', $line, $matches)) { $out[] = '|-gem '.resolvePokemon($matches[1]).' '.resolveItem($matches[2]).' '.resolveMove($matches[3]).''; } else if (preg_match('/^The ([a-zA-Z .\']+) raised ([^<>]+)\'s ([a-zA-Z .\']+)!$/', $line, $matches)) { $out[] = '|-item-boost '.resolvePokemon($matches[2]).' '.resolveStat($matches[3]).' 1 '.resolveItem($matches[1]).''; } else if (preg_match('/^\<([^<>]+) switched items with ([^<>]+)!\>$/', $line, $matches)) { $out[] = '|-trick '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]); } else if (preg_match('/^<([^<>]+) obtained one ([a-zA-Z .\']+)!>$/', $line, $matches)) { $out[] = '|-trick-get '.resolvePokemon($matches[1]).' '.resolveItem($matches[2]).''; } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) drastically rose!$/', $line, $matches)) { $out[] = '|-boost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 3'; } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) sharply rose!$/', $line, $matches)) { if ($lastmove === 'TailGlow') { $out[] = '|-boost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 3'; } else { $out[] = '|-boost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 2'; } } else if (preg_match('/^([^<>]+)\'s ([a-zA-Z .]+) rose!$/', $line, $matches)) { $out[] = '|-boost '.resolvePokemon($matches[1]).' '.resolveStat($matches[2]).' 1'; } else if (preg_match('/^\<([^<>]+) stockpiled ([1-3])!\>$/', $line, $matches)) { $out[] = '|-start|'.resolvePokemon($matches[1]).' stockpile'.$matches[2]; } else if (preg_match('/^\<([^<>]+)\'s perish count fell to ([0-3]).\>$/', $line, $matches)) { $out[] = '|-start|'.resolvePokemon($matches[1]).' perish'.$matches[2]; if ($matches[2] === '0') markLastDamage($out); } else if (preg_match('/^([^<>]+) intimidates ([^<>]+)!$/', $line, $matches)) { $out[] = '|-intimidate '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]); } else if (preg_match('/^\<([^<>]+) moved its status onto ([^<>]+)!\>$/', $line, $matches)) { $out[] = '|-psycho-shift '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]); } else if (preg_match('/^\<([^<>]+) took ([^<>]+) down with it!\>$/', $line, $matches)) { $out[] = '|-also-ko '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]); markLastDamage($out); } else if (preg_match('/^\]+)\'s feet!\>$/', $line, $matches)) { $out[] = '|-absorb-spikes '.resolvePokemon($matches[1]).' ToxicSpikes'; } else if (preg_match('/^\<([^<>]+) lost some HP because of Solar Power!\>$/', $line, $matches)) { $out[] = 'residual '.resolvePokemon($matches[1]).' ability-damage SolarPower ??'; markLastDamage($out); } else if (preg_match('/^\<([^<>]+)\'s ([A-Z][a-z]+) Absorb absorbs the attack!\>$/', $line, $matches)) { $out[] = '|-ability-heal '.resolvePokemon($matches[1]).' '.$matches[2].'Absorb ??'; } else if (preg_match('/^\<([^<>]+)\'s ([A-Z][a-z]+) Absorb made the attack useless!\>$/', $line, $matches)) { $out[] = '|-ability-heal '.resolvePokemon($matches[1]).' '.$matches[2].'Absorb ??'; } else if (preg_match('/^([^<>]+)\'s Iron Barbs hurts ([^<>]+)$/', $line, $matches)) { $out[] = '|-ability-damage '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' IronBarbs ??'; resolvePokemon($matches[2]); markLastDamage($out); } else if (preg_match('/^([^<>]+)\'s Rough Skin hurts ([^<>]+)$/', $line, $matches)) { $out[] = '|-ability-damage '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' RoughSkin ??'; resolvePokemon($matches[2]); markLastDamage($out); } else if (preg_match('/^([^<>]+)\'s Aftermath damages ([^<>]+)!$/', $line, $matches)) { $out[] = '|-ability-damage '.resolvePokemon($matches[1]).' '.resolvePokemon($matches[2]).' Aftermath ??'; resolvePokemon($matches[2]); markLastDamage($out); } else if (preg_match('/^\<([^<>]+)\'s ([^<>]+) was bounced back by Magic Mirror!\>$/', $line, $matches)) { $out[] = '|-bounce-back '.resolvePokemon($matches[1]).' MagicMirror '.resolveMove($matches[2]); } else if (preg_match('/^\<([^<>]+)\'s ([^<>]+) was bounced back by Magic Coat!\>$/', $line, $matches)) { $out[] = '|-bounce-back '.resolvePokemon($matches[1]).' MagicCoat '.resolveMove($matches[2]); } else if (preg_match('/^\]+) and ([^<>]+) is underway!\>$/', $line, $matches)) { $out[] = 'player '.$matches[1]; $out[] = 'foe-player '.$matches[2]; $out[] = 'start'; $allyname = resolveUsername($matches[1]); $playernames = array($matches[1],$matches[2]); $english = 'warn'; } else if (preg_match('/^\]+) and ([^<>]+) started!\>$/', $line, $matches)) { if ($allyname === '' && $convertloopnum === 0) { $convertNotDone = true; } else if ($allyname === resolveUsername($matches[1]) || (substr($allyname, 0,6) === 'foeof-' && substr($allyname, 6) === resolveUsername($matches[2]))) { $out[] = 'player '.$matches[1]; $out[] = 'foe-player '.$matches[2]; $out[] = 'start'; $allyname = resolveUsername($matches[1]); $playernames = array($matches[1],$matches[2]); } else { $out[] = 'player '.$matches[2]; $out[] = 'foe-player '.$matches[1]; $out[] = 'start'; $allyname = resolveUsername($matches[2]); $playernames = array($matches[2],$matches[1]); } $english = true; } else if (preg_match('/^\<([^<>]+) won the battle!\>$/', $line, $matches)) { $winner = $matches[1]; } else if (preg_match('/^\]+) and ([^<>]+)!\>$/', $line, $matches)) { $winner = true; } else if (preg_match('/^Hit ([0-9]) times!$/', $line, $matches)) { $out[] = '|-hit-count '.$movetarget.' '.$matches[1]; } else { $out[] = 'unknown-effect '.$newline; } if ($returnNow) { return false; } } if (!$english) { $convertNotDone = false; if (@$_REQUEST['dev']) echo '"'.implode("\n", $text).'"'; return array('error Replay file must be an English Pokemon Online replay file.'); } if ($switchcounter === 104) { return array('error Double battles are not supported (neither are triples, for that matter).'); } if ($switchcounter === 106) { return array('error Triple battles are not supported (neither are doubles, for that matter).'); } if ($winner === true) $out[] = 'tie'; else if ($winner) $out[] = 'win '.$winner; else $out[] = 'premature-end'; foreach ($currentpokemon as $poke) { $oldlinesoffset++; array_unshift($out, 'pokemon '.$poke); } { $oldlinesoffset++; array_unshift($out, 'gen '.$GLOBALS['gen']); } if ($english === 'warn' && $switchcounter !== 102) { $oldlinesoffset++; array_unshift($out, 'warning This is a spectator replay. Crashes may occur since the game may have been joined midway-through.'); } return $out; } function convertById($name) { global $REPLAYS; if (!$REPLAYS[$name]) { return; } $text = file_get_contents("uploads/$name.html"); $out = pokeConvert($text); if (substr($out[0],0,6) === 'error ') { return $out; } $fp = fopen("uploads/$name.js",'w'); fwrite($fp, "var newlog = [\n"); foreach ($out as $line) { fwrite($fp, "'".addcslashes($line,"'\\")."', \n"); } fwrite($fp, "''];"); fclose($fp); $fp = fopen("uploads/$name.txt",'w'); foreach ($out as $line) fwrite($fp, $line."\r\n"); fclose($fp); $REPLAYS[$name]['unidentified'] = array(); $REPLAYS[$name]['tags'] = array(); $lsreflect = array(); foreach ($out as $line) { if (startsWith($line, '|-bounce-back ') && strpos($line, ' MagicCoat ')) $REPLAYS[$name]['tags'][] = 'Magic Coat'; if (startsWith($line, '|-transform ')) $REPLAYS[$name]['tags'][] = 'Transform'; if (startsWith($line, 'move ') && strpos($line, ' RelicSong ')) $REPLAYS[$name]['tags'][] = 'Relic Song'; if (endsWith($line, ' LightScreen')) $lsreflect['ls'] = true; if (endsWith($line, ' Reflect')) $lsreflect['r'] = true; if (endsWith($line, ' LightScreen end')) $lsreflect['ls'] = false; if (endsWith($line, ' Reflect end')) $lsreflect['r'] = false; if (startsWith($line, 'unknown-effect ')) $REPLAYS[$name]['unidentified'][] = $line; if (startsRemove($line, 'error ')) $REPLAYS[$name]['error'] = $line; if (startsRemove($line, 'warning ')) $REPLAYS[$name]['tags'][] = 'Warning: '.$line; if ($lsreflect['r'] && $lsreflect['ls']) { $REPLAYS[$name]['tags'][] = 'Dual Screens'; $lsreflect = array(); } } if (!$REPLAYS[$name]['unidentified']) unset($REPLAYS[$name]['unidentified']); persist_save('REPLAYS'); return $out; }