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

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

visit(0, 'smithy');

    
$id_build = mysql_fetch_assoc(mysql_query("SELECT id FROM construct WHERE cid = '10' 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
{
    if (
$id == 1)
    {
        
$attack = 3;
        
$defence = 2;
        
$nazv = ($user['race'] == 1) ? 'Паладин' : 'Призрак';
        
$img = ($user['race'] == 1) ? '<img src="images/paladin.png" alt=""/>' : '<img src="images/prizrak.png" alt=""/>';
    }
    if (
$id == 2)
    {
        
$attack = 5;
        
$defence = 4;
        
$nazv = ($user['race'] == 1) ? 'Мечник' : 'Химера';
        
$img = ($user['race'] == 1) ? '<img src="images/mechnik.png" alt=""/>' : '<img src="images/himera.png" alt=""/>';
    }
    if (
$id == 3)
    {
        
$attack = 10;
        
$defence = 6;
        
$nazv = ($user['race'] == 1) ? 'Стрелок' : 'Осквернитель';
        
$img = ($user['race'] == 1) ? '<img src="images/strelok.png" alt=""/>' : '<img src="images/oskvernitel.png" alt=""/>';
    }
    if (
$id == 4)
    {
        
$attack = 13;
        
$defence = 8;
        
$nazv = ($user['race'] == 1) ? 'Маг' : 'Грифон';
        
$img = ($user['race'] == 1) ? '<img src="images/mag.png" alt=""/>' : '<img src="images/grifon.png" alt=""/>';
    }
    if (
$id == 5)
    {
        
$attack = 25;
        
$defence = 15;
        
$nazv = ($user['race'] == 1) ? 'Колосс' : 'Йетти';
        
$img = ($user['race'] == 1) ? '<img src="images/koloss.png" alt=""/>' : '<img src="images/yetti.png" alt=""/>';
    }

        
$ctrl = mysql_query("SELECT * FROM upgraded_units WHERE player = '$user[id]' AND uid = '$id' LIMIT 1");
        
$control = mysql_fetch_assoc($ctrl);

    if (isset(
$_POST['ok']))
    {
        
$what = number($_POST['what']);
    
//---------------------------------------------------//
        
if ($what == 1 && $control['power'] == 0)
        {
            
$FOOD = 150;
            
$GOLD = 160;
            
$time_to_mod = 300;
        }
        if (
$what == 1 && $control['power'] == 1)
        {
            
$FOOD = 265;
            
$GOLD = 290;
            
$time_to_mod = 350;
        }
        if (
$what == 1 && $control['power'] == 2)
        {
            
$FOOD = 380;
            
$GOLD = 400;
            
$time_to_mod = 400;
        }
        if (
$what == 1 && $control['power'] == 3)
        {
            
$FOOD = 430;
            
$GOLD = 430;
            
$time_to_mod = 450;
        }
        if (
$what == 1 && $control['power'] == 4)
        {
            
$FOOD = 660;
            
$GOLD = 750;
            
$time_to_mod = 550;
        }
        if (
$what == 1 && $control['power'] == 5)
        {
            
$FOOD = 750;
            
$GOLD = 890;
            
$time_to_mod = 700;
        }
        if (
$what == 1 && $control['power'] == 6)
        {
            
$FOOD = 885;
            
$GOLD = 970;
            
$time_to_mod = 800;
        }
        if (
$what == 1 && $control['power'] == 7)
        {
            
$FOOD = 1055;
            
$GOLD = 1190;
            
$time_to_mod = 900;
        }
        if (
$what == 1 && $control['power'] == 8)
        {
            
$FOOD = 1450;
            
$GOLD = 1550;
            
$time_to_mod = 999;
        }
        if (
$what == 1 && $control['power'] == 9)
        {
            
$FOOD = 1880;
            
$GOLD = 1850;
            
$time_to_mod = 1050;
        }
        if (
$what == 2 && $control['defence'] == 0)
        {
            
$FOOD = 150;
            
$GOLD = 160;
            
$time_to_mod = 300;
        }
        if (
$what == 2 && $control['defence'] == 1)
        {
            
$FOOD = 265;
            
$GOLD = 290;
            
$time_to_mod = 350;
        }
        if (
$what == 2 && $control['defence'] == 2)
        {
            
$FOOD = 380;
            
$GOLD = 400;
            
$time_to_mod = 400;
        }
        if (
$what == 2 && $control['defence'] == 3)
        {
            
$FOOD = 430;
            
$GOLD = 430;
            
$time_to_mod = 450;
        }
        if (
$what == 2 && $control['defence'] == 4)
        {
            
$FOOD = 660;
            
$GOLD = 750;
            
$time_to_mod = 550;
        }
        if (
$what == 2 && $control['defence'] == 5)
        {
            
$FOOD = 750;
            
$GOLD = 890;
            
$time_to_mod = 700;
        }
        if (
$what == 2 && $control['defence'] == 6)
        {
            
$FOOD = 885;
            
$GOLD = 970;
            
$time_to_mod = 800;
        }
        if (
$what == 2 && $control['defence'] == 7)
        {
            
$FOOD = 1055;
            
$GOLD = 1190;
            
$time_to_mod = 900;
        }
        if (
$what == 2 && $control['defence'] == 8)
        {
            
$FOOD = 1450;
            
$GOLD = 1550;
            
$time_to_mod = 999;
        }
        if (
$what == 2 && $control['defence'] == 9)
        {
            
$FOOD = 1880;
            
$GOLD = 1850;
            
$time_to_mod = 1050;
        }
    
//---------------------------------------------------//
        
if ($what == 1 && $control['power'] == 10)
        {
            
err('Атака данного юнита улучшена на максимум!');
        }
        elseif (
$what == 2 && $control['defence'] == 10)
        {
            
err('Защита данного юнита улучшена на максимум!');
        }
        else
        {
            echo 
'Для улучшения необходимо:
                   <br/>
                  <img src="images/res.1.png" alt="Еда"/> ' 
. $FOOD . '
                  <img src="images/res.5.png" alt="Золото"/> ' 
. $GOLD . '
                     <img src="images/time.png" alt="Время"/> ' 
. conv($time_to_mod) . '
                    <form method="post" action="smithy'
.$id.'">
                  <input type="hidden" name="what" value="'
.$what.'"/>
                    <input type="submit" name="next" value="Продолжить?"/>
                   </form>
                   <a href="smithy'
.$id.'">Вернуться</a>';
         }
         include 
'sys/foot.php';
         exit();
    }

    if (isset(
$_POST['next']))
    {
        
$what = number($_POST['what']);
    
//---------------------------------------------------//
        
if ($what == 1 && $control['power'] == 0)
        {
            
$FOOD = 150;
            
$GOLD = 160;
            
$time_to_mod = 300;
        }
        if (
$what == 1 && $control['power'] == 1)
        {
            
$FOOD = 265;
            
$GOLD = 290;
            
$time_to_mod = 350;
        }
        if (
$what == 1 && $control['power'] == 2)
        {
            
$FOOD = 380;
            
$GOLD = 400;
            
$time_to_mod = 400;
        }
        if (
$what == 1 && $control['power'] == 3)
        {
            
$FOOD = 430;
            
$GOLD = 430;
            
$time_to_mod = 450;
        }
        if (
$what == 1 && $control['power'] == 4)
        {
            
$FOOD = 660;
            
$GOLD = 750;
            
$time_to_mod = 550;
        }
        if (
$what == 1 && $control['power'] == 5)
        {
            
$FOOD = 750;
            
$GOLD = 890;
            
$time_to_mod = 700;
        }
        if (
$what == 1 && $control['power'] == 6)
        {
            
$FOOD = 885;
            
$GOLD = 970;
            
$time_to_mod = 800;
        }
        if (
$what == 1 && $control['power'] == 7)
        {
            
$FOOD = 1055;
            
$GOLD = 1190;
            
$time_to_mod = 900;
        }
        if (
$what == 1 && $control['power'] == 8)
        {
            
$FOOD = 1450;
            
$GOLD = 1550;
            
$time_to_mod = 999;
        }
        if (
$what == 1 && $control['power'] == 9)
        {
            
$FOOD = 1880;
            
$GOLD = 1850;
            
$time_to_mod = 1050;
        }
        if (
$what == 2 && $control['defence'] == 0)
        {
            
$FOOD = 150;
            
$GOLD = 160;
            
$time_to_mod = 300;
        }
        if (
$what == 2 && $control['defence'] == 1)
        {
            
$FOOD = 265;
            
$GOLD = 290;
            
$time_to_mod = 350;
        }
        if (
$what == 2 && $control['defence'] == 2)
        {
            
$FOOD = 380;
            
$GOLD = 400;
            
$time_to_mod = 400;
        }
        if (
$what == 2 && $control['defence'] == 3)
        {
            
$FOOD = 430;
            
$GOLD = 430;
            
$time_to_mod = 450;
        }
        if (
$what == 2 && $control['defence'] == 4)
        {
            
$FOOD = 660;
            
$GOLD = 750;
            
$time_to_mod = 550;
        }
        if (
$what == 2 && $control['defence'] == 5)
        {
            
$FOOD = 750;
            
$GOLD = 890;
            
$time_to_mod = 700;
        }
        if (
$what == 2 && $control['defence'] == 6)
        {
            
$FOOD = 885;
            
$GOLD = 970;
            
$time_to_mod = 800;
        }
        if (
$what == 2 && $control['defence'] == 7)
        {
            
$FOOD = 1055;
            
$GOLD = 1190;
            
$time_to_mod = 900;
        }
        if (
$what == 2 && $control['defence'] == 8)
        {
            
$FOOD = 1450;
            
$GOLD = 1550;
            
$time_to_mod = 999;
        }
        if (
$what == 2 && $control['defence'] == 9)
        {
            
$FOOD = 1880;
            
$GOLD = 1850;
            
$time_to_mod = 1050;
        }
    
//---------------------------------------------------//
        
if ($control['timeleft'] > $rtime)
        {
            
err('В данные момент уже производится улучшение этого юнита!');
        }
        elseif (
$what == 1 && $control['power'] == 10)
        {
            
err('Атака данного юнита улучшена на максимум!');
        }
        elseif (
$what == 2 && $control['defence'] == 10)
        {
            
err('Защита данного юнита улучшена на максимум!');
        }
        elseif (
$user['food'] < $FOOD)
        {
            
err('Нехватает ' . ($FOOD - $user['food']) . ' еды!');
        }
        elseif (
$user['gold'] < $GOLD)
        {
            
err('Нехватает ' . ($GOLD - $user['gold']) . ' золота!');
        }
        else
        {
            
$what = ($what == 1) ? 'power_mod' : 'defence_mod';

            if (
mysql_num_rows($ctrl) != false)
            {
                
mysql_query("UPDATE users SET food = food - '$FOOD', gold = gold - '$GOLD' WHERE id = '$user[id]' LIMIT 1");
                
mysql_query("UPDATE upgraded_units SET $what = $what + '1', timeleft = '" . ($rtime + $time_to_mod) . "' WHERE player = '$user[id]' AND uid = '$id' LIMIT 1");
                
msg('Началось улучшение навыков юнита.');
            }
            else
            {
                
mysql_query("UPDATE users SET food = food - '$FOOD', gold = gold - '$GOLD' WHERE id = '$user[id]' LIMIT 1");
                
mysql_query("INSERT INTO upgraded_units SET $what = '1', timeleft = '" . ($rtime + $time_to_mod) . "', player = '$user[id]', uid = '$id'");
                
msg('Началось улучшение навыков юнита.');
            }
        }
    }

    if (
$control['timeleft'] > $rtime)
    {
        echo 
'<div style="padding:10px;">Идет улучшение навыков юнита, осталось ' . val($control['timeleft'] - $rtime) . '</div>' . separator;
    }

    echo 
$img . '
         <br/>
         <b>' 
. $nazv . '</b>
         <br/>
         <img src="images/attack.png" alt=""/> ' 
. $attack . '<span style="color:#00AA00">+' . paramUnit($id, $user['id'], 1) . '</span> |
         <img src="images/defence.png" alt=""/> ' 
. $defence . '<span style="color:#00AA00">+' . paramUnit($id, $user['id'], 2) . '</span>
         <br/>
         <form method="post" action="smithy_ok'
.$id.'">
         Что улучшить?
         <br/>
         <select name="what">
         <option value="1">Атака</option>
         <option value="2">Защита</option>
         </select>
         <br/>
         <input type="submit" name="ok" value="Улучшить"/>
         </form>'
;

}

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

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