<?php
require_once ('system/func.php');
$title = 'Тренировка';
require_once ('system/header.php');
auth(); // Закроем от гостей





    function cost($i) {
        
        switch($i) {
          case 0:
           $cost= 100;
           break;
        
          case 1:
           $cost= 330;
           break;
        
          case 2:
           $cost= 700;
           break;
          
          case 3:
           $cost= 1000;
           break;

          case 4:
           $cost= 1300;
           break;   
           
          case 5:
           $cost= 50;
           break;        

          case 6:
           $cost= 2200;
           break;   

          case 7:
           $cost= 2800;
           break;

          case 8:
           $cost= 3600;
           break;   
           
          case 9:
           $cost= 4900;
           break;   

          case 10:
           $cost= 8000;
         
           break;   

          case 11:
           $cost= 150;
           break;   

          case 12:
           $cost= 9000;
           break;   

          case 13:
           $cost= 10000;
           break;   

          case 14:
           $cost= 11000;
           break;   

          case 15:
           $cost= 13000;
           break;   

          case 16:
           $cost= 23000;
           break;   

          case 17:
           $cost= 300;
           break;   

          case 18:
           $cost= 30000;
           break;   

          case 19:
           $cost= 33000;
           break;   

          case 20:
           $cost= 36000;
           break;   

          case 21:
           $cost= 43000;
           break;   

          case 22:
           $cost= 33000;
           break;   

          case 23:
           $cost= 600;
           break;   

          case 24:
           $cost= 64000;
           break;   

          case 25:
           $cost= 78000;
           break;   

          case 26:
           $cost= 90000;
           break;   

          case 27:
           $cost= 100000;
           break;   

          case 28:
           $cost= 110000;
           break;   

          case 29:
           $cost= 1200;
           break;   

          case 30:
           $cost= 130000;
           break;   

          case 31:
           $cost= 133000;
           break;   

          case 32:
           $cost= 140000;
           break;   

          case 33:
           $cost= 143000;
           break;   

          case 34:
           $cost= 160000;
           break;   

          case 35:
           $cost= 2400;
           break;   

          case 36:
           $cost= 200000;
           break;   

          case 37:
           $cost= 220000;
           break;   

          case 38:
           $cost= 240000;
           break;   

          case 39:
           $cost=260000;
           break;   

          case 40:
           $cost= 270000;
           break;   

          case 41:
           $cost= 4000;
           break;   

          case 42:
           $cost= 303000;
           break;   

          case 43:
           $cost= 312000;
           break;   

          case 44:
           $cost= 324000;
           break;   

          case 45:
           $cost= 333000;
           break;   

          case 46:
           $cost= 343873;
           break;   

          case 47:
           $cost= 6000;
           break;   

          case 48:
           $cost= 373000;
           break;   

          case 49:
           $cost= 383000;
           break;   

          case 50:
           $cost= 392000;
           break;   

          case 51:
           $cost= 410000;
           break;   

          case 52:
           $cost= 433000;
           break;   

          case 53:
           $cost= 10000;
           break;   

          case 54:
           $cost= 470000;
           break;   

          case 55:
           $cost= 483000;
           break;   

          case 56:
           $cost= 500000;
           break;   

          case 57:
           $cost= 520000;
           break;   

          case 58:
           $cost= 600000;
           break;   

          case 59:
           $cost= 15000;
           break;   

 

        }
        
global $user;
global $auction;
    return $cost;
    
    }

    function value($i) {
        
        switch($i) {
          case 0:
           $value = 'gold';
           break;
        
          case 1:
           $value = 'gold';
           break;
        
          case 2:
           $value = 'gold';
           break;
          
          case 3:
           $value = 'gold';
           break;

          case 4:
           $value = 'gold';
           break;        

          case 5:
           $value = 'almaz';
           break;        

          case 6:
           $value = 'gold';
           break;        

          case 7:
           $value = 'gold';
           break;        

          case 8:
           $value = 'gold';
           break;        

          case 9:
           $value = 'gold';
           break;        

          case 10:
           $value = 'gold';
           break;        

          case 11:
           $value = 'almaz';
           break;        

          case 12:
           $value = 'gold';
           break;        

          case 13:
           $value = 'gold';
           break;        

          case 14:
           $value = 'gold';
           break;        

          case 15:
           $value = 'gold';
           break;        

          case 16:
           $value = 'gold';
           break;        

          case 17:
           $value = 'almaz';
           break;        

          case 18:
           $value = 'gold';
           break;        
        
          case 19:
           $value = 'gold';
           break;        

          case 20:
           $value = 'gold';
           break;        
          
          case 21:
           $value = 'gold';
           break;        
          
          case 22:
           $value = 'gold';
           break;     
              
          case 23:
           $value = 'almaz';
           break;        

          case 24:
           $value = 'gold';
           break;     

          case 25:
           $value = 'gold';
           break;     

          case 26:
           $value = 'gold';
           break;     

          case 27:
           $value = 'gold';
           break;     

          case 28:
           $value = 'gold';
           break;     

          case 29:
           $value = 'almaz';
           break;     

          case 30:
           $value = 'gold';
           break;     

          case 31:
           $value = 'gold';
           break;     

          case 32:
           $value = 'gold';
           break;     

          case 33:
           $value = 'gold';
           break;     

          case 34:
           $value = 'gold';
           break;     

          case 35:
           $value = 'almaz';
           break;     

          case 36:
           $value = 'gold';
           break;     

          case 37:
           $value = 'gold';
           break;     

          case 38:
           $value = 'gold';
           break;     

          case 39:
           $value = 'gold';
           break;     

          case 40:
           $value = 'gold';
           break;     

          case 41:
           $value = 'almaz';
           break;     

          case 42:
           $value = 'gold';
           break;     

          case 43:
           $value = 'gold';
           break;     

          case 44:
           $value = 'gold';
           break;     

          case 45:
           $value = 'gold';
           break;     

          case 46:
           $value = 'gold';
           break;     

          case 47:
           $value = 'almaz';
           break;     

          case 48:
           $value = 'gold';
           break;     

          case 49:
           $value = 'gold';
           break;     

          case 50:
           $value = 'gold';
           break;     

          case 51:
           $value = 'gold';
           break;     

          case 52:
           $value = 'gold';
           break;     

          case 53:
           $value = 'almaz';
           break;     

          case 54:
           $value = 'gold';
           break;     

          case 55:
           $value = 'gold';
           break;     

          case 56:
           $value = 'gold';
           break;     

          case 57:
           $value = 'gold';
           break;     

          case 58:
           $value = 'gold';
           break;     

          case 59:
           $value = 'almaz';
           break;     

        }
    
    return $value;
    
    }



 

 

