Попытка закрыть #6.

This commit is contained in:
lopar 2020-10-26 20:16:28 +02:00
parent 08d8a8bc80
commit 826471baa3
4 changed files with 253 additions and 208 deletions

284
city.php
View File

@ -10,7 +10,6 @@ if (empty($_SESSION['uid'])) {
require_once "functions.php";
$user = $user ?? [];
$tm = time();
if ($user->battle) {
header('location: fbattle.php');
@ -24,336 +23,207 @@ if ($user->zayavka) {
exit;
}
function move($room, $redirect = null)
{
$d = db::c()->query('SELECT SUM(`massa`) AS `mass` FROM `inventory` WHERE `owner` = ?i AND `setsale` = 0', $_SESSION['uid'])->fetch_assoc();
$eff = db::c()->query('SELECT `type` FROM `effects` WHERE `owner` = ?i AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid'])->fetch_assoc();
if ($d['mass'] > get_meshok()) {
return 'У вас переполнен рюкзак, вы не можете передвигаться...';
}
if ($eff['type'] == 10) {
return 'Вы парализованы и не можете передвигаться...';
}
if ($eff['type'] == 13 || $eff['type'] == 14) {
return 'У вас тяжелая травма, вы не можете передвигаться...';
}
db::c()->query('UPDATE `users`,`online` SET `users`.`room` = ?i,`online`.`room` = ?i WHERE `online`.`id` = `users`.`id` AND `online`.`id` = ?i', $room, $room, $_SESSION['uid']);
if ($redirect) {
header('location: ' . $redirect);
exit;
}
return true;
}
$online = db::c()->query('SELECT 1 FROM `online` WHERE `real_time` >= ?i', (time() - 60));
$location = explode('/', filter_input(INPUT_SERVER, 'QUERY_STRING'));
switch ($location[0]) {
default:
break;
case 'cp':
move(20, 'city.php');
Travel::toRoom(20);
break;
case 'strah':
move(21, 'city.php');
Travel::toRoom(21);
break;
case 'bps':
move(26, 'city.php');
Travel::toRoom(26);
break;
case 'ps':
move(51, 'city.php');
Travel::toRoom(51);
break;
case 'zaliv':
move(2111, 'city.php');
Travel::toRoom(2111);
break;
case 'zamk':
move(2601, 'city.php');
Travel::toRoom(2601);
break;
case 'abog':
move(2655, 'city.php');
Travel::toRoom(2655);
break;
case 'torg':
move(2702, 'city.php');
Travel::toRoom(2702);
break;
case 'got':
if ($user->room == 20) {
switch ($location[1]) {
default:
break;
case 'level1':
header('location: main.php?goto=arena');
exit;
break;
case 'level7':
header('location: city.php?strah');
Travel::toRoom(21);
break;
case 'level8':
header('location: city.php?bps');
Travel::toRoom(26);
break;
case 'level13':
header('location: quest_room.php');
break;
case 'level222':
header('location: city.php?torg');
Travel::toRoom(2702);
break;
case 'level17':
move(50, 'ashop.php');
Travel::toRoom(50, 'ashop.php');
break;
case 'level2':
move(22, 'shop.php');
Travel::toRoom(22, 'shop.php');
break;
case 'level4':
move(23, 'repair.php');
Travel::toRoom(23, 'repair.php');
break;
case 'level6':
move(27, 'post.php');
Travel::toRoom(27, 'post.php');
break;
case 'level3':
move(25, 'comission.php');
Travel::toRoom(25, 'comission.php');
break;
}
} elseif ($user->room == 21) {
switch ($location[1]) {
default:
break;
case 'level4':
header('location: city.php?cp');
Travel::toRoom(20);
break;
case 'level3':
header('location: city.php?zaliv');
Travel::toRoom(2111);
break;
case 'level13':
move(34, 'fshop.php');
Travel::toRoom(34, 'fshop.php');
break;
case 'level5':
move(29, 'bank.php');
Travel::toRoom(29, 'bank.php');
break;
case 'level16':
move(31, 'tower.php');
Travel::toRoom(31, 'tower.php');
break;
case 'level14':
move(30, 'clan_create.php');
Travel::toRoom(30, 'clan_create.php');
break;
case 'level650':
move(650, 'ul_clans.php');
Travel::toRoom(650, 'ul_clans.php');
break;
}
} elseif ($user->room == 2111) {
switch ($location[1]) {
default:
break;
case 'level1':
header('location: city.php?strah');
Travel::toRoom(21);
break;
case 'level2':
header('location: city.php?haos');
break;
case 'level203':
move(1055, 'group_arena.php');
Travel::toRoom(1055, 'group_arena.php');
break;
case 'level1000':
move(620, 'enter_cave.php');
Travel::toRoom(620, 'enter_cave.php');
break;
case 'room666':
move(666, 'jail.php');
Travel::toRoom(666, 'jail.php');
break;
}
} elseif ($user->room == 2601) {
switch ($location[1]) {
default:
break;
case 'level4':
header('location: city.php?bps');
Travel::toRoom(26);
break;
case 'level55':
header('location: city.php?abog');
Travel::toRoom(2655);
break;
case 'level1':
move(37, 'gotzamok.php');
Travel::toRoom(37, 'gotzamok.php');
break;
case 'level1051':
move(1051, 'lab_enter.php');
Travel::toRoom(1051, 'lab_enter.php');
break;
case 'level5':
move(404, 'vxod.php');
Travel::toRoom(404, 'vxod.php');
break;
}
} elseif ($user->room == 2701) {
switch ($location[1]) {
default:
break;
case 'level1':
header('location: city.php?zaliv');
Travel::toRoom(2111);
break;
case 'level2':
move(402, 'lab_chaos_enter.php');
Travel::toRoom(402, 'lab_chaos_enter.php');
break;
}
} elseif ($user->room == 2702) {
switch ($location[1]) {
default:
break;
case 'level10':
header('location: city.php?cp');
Travel::toRoom(20);
break;
case 'level6':
move(61, 'akadem.php');
Travel::toRoom(61, 'akadem.php');
break;
}
} elseif ($user->room == 2655) {
switch ($location[1]) {
default:
break;
case 'level10':
header('location: city.php?zamk');
Travel::toRoom(2601);
break;
case 'level2055':
move(603, 'aren_of_angels.php');
Travel::toRoom(603, 'aren_of_angels.php');
break;
}
} elseif ($user->room == 26) {
switch ($location[1]) {
default:
break;
case 'level4':
header('location: city.php?cp');
Travel::toRoom(20);
break;
case 'level3':
header('location: city.php?zamk');
Travel::toRoom(2601);
break;
case 'level660':
move(660, 'hostel.php');
Travel::toRoom(660, 'hostel.php');
break;
case 'level7':
move(777, 'obshaga.php');
Travel::toRoom(777, 'obshaga.php');
break;
case 'level56':
move(401, 'hell.php');
Travel::toRoom(401, 'hell.php');
break;
}
}
}
function getSeason()
{
$todayMonth = date('n');
if ($todayMonth >= 3 && $todayMonth <= 5) {
return 'spring_';
}
if ($todayMonth >= 6 && $todayMonth <= 8) {
return 'summer_';
}
if ($todayMonth >= 9 && $todayMonth <= 11) {
return 'autumn_';
}
return 'winter_';
}
function buildset($id, $img, $top, $left, $des, $noSeason = 0)
{
if (!$noSeason) {
$img = getSeason() . $img;
}
?>
<div style="position:absolute; left:<?= $left ?>px; top:<?= $top ?>px; z-index:90; cursor: pointer;">
<img src="i/city/sub/<?= $img ?>.png" alt="<?= $des ?>" title="<?= $des ?>" class="building"
id="<?= $id ?>" onclick="solo(<?= $id ?>)"/>
</div>
<?php
}
function bgset($img)
{
$daytime = date('H');
if ($daytime >= 6 && $daytime <= 21) {
$background = getSeason() . $img . '_day';
}
else {
$background = getSeason() . $img . '_night';
}
echo sprintf('<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="i/city/%s.jpg">', $background);
}
$online = db::c()->query('SELECT 1 FROM `online` WHERE `real_time` >= ?i', (time() - 60));
Template::header('city');
?>
<style>
img.building:hover {
filter: drop-shadow(2px 2px 2px white) sepia(15%);
}
</style>
<script type="text/javascript">
function solo(n) {
top.changeroom = n;
window.location.href = 'city.php?got/level' + n;
}
function Down() {
top.CtrlPress = window.event.ctrlKey
}
document.onmousedown = Down;
</script>
<table class="allzeroes">
<TR>
<TD align=center></TD>
<TD align=right>Сейчас в игре : <?= $online->getNumRows() ?> игроков.</TD>
</TR>
<TR>
<TD align=center colspan=2>
<?php
if ($user->room == 20) {
bgset('cap_cp');
buildset(1, "cap_club", 30, 235, "Бойцовский Клуб");
buildset(2, "cap_shop", 202, 171, "Магазин");
buildset(3, "cap_kom", 205, 105, "Комиссионный магазин");
buildset(4, "cap_rem", 202, 290, "Ремонтная мастерская");
buildset(13, "cap_statue", 222, 365, "Памятник Мэру Города");
buildset(6, "cap_po4ta", 180, 540, "Почта");
buildset(7, "cap_arr_right", 260, 710, "Страшилкина Улица", 1);
buildset(222, "cap_arr_top", 180, 650, "Торговая улица", 1);
buildset(8, "cap_arr_left", 258, 21, "Большая парковая улица", 1);
buildset(17, "cap_berezka", 205, 435, "Березка");
buildset(9, "cap_tree2", 260, 530, "Новогодняя елка");
buildset(14, "cap_sneg_3", 210, 390, "Снеговик");
echo "</div>";
} elseif ($user->room == 21) {
bgset('cap_strash');
buildset(5, "cap_bank", 180, 485, "Банк");
buildset(14, "cap_registratura", 170, 113, "Регистратура кланов");
buildset(16, "cap_tower", 5, 315, "Башня смерти");
buildset(16555, "cap_tree", 165, 20, "Дерево");
buildset(3, "cap_arr_right", 255, 708, "Ристалище", 1);
buildset(13, "cap_flowershop", 220, 613, "Цветочный магазин");
buildset(4, "cap_arr_left", 258, 21, "Центральная площадь", 1);
echo "</div>";
} elseif ($user->room == 26) {
bgset('cap_park');
buildset(6, "cap_gate", 170, 340, "Городские ворота", 1);
buildset(660, "cap_vokzal", 163, 43, "Общежитие");
buildset(3, "cap_arr_left", 259, 27, "Замковая площадь", 1);
buildset(4, "cap_arr_right", 259, 715, "Центральная площадь", 1);
echo "</div>";
} elseif ($user->room == 2601) {
bgset('cap_zamk');
buildset(1052, "cap_lavka", 240, 425, "Храмовая лавка");
buildset(10, "ava_post", 240, 300, "Сувенирный магазинчик", 1);
buildset(1, "cap_ruins", 166, 48, "Руины Старого замка");
buildset(1051, "cap_lab", 130, 327, "Вход в Лабиринт Хаоса");
buildset(55, "cap_arr_left", 258, 21, "Арена Богов", 1);
buildset(4, "cap_arr_right", 260, 710, "Большая парковая улица", 1);
echo "</div>";
} elseif ($user->room == 2655) {
bgset('ar_e_n');
buildset(2055, "cap_altr_g", 230, 340, "Арена Ангелов");
buildset(10, "arr_right_png", 260, 710, "Замковая площадь", 1);
echo "</div>";
} elseif ($user->room == 2111) {
bgset('rist_bg');
buildset(1, "cap_arr_uleft", 240, 30, "Страшилкина Улица", 1);
buildset(2, "cap_arr_right", 245, 708, "Секретный Лабиринт", 1);
buildset(14, "cap_rist_solo", 210, 160, "Вход в Одиночные сражения");
buildset(14, "cap_rist_group", 243, 340, "Вход в Сражение отрядов");
buildset(1000, "av_zamk_rud", 80, 310, "Рудник");
buildset(203, "cap_rist_monstr", 145, 570, "Вход в Груповые сражения");
buildset(21, "angelscastle", 131, 628, "Замок Мэра Города");
echo "</div>";
} elseif ($user->room == 2701) {
bgset('arena_bg1');
buildset(1, "cap_3strelka", 260, 30, "Берег Залива");
buildset(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса");
echo "</div>";
} elseif ($user->room == 2702) {
bgset('cap_torg');
buildset(6, "cap_arenda", 175, 70, "Академия");
buildset(16, "cap_t_build42", 120, 300, "Аукцион");
buildset(16555, "cap_prokat", 155, 480, "Прокатная лавка");
buildset(21, "cap_lombard", 150, 565, "Ломбард");
buildset(10, "cap_arr_uleft", 259, 25, "Центральная площадь", 1);
echo "</div>";
}
?>
</td>
</tr>
</table>
echo sprintf('<div style="text-align: right;">Сейчас в игре: %s игроков.></div>', $online->getNumRows());
if (in_array($user->room, [20, 21, 26, 2601, 2655, 2111, 2701, 2702])) {
/* Улицы:
* 20 Центральная
* 21 Страшилкина
* 26 Парковая
* 2601 Замковая
* 2655 С ареной
* 2111 С ристалищем
* 2701 С ещё одним ристалищем?
* 2702 Торговая
*/
City::showStreet($user->room);
}

88
classes/City.php Normal file
View File

@ -0,0 +1,88 @@
<?php
# Date: 26.10.2020 (17:56)
class City
{
public static function showStreet(int $id)
{
if ($id === 20) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_cp_day.jpg">' .
self::showBuilding(1, "spring_cap_club", 30, 235, "Бойцовский Клуб") .
self::showBuilding(2, "spring_cap_shop", 202, 171, "Магазин") .
self::showBuilding(3, "spring_cap_kom", 205, 105, "Комиссионный магазин") .
self::showBuilding(4, "spring_cap_rem", 202, 290, "Ремонтная мастерская") .
self::showBuilding(6, "spring_cap_po4ta", 180, 540, "Почта") .
self::showBuilding(7, "spring_cap_arr_right", 260, 710, "Страшилкина Улица") .
self::showBuilding(8, "spring_cap_arr_left", 258, 21, "Большая парковая улица") .
self::showBuilding(9, "spring_cap_tree2", 260, 530, "Новогодняя елка") .
self::showBuilding(13, "spring_cap_statue", 222, 365, "Памятник Мэру Города") .
self::showBuilding(14, "spring_cap_sneg_3", 210, 390, "Снеговик") .
self::showBuilding(17, "spring_cap_berezka", 205, 435, "Березка") .
self::showBuilding(222, "spring_cap_arr_top", 180, 650, "Торговая улица") .
'</div>';
} elseif ($id === 21) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_strash_day.jpg">' .
self::showBuilding(3, "cap_arr_right", 255, 708, "Ристалище") .
self::showBuilding(4, "cap_arr_left", 258, 21, "Центральная площадь") .
self::showBuilding(5, "cap_bank", 180, 485, "Банк") .
self::showBuilding(13, "cap_flowershop", 220, 613, "Цветочный магазин") .
self::showBuilding(14, "cap_registratura", 170, 113, "Регистратура кланов") .
self::showBuilding(16, "cap_tower", 5, 315, "Башня смерти") .
self::showBuilding(16555, "cap_tree", 165, 20, "Дерево") .
'</div>';
} elseif ($id === 26) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_park_day.jpg">' .
self::showBuilding(3, "cap_arr_left", 259, 27, "Замковая площадь") .
self::showBuilding(4, "cap_arr_right", 259, 715, "Центральная площадь") .
self::showBuilding(6, "cap_gate", 170, 340, "Городские ворота") .
self::showBuilding(660, "cap_vokzal", 163, 43, "Общежитие") .
'</div>';
} elseif ($id === 2601) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/sub/cap_zamk_day.jpg">' .
self::showBuilding(1, "cap_ruins", 166, 48, "Руины Старого замка") .
self::showBuilding(4, "cap_arr_right", 260, 710, "Большая парковая улица") .
self::showBuilding(10, "ava_post", 240, 300, "Сувенирный магазинчик") .
self::showBuilding(55, "cap_arr_left", 258, 21, "Арена Богов") .
self::showBuilding(1051, "cap_lab", 130, 327, "Вход в Лабиринт Хаоса") .
self::showBuilding(1052, "cap_lavka", 240, 425, "Храмовая лавка") .
'</div>';
} elseif ($id === 2655) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/ar_e_d.jpg">' .
self::showBuilding(10, "arr_right_png", 260, 710, "Замковая площадь") .
self::showBuilding(2055, "cap_altr_g", 230, 340, "Арена Ангелов") .
'</div>';
} elseif ($id === 2111) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_rist_day.jpg.jpg">' .
self::showBuilding(1, "cap_arr_uleft", 240, 30, "Страшилкина Улица") .
self::showBuilding(2, "cap_arr_right", 245, 708, "Секретный Лабиринт") .
self::showBuilding(14, "cap_rist_solo", 210, 160, "Вход в Одиночные сражения") .
self::showBuilding(14, "cap_rist_group", 243, 340, "Вход в Сражение отрядов") .
self::showBuilding(21, "angelscastle", 131, 628, "Замок Мэра Города") .
self::showBuilding(203, "cap_rist_monstr", 145, 570, "Вход в Груповые сражения") .
self::showBuilding(1000, "av_zamk_rud", 80, 310, "Рудник") .
'</div>';
} elseif ($id === 2701) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_arena_bg1_day2.jpg">' .
self::showBuilding(1, "cap_3strelka", 260, 30, "Берег Залива") .
self::showBuilding(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса") .
'</div>';
} elseif ($id === 2702) {
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_torg_day.jpg">' .
self::showBuilding(6, "cap_arenda", 175, 70, "Академия") .
self::showBuilding(10, "cap_arr_uleft", 259, 25, "Центральная площадь") .
self::showBuilding(16, "cap_t_build42", 120, 300, "Аукцион") .
self::showBuilding(21, "cap_lombard", 150, 565, "Ломбард") .
self::showBuilding(16555, "cap_prokat", 155, 480, "Прокатная лавка") .
'</div>';
}
}
private static function showBuilding(int $id, string $image, int $top, int $left, string $description)
{
return sprintf('
<div style="position:absolute; left:%spx; top:%spx; z-index:90; cursor: pointer;">
<img src="/i/city/sub/%s.png" alt="%s" title="%s" class="building" id="%s" onclick="window.location.href = \'city.php?got/level%s\'">
</div>',
$left, $top, $image, $description, $description, $id, $id);
}
}

