Файл: wenr.online/app/game/smith.php
Строк: 70
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (!$user->isAuth()) {
redirect('/');
exit;
}
$slot1 = 0;
$slot2 = 0;
if(isset($_SESSION['slot'][1])) $slot1 = $_SESSION['slot'][1]['item'];
if(isset($_SESSION['slot'][2])) $slot2 = $_SESSION['slot'][2]['item'];
function check_item($name){
global $db,$user;
$stall = $db->prepare('select * from `bag` where `name` = ? and `user` = ?');
$stall -> execute([$name,$user->get()->user_id]);
return $stall -> fetch(PDO :: FETCH_OBJ);
}
$all = $db->prepare('select * from `bag` where user = ? and type = ? and status = ? order by id');
$all -> execute([$user->get()->user_id,'weapon',0]);
$smith = $db->prepare('select id,name from bag where user = ? and type = ? and name != ? and name != ? order by name');
$smith -> execute([$user->get()->user_id,'drop',$slot1,$slot2]);
$smith = $smith->fetchAll();
if(isset($_GET['clear'])){
unset($_SESSION['slot']);
redirect('/smith');
exit;
}
if(isset($_POST['slot'])){
$slot_id = Clean :: int($_GET['slot']);
$item_id = Clean :: int($_POST['slot']);
if(!in_array($slot_id,[1,2])){
redirect('/smith');
exit;
}
$item = $db->prepare('select * from `bag` where `id` = ?');
$item -> execute([$item_id]);
$item = $item -> fetch(PDO :: FETCH_OBJ);
if(!isset($item->id) or $item->user != $user->get()->user_id or $item->type != 'drop'){
redirect('/smith');
exit;
}
if($user->get()->forging == 0){
Notif :: error('Для работы необходим навык «Ковка оружия»','/smith');
exit;
}
$_SESSION['slot'][$slot_id] = ['item'=>$item->name,'img'=>$item->type.'/'.$item->img];
redirect('/smith');
exit;
}
$forging_we = $db->prepare('select * from `smith` where `one` = ? and `dop` = ?');
$forging_we -> execute([$slot1,$slot2]);
$forging_we = $forging_we -> fetch(PDO :: FETCH_OBJ);
if(isset($_POST['go'])){
if(!isset($forging_we->id)){
redirect('/smith');
exit;
}
if($user->get()->forging == 0){
Notif :: error('Для работы необходим навык «Ковка оружия»','/smith');
exit;
}
if(!isset(check_item($forging_we->one) -> id)){
Notif :: error('Для ковки оружия нужна «'.$forging_we->one.'»','/smith');
exit;
}
if(!isset(check_item($forging_we->dop) -> id) and !empty($forging_we->dop)){
Notif :: error('Для ковки оружия нужна «'.$forging_we->dop.'»','/smith');
exit;
}
$item = $db->prepare('select * from `shop` where `id` = ?');
$item -> execute([$forging_we->item]);
$item = $item -> fetch(PDO :: FETCH_OBJ);
$sql = $db->prepare('insert into `bag` (`name`,`user`,`type`,`dex`,`force`,`hp`,`max_hp`,`mana`,`mana_max`,`img`) values (?,?,?,?,?,?,?,?,?,?)');
$sql -> execute([
$item->name,
$user->get()->user_id,
$item->type,
$item->dex,
$item->force,
$item->hp,
$item->max_hp,
$item->mana,
$item->mana_max,
$item->img
]);
$del = $db->prepare('delete from `bag` where `id` = ?');
$del -> execute([check_item($forging_we->one)->id]);
$del = $db->prepare('delete from `bag` where `id` = ?');
$del -> execute([check_item($forging_we->dop)->id]);
unset($_SESSION['slot']);
Notif :: message('Вы выковали «'.$forging_we->name.'»','/smith');
exit;
}
if(isset($_POST['item'])){
$item_id = Clean :: int($_POST['item']);
$item = $db->prepare('select * from `bag` where `id` = ?');
$item -> execute([$item_id]);
$item = $item -> fetch(PDO :: FETCH_OBJ);
if(!isset($item->id) or $item->user != $user->get()->user_id or $item->status = 0 or $item->type != 'weapon'){
redirect('/smith');
exit;
}
$array = ['Меч демона','Лук демона'];
if($user->get()->smith == 0){
Notif :: error('Для работы необходим навык «Заточка клинков»','/smith');
exit;
}
if(in_array($item->name,$array)){
Notif :: error('Оружие «'.$item->name.'» не поддается заточке','/smith');
exit;
}
if($item ->smith >= 20){
Notif :: error('Дальнейшее улучшение невозможно','/smith');
exit;
}
if($user->get()->gold < 100){
Notif :: error('Нехватает золота для улучшения','/smith');
exit;
}
if($item->force > 0){
$up = $db->prepare('update `bag` set `force` = ?, `smith` = ? where `id` = ?');
$up -> execute([$item->force+1,$item->smith+1,$item->id]);
}
if($item->dex > 0){
$up = $db->prepare('update `bag` set `dex` = ?, `smith` = ? where `id` = ?');
$up -> execute([$item->dex+1,$item->smith+1,$item->id]);
}
$gold = $db->prepare('update users set gold = ? where user_id = ?');
$gold -> execute([$user->get()->gold-100,$user->get()->user_id]);
Notif :: message('Вы успешно улучшили оружие «'.$item->name.'»','/smith');
exit;
}
echo $template->render('game.smith',['all' => $all->fetchAll(), 'forging_we' => $forging_we, 'smith' => $smith]);