battles/buy.php

56 lines
2.0 KiB
PHP
Raw Normal View History

<?php
//Покупка абилок? Тут?!
session_start();
2020-09-30 12:48:53 +00:00
if (empty($_SESSION['uid'])) {
header('Location: Index.php');
exit;
}
include('config.php');
$is_now = db::c()->query('SELECT `id`, `uid` FROM `abils_user` WHERE `uid` = ?i', $user['id'])->fetch_assoc();
function add_user_abil($ab, $cost)
{
global $user, $banks;
if (isset($ab) && $banks['ekr'] >= $cost) {
$isset = mysql_fetch_array(mysql_query('SELECT `id`, `' . $ab . '` FROM `abils_user` WHERE `uid` = "' . $user['id'] . '" LIMIT 1'));
$isset[$ab] += 1;
2020-09-30 12:48:53 +00:00
mysql_query('UPDATE `abils_user` SET `' . $ab . '` = "' . $isset[$ab] . '" WHERE `uid` = "' . $user['id'] . '"');
$banks['ekr'] -= $cost;
2020-09-30 12:48:53 +00:00
mysql_query('UPDATE `bank` SET `ekr` = "' . $banks['ekr'] . '" WHERE `id` = "' . $user['id'] . '"');
return true;
}
return false;
}
$cost = [1, 2, 10, 0.50, 0.80, 1, 1, 0.10, 0.20, 4, 0.02, 20, 10, 1, 1];
$mag = ['sleep15', 'sleep30', 'closebattle', 'heal20', 'heal35', 'heal50', 'travmoff', 'attack', 'bloodattack', 'death', 'comment', 'openbattle', 'reamdeath', 'clone', 'unclone'];
if (isset($_POST['type'], $_POST['user'])) {
if (isset($user['id'])) {
$price = $cost[$_POST['type'] - 1];
$abil = $mag[$_POST['type'] - 1];
if (isset($banks['id'])) {
if ($banks['ekr'] >= $price) {
if (isset($is_now['id'])) {
if ($user['battle'] == 0) {
2020-09-30 12:48:53 +00:00
if (add_user_abil($abil, $price)) {
echo 'success';
} else {
echo 'Error';
}
} else {
echo 'Не в бою ...';
}
} else {
echo 1;
}
} else {
echo 'Не хватает средств';
}
} else {
echo '<small>Выберите счёт в банке</small>';
}
} else {
echo "Вы не авторизированы";
}
}