<?
include './system/common.php'; 
include './system/functions.php'; 
include './system/user.php'; 
if($user) { header('location: /'); exit; } 
$title = 'Зарождение'; 
include './system/h.php'; 

$ref = _string(_num($_GET['ref'])); 
$_SESSION['ref']=$ref;
if ($_SESSION['start']==0 or (!isset($_SESSION['start'])))  {
if ($_SESSION['compl']==0 or (!isset($_SESSION['compl'])))  {
$_SESSION['compl']=1;}
$sex=$_GET['sex'];
if ($sex == 'm' or $sex == 'f') {
$_SESSION['sex']=$sex;
header('Location: startpage');exit;
}
if (isset($_GET['c_sm'])) {
$complect=rand(1,3);
$_SESSION['compl']=$complect;
header('Location: startpage');exit;
}
if (isset($_GET['v_sn'])) {
$_SESSION['start']=1;
header('Location: startpage');exit;
}
$complect=$_SESSION['compl'];
if($complect==1){
$w_1['item']=9;$w_2['item']=10;$w_3['item']=11;$w_4['item']=12;$w_5['item']=13;$w_6['item']=14;$w_7['item']=15;$w_8['item']=16;
}elseif($complect==2){
$w_1['item']=25;$w_2['item']=26;$w_3['item']=27;$w_4['item']=28;$w_5['item']=29;$w_6['item']=30;$w_7['item']=31;$w_8['item']=32;
}elseif($complect==3){
$w_1['item']=17;$w_2['item']=18;$w_3['item']=19;$w_4['item']=20;$w_5['item']=21;$w_6['item']=22;$w_7['item']=23;$w_8['item']=24;
}if($_SESSION['sex']==f){$i['sex']=1;}else{$i['sex']=0;}
if (isset($_GET['prd'])) {
$_SESSION['start']=3;
header('Location: startpage');exit;
}
?>
<div class='center'>
<div class='main' style='word-wrap:break-word;'>
<span style='text-shadow:none;'></span>
<div class='head' onclick='location.href="/"'>Зарождение</div>
<div class='line'></div>
<span class='blue'>Выбери себе снаряжение для битвы!</span></div><div class='line'></div>
<div class='main' style='word-wrap:break-word;'>
<img src='/manekenImage/<?=$i['sex']?>/<?=$w_1['item']?>/<?=$w_2['item']?>/<?=$w_3['item']?>/<?=$w_4['item']?>/<?=$w_5['item']?>/<?=$w_6['item']?>/<?=$w_7['item']?>/<?=$w_8['item']?>/' width='120' height='160' style='margin-right:10px;margin-top:3px;' alt='*'/>
</div><div class='line'></div
><div class='main' style='word-wrap:break-word;'><? if($_SESSION['sex']==f){?>
<span class='blue'>Пол:</span> <a href='/startpage?sex=m'>мужской</a> / <span class='bold'>женский</span><? }
else{?><span class='blue'>Пол:</span> <span class='bold'>мужской</span> / <a href='/startpage?sex=f'>женский</a><? }
?><div class='dot-line'></div><a class='btn' href='/startpage?c_sm'><span class='end'><span class='label'>Выбрать другое снаряжение</span></span></a>
<div class='dot-line'></div><span class='dgreen bold'>+992</span> к параметрам<div class='mb10'></div>
<a class='btn' href='/startpage?prd'><span class='end'><span class='label'>
<span class='dgreen'>Взять это снаряжение</span></span></span></a></div></div><br/>
<?}
if ($_SESSION['start']==1)  {
if (isset($_GET['at'])) {
$_SESSION['start']=2;
header('Location: startpage');exit;
}
?><div class='main' style='word-wrap:break-word;'><span style='text-shadow:none;'></span><div class='head' onclick='location.href="/"'><div class='center'>Зарождение</div>
</div><div class='line'></div>
<div class='center'>На своём пути вы встретили врага<div class='medium'><span class='blue'>— Стой, дальше дороги нет, держи меч и готовься к битве.</span><br/></br></div></div>
<div class='line'></div><div class='block_zero'><div class='float-left'>
<img src='/manekenImage/0/41/42/43/44/45/46/47/48/' width='120' height='160' style='margin-right:10px;margin-top:3px;' alt=''/></div>
<img src='/images/icon/race/1.png' alt=''/> Враг<br/><br/>
<img src='/images/icon/str.png' alt='str'/> Сила: 190<br/>
<img src='/images/icon/vit.png' alt='vit'/> Жизни: 198<br/>
<img src='/images/icon/agi.png' alt='agi'/> Удача: 198<br/>
<img src='/images/icon/def.png' alt='def'/> Броня: 190<br/><br/>
<form action='/startpage?at' method='post'><div>
<span class="btn"><span class="end"><input class='label' type='submit' value='Атаковать'>Атаковать</div></span></span>
</form><div style='clear:both;'></div></div></div><br/><? }
if ($_SESSION['start']==2)  {
if (isset($_GET['prd'])) {
$_SESSION['start']=3;
header('Location: startpage');exit;
}
?><div class='main' style='word-wrap:break-word;'><span style='text-shadow:none;'></span><div class='head' onclick='location.href="/"'><div class='center'>Зарождение</div>
</div><div class='line'></div>
<div class='center'><div class='block_light'><h2 class='dgreen' style='font-weight:bold;'><img src='/images/icon/2hit.png' alt=''/> Победа! <img src='/images/icon/2hit.png' alt=''/></h2> <div class='separ'></div>
<span class='blue'>Награда:</span> <img src='/images/icon/silver.png' alt=''/> 500 серебра</div></div><div class='line'></div>
<div class='float-left'><img src='/manekenImage/0/41/42/43/44/45/46/47/48/' width='120' height='160' style='margin-right:10px;margin-top:3px;' alt=''/></div>
<img src='/images/icon/race/1.png' alt=''/> Враг<br/><br/>
<img src='/images/icon/str.png' alt='str'/> Сила: 190<br/>
<img src='/images/icon/vit.png' alt='vit'/> Жизни: 198<br/>
<img src='/images/icon/agi.png' alt='agi'/> Удача: 198<br/>
<img src='/images/icon/def.png' alt='def'/> Броня: 190<br/>
<div style='clear:both;'></div>
<div class='line'></div>
<center><span class='blue'>Неплохо! Но ещё есть куда стремиться!<br/>Удачи тебе!</span><div class='dot-line'></div><a class='btn' href='/startpage?prd'><span class='end'><span class='label'>Продолжить путь</span></span></a></div><br/></center><? }
if ($_SESSION['start']==3)  {
$ref=$_SESSION['ref'];
$password = rand(111,999); 

  if(mysql_query('INSERT INTO `users` (`login`, 
`password`) VALUEs ("Боец", 
                                               "'.$password.'")')) { 


     
    $id = mysql_insert_id(); 

if($ref) { 

  $ref_user = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$ref.'"'); 
  $ref_user = mysql_fetch_array($ref_user); 

  if($ref_user) { 
   
    mysql_query('INSERT INTO `ref` (`user`, 
                                      `ho`) VALUEs ("'.$ref_user['id'].'", 
                                                                "'.$id.'")'); 
   
  } 

} 
   
  $user = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$id.'"'); 
  $user = mysql_fetch_array($user); 

