battles/daemons/arch_.php

188 lines
14 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
#!/usr/bin/php
<?php
include("../config.php");
include("../functions.php");
$data = mysql_fetch_array(mysql_query("SELECT * FROM `deztow_turnir` WHERE `active` = TRUE"));
$starttime = time();
while(1) {
$ls = mysql_fetch_array(mysql_query("SELECT COUNT(`id`), SUM(`bot`) FROM `users` WHERE `in_tower` = 1"));
while(($ls[0]-$ls[1]) < 2 || $arch['room'] < 500) {
$test = mysql_fetch_array(mysql_query("SELECT 1"));
if($test[1] != 1) {
include("../config.php");
}
$data = mysql_fetch_array(mysql_query("SELECT * FROM `deztow_turnir` WHERE `active` = TRUE"));
$starttime = time();
$ls = mysql_fetch_array(mysql_query("SELECT COUNT(`id`), SUM(`bot`) FROM `users` WHERE `in_tower` = 1"));
$arch = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '233' LIMIT 1"));
exec('echo "'.date("Y-m-d H:i:s").'[WAIT] waiting for tournir" > /var/log/arch.log');
sleep(5);
}
$arch = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '233' LIMIT 1"));
$arha = mysql_fetch_array(mysql_query("SELECT * FROM `bots` WHERE `prototype` = '233' LIMIT 1"));
$user = $arch;
$rhar = array("501" => array (20,0,502,505,0),"502" => array (15,0,0,0,501),"503" => array (15,0,0,507,0),"504" => array (15,0,0,508,0),"505" => array (20,501,0,510,0),"506" => array (15,0,507,511,0),"507" => array (15,503,508,0,506),"508" => array (25,504,0,513,507),"509" => array (20,0,0,515,0),"510" => array (20,505,511,0,0),"511" => array (20,506,0,0,510),"512" => array (30,0,513,519,0),"513" => array (25,508,514,0,512),"514" => array (20,0,0,0,513),"515" => array (20,509,0,522,0),"516" => array (25,0,517,523,0),"517" => array (25,0,518,0,516),"518" => array (35,0,519,525,517),"519" => array (35,512,520,526,518),"520" => array (35,0,521,0,519),"521" => array (15,0,0,528,0),"522" => array (20,515,0,529,0),"523" => array (15,516,0,530,0),"524" => array (20,0,525,531,0),"525" => array (35,518,526,532,524),"526" => array (40,519,527,533,525),"527" => array (35,0,0,0,526),"528" => array (15,521,529,535,0),"529" => array (20,522,0,0,528),"530" => array (20,523,531,537,0),"531" => array (35,524,0,538,530),"532" => array (20,525,533,539,0),"533" => array (20,526,534,540,532),"534" => array (15,0,0,0,533),"535" => array (20,528,0,541,0),"536" => array (20,0,537,0,535),"537" => array (35,530,0,543,536),"538" => array (20,531,0,544,0),"539" => array (20,532,0,545,0),"540" => array (15,533,0,546,0),"541" => array (20,535,542,547,0),"542" => array (15,0,543,0,541),"543" => array (40,537,544,549,542),"544" => array (40,538,545,550,543),"545" => array (40,539,0,551,544),"546" => array (15,540,0,552,0),"547" => array (20,541,548,553,0),"548" => array (20,0,549,0,547),"549" => array (35,543,550,0,548),"550" => array (40,544,551,554,549),"551" => array (40,545,0,555,550),"552" => array (15,546,0,556,0),"553" => array (20,547,0,557,0),"554" => array (20,550,555,0,0),"555" => array (35,551,0,0,554),"556" => array (15,552,0,559,0),"557" => array (15,553,0,0,0),"558" => array (20,0,559,0,0),"559" => array (20,556,560,0,558),"560" => array (20,0,0,0,559));
$nextroom = mt_rand(1, 4);
if(time()-$movetime >= $rhar[$arch['room']][0] && $rhar[$arch['room']][$nextroom] > 0 && !$arha['battle']) {
$movetime = time();
$list = mysql_query("SELECT `id`, `room`, `login` FROM `users` WHERE `room` = '".$arch['room']."' AND `in_tower` = 1");
while($u = mysql_fetch_array($list)) {
addchp('<font color=red>Внимание!</font> <b>Архивариус</b> отправился в <b>'.$rooms[$rhar[$arch['room']][$nextroom]].'</b>.', '{[]}'.$u['login'].'{[]}');
}
$arch['room'] = $rhar[$arch['room']][$nextroom];
$list = mysql_query("SELECT `id`, `room`, `login` FROM `users` WHERE `room` = '".$arch['room']."' AND `in_tower` = 1");
while($u = mysql_fetch_array($list)) {
addchp('<font color=red>Внимание!</font> <b>Архивариус</b> вошел в комнату.', '{[]}'.$u['login'].'{[]}');
}
#exec("echo \"".date("Y-m-d H:i:s")."[MOVE] ".$arch['room']."\" >> /var/log/arch.log");
mysql_query("UPDATE `users`, `online` SET `users`.`room` = '".$arch['room']."', `online`.`room` = '".$arch['room']."' WHERE `online`.`id` = `users`.`id` AND `online`.`id` = '233'");
}
$d = mysql_fetch_array(mysql_query("SELECT SUM(`massa`) FROM `inventory` WHERE `owner` = '233' AND `dressed` = 0"));
if($d[0] < $arch['sila']*4 && !$arha['battle']) {
$objs = mysql_query("SELECT * FROM `deztow_items` WHERE `name` != 'Чек на предьявителя' AND `room` = '".$arch['room']."' LIMIT 1");
while($obj = mysql_fetch_array($objs)) {
mysql_query("DELETE FROM `deztow_items` WHERE `id` = '".$obj['id']."' LIMIT 1");
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `shop` WHERE `id` = '".$obj['iteam_id']."' LIMIT 1"));
mysql_query("INSERT INTO `inventory` (`prototype`,`owner`,`name`,`type`,`massa`,`cost`,`img`,`maxdur`,`isrep`,`gsila`,`glovk`,`ginta`,`gintel`,`ghp`,`gnoj`,`gtopor`,`gdubina`,`gmech`,`gfire`,`gwater`,`gair`,`gearth`,`glight`,`ggray`,`gdark`,`needident`,`nsila`,`nlovk`,`ninta`,`nintel`,`nmudra`,`nvinos`,`nnoj`,`ntopor`,`ndubina`,`nmech`,`nfire`,`nwater`,`nair`,`nearth`,`nlight`,`ngray`,`ndark`,`mfkrit`,`mfakrit`,`mfuvorot`,`mfauvorot`,`bron1`,`bron2`,`bron3`,`bron4`,`maxu`,`minu`,`magic`,`nlevel`,`nalign`,`dategoden`,`goden`,`otdel`,`gmp`,`gmeshok`,`encicl`,`artefact`,`koll`) VALUES ('{$dress['id']}','233','{$dress['name']}','{$dress['type']}',{$dress['massa']},{$dress['cost']},'{$dress['img']}',{$dress['maxdur']},{$dress['isrep']},'{$dress['gsila']}','{$dress['glovk']}','{$dress['ginta']}','{$dress['gintel']}','{$dress['ghp']}','{$dress['gnoj']}','{$dress['gtopor']}','{$dress['gdubina']}','{$dress['gmech']}','{$dress['gfire']}','{$dress['gwater']}','{$dress['gair']}','{$dress['gearth']}','{$dress['glight']}','{$dress['ggray']}','{$dress['gdark']}','{$dress['needident']}','{$dress['nsila']}','{$dress['nlovk']}','{$dress['ninta']}','{$dress['nintel']}','{$dress['nmudra']}','{$dress['nvinos']}','{$dress['nnoj']}','{$dress['ntopor']}','{$dress['ndubina']}','{$dress['nmech']}','{$dress['nfire']}','{$dress['nwater']}','{$dress['nair']}','{$dress['nearth']}','{$dress['nlight']}','{$dress['ngray']}','{$dress['ndark']}','{$dress['mfkrit']}','{$dress['mfakrit']}','{$dress['mfuvorot']}','{$dress['mfauvorot']}','{$dress['bron1']}','{$dress['bron2']}','{$dress['bron3']}','{$dress['bron4']}','{$dress['maxu']}','{$dress['minu']}','{$dress['magic']}','{$dress['nlevel']}','{$dress['nalign']}','".(($dress['goden'])?($dress['goden']*24*60*60+time()):"")."','{$dress['goden']}','{$dress['razdel']}','{$dress['gmp']}','{$dress['gmeshok']}','{$dress['encicl']}','{$dress['artefact']}','{$dress[koll]}')");
$iid = mysql_insert_id();
$ncost = $dress['cost'];
$nal = $dress['nalign'];
$nid = $dress['id'];
switch($dress['type']) {
case 1: $slot1 = 'sergi'; break;
case 2: $slot1 = 'kulon'; break;
case 3: $slot1 = 'weap'; break;
case 4: $slot1 = 'bron'; break;
case 5: $slot1 = 'r1'; break;
case 6: $slot1 = 'r2'; break;
case 7: $slot1 = 'r3'; break;
case 8: $slot1 = 'helm'; break;
case 9: $slot1 = 'perchi'; break;
case 10: $slot1 = 'shit'; break;
case 11: $slot1 = 'boots'; break;
}
$dress = mysql_fetch_array(mysql_query("SELECT `cost` FROM `inventory` WHERE `id` = '".$arch[$slot1]."' LIMIT 1"));
if($dress[0] < $ncost && $nal == 0) {
dressitem2($iid);
}
}
}
$pay = mysql_fetch_array(mysql_query("SELECT `present` FROM `inventory` WHERE `owner` = 233 AND `name` = 'Чек на предьявителя';"));
if($pay && !$arha['battle']) {
mysql_query("DELETE FROM `inventory` WHERE `owner` = 233 AND `name` = 'Чек на предьявителя';");
$us = mysql_fetch_array(mysql_query("SELECT `id` FROM `users` WHERE `login` = '".$pay[0]."' LIMIT 1;"));
if(rand(1,2)==1) {
mysql_query("UPDATE `users` SET `money` = `money`+400 WHERE `login` = '".$pay[0]."';");
addchp ('<font color=red>Внимание!</font> <B>Архивариус</B> передал вам <B>400.00 кр</B>. ','{[]}'.$pay[0].'{[]}');
exec("echo \"[PAYMENT] obnal to ".$us['id']."\" >> /var/log/arch.log");
mysql_query('UPDATE `deztow_turnir` SET `log` = CONCAT(`log`,\''."<span class=date>".date("d.m.y H:i")."</span> ".nick3($us['id'])." обналичил чек на <B>400 кр.</B><BR>".'\') WHERE `active` = TRUE');
} else {
mysql_query('UPDATE `deztow_turnir` SET `log` = CONCAT(`log`,\''."<span class=date>".date("d.m.y H:i")."</span> ".nick3(233)." в ярости накинулся на ".nick3($us['id']).".<BR>".'\') WHERE `active` = TRUE');
// начинаем бой
mysql_query("INSERT INTO `bots` (`name`,`prototype`,`battle`,`hp`) values ('Архивариус','233','','".$arch['hp']."');");
$bot = mysql_insert_id();
$teams = array();
$teams[$bot][$jert['id']] = array(0,0,time());
$teams[$jert['id']][$bot] = array(0,0,time());
$sv = array(3,5,7,10);
mysql_query("INSERT INTO `battle` (
`id`,`coment`,`teams`,`timeout`,`type`,`status`,`t1`,`t2`,`to1`,`to2`)
VALUES
(NULL,'','".serialize($teams)."','".$sv[rand(0,3)]."','10','0','".$bot."','".$jert['id']."','".time()."','".time()."')");
}
$id = mysql_insert_id();
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$bot} LIMIT 1;");
mysql_query("UPDATE `users` SET `battle` = {$id} WHERE `id` = {$jert['id']} LIMIT 1;");
// создаем лог
addlog($id,"Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу. <BR>");
//chmod("/backup/logs/battle".$id.".txt",766);
chown ("../backup/logs/battle".$id.".txt" , "www-data" );
chgrp ("../backup/logs/battle".$id.".txt" , "www-data" );
exec("echo \"".date("Y-m-d H:i:s")."[PAYMENT] aggression to ".$jert['id']."\" >> /var/log/arch.log");
mysql_query("UPDATE users SET `battle` ={$id},`zayavka`=0 WHERE `id` = {$jert['id']}");
mysql_query('UPDATE `deztow_turnir` SET `log` = CONCAT(`log`,\''."<span class=date>".date("d.m.y H:i")."</span> ".nick3($bot)." напал на ".nick3($jert['id'])." завязался <a href=\"logs.php?log={$id}\" target=_blank>бой »»</a><BR>".'\') WHERE `active` = TRUE');
$archa['battle'] = $id;
}
// нападаем на юзверей
if(($starttime+180) <= time() AND !$arha['battle']) {
$jert = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `room` = '".$arch['room']."' AND `in_tower`=1 AND `id`<>233 LIMIT 1;"));
//print_r($jert);
if($jert['hp'] > 0 && ($jert['id']!=233)) {
if($jert['battle'] > 0) {
// вмешиваемся
mysql_query("INSERT INTO `bots` (`name`,`prototype`,`battle`,`hp`) values ('Архивариус','233','','".$arch['hp']."');");
$bot = mysql_insert_id();
$bd = mysql_fetch_array(mysql_query ('SELECT * FROM `battle` WHERE `id` = '.$jert['battle'].' LIMIT 1;'));
$battle = unserialize($bd['teams']);
$ak = array_keys($battle[$jert['id']]);
$battle[$bot] = $battle[$ak[0]];
foreach($battle[$bot] as $k => $v) {
$battle[$k][$bot] = array(0,0,time());
}
$t1 = explode(";",$bd['t1']);
// проставляем кто-где
if (in_array ($jert['id'],$t1)) {
$ttt = 2;
} else {
$ttt = 1;
}
addlog($jert['battle'],'<span class=date>'.date("H:i").'</span> '.nick5($bot,"B".$ttt).' вмешался в поединок!<BR>\') WHERE `id` = '.$jert['battle'].'');
exec("echo \"".date("Y-m-d H:i:s")."[AGRESSION] in battle to ".$jert['id']."\" >> /var/log/arch.log");
mysql_query('UPDATE `battle` SET `teams` = \''.serialize($battle).'\', `t'.$ttt.'`=CONCAT(`t'.$ttt.'`,\';'.$bot.'\') WHERE `id` = '.$jert['battle'].' ;');
mysql_query("UPDATE bots SET `battle` =".$jert['battle']." WHERE `id`= ".$bot);
mysql_query('UPDATE `deztow_turnir` SET `log` = CONCAT(`log`,\''."<span class=date>".date("d.m.y H:i")."</span> ".nick3($bot)." вмешался в поединок <a href=\"logs.php?log={$jert['battle']}\" target=_blank>»»</a><BR>".'\') WHERE `active` = TRUE;');
}else
{
// начинаем бой
mysql_query("INSERT INTO `bots` (`name`,`prototype`,`battle`,`hp`) values ('Архивариус','233','','".$arch['hp']."');");
$bot = mysql_insert_id();
$teams = array();
$teams[$bot][$jert['id']] = array(0,0,time());
$teams[$jert['id']][$bot] = array(0,0,time());
$sv = array(3,5,7,10);
//$tou = array_rand($sv,1);
exec("echo \"".date("Y-m-d H:i:s")."[AGRESSION] to ".$jert['id']."\" >> /var/log/arch.log");
mysql_query("INSERT INTO `battle`
(
`id`,`coment`,`teams`,`timeout`,`type`,`status`,`t1`,`t2`,`to1`,`to2`
)
VALUES
(
NULL,'','".serialize($teams)."','".$sv[rand(0,3)]."','10','0','".$bot."','".$jert['id']."','".time()."','".time()."'
)");
$id = mysql_insert_id();
// апдейтим врага
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$bot} LIMIT 1;");
mysql_query("UPDATE `users` SET `battle` = {$id} WHERE `id` = {$jert['id']} LIMIT 1;");
// создаем лог
$rr = "<b>".nick3($bot)."</b> и <b>".nick3($jert['id'])."</b>";
addlog($id,"Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу. <BR>");
//chmod("/backup/logs/battle".$id.".txt",766);
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` = {$jert['id']}");
mysql_query('UPDATE `deztow_turnir` SET `log` = CONCAT(`log`,\''."<span class=date>".date("d.m.y H:i")."</span> ".nick3($bot)." напал на ".nick3($jert['id'])." завязался <a href=\"logs.php?log={$id}\" target=_blank>бой »»</a><BR>".'\') WHERE `active` = TRUE');
}
}
}
sleep(5);
}
?>