2020-10-26 18:16:28 +00:00
< ? php
# Date: 26.10.2020 (16:08)
2020-10-28 20:21:08 +00:00
namespace Battles ;
2021-05-25 15:15:51 +00:00
2022-01-26 23:15:33 +00:00
use Battles\Database\Db ;
2021-01-28 21:05:34 +00:00
2020-10-26 18:16:28 +00:00
class Travel
{
2020-10-26 22:13:07 +00:00
/**
* Соответствие ID комнаты игровому файлу .
* @ var string []
*/
2020-10-29 23:30:05 +00:00
public static $roomFileName = [
2020-10-27 18:14:07 +00:00
1 => 'main.php' ,
2020-10-26 22:13:07 +00:00
20 => 'city.php' ,
21 => 'city.php' ,
22 => 'shop.php' ,
23 => 'repair.php' ,
26 => 'city.php' ,
27 => 'post.php' ,
29 => 'bank.php' ,
30 => 'clan_create.php' ,
31 => 'tower.php' ,
34 => 'fshop.php' ,
37 => 'gotzamok.php' ,
2020-10-29 23:30:05 +00:00
38 => 'gotzamok.php' ,
39 => 'gotzamok.php' ,
40 => 'gotzamok.php' ,
41 => 'gotzamok.php' ,
2020-10-26 22:13:07 +00:00
51 => 'city.php' ,
61 => 'akadem.php' ,
401 => 'hell.php' ,
2020-10-29 23:30:05 +00:00
402 => 'vxod.php' ,
403 => 'canalizaciya.php' ,
//404 => 'vxod.php',
600 => 'c_haos.php' ,
601 => 'c_haos_in.php' ,
602 => 'c_park.php' ,
2020-10-26 22:13:07 +00:00
603 => 'aren_of_angels.php' ,
620 => 'enter_cave.php' ,
2020-10-29 23:30:05 +00:00
621 => 'cave.php' ,
2020-10-26 22:13:07 +00:00
650 => 'ul_clans.php' ,
660 => 'hostel.php' ,
2020-10-29 23:30:05 +00:00
661 => 'hostel_room.php' ,
662 => 'quest_room.php' ,
2020-10-26 22:13:07 +00:00
666 => 'jail.php' ,
2020-10-29 23:30:05 +00:00
760 => 'c_forest.php' ,
2020-10-26 22:13:07 +00:00
777 => 'obshaga.php' ,
1051 => 'lab_enter.php' ,
2020-10-29 23:30:05 +00:00
1052 => 'labirint.php' ,
2020-10-26 22:13:07 +00:00
1055 => 'group_arena.php' ,
2111 => 'city.php' ,
2601 => 'city.php' ,
2655 => 'city.php' ,
2020-10-27 00:36:29 +00:00
2702 => 'city.php'
2020-10-26 22:13:07 +00:00
];
2022-02-12 12:25:43 +00:00
private static array $fbattleCheckFiles = [
'c_haos_in.php' ,
'c_haos.php' ,
'c_park.php' ,
'city.php' ,
'clan_castle.php' ,
'enter_cave.php' ,
'library.php' ,
'atk.php' ,
'podzem_dialog.php' ,
'post.php' ,
'shop.php' ,
'tournament.php' ,
'vxod.php' ,
'bank.php' ,
'canalizaciya,php' ,
'forest.php' ,
'main.php' ,
'repair.php' ,
'towerstamp.php' ,
'hell.php' ,
'ul_clans.php' ,
'labirint.php' ,
'akadem.php' ,
'towerin.php' ,
'user_anketa.php' ,
'zayavka.php' ,
];
private static array $towerinCheckFiles = [
'main.php' ,
'city.php' ,
'tower.php'
];
private static array $roomsCheck = [ 22 , 23 , 27 , 29 , 30 , 31 , 37 , 38 , 39 , 40 , 41 , 45 , 53 , 61 , 401 , 402 , 600 , 601 , 602 , 621 , 650 , 1051 , 1052 ];
2020-10-26 22:13:07 +00:00
/**
* Перемещение по комнатам .
2022-02-12 12:25:43 +00:00
*
* @ param int $roomId ID куда идём .
2021-05-25 15:15:51 +00:00
* @ param int $roomIdCurrent ID откуда идём .
2020-10-26 22:13:07 +00:00
*/
2020-10-26 22:21:00 +00:00
public static function toRoom ( int $roomId , int $roomIdCurrent ) : void
2020-10-26 18:16:28 +00:00
{
2022-01-26 23:15:33 +00:00
UserStats :: getInstance () ->
$itemsWeightOverflow = Db :: getInstance () -> fetchColumn ( 'SELECT SUM(weight) - (select strength * 4 from users where id = ?) AS weight_overflow FROM inventory WHERE owner_id = ? AND on_sale = 0' , [ $_SESSION [ 'uid' ], $_SESSION [ 'uid' ]]);
$eff = Db :: getInstance () -> fetchColumn ( 'SELECT type FROM users_effects WHERE owner_id = ? AND (`type` = 10 OR `type` = 13 OR `type` = 14)' , $_SESSION [ 'uid' ]);
2020-10-26 18:16:28 +00:00
$errors = [];
2022-01-26 23:15:33 +00:00
if ( $itemsWeightOverflow > 0 ) {
2020-10-26 18:16:28 +00:00
$errors [ 0 ] = 'У вас переполнен рюкзак, вы не можете передвигаться...' ;
}
2022-01-26 23:15:33 +00:00
if ( $eff == 10 ) {
2020-10-26 18:16:28 +00:00
$errors [ 1 ] = 'Вы парализованы и не можете передвигаться...' ;
}
2022-01-26 23:15:33 +00:00
if ( $eff == 13 || $eff == 14 ) {
2020-10-26 18:16:28 +00:00
$errors [ 2 ] = 'У вас тяжелая травма, вы не можете передвигаться...' ;
}
if ( $errors ) {
foreach ( $errors as $error ) {
echo sprintf ( '<span class="error">%s</span>' , $error );
}
2020-10-26 22:13:07 +00:00
} elseif ( in_array ( $roomId , self :: allowedRoomMoves ( $roomIdCurrent ))) {
2022-01-26 23:15:33 +00:00
Db :: getInstance () -> execute ( 'UPDATE users, online SET users.room = ?, online.room = ? WHERE `online`.`user_id` = `users`.`id` AND `online`.`user_id` = ?' , [ $roomId , $roomId , $_SESSION [ 'uid' ]]);
2020-10-26 22:13:07 +00:00
header ( 'location: ' . self :: $roomFileName [ $roomId ]);
2020-10-26 18:16:28 +00:00
exit ;
}
}
/**
* Проверка можно ли перейти из комнаты в комнату .
2022-02-12 12:25:43 +00:00
*
2020-10-26 18:16:28 +00:00
* @ param int $roomId ID комнаты
2022-02-12 12:25:43 +00:00
*
2020-10-26 18:16:28 +00:00
* @ return array | int []
*/
private static function allowedRoomMoves ( int $roomId ) : array
{
/*
* 1 location : main . php ? goto = arena
* 2 Room 22 shop . 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 ]
*/
2022-01-21 16:17:56 +00:00
$room [ 20 ] = [ 1 , 21 , 22 , 23 , 26 , 27 , 2702 ];
$room [ 1 ] = $room [ 22 ] = $room [ 23 ] = $room [ 27 ] = [ 20 ];
2020-10-26 18:16:28 +00:00
/*
* 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
*/
2020-10-26 22:13:07 +00:00
$room [ 21 ] = [ 20 , 29 , 30 , 31 , 34 , 650 , 2111 ];
2020-10-27 16:51:55 +00:00
$room [ 29 ] = $room [ 30 ] = $room [ 31 ] = $room [ 34 ] = [ 21 ];
2020-10-26 18:16:28 +00:00
2020-10-26 23:18:02 +00:00
$room [ 26 ] = [ 20 , 401 , 660 , 777 , 2601 ];
2020-10-27 16:51:55 +00:00
$room [ 401 ] = $room [ 660 ] = $room [ 777 ] = [ 26 ];
2020-10-26 22:13:07 +00:00
$room [ 2601 ] = [ 26 , 37 , 404 , 1051 , 2655 ];
2020-10-27 16:51:55 +00:00
2020-10-26 22:13:07 +00:00
$room [ 2655 ] = [ 603 , 2601 ];
2020-10-26 18:16:28 +00:00
/*
* 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
*/
2020-10-26 22:13:07 +00:00
$room [ 2111 ] = [ 21 , 620 , 666 , 1055 ];
$room [ 2701 ] = [ 402 , 2111 ];
$room [ 2702 ] = [ 20 , 61 ];
if ( $room [ $roomId ] === null ) {
2020-10-26 18:16:28 +00:00
return [];
}
return $room [ $roomId ];
}
2022-02-12 12:25:43 +00:00
/** Проверки на соответствие скрипта и комнаты , которые были натыканы по всем файлам .
* @ param int $inRoom
* @ param int $inBattle
* @ param int $inTower
*
* @ return void
*/
public static function roomRedirects ( int $inRoom , int $inBattle , int $inTower )
{
if ( $inBattle && in_array ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], self :: $fbattleCheckFiles )) {
header ( 'location: fbattle.php' );
exit ;
}
if ( $inTower && in_array ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], self :: $towerinCheckFiles )) {
header ( 'location: towerin.php' );
exit ;
}
// Если я в одной из этих комнат,
// [И] Имя файла который инклюдит файл с проверкой не совпадает с именем файла локации в которой я нахожусь
// [И] Номер комнаты который я пытаюсь открыть есть в списке проверяемых
if ( in_array ( $inRoom , self :: $roomsCheck )
&& pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ] != self :: $roomFileName [ $inRoom ]
&& in_array ( array_search ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], self :: $roomFileName ), self :: $roomsCheck )) {
header ( 'location: main.php' );
exit ;
}
}
2020-10-26 18:16:28 +00:00
}