prepare('SELECT * FROM `user` WHERE `id` = ?');
$_user -> execute([1]);
$user = $_user -> fetch();
function check($x, $y, $dash, $set = array()) {
global $size;
if (!isset($dash[$x][$y])) return $set;
if ($dash[$x][$y] == '5') return false;
$set[$x . '_' . $y] = $dash[$x][$y];
if ($dash[$x][$y] == '6') return $set;
$shifts = [
[$x + 1, $y], [$x - 1, $y],
[$x, $y + 1], [$x, $y - 1]
];
for ($i = 0; $i < 4; ++$i) {
$x2 = $shifts[$i][0];
$y2 = $shifts[$i][1];
if ($x2 >= 0 && $x2 <= $size[0] && $y2 >= 0 && $y2 <= $size[1] && isset($dash[$x2][$y2]) && $dash[$x2][$y2] == $dash[$x][$y] && !isset($set[$x2.'_'.$y2])) $set = check($x2, $y2, $dash, $set);
}
return $set;
}
switch($_GET['i']){
default:
$_location = $db -> prepare('SELECT * FROM `locations` WHERE `id` = ?');
$_location -> execute([1]);
$location = $_location -> fetch();
$_actions = $db -> query('SELECT * FROM `locations_actions`');
$actions = $_actions -> fetchAll();
echo '
';
echo '
';
if(!$_SESSION['message']) foreach($actions as $action){
$_lines = $db -> prepare('SELECT * FROM `location_lines` WHERE `action` = ? AND `action_` = ? AND `action_` <> ? LIMIT 1');
$_lines -> execute([$user['action'], $action['id'], $user['action']]);
$line = $_lines -> fetch();
if($action['id'] !== $user['action'] and $line) echo '
';
}
else echo '
';
echo '
'.$_SESSION['message'].'
Заново
';
//unset($_SESSION['message']);
//echo '
//
//';
break;
case 'new':
$_actions = $db -> prepare('UPDATE `user` SET `action` = ? WHERE `id` = ?');
$_actions -> execute([1, $user['id']]);
header('Location:/area.php');
exit;
case 'unset':
unset($_SESSION['message']);
header('Location:/area.php');
exit;
case 'action':
$_location = $db -> prepare('SELECT * FROM `locations` WHERE `id` = ?');
$_location -> execute([1]);
$location = $_location -> fetch();
$_actions = $db -> prepare('SELECT * FROM `locations_actions` WHERE `id` = ?');
$_actions -> execute([(int)$_GET['action']]);
$action = $_actions -> fetch();
$_lines = $db -> prepare('SELECT * FROM `location_lines` WHERE `action` = ? AND `action_` = ?');
$_lines -> execute([$user['action'], (int)$_GET['action']]);
$line = $_lines -> fetch();
if($line && $action && $action['location'] == $location['id'] ){
$_actions = $db -> prepare('UPDATE `user` SET `action` = ? WHERE `id` = ?');
$_actions -> execute([(int)$_GET['action'], $user['id']]);
if($action['type'] == 3){
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `put` = ?, `round` = ?, `attack` = ? WHERE `id` = ?');
$__user->execute([0, 0, 1, 1, $user['id']]);
$_mob = $db -> prepare('SELECT * FROM `monsters` WHERE `id` = ?');
$_mob -> execute([$action['monster']]);
$mob = $_mob -> fetch();
$_check = $db -> prepare('SELECT * FROM `attack` WHERE `user` = ?');
$_check -> execute([$user['id']]);
$check = $_check -> fetch();
if($mob and !$check){
$__user = $db->prepare('INSERT INTO `attack` SET `user` = ?, `location` = ?, `mob` = ?, `hp` = ?, `effect` = ?, `time` = ?, `kill` = ?');
$__user->execute([$user['id'], 1, $mob['id'], $mob['hp'], 0, time(), 0]);
$_area = $db -> prepare('SELECT * FROM `area`');
$_area -> execute();
$_area = $_area -> fetchAll();
$_areas = $db -> prepare('SELECT * FROM `areas`');
$_areas -> execute();
$areas = $_areas -> fetchAll();
foreach ($areas as $area) {
$dash[$area['x']][$area['y']] = $area['area'];
}
$randi = rand(2,4);
for ($i>0; $i<$randi; ++$i) {
while (true) {
$area = $_area[array_rand($_area)];
if ($area['chanse'] >= rand(1, 100)) {
$rand = $area['id'] == 6 ? 5 : $area['id'];
break;
}
}
$x = rand(0,2);
$y = rand(0,2);
$_check = $db->query('SELECT `x`,`y` FROM `areas` WHERE `user` = '.$user['id'].' AND `x` = '.$x.' AND `y` = '.$y.' LIMIT 1');
$check = $_check->fetch();
if(!$check and count(check($x, $y, $dash)) < 3){
$__user = $db->prepare('INSERT INTO `areas` SET `user` = ?, `x` = ?, `y` = ?, `area` = ?');
$__user->execute([$user['id'], $x, $y, $rand]);
}
else{
--$i;
}
}
}
header('Location:/area.php?i=area');
exit;
}
}
else{
header('Location:/area.php');
exit;
}
break;
case 'image':
$_location = $db -> prepare('SELECT * FROM `locations` WHERE `id` = ?');
$_location -> execute([1]);
$location = $_location -> fetch();
$_actions = $db -> query('SELECT * FROM `locations_actions`');
$actions = $_actions -> fetchAll();
header('Content-type: image/png');
$basis = imagecreatefrompng('images/1.png');
$w = imagecolorallocate($basis, 255, 250, 255);
if($_SESSION['message']) imagecopyresampled($basis, imagecreatefrompng('images/locations/win.png'), 0, 50, 0, 0, 318, 221, 318, 221);
else {
imagesetstyle ($basis, [$w, $w, $w, IMG_COLOR_TRANSPARENT, $w, $w, $w]);
foreach($actions as $action){
$image = $user['action'] == $action['id'] ? imagecreatefrompng('images/locations/user.png') : imagecreatefrompng('images/locations/'.$action['type'].'.png');
imagecopyresampled($basis, $image, $action['top'], $action['left'], 0, 0, 16, 16, 16, 16);
imagedestroy($image);
$_lines = $db -> prepare('SELECT * FROM `location_lines` WHERE `action` = ? AND `location` = ?');
$_lines -> execute([$action['id'],1]);
$lines = $_lines -> fetchAll();
foreach($lines as $line){
imageline($basis, $line['line_x'], $line['line_y'], $line['line_x_'], $line['line_y_'], IMG_COLOR_STYLED);
imageline($basis, $line['line_x'], $line['line_y'] + 1, $line['line_x_'], $line['line_y_'] + 1, IMG_COLOR_STYLED);
//imageline($basis, $line['line_x'], $line['line_y']+2, $line['line_x_'], $line['line_y_']+2, IMG_COLOR_STYLED);
//imageline($basis, $line['line_x'], $line['line_y']+3, $line['line_x_'], $line['line_y_']+3, IMG_COLOR_STYLED);
}
$_lines = $db -> prepare('SELECT * FROM `location_lines` WHERE `action` = ? AND `action_` = ?');
$_lines -> execute([$user['action'], $action['id']]);
$line = $_lines -> fetch();
if($line) imagecopyresampled($basis, imagecreatefrompng('images/locations/cursor.png'), $action['top'] + 2, $action['left'] - 20, 0, 0, 12, 17, 12, 17);
}
}
imagepng($basis);
imagedestroy($basis);
exit;
case 'area':
$_attack = $db -> prepare('SELECT * FROM `attack` WHERE `user` = ?');
$_attack -> execute([$user['id']]);
$attack = $_attack -> fetch();
$_mobs = $db -> prepare('SELECT * FROM `monsters` WHERE `id` = ?');
$_mobs -> execute([$attack['mob']]);
$mob = $_mobs -> fetch();
if(!$attack or !$mob){
header('Location:/area.php');
exit;
}
$_areas = $db -> prepare('SELECT * FROM `areas`');
$_areas -> execute();
$areas = $_areas -> fetchAll();
foreach ($areas as $area) {
$dash[$area['x']][$area['y']] = $area['area'];
}
$_area = $db -> prepare('SELECT * FROM `area`');
$_area -> execute();
$_area = $_area -> fetchAll();
while (true) {
$area = $_area[array_rand($_area)];
if ($area['chanse'] >= rand(1, 100)) {
$rand = $area['id'];
break;
}
}
if(!$user['attack'] and !$user['round'] and $attack['hp'] > 0){
$__user = $db->prepare('UPDATE `user` SET `attack` = ?, `round` = ? WHERE `id` = ?');
$__user->execute([1, 5, $user['id']]);
header('Location:/area.php?i=area');
exit;
}
if($attack['hp'] < 1){
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `round` = ?, `attack` = ?, `put` = ? WHERE `id` = ?');
$__user->execute([0, 0, 0, 0, $user['id']]);
$__areas = $db->prepare('DELETE FROM `areas` WHERE `user` = ?');
$__areas->execute([$user['id']]);
$__logs = $db->prepare('DELETE FROM `logs` WHERE `user` = ?');
$__logs->execute([$user['id']]);
$__attack = $db->prepare('DELETE FROM `attack` WHERE `user` = ?');
$__attack->execute([$user['id']]);
header('Location:/area.php?i=win');
exit;
}
if(!$user['area']){
$__user = $db->prepare('UPDATE `user` SET `area` = ? WHERE `id` = ?');
$__user->execute([$rand, $user['id']]);
header('Location:/area.php?i=area');
exit;
}
if($user['round'] > 9 or $user['hp'] < 1 or count($areas) > 8){
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `round` = ?, `attack` = ?, `put` = ? WHERE `id` = ?');
$__user->execute([0, 0, 0, 0, $user['id']]);
$__areas = $db->prepare('DELETE FROM `areas` WHERE `user` = ?');
$__areas->execute([$user['id']]);
$__logs = $db->prepare('DELETE FROM `logs` WHERE `user` = ?');
$__logs->execute([$user['id']]);
$__attack = $db->prepare('DELETE FROM `attack` WHERE `user` = ?');
$__attack->execute([$user['id']]);
header('Location:/area.php?i=failure');
exit;
}
if($user['attack'] < 1){
$__user = $db->prepare('UPDATE `user` SET `hp` = `hp` - ?, `attack` = ?, `round` = `round` + 1 WHERE `id` = ?');
$__user->execute([$mob['atk'], 5, $user['id']]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `usery` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $mob['atk'], $mob['id'], $attack['id'],time()]);
header('Location:/area.php?i=area');
exit;
}
if(isset($_GET['put'])){
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `put` = ? WHERE `id` = ?');
$__user->execute([($user['put'] ? $user['put'] : $rand), $user['area'], $user['id']]);
header('Location:/area.php?i=area');
exit;
}
echo '
На вас напал '.$mob['name'].' || У него '.$attack['hp'].' HP
Раунд: '.$user['round'].' || Доступно сфер до нового раунда '.$user['attack'].'
Ваша сфера:
Запасной слот:
';
for ($y = 0; $y < $size[0]; ++$y) {
for ($x = 0; $x < $size[1]; ++$x) {
echo $dash[$x][$y] ? ($user['area'] == '6' ? '
':'
'):'
';
}
echo '
';
}
$_logs = $db -> prepare('SELECT * FROM `logs` WHERE `user` = ? AND `attack` = ? ORDER BY `time` DESC');
$_logs -> execute([$user['id'], $attack['id']]);
$logs = $_logs -> fetchAll();
if($logs){
foreach($logs as $log){
echo $log['dmg'] ? '
Вы нанесли монстру '.$mob['name'].'
'.$log['dmg'].'
урона
' : ($log['usery'] ? '
'.$mob['name'].' Нанёс Вам
'.$log['usery'].'
урона '.($log['def'] ? $log['def'] : '').'
':($log['heal'] ? '
Вы исцелили себя на
'.$log['heal'].'
HP
' : ''));
}
}
break;
case 'pickup':
if(isset($_GET['x']) and isset($_GET['y'])){
$_attack = $db -> prepare('SELECT * FROM `attack` WHERE `user` = ?');
$_attack -> execute([$user['id']]);
$attack = $_attack -> fetch();
$_mobs = $db -> prepare('SELECT * FROM `monsters` WHERE `id` = ?');
$_mobs -> execute([$attack['mob']]);
$mob = $_mobs -> fetch();
if(!$attack or !$mob){
header('Location:/area.php');
exit;
}
$_areas = $db -> query('SELECT `area`,`x`,`y` FROM `areas`');
$areas = $_areas -> fetchAll();
foreach ($areas as $area) {
$dash[$area['x']][$area['y']] = $area['area'];
}
$_areas = $db -> query('SELECT * FROM `area` WHERE `id` = '.$user['area'].' LIMIT 1');
$area = $_areas -> fetch();
if($area){
$_check = $db->prepare('SELECT * FROM `areas` WHERE `x` = ? AND `y` = ? LIMIT 1');
$_check -> execute([(int)$_GET['x'], (int)$_GET['y']]);
$check = $_check->fetch();
if($check and $area['id'] != 6){
header('Location:/area.php?i=area');
exit;
}
else{
if($area['id'] !== '6'){
$__areas = $db->prepare('INSERT INTO `areas` SET `user` = ?, `area` = ?, `x` = ?, `y` = ?');
$__areas->execute([1,$user['area'],(int)$_GET['x'],(int)$_GET['y']]);
}
$dash[(int) $_GET['x']][(int) $_GET['y']] = $user['area'];
$checker = check((int)$_GET['x'], (int)$_GET['y'], $dash);
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `attack` = `attack` - 1 WHERE `id` = ? LIMIT 1');
$__user->execute([0, $user['id']]);
if(count($checker) > 2 or $area['id'] == '6'){
foreach($checker as $key=>$value){
$x = $key[0];
$y = $key[2];
$__delete = $db->prepare('DELETE FROM `areas` WHERE `x` = ? AND `y` = ?');
$__delete->execute([$x, $y]);
}
switch($area['type']){
case 'attack':
$dmg = count($checker) == 3 ? $user['dmg'] : $user['dmg'] * 2;
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `dmg` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $dmg, $mob['id'], $attack['id'],time()]);
$__attack = $db->prepare('UPDATE `attack` SET `hp` = `hp` - ? WHERE `id` = ? LIMIT 1');
$__attack->execute([$dmg, $attack['id']]);
$__user = $db->prepare('UPDATE `user` SET `hp` = `hp` - '.$mob['atk'].', `attack` = ?, `round` = `round` + 1 WHERE `id` = ?');
$__user->execute([$mob['atk'], 5, $user['id']]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `usery` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $mob['atk'], $mob['id'], $attack['id'],time()]);
break;
case 'defense':
$dmg = count($checker) == 3 ? $mob['atk'] / 2 : 0;
$__user = $db->prepare('UPDATE `user` SET `hp` = `hp` - ?, `attack` = ?, `round` = `round` + 1 WHERE `id` = ?');
$__user->execute([$dmg, 5, $user['id']]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `usery` = ?, `monster` = ?, `attack` = ?, `time` = ?, `def` = ?');
$__logs->execute([$user['id'], $dmg, $mob['id'], $attack['id'],time(),($dmg ? '(Вы частично заблокировали урон)' : '(Вы полностью блокировали атаку)')]);
break;
case 'heal':
$heal = count($checker) == 3 ? $user['dmg'] * 3 : $user['dmg'] * 6;
$__user = $db->prepare('UPDATE `user` SET `hp` = `hp` + ?, `attack` = ?, `round` = `round` + 1 WHERE `id` = ?');
$__user->execute([$heal - $mob['atk'], 5, $user['id']]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `usery` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $mob['atk'], $mob['id'], $attack['id'],time()]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `heal` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $heal, $mob['id'], $attack['id'],time()]);
break;
case 'super':
$dmg = count($checker) == 3 ? $user['dmg'] * 2 : $user['dmg'] * 4;
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `dmg` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $dmg, $mob['id'], $attack['id'],time()]);
$__attack = $db->prepare('UPDATE `attack` SET `hp` = `hp` - ? WHERE `id` = ?');
$__attack->execute([$dmg, $attack['id']]);
$__user = $db->prepare('UPDATE `user` SET `hp` = `hp` - ?, `attack` = ?, `round` = `round` + 1 WHERE `id` = ?');
$__user->execute([$mob['atk'], 5, $user['id']]);
$__logs = $db->prepare('INSERT INTO `logs` SET `user` = ?, `usery` = ?, `monster` = ?, `attack` = ?, `time` = ?');
$__logs->execute([$user['id'], $mob['atk'], $mob['id'], $attack['id'],time()]);
break;
}
}
header('Location:/area.php?i=area');
exit;
}
}
}
break;
case 'win':
$_SESSION['message'] = '
Вы выиграли!
кам бек
';
header('Location:/area.php');
exit;
case 'failure':
$_SESSION['message'] = '
Вы проиграли! Усильте свои статы, выкуйте новые мечи и возьмите реванш!
Кам бек
';
header('Location:/area.php');
exit;
}
echo '
Скрипт выполнялся '.round((microtime(true) - $start), 6).' сек.';
?>