battles/_unused-files/hellround.php

121 lines
5.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php // #!/usr/bin/php
// демон, запускающий волны
$names = array("Слуга хаоса","Котельщик","Надсмотрищик","Кожекрылый","Валькирия","Грешная Душа","Падший Ангел","Падший Ангел","Дьявол");
$bots = array(79,80,81,82,83,84,85,86,87);
$shema = array ( "79" => 4,
"80" => 4,
"81" => 2,
"82" => 2,
"83" => 2,
"84" => 1,
"85" => 1,
"86" => 1,
"87" => 1,
);
// подключаем конфиг
// include "../connect.php";
// подключаем функции
// include "../functions.php";
// циклим демона
// while(1) {
// итерация
// есть ли конект с базой
$test = mysql_fetch_array(mysql_query("SELECT 1;"));
if($test[1]!=1) {
// include "../connect.php";
}
// выбираем все походы
$pohs = mysql_query("SELECT `owner`,`volna`,`id` FROM `hellround_pohod` WHERE `end` = 0;");
while ($poh = mysql_fetch_array($pohs)) {
// проверяем на живность
$u = mysql_fetch_array(mysql_query("SELECT `hp` FROM `users` WHERE `id` = '".$poh['owner']."' LIMIT 1;"));
if($u['hp'] <= 0) {
// удаляем ресурсы
mysql_query("DELETE FROM `inventory` WHERE `owner` = '".$poh['owner']."' AND `bs` = 1;");
mysql_query("UPDATE `hellround_pohod` SET `end` = 1, `date_out` = NOW( ) WHERE `id` = ".$poh['id']." AND `end` = 0;");
addchp ('<font color=red>Внимание!</font> Вы погибли в противостоянии хаосу...<BR>\'; top.frames[\'main\'].location=\'main.php\'; var z = \' ','{[]}'.nick7 ($poh['owner']).'{[]}');
echo "USER: ".$poh['owner']." live trip.\n";
} else
{
// забираем последний бой, может пора запускать волну?
$last_a = mysql_fetch_array(mysql_query("SELECT `id` FROM `battle` WHERE `t1` = '".$poh['owner']."' AND `win` = 3 ORDER by `id` DESC LIMIT 1;"));
$last_b = mysql_fetch_array(mysql_query("SELECT `to1` FROM `battle` WHERE `t1` = '".$poh['owner']."' AND `win` <> 3 ORDER by `id` DESC LIMIT 1;"));
$last_b = $last_b[0];
$last_a = $last_a[0];
// echo $last_a." ".$last_b." ".$poh['owner']."\n";
// проверяем, запускаем ботов
if ((time()-$last_b) >= 60 && $last_a == 0) {
// если прошло больше минуты, стартуем волну
$nextvolna = $poh['volna']+1;
$bot[1] = $shema[$bots[0]]*$nextvolna;
$bot[2] = $shema[$bots[1]]*$nextvolna;
$bot[3] = $shema[$bots[2]]*$nextvolna;
if ($nextvolna >= 10) {
$bot[4] = $shema[$bots[3]]*$nextvolna;
$bot[5] = $shema[$bots[4]]*$nextvolna;
$bot[6] = $shema[$bots[5]]*$nextvolna;
}
if ($nextvolna >= 25) {
$bot[7] = $shema[$bots[6]]*$nextvolna;
$bot[8] = $shema[$bots[7]]*$nextvolna;
$bot[9] = $shema[$bots[8]]*$nextvolna;
}
// делаем массив с айдишниками ботов
for($n = 1; $n <= 9; $n++) {
for($i = 1; $i <= (int)$bot[$n]; $i++){
$botz = mysql_fetch_array(mysql_query("SELECT `maxhp`,`id` FROM `users` WHERE `id` = '".$bots[$n-1]."' LIMIT 1;"));
mysql_query("INSERT INTO `bots` (`name`,`prototype`,`battle`,`hp`) values ('".$names[$n]." (проекция ".($i).")','".$bots[$n-1]."','','".$botz['maxhp']."');");
$botz = mysql_insert_id();
$enemys[] = $botz;
}
}
// array of teams
$teams = array();
foreach($enemys as $v) {
$teams[$poh['owner']][$v] = array(0,0,time());
$teams[$v][$poh['owner']] = array(0,0,time());
}
// запись о битве
mysql_query("INSERT INTO `battle`
(
`id`,`coment`,`teams`,`timeout`,`type`,`status`,`t1`,`t2`,`to1`,`to2`
)
VALUES
(
NULL,'','".serialize($teams)."','3','1','0','".$poh['owner']."','".implode(";",$enemys)."','".time()."','".time()."'
)");
$id = mysql_insert_id();
// апдейтим бота
foreach($enemys as $v) {
mysql_query("UPDATE `bots` SET `battle` = ".$id." WHERE `id` = ".$v." LIMIT 1;");
}
// создаем лог
//$rr = "<b>".nick3($user['id'])."</b> и <b>".nick3($bot)."</b>";
//mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу. <BR>');");
addlog($id,"Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда <b>".nick3($poh['owner'])."</b> вышел на битву с Адом... <BR>");
chown ("backup/logs/battle".$id.".txt" , "www-data" );
chgrp ("backup/logs/battle".$id.".txt" , "www-data" );
mysql_query("UPDATE users SET `battle` =".$id.",`zayavka`=0 WHERE `id`= ".$poh['owner'].";");
addchp ('<font color=red>Внимание!</font> Новое пришествие...<BR>\'; top.frames[\'main\'].location=\'fbattle.php\'; var z = \' ','{[]}'.nick7 ($poh['owner']).'{[]}');
mysql_query("UPDATE `hellround_pohod` SET `volna`=`volna`+1 WHERE `id` = ".$poh['id']." LIMIT 1;");
echo "USER: ".$poh['owner']." New wave.\n";
}
}
// задержка
sleep(5);
}
// }
?>