Вход Регистрация
Файл: duty.php
Строк: 146
<?php

require 'sys/sid.php';
require 
'sys/config.php';
include 
'sys/user.php';
include 
'sys/head.php';

visit(0, 'duty');

    
$id_build = mysql_fetch_assoc(mysql_query("SELECT id FROM construct WHERE cid = '6' AND user = '$user[id]' AND timeleft < '$rtime' LIMIT 1"));
    if (!isset(
$id_build['id']))
    {
        
err('У тебя не построено здание Казарма!');
        include 
'sys/foot.php';
        exit();
    }

$id = number($_GET['id']);
if (
$id < 1 || $id > 5)
{
    
err('Ошибка!');
}
else
{
    
$test = mysql_query("SELECT id, timeleft, cid FROM duty WHERE user = '$user[id]' AND timeleft > '$rtime' AND done = '1' LIMIT 1");

    if (
$id == 1)
    {
        
$tree = ($user['race'] == 1) ? 100 : 95;
        
$stone = ($user['race'] == 1) ? 130 : 75;
        
$ore = ($user['race'] == 1) ? 55 : 40;
        
$gold = ($user['race'] == 1) ? 30 : 40;
        
$attack = ($user['race'] == 1) ? 15 : 40;
        
$defence = ($user['race'] == 1) ? 40 : 20;
        
$hp = ($user['race'] == 1) ? 50 : 5;
        
$timer = ($user['race'] == 1) ? 426 : 300;
        
$speed = ($user['race'] == 1) ? 14 : 12;
        
$capacity = ($user['race'] == 1) ? 30 : 60;
        
$nazv = ($user['race'] == 1) ? 'Паладин' : 'Призрак';
        
$img = ($user['race'] == 1) ? '<img src="images/paladin.png" alt=""/>' : '<img src="images/prizrak.png" alt=""/>';
    }
    if (
$id == 2)
    {
        
$tree = ($user['race'] == 1) ? 140 : 145;
        
$stone = ($user['race'] == 1) ? 150 : 70;
        
$ore = ($user['race'] == 1) ? 185 : 85;
        
$gold = ($user['race'] == 1) ? 60 : 40;
        
$attack = ($user['race'] == 1) ? 65 : 10;
        
$defence = ($user['race'] == 1) ? 35 : 35;
        
$hp = ($user['race'] == 1) ? 20 : 60;
        
$timer = ($user['race'] == 1) ? 600 : 444;
        
$speed = ($user['race'] == 1) ? 12 : 10;
        
$capacity = ($user['race'] == 1) ? 40 : 45;
        
$nazv = ($user['race'] == 1) ? 'Мечник' : 'Химера';
        
$img = ($user['race'] == 1) ? '<img src="images/mechnik.png" alt=""/>' : '<img src="images/himera.png" alt=""/>';
    }
    if (
$id == 3)
    {
        
$tree = ($user['race'] == 1) ? 350 : 130;
        
$stone = ($user['race'] == 1) ? 450 : 120;
        
$ore = ($user['race'] == 1) ? 230 : 170;
        
$gold = ($user['race'] == 1) ? 60 : 70;
        
$attack = ($user['race'] == 1) ? 90 : 60;
        
$defence = ($user['race'] == 1) ? 25 : 30;
        
$hp = ($user['race'] == 1) ? 40 : 30;
        
$timer = ($user['race'] == 1) ? 1020 : 492;
        
$speed = ($user['race'] == 1) ? 38 : 10;
        
$capacity = ($user['race'] == 1) ? 75 : 50;
        
$nazv = ($user['race'] == 1) ? 'Стрелок' : 'Осквернитель';
        
$img = ($user['race'] == 1) ? '<img src="images/strelok.png" alt=""/>' : '<img src="images/oskvernitel.png" alt=""/>';
    }
    if (
$id == 4)
    {
        
$tree = ($user['race'] == 1) ? 360 : 370;
        
$stone = ($user['race'] == 1) ? 330 : 270;
        
$ore = ($user['race'] == 1) ? 280 : 290;
        
$gold = ($user['race'] == 1) ? 120 : 75;
        
$attack = ($user['race'] == 1) ? 45 : 55;
        
$defence = ($user['race'] == 1) ? 115 : 100;
        
$hp = ($user['race'] == 1) ? 55 : 40;
        
$timer = ($user['race'] == 1) ? 1044 : 984;
        
$speed = ($user['race'] == 1) ? 32 : 20;
        
$capacity = ($user['race'] == 1) ? 35 : 110;
        
$nazv = ($user['race'] == 1) ? 'Маг' : 'Грифон';
        
$img = ($user['race'] == 1) ? '<img src="images/mag.png" alt=""/>' : '<img src="images/grifon.png" alt=""/>';
    }
    if (
$id == 5)
    {
        
$tree = ($user['race'] == 1) ? 500 : 450;
        
$stone = ($user['race'] == 1) ? 620 : 515;
        
$ore = ($user['race'] == 1) ? 675 : 780;
        
$gold = ($user['race'] == 1) ? 170 : 80;
        
$attack = ($user['race'] == 1) ? 140 : 150;
        
$defence = ($user['race'] == 1) ? 50 : 50;
        
$hp = ($user['race'] == 1) ? 165 : 75;
        
$timer = ($user['race'] == 1) ? 1284 : 1218;
        
$speed = ($user['race'] == 1) ? 26 : 18;
        
$capacity = ($user['race'] == 1) ? 65 : 80;
        
$nazv = ($user['race'] == 1) ? 'Колосс' : 'Йетти';
        
$img = ($user['race'] == 1) ? '<img src="images/koloss.png" alt=""/>' : '<img src="images/yetti.png" alt=""/>';
    }

    if (isset(
$_POST['ok']))
    {
        
$count = number($_POST['count']);
        
$name = char($_POST['name'], 0);
        
$union = number($_POST['union']);

        if (
mysql_num_rows($test) != false) $err = 'Только 1 партию юнитов можно тренировать одновременно!';
        if (empty(
$name) && $union == 0) $err = 'Необходимо ввести название отряда!';
        if (empty(
$count)) $err = 'Необходимо ввести кол-во!';
        if (
$user['tree'] < $tree * $count) $err2[] .= '<img src="/images/res.2.png" alt="" title="Дерево"/>' . ($tree * $count - $user['tree']);
        if (
$user['stone'] < $stone * $count) $err2[] .= '<img src="/images/res.3.png" alt="" title="Камень"/>' . ($stone * $count - $user['stone']);
        if (
$user['ore'] < $ore * $count) $err2[] .= '<img src="/images/res.4.png" alt="" title="Руда"/>' . ($ore * $count - $user['ore']);
        if (
$user['gold'] < $gold * $count) $err2[] .= '<img src="/images/res.5.png" alt="" title="Золото"/>' . ($gold * $count - $user['gold']);

        if (!empty(
$err2))
        {
            
err('Тебе нехватает: ' . implode(', ', $err2));
        }
        elseif (!empty(
$err))
        {
            
err($err);
        }
        else
        {
            
mysql_query("UPDATE users SET
            tree = tree - '" 
. ($tree * $count) . "',
            stone = stone - '" 
. ($stone * $count) . "',
            ore = ore - '" 
. ($ore * $count) . "',
            gold = gold - '" 
. ($gold * $count) . "' WHERE id = '$user[id]' LIMIT 1");

            if (
$union == 0) mysql_query("INSERT INTO duty SET id = '" . mt_rand(1000000, 9999999) . "', name = '$name', lot = '$count', timeleft = '" . ($rtime + $count * $timer) . "', cid = '$id', user = '$user[id]', health = '$hp', power = '$attack', defence = '$defence', speed = '$speed', capacity = '$capacity', done = '1'");

            else 
mysql_query("UPDATE duty SET lot = lot + '$count', timeleft = '" . ($rtime + $count * $timer) . "', done = '1' WHERE id = '$union' AND user = '$user[id]' LIMIT 1");
            if (!isset(
$_SESSION['countDone'])) $_SESSION['countDone'] = $count;
            
msg('Юниты тренируются.');
        }
    }

    if (
mysql_num_rows($test) != false)
    {
        
$inSql = mysql_fetch_assoc($test);
        if (
$user['race'] == 1)
        {
            if (
$inSql['cid'] == 1) $r = 'Паладин';
            if (
$inSql['cid'] == 2) $r = 'Мечник';
            if (
$inSql['cid'] == 3) $r = 'Стрелок';
            if (
$inSql['cid'] == 4) $r = 'Маг';
            if (
$inSql['cid'] == 5) $r = 'Колосс';
        }
        else
        {
               if (
$inSql['cid'] == 1) $r = 'Призрак';
            if (
$inSql['cid'] == 2) $r = 'Химера';
            if (
$inSql['cid'] == 3) $r = 'Осквернитель';
            if (
$inSql['cid'] == 4) $r = 'Грифон';
            if (
$inSql['cid'] == 5) $r = 'Йетти';
        }
        echo 
'Тренировка юнитов (' . number($_SESSION['countDone']) . ' чел. ' . $r . ') закончится через ' . val($inSql['timeleft'] - $rtime) . separator;
    }

    echo 
'<form method="post" action="duty'.$id.'">
          ' 
. $img . '
          <br/>
          <b>' 
. $nazv . '</b>
          <br/>
          <img src="images/attack.png" alt="" title="Атака"/> Атака: ' 
. $attack . '<br/>
          <img src="images/defence.png" alt="" title="Защита"/> Защита: ' 
. $defence . '<br/>
          <img src="images/hp.png" alt="" title="Здоровье"/> Здоровье: ' 
. $hp . '<br/>
          <img src="images/speed.png" alt="" title="Скорость"/> Скорость: ' 
. $speed . ' полей/час<br/>
          <img src="images/capacity.png" alt="" title="Грузоподъемность"/> Грузоподъемность: ' 
. $capacity . ' ед.<br/>
          <img src="images/time.png" alt="" title="Время обучения"/> Время обучения: ' 
. val($timer) . '
          ' 
. separator . '
          Кол-во юнитов:<br/>
          <input type="text" name="count" size="3"/>
          <br/>
          Название для отряда (max. 10):<br/>
          <input type="text" name="name" size="10" maxlength="10"/>
          <br/>
          Объеденить в отряд?
          <br/>
          <select name="union">
          <option value="0">- Не объеденять -</option>'
;
          
$l = mysql_query("SELECT duty .*, SUM(lot) AS l FROM duty WHERE done = '0' AND user = '$user[id]' AND timeleft < '$rtime' AND cid = '$id' GROUP BY lot");
          while(
$leg = mysql_fetch_assoc($l))
          {
              if (isset(
$leg['id'])) echo '<option value="'.$leg['id'].'">' . $leg['name'] . ' (' . $leg['l'] . ')</option>';
          }
    echo 
'</select>
          <br/>
          <img src="images/res.2.png" alt="Дерево"/> ' 
. $tree . '
          <img src="images/res.3.png" alt="Камень"/> ' 
. $stone . '
          <img src="images/res.4.png" alt="Руда"/> ' 
. $ore . '
          <img src="images/res.5.png" alt="Золото"/> ' 
. $gold . '
          <br/>
          <input type="submit" name="ok" value="Тренировать"/>
          </form>'
;
}

echo 
'<a href="index.php">На главную</a>';

include 
'sys/foot.php';
?>
Онлайн: 2
Реклама