$com=$_SESSION['compl'];
if($com==1){$com=1;}
elseif($com==2){$com=20;}
elseif($com==3){$com=21;}
if($_SESSION['sex']==m){$isex=0;}else{$isex=1;}
   for($w = 1; $w < 9; $w++) {
    if($com==1){$com=1;}
elseif($com==2){$com=20;}
elseif($com==3){$com=21;}
   
$buy_complect =$com;


    
    $complect = mysql_query('SELECT * FROM `complects` WHERE `id` = "'.$buy_complect.'"');
    $complect = mysql_fetch_array($complect);
    
    switch($complect['quality']) {
      case 1:
      $complect_quality_skill =   1;
       break;
      case 2:
      $complect_quality_skill =  10;
       break;
      case 3:
      $complect_quality_skill =  24;
       break;
      case 4:
      $complect_quality_skill =  48;
       break;
      case 5:
      $complect_quality_skill = 200;
       break;
      case 6:
      $complect_quality_skill = 250;
       break;
	
	}
    

    
    for($w = 1; $w < 9; $w++) {
      $shop = mysql_query('SELECT * FROM `shop` WHERE `id` = "'.$complect['w_'.$w].'"');
      $shop = mysql_fetch_array($shop);
    }
    


    for($w = 1; $w < 9; $w++) {
    
      $shop = mysql_query('SELECT * FROM `shop` WHERE `id` = "'.$complect['w_'.$w].'"');
      $shop = mysql_fetch_array($shop);
    
    
      mysql_query('INSERT INTO `inv` (`user`,
                                      `item`,
                                     `bonus`,
                                      `_str`,
                                      `_vit`,
                                      `_agi`,
                                      `_def`,
                                      `quality`) VALUES ("'.$user['id'].'",
                                                      "'.$shop['id'].'",
                                                   "'.$shop['bonus'].'",
                                                    "'.$shop['_str'].'",
                                                    "'.$shop['_vit'].'",
                                                    "'.$shop['_agi'].'",
                                                    "'.$shop['_def'].'",
                                                    "'.$shop['quality'].'"
                                                    )');
    
        
    }
    
    
       $q = mysql_query('SELECT * FROM `inv` WHERE `user` = \''.$user['id'].'\' AND `equip` = \'0\' ORDER BY `id` DESC');
  while($row = mysql_fetch_array($q)) { 
    $ite = mysql_query('SELECT * FROM `items` WHERE `id`="'.$row['item'].'"');
    $ite = mysql_fetch_array($ite);
      mysql_query('UPDATE `inv` SET `equip` = "1" WHERE `id`="'.$row['id'].'" AND `user`="'.$user['id'].'"');
     
      mysql_query('UPDATE `users` SET `str` = `str` + '.$row['_str'].',
                                      
                                      `vit` = `vit` + '.$row['_vit'].',
                                      
                                      `agi` = `agi` + '.$row['_agi'].',
                                      
                                      `def` = `def` + '.$row['_def'].',
                                      
                         `w_'.$ite['w'].'` = '.$row['id'].' WHERE `id` = \''.$user['id'].'\'');    }
        
  
$_g = 0; 
$_s = 1000; 
$_i = $user['id']-1;

if($_SESSION['sex']==f){$isex=1;}else{$isex=0;}
     mysql_query('UPDATE `users` SET `hp` = "'.($user['vit'] * 2).'", `sex` = "'.$isex.'",`mp` = "'.$user['mana'].'" WHERE `id` = "'.$id.'"');

     mysql_query('UPDATE `users` SET `g`  ="'.$_g.'", 
                                     `s`  ="'.$_s.'" WHERE `id` = "'.$id.'"'); 


  mysql_query('INSERT INTO `arena` (`user`,`opponent`) VALUES ("'.$user['id'].'","'.$_i.'")');


            setCookie('id', $user['id'], time() + 86400, '/'); 
setCookie('password', $password, time() + 86400, '/'); 
     
     
 $_SESSION = array();

      header('location: /arena'); 
  } 
}
}

include './system/f.php'; 
?>