game/bandit.php
2023-07-31 20:06:51 +03:00

87 lines
2.3 KiB
PHP

<?php
if (!defined('GAME_VERSION')) {
require_once '_incl_data/autoload.php';
}
use Core\Db;
$u = User::start();
if ($u->room['name'] != 'Однорукий бандит') {
die();
}
function roll(int $w1, int $w2, int $w3): array
{
$w = $w1 . $w2 . $w3;
$combo = [
'000' => [50, 0],
'111' => [20, 1],
'222' => [10, 2],
'333' => [4, 3],
'444' => [2, 4],
];
$win = 0;
$n = 99;
if (isset($combo[$w])) {
[$win, $n] = $combo[$w];
} elseif ($w1 == 4 && $w2 == 4 || $w1 == 4 && $w3 == 4 || $w2 == 4 && $w3 == 4) {
// 1 2 3
$win = 1;
$n = 5;
}
return ['win' => $win, 'n' => $n, 'combination' => $w];
}
//Раздаем выйгрыши
$r = '';
if (isset($_GET['bet'])) {
$bet = 1;
if ($_GET['bet'] == 2) {
$bet = 2;
} elseif ($_GET['bet'] == 3) {
$bet = 3;
}
if ($u->info['money2'] >= $bet) {
//Играем!
[$win, $n, $combination] = roll(rand(0, 4), rand(0, 4), rand(0, 4));
if (($n == 5 || $n == 4 || $n == 3) && rand(0, 100) >= 50) {
//Играем!
[$win, $n, $combination] = roll(rand(0, 2), rand(0, 3), rand(0, 3));
}
//
$u->info['money2'] -= $bet;
$u->info['money2'] += $bet * $win;
$u->addEkr($bet * $win - $bet);
//
Db::sql('insert into bandit (uid, time, room, s, wm, w) VALUES (?,unix_timestamp(), ?, ?, ?, ?)',
[$u->info['id'], $u->info['room'], $bet, $bet * $win, $combination]);
$gid = Db::lastInsertId();
//
if ($win > 0) {
$prize = $bet * $win;
$chatDto = new ChatMessage();
$chatDto->setCity($u->info['city']);
$chatDto->setRoom(390);
$chatDto->setLogin('<span style="color: #0066FF">Крупье</span>');
$chatDto->setText("<small>Игрок {$u->info['login']} выиграл $prize екр, ставка $bet екр, игра №$gid</small>");
$chatDto->setType(6);
(new Chat())->sendMsg($chatDto);
}
//
$r .= 'cash=' . floor($u->info['money2']);
$r .= '&combination=' . $combination . '&n=' . $n . '&win=' . ($bet * $win);
}
} else {
$r .= 'cash=' . floor($u->info['money2']);
}
echo $r;