battles/classes/Battles/Travel.php

143 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
# Date: 26.10.2020 (16:08)
namespace Battles;
class Travel
{
/**
* Соответствие ID комнаты игровому файлу.
* @var string[]
*/
public static $roomFileName = [
1 => 'main.php',
20 => 'city.php',
21 => 'city.php',
22 => 'shop.php',
23 => 'repair.php',
25 => 'comission.php',
26 => 'city.php',
27 => 'post.php',
29 => 'bank.php',
30 => 'clan_create.php',
31 => 'tower.php',
34 => 'fshop.php',
37 => 'gotzamok.php',
38 => 'gotzamok.php',
39 => 'gotzamok.php',
40 => 'gotzamok.php',
41 => 'gotzamok.php',
51 => 'city.php',
61 => 'akadem.php',
401 => 'hell.php',
402 => 'vxod.php',
403 => 'canalizaciya.php',
//404 => 'vxod.php',
600 => 'c_haos.php',
601 => 'c_haos_in.php',
602 => 'c_park.php',
603 => 'aren_of_angels.php',
620 => 'enter_cave.php',
621 => 'cave.php',
650 => 'ul_clans.php',
660 => 'hostel.php',
661 => 'hostel_room.php',
662 => 'quest_room.php',
666 => 'jail.php',
760 => 'c_forest.php',
777 => 'obshaga.php',
1051 => 'lab_enter.php',
1052 => 'labirint.php',
1055 => 'group_arena.php',
2111 => 'city.php',
2601 => 'city.php',
2655 => 'city.php',
2702 => 'city.php'
];
/**
* Перемещение по комнатам.
* @param int $roomId ID куда идём.
* @param int $roomIdCurrent ID откуда идём.
* @throws \Krugozor\Database\Mysql\Exception
*/
public static function toRoom(int $roomId, int $roomIdCurrent): void
{
$itemsWeight = \db::c()->query('SELECT SUM(weight) AS all_weight FROM `inventory` WHERE owner_id = ?i AND on_sale = 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($roomIdCurrent))) {
\db::c()->query('UPDATE users, online SET users.room = ?i, online.room = ?i WHERE `online`.`user_id` = `users`.`id` AND `online`.`user_id` = ?i', $roomId, $roomId, $_SESSION['uid']);
header('location: ' . self::$roomFileName[$roomId]);
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
* 222 Room 2702 [STREET]
*/
$room[20] = [1, 21, 22, 23, 25, 26, 27, 2702];
$room[1] = $room[22] = $room[23] = $room[25] = $room[27] = [20];
/*
* 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] = [20, 29, 30, 31, 34, 650, 2111];
$room[29] = $room[30] = $room[31] = $room[34] = [21];
$room[26] = [20, 401, 660, 777, 2601];
$room[401] = $room[660] = $room[777] = [26];
$room[2601] = [26, 37, 404, 1051, 2655];
$room[2655] = [603, 2601];
/*
* 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] = [21, 620, 666, 1055];
$room[2701] = [402, 2111];
$room[2702] = [20, 61];
if ($room[$roomId] === null) {
return [];
}
return $room[$roomId];
}
}