Файл: sys/head.php
Строк: 1166
<?php
echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<meta http-equiv="Content-Type" content="application/vnd.wap.xhtml+xml; charset=UTF-8"/>
<meta name="name" content="' . $_SERVER['SCRIPT_NAME'] . '"/>
<meta name="author" content="KoT" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="/style.css" type="text/css"/>
<title>Золотая империя</title>
</head>
<body>
<div class="logo"> <img src="/images/logo.jpg" width="500" height="100" alt=""/> </img></div>
<div style="text-align:center;">
</div>
<div class="t">';
if (isset($_SESSION['us']) && isset($_SESSION['ps']))
{
// завершение тренеривки спец. юнитов
$doneGenArmy = mysql_query("SELECT id FROM generals WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
$doneSabArmy = mysql_query("SELECT id FROM saboteurs WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
$doneScoArmy = mysql_query("SELECT id FROM scouts WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
$doneRecArmy = mysql_query("SELECT id FROM recruiters WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
$doneThiArmy = mysql_query("SELECT id FROM thiefs WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
if (mysql_num_rows($doneGenArmy) != false)
{
mysql_query("UPDATE generals SET timeleft = '0' WHERE player = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка генерала окончена.');
}
if (mysql_num_rows($doneSabArmy) != false)
{
mysql_query("UPDATE saboteurs SET timeleft = '0' WHERE player = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка саботажника окончена.');
}
if (mysql_num_rows($doneScoArmy) != false)
{
mysql_query("UPDATE scouts SET timeleft = '0' WHERE player = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка шпиона окончена.');
}
if (mysql_num_rows($doneRecArmy) != false)
{
mysql_query("UPDATE recruiters SET timeleft = '0' WHERE player = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка вербовщика окончена.');
}
if (mysql_num_rows($doneThiArmy) != false)
{
mysql_query("UPDATE thiefs SET timeleft = '0' WHERE player = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка вора окончена.');
}
// завершение тренеривки юнитов
$doneArmy = mysql_query("SELECT cid FROM duty WHERE done != '0' AND user = '$user[id]' AND timeleft < '$rtime'");
if (mysql_num_rows($doneArmy) != false)
{
$inD = mysql_fetch_assoc($doneArmy);
if ($user['race'] == 1)
{
if ($inD['cid'] == 1) $r = 'Паладин';
if ($inD['cid'] == 2) $r = 'Мечник';
if ($inD['cid'] == 3) $r = 'Стрелок';
if ($inD['cid'] == 4) $r = 'Маг';
if ($inD['cid'] == 5) $r = 'Колосс';
}
else
{
if ($inD['cid'] == 1) $r = 'Призрак';
if ($inD['cid'] == 2) $r = 'Химера';
if ($inD['cid'] == 3) $r = 'Осквернитель';
if ($inD['cid'] == 4) $r = 'Грифон';
if ($inD['cid'] == 5) $r = 'Йетти';
}
mysql_query("UPDATE duty SET done = '0' WHERE done != '0' AND user = '$user[id]' AND timeleft < '$rtime'");
msg('Тренировка ' . $r . ' ' . (isset($_SESSION['countDone']) ? '(' . $_SESSION['countDone'] . ' чел.)' : '') . ' окончена.');
unset($_SESSION['countDone']);
}
// завершение постройки / улучшения зданий
$upLVL = mysql_query("SELECT * FROM construct WHERE uplvl != '0' AND user = '$user[id]' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($upLVL) != false)
{
$inUP = mysql_fetch_assoc($upLVL);
mysql_query("UPDATE construct SET uplvl = '0', level = '" . ($inUP['level'] + 1) . "' WHERE uplvl != '0' AND user = '$user[id]' AND timeleft < '$rtime' LIMIT 1");
##########################################
switch($inUP['cid']):
case 1:
$name = '<img src="images/building_group_1_small.png" alt=""/> Ферма';
break;
case 2:
$name = '<img src="images/building_group_2_small.png" alt=""/> Шахта';
break;
case 3:
$name = '<img src="images/building_group_3_small.png" alt=""/> Лесопилка';
break;
case 4:
$name = '<img src="images/building_group_4_small.png" alt=""/> Каменоломня';
break;
case 5:
$name = '<img src="images/building_group_5_small.png" alt=""/> Прииск';
break;
case 6:
$name = '<img src="images/building_group_6_small.png" alt=""/> Казарма';
break;
case 7:
$name = '<img src="images/building_group_7_small.png" alt=""/> Торговая палата';
break;
case 8:
$name = '<img src="images/building_group_8_small.png" alt=""/> Склад';
break;
case 9:
$name = '<img src="images/building_group_9_small.png" alt=""/> Рынок';
break;
case 10:
$name = '<img src="images/building_group_10_small.png" alt=""/> Кузница';
break;
case 11:
$name = '<img src="images/building_group_11_small.png" alt=""/> Дипломатический центр';
break;
case 12:
$name = '<img src="images/building_group_12_small.png" alt=""/> Цитадель';
break;
case 13:
$name = '<img src="images/building_group_13_small.png" alt=""/> Бастион';
break;
case 14:
$name = '<img src="images/building_group_14_small.png" alt=""/> Смотровая башня';
break;
endswitch;
##########################################
$ReSuLt = ($inUP['uplvl'] == 1) ? 'улучшено.' : 'построено.';
msg('Здание ' . $name . ' ' . $ReSuLt);
}
// отображения движения войск
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) != false)
{
$armGoMe = mysql_query("SELECT id FROM users WHERE terrain IN(SELECT id FROM location WHERE id_player = '$user[id]') AND id IN(SELECT user FROM duty WHERE time_run > '$rtime')");
$amrGoMyBack = mysql_query("SELECT id FROM duty WHERE user = '$user[id]' AND time_back > '$rtime' AND done = '0'");
$amrGoMyRun = mysql_query("SELECT id FROM duty WHERE user = '$user[id]' AND time_run > '$rtime' AND done = '0'");
// возвращение войска
if (mysql_num_rows($amrGoMyBack) != false)
{
$armMy = '<a href="troops_back"><img src="/images/attackmy.png" alt="*"/> (' . (mysql_num_rows($amrGoMyBack) + mysql_num_rows($amrGoMyRun)) . ')</a>';
}
// нападение на противника
if (mysql_num_rows($amrGoMyRun) != false)
{
$armMy = '<a href="troops_run"><img src="/images/attackmy.png" alt="*"/> (' . (mysql_num_rows($amrGoMyBack) + mysql_num_rows($amrGoMyRun)) . ')</a>';
}
// нападение от противника
if (mysql_num_rows($armGoMe) != false)
{
$armMe = '<a href="troops_enemy"><img src="/images/attackme.png" alt="*"/> (' . mysql_num_rows($armGoMe) . ')</a>';
}
if (isset($armMy) || isset($armMe)) echo '<div align="center">' . $armMy . ' ' . $armMe . '</div>' . separator;
}
// Бан
if ($user['ban'] > $rtime || $user['forever'] == 1)
{
if ($user['forever'] == 0)
{
$o = '. Освобождение через ' . val($user['ban'] - $rtime);
}
elseif ($user['forever'] == 1)
{
$o = ' пожизенно';
}
err('Твой замок арестован' . $o . '. Причина ' . $user['why']);
include '/sys/foot.php';
exit();
}
// Склад
$skl = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '8' AND timeleft < '$rtime' LIMIT 1");
$my_skl = mysql_fetch_assoc($skl);
$STORAGE = $my_skl['level'] * 5 * 1000;
// забираем похищенные ресурсы из временной таблы
$temp = mysql_query("SELECT id FROM temporary WHERE player = '$user[id]' AND timeleft < '$rtime'");
if (mysql_num_rows($temp) != false)
{
$temprary = mysql_fetch_assoc($temp);
mysql_query("UPDATE users SET
food = '" . plus($user['food'], $temprary['food'], (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "',
tree = '" . plus($user['tree'], $temprary['tree'], (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "',
stone = '" . plus($user['stone'], $temprary['stone'], (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "',
ore = '" . plus($user['ore'], $temprary['ore'], (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "',
gold = '" . plus($user['gold'], $temprary['gold'], (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "'
WHERE id = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM temporary WHERE player = '$user[id]' AND timeleft < '$rtime'");
}
######################
// Улучшение параметров юнита
$upUnit = mysql_query("SELECT * FROM upgraded_units WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime'");
if (mysql_num_rows($upUnit) != false)
{
$isU = mysql_fetch_assoc($upUnit);
// улучшение атаки
if ($isU['power_mod'] == 1)
{
mysql_query("UPDATE upgraded_units SET power = power + '1', power_mod = '0' WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime' AND id = '$isU[id]'");
mysql_query("UPDATE upgraded_units SET timeleft = '0' WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime' AND id = '$isU[id]'");
}
// улучшение защиты
if ($isU['defence_mod'] == 1)
{
mysql_query("UPDATE upgraded_units SET defence = defence + '1', defence_mod = '0' WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime' AND id = '$isU[id]'");
mysql_query("UPDATE upgraded_units SET timeleft = '0' WHERE player = '$user[id]' AND timeleft != '0' AND timeleft < '$rtime' AND id = '$isU[id]'");
}
}
######################
// когда была отменена передача ресурсов
$CAN = mysql_query("SELECT * FROM rialto WHERE player = '$user[id]' AND timeleft < '$rtime' AND time_back != '0' AND time_back <= '$rtime' LIMIT 1");
if (mysql_num_rows($CAN) != false)
{
$CANSEL = mysql_fetch_assoc($CAN);
mysql_query("UPDATE users SET $CANSEL[resource] = $CANSEL[resource] + '$CANSEL[goods]' WHERE id = '$user[id]' LIMIT 1");
mysql_query("UPDATE rialto SET time_run = '0', goods = '0', resource = '', destination_dealer = '0' WHERE id = '$CANSEL[id]' AND player = '$user[id]' LIMIT 1");
}
// Передача ресурсов другому игроку
$Deal = mysql_query("SELECT * FROM rialto WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($Deal) != false)
{
$InD = mysql_fetch_assoc($Deal);
// координаты передаваемого
$CoorMe = mysql_fetch_assoc(mysql_query("SELECT id FROM location WHERE x = '".user($InD['player'], 'coor_x')."' AND y = '".user($InD['player'], 'coor_y')."' LIMIT 1"));
// координаты пункта назначения
$TerrainHis = mysql_fetch_assoc(mysql_query("SELECT x, y, id_player FROM location WHERE id = '$InD[destination_dealer]' LIMIT 1"));
// вместительность склада другого игрока
$skl2 = mysql_fetch_assoc(mysql_query("SELECT id, level FROM construct WHERE user = '$TerrainHis[id_player]' AND cid = '8' AND timeleft < '$rtime' LIMIT 1"));
$STORAGE2 = $skl2['level'] * 5 * 1000;
// передаем...
$arr = travel_time(10 * (user($InD['player'], 'race') == 1 ? 35 : 20), user($InD['player'], 'coor_x'), user($InD['player'], 'coor_y'), $TerrainHis['x'], $TerrainHis['y']);
mysql_query("UPDATE users SET $InD[resource] = '" . plus(user($TerrainHis['id_player'], $InD['resource']), $InD['goods'], (!isset($skl2['id'])) ? 1000 : $STORAGE2)."' WHERE id = '$TerrainHis[id_player]' LIMIT 1");
//----------------------------//
if ($InD['resource'] == 'food') $R = 1;
if ($InD['resource'] == 'tree') $R = 2;
if ($InD['resource'] == 'stone') $R = 3;
if ($InD['resource'] == 'ore') $R = 4;
if ($InD['resource'] == 'gold') $R = 5;
$message1 = 'Было доставлено <img src="images/res.'.$R.'.png" alt=""/> ' . $InD['goods'] . ' для ' . user($TerrainHis['id_player'], 'nick');
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InD[player]', '$message1', '$rtime', '0', 'i')");
$message2 = 'Было доставлено <img src="images/res.'.$R.'.png" alt=""/> ' . $InD['goods'] . ' от ' . user($InD['player'], 'nick');
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$TerrainHis[id_player]', '$message2', '$rtime', '0', 'i')");
//----------------------------//
// обнуляем...
mysql_query("UPDATE rialto SET time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])). "' WHERE player = '$InD[player]' LIMIT 1");
mysql_query("UPDATE rialto SET goods = '0', resource = '', time_run = '0' WHERE player = '$InD[player]' LIMIT 1");
}
######################
// Разведка
$Scout = mysql_query("SELECT * FROM scouts WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($Scout) != false)
{
$InD = mysql_fetch_assoc($Scout);
// координаты разведчика
$CoorMe = mysql_fetch_assoc(mysql_query("SELECT id FROM location WHERE x = '".user($InD['player'], 'coor_x')."' AND y = '".user($InD['player'], 'coor_y')."' LIMIT 1"));
// координаты пункта назначения
$TerrainHis = mysql_fetch_assoc(mysql_query("SELECT x, y, id_player FROM location WHERE id = '$InD[destination]' LIMIT 1"));
// колдуем с вычислениями параметров шпионов...
$empty_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$TerrainHis[id_player]' AND timeleft < '$rtime' AND time_run < '$rtime' AND time_back < '$rtime' LIMIT 1"));
if (isset($empty_scout['id']))
{
// вычисляем шанс шпиона вычислить вора
$chance = abs(mt_rand(1, $InD['practice']) - mt_rand(1, $empty_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE scouts SET health = health - '$chance' WHERE player = '$InD[player]' LIMIT 1");
$Death = true;
}
}
if (!empty($Death))
{
$message = 'Разведка на игрока ' . user($TerrainHis['id_player'], 'nick') . ' не удалась.';
}
else
{
$tratata = mysql_fetch_assoc(
mysql_query("SELECT COUNT(t1.id) AS a, (SUM(lot) * SUM(power)) AS p, user, food, tree, stone, ore, gold,
(SELECT COUNT(id) FROM duty WHERE user = '$TerrainHis[id_player]' AND security = '1') AS s FROM duty AS t1 LEFT JOIN users AS t2 ON(t1.user = t2.id) WHERE t1.user = '$TerrainHis[id_player]' GROUP BY t1.id"));
$message = 'Отчет о разведке на игрока ' . user($TerrainHis['id_player'], 'nick') . ':<br/>
Легионов: ' . (!empty($tratata['a']) ? $tratata['a'] : 'Нет') . ', Общая мощь легионов: ' . (!empty($tratata['p']) ? $tratata['p'] : 0) . ', Легионов в охране: ' . (!empty($tratata['s']) ? $tratata['s'] : 'Нет') . ', Ресурсов:
<img src="/images/res.1.png" alt="" title="Еда"/> ' . $tratata['food'] . '
<img src="/images/res.2.png" alt="" title="Дерево"/> ' . $tratata['tree'] . '
<img src="/images/res.3.png" alt="" title="Камень"/> ' . $tratata['stone'] . '
<img src="/images/res.4.png" alt="" title="Руда"/> ' . $tratata['ore'] . '
<img src="/images/res.5.png" alt="" title="Золото"/> ' . $tratata['gold'];
}
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InD[player]', '$message', '$rtime', '0', 'i')");
$arr = travel_time(10 * (user($InD['player'], 'race') == 1 ? 50 : 40), user($InD['player'], 'coor_x'), user($InD['player'], 'coor_y'), $TerrainHis['x'], $TerrainHis['y']);
mysql_query("UPDATE scouts SET time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])) . "' WHERE player = '$InD[player]' LIMIT 1");
mysql_query("UPDATE scouts SET time_run = '0' WHERE player = '$InD[player]' LIMIT 1");
unset($Death);
}
// Саботажничество
$Sab = mysql_query("SELECT * FROM saboteurs WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($Sab) != false)
{
$InD = mysql_fetch_assoc($Sab);
// координаты саботажника
$CoorMe = mysql_fetch_assoc(mysql_query("SELECT id FROM location WHERE x = '".user($InD['player'], 'coor_x')."' AND y = '".user($InD['player'], 'coor_y')."' LIMIT 1"));
// координаты пункта назначения
$TerrainHis = mysql_fetch_assoc(mysql_query("SELECT x, y, id_player FROM location WHERE id = '$InD[destination]' LIMIT 1"));
// колдуем с вычислениями параметров шпионов...
$empty_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$TerrainHis[id_player]' AND timeleft < '$rtime' AND time_run < '$rtime' AND time_back < '$rtime' LIMIT 1"));
if (isset($empty_scout['id']))
{
// вычисляем шанс шпиона вычислить саботажника
$chance = abs(mt_rand(1, $InD['practice']) - mt_rand(1, $empty_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE saboteurs SET health = health - '$chance' WHERE player = '$InD[player]' LIMIT 1");
$Death = true;
}
}
if (!empty($Death))
{
$message = 'Саботажнику не удалось произвести ' . ($InD['intent'] == 1 ? 'бунт в замке' : 'разрушение зданий') . ' у игрока ' . user($TerrainHis['id_player'], 'nick') . '.';
}
else
{
$terrainsec = mysql_fetch_assoc(mysql_query("SELECT SUM(lot) AS l, id FROM duty WHERE user = '$TerrainHis[id_player]' AND security = '1' GROUP BY lot"));
$randombuild = mysql_fetch_assoc(mysql_query("SELECT id, cid, level, maxlvl FROM construct WHERE user = '$TerrainHis[id_player]' ORDER BY RAND() LIMIT 1"));
if ($InD['intent'] == 1)
{
if (minus($terrainsec['l'], round($terrainsec['l'] / 200 * $InD['practice'])) > 0)
{
mysql_query("UPDATE duty SET lot = '" . minus($terrainsec['l'], round($terrainsec['l'] / 200 * $InD['practice'])) . "' WHERE user = '$TerrainHis[id_player]' AND security = '1'");
$prst = 'После бунта в замке не погибло ни одного человека.';
}
else
{
mysql_query("DELETE FROM duty WHERE user = '$TerrainHis[id_player]' AND security = '1'");
$prst = 'После бунта в замке погибло ' . round($terrainsec['l'] / 200 * $InD['practice']) . '% армии.';
}
}
else
{
if ($randombuild['level'] > 1 && $InD['practice'] > 10)
{
mysql_query("UPDATE construct SET level = level - '" . round($randombuild['maxlvl'] / 200 * $InD['practice']) . "' WHERE user = '$TerrainHis[id_player]' AND id = '$randombuild[id]' LIMIT 1");
$prst = 'Здание ' . builds($randombuild['cid']) . ' было разрушено до ' . ($randombuild['level'] - round($randombuild['maxlvl'] / 200 * $InD['practice'])) . ' уровня.';
}
elseif ($randombuild['level'] == 1 && $InD['practice'] > 10 || $randombuild['level'] < round($randombuild['maxlvl'] / 200 * $InD['practice']))
{
mysql_query("DELETE FROM construct WHERE user = '$TerrainHis[id_player]' AND id = '$randombuild[id]' LIMIT 1");
$prst = 'Здание ' . builds($randombuild['cid']) . ' было разрушено полностью.';
}
else
{
$prst = 'Ни одного здания небыло разрушено.';
}
}
$message = 'Отчет о саботаже на игрока ' . user($TerrainHis['id_player'], 'nick') . ':<br/>' . $prst;
$message2 = 'Отчет о саботаже на твой замок от игрока ' . user($InD['player'], 'nick') . ':<br/>' . $prst;
}
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InD[player]', '$message', '$rtime', '0', 'i')");
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$TerrainHis[id_player]', '$message2', '$rtime', '0', 'i')");
$arr = travel_time(10 * (user($InD['player'], 'race') == 1 ? 50 : 40), user($InD['player'], 'coor_x'), user($InD['player'], 'coor_y'), $TerrainHis['x'], $TerrainHis['y']);
mysql_query("UPDATE saboteurs SET time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])) . "' WHERE player = '$InD[player]' LIMIT 1");
mysql_query("UPDATE saboteurs SET time_run = '0' WHERE player = '$InD[player]' LIMIT 1");
unset($Death);
}
// Вербовка
$Rec = mysql_query("SELECT * FROM recruiters WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($Rec) != false)
{
$InD = mysql_fetch_assoc($Rec);
// координаты вербовщика
$CoorMe = mysql_fetch_assoc(mysql_query("SELECT id FROM location WHERE x = '".user($InD['player'], 'coor_x')."' AND y = '".user($InD['player'], 'coor_y')."' LIMIT 1"));
// координаты пункта назначения
$TerrainHis = mysql_fetch_assoc(mysql_query("SELECT x, y, id_player FROM location WHERE id = '$InD[destination]' LIMIT 1"));
// колдуем с вычислениями параметров шпионов...
$empty_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$TerrainHis[id_player]' AND timeleft < '$rtime' AND time_run < '$rtime' AND time_back < '$rtime' LIMIT 1"));
if (isset($empty_scout['id']))
{
// вычисляем шанс шпиона вычислить вербовщика
$chance = abs(mt_rand(1, $InD['practice']) - mt_rand(1, $empty_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE recruiters SET health = health - '$chance' WHERE player = '$InD[player]' LIMIT 1");
$Death = true;
}
}
$arr = travel_time(10 * (user($InD['player'], 'race') == 1 ? 50 : 40), user($InD['player'], 'coor_x'), user($InD['player'], 'coor_y'), $TerrainHis['x'], $TerrainHis['y']);
if (!empty($Death))
{
$message = 'У игрока ' . user($TerrainHis['id_player'], 'nick') . ' не удалась никого завербовать.';
}
else
{
$terrainsec = mysql_fetch_assoc(mysql_query("SELECT SUM(lot) AS l, duty .* FROM duty WHERE user = '$TerrainHis[id_player]' GROUP BY lot ORDER BY RAND()"));
if (minus($terrainsec['l'], round($terrainsec['l'] / 200 * $InD['practice'])) > 0)
{
mysql_query("INSERT INTO duty SET
name = '(Пленные)',
cid = '$terrainsec[cid]',
user = '$InD[player]',
health = '$terrainsec[health]',
power = '$terrainsec[power]',
defence = '$terrainsec[defence]',
lot = '" . round($terrainsec['l'] / 200 * $InD['practice']) . "',
capacity = '$terrainsec[capacity]',
speed = '$terrainsec[speed]',
time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])) . "'");
mysql_query("UPDATE duty SET lot = '" . minus($terrainsec['l'], round($terrainsec['l'] / 200 * $InD['practice'])) . "' WHERE user = '$TerrainHis[id_player]' AND id = '$terrainsec[id]'");
}
else
{
mysql_query("INSERT INTO duty SET
name = '(Пленные)',
cid = '$terrainsec[cid]',
user = '$InD[player]',
health = '$terrainsec[health]',
power = '$terrainsec[power]',
defence = '$terrainsec[defence]',
lot = '" . round($terrainsec['l'] / 200 * $InD['practice']) . "',
capacity = '$terrainsec[capacity]',
speed = '$terrainsec[speed]',
time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])) . "',
user = '$InD[player]'");
mysql_query("DELETE FROM duty WHERE user = '$TerrainHis[id_player]' AND security = '1' AND id = '$terrainsec[id]'");
}
$message = 'У игрока ' . user($TerrainHis['id_player'], 'nick') . ' было завербовано ' . round($terrainsec['l'] / 200 * $InD['practice']) . '% армии.';
$message2 = 'Игрок ' . user($InD['player'], 'nick') . ' завербовал у тебя ' . round($terrainsec['l'] / 200 * $InD['practice']) . '% армии.';
}
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InD[player]', '$message', '$rtime', '0', 'i')");
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$TerrainHis[id_player]', '$message2', '$rtime', '0', 'i')");
mysql_query("UPDATE recruiters SET time_back = '" . (($rtime + $arr) - ($rtime - $InD['time_run'])) . "' WHERE player = '$InD[player]' LIMIT 1");
mysql_query("UPDATE recruiters SET time_run = '0' WHERE player = '$InD[player]' LIMIT 1");
unset($Death);
}
// Сражение
$Attack = mysql_query("SELECT duty .*,
(SELECT SUM(power) FROM duty WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' AND done = '0') AS power,
(SELECT SUM(lot) FROM duty WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' AND done = '0') AS lot
FROM duty WHERE time_run != '0' AND time_run <= '$rtime' AND timeleft < '$rtime' AND done = '0'");
if (mysql_num_rows($Attack) != false)
{
$InAttack = mysql_fetch_assoc($Attack);
// координаты нападающего
$CoorMe = mysql_fetch_assoc(mysql_query("SELECT id FROM location WHERE x = '".user($InAttack['user'], 'coor_x')."' AND y = '".user($InAttack['user'], 'coor_y')."' LIMIT 1"));
// координаты пункта назначения
$TerrainMe = mysql_fetch_assoc(mysql_query("SELECT x, y, id_player FROM location WHERE id = '".user($InAttack['user'], 'terrain')."' LIMIT 1"));
// параметры армии противника
$StrongFoe = mysql_fetch_assoc(mysql_query("SELECT duty .*,
(SELECT SUM(power) FROM duty WHERE time_run = '0' AND time_back = '0' AND timeleft < '$rtime' AND user = '$TerrainMe[id_player]' AND done = '0') AS power,
(SELECT SUM(lot) FROM duty WHERE time_run = '0' AND time_back = '0' AND timeleft < '$rtime' AND user = '$TerrainMe[id_player]' AND done = '0') AS lot
FROM duty WHERE user = '$TerrainMe[id_player]' AND done = '0'"));
// Параметры генералов
$prmMyGen = mysql_fetch_assoc(mysql_query("SELECT * FROM generals WHERE cid = '$InAttack[id]' LIMIT 1"));
$prmFoeGen = mysql_fetch_assoc(mysql_query("SELECT * FROM generals WHERE cid = '$StrongFoe[id]'"));
$Fattack = ($prmFoeGen['attack'] != 0) ? $prmFoeGen['attack'] : 0;
$Fdefence = ($prmFoeGen['defence'] != 0) ? $prmFoeGen['defence'] : 0;
// математические расчеты битвы..
// "путевка"...
$arrival = travel_time(10 * $InAttack['speed'], user($InAttack['user'], 'coor_x'), user($InAttack['user'], 'coor_y'), $TerrainMe['x'], $TerrainMe['y']);
// сила нападающего
$my_power = (($InAttack['power'] + paramUnit($InAttack['uid'], $InAttack['user'], 1)) * $InAttack['lot'] + $prmMyGen['attack']);
// сила оппонента
$opp_power = (($StrongFoe['power'] + paramUnit($StrongFoe['uid'], $StrongFoe['user'], 1)) * $StrongFoe['lot'] + $Fattack);
// защита нападающего
$my_def = (($InAttack['defence'] + paramUnit($InAttack['uid'], $InAttack['user'], 2)) * $InAttack['lot'] + $prmMyGen['defence']);
// защита оппонента
$opp_def = (($StrongFoe['defence'] + paramUnit($StrongFoe['uid'], $StrongFoe['user'], 2)) * $StrongFoe['lot'] + $Fdefence);
// здоровье нападающего
$my_life = ($InAttack['health'] * $InAttack['lot']);
// здоровье оппонента
$opp_life = ($StrongFoe['health'] * $StrongFoe['lot']);
// коэфициент защиты нападающего
$my_def = round($my_def / 100 * $InAttack['defence']);
// коэфициент защиты оппонента
$opp_def = round($opp_def / 100 * $StrongFoe['defence']);
// вычитание нападающему
$my_minus = minus($my_life, minus($opp_power, $my_def));
// рез-т кол-ва оставшихся у нападающего
$battleResMy = floor($my_minus / $my_life);
// вычитание оппоненту
$opp_minus = minus($opp_life, minus($my_power, $opp_def));
// рез-т кол-ва оставшихся у оппонента
$battleResOpp = floor($opp_minus / $opp_life);
// процент от оставшихся у нападающего
$ResultMy = round($battleResMy * 100 / $InAttack['lot']);
// процент от оставшихся у оппонента
$ResultOpp = round($battleResOpp * 100 / $StrongFoe['lot']);
// если армия нападающего сильнее 100% противника
if ($battleResMy > 0 && $battleResOpp == 0 && $StrongFoe['security'] == 1)
{
// грабеж
$robbery = ($battleResMy * $InAttack['capacity']);
$isset_thief = mysql_fetch_assoc(mysql_query("SELECT * FROM thiefs WHERE player = '$InAttack[user]' AND timeleft < '$rtime' LIMIT 1"));
// проверяем шпиона..
$isset_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$StrongFoe[user]' AND timeleft < '$rtime' LIMIT 1"));
if (isset($isset_scout['id']) && isset($isset_thief['id']))
{
// шанс шпиона вычислить вора
$chance = abs(mt_rand(1, $isset_thief['practice']) - mt_rand(1, $isset_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE thiefs SET health = health - '$chance' WHERE player = '$InAttack[user]' LIMIT 1");
$Death = true;
}
}
// проверяем вора..
elseif (isset($isset_thief['id']))
{
$robbery = round($robbery / 100 * $isset_thief['practice']);
}
$_robbery = round($robbery / 5);
// грабим склад
$ufood = minus(user($StrongFoe['user'], 'food'), $_robbery);
$uore = minus(user($StrongFoe['user'], 'ore'), $_robbery);
$utree = minus(user($StrongFoe['user'], 'tree'), $_robbery);
$ustone = minus(user($StrongFoe['user'], 'stone'), $_robbery);
$ugold = minus(user($StrongFoe['user'], 'gold'), $_robbery);
$mfood = minus(user($StrongFoe['user'], 'food'), $ufood);
$more = minus(user($StrongFoe['user'], 'ore'), $uore);
$mtree = minus(user($StrongFoe['user'], 'tree'), $utree);
$mstone = minus(user($StrongFoe['user'], 'stone'), $ustone);
$mgold = minus(user($StrongFoe['user'], 'gold'), $ugold);
// запись похищенных ресурсов во временную таблу
mysql_query("INSERT INTO temporary SET
id = '$InAttack[id]',
food = '$mfood',
tree = '$mtree',
stone = '$mstone',
ore = '$more',
gold = '$mgold',
player = '$InAttack[user]',
timeleft = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "'");
mysql_query("UPDATE users SET food = '$ufood', tree = '$utree', stone = '$ustone', ore = '$uore', gold = '$ugold' WHERE id = '$StrongFoe[user]' LIMIT 1");
// урон генералам
$damageMeGen = 100 - $ResultMy;
$GenMin = minus($prmMyGen['health'], $damageMeGen);
$damageFoeGen = 100 - $ResultOpp;
$GenMinF = minus($prmFoeGen['health'], $damageFoeGen);
if (isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET health = '$GenMinF' WHERE id = '$prmFoeGen[id]' AND cid IN(SELECT id FROM duty WHERE security = '1')");
}
$prct = round(2 + ($prmMyGen['level'] * $prmMyGen['career']) * 100 / 100);
mysql_query("UPDATE generals SET health = '$GenMin', practice = practice + '$prct' WHERE id = '$prmMyGen[id]' LIMIT 1");
if ($prmMyGen['practice'] == compute_params($prmMyGen['id'], 0))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmMyGen[id]' LIMIT 1");
}
if (!empty($Death))
{
$mess_thief1 = '<br/>Шпион противника обнаружил твоего вора при нападении, вор не смог ничего украсть.';
$mess_thief2 = '<br/>Твой шпион обнаружил у противника вора при нападении, вор не смог ничего украсть.';
}
$message1 = 'Твои войска с легкостью одержали победу над замком ' . user($StrongFoe['user'], 'nick') . '.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'Твои войска потерпели жестокого поражения от ' . user($InAttack['user'], 'nick') . '. У него осталось ' . $ResultMy . '% армии.<br/>Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief2;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$StrongFoe[user]', '$message2', '$rtime', '0', 'i')");
// возвращаем армию обратно
mysql_query("UPDATE users SET terrain = '$CoorMe[id]' WHERE id = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResMy', time_run = '0', time_back = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "' WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' AND done = '0' LIMIT 1");
mysql_query("DELETE FROM duty WHERE id = '$StrongFoe[id]' AND user = '$StrongFoe[user]' LIMIT 1");
}
// если армия оппонента 100% сильнее нападающего
elseif ($battleResOpp > 0 && $battleResMy == 0 && $StrongFoe['security'] == 1)
{
// урон генералам
$damageMeGen = 100 - $ResultMy;
$GenMin = minus($prmMyGen['health'], $damageMeGen);
$damageFoeGen = 100 - $ResultOpp;
$GenMinF = minus($prmFoeGen['health'], $damageFoeGen);
if (isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET health = '$GenMinF' WHERE id = '$prmFoeGen[id]' AND cid IN(SELECT id FROM duty WHERE security = '1')");
}
$prct = round(2 + ($prmMyGen['level'] * $prmMyGen['career']) * 100 / 100);
mysql_query("UPDATE generals SET health = '$damageMeGen', practice = practice + '$prct' WHERE id = '$prmMyGen[id]' LIMIT 1");
if ($prmMyGen['practice'] == compute_params($prmMyGen['id'], 0))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmMyGen[id]' LIMIT 1");
}
if ($prmFoeGen['practice'] == compute_params($prmFoeGen['id'], 0) && isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmFoeGen[id]' LIMIT 1");
}
$message1 = 'На твой замок было совершено неудачное нападение от ' . user($InAttack['user'], 'nick') . ', войска выдержали оборону.';
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$StrongFoe[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'Твои войска потерпели позорного поражения после нападения на замок ' . user($StrongFoe['user'], 'nick') . '. У противника осталось ' . $ResultOpp . '% армии.';
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message2', '$rtime', '0', 'i')");
mysql_query("DELETE FROM duty WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResOpp' WHERE id = '$StrongFoe[id]' AND user = '$StrongFoe[user]' AND done = '0'");
}
// если армия нападающего сильнее оппонента, но не убила всю его армию
elseif ($battleResMy > $battleResOpp && $battleResMy != 0 && $battleResOpp != 0 && $StrongFoe['security'] == 1)
{
// грабеж
$robbery = ($battleResMy * $InAttack['capacity']);
$isset_thief = mysql_fetch_assoc(mysql_query("SELECT * FROM thiefs WHERE player = '$InAttack[user]' AND timeleft < '$rtime' LIMIT 1"));
// проверяем шпиона..
$isset_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$StrongFoe[user]' AND timeleft < '$rtime' LIMIT 1"));
if (isset($isset_scout['id']) && isset($isset_thief['id']))
{
// шанс шпиона вычислить вора
$chance = abs(mt_rand(1, $isset_thief['practice']) - mt_rand(1, $isset_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE thiefs SET health = health - '$chance' WHERE player = '$InAttack[user]' LIMIT 1");
$Death = true;
}
}
// проверяем вора..
elseif (isset($isset_thief['id']))
{
$robbery = round($robbery / 200 * $isset_thief['practice']);
}
$_robbery = round($robbery / 5);
// грабим склад
$ufood = minus(user($StrongFoe['user'], 'food'), $_robbery);
$uore = minus(user($StrongFoe['user'], 'ore'), $_robbery);
$utree = minus(user($StrongFoe['user'], 'tree'), $_robbery);
$ustone = minus(user($StrongFoe['user'], 'stone'), $_robbery);
$ugold = minus(user($StrongFoe['user'], 'gold'), $_robbery);
$mfood = minus(user($StrongFoe['user'], 'food'), $ufood);
$more = minus(user($StrongFoe['user'], 'ore'), $uore);
$mtree = minus(user($StrongFoe['user'], 'tree'), $utree);
$mstone = minus(user($StrongFoe['user'], 'stone'), $ustone);
$mgold = minus(user($StrongFoe['user'], 'gold'), $ugold);
// запись похищенных ресурсов во временную таблу
mysql_query("INSERT INTO temporary SET
id = '$InAttack[id]',
food = '$mfood',
tree = '$mtree',
stone = '$mstone',
ore = '$more',
gold = '$mgold',
player = '$InAttack[user]',
timeleft = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "'");
mysql_query("UPDATE users SET food = '$ufood', tree = '$utree', stone = '$ustone', ore = '$uore', gold = '$ugold' WHERE id = '$StrongFoe[user]' LIMIT 1");
// урон генералам
$damageMeGen = 100 - $ResultMy;
$GenMin = minus($prmMyGen['health'], $damageMeGen);
$damageFoeGen = 100 - $ResultOpp;
$GenMinF = minus($prmFoeGen['health'], $damageFoeGen);
if (isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET health = '$GenMinF' WHERE id = '$prmFoeGen[id]' AND cid IN(SELECT id FROM duty WHERE security = '1')");
}
$prct = round(2 + ($prmMyGen['level'] * $prmMyGen['career']) * 100 / 100);
mysql_query("UPDATE generals SET health = '$damageMeGen', practice = practice + '$prct' WHERE id = '$prmMyGen[id]' LIMIT 1");
if ($prmMyGen['practice'] == compute_params($prmMyGen['id'], 0))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmMyGen[id]' LIMIT 1");
}
if ($prmFoeGen['practice'] == compute_params($prmFoeGen['id'], 0) && isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmFoeGen[id]' LIMIT 1");
}
if (!empty($Death))
{
$mess_thief1 = '<br/>Шпион противника обнаружил твоего вора при нападении, вор не смог ничего украсть.';
$mess_thief2 = '<br/>Твой шпион обнаружил у противника вора при нападении, вор не смог ничего украсть.';
}
$message1 = 'На твой замок было совершено нападение от ' . user($InAttack['user'], 'nick') . ', часть твоих войск отступило, у противника осталось ' . $ResultMy . '% армии.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief2;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$StrongFoe[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'Твои войска успешно напали на замок ' . user($StrongFoe['user'], 'nick') . ', ' . $ResultOpp . '% армии противника отступило.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief1;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message2', '$rtime', '0', 'i')");
// возвращаем армию обратно
mysql_query("UPDATE users SET terrain = '$CoorMe[id]' WHERE id = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResMy', time_run = '0', time_back = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "' WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' AND done = '0' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResOpp' WHERE id = '$StrongFoe[id]' AND user = '$StrongFoe[user]' AND done = '0'");
}
// если армия оппонента сильнее, чем нападающего, но не убила всю его армию
elseif ($battleResMy < $battleResOpp && $battleResMy != 0 && $battleResOpp != 0 && $StrongFoe['security'] == 1)
{
// грабеж
$robbery = ($battleResMy * $InAttack['capacity']);
$isset_thief = mysql_fetch_assoc(mysql_query("SELECT * FROM thiefs WHERE player = '$InAttack[user]' AND timeleft < '$rtime' LIMIT 1"));
// проверяем шпиона..
$isset_scout = mysql_fetch_assoc(mysql_query("SELECT * FROM scouts WHERE player = '$StrongFoe[user]' AND timeleft < '$rtime' LIMIT 1"));
if (isset($isset_scout['id']) && isset($isset_thief['id']))
{
// шанс шпиона вычислить вора
$chance = abs(mt_rand(1, $isset_thief['practice']) - mt_rand(1, $isset_scout['practice']));
if (mt_rand(1, 100) > $chance)
{
mysql_query("UPDATE thiefs SET health = health - '$chance' WHERE player = '$InAttack[user]' LIMIT 1");
$Death = true;
}
}
// проверяем вора..
elseif (isset($isset_thief['id']))
{
$robbery = round($robbery / 200 * $isset_thief['practice']);
}
$_robbery = round($robbery / 5);
// грабим склад
$ufood = minus(user($StrongFoe['user'], 'food'), $_robbery);
$uore = minus(user($StrongFoe['user'], 'ore'), $_robbery);
$utree = minus(user($StrongFoe['user'], 'tree'), $_robbery);
$ustone = minus(user($StrongFoe['user'], 'stone'), $_robbery);
$ugold = minus(user($StrongFoe['user'], 'gold'), $_robbery);
$mfood = minus(user($StrongFoe['user'], 'food'), $ufood);
$more = minus(user($StrongFoe['user'], 'ore'), $uore);
$mtree = minus(user($StrongFoe['user'], 'tree'), $utree);
$mstone = minus(user($StrongFoe['user'], 'stone'), $ustone);
$mgold = minus(user($StrongFoe['user'], 'gold'), $ugold);
// запись похищенных ресурсов во временную таблу
mysql_query("INSERT INTO temporary SET
id = '$InAttack[id]',
food = '$mfood',
tree = '$mtree',
stone = '$mstone',
ore = '$more',
gold = '$mgold',
player = '$InAttack[user]',
timeleft = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "'");
mysql_query("UPDATE users SET food = '$ufood', tree = '$utree', stone = '$ustone', ore = '$uore', gold = '$ugold' WHERE id = '$StrongFoe[user]' LIMIT 1");
// урон генералам
$damageMeGen = 100 - $ResultMy;
$GenMin = minus($prmMyGen['health'], $damageMeGen);
$damageFoeGen = 100 - $ResultOpp;
$GenMinF = minus($prmFoeGen['health'], $damageFoeGen);
if (isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET health = '$GenMinF' WHERE id = '$prmFoeGen[id]' AND cid IN(SELECT id FROM duty WHERE security = '1')");
}
$prct = round(2 + ($prmMyGen['level'] * $prmMyGen['career']) * 100 / 100);
mysql_query("UPDATE generals SET health = '$damageMeGen', practice = practice + '$prct' WHERE id = '$prmMyGen[id]' LIMIT 1");
if ($prmMyGen['practice'] == compute_params($prmMyGen['id'], 0))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmMyGen[id]' LIMIT 1");
}
if ($prmFoeGen['practice'] == compute_params($prmFoeGen['id'], 0) && isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmFoeGen[id]' LIMIT 1");
}
if (!empty($Death))
{
$mess_thief1 = '<br/>Шпион противника обнаружил твоего вора при нападении, вор не смог ничего украсть.';
$mess_thief2 = '<br/>Твой шпион обнаружил у противника вора при нападении, вор не смог ничего украсть.';
}
$message1 = 'На твой замок было совершено нападение от ' . user($InAttack['user'], 'nick') . ', твои войска прекрасно справились с обороной, ' . $ResultMy . '% армии противника отступило.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief2;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$StrongFoe[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'Часть твоих войск вернулись ни с чем после нападения на замок ' . user($StrongFoe['user'], 'nick') . '. У противника осталось ' . $ResultOpp . '% армии.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold . $mess_thief1;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message2', '$rtime', '0', 'i')");
// возвращаем армию обратно
mysql_query("UPDATE users SET terrain = '$CoorMe[id]' WHERE id = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResMy', time_run = '0', time_back = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "' WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' AND done = '0' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResOpp' WHERE id = '$StrongFoe[id]' AND user = '$StrongFoe[user]' AND done = '0'");
}
// когда у противника не выставлена охрана замка или произошла ничья
else
{
// грабеж
$robbery = ($battleResMy * $InAttack['capacity']);
$_robbery = round($robbery / 5);
// грабим склад
$ufood = minus(user($StrongFoe['user'], 'food'), $_robbery);
$uore = minus(user($StrongFoe['user'], 'ore'), $_robbery);
$utree = minus(user($StrongFoe['user'], 'tree'), $_robbery);
$ustone = minus(user($StrongFoe['user'], 'stone'), $_robbery);
$ugold = minus(user($StrongFoe['user'], 'gold'), $_robbery);
$mfood = minus(user($StrongFoe['user'], 'food'), $ufood);
$more = minus(user($StrongFoe['user'], 'ore'), $uore);
$mtree = minus(user($StrongFoe['user'], 'tree'), $utree);
$mstone = minus(user($StrongFoe['user'], 'stone'), $ustone);
$mgold = minus(user($StrongFoe['user'], 'gold'), $ugold);
// охраны нет
if ($StrongFoe['security'] == 0)
{
$message1 = 'Атака на ' . user($TerrainMe['id_player'], 'nick') . ' прошла без кровопролития.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'На замок было совершено нападение от ' . user($InAttack['user'], 'nick') . ', но у тебя нет охраны.<br/>
Ресурсов было похищено:
<img src="/images/res.1.png" alt=""/>' . $mfood . '
<img src="/images/res.2.png" alt=""/>' . $mtree . '
<img src="/images/res.3.png" alt=""/>' . $mstone . '
<img src="/images/res.4.png" alt=""/>' . $more . '
<img src="/images/res.5.png" alt=""/>' . $mgold;
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$TerrainMe[id_player]', '$message2', '$rtime', '0', 'i')");
// запись похищенных ресурсов во временную таблу
mysql_query("INSERT INTO temporary SET
id = '$InAttack[id]',
food = '$mfood',
tree = '$mtree',
stone = '$mstone',
ore = '$more',
gold = '$mgold',
player = '$InAttack[user]',
timeleft = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "'");
mysql_query("UPDATE users SET food = '$ufood', tree = '$utree', stone = '$ustone', ore = '$uore', gold = '$ugold' WHERE id = '$StrongFoe[user]' LIMIT 1");
// возвращаем армию обратно
mysql_query("UPDATE users SET terrain = '$CoorMe[id]' WHERE id = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET time_run = '0', time_back = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "' WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' AND done = '0' LIMIT 1");
}
// охрана есть, НО НИЧЬЯ
else
{
// урон генералам
$damageMeGen = 100 - $ResultMy;
$GenMin = minus($prmMyGen['health'], $damageMeGen);
$damageFoeGen = 100 - $ResultOpp;
$GenMinF = minus($prmFoeGen['health'], $damageFoeGen);
if (isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET health = '$GenMinF' WHERE id = '$prmFoeGen[id]' AND cid IN(SELECT id FROM duty WHERE security = '1')");
}
$prct = round(2 + ($prmMyGen['level'] * $prmMyGen['career']) * 100 / 100);
mysql_query("UPDATE generals SET health = '$damageMeGen', practice = practice + '$prct' WHERE id = '$prmMyGen[id]' LIMIT 1");
if ($prmMyGen['practice'] == compute_params($prmMyGen['id'], 0))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmMyGen[id]' LIMIT 1");
}
if ($prmFoeGen['practice'] == compute_params($prmFoeGen['id'], 0) && isset($prmFoeGen['id']))
{
mysql_query("UPDATE generals SET
practice = '0',
level = level + '1',
free_params = free_params + '4'
WHERE id = '$prmFoeGen[id]' LIMIT 1");
}
$message1 = 'На твой замок было совершено нападение от ' . user($InAttack['user'], 'nick') . ', в результате битвы произошла ничья...';
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$StrongFoe[user]', '$message1', '$rtime', '0', 'i')");
$message2 = 'При нападении на замок ' . user($StrongFoe['user'], 'nick') . ' в результате битвы произошла ничья...';
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$InAttack[user]', '$message2', '$rtime', '0', 'i')");
// возвращаем армию обратно
mysql_query("UPDATE users SET terrain = '$CoorMe[id]' WHERE id = '$InAttack[user]' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResMy', time_run = '0', time_back = '" . (($rtime + $arrival) - ($rtime - $InAttack['time_run'])) . "' WHERE id = '$InAttack[id]' AND user = '$InAttack[user]' AND done = '0' LIMIT 1");
mysql_query("UPDATE duty SET lot = lot - '$battleResOpp' WHERE id = '$StrongFoe[id]' AND user = '$StrongFoe[user]' AND done = '0'");
}
///////////////////
}
}
######################
// Добыча ресурсов
if (round(($rtime - $user['time_later']) / 60) > 0)
{
$ONLY = round(($rtime - $user['time_later']) / 60);
// Добыча еды
$b_1 = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '1' AND timeleft < '$rtime' LIMIT 1");
$count_1 = mysql_num_rows($b_1);
$fetch = mysql_fetch_assoc($b_1);
$d = ($fetch['level'] == 1) ? round(300 / 60) : round(300 * $fetch['level'] / 60);
if ($count_1 == 1) $ago = $d;
elseif ($count_1 == 0) $ago = 3;
$ago = $ago * $ONLY;
if (!empty($ago) && $user['food'] < 1000 && !isset($my_skl['id']) || !empty($ago) && $user['food'] < $STORAGE && isset($my_skl['id'])) mysql_query("UPDATE users SET time_later = '$rtime', food = '" . plus($user['food'], $ago, (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
unset($ago);
// Добыча руды
$b_2 = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '2' AND timeleft < '$rtime' LIMIT 1");
$count_2 = mysql_num_rows($b_2);
$fetch = mysql_fetch_assoc($b_2);
$d = ($fetch['level'] == 1) ? round(300 / 60) : round(300 * $fetch['level'] / 60);
if ($count_2 == 1) $ago = $d;
elseif ($count_2 == 0) $ago = 3;
$ago = $ago * $ONLY;
if (!empty($ago) && $user['ore'] < 1000 && !isset($my_skl['id']) || !empty($ago) && $user['ore'] < $STORAGE && isset($my_skl['id'])) mysql_query("UPDATE users SET time_later = '$rtime', ore = '" . plus($user['ore'], $ago, (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
unset($ago);
// Добыча дерева
$b_3 = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '3' AND timeleft < '$rtime' LIMIT 1");
$count_3 = mysql_num_rows($b_3);
$fetch = mysql_fetch_assoc($b_3);
$d = ($fetch['level'] == 1) ? round(300 / 60) : round(300 * $fetch['level'] / 60);
if ($count_3 == 1) $ago = $d;
elseif ($count_3 == 0) $ago = 3;
$ago = $ago * $ONLY;
if (!empty($ago) && $user['tree'] < 1000 && !isset($my_skl['id']) || !empty($ago) && $user['tree'] < $STORAGE && isset($my_skl['id'])) mysql_query("UPDATE users SET time_later = '$rtime', tree = '" . plus($user['tree'], $ago, (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
unset($ago);
// Добыча камня
$b_4 = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '4' AND timeleft < '$rtime' LIMIT 1");
$count_4 = mysql_num_rows($b_4);
$fetch = mysql_fetch_assoc($b_4);
$d = ($fetch['level'] == 1) ? round(300 / 60) : round(300 * $fetch['level'] / 60);
if ($count_4 == 1) $ago = $d;
elseif ($count_4 == 0) $ago = 3;
$ago = $ago * $ONLY;
if (!empty($ago) && $user['stone'] < 1000 && !isset($my_skl['id']) || !empty($ago) && $user['stone'] < $STORAGE && isset($my_skl['id'])) mysql_query("UPDATE users SET time_later = '$rtime', stone = '" . plus($user['stone'], $ago, (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
unset($ago);
// Добыча золота
$b_5 = mysql_query("SELECT id, level FROM construct WHERE user = '$user[id]' AND cid = '5' AND timeleft < '$rtime' LIMIT 1");
$count_5 = mysql_num_rows($b_5);
$fetch = mysql_fetch_assoc($b_5);
$d = ($fetch['level'] == 1) ? round(300 / 60) : round(300 * $fetch['level'] / 60);
if ($count_5 == 1) $ago = $d;
elseif ($count_5 == 0) $ago = 3;
$ago = $ago * $ONLY;
if (!empty($ago) && $user['gold'] < 1000 && !isset($my_skl['id']) || !empty($ago) && $user['gold'] < $STORAGE && isset($my_skl['id'])) mysql_query("UPDATE users SET time_later = '$rtime', gold = '" . plus($user['gold'], $ago, (!isset($my_skl['id'])) ? 1000 : $STORAGE) . "' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
// Голодовка
$countArmy = mysql_fetch_assoc(mysql_query("SELECT SUM(lot) AS num FROM duty WHERE user = '$user[id]' AND timeleft < '$rtime' AND done = '0'"));
$MIN = minus($user['food'], ceil($countArmy['num'] / 100 * 5));
if ($MIN > $user['food'])
{
mysql_query("UPDATE duty SET lot = '$MIN' WHERE user = '$user[id]' AND done = '0' LIMIT 1");
$message = 'В замке началась голодовка, из войск погибло ' . $MIN . ' чел.';
mysql_query("INSERT INTO `letters` (`id`, `who`, `idwho`, `message`, `data`, `read`, `mod`)
VALUES ('" . mt_rand(1000000, 9999999) . "', '0', '$user[id]', '$message', '$rtime', '0', 'i')");
}
if ($user['time_hunger'] < $rtime && $count_1 != false) mysql_query("UPDATE users SET food = '$MIN', time_hunger = '" . ($rtime + 1 * 60 * 60) . "' AND done = '0' WHERE id = '$user[id]' LIMIT 1");
#---------------------#
}
######################
$r1 = ($user['food'] == $STORAGE) ? $r1 . '<u>' . number_format($user['food']) . '</u>' : number_format($user['food']);
$r2 = ($user['tree'] == $STORAGE) ? $r2 . '<u>' . number_format($user['tree']) . '</u>' : number_format($user['tree']);
$r3 = ($user['stone'] == $STORAGE) ? $r3 . '<u>' . number_format($user['stone']) . '</u>' : number_format($user['stone']);
$r4 = ($user['ore'] == $STORAGE) ? $r4 . '<u>' . number_format($user['ore']) . '</u>' : number_format($user['ore']);
$r5 = ($user['gold'] == $STORAGE) ? $r5 . '<u>' . number_format($user['gold']) . '</u>' : number_format($user['gold']);
$newMail = mysql_result(mysql_query("SELECT COUNT(*) FROM `letters` WHERE `idwho` = '$user[id]' AND `read` = '0'"), 0);
if ($newMail != 0) $newM = '<span class="menu_count">' . $newMail . '</span>';
echo '<table cellpadding="4" align="center">
<tr>
<td>
<a href="/index.php"><img src="/images/main.png" alt="" title="На главную"/></a>
</td><td>
<a href="/map.php"><img src="/images/map.png" alt="" title="Перемещение"/></a>
</td><td>
<a href="/army.php"><img src="/images/command.png" alt="" title="Армия"/></a>
</td><td>
<a href="/chat/"><img src="/images/tavern.png" alt="" title="Таверна"/></a>
</td><td>
<a href="/mail.php"><img src="/images/mail_top.png" alt="" title="Почта"/>' . $newM . '</a>
</td>
<td> <a href="/worldkassa/"><img src="/images/money.png" width="25" height="25" alt="" title="worldkassa"/></a></td>
' . ($user['level'] == 2 ?
'<td>
<a href="/panel.php"><img src="/images/panel.png" alt="" title="Админка"/></a>
</td>' : '') . '
</tr>
</table>
<span class="nowrap"><img src="/images/res.1.png" alt="" title="Еда"/> ' . $r1 . '</span>
<span class="nowrap"><img src="/images/res.2.png" alt="" title="Дерево"/> ' . $r2 . '</span>
<span class="nowrap"><img src="/images/res.3.png" alt="" title="Камень"/> ' . $r3 . '</span>
<span class="nowrap"><img src="/images/res.4.png" alt="" title="Руда"/> ' . $r4 . '</span>
<span class="nowrap"><img src="/images/res.5.png" alt="" title="Золото"/> ' . $r5 . '</span>
<span class="nowrap"><img src="/images/crystal.png" alt="" title="Кристаллы"/> ' . $user['crystal'] . '</span>
<span class="nowrap" style="float: right;"><img src="/kolco/'.$user['kolcoo'].'" alt="" title="Колько"/> </span>
' . separator;
if($user['loks']==0) {
mysql_query("UPDATE `users` SET `loks` = '1' WHERE `id` = '".$user['id']."'");
mysql_query("INSERT INTO `location` (`pic`, `id_player`, `x`, `y`) values('t3c2f0.png', '".$user['id']."', '".$user['coor_x']."', '".$user['coor_y']."')");
}
if (!isset($_GET['adv'])) include $_SERVER['DOCUMENT_ROOT'] . '/sys/advisor.php';
}
if (!empty($_COOKIE['us']) && empty($_SESSION['us']))
{
$_SESSION['us'] = char($_COOKIE['us'], 0);
$_SESSION['ps'] = char($_COOKIE['ps'], 0);
header('Location: /');
}
?>