2018-01-29 19:24:30 +00:00
|
|
|
<?php
|
2021-08-27 15:55:18 +00:00
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
use Battles\Database\Db;
|
2021-08-27 15:55:18 +00:00
|
|
|
use Battles\User;
|
|
|
|
|
2020-09-30 12:52:51 +00:00
|
|
|
require_once "functions.php";
|
2022-01-26 23:15:33 +00:00
|
|
|
if (!User::getInstance()->getClan() || User::getInstance()->getBattle()) {
|
2021-08-27 15:55:18 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
$check_owner = Db::getInstance()->execute('select short_name from clans where owner_id = ?', User::getInstance()->getId())->fetchColumn();
|
|
|
|
$check_bonuses = Db::getInstance()->execute('select count(*) from clan_bonuses where short_name = ?', User::getInstance()->getClan())->fetchColumn();
|
2021-08-27 15:55:18 +00:00
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
if (User::getInstance()->getClan() !== $check_owner) {
|
2021-08-27 15:55:18 +00:00
|
|
|
exit('Запрещено: Вы не глава клана.');
|
|
|
|
}
|
|
|
|
if (!$check_bonuses) {
|
|
|
|
exit('Запрещено: Вашему клану нельзя покупать бонусы.');
|
2018-01-29 19:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 15:55:18 +00:00
|
|
|
function buy_bonus($name): bool
|
2018-07-02 15:35:25 +00:00
|
|
|
{
|
2022-08-09 19:57:43 +00:00
|
|
|
if (User::getInstance()->money()->getBank() <= PRICES[$name]) {
|
2021-08-27 15:55:18 +00:00
|
|
|
return false;
|
2018-07-02 15:35:25 +00:00
|
|
|
}
|
2022-01-26 23:15:33 +00:00
|
|
|
|
2021-08-27 15:55:18 +00:00
|
|
|
$query = sprintf('update clan_bonuses set %s = %s + 1 where short_name = ?', $name, $name);
|
2022-01-26 23:15:33 +00:00
|
|
|
Db::getInstance()->execute($query, User::getInstance()->getClan());
|
2022-08-09 19:57:43 +00:00
|
|
|
User::getInstance()->money()->modifyBank(-PRICES[$name]);
|
2021-08-27 15:55:18 +00:00
|
|
|
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';
|