battles/cronjobs/cron.php

539 lines
27 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
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
include_once '../config.php';
include_once '../functions.php';
$tm = time();
##########
$zayavka = db::c()->query('SELECT `id`,`start`,`level`,`t1c`,`team1`,`t2c`,`team2` FROM `zayavka`')->fetch_assoc();
while($zayavka) {
if($zayavka['start'] <= time()) {
if($zayavka['level'] == 4 || (($zayavka['t1c'] == count($zayavka['team1'])) && ($zayavka['t2c'] == count($zayavka['team2'])))) {
startbattle("CHAOS", $zayavka['id'], 4);
} elseif($zayavka['level'] == 5) {
startbattle("CHAOS", $zayavka['id'], 5);
}
}
}
function delzayavka($id, $zay, $r, $f = 1) {
$z = getlist($r, null, $zay);
if($f != 1) {
if($z[$zay]['level'] > 3) {
return 'Ай-ай-ай!';
}
}
if(mysql_query("DELETE FROM `zayavka` WHERE `id` = {$zay} AND (`team1` LIKE '{$id};%' OR `team2` LIKE '{$id};%') LIMIT 1")) {
if(count($z[$zay]['team1']) > 0) {
foreach($z[$zay]['team1'] as $k => $v) {
mysql_query("UPDATE `users` SET `zayavka` = 0 WHERE `id` = {$v}");
}
}
if(count($z[$zay]['team2']) > 0) {
foreach($z[$zay]['team2'] as $k => $v) {
mysql_query("UPDATE `users` SET `zayavka` = 0 WHERE `id` = {$v}");
}
}
}
}
function fteam($team) {
$team = explode(";", $team);
unset($team[count($team)-1]);
return $team;
}
function getlist($razdel = 1, $level = null, $id = null ) {
$fict = mysql_query("SELECT * FROM `zayavka` WHERE ".(($level != null)? " ((`t1min` <= '{$level}' OR `t1min` = '99') AND (`t1max` >= '{$level}' OR `t1max` = '99') ".(($razdel == 4)?"AND (`t2min` <= '{$level}' OR `t2min` = '99') AND (`t2max` >= '{$level}' OR `t2max` = '99')":"").") AND " : "")." `level` = {$razdel} ".(($id != null)? " AND `id` = {$id} " : "")." ORDER BY `podan` DESC");
while($row = mysql_fetch_array($fict)) {
if(($row['start']+300) < time()) {
if(mysql_query("DELETE FROM `zayavka` WHERE `id` = '{$row['id']}' LIMIT 1")) {
$team1 = fteam($row['team1']);
foreach($team1 as $k => $v) {
mysql_query("UPDATE `users` SET `zayavka` = '0' WHERE `id` = {$v}");
}
$team2 = fteam($row['team2']);
foreach($z[$zay]['team2'] as $k => $v) {
mysql_query("UPDATE `users` SET `zayavka` = '0' WHERE `id` = {$v}");
}
}
}
$zay[$row['id']] = array("team1" => fteam($row['team1']), "team2" => fteam($row['team2']), "coment" => $row['coment'], "type" => $row['type'], "timeout" => $row['timeout'], "start" => $row['start'], "t1min" => $row['t1min'], "t1max" => $row['t1max'], "t2min" => $row['t2min'], "t2max" => $row['t2max'], "t1c" => $row['t1c'], "t2c" => $row['t2c'], "podan" => $row['podan'], "id" => $row['id'], "level" => $row['level'], "blood" => $row['blood'], "bots" => $row['bots']);
}
return $zayavka;
}
function startbattle($id, $zay, $r) {
$z = getlist($r, null, $zay);
if($id == 'CHAOS') { $id = $z[$zay]['team1'][0]; }
delzayavka($id, $zay, $r);
$z = $z[$zay];
$count_users = count($z['team1']);
$bot = 0;
if($z['bots'] > 0 && $count_users > 0) {
$bots_raw = array(7 => array(10962, 10964, 10965), 8 => array(10962, 10964, 10965), 13 => array(10962, 10964, 10965));
$i = 0;
while($i <= count($bots_raw[$z['bots']])) {
$bot_id = $bots_raw[$z['bots']][$i];
$bot = createbot($bot_id, '');
$z['team1'][] = $bot['id'];
$i++;
$count_users++;
}
}
if($z['type'] == 4 || $z['type'] == 5) {
foreach($z['team1'] as $k => $v) {
undressall($v);
}
foreach($z['team2'] as $k => $v) {
undressall($v);
}
}
if($z['type'] == 3 || $z['type'] == 5) {
if($count_users < 4) {
mysql_query("UPDATE `users` SET `zayavka` = '0' WHERE `zayavka` = '".$zay."'");
foreach($z['team1'] as $k => $v) {
if($v < _BOTSEPARATOR_) {
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=6&user='.$v);
}
}
mysql_query("UPDATE `variables` SET `value` = '{$count_users}}' WHERE `var` = 'haos_match' LIMIT 1");
mysql_query("DELETE FROM `zayavka` WHERE `id` = '".$zay."' LIMIT 1");
}
$all = count($z['team1'])-1;
$power1 = 0; $power2 = 0;
for($i = 0; $i <= $all; $i++) {
if($z['team1'][$i] < _BOTSEPARATOR_) {
$gamer = mysql_fetch_array(mysql_query("SELECT (`level`*50)+`sila`+`lovk`+`inta`+`vinos`+`intel`+`stats`+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0) FROM `users` WHERE `id` = '".$z['team1'][$i]."' LIMIT 1"));
} else {
$bt = mysql_fetch_array(mysql_query('SELECT `id`, `prototype` FROM `bots` WHERE `id` = "'.$z['team1'][$i].'"'));
$gamer = mysql_fetch_array(mysql_query("SELECT (`level`*50)+`sila`+`lovk`+`inta`+`vinos`+`intel`+`stats`+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0) FROM `users` WHERE `id` = '".$bt['prototype']."' LIMIT 1"));
}
$cost[] = array($z['team1'][$i], $gamer[0]);
}
$z['team1'] = null;
$z['team2'] = null;
$flag = true;
while($flag) {
$flag = false;
for($ii = 0; $ii <= $all-1; $ii++) {
if($cost[$ii][1] < $cost[$ii+1][1]) {
$ctr = $cost[$ii+1];
$cost[$ii+1] = $cost[$ii];
$cost[$ii] = $ctr;
$flag = true;
}
}
}
while(count($cost) > 0) {
if($power1 <= $power2) {
$tmp = array_shift($cost);
$power1 += $tmp[1];
$z['team1'][] = $tmp[0];
} else {
$tmp = array_shift($cost);
$power2 += $tmp[1];
$z['team2'][] = $tmp[0];
}
}
}
$teams = array();
foreach($z['team1'] as $k => $v) {
foreach($z['team2'] as $kk => $vv) {
$teams[$v][$vv] = array(0, 0, time());
}
}
foreach($z['team2'] as $k => $v) {
foreach($z['team1'] as $kk => $vv) {
$teams[$v][$vv] = array(0, 0, time());
}
}
if(count($z['team2']) == 0) {
mysql_query("UPDATE `users` SET `zayavka` = 0 WHERE `zayavka` = '".$zay."'");
foreach($z['team1'] as $k => $v) {
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=6&user='.$v);
}
mysql_query("DELETE FROM `zayavka` WHERE `id` = '".$zay."' LIMIT 1");
die();
}
$arr = array(3, 4, 5, 7, 10);
if(in_array($z['timeout'], $arr)) {
} else {
$z['timeout'] = 3;
}
if($z['type'] == 1 || $z['type'] == 4) {
$rs = ', `fiz`'; $rss = ', 1';
} else {
$rs = ''; $rss = '';
}
mysql_query("INSERT INTO `battle` (`coment`, `teams`, `timeout`, `type`, `status`, `t1`, `t2`, `to1`, `to2`, `blood`$rs, `bots`) VALUES ('{$z['coment']}', '".serialize($teams)."', '{$z['timeout']}', '{$z['type']}', '0', '".implode(";", $z['team1'])."', '".implode(";", $z['team2'])."', '".time()."', '".time()."', '".$z['blood']."'$rss, '".$z['bots']."')");
$id = mysql_insert_id();
$rr = "<b>";
foreach($z['team1'] as $k => $v) {
if($k != 0) { $rr .= ", "; }
$rr .= nick3($v);
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=7&user='.$v);
}
$rr .= "</b> и <b>";
foreach($z['team2'] as $k => $v) {
if($k != 0) { $rr .= ", "; }
$rr .= nick3($v);
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=7&user='.$v);
}
$rr .= "</b>";
addlog($id, "Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу.<BR>");
foreach($z['team1'] as $k => $v) {
if($v < _BOTSEPARATOR_) {
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE `id` = {$v}");
} else {
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$v}");
}
}
foreach($z['team2'] as $k => $v) {
if($v < _BOTSEPARATOR_) {
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE `id` = {$v}");
} else {
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$v}");
}
}
}
##########
########Start Заявки для ботов в хаоты########
$battle_bots = mysql_fetch_array(mysql_query('SELECT `id` FROM `battle` WHERE `win` = 3 AND `bots` > 0 ORDER BY `id` DESC LIMIT 1'));
$zay_bots = mysql_fetch_array(mysql_query('SELECT `id` FROM `zayavka` WHERE `bots` > 0 ORDER BY `id` DESC LIMIT 1'));
if(!isset($battle_bots['id']) && !isset($zay_bots['id'])) {
$haos_match = array();
$hm_ok = array(7 => 1);
foreach($hm_ok as $lvl => $flag) {
if($flag == 1) {
mysql_query("INSERT INTO `zayavka` (`start`, `timeout`, `t1c`, `t2c`, `type`, `level`, `coment`, `team1`, `stavka`, `t1min`, `t2min`, `t1max`, `t2max`, `podan`, `blood`, `bots`) VALUES ('".(time()+3*60)."', '3', '99', '99', '3', '5', '<u>Бой с силами Хаоса <b>{$lvl}</b> уровня.</u>', '', '', '{$lvl}', '{$lvl}', '{$lvl}', '{$lvl}', '".date("H:i")."', '0', '{$lvl}')");
$haos_match[$lvl] = mysql_insert_id();
}
}
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=1');
}
########End Заявки для ботов в хаоты########
######
$te_zay = mysql_query('SELECT `id`, `start` FROM `zayavka`');
while($zs = mysql_fetch_array($te_zay)) {
if(($zs['start']+180) < time()) {
mysql_query('UPDATE `users` SET `zayavka` = "0" WHERE `zayavka` = "'.$zs['id'].'"');
mysql_query('DELETE FROM `zayavka` WHERE `id` = "'.$zs['id'].'"');
}
}
######
if(date("H-i") == "03-00") {
$del_tm = (time()-60*60*24*7);
$us_lim = mysql_fetch_array(mysql_query("SELECT `id` FROM `battle` WHERE `to1` < '{$del_tm}' ORDER BY `to1` DESC LIMIT 1"));
$us_lim = $us_lim['id'];
mysql_query("DELETE FROM `battle` WHERE `id` < '{$us_lim}'");
$del_tm = (time()-60*60*24*60);
mysql_query("DELETE FROM `delo` WHERE `date` < '".$del_tm."'");
mysql_query("OPTIMIZE `battle`, `delo`");
}
if(date("H-i") == "00-00") {
$perses = mysql_query('SELECT `id`, `vip`, `vip_time` FROM `users` WHERE `vip` > 0 AND `vip_time` > 0');
while($unvip = mysql_fetch_array($perses)) {
if($unvip['vip'] > 0) {
if($unvip['vip_time'] <= time()) {
remove_vip($unvip['id']);
}
}
}
}
$sp = mysql_query('SELECT `id`, `vip`, `vip_time` FROM `users` WHERE `vip` > 0 AND `vip_time` > "'.time().'"');
while($pl = mysql_fetch_array($sp)) {
upd_vip($pl['id'], $pl['vip']);
}
mysql_query('UPDATE `actions` SET `vals` = "end" WHERE `vars` LIKE "start_quest%" AND `vals` = "go" AND `val` <= "'.time().'"');
if(date("H-i") == "06-00") {
if(date("d") == "01") {
mysql_query("UPDATE `variables` SET `value` = '{$tm}' WHERE `var` = 'ref_month' LIMIT 1");
mysql_query("UPDATE `variables` SET `value` = '0' WHERE `var` = 'ref_m_id' LIMIT 1");
}
if(date("N") == "7") {
mysql_query("UPDATE `variables` SET `value` = '{$tm}' WHERE `var` = 'ref_week' LIMIT 1");
mysql_query("UPDATE `variables` SET `value` = '0' WHERE `var` = 'ref_w_id' LIMIT 1");
}
}
$st_ar = mysql_fetch_array(mysql_query('SELECT `value` FROM `variables` WHERE `var` = "arena_of_gods" LIMIT 1'));
if($st_ar['value'] <= time()) {
$dark = mysql_fetch_array(mysql_query('SELECT `id`, `login`, `level`, `hp` FROM `users` WHERE `id` = 10023 LIMIT 1'));
$light = mysql_fetch_array(mysql_query('SELECT `id`, `login`, `level`, `hp` FROM `users` WHERE `id` = 10024 LIMIT 1'));
##############
mysql_query("INSERT INTO `bots` (`name`, `prototype`, `battle`, `hp`, `owner`) VALUES ('".$light['login']."', '".$light['id']."', '', '".$light['hp']."', '1')");
$light['id_at'] = mysql_insert_id();
mysql_query("INSERT INTO `bots` (`name`, `prototype`, `battle`, `hp`) VALUES ('".$dark['login']."', '".$dark['id']."', '', '".$dark['hp']."')");
$dark['id_at'] = mysql_insert_id();
##############
$teams = array();
$teams[$dark['id_at']][$light['id_at']] = array(0, 0, time());
$teams[$light['id_at']][$dark['id_at']] = array(0, 0, time());
mysql_query("INSERT INTO `battle` (`id`, `coment`, `teams`, `time_m`, `timeout`, `type`, `status`, `t1`, `t2`, `to1`, `to2`, `blood`, `aren_of`) VALUES (NULL, '', '".serialize($teams)."', '".time()."', '3', '1', '0', '".$dark['id_at']."', '".$light['id_at']."', '".time()."', '".time()."', '1', '1')");
$id = mysql_insert_id();
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE (`id` = {$dark['id_at']} OR `id` = {$light['id_at']}) LIMIT 2");
$rr = "<b>".nick3($dark['id_at'])."</b> и <b>".nick3($light['id_at'])."</b>";
addlog($id, "Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу. <br />");
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE (`id` = {$dark['id']} OR `id` = {$light['id']}) LIMIT 2");
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=2');
mysql_query('UPDATE `variables` SET `value` = "'.(time()+60*60*24*7).'" WHERE `var` = "arena_of_gods" LIMIT 1');
}
$st_ar['value'] -= 3600;
if(date("z-H-i") == date("z-H-i", $st_ar['value'])) {
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=3');
}
$komp_users = mysql_query("SELECT * FROM `users`, `online` WHERE `users`.`id` = `online`.`id` AND `online`.`date` >= ".(time()-60)."");
while($ku = mysql_fetch_array($komp_users)) {
$bns = 0;
$efs_bns = mysql_fetch_array(mysql_query('SELECT SUM(`hp`) AS `hps` FROM `effects` WHERE `owner` = "'.$ku['id'].'"'));
if($efs_bns['hps'] > 0) {
$bns = $efs_bns['hps'];
}
mysql_query("UPDATE `users` SET `maxhp` = (IFNULL((SELECT SUM(`ghp`) FROM `inventory` WHERE `dressed` = 1 AND `owner` = `users`.`id`),0) + (`users`.`vinos`*6)+$bns) WHERE `id` = '{$ku['id']}'");
}
mysql_query("UPDATE `users` SET `hp` = 0 WHERE `hp` < 0");
mysql_query("UPDATE `users` SET `mana` = 0 WHERE `mana` < 0");
$its = mysql_query("SELECT `id`, `owner`, `name` FROM `inventory` WHERE `dressed` = 0 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '".time()."'))");
while($it = mysql_fetch_array($its)) {
mysql_query("DELETE FROM `inventory` WHERE `id` = '".$it['id']."' LIMIT 1;");
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '".$it['owner']."' '\"".$it['name']."\" разрушился id:(cap".$it['id'].").', 1, '".time()."')");
}
$effs = mysql_query("SELECT * FROM `effects` WHERE `time` <= ".time()." AND `sleep` = 0");
mysql_query("DELETE FROM `effects` WHERE `time` <= ".time()." AND `sleep` = 0");
while($eff = mysql_fetch_array($effs)) {
switch($eff['type']) {
case 11:
mysql_query("UPDATE `users` SET `sila` = `sila`+'".$eff['sila']."', `lovk` = `lovk`+'".$eff['lovk']."', `inta` = `inta`+'".$eff['inta']."' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 12:
mysql_query("UPDATE `users` SET `sila` = `sila`+'".$eff['sila']."', `lovk` = `lovk`+'".$eff['lovk']."', `inta` = `inta`+'".$eff['inta']."' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 13:
mysql_query("UPDATE `users` SET `sila` = `sila`+'".$eff['sila']."', `lovk` = `lovk`+'".$eff['lovk']."', `inta` = `inta`+'".$eff['inta']."' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 14:
mysql_query("UPDATE `users` SET `sila` = `sila`+'".$eff['sila']."', `lovk` = `lovk`+'".$eff['lovk']."', `inta` = `inta`+'".$eff['inta']."' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 21:
mysql_query("UPDATE `users` SET `sila` = `sila`-'".$eff['sila']."', `lovk` = `lovk`-'".$eff['lovk']."', `inta` = `inta`-'".$eff['inta']."', `vinos` = `vinos`-'".$eff['vinos']."' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 4:
mysql_query("UPDATE `users` SET `align` = '0' WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 7:
mysql_query("UPDATE `users` SET `maxhp` = (`maxhp`-200), `hp` = `maxhp` WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
case 1022:
mysql_query("UPDATE `users` SET `invis` = 0 WHERE `id` = '".$eff['owner']."' LIMIT 1");
break;
}
}
$hostel = mysql_query('SELECT `id`, `sleep` FROM `users` WHERE `sleep` != 0');
while($pl = mysql_fetch_array($hostel)) {
if($pl['sleep'] <= time()) {
mysql_query('UPDATE `users` SET `sleep` = 0 WHERE `id` = "'.$pl['id'].'"');
mysql_query('UPDATE `hostel` SET `sleeptime` = "'.(time()+60*60*6).'" WHERE `uid` = "'.$pl['id'].'"');
$ef = mysql_query('SELECT `id`, `time`, `sleep` FROM `effects` WHERE `owner` = "'.$pl['id'].'" AND `sleep` != 0');
while($ps = mysql_fetch_array($ef)) {
$tm = (time()+$ps['sleep']);
mysql_query('UPDATE `effects` SET `time` = "'.$tm.'", `sleep` = "0" WHERE `id` = "'.$ps['id'].'" AND `owner` = "'.$pl['id'].'"');
}
}
}
mysql_query('LOCK TABLES `inventory` WRITE, `variables` WRITE, `deztow_turnir` WRITE, `deztow_stavka` WRITE, `effects` WRITE, `deztow_charstams` WRITE, `deztow_gamers_inv` WRITE, `deztow_items` WRITE, `deztow_trap` WRITE, `online` WRITE');
$turnirstart = mysql_fetch_array(mysql_query("SELECT `value`, `bs_art` FROM `variables` WHERE `var` = 'startbs' LIMIT 1"));
$turnirstart['value'] -= 900;
if(date("z-H-i") == date("z-H-i", $turnirstart['value']))
if($turnirstart['bs_art'] == 0) {
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=4');
} elseif($turnirstart['bs_art'] == 1) {
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=4');
}
$tr = mysql_fetch_array(mysql_query("SELECT `id`, `type`, `winner`, `coin`, `start_time`, `log`, `endtime`, `active`, `winnerlog`, `art` FROM `deztow_turnir` WHERE `active` = TRUE LIMIT 1"));
$turnirstart = mysql_fetch_array(mysql_query("SELECT `value`, `bs_art` FROM `variables` WHERE `var` = 'startbs' LIMIT 1"));
$dd = mysql_fetch_array(mysql_query("SELECT COUNT(`kredit`) FROM `deztow_stavka` WHERE `owner` != 1254"));
if($dd[0] < 2 && $turnirstart[0] <= time()) {
if($turnirstart['bs_art'] == 1) {
$bs_art = 0;
} elseif($turnirstart['bs_art'] == 0) {
$bs_art = 0;
}
mysql_query('UPDATE `variables` SET `value` = "'.(time()+60*60).'", `bs_art` = "'.$bs_art.'" WHERE `var` = "startbs" LIMIT 1');
mysql_query("INSERT INTO `deztow_stavka` (`owner`, `kredit`, `time`) VALUES ('1254', '30', '".time()."')");
file_get_contents('http://capitalcity.old-dark.ru/chats.php?id=5');
}
if(!$tr && $turnirstart[0] <= time() && $dd[0] >= 2) {
$minroom = 501;
$maxroom = 560;
$data = mysql_query("SELECT `dt`.`owner` FROM `deztow_stavka` AS `dt`, `online` AS `o` WHERE (SELECT COUNT(`id`) FROM `effects` WHERE `effects`.`owner` = `dt`.`owner` AND (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14 OR `type` = 2 OR `type` = 3 OR `type` = 4 OR `type` = 202 OR `type` = 201 OR `type` = 21)) = 0 AND `o`.`id` = `dt`.`owner` AND `room` = 31 AND `o`.`date` >= '".(time()-300)."' ORDER BY `kredit` DESC, `dt`.`time` ASC LIMIT 50");
$stavka = mysql_fetch_array(mysql_query("SELECT SUM(`kredit`)*0.7 FROM `deztow_stavka`"));
while($row = mysql_fetch_array($data)) {
enter_bs($row[0]);
$tec = mysql_fetch_array(mysql_query("SELECT `id`, `owner`, `name`, `sila`, `lovk`, `inta`, `vinos`, `intel`, `mudra`, `def` FROM `deztow_charstams` WHERE `owner` = '{$row['owner']}' AND `def` = '1' LIMIT 1"));
$usk = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$row[0]."' LIMIT 1"));
if(isset($tec['id'])) {
mysql_query("UPDATE `users` SET `sila` = '".$tec['sila']."', `lovk` = '".$tec['lovk']."', `inta` = '".$tec['inta']."', `vinos` = '".$tec['vinos']."', `intel` = '".$tec['intel']."', `stats` = 0, `noj` = 0, `mec` = 0, `topor` = 0, `dubina` = 0, `mfire` = 0, `mwater` = 0, `mair` = 0, `mearth` = 0, `mlight` = 0, `mgray` = 0, `mdark` = 0, `master` = '8', `maxhp` = '".($tec['vinos']*6)."', `hp` = '".($tec['vinos']*6)."', `level` = 7, `nextup` = 999999999 WHERE `id` = '".$usk['id']."' LIMIT 1");
} else {
mysql_query("UPDATE `users` SET `sila` = '3', `lovk` = '3', `inta` = '3', `vinos` = '10', `intel` = '0', `stats` = 64, `noj` = 0, `mec` = 0, `topor` = 0, `dubina` = 0, `mfire` = 0, `mwater` = 0, `mair` = 0, `mearth` = 0, `mlight` = 0, `mgray` = 0, `mdark` = 0, `master` = '8', `maxhp` = '60', `hp` = '60', `level` = 7, `nextup` = 999999999 WHERE `id` = '".$usk['id']."' LIMIT 1");
}
$rum = rand($minroom, $maxroom);
$urs[$row['owner']] = $rum;
$i++;
if($i > 1) { $lors .= ", "; }
$lors .= nick3($row['owner']);
}
undressall(233);
undressall(234);
undressall(235);
mysql_query("DELETE FROM `inventory` WHERE `owner` = 233");
mysql_query("DELETE FROM `inventory` WHERE `owner` = 234");
mysql_query("DELETE FROM `inventory` WHERE `owner` = 235");
$rums = rand($minroom, $maxroom);
mysql_query("UPDATE `users` SET `in_tower` = 1, `chattime` = '999999999999', `room` = '".$rums."' WHERE `id` = '233' LIMIT 1");
mysql_query("UPDATE `users` SET `in_tower` = 1, `chattime` = '999999999999', `room` = '".$rums."' WHERE `id` = '234' LIMIT 1");
mysql_query("UPDATE `users` SET `in_tower` = 1, `chattime` = '999999999999', `room` = '".$rums."' WHERE `id` = '235' LIMIT 1");
mysql_query("UPDATE `online` SET `room` = '".$rums."', `date` = '999999999999' WHERE `id` = '233' LIMIT 1");
mysql_query("UPDATE `online` SET `room` = '".$rums."', `date` = '999999999999' WHERE `id` = '234' LIMIT 1");
mysql_query("UPDATE `online` SET `room` = '".$rums."', `date` = '999999999999' WHERE `id` = '235' LIMIT 1");
echo mysql_error();
$i++;
$lors .= ", ".nick3(233);
$lors .= ", ".nick3(234);
$lors .= ", ".nick3(235);
$lors .= ltrim(",", $lors);
mysql_query("TRUNCATE TABLE `deztow_items`");
$shmots = array("1", "1", "92", "92", "93", "93", "19", "19", "20", "20", "20", "23", "23", "24", "14", "87", "87", "6", "6", "17", "17", "17", "17", "11", "11", "12", "12", "12", "28", "28", "43", "43", "36", "36", "36", "37", "37", "37", "38", "38", "38", "50", "50", "57", "52", "52", "51", "51", "48", "48", "47", "47", "49", "49", "59", "59", "60", "60", "61", "61", "63", "64", "64", "65", "65", "66", "66", "68", "68", "69", "69", "72", "72", "4", "5", "79", "79", "80", "76", "75", "75", "94", "94", "95", "95", "82", "91", "91", "34", "34", "86", "86", "86", "9", "9", "101", "101", "101", "101", "101", "97", "97", "97", "97", "100", "100", "100", "100", "171", "171", "171", "171", "103", "103", "103", "104", "105", "105", "106", "106", "107", "107", "108", "108", "109", "110", "111", "112", "112", "113", "113", "119", "364", "284", "284", "284", "284", "284", "285", "285", "285", "285", "286", "286", "286", "286");
while($sh = array_shift($shmots)) {
$shopid = mysql_fetch_array(mysql_query("SELECT `id`, `name`, `img` FROM `shop` WHERE `id` = '".$sh."' LIMIT 1"));
if(isset($shopid['id'])) {
mysql_query("INSERT `deztow_items` (`iteam_id`, `name`, `img`, `room`) VALUES ('".$shopid['id']."', '".$shopid['name']."', '".$shopid['img']."', '".rand($minroom, $maxroom)."')");
}
}
$log = '<span class=date>'.date("d.m.y H:i").'</span> Начало турнира. Участники : '.$lors.'<br />';
$end = (time() + 21600);
mysql_query("INSERT `deztow_turnir` (`type`, `winner`, `coin`, `start_time`, `log`, `endtime`, `active`) VALUES ('".rand(1, 7)."', '', '".$stavka[0]."', '".time()."', '".$log."', '".$end."', '1')");
foreach($urs as $row => $rum) {
mysql_query("UPDATE `users` SET `in_tower` = 1, `room` = '".$rum."' WHERE `id` = '".$row."'");
mysql_query("UPDATE `online` SET `room` = '".$rum."' WHERE `id` = '".$row."' LIMIT 1");
}
}
$tur_data = mysql_fetch_array(mysql_query("SELECT `id`, `type`, `winner`, `coin`, `start_time`, `log`, `endtime`, `active`, `winnerlog`, `art` FROM `deztow_turnir` WHERE `active` = '1' LIMIT 1"));
if($tur_data['endtime'] < time() && $tur_data['id']) {
$list = mysql_query("SELECT * FROM `users` WHERE `in_tower` = 1");
while($u = mysql_fetch_array($list)) {
undressall($u['id']);
$rep = mysql_query("SELECT * FROM `inventory` WHERE `owner` = '".$u['id']."' AND `bs` = 1");
while($r = mysql_fetch_array($rep)) {
mysql_query("INSERT `deztow_items` (`iteam_id`, `name`, `img`, `room`) VALUES ('".$r['prototype']."', '".$r['name']."', '".$r['img']."', '".$u['room']."')");
}
mysql_query("DELETE FROM `inventory` WHERE `owner` = '".$u['id']."' AND `bs` = 1");
$rep = mysql_query("SELECT `id_item`, `owner` FROM `deztow_gamers_inv` WHERE `owner` = '".$u['id']."'");
while($r = mysql_fetch_array($rep)) {
mysql_query("UPDATE `inventory` SET `owner` = '".$u['id']."' WHERE `owner` = '0' AND `id` = '".$r['id_item']."'");
}
$tec = mysql_fetch_array(mysql_query("SELECT `id`, `owner`, `name`, `sila`, `lovk`, `inta`, `vinos`, `intel`, `maxhp`, `money`, `exp`, `mudra`, `stats`, `nextup`, `level`, `align`, `master`, `noj`, `mec`, `topor`, `dubina`, `mlight`, `mgray`, `mdark` FROM `deztow_realchars` WHERE `owner` = '{$u['id']}' LIMIT 1"));
if(isset($tec['id'])) {
$u = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$u['id']}' LIMIT 1"));
$stats = $tec['stats'];
$master = $tec['master'];
mysql_query("UPDATE `users` SET `sila` = '".$tec['sila']."', `lovk` = '".$tec['lovk']."', `inta` = '".$tec['inta']."', `vinos` = '".$tec['vinos']."', `hp` = '".($tec['vinos']*6)."', `maxhp` = '".($tec['vinos']*6)."', `intel` = '".$tec['intel']."', `stats` = '".$tec['stats']."', `nextup` = '".$tec['nextup']."', `level` = '".$tec['level']."', `align` = '".$tec['align']."', `noj` = '".$tec['noj']."', `mec` = '".$tec['mec']."', `topor` = '".$tec['topor']."', `dubina` = '".$tec['dubina']."', `mlight` = '".$tec['mlight']."', `mgray` = '".$tec['mgray']."', `mdark` = '".$tec['mdark']."', `master` = '".$tec['master']."' WHERE `id` = '".$u['id']."' LIMIT 1");
mysql_query("DELETE FROM `deztow_realchars` WHERE `owner` = '{$u['id']}'");
$eff = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = '".$u['id']."' AND (`type` = 1 `type` = 2 `type` = 3 `type` = 4 `type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14 `type` = 21 `type` = 201 `type` = 202)"));
mysql_query("DELETE FROM `effects` WHERE `owner` = '".$u['id']."' AND `type` != 1 AND `type` != 2 AND `type` != 3 AND `type` != 4 AND `type` != 5 AND `type` != 6 AND `type` != 11 AND `type` != 12 AND `type` != 13 AND `type` != 14");
if(isset($tec['id'])) {
mysql_query("UPDATE `users` SET `sila` = (`sila`-'".$eff['sila']."'), `lovk` = (`lovk`-'".$eff['lovk']."'), `inta` = (`inta`-'".$eff['inta']."'), `maxhp` = (`maxhp`-'".$eff['hp']."') WHERE `id` = '".$eff['owner']."' LIMIT 1");
}
if($u['id'] != 233 && $u['id'] != 234 && $u['id'] != 235) {
settravma($u['id'], 100, 86400, 1);
}
get_out($u['id']);
mysql_query("UPDATE `users` SET `in_tower` = 0, `room` = '31' WHERE `id` = '".$u['id']."' LIMIT 1");
mysql_query("UPDATE `online` SET `room` = '31' WHERE `id` = '".$u['id']."' LIMIT 1");
}
}
mysql_query('UPDATE `deztow_turnir` SET `winner` = \'NO!\', `winnerlog` = \'<b>Ничья</b>\', `endtime` = '.time().', `active` = 0, `log` = CONCAT(`log`,\''."Турнир закончен по тайм-ауту. Победителя нет!<br />".'\') WHERE `active` = TRUE LIMIT 1');
$turnirstart = mysql_fetch_array(mysql_query("SELECT `value`, `bs_art` FROM `variables` WHERE `var` = 'startbs' LIMIT 1"));
if($turnirstart['bs_art'] == 1) {
$bs_art = 0;
} elseif($turnirstart['bs_art'] == 0) {
$bs_art = 0; #1
}
$times = (time() + 7200);
mysql_query("UPDATE `variables` SET `value` = '".$times."', `bs_art` = '".$bs_art."' WHERE `var` = 'startbs' LIMIT 1");
mysql_query("TRUNCATE TABLE `deztow_stavka`");
mysql_query("TRUNCATE TABLE `deztow_gamers_inv`");
mysql_query("TRUNCATE TABLE `deztow_items`");
mysql_query("TRUNCATE TABLE `deztow_trap`");
}
mysql_query('UNLOCK TABLES');