db = $db; $_user = $this->db->prepare('SELECT * FROM `user` WHERE `id` = ?'); $_user -> execute([1]); $this->user = $_user -> fetch(); } public function fill() { for ($x = 0; $x < $this->size[0]; ++$x) { for ($y = 0; $y < $this->size[1]; ++$y) { $table = ' %s '; if ($slot = $this->find($x, $y)) { $_item = $this->db->prepare('SELECT * FROM `items` where `id` = ? LIMIT 1'); $_item -> execute([$slot['item']]); $item = $_item -> fetch(); if(time() > ($slot['time'] + $item['time'])){ $__table = $this->db->prepare('UPDATE `table` SET `status` = ? WHERE `id` = ? LIMIT 1'); $__table->execute(['sword', $slot['id']]); } if(time() > ($slot['time'] + $item['complete'])){ $__table = $this->db->prepare('UPDATE `table` SET `status` = ? WHERE `id` = ? LIMIT 1'); $__table->execute(['complete', $slot['id']]); } $background = '?i=preview&img='.$item['image'].'&rotation='.($slot['rotation'] ? $slot['rotation'] : 0); $shiftX = ($x - ($slot['rotation'] == '180' ? $slot['x2'] : $slot['x'])) * $this->dp; $shiftY = ($y - ($slot['rotation'] == '90' ? $slot['y2'] : $slot['y'])) * $this->dp; $a = ''; $this->table[$y][$x] = sprintf($table, $this->dp, $this->dp, $background, $shiftX, $shiftY, $a); } else{ if($_GET['i'] == 'ore' && isset($_GET['item'])) $a2 = ''; $this->table[$y][$x] = sprintf($table, $this->dp, $this->dp, 'images/slot.png', 0, 0, $a2); } } } } public function show() { $this->fill(); for ($y = 0; $y < $this->size[1]; ++$y) { echo '
'; for ($x = 0; $x < $this->size[0]; ++$x) { echo $this->table[$y][$x]; } echo '
'; } } public function find($x, $y) { $_check = $this->db->prepare('SELECT * FROM `table` WHERE ? >= LEAST(`x`, `x2`) AND ? <= GREATEST(`x`, `x2`) AND ? >= LEAST(`y`, `y2`) AND ? <= GREATEST(`y`, `y2`)'); $_check -> execute([$x,$x,$y,$y]); return $_check->fetch(); } } $Table = new Table(new PDO('mysql:host=127.0.0.1;dbname=sword;charset=UTF8', 'root', ''), 1); $user = $Table->user; switch($_GET['i']){ case 'sword': $_slot = $Table->db->prepare('SELECT * FROM `table` WHERE `user` = ? AND `id` = ?'); $_slot -> execute([$user['id'], (int)$_GET['sword']]); $slot = $_slot-> fetch(); $_item = $Table->db->prepare('SELECT * FROM `items` WHERE `id` = ?'); $_item -> execute([$slot['item']]); $item = $_item-> fetch(); if(!$slot){ header('Location:/'); exit; } if($slot['status'] == 'ore'){ echo ' До стадии клинка:'.($item['time'] + ($slot['time'] - time())).' сек До изготовления:'.($item['complete'] + ($slot['time'] - time())).' сек
Стадия: Руда '; } if($slot['status'] == 'sword'){ echo ' До изготовления:'.($item['complete'] + ($slot['time'] - time())).' сек
Стадия: Клинок '; } if($slot['status'] == 'complete'){ $_sword = $Table->db->prepare('SELECT * FROM `swords` WHERE `ore` = ? ORDER BY RAND() LIMIT 1'); $_sword -> execute([$item['ore']]); $sword = $_sword-> fetch(); echo 'Вы выковали '.$sword['name'].'!!'; $__slot = $Table->db->prepare('INSERT INTO `inventory` SET `user` = ?, `time` = ?, `item` = ?, `type` = ?, `count` = ?, `rang` = ?'); $__slot->execute([$user['id'], time(), $sword['id'], 'sword', '1', '1']); $__slot = $Table->db->prepare('DELETE FROM `table` WHERE `id` = ? LIMIT 1'); $__slot->execute([(int)$_GET['sword']]); } default: echo' '; $Table->show(); break; case 'preview': header('Content-Type: image/png'); $dp = 4; $image = imagecreatefrompng('images/swords/'.$_GET['img'].'.png'); list($width, $height) = getimagesize('images/swords/'.$_GET['img'].'.png'); if(in_array($_GET['rotation'], [90,270])){ $image = imagerotate($image, $_GET['rotation'], 0); $image2 = imagecreate ($height * $dp, $width * $dp); imagecopyresampled($image2, $image, 0, 0, 0, 0, $height * $dp, $width * $dp , $height, $width); } elseif($_GET['rotation'] == 180){ $image = imagerotate($image, $_GET['rotation'], 0); $image2 = imagecreate ($width * $dp, $height * $dp); imagecopyresampled($image2, $image, 0, 0, 0, 0, $width * $dp, $height * $dp , $width, $height); } else{ $image2 = imagecreate ($width * $dp, $height * $dp); imagecopyresampled($image2, $image, 0, 0, 0, 0, $width * $dp, $height * $dp , $width, $height); } imagepng($image2); exit; case 'ore': // ?x='.$x.'&y='.$y.'&item='.$_GET['ore'].'&rotation='.$user['last_rotation'].' if(isset($_GET['x']) and isset($_GET['y']) and isset($_GET['item'])){ $_items = $Table->db->prepare('SELECT * FROM `items` WHERE `id` = ?'); $_items -> execute([(int)$_GET['item']]); $item = $_items -> fetch(); if($item){ $x2 = (in_array($_GET['rotation'], [90,270]) ? ((int)$_GET['x'] + $item['height'] - 1) : ((int)$_GET['x'] + $item['width'] -1)); $y2 = (in_array($_GET['rotation'], [90,270]) ? ((int)$_GET['y'] + $item['width'] - 1) : ((int)$_GET['y'] + $item['height'] -1)); $_check = $Table->db->prepare('SELECT * FROM `table` WHERE ? >= LEAST(`x`, `x2`) AND ? <= GREATEST(`x`, `x2`) AND ? >= LEAST(`y`, `y2`) AND ? <= GREATEST(`y`, `y2`)'); $_check -> execute([$x2,$x2,$y2,$y2]); $check = $_check->fetch(); if($check){ header('Location:/?blacksmit'); exit; } else{ $__table = $Table->db->prepare('INSERT INTO `table` SET `user` = ?, `item` = ?, `x` = ?, `y` = ?, `x2` = ?, `y2` = ?, `rotation` = ?, `time` = ?, `status` = ?'); $__table->execute([$user['id'],(int)$_GET['item'],(int)$_GET['x'],(int)$_GET['y'],$x2,$y2,($_GET['rotation'] ? (int)$_GET['rotation'] : 0), time(), 'ore']); } } header('Location:/?blacksmit'); exit; } echo' '; $Table->show(); break; }