game/bandit.php

87 lines
2.3 KiB
PHP
Raw Normal View History

2022-06-06 21:30:34 +00:00
<?php
2023-07-11 15:16:35 +00:00
if (!defined('GAME_VERSION')) {
require_once '_incl_data/autoload.php';
}
use Core\Db;
$u = User::start();
2022-06-06 21:30:34 +00:00
2023-01-10 16:29:32 +00:00
if ($u->room['name'] != 'Однорукий бандит') {
die();
}
2023-07-11 15:16:35 +00:00
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],
];
2023-07-11 15:16:35 +00:00
$win = 0;
$n = 99;
2023-07-11 15:16:35 +00:00
if (isset($combo[$w])) {
list($win, $n) = $combo[$w];
} elseif ($w1 == 4 && $w2 == 4 || $w1 == 4 && $w3 == 4 || $w2 == 4 && $w3 == 4) {
// 1 2 3
$win = 1;
$n = 5;
}
2023-07-11 15:16:35 +00:00
return ['win' => $win, 'n' => $n, 'combination' => $w];
}
2023-07-11 15:16:35 +00:00
//Раздаем выйгрыши
$r = '';
if (isset($_GET['bet'])) {
2023-07-11 15:16:35 +00:00
$bet = 1;
if ($_GET['bet'] == 2) {
2023-07-11 15:16:35 +00:00
$bet = 2;
} elseif ($_GET['bet'] == 3) {
2023-07-11 15:16:35 +00:00
$bet = 3;
}
2023-07-11 15:16:35 +00:00
if ($u->info['money2'] >= $bet) {
2023-01-10 16:29:32 +00:00
//Играем!
2023-07-11 15:16:35 +00:00
list($win, $n, $combination) = roll(rand(0, 4), rand(0, 4), rand(0, 4));
if (($n == 5 || $n == 4 || $n == 3) && rand(0, 100) >= 50) {
2023-01-10 16:29:32 +00:00
//Играем!
2023-07-11 15:16:35 +00:00
list($win, $n, $combination) = roll(rand(0, 2), rand(0, 3), rand(0, 3));
}
//
2023-07-11 15:16:35 +00:00
$u->info['money2'] -= $bet;
$u->info['money2'] += $bet * $win;
$u->addEkr($bet * $win - $bet);
//
2023-07-11 15:16:35 +00:00
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) {
2023-07-11 15:16:35 +00:00
$prize = $bet * $win;
2023-01-28 02:24:37 +00:00
$chatDto = new ChatMessage();
$chatDto->setCity($u->info['city']);
$chatDto->setRoom(390);
$chatDto->setLogin('<span style="color: #0066FF">Крупье</span>');
2023-07-11 15:16:35 +00:00
$chatDto->setText("<small>Игрок {$u->info['login']} выиграл $prize екр, ставка $bet екр, игра №$gid</small>");
2023-01-28 02:24:37 +00:00
$chatDto->setType(6);
(new Chat())->sendMsg($chatDto);
}
//
2023-07-11 15:16:35 +00:00
$r .= 'cash=' . floor($u->info['money2']);
$r .= '&combination=' . $combination . '&n=' . $n . '&win=' . ($bet * $win);
}
} else {
2023-07-11 15:16:35 +00:00
$r .= 'cash=' . floor($u->info['money2']);
2022-06-06 21:30:34 +00:00
}
echo $r;