예제 #1
0
 protected function challenge_save($dont_save = null, $auto = null)
 {
     // avgjør vinner
     $winner = CardsPoker::compare($this->solve1, $this->solve2);
     // avgjør gevinst
     $prize = $winner[0] == 0 ? $this->data['poker_cash'] : bcmul($this->data['poker_cash'], 2);
     // oppdater
     $update = $dont_save ? '' : ", poker_challenger_result = {$this->solve2[0]}, poker_state = 4, poker_prize = {$prize}, poker_winner = {$winner[0]}";
     if ($auto && !$dont_save) {
         $update .= ", poker_auto = 1";
     }
     $cards = implode(",", $this->poker2->get_cards());
     $a = \Kofradia\DB::get()->exec("\n\t\t\tUPDATE poker\n\t\t\tSET poker_challenger_cards = " . \Kofradia\DB::quote($cards) . "{$update}\n\t\t\tWHERE poker_id = {$this->id} AND poker_state = 3");
     if ($a == 0) {
         return false;
     }
     if ($dont_save) {
         return true;
     }
     $this->data['poker_challenger_cards'] = $cards;
     $this->data['poker_challenger_result'] = $this->solve2[0];
     $this->data['poker_state'] = 4;
     $this->data['poker_prize'] = $prize;
     $this->data['poker_winner'] = $winner[0];
     $up1 = player::get($this->data['poker_starter_up_id']);
     $up2 = player::get($this->data['poker_challenger_up_id']);
     switch ($winner[0]) {
         // starter vant
         case 1:
             \Kofradia\DB::get()->exec("\n\t\t\t\t\tUPDATE users_players\n\t\t\t\t\tSET up_cash = up_cash + {$prize}\n\t\t\t\t\tWHERE up_id = {$this->data['poker_starter_up_id']}");
             $up1->data['up_cash'] = bcadd($up1->data['up_cash'], $prize);
             putlog("SPAMLOG", "%bPOKER%b: %u{$up2->data['up_name']}%u tapte (" . strip_tags($this->text2) . "). %u{$up1->data['up_name']}%u vant %u" . game::format_cash($prize) . "%u (" . strip_tags($this->text1) . ")");
             break;
             // utfordrer vant
         // utfordrer vant
         case 2:
             \Kofradia\DB::get()->exec("\n\t\t\t\t\tUPDATE users_players\n\t\t\t\t\tSET up_cash = up_cash + {$prize}\n\t\t\t\t\tWHERE up_id = {$this->data['poker_challenger_up_id']}");
             $up2->data['up_cash'] = bcadd($up2->data['up_cash'], $prize);
             putlog("SPAMLOG", "%bPOKER%b: %u{$up2->data['up_name']}%u vant %u" . game::format_cash($prize) . "%u (" . strip_tags($this->text2) . "). %u{$up1->data['up_name']}%u tapte (" . strip_tags($this->text1) . ")");
             break;
             // uavgjort
         // uavgjort
         default:
             \Kofradia\DB::get()->exec("\n\t\t\t\t\tUPDATE users_players\n\t\t\t\t\tSET up_cash = up_cash + {$prize}\n\t\t\t\t\tWHERE up_id IN ({$this->data['poker_starter_up_id']}, {$this->data['poker_challenger_up_id']})");
             $up1->data['up_cash'] = bcadd($up1->data['up_cash'], $prize);
             $up2->data['up_cash'] = bcadd($up2->data['up_cash'], $prize);
             putlog("SPAMLOG", "%bPOKER%b: %u{$up2->data['up_name']}%u (" . strip_tags($this->text2) . ") uavgjort mot %u{$up1->data['up_name']}%u (" . strip_tags($this->text1) . ")  - Begge fikk %u" . game::format_cash($prize) . "%u");
     }
     // trigger
     $up1->trigger("poker_result", array("won" => $winner[0] == 0 ? 0 : ($winner[0] == 1 ? 1 : -1), "cash" => $this->data['poker_cash'], "prize" => $prize, "opponent" => $up2));
     $up2->trigger("poker_result", array("won" => $winner[0] == 0 ? 0 : ($winner[0] == 1 ? -1 : 1), "cash" => $this->data['poker_cash'], "prize" => $prize, "opponent" => $up1));
     return array($winner, $prize, $up1, $up2);
 }
예제 #2
0
    $status->update("finish", 1);
    login::$user->player->oppdrag->update_status($oppdrag['o_id'], $status);
    redirect::handle();
}
// ferdig?
$success = false;
if ($finish) {
    $poker = new CardsPoker(explode(",", $cards));
    $poker_pc = new CardsPoker(explode(",", $status->get("cards_pc")));
    $poker_pc->remove_cards(explode(",", $status->get("cards_used")));
    // spill for pcen
    $poker_pc->play();
    $solve = $poker->solve();
    $solve_pc = $poker_pc->solve();
    // hvem vant?
    $won = CardsPoker::compare($solve, $solve_pc);
    if ($won[0] == 1) {
        // brukeren vant -- gi tilbake nye chips
        $chips = $chips + $status->get("bet");
    } elseif ($won[0] == 2) {
        // pcen vant -- trekk fra chips
        $chips = $chips - $status->get("bet");
    }
    $status->update("chips", $chips);
    $cards = false;
    $status->remove("cards");
    $status->remove("cards_pc");
    $status->remove("finish");
    $status->remove("cards_used");
    login::$user->player->oppdrag->update_status($oppdrag['o_id'], $status);
    // ingen flere chips?
예제 #3
0
파일: poker.php 프로젝트: Kuzat/kofradia
    protected function stats_row($row, $starter, $i)
    {
        $poker1 = new CardsPoker(explode(",", $row['poker_starter_cards']));
        $solve1 = $poker1->solve();
        $text1 = $poker1->solve_text($solve1);
        $poker2 = new CardsPoker(explode(",", $row['poker_challenger_cards']));
        $solve2 = $poker2->solve();
        $text2 = $poker2->solve_text($solve2);
        $winner = CardsPoker::compare($solve1, $solve2);
        return '
					<tr' . ($i % 2 == 0 ? ' class="color"' : '') . '>
						<td><user id="' . $row['poker_' . ($starter ? 'challenger' : 'starter') . '_up_id'] . '" /></td>
						<td><span class="dark">' . ess::$b->date->get($row['poker_time_challenge'])->format() . '</span><br />' . game::timespan($row['poker_time_challenge'], game::TIME_ABS) . '</td>
						<td>' . ($starter ? $text1 : $text2) . '<br /><span style="color: #888">' . ($starter ? $text2 : $text1) . '</span></td>
						<td class="r">' . game::format_cash($row['poker_cash']) . '</td>' . ($winner[0] == 0 ? '
						<td>Uavgjort</td>' : ($winner[0] == 1 && $starter || $winner[0] == 2 && !$starter ? '
						<td class="vi"><b>Vant!</b><br />' . game::format_cash($row['poker_prize']) . '</td>' : '
						<td class="ta"><b>Tapte..</b></td>')) . '
					</tr>';
    }