 <?php
include 'core/system.php';

head('Сердце Тьмы');
reg();
$sql = $dbc->query("SELECT * FROM `artefact` WHERE `user_id`='".$user['id']."' AND `status` = 2 AND `art` = 0 ORDER by `art_id` ");

$total = $dbc->query("SELECT `id` FROM `artefact` where `user_id` ='".$user['id']."' AND `status` = 2 AND `art` = 0 "); $total = $total->num_rows;


if($total==0){
echo '<div class="main"><div class="block_zero center">Нет вещей для улучшения!</div></div>';

    foot();
    exit;
}
while($row = $sql->fetch_assoc()){
if($row['craft']>0){ $fla = '<span class="info">+'.$row['craft'].''; }else{ $fla = '';}



$sia = $row['craft']+1;

if($row['lite']==iSuperior){ $last = 1000*$sia; $limit = 5; }





if($row['lite']==iEpic){ $last = 5000*$sia; $limit = 10; }


$rubin = 0;


if($row['lite']==iLegendary){ $last = 20000*$sia; $limit = 48;  }


if($row['lite']==mif){ $last = 50000*$sia; $limit = $user['level'];  }


if($row['lite']==iLegendary and $sia>=15){ $last = $last+20000;  }

$sevo = $sia - 30;

$credit = 1000*$sevo;


$devo = 1000 + $credit;


if($row['lite']==iLegendary and $sia>=31){ $last = $last+120000; $rubin = $devo;   }



if($row['lite']==mif and $sia>=31){ $last = $last+120000; $rubin = $devo;   }


if($row['craft'] > 29){ $yrs = '<img src=img/money/rubin.png> '.$rubin.'';}else{ $yrs = '';}










?><div class="sblue-panel"><div class="panel-inner-3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="37" style="vertical-align: top;"><img width="32"height="32" src="img/items/<?=$row['img']?>.png" alt="."border="0"></td><td><div><a href="/info_art.php?ids=<?=$row['id']?>" class="<?=$row['lite']?>"><center><?=$row['nik']?></a><?=$fla?></center></div><span class="nowrap"></span> <span class="nowrap"></span><span class="clearer"></span></td><?



if($row['craft']<$limit){
?><td width="40"><a href="/craft.php?id=<?=$row['id']?><??>&amp;craft" class="gr-btn center"><span>Заточить за <img src="img/stat/sera.png"><?=$last?> <?=$yrs?></span></a></td><? 




}      ?></tr></table></div></div><?









echo' </div>';
if(isset($_GET['craft']) and !empty($_GET['id'])){

    $pet_id = int($_GET['id']);
$pet = $dbc->query("SELECT * FROM `artefact` WHERE `id`='".$pet_id."' AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc();

if($pet['art']==1){ $_SESSION['message']='Артефакт нельзя заточить'; header('location:craft.php');exit;}
if($pet['tip']==9){ $_SESSION['message']='Артефакт нельзя зачаровать'; header('location:mag.php');exit;} 

if(!$pet){
        header("Location: craft.php");

        exit;
        }
        if($pet['status']==1){
        header("Location: craft.php");

        exit;
        }
$sia = $pet['craft']+1;

if($pet['lite']==iSuperior){ $last = 1000*$sia; $limit = 5; }






if($pet['lite']==iEpic){ $last = 5000*$sia; $limit = 10; }




if($pet['lite']==iLegendary){ $last = 20000*$sia; $limit = 48;  }

if($pet['lite']==mif){ $last = 50000*$sia; $limit = $user['level'];  }



if($pet['lite']==iLegendary and $sia>=15){ $last = $last+20000;  }



$rubin = 0;


$sevo = $sia - 30;

$credit = 1000*$sevo;


$devo = 1000 + $credit;


if($pet['lite']==iLegendary and $sia>=31){ $last = $last+120000; $rubin = $devo;   }

if($pet['lite']==mif and $sia>=31){ $last = $last+120000; $rubin = $devo;   }














if($user['serebro']<$last){ $_SESSION['message']='не достаточно серебра'; header('location: craft.php');exit; 

}
if($user['rub']<$rubin){ $_SESSION['message']='не достаточно Рубинов'; header('location: craft.php');exit; 


}if($pet['craft']>=$limit){ header('location: craft.php');exit; }





if($pet['craft']<30){ 

$dbc->query("UPDATE `users` SET `strength`=`strength`+1,`max_health`=`max_health`+5,`defense`=`defense`+1,`serebro`=`serebro`-'".$last."' ,`rub` =`rub`-'".$rubin."' WHERE `id`='".$user['id']."'");




        
$dbc->query("UPDATE `artefact` SET `strong`=`strong`+1,`hp`=`hp`+5,`prot`=`prot`+1, `craft`=`craft`+1 WHERE `id`='".$pet['id']."'");



}else{ 




$dbc->query("UPDATE `users` SET `strength`=`strength`+5,`max_health`=`max_health`+50,`defense`=`defense`+5,`serebro`=`serebro`-'".$last."' ,`rub` =`rub`-'".$rubin."' WHERE `id`='".$user['id']."'");



        
$dbc->query("UPDATE `artefact` SET `strong`=`strong`+5,`hp`=`hp`+50,`prot`=`prot`+5, `craft`=`craft`+1 ,`sp`=`sp`+1 WHERE `id`='".$pet['id']."'");

}


if($pet['sp']==19){ 

$dbc->query("UPDATE `users` SET `sokru`=`sokru`+20,`vampir`=`vampir`+20 WHERE `id`='".$user['id']."'");



        
$dbc->query("UPDATE `artefact` SET `sok`=`sok`+20,`vamp`=`vamp`+20,`lite`='mif' WHERE `id`='".$pet['id']."'"); }




$_SESSION['message'] = 'Заточка + 1 на '.$pet[nik].'';

header('Location: craft.php?');exit();

        foot();
}
}
if($user['art']==1){ ?><center><a class="btn" href="craft_art.php">Улучшить  Артефакт</a></center><? }
foot();
?> 
