battles/classes/Travel.php

83 lines
3.1 KiB
PHP
Raw Normal View History

2020-10-26 18:16:28 +00:00
<?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];
}
}