if(isset($_GET['str'])) {
if($user['_str'] != 60) {
if(value($user['_str']) == 'gold') {
if($user['gold'] < cost($user['_str'])) {
$_SESSION['msg'] = "Не хватает ".ico('icons','gold.png')." ".(cost($user['_str'])-$user['gold'])." золота";
header('Location: /train?'.$random);
exit();
}else{
mysql_query('UPDATE `users` SET `str` =   `str` + 10,
                                         `_str` =  `_str` + 1
                                         WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `gold` = `gold` - '.cost($user['_str']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = "<div class='block_win'>Сила +10</div> ";
header('Location: /train?'.$random);
exit();
}
}elseif(value($user['_str'] == 'almaz')) {
if($user['almaz'] < cost($user['_str'])) {
$_SESSION['msg'] = " <div class='block_lose'> Не хватает ".ico('icons','almaz.png')." ".(cost($user['_str'])-$user['almaz'])." алмазов</div>";
header('Location: /train?'.$random);
exit();}else{
mysql_query('UPDATE `users` SET `str` =   `str` + 15,
                                         `_str` =  `_str` + 1
                                        WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `almaz` = `almaz` - '.cost($user['_str']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = " <div class='block_win'> Сила  +15</div> ";
header('Location: /train?'.$random);
exit();
}    
}
}    
}
if(isset($_GET['def'])) {
if($user['_def'] != 60) {
if(value($user['_def']) == 'gold') {
if($user['gold'] < cost($user['_def'])) {
$_SESSION['msg'] = "Не хватает ".ico('icons','gold.png')." ".(cost($user['_def'])-$user['gold'])." золота";
header('Location: /train?'.$random);
exit();
}else{
mysql_query('UPDATE `users` SET `def` =   `def` + 10,
                                         `_def` =  `_def` + 1
                                         WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `gold` = `gold` - '.cost($user['_def']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = " <div class='block_win'> Броня +10</div>";
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

header('Location: /train?'.$random);
exit();
}
}elseif(value($user['_def'] == 'almaz')) {
if($user['almaz'] < cost($user['_def'])) {
$_SESSION['msg'] = " <div class='block_lose'> Не хватает ".ico('icons','almaz.png')." ".(cost($user['_def'])-$user['almaz'])." алмазов</div>";
header('Location: /train?'.$random);
exit();
}else{
mysql_query('UPDATE `users` SET `def` =   `def` + 15,
                                         `_def` =  `_def` + 1
                                        WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `almaz` = `almaz` - '.cost($user['_def']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = " <div class='block_win'> Броня +15</div> ";
header('Location: /train?'.$random);
exit();
}    
}
}    
}
if(isset($_GET['health'])) {
if($user['_health'] != 60) {
if(value($user['_health']) == 'gold') {

if($user['gold'] < cost($user['_health'])) {
$_SESSION['msg'] = " <div class='block_lose'> Не хватает ".ico('icons','gold.png')." ".(cost($user['_health'])-$user['gold'])." золота</div>";
header('Location: /train?'.$random);
exit();
}else{
mysql_query('UPDATE `users` SET `max_health` =   `max_health` + 10,
                                         `_health` =  `_health` + 1
                                        WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `gold` = `gold` - '.cost($user['_health']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = " <div class='block_win'> Здоровье +10</div> ";
header('Location: /train?'.$random);
exit();
}
}elseif(value($user['_health'] == 'almaz')) {
if($user['almaz'] < cost($user['_health'])) {
$_SESSION['msg'] = " <div class='block_lose'> Не хватает ".ico('icons','almaz.png')." ".(cost($user['_health'])-$user['almaz'])." алмазов</div>";
header('Location: /train?'.$random);
exit();
}else{
mysql_query('UPDATE `users` SET `max_health` =   `max_health` + 15,
                                         `_health` =  `_health` + 1
                                        WHERE `id` = "'.$user['id'].'"');
mysql_query('UPDATE `users` SET `almaz` = `almaz` - '.cost($user['_health']).' WHERE `id` = "'.$user['id'].'"');
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '12'"));
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$q['id']."')");

$_SESSION['msg'] = " <div class='block_win'> Здоровье + 15</div> ";
header('Location: /train?'.$random);
exit();
}    
}
}    
}

echo div('block_c')."<img src='/images/other/train.png?v2'></div>";

echo div('wrapper');


echo ico ('icons','str.png')." Сила: $user[str] <br>";
if($user['_str'] != 60){
echo "<center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'>  <a href='?str'  >Улучшить  ".(value($user['_str']) == 'almaz' ? ico('icons','almaz.png') : ico('icons','gold.png'))." ".cost($user['_str'])."</div></span></span></a></center>";
}
echo"</div>";
echo div('wrapper');


echo ico ('icons','def.png')." Броня: $user[def] <br>";
if($user['_def'] != 60){
    echo "<center> <div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?def' >Улучшить  ".(value($user['_def']) == 'almaz' ? ico('icons','almaz.png') : ico('icons','gold.png'))." ".cost($user['_def'])."</div></span></span></a></center>";

}
echo "</div>";


echo div('wrapper');

echo ico ('icons','health.png')." Здоровье: $user[max_health]<br>";
if($user['_health'] != 60){
    echo "<center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?health'>Улучшить  ".(value($user['_health']) == 'almaz' ? ico('icons','almaz.png') : ico('icons','gold.png'))." ".cost($user['_health'])."</div></span></span></a>";

}
echo"</div>";
require_once ('system/footer.php');
?>