2018-01-29 19:24:30 +00:00
|
|
|
<?php
|
2021-08-27 15:55:18 +00:00
|
|
|
|
|
|
|
use Battles\Bank;
|
|
|
|
use Battles\Database\DBPDO;
|
|
|
|
use Battles\User;
|
|
|
|
|
|
|
|
require_once "functions.php";
|
|
|
|
if (User::$current->getBattle()) {
|
|
|
|
exit();
|
2020-09-30 12:48:53 +00:00
|
|
|
}
|
2021-08-27 15:55:18 +00:00
|
|
|
const PRICES = [
|
|
|
|
'sleep15' => 20,
|
|
|
|
'sleep30' => 20,
|
|
|
|
'closebattle' => 100,
|
|
|
|
'heal20' => 10,
|
|
|
|
'heal35' => 25,
|
|
|
|
'heal50' => 50,
|
|
|
|
'travmoff' => 10,
|
|
|
|
'attack' => 10,
|
|
|
|
'bloodattack' => 25,
|
|
|
|
'death' => 100,
|
|
|
|
'comment' => 5,
|
|
|
|
'openbattle' => 100,
|
|
|
|
'reamdeath' => 50,
|
|
|
|
'clone' => 25,
|
|
|
|
'unclone' => 25,
|
|
|
|
];
|
2018-01-29 19:24:30 +00:00
|
|
|
|
2021-08-27 15:55:18 +00:00
|
|
|
$check_bonuses = DBPDO::$db->ofetch('select 1 from users_bonuses where user_id = ?', User::$current->getId());
|
|
|
|
|
|
|
|
if (!$check_bonuses) {
|
|
|
|
exit('Запрещено: Вам нельзя покупать бонусы.');
|
|
|
|
}
|
|
|
|
|
|
|
|
function buy_bonus($name): bool
|
2018-07-02 15:35:25 +00:00
|
|
|
{
|
2021-08-27 15:55:18 +00:00
|
|
|
global $prices;
|
|
|
|
$bank = new Bank(User::$current->getId());
|
|
|
|
if ($bank->getMoney() <= PRICES[$name]) {
|
|
|
|
return false;
|
2018-07-02 15:35:25 +00:00
|
|
|
}
|
2021-08-27 15:55:18 +00:00
|
|
|
$query = sprintf('update users_bonuses set %s = %s + 1 where user_id = ?', $name, $name);
|
|
|
|
DBPDO::$db->execute($query, User::$current->getId());
|
|
|
|
$bank->setMoney($bank->getMoney() - $prices[$name]);
|
|
|
|
return true;
|
2018-07-02 15:35:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 15:55:18 +00:00
|
|
|
echo !empty($_POST['type']) && buy_bonus($_POST['type']) ? 'success' : 'error';
|