Beispiel #1
0
function complete_trade($tradeid)
{
    //Removes trainer1's pokemon and gives them to trainer 2. Then vice versa. Then marks the trade as completed. As a traded pokemon is not "caught", supply a $source other than organic to capture_pokemon().
    global $file_db;
    //Bring up this trade's data.
    $tradedata = $file_db->query("SELECT * FROM trades WHERE id=" . $tradeid . "")->fetchAll();
    //Build our arrays ready for the switcheroo.
    $pokemon1 = explode(',', $tradedata[0]['pokemon1']);
    $pokemon2 = explode(',', $tradedata[0]['pokemon2']);
    //First up, trainer1. Say goodbye to your pokemon.
    $r1 = release_pokemon($tradedata[0]['trainer1'], $pokemon1);
    //Now give these pokemon to trainer2.
    foreach ($pokemon1 as $p1poke) {
        dex_pokemon($tradedata[0]['trainer2'], round($p1poke));
        capture_pokemon($tradedata[0]['trainer2'], $p1poke, $source = "trade");
    }
    //Now it's trainer 2's turn.
    $r2 = release_pokemon($tradedata[0]['trainer2'], $pokemon2);
    //Now give these pokemon to trainer1.
    foreach ($pokemon2 as $p2poke) {
        dex_pokemon($tradedata[0]['trainer1'], round($p2poke));
        capture_pokemon($tradedata[0]['trainer1'], $p2poke, $source = "trade");
    }
    //Release the trade slots for both users.
    releasetrade($tradedata[0]['trainer1'], $tradeid, $reason = "complete");
    releasetrade($tradedata[0]['trainer2'], $tradeid, $reason = "complete");
    //Add this successful trade to the log.
    $file_db->exec("INSERT INTO tradelog (\n\t\t\t\ttrainer1, \n\t\t\t\ttrainer2, \n\t\t\t\tpokemon1, \n\t\t\t\tpokemon2,\n\t\t\t\tdate)\n\t\tVALUES (\n\t\t\t\t" . $tradedata[0]['trainer1'] . ", \n\t\t\t\t" . $tradedata[0]['trainer2'] . ",\n\t\t\t\t'" . $tradedata[0]['pokemon1'] . "',\n\t\t\t\t'" . $tradedata[0]['pokemon2'] . "',\n\t\t\t\t" . time() . ")\n\t\t\t\t");
    //Increase our total trades stat.
    $file_db->exec('UPDATE stats
							SET total_trades = total_trades + 1');
    //Finally, this trade is now complete!
    $file_db->exec("UPDATE trades\n\t\t\t\t\t\t\tSET stage=99\n\t\t\t\t\t\t\tWHERE id=" . $tradeid . "");
}
Beispiel #2
0
    //If a form is being submitted, handle it.
    if (isset($_GET['do'])) {
        if ($_POST['sesc'] != $context['session_id']) {
            //We're still checking sessions though.
            layout_above('Error', 'Error');
            echo 'Something went wrong. Try logging out and back in.';
            layout_below();
            exit;
        }
        layout_above('Release Pokemon', 'Release Pokemon');
        if (empty($_POST['poke_release'])) {
            echo 'No pokemon selected!';
            layout_below();
            exit;
        }
        $release = release_pokemon($_GET['release'], $_POST['poke_release']);
        if (is_array($release)) {
            echo '
			<div id="submain" style="min-height: 610px;"><div style="width: 303px; height: 600px; padding:0; margin-left: 10px; margin-bottom: 10px; background: url(images/releasebg.png) top right no-repeat; float:right"></div>
				<h2>Pokemon Released</h2>';
            foreach ($release['released'] as $rp) {
                echo '<div style="border-bottom: 2px dotted #555; line-height: 101px;"><img src="' . $baseurl . 'img/' . (is_shiny($rp) ? 'shiny/' : '') . sprintf("%03d", round($rp)) . '.png" style="float:left;" />
				', $pokemon[round($rp)], '', is_shiny($rp) ? '(Shiny)' : '', '</div>';
            }
            if (!empty($release['orphaned'])) {
                echo '<br><br><h2>Orphaned Pokemon <span title="Pokemon that you no longer own at all">' . $info_symbol . '</span></h2>';
                foreach ($release['orphaned'] as $op) {
                    echo '<div style="border-bottom: 2px dotted #555; line-height: 101px;"><img src="' . $baseurl . 'img/' . (is_shiny($op) ? 'shiny/' : '') . sprintf("%03d", round($op)) . '.png" style="float:left;" />
					', $pokemon[round($op)], '', is_shiny($op) ? '(Shiny)' : '', '</div>';
                }
            }