83
classes/Travel.php Normal file
View File

@ -0,0 +1,83 @@
<?php
# Date: 26.10.2020 (16:08)
class Travel
{
public static function toRoom(int $roomId, string $redirectToFile = 'city.php'): void
{
$itemsWeight = db::c()->query('SELECT SUM(weight) AS all_weight FROM `inventory` WHERE owner_id = ?i AND `setsale` = 0', $_SESSION['uid'])->fetch_assoc();
$eff = db::c()->query('SELECT type FROM users_effects WHERE owner_id = ?i AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid'])->fetch_assoc();
$errors = [];
if ($itemsWeight['all_weight'] > get_meshok()) {
$errors[0] = 'У вас переполнен рюкзак, вы не можете передвигаться...';
}
if ($eff['type'] == 10) {
$errors[1] = 'Вы парализованы и не можете передвигаться...';
}
if ($eff['type'] == 13 || $eff['type'] == 14) {
$errors[2] = 'У вас тяжелая травма, вы не можете передвигаться...';
}
if ($errors) {
foreach ($errors as $error) {
echo sprintf('<span class="error">%s</span>', $error);
}
} elseif (in_array($roomId, self::allowedRoomMoves($roomId))) {
db::c()->query('UPDATE users, online SET users.room = ?i, online.room = ?i WHERE `online`.`user_id` = `users`.`id` AND `online`.`id` = ?i', $roomId, $roomId, $_SESSION['uid']);
header('location: ' . $redirectToFile);
exit;
}
}
/**
* Проверка можно ли перейти из комнаты в комнату.
* @param int $roomId ID комнаты
* @return array|int[]
*/
private static function allowedRoomMoves(int $roomId): array
{
/*
* 1 location: main.php?goto=arena
* 2 Room 22 shop.php
* 3 Room 25 comission.php
* 4 Room 23 repair.php
* 6 Room 27 posr.php
* 7 Room 21 [STREET]
* 8 Room 26 [STREET]
* 13 location: quest_room.php
* 17 Room 50 ashop.php
* 222 Room 2702 [STREET]
*/
$room[20] = [1, 2, 3, 4, 6, 7, 8, 9, 13, 14, 17, 222]; // level+n
/*
* 3 Room 2111 [STREET]
* 4 Room 20 [STREET]
* 5 Room 29 Bank.php
* 13 Room 34 fshop.php
* 14 Room 30 clan_create.php
* 16 Room 31 tower.php
* 650 Room 650 ul_clans.php
*/
$room[21] = [3, 4, 5, 13, 14, 16, 16555];
$room[26] = [3, 4, 6, 660];
$room[2601] = [1, 4, 10, 55, 1051, 1052];
$room[2655] = [10, 2055];
/*
* 1 Room 21 [STREET]
* 2 location: city.php?haos - где эта херня вообще?
* 14 NULL
* 21 NULL
* 203 Room 1055 group_arena.php
* [!not on map]666 Room 666 jail.php
* 1000
*/
$room[2111] = [1, 2, 14, 21, 203, 1000];
$room[2701] = [1, 2];
$room[2702] = [6, 10, 16, 21, 16555];
if (empty($room[$roomId])) {
return [];
}
return $room[$roomId];
}
}

View File

@ -431,4 +431,8 @@ div.secret-info {
}
div.secret-info > span {
color: #966;
}
}
/* for classes/City.php included in /city.php */
img.building:hover {
filter: drop-shadow(2px 2px 2px white) sepia(15%);
}