<?php
define('DB_HOST', 'localhost'); // Сервер
define('DB_NAME', '79998786090'); // Имя базы
define('DB_USER', '79998786090'); // Пользователь
define('DB_PASS', '1122334455'); // Пароль
$db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=UTF8", DB_USER, DB_PASS);


// Создаём заявки на очередь
if ($db->query("SELECT COUNT(*) FROM `demons_battles` WHERE `status` = 'prepare'")->fetchColumn() == false) {

    $db->exec("INSERT INTO `demons_battles`(`status`, `starttime`) VALUES ('prepare', '" . (time() + 600) . "')");
} else {
    // Запускаем бой
    $userList = $db->query("SELECT `health` FROM `demons_players`")->fetchAll();
    $hp = 0;
    foreach ($userList as $health) {
        $hp += $health['health'];
    }

    $healthImp = $hp * 3; // Жизнь помошников демона
    $healthBoss = $hp * 6; // Жизнь демона
    $db->exec("UPDATE `demons_battles` SET `status`= 'battle', `mob_health` = '" . $healthImp . "', `mob_max_health` = '" . $healthImp . "', `health` = '" . $healthBoss . "',`max_health` = '" . $healthBoss . "'");

}




