2018-01-28 16:40:49 +00:00
< ? php
2018-01-29 22:05:41 +00:00
/**
* Copyright ( c ) 2018.
* Author : Igor Barkov < lopar . 4 ever @ gmail . com >
* Project name : Battles - Game
*/
2021-01-27 15:19:05 +00:00
use Battles\Travel ;
use Battles\User ;
2018-01-28 16:40:49 +00:00
require_once 'config.php' ;
2021-01-29 15:21:14 +00:00
if ( empty ( $_SESSION [ 'uid' ])) {
header ( " Location: index.php " );
exit ;
} else {
$user = new User ( $_SESSION [ 'uid' ]);
}
2020-10-29 23:30:05 +00:00
2020-08-30 00:09:53 +00:00
if ( $user -> id && $user -> block ) {
exit ( 'user blocked!' );
2018-06-24 01:18:49 +00:00
}
2020-06-23 15:13:20 +00:00
2020-10-29 23:30:05 +00:00
/*
* Проверки на соответствие скрипта и комнаты , которые были натыканы по всем файлам .
*/
$fbattleCheckFiles = [
'c_haos_in.php' ,
'c_haos.php' ,
'c_park.php' ,
'city.php' ,
'clan_castle.php' ,
'comission.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' ,
];
//Может просто отовсюду? О _о
if ( $user -> battle && in_array ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], $fbattleCheckFiles )) {
header ( 'location: fbattle.php' );
exit ;
}
$towerinCheckFiles = [ 'main.php' , 'city.php' , 'tower.php' ];
if ( $user -> in_tower && in_array ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], $towerinCheckFiles )) {
header ( 'location: towerin.php' );
exit ;
}
$roomsCheck = [ 22 , 23 , 25 , 27 , 29 , 30 , 31 , 37 , 38 , 39 , 40 , 41 , 45 , 53 , 61 , 401 , 402 , 600 , 601 , 602 , 621 , 650 , 1051 , 1052 ];
// Если я в одной из этих комнат,
// [И] Имя файла который инклюдит файл с проверкой не совпадает с именем файла локации в которой я нахожусь
// [И] Номер комнаты который я пытаюсь открыть есть в списке проверяемых
if ( in_array ( $user -> room , $roomsCheck )
2021-01-27 15:19:05 +00:00
&& pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ] != Travel :: $roomFileName [ $user -> room ]
&& in_array ( array_search ( pathinfo ( debug_backtrace ()[ 0 ][ 'file' ])[ 'basename' ], Travel :: $roomFileName ), $roomsCheck )) {
2020-10-29 23:30:05 +00:00
header ( 'location: main.php' );
exit ;
}
2018-12-10 23:52:46 +00:00
$ip = filter_input ( INPUT_SERVER , 'REMOTE_ADDR' , FILTER_VALIDATE_IP );
2020-06-23 15:57:20 +00:00
if ( isset ( $_GET [ 'goto' ]) && isset ( $_GET [ 'tStamp' ]) && isset ( $_GET [ 'vcode' ]) && $_GET [ 'vcode' ] == md5 ( sha1 ( $_GET [ 'goto' ] . $_GET [ 'tStamp' ]))) {
db :: c () -> query ( 'UPDATE `users`,`online` SET `users`.`room` = ?i, `online`.`room` = ?i WHERE `online`.`id` = `users`.`id` AND `online`.`id` = ?i' , $_GET [ 'goto' ], $_GET [ 'goto' ], $_SESSION [ 'uid' ]);
2020-08-30 00:09:53 +00:00
$user -> room = intval ( $_GET [ 'goto' ]);
2020-06-23 19:34:52 +00:00
}
2018-01-28 16:40:49 +00:00
function createbot ( $bot , $login = " " )
{
$rec = db :: c () -> query ( 'SELECT `id`, `login`, `maxhp` FROM `users` WHERE `id` = "?s" LIMIT 1' , $bot ) -> fetch_assoc ();
if ( isset ( $rec [ 'id' ])) {
if ( $login ) {
$rec [ 'login' ] = $login ;
}
$botname = $rec [ 'login' ];
2018-12-10 20:16:42 +00:00
db :: c () -> query ( 'INSERT INTO `bots` (`name`, `prototype`, `hp`) VALUES ("?s", "?s", "?s")' , $botname , $bot , $rec [ 'maxhp' ]);
2018-01-28 21:22:28 +00:00
$nid = db :: c () -> getLastInsertId ();
2018-12-27 14:46:00 +00:00
return [ " id " => $nid , " login " => $botname ];
2018-01-28 16:40:49 +00:00
} else {
return false ;
}
}
2018-12-27 14:46:00 +00:00
$var_map = [
2018-01-28 16:40:49 +00:00
'cell_1' => 'Березовая роща' , 'cell_2' => 'Березовая просека' , 'cell_3' => 'Тёмный угол' , 'cell_4' => 'Мрачная опушка' ,
'cell_5' => 'Тёмное урочище' , 'cell_6' => 'Бурелом' , 'cell_7' => 'Старая ива' , 'cell_8' => 'Разнолесье' ,
'cell_9' => 'Сосновая тропа' , 'cell_10' => 'Забытая дорога' , 'cell_11' => 'Новая дорога' , 'cell_12' => 'Мщаник' ,
'cell_13' => 'Ясная поляна' , 'cell_14' => 'Заросший тракт' , 'cell_15' => 'Смутный ельник' , 'cell_16' => 'Сосновый б о р ' ,
'cell_17' => 'Тихоход' , 'cell_18' => 'Сосновый гай' , 'cell_19' => 'Смешаный лес' , 'cell_20' => 'Темная поляна' ,
'cell_21' => 'Осенний угол' , 'cell_22' => 'Грибное место' , 'cell_23' => 'Опушка' , 'cell_24' => 'Рыжий лес' ,
2020-06-23 16:57:16 +00:00
'cell_25' => 'Полесье' ,
2018-12-27 14:46:00 +00:00
];
2018-01-28 16:40:49 +00:00
2020-06-23 16:57:16 +00:00
function get_out ( $u )
{
2020-06-23 15:57:20 +00:00
$pers = db :: c () -> query ( 'SELECT * FROM users WHERE id = ?i' , $u ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
undressall ( $pers [ 'id' ]);
2020-06-23 15:57:20 +00:00
db :: c () -> query ( 'UPDATE inventory SET owner = ?i WHERE owner = ?i' , $pers [ 'id' ], $pers [ 'id' ] + _BOTSEPARATOR_ );
2018-01-28 16:40:49 +00:00
###
2020-06-23 16:57:16 +00:00
$row = db :: c () -> query ( 'SELECT * FROM `effects` WHERE `owner` = ?i' , $pers [ 'id' ] + _BOTSEPARATOR_ );
2018-12-27 14:46:00 +00:00
$travm = [ 11 , 12 , 13 , 14 ];
2020-06-23 15:57:20 +00:00
while ( $efs = $row -> fetch_assoc ()) {
2018-07-02 15:35:25 +00:00
if ( in_array ( $efs [ 'type' ], $travm )) {
$pers [ 'sila' ] -= $efs [ 'sila' ];
$pers [ 'lovk' ] -= $efs [ 'lovk' ];
$pers [ 'inta' ] -= $efs [ 'inta' ];
$pers [ 'vinos' ] -= $efs [ 'vinos' ];
} else {
$pers [ 'sila' ] += $efs [ 'sila' ];
$pers [ 'lovk' ] += $efs [ 'lovk' ];
$pers [ 'inta' ] += $efs [ 'inta' ];
$pers [ 'vinos' ] += $efs [ 'vinos' ];
$pers [ 'maxhp' ] += $efs [ 'hp' ];
}
2018-12-10 20:16:42 +00:00
$efs [ 'owner' ] = $_SESSION [ 'uid' ];
2020-06-23 15:57:20 +00:00
//mysql_query('UPDATE `effects` SET `owner` = "' . $efs['owner'] . '" WHERE `id` = "' . $efs['id'] . '" LIMIT 1');
//mysql_query('UPDATE `users` SET `sila` = "' . $pers['sila'] . '", `lovk` = "' . $pers['lovk'] . '", `inta` = "' . $pers['inta'] . '", `vinos` = "' . $pers['vinos'] . '", `maxhp` = "' . $pers['maxhp'] . '" WHERE `id` = "' . $pers['id'] . '" LIMIT 1');
2018-01-28 16:40:49 +00:00
}
###
}
2018-01-28 21:51:21 +00:00
function takeshopitem ( $item , $table = " shop " , $present = '' , $onlyonetrip = '' , $fields = 0 , $uid = 0 , $koll = 1 , $podzem = 0 )
2018-01-28 16:40:49 +00:00
{
global $user ;
2018-12-10 20:16:42 +00:00
$flds = [];
$goden = '' ;
2018-01-28 16:40:49 +00:00
if ( ! $uid ) {
2020-08-30 00:09:53 +00:00
$uid = $user -> id ;
2018-01-28 16:40:49 +00:00
}
2020-06-23 15:57:20 +00:00
$r = db :: c () -> query ( 'SHOW FIELDS FROM ?f' , $table );
$r2 = db :: c () -> query ( 'SHOW FIELDS FROM inventory' );
2018-01-28 16:40:49 +00:00
2020-06-23 15:57:20 +00:00
while ( $rec = $r2 -> fetch_assoc ()) {
2018-01-28 16:40:49 +00:00
$flds [ $rec [ 'Field' ]] = 1 ;
}
2020-06-23 15:57:20 +00:00
$rec1 = db :: c () -> query ( 'SELECT * FROM ?f WHERE id = ?i' , $table , $item ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
if ( $rec1 [ 'koll' ]) {
2020-06-23 15:57:20 +00:00
db :: c () -> query ( 'UPDATE inventory SET koll = (koll + ?i), massa = (massa + ?i), cost = (cost + ?i) WHERE owner = ?i AND prototype = ?i' , $koll , $rec1 [ 'massa' ] * $koll , $rec1 [ 'cost' ], $uid , $item );
2020-06-23 20:24:15 +00:00
if ( db :: c () -> getAffectedRows () > 0 ) {
return [ " img " => $rec1 [ 'img' ], " name " => $rec1 [ 'name' ]];
}
2018-01-28 16:40:49 +00:00
$rec1 [ 'koll' ] = $koll ;
$rec1 [ 'massa' ] *= $koll ;
}
if ( $rec1 [ 'onlyone' ]) {
2020-06-23 15:57:20 +00:00
$i = db :: c () -> query ( 'SELECT id FROM inventory WHERE owner = ?i AND prototype = ?i' , $uid , $item ) -> fetch_row ();
2018-01-28 16:40:49 +00:00
if ( $i ) {
2018-12-27 14:46:00 +00:00
return [ " error " => " У вас слишком много таких вещей." ];
2018-01-28 16:40:49 +00:00
}
}
if ( $present ) {
$rec1 [ 'present' ] = $present ;
$rec1 [ 'cost' ] = 0 ;
$rec1 [ 'ecost' ] = 0 ;
}
$sql = " " ;
2020-06-23 15:57:20 +00:00
while ( $rec = $r -> fetch_assoc ()) {
2020-06-23 20:24:15 +00:00
if ( ! $flds [ $rec [ 'Field' ]]) {
continue ;
}
2018-01-28 16:40:49 +00:00
if ( $rec [ 'Field' ] == " dategoden " ) {
$goden = $rec1 [ $rec [ 'Field' ]];
}
if ( $rec [ 'Field' ] == " goden " ) {
$goden = $rec1 [ $rec [ 'Field' ]];
}
2020-06-23 20:24:15 +00:00
if ( $rec [ 'Field' ] == " id " || $rec [ 'Field' ] == " prototype " || $rec [ 'Field' ] == " dategoden " ) {
continue ;
}
2018-01-28 16:40:49 +00:00
$sql .= " , ` $rec[Field] ` = ' " . $rec1 [ $rec [ 'Field' ]] . " ' " ;
}
if ( $podzem ) {
$rec1 [ 'podzem' ] = $podzem ;
}
if ( $fields [ 'goden' ]) {
$goden = $fields [ " goden " ];
}
2018-12-10 20:16:42 +00:00
mysql_query ( " INSERT INTO `inventory` SET " . ( $present ? " `present` = ' $present ', " : " " ) . ( $rec1 [ 'podzem' ] ? " `podzem` = ' $rec1[podzem] ', " : " " ) . " `owner` = ' $uid ', `otdel` = $rec1[razdel] , `prototype` = ' $item ' " . ( $onlyonetrip ? " , `foronetrip` = 1 " : " " ) . ( $goden ? " , `dategoden` = ' " . ( $goden * 60 * 60 * 24 + time ()) . " ' " : " " ) . " $sql " );
2018-12-27 14:46:00 +00:00
return [ " img " => $rec1 [ 'img' ], " name " => $rec1 [ 'name' ], " id " => mysql_insert_id ()];
2018-01-28 16:40:49 +00:00
}
define ( '_BOTSEPARATOR_' , 10000000 );
function level_up ( $uid )
{
2020-07-03 15:36:06 +00:00
$us = db :: c () -> query ( 'SELECT `id`, `login`, `level`, `money`, `exp`, `nextup`, `stats`, `master`, `ip`, `in_tower` FROM `users` WHERE `id` =?i' , $uid ) -> fetch_assoc ();
2020-06-23 20:24:15 +00:00
if ( isset ( $us [ 'id' ]) && $us [ 'exp' ] >= $us [ 'nextup' ] && ! $us [ 'in_tower' ]) {
2020-08-30 16:28:15 +00:00
if ( Config :: $exptable [ $us [ 'nextup' ]][ 4 ] == 1 ) {
2020-06-23 20:24:15 +00:00
addch ( " Персонаж <b> { $us [ 'login' ] } </b> перешел на " . ( $us [ 'level' ] + 1 ) . " уровень. " );
2020-08-30 16:28:15 +00:00
addchp ( '<span class=\'success\'>Внимание!</span> Вы перешли на новый уровень. З а это Вы получаете: ' . Config :: $exptable [ $us [ 'nextup' ]][ 3 ] . ' кр.' , '{[]}' . $us [ 'login' ] . '{[]}' );
2018-01-28 16:40:49 +00:00
}
2020-08-30 16:28:15 +00:00
$us [ 'nextup' ] = Config :: $exptable [ $us [ 'nextup' ]][ 5 ];
$us [ 'stats' ] += Config :: $exptable [ $us [ 'nextup' ]][ 0 ];
$us [ 'master' ] += Config :: $exptable [ $us [ 'nextup' ]][ 1 ];
2020-07-03 15:36:06 +00:00
db :: c () -> query ( 'UPDATE `users` SET `nextup` = ?i, `stats` = ?i, `master` = ?i, `level` = ?i WHERE `id` = ?i' , $us [ 'nextup' ], $us [ 'stats' ], $us [ 'master' ], $us [ 'level' ], $us [ 'id' ]);
2018-01-28 16:40:49 +00:00
}
}
2020-06-24 05:30:01 +00:00
/*
* Проверка делающая левелап и ограничитель максимального уровня .
*/
2020-07-03 15:39:46 +00:00
//if (isset($_SESSION['uid'])) {
// try {
// $userInfo = db::c()->query('SELECT `exp`, `nextup`, `level` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
// if ($userInfo && ($userInfo['exp'] >= $userInfo['nextup']) && $userInfo['level'] < 50) {
// level_up($_SESSION['uid']);
// $levelUpArray = ['nextup' => $nextup, 'stats' =>];
// db::c()->query('UPDATE users SET ?Ai, stats = (stats +2), level = (level +1) WHERE id = ?i', $levelUpArray, $_SESSION['uid']);
// }
// } catch (\Krugozor\Database\Mysql\Exception $e) {
// echo $e->getTraceAsString();
// }
//}
2020-06-24 05:30:01 +00:00
2018-01-28 16:40:49 +00:00
function savecavedata ( $cavedata , $caveleader , $floor )
{
$f1 = fopen ( " cavedata/ $caveleader - $floor .dat " , " wb+ " );
flock ( $f1 , LOCK_EX );
fwrite ( $f1 , serialize ( $cavedata ));
flock ( $f1 , LOCK_UN );
fclose ( $f1 );
}
2020-06-23 20:24:15 +00:00
function GiveExp ( $id , $exp )
{
2020-06-23 19:10:00 +00:00
db :: c () -> query ( 'UPDATE users SET exp = exp + ?i WHERE id = ?i' , $exp , $id );
2018-01-28 16:40:49 +00:00
}
2020-06-23 20:24:15 +00:00
function GiveRep ( $id , $rep )
{
2020-06-23 19:10:00 +00:00
db :: c () -> query ( 'UPDATE users SET doblest = (doblest + ?i), rep_laba = (rep_laba + ?i) WHERE `id` = ?i' , $rep , $rep , $id );
2018-01-28 16:40:49 +00:00
}
2018-12-27 13:18:55 +00:00
/**
2020-08-29 23:21:22 +00:00
* Генератор прогрессбара .
2020-08-30 00:09:53 +00:00
* @ param $current - Текущее значение .
* @ param $maximum - Максимальное значение .
2020-08-29 23:21:22 +00:00
* @ param string $line_color - Цвет полоски прогрессбара .
2020-08-30 00:09:53 +00:00
* @ param string $bg_color - Фон прогрессбара .
2020-08-29 23:21:22 +00:00
* @ return string
2018-12-27 13:18:55 +00:00
*/
2018-12-27 23:13:46 +00:00
function showProgressBar ( $current , $maximum , $line_color = 'limegreen' , $bg_color = 'silver' )
2018-12-27 12:59:45 +00:00
{
2018-12-27 23:13:46 +00:00
$bar = round ( $current / $maximum * 100 );
2020-06-23 20:24:15 +00:00
return <<< HTML
2018-12-27 23:13:46 +00:00
< div style = " width: 100%; height: 16px; background: $bg_color ; overflow: hidden; border-radius: 3px; " >
< div style = " height: 16px; background: $line_color ; border-radius: 3px; width: $bar %; " ></ div >
2018-12-27 12:59:45 +00:00
</ div >
2018-12-27 13:18:55 +00:00
< div style = " width: 100%; height: 16px; font-size: 14px; text-align: center; margin-top: -16px; " >
2018-12-27 23:13:46 +00:00
$current / $maximum
2018-12-27 12:59:45 +00:00
</ div >
2018-12-27 13:18:55 +00:00
HTML ;
2018-12-27 12:59:45 +00:00
}
2020-06-24 06:45:32 +00:00
/**
* Функция отображает слот для свитков в окне персонажа .
2020-07-03 15:36:06 +00:00
*
2020-06-24 06:45:32 +00:00
* @ param $slot
2020-07-03 15:36:06 +00:00
*
2020-06-24 06:45:32 +00:00
* @ throws \Krugozor\Database\Mysql\Exception
*/
2018-01-28 16:40:49 +00:00
function echoscroll ( $slot )
{
global $user ;
2020-06-24 06:45:32 +00:00
$all_magic = 0 ;
2020-08-30 00:09:53 +00:00
if ( $user -> battle ) {
2018-01-28 16:40:49 +00:00
$script = 'fbattle' ;
2020-08-30 00:09:53 +00:00
$bat = db :: c () -> query ( 'SELECT `magic` FROM `battle` WHERE `id` = ?i' , $user -> battle ) -> fetch_assoc ();
2018-03-08 22:30:57 +00:00
$all_magic = unserialize ( $bat [ 'magic' ]);
2020-06-24 06:45:32 +00:00
} else {
$script = 'main' ;
2018-03-08 22:30:57 +00:00
}
2020-08-30 00:09:53 +00:00
$dress = db :: c () -> query ( 'SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i' , $user -> $slot ) -> fetch_assoc ();
2018-03-08 22:14:29 +00:00
$need_charge = db :: c () -> query ( 'SELECT `needcharge` FROM `magic` WHERE `id` = ?i' , $dress [ 'magic' ]) -> fetch_assoc ();
2018-03-08 22:30:57 +00:00
2020-08-30 00:09:53 +00:00
if (( $user -> $slot > 0 ) && ( $all_magic [ $user -> id ] < 1 || empty ( $need_charge [ 'needcharge' ]))) {
$row [ 'id' ] = $user -> $slot ;
2018-01-28 16:40:49 +00:00
if ( $dress [ 'magic' ]) {
2020-06-24 06:45:32 +00:00
$magic = db :: c () -> query ( 'SELECT targeted FROM `magic` WHERE `id` = ?i' , $dress [ 'magic' ]) -> fetch_assoc ();
2018-01-28 16:40:49 +00:00
echo " <a onclick= \" " ;
if ( $magic [ 'targeted' ] == 1 ) {
echo " okno('Введите название предмета', ' " . $script . " .php?use= { $row [ 'id' ] } ', 'target'); " ;
} else
if ( $magic [ 'targeted' ] == 2 ) {
echo " findlogin('Введите имя персонажа', ' " . $script . " .php?use= { $row [ 'id' ] } ', 'target'); " ;
} else {
echo " if(confirm('Использовать сейчас?')) { window.location=' " . $script . " .php?use= " . $row [ 'id' ] . " ';} " ;
}
echo " \" href='#'> " ;
}
2020-06-24 06:45:32 +00:00
echo <<< ACTIVE_SCROLL
< img class = 'tooltip' src = " i/sh/ { $dress [ 'img' ] } " width = '40' title = " <b> { $dress [ 'name' ] } </b><br> Прочность { $dress [ 'duration' ] } / { $dress [ 'maxdur' ] } " height = '25' alt = " Свиток " ></ a >
ACTIVE_SCROLL ;
2020-08-30 00:09:53 +00:00
} elseif (( $user -> $slot > 0 ) && ( $all_magic [ $user -> id ] >= 1 ) && $need_charge [ 'needcharge' ] > 0 ) {
2020-06-24 06:45:32 +00:00
echo <<< INACTIVE_SCROLL
< img src = " i/sh/magicclock.gif " width = " 40 " height = " 25 " title = 'Произведите размен ударами и магия снова станет доступна' alt = " Свиток " >
INACTIVE_SCROLL ;
2018-01-28 16:40:49 +00:00
} else {
2020-06-24 06:45:32 +00:00
echo <<< EMPTY_SLOT
< img class = " tooltip " src = " i/w13.gif " width = " 40 " height = " 25 " title = '<b>Пустой слот магия</b>' alt = " Слот для свитка " >
EMPTY_SLOT ;
2018-01-28 16:40:49 +00:00
}
}
// ссылка на магию
function showhrefmagic ( $dress )
{
2019-01-12 21:35:48 +00:00
$user = db :: c () -> query ( 'SELECT `battle` FROM `users` WHERE `id` = ?i' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2018-12-27 16:13:40 +00:00
$magic = db :: c () -> query ( 'SELECT * FROM `magic` WHERE `id` = ?i' , $dress [ 'includemagic' ]) -> fetch_assoc ();
2018-01-28 16:40:49 +00:00
$r = '' ;
2018-12-27 16:13:40 +00:00
$script = 'main' ;
2020-06-23 20:24:15 +00:00
if ( $user [ 'battle' ]) {
$script = 'fbattle' ;
}
2018-01-28 16:40:49 +00:00
$r .= " <a onclick= \" " ;
if ( $magic [ 'targeted' ] == 1 ) {
$r .= " okno('Введите название предмета', ' { $script } .php?use= { $dress [ 'id' ] } ', 'target') " ;
} elseif ( $magic [ 'targeted' ] == 2 ) {
$r .= " findlogin(' " . $magic [ 'name' ] . " ', ' { $script } .php?use= { $dress [ 'id' ] } ', 'target') " ;
} else {
$r .= " if (confirm('Использовать сейчас?')) window.location=' " . $script . " .php?use= " . $dress [ 'id' ] . " '; " ;
}
$r .= " \" href='#'> " ;
2019-01-12 21:35:48 +00:00
$r .= " <img src= \" i/sh/ { $dress [ 'img' ] } \" style= \" filter:shadow(color=red, direction=90, strength=3); \" title= \" " . $dress [ 'name' ] . (( $dress [ 'text' ] != null ) ? " <br />Н а оружии выгравировано ' { $dress [ 'text' ] } ' " : " " ) . " \" ><br> " ;
2018-01-28 16:40:49 +00:00
return $r ;
}
function timeOut ( $ttm )
{
$out = '' ;
$time_still = $ttm ;
$tmp = floor ( $time_still / 2592000 );
$id = 0 ;
if ( $tmp > 0 ) {
$id ++ ;
if ( $id < 3 ) {
$out .= $tmp . " мес. " ;
}
$time_still = $time_still - $tmp * 2592000 ;
}
$tmp = floor ( $time_still / 86400 );
if ( $tmp > 0 ) {
$id ++ ;
if ( $id < 3 ) {
$out .= $tmp . " дн. " ;
}
$time_still = $time_still - $tmp * 86400 ;
}
$tmp = floor ( $time_still / 3600 );
if ( $tmp > 0 ) {
$id ++ ;
if ( $id < 3 ) {
$out .= $tmp . " ч. " ;
}
$time_still = $time_still - $tmp * 3600 ;
}
$tmp = floor ( $time_still / 60 );
if ( $tmp > 0 ) {
$id ++ ;
if ( $id < 3 ) {
$out .= $tmp . " мин. " ;
}
}
if ( $out == '' ) {
if ( $time_still < 0 ) {
$time_still = 0 ;
}
$out = $time_still . ' сек.' ;
}
return $out ;
}
2021-01-31 14:59:13 +00:00
function show_eff_inf ( $u )
2018-11-01 15:08:24 +00:00
{
2021-01-31 14:59:13 +00:00
global $db ;
2018-11-01 15:08:24 +00:00
$img = [
2018-12-10 23:52:46 +00:00
1 => " travma.gif " , 2 => " magic/sleep.gif " , 3 => " magic/sleepf.gif " , 4 => " magic/haos.gif " ,
5 => " magic/obezl.gif " , 6 => " expx15.gif " , 7 => " euphoria.png " , 8 => " sleep_obj.gif " ,
10 => " magic/chains.gif " , 11 => " travma.gif " , 12 => " travma.gif " , 13 => " travma.gif " ,
14 => " travma.gif " , 20 => " check.gif " , 21 => " magic/al_neut_power.gif " , 22 => " magic/fist_def.gif " ,
201 => " magic/defence.gif " , 202 => " magic/devastate.gif " , 203 => " magic/spell_luck.gif " , 215 => " magic/wis_air_def1.gif " ,
216 => " magic/wis_air_def2.gif " , 217 => " magic/wis_air_def3.gif " , 218 => " magic/wis_earth_def1.gif " , 219 => " magic/wis_earth_def2.gif " ,
220 => " magic/wis_earth_def3.gif " , 221 => " magic/wis_fire_def1.gif " , 222 => " magic/wis_fire_def2.gif " , 223 => " magic/wis_fire_def3.gif " ,
224 => " magic/wis_water_def1.gif " , 225 => " magic/wis_water_def2.gif " , 226 => " magic/wis_water_def3.gif " , 227 => " magic/attack_defence.gif " ,
2020-06-23 16:57:16 +00:00
1022 => " sh/hidden.gif " ,
2018-11-01 15:08:24 +00:00
];
2018-01-28 16:40:49 +00:00
$r = '' ;
2021-01-31 14:59:13 +00:00
$effs = $db -> ofetchAll ( 'SELECT * FROM users_effects WHERE type != 20 AND owner_id = ?' , $u );
$i = 0 ;
while ( $i < count ( $effs )) {
$r .= '<div>' ;
$r .= '<img class="image" src="/i/' . $img [ $effs -> type ] . '" /> <a href=\'main.php?edit=1&del=1&efid=' . $effs -> effect_id . '\' onclick=\'return confirm("Удалить ' . $effs -> name . '?")\'><img src=\'i/clear.gif\' style=\'float: right;\' /></a>' ;
$r .= '<span class="title">' . $effs -> name . '</span>' ;
if ( $effs [ 'sleep' ] != 0 ) {
$r .= '<div class="timeleft">Эффект заморожен</div>' ;
} else {
$r .= '<div class="timeleft">' . timeOut ( $effs -> remaining_time - time ()) . '</div>' ;
2018-01-28 16:40:49 +00:00
}
2021-01-31 14:59:13 +00:00
$r .= '</div>' ;
$i ++ ;
2018-01-28 16:40:49 +00:00
}
return $r ;
}
2018-03-01 10:57:27 +00:00
/**
* @ param $time
* @ param $vars
* @ param $vls
* @ param $uid
2018-12-27 14:46:00 +00:00
*
2018-03-01 10:57:27 +00:00
* @ return bool
*/
2018-01-28 16:40:49 +00:00
function addActions ( $time , $vars , $vls , $uid )
{
2018-03-01 10:57:27 +00:00
db :: c () -> query ( 'LOCK TABLES `actions` WRITE' );
2018-12-10 20:16:42 +00:00
$ins = db :: c () -> query ( 'INSERT INTO `actions` (`uid`,`time`,`city`,`room`,`vars`,`ip`,`vals`) VALUES (?i, ?i, "?s", ?i, "?s", "?s", "?s")' , $uid , $time , " capitalcity " , 0 , $vars , $_SERVER [ 'HTTP_X_REAL_IP' ], $vls );
2018-03-01 10:57:27 +00:00
db :: c () -> query ( 'UNLOCK TABLES' );
2020-06-23 20:24:15 +00:00
return $ins ;
2018-01-28 16:40:49 +00:00
}
2020-08-29 23:21:22 +00:00
function undressall ( $user_id )
2018-01-28 16:40:49 +00:00
{
2020-08-29 23:21:22 +00:00
db :: c () -> query ( 'UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i' , $user_id );
2018-01-28 16:40:49 +00:00
}
function dropitemid ( $slot , $id )
{
2020-08-30 00:09:53 +00:00
global $user ;
2018-01-28 16:40:49 +00:00
switch ( $slot ) {
case 1 :
$slot1 = 'sergi' ;
break ;
case 2 :
$slot1 = 'kulon' ;
break ;
case 3 :
$slot1 = 'weap' ;
break ;
case 4 :
$slot1 = 'bron' ;
break ;
case 5 :
$slot1 = 'r1' ;
break ;
case 6 :
$slot1 = 'r2' ;
break ;
case 7 :
$slot1 = 'r3' ;
break ;
case 8 :
$slot1 = 'helm' ;
break ;
case 9 :
$slot1 = 'perchi' ;
break ;
case 10 :
$slot1 = 'shit' ;
break ;
case 11 :
$slot1 = 'boots' ;
break ;
case 12 :
$slot1 = 'm1' ;
break ;
case 13 :
$slot1 = 'm2' ;
break ;
case 14 :
$slot1 = 'm3' ;
break ;
case 15 :
$slot1 = 'm4' ;
break ;
case 16 :
$slot1 = 'm5' ;
break ;
case 17 :
$slot1 = 'm6' ;
break ;
case 18 :
$slot1 = 'm7' ;
break ;
case 19 :
$slot1 = 'm8' ;
break ;
case 20 :
$slot1 = 'm9' ;
break ;
case 21 :
$slot1 = 'm10' ;
break ;
case 22 :
$slot1 = 'rybax' ;
break ;
case 23 :
$slot1 = 'plaw' ;
break ;
2018-12-10 20:16:42 +00:00
default :
$slot1 = '' ;
break ;
2018-01-28 16:40:49 +00:00
}
2019-09-17 14:37:44 +00:00
$checkid = db :: c () -> query ( 'SELECT 1 FROM `users` WHERE `id` = ?i' , $id );
if ( $checkid -> getNumRows ()) {
if ( mysql_query ( 'UPDATE `users`, `inventory` SET `users`.`' . $slot1 . '` = 0, `inventory`.`dressed` = 0, `users`.`sila` = `users`.`sila` - `inventory`.`gsila`, `users`.`lovk` = `users`.`lovk` - `inventory`.`glovk`, `users`.`inta` = `users`.`inta` - `inventory`.`ginta`, `users`.`intel` = `users`.`intel` - `inventory`.`gintel`, `users`.`maxhp` = `users`.`maxhp` - `inventory`.`ghp`, `users`.`noj` = `users`.`noj` - `inventory`.`gnoj`, `users`.`topor` = `users`.`topor` - `inventory`.`gtopor`, `users`.`dubina` = `users`.`dubina` - `inventory`.`gdubina`, `users`.`mec` = `users`.`mec` - `inventory`.`gmech`, `users`.`mfire` = `users`.`mfire` - `inventory`.`gfire`, `users`.`mwater` = `users`.`mwater` - `inventory`.`gwater`, `users`.`mair` = `users`.`mair` - `inventory`.`gair`, `users`.`mearth` = `users`.`mearth` - `inventory`.`gearth`, `users`.`mlight` = `users`.`mlight` - `inventory`.`glight`, `users`.`mgray` = `users`.`mgray` - `inventory`.`ggray`, `users`.`mdark` = `users`.`mdark` - `inventory`.`gdark`, `users`.`fkrit` = `users`.`fkrit` - `inventory`.`mfkrit`, `users`.`fakrit` = `users`.`fakrit` - `inventory`.`mfakrit`, `users`.`fuvorot` = `users`.`fuvorot` - `inventory`.`mfuvorot`, `users`.`fauvorot` = `users`.`fauvorot` - `inventory`.`mfauvorot`, `users`.`ubron1` = `users`.`ubron1` - `inventory`.`bron1`, `users`.`ubron2` = `users`.`ubron2` - `inventory`.`bron2`, `users`.`ubron3` = `users`.`ubron3` - `inventory`.`bron3`, `users`.`ubron4` = `users`.`ubron4` - `inventory`.`bron4`, `users`.`uminu` = `users`.`uminu` - `inventory`.`minu`, `users`.`umaxu` = `users`.`umaxu` - `inventory`.`maxu` WHERE `inventory`.`id` = `users`.`' . $slot1 . '` AND `inventory`.`dressed` = 1 AND `inventory`.`owner` = "' . $id . '" AND `users`.`id` = "' . $id . '"' )) {
db :: c () -> query ( 'UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i' , time (), $id );
2020-08-30 00:09:53 +00:00
$user -> $slot1 = 0 ;
2018-01-28 16:40:49 +00:00
}
return true ;
2020-06-23 20:24:15 +00:00
} else {
return false ;
}
2018-01-28 16:40:49 +00:00
}
// снять предмет
function dropitem ( $slot )
{
2018-01-28 21:51:21 +00:00
global $user ;
2018-12-10 20:16:42 +00:00
$wear_arr = [];
2018-01-28 16:40:49 +00:00
switch ( $slot ) {
case 1 :
$slot1 = 'sergi' ;
break ;
case 2 :
$slot1 = 'kulon' ;
break ;
case 3 :
$slot1 = 'weap' ;
break ;
case 4 :
$slot1 = 'bron' ;
break ;
case 5 :
$slot1 = 'r1' ;
break ;
case 6 :
$slot1 = 'r2' ;
break ;
case 7 :
$slot1 = 'r3' ;
break ;
case 8 :
$slot1 = 'helm' ;
break ;
case 9 :
$slot1 = 'perchi' ;
break ;
case 10 :
$slot1 = 'shit' ;
break ;
case 11 :
$slot1 = 'boots' ;
break ;
case 12 :
$slot1 = 'm1' ;
break ;
case 13 :
$slot1 = 'm2' ;
break ;
case 14 :
$slot1 = 'm3' ;
break ;
case 15 :
$slot1 = 'm4' ;
break ;
case 16 :
$slot1 = 'm5' ;
break ;
case 17 :
$slot1 = 'm6' ;
break ;
case 18 :
$slot1 = 'm7' ;
break ;
case 19 :
$slot1 = 'm8' ;
break ;
case 20 :
$slot1 = 'm9' ;
break ;
case 21 :
$slot1 = 'm10' ;
break ;
case 22 :
$slot1 = 'rybax' ;
break ;
case 23 :
$slot1 = 'plaw' ;
break ;
2018-12-10 20:16:42 +00:00
default :
$slot1 = '' ;
break ;
2018-01-28 16:40:49 +00:00
}
2020-08-30 00:09:53 +00:00
if ( db :: c () -> query ( ' UPDATE `users` as `u` , `inventory` as `i` SET `u` . ? f = 0 , `i` . `dressed` = 0 ,
2018-11-01 16:00:26 +00:00
`u` . `sila` = `u` . `sila` - `i` . `gsila` ,
`u` . `lovk` = `u` . `lovk` - `i` . `glovk` ,
`u` . `inta` = `u` . `inta` - `i` . `ginta` ,
`u` . `intel` = `u` . `intel` - `i` . `gintel` ,
`u` . `maxhp` = `u` . `maxhp` - `i` . `ghp` ,
`u` . `noj` = `u` . `noj` - `i` . `gnoj` ,
`u` . `topor` = `u` . `topor` - `i` . `gtopor` ,
`u` . `dubina` = `u` . `dubina` - `i` . `gdubina` ,
`u` . `mec` = `u` . `mec` - `i` . `gmech` ,
`u` . `mfire` = `u` . `mfire` - `i` . `gfire` ,
`u` . `mwater` = `u` . `mwater` - `i` . `gwater` ,
`u` . `mair` = `u` . `mair` - `i` . `gair` ,
`u` . `mearth` = `u` . `mearth` - `i` . `gearth` ,
`u` . `mlight` = `u` . `mlight` - `i` . `glight` ,
`u` . `mgray` = `u` . `mgray` - `i` . `ggray` ,
`u` . `mdark` = `u` . `mdark` - `i` . `gdark` ,
`u` . `ubron1` = `u` . `ubron1` - `i` . `bron1` ,
`u` . `ubron2` = `u` . `ubron2` - `i` . `bron2` ,
`u` . `ubron3` = `u` . `ubron3` - `i` . `bron3` ,
`u` . `ubron4` = `u` . `ubron4` - `i` . `bron4` ,
`u` . `fkrit` = `u` . `fkrit` - `i` . `mfkrit` ,
`u` . `fakrit` = `u` . `fakrit` - `i` . `mfakrit` ,
`u` . `fuvorot` = `u` . `fuvorot` - `i` . `mfuvorot` ,
`u` . `fauvorot` = `u` . `fauvorot` - `i` . `mfauvorot` ,
`u` . `uminu` = `u` . `uminu` - `i` . `minu` ,
`u` . `umaxu` = `u` . `umaxu` - `i` . `maxu`
2020-08-30 00:09:53 +00:00
WHERE `i` . `id` = `u` . ? f AND `i` . `dressed` = 1 AND `i` . `owner` = ? i AND u . id = ? i ' , $slot1 , $slot1 , $user -> id , $user -> id )) {
db :: c () -> query ( 'UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i' , time (), $user -> id );
}
2018-11-01 16:00:26 +00:00
2020-08-30 00:09:53 +00:00
$wear_raw = db :: c () -> query ( 'SELECT * FROM `inventory` where `owner` = ?i AND `dressed` = 1' , $user -> id );
while ( $wear_list = $wear_raw -> fetch_assoc ()) {
$wear_arr [] = $wear_list [ 'prototype' ];
}
2018-01-28 16:40:49 +00:00
2020-08-30 00:09:53 +00:00
$item [ 'id' ] = $user -> $slot1 ;
2018-01-28 16:40:49 +00:00
2020-08-30 00:09:53 +00:00
$get_pro = db :: c () -> query ( 'SELECT * FROM `inventory` where `id` = ?i' , $item [ 'id' ]) -> fetch_assoc ();
/////////////////////
$sets_items = db :: c () -> query ( 'SELECT * FROM `item_sets`' );
2018-01-28 16:40:49 +00:00
2020-08-30 00:09:53 +00:00
//для каждого комплекта
while ( $items_in_set = $sets_items -> fetch_assoc ()) {
$checker = 0 ;
$temp_is = explode ( " , " , $items_in_set [ 'prot_id' ]);
$set_id = $items_in_set [ 'set_id' ];
2018-01-28 16:40:49 +00:00
2020-08-30 00:09:53 +00:00
//если прото в комплекте и не одет
if ( in_array ( $get_pro [ 'prototype' ], $temp_is ) && ( ! in_array ( $get_pro [ 'prototype' ], $wear_arr ))) {
$checker = 1 ;
2020-06-23 20:24:15 +00:00
2020-08-30 00:09:53 +00:00
//для каждого одетого предмета
foreach ( $temp_is as $check_proto ) {
if ( $check_proto != $get_pro [ 'prototype' ] && ! in_array ( $check_proto , $wear_arr )) {
$checker = 0 ;
2020-06-23 20:24:15 +00:00
}
2018-01-28 16:40:49 +00:00
}
2020-08-30 00:09:53 +00:00
}
2018-01-28 16:40:49 +00:00
2020-08-30 00:09:53 +00:00
//
if (( $checker == 1 ) && ( ! in_array ( $get_pro [ 'prototype' ], $wear_arr ))) {
db :: c () -> query ( ' UPDATE `users` as `u` , `item_sets` as `s` SET
2018-11-01 16:00:26 +00:00
`u` . `uminu` = `u` . `uminu` - `s` . `minu` ,
`u` . `umaxu` = `u` . `umaxu` - `s` . `maxu` ,
`u` . `sila = ` u `.` sila - `s` . `gsila` ,
`u` . `lovk = ` u `.` lovk - `s` . `glovk` ,
`u` . `inta = ` u `.` inta - `s` . `ginta` ,
`u` . `intel = ` u `.` intel - `s` . `gintel` ,
`u` . `maxhp = ` u `.` maxhp - `s` . `ghp` ,
`u` . `maxmana = ` u `.` maxmana - `s` . `gmana` ,
`u` . `fkrit = ` u `.` fkrit - `s` . `mfkrit` ,
`u` . `fakrit = ` u `.` fakrit - `s` . `mfakrit` ,
`u` . `fuvorot = ` u `.` fuvorot - `s` . `mfuvorot` ,
`u` . `fauvorot = ` u `.` fauvorot - `s` . `mfauvorot` ,
`u` . `noj = ` u `.` noj - `s` . `gnoj` ,
`u` . `topor = ` u `.` topor - `s` . `gtopor` ,
`u` . `dubina = ` u `.` dubina - `s` . `gdubina` ,
`u` . `mec = ` u `.` mec - `s` . `gmech` ,
`u` . `ubron1 = ` u `.` ubron1 - `s` . `bron1` ,
`u` . `ubron2 = ` u `.` ubron2 - `s` . `bron2` ,
`u` . `ubron3 = ` u `.` ubron3 - `s` . `bron3` ,
`u` . `ubron4 = ` u `.` ubron4 - `s` . `bron4` ,
`u` . `mfire = ` u `.` mfire - `s` . `gfire` ,
`u` . `mwater = ` u `.` mwater - `s` . `gwater` ,
`u` . `mair = ` u `.` mair - `s` . `gair` ,
`u` . `mearth = ` u `.` mearth - `s` . `gearth` ,
`u` . `mlight = ` u `.` mlight - `s` . `glight` ,
`u` . `mgray = ` u `.` mgray - `s` . `ggray`
2018-01-28 16:40:49 +00:00
WHERE
2020-08-30 00:09:53 +00:00
`u` . `id` = ? i AND `s` . `set_id` = ? i ' , $user -> id , $set_id );
2018-11-01 16:00:26 +00:00
}
2018-01-28 16:40:49 +00:00
}
2020-08-30 00:09:53 +00:00
return true ;
2018-01-28 16:40:49 +00:00
}
2020-10-30 00:33:02 +00:00
#15
2018-01-28 21:51:21 +00:00
function ref_drop ()
2018-01-28 16:40:49 +00:00
{
2018-06-24 01:18:49 +00:00
//сможет держать
function derj ( $id )
{
2018-12-10 23:52:46 +00:00
$user = db :: c () -> query ( 'SELECT `id`, `align` FROM `users` WHERE `id` = ?i' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
$ts = db :: c () -> query ( 'SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i' , $id ) -> fetch_assoc ();
2018-06-24 01:18:49 +00:00
$al = '(1 = 1)' ;
2020-06-23 20:24:15 +00:00
if ( $ts [ 'nalign' ] == 1.1 ) {
$al = '(1 = 2)' ;
}
2018-12-10 20:16:42 +00:00
$dd = db :: c () -> query ( ' SELECT `i` . `id` FROM `users` AS `u` , `inventory` AS `i`
2018-06-24 01:18:49 +00:00
WHERE
2018-11-01 15:33:21 +00:00
`i` . `needident` = 0 AND
`i` . `id` = ? i AND
`i` . `duration` < `i` . `maxdur` AND
`i` . `owner` = ? i AND
`u` . `sila` >= `i` . `nsila` AND
`u` . `lovk` >= `i` . `nlovk` AND
`u` . `inta` >= `i` . `ninta` AND
`u` . `vinos` >= `i` . `nvinos` AND
`u` . `intel` >= `i` . `nintel` AND
`u` . `mudra` >= `i` . `nmudra` AND
`u` . `level` >= `i` . `nlevel` AND
2018-11-01 15:35:12 +00:00
( " ?s " OR ( ? i = `i` . `nalign` ) or ( `i` . `nalign` = 0 )) AND
2018-11-01 15:33:21 +00:00
`u` . `noj` >= `i` . `nnoj` AND
`u` . `topor` >= `i` . `ntopor` AND
`u` . `dubina` >= `i` . `ndubina` AND
`u` . `mec` >= `i` . `nmech` AND
`u` . `mfire` >= `i` . `nfire` AND
`u` . `mwater` >= `i` . `nwater` AND
`u` . `mair` >= `i` . `nair` AND
`u` . `mearth` >= `i` . `nearth` AND
`u` . `mlight` >= `i` . `nlight` AND
`u` . `mgray` >= `i` . `ngray` AND
`u` . `mdark` >= `i` . `ndark` AND
`i` . `setsale` = 0 AND
2018-12-10 23:52:46 +00:00
`u` . `id` = ? i ', $id, $user[' id '], $al, $user[' align '], $user[' id ' ]);
2020-06-23 20:24:15 +00:00
return $dd -> getNumRows () > 0 ;
2018-06-24 01:18:49 +00:00
}
2018-12-11 13:09:21 +00:00
2018-12-11 13:00:16 +00:00
$slot = [ 'sergi' , 'kulon' , 'weap' , 'bron' , 'r1' , 'r2' , 'r3' , 'helm' , 'perchi' , 'shit' , 'boots' , 'm1' , 'm2' , 'm3' , 'm4' , 'm5' , 'm6' , 'm7' , 'm8' , 'm9' , 'm10' ];
2018-12-11 13:09:21 +00:00
$user = db :: c () -> query ( 'SELECT `sergi`,`kulon`,`weap`,`bron`,`r1`,`r2`,`r3`,`helm`,`perchi`,`shit`,`boots`,`m1`,`m2`,`m3`,`m4`,`m5`,`m6`,`m7`,`m8`,`m9`,`m10` FROM `users` WHERE id = ?i' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2018-01-28 16:40:49 +00:00
for ( $i = 0 ; $i <= 20 ; $i ++ ) {
if ( $user [ $slot [ $i ]] && ! derj ( $user [ $slot [ $i ]])) {
dropitem ( $i + 1 );
$user [ $slot [ $i ]] = null ;
}
}
}
2020-08-30 00:09:53 +00:00
/**
* Уничтожить предмет , принадлежащий игроку , вызывающего функцию .
* @ param $id - ID предмета игрока .
* @ throws \Krugozor\Database\Mysql\Exception
*/
2018-01-28 16:40:49 +00:00
function destructitem ( $id )
{
2018-06-23 16:22:20 +00:00
global $user ;
2020-08-30 00:09:53 +00:00
$item = db :: c () -> query ( 'SELECT 1 FROM inventory WHERE owner_id = ?i AND item_id = ?i' , $user -> id , $id );
if ( $item -> getNumRows ()) {
2018-06-23 16:22:20 +00:00
db :: c () -> query ( 'DELETE FROM `inventory` WHERE `id` = ?i' , $id );
2018-01-28 16:40:49 +00:00
}
}
// использовать магию
2020-08-29 23:21:22 +00:00
function usemagic ( $id , $target )
2018-01-28 16:40:49 +00:00
{
2018-01-28 21:51:21 +00:00
global $user ;
2020-08-30 00:09:53 +00:00
$row = db :: c () -> query ( 'SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i' , $user -> id , $id ) -> fetch_assoc_array ();
$bat = db :: c () -> query ( 'SELECT * FROM `battle` WHERE `id` = ?i' , $user -> battle ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
$all_magic = unserialize ( $bat [ 'magic' ]);
$charge = 0 ;
2020-06-23 19:10:00 +00:00
$magic = db :: c () -> query ( 'SELECT * FROM `magic` WHERE `id` = ?i' , $row [ 'magic' ]) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
if ( $magic [ 'needcharge' ] > 0 ) {
$charge = $magic [ 'needcharge' ];
}
2020-06-23 19:10:00 +00:00
$incmagic = db :: c () -> query ( 'SELECT * FROM `magic` WHERE `id` = ?i' , $row [ 'includemagic' ]) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
if ( $incmagic [ 'needcharge' ] > 0 ) {
$charge = $incmagic [ 'needcharge' ];
}
2020-10-30 00:33:02 +00:00
//Переделать под новую базу
2020-08-30 00:09:53 +00:00
if (( $all_magic [ $user -> id ] < 1 || $charge == 0 ) &&
( $user [ 'sila' ] >= $row [ 'nsila' ] &&
$user [ 'lovk' ] >= $row [ 'nlovk' ] &&
$user [ 'inta' ] >= $row [ 'ninta' ] &&
$user [ 'vinos' ] >= $row [ 'nvinos' ] &&
$user [ 'intel' ] >= $row [ 'nintel' ] &&
$user [ 'level' ] >= $row [ 'nlevel' ] &&
2020-06-23 20:24:15 +00:00
(( $user [ 'align' ] > 7 && $user [ 'align' ] < 8 ) || (( int ) $user [ 'align' ] == ( int ) $row [ 'nalign' ]) || ( $row [ 'nalign' ] == 0 )) &&
2020-08-30 00:09:53 +00:00
$user [ 'noj' ] >= $row [ 'nnoj' ] &&
$user [ 'topor' ] >= $row [ 'ntopor' ] &&
$user [ 'dubina' ] >= $row [ 'ndubina' ] &&
$user [ 'mec' ] >= $row [ 'nmech' ] &&
2020-06-23 20:24:15 +00:00
( $row [ 'type' ] < 13 || $row [ 'type' ] == 50 ) && ( $user [ 'mfire' ] >= $row [ 'nfire' ]) &&
2020-08-30 00:09:53 +00:00
$user [ 'mwater' ] >= $row [ 'nwater' ] &&
$user [ 'mair' ] >= $row [ 'nair' ] &&
$user [ 'mearth' ] >= $row [ 'nearth' ] &&
$user [ 'mlight' ] >= $row [ 'nlight' ] &&
$user [ 'mgray' ] >= $row [ 'ngray' ] &&
$user [ 'mdark' ] >= $row [ 'ndark' ] &&
$row [ 'needident' ] == 0
2020-06-23 20:24:15 +00:00
) || $row [ 'magic' ] == 48 || $row [ 'magic' ] == 50 ) {
if ( ! $row [ 'magic' ]) {
$incmagic [ 'name' ] = $row [ 'includemagicname' ];
$incmagic [ 'cur' ] = $row [ 'includemagicdex' ];
$incmagic [ 'max' ] = $row [ 'includemagicmax' ];
if ( $incmagic [ 'cur' ] <= 0 ) {
return false ;
2018-01-28 16:40:49 +00:00
}
2020-06-23 20:24:15 +00:00
$magic [ 'targeted' ] = $incmagic [ 'targeted' ];
echo " <span class='error'> " ;
include ( " magic/ " . $incmagic [ 'file' ]);
echo " </span> " ;
} else {
echo " <span class='error'> " ;
include ( " magic/ " . $magic [ 'file' ]);
echo " </span> " ;
}
if ( $bat ) {
if ( $row [ 'maxdur' ] <= ( $row [ 'duration' ] + 1 )) {
destructitem ( $row [ 'id' ]);
} else {
if ( ! $row [ 'magic' ]) {
db :: c () -> query ( 'UPDATE `inventory` SET `includemagicdex` =`includemagicdex` - ?i WHERE id = ?i' , $bat , $row [ 'id' ]);
2018-01-28 16:40:49 +00:00
} else {
2020-06-23 20:24:15 +00:00
db :: c () -> query ( 'UPDATE `inventory` SET duration = duration + ?i WHERE id = ?i' , $bat , $row [ 'id' ]);
2018-01-28 16:40:49 +00:00
}
}
2020-06-23 20:24:15 +00:00
if ( ! $charge ) {
$charge = 0 ;
}
//ограничение по кол-ву за ход
2020-08-30 00:09:53 +00:00
if ( $user -> battle > 0 ) {
$bat = db :: c () -> query ( 'SELECT * FROM `battle` WHERE `id` = ?i' , $user -> battle ) -> fetch_assoc_array ();
2020-06-23 20:24:15 +00:00
}
if ( $bat [ 'magic' ] == '' ) {
$all_magic = [];
} else {
$all_magic = unserialize ( $bat [ 'magic' ]);
}
2020-08-30 00:09:53 +00:00
$all_magic [ $user -> id ] += $charge ;
db :: c () -> query ( 'UPDATE `battle` SET `magic`= "?s" WHERE id = ?i' , serialize ( $all_magic ), $user -> battle );
2018-01-28 16:40:49 +00:00
}
2020-06-23 19:10:00 +00:00
}
2020-06-23 20:24:15 +00:00
return false ;
2018-01-28 16:40:49 +00:00
}
function addch ( $text , $room = 0 )
{
global $user ;
if ( $room == 0 ) {
2020-08-30 00:09:53 +00:00
$room = $user -> room ;
2018-01-28 16:40:49 +00:00
}
if ( $fp = @ fopen ( " tmp/chat.txt " , " a " )) { //открытие
flock ( $fp , LOCK_EX ); //БЛОКИРОВКА ФАЙЛА
fputs ( $fp , " :[ " . time () . " ]:[!sys!!]:[ " . ( $text ) . " ]:[ " . $room . " ] \r \n " ); //работа с файлом
fflush ( $fp ); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock ( $fp , LOCK_UN ); //СНЯТИЕ БЛОКИРОВКИ
fclose ( $fp ); //закрытие
}
}
function addchp ( $text , $who , $room = 0 )
{
global $user ;
if ( $room == 0 ) {
2020-08-30 00:09:53 +00:00
$room = $user -> room ;
2018-01-28 16:40:49 +00:00
}
$fp = fopen ( " tmp/chat.txt " , " a " ); //открытие
flock ( $fp , LOCK_EX ); //БЛОКИРОВКА ФАЙЛА
fputs ( $fp , " :[ " . time () . " ]:[ { $who } ]:[ " . ( $text ) . " ]:[ " . $room . " ] \r \n " ); //работа с файлом
fflush ( $fp ); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock ( $fp , LOCK_UN ); //СНЯТИЕ БЛОКИРОВКИ
fclose ( $fp ); //закрытие
}
2018-11-05 20:54:18 +00:00
/**
2018-12-10 23:52:46 +00:00
* @ param $msg
2018-12-27 14:46:00 +00:00
*
2018-12-10 23:52:46 +00:00
* @ throws \Krugozor\Database\Mysql\Exception
2018-11-05 20:54:18 +00:00
* Отправка системного сообщения в чат .
2018-12-10 23:52:46 +00:00
*/
function AddChatSystem ( $msg )
2018-01-28 16:40:49 +00:00
{
2020-06-23 20:24:15 +00:00
if ( $msg ) {
db :: c () -> query ( 'INSERT INTO `chat` (`cid`,`msg`,`type`) VALUES (?i,"?s","?s")' , 1 , $msg , 'sys' );
}
2018-01-28 16:40:49 +00:00
}
function err ( $t )
{
2020-06-23 09:24:37 +00:00
echo '<span class="error">' . $t . '</span>' ;
2018-03-03 11:50:13 +00:00
return true ;
2018-01-28 16:40:49 +00:00
}
2020-06-23 15:13:20 +00:00
2019-02-15 22:03:02 +00:00
/**
* @ param $name
* @ param $text
2019-09-17 14:37:44 +00:00
*
2019-02-15 22:03:02 +00:00
* @ throws \Krugozor\Database\Mysql\Exception
*/
function telegraph ( $userId , $text )
{
db :: c () -> query ( 'SELECT 1 FROM `users` WHERE `id` = ?i' , $userId ) -> fetch_assoc ();
2020-06-23 20:24:15 +00:00
if ( db :: c () -> getAffectedRows ()) {
db :: c () -> query ( 'INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")' , $userId , $text );
}
2018-01-28 16:40:49 +00:00
}
function get_meshok ()
{
global $user ;
2020-10-26 22:13:07 +00:00
$itemsWeight = db :: c () -> query ( 'SELECT SUM(weight) AS all_weight FROM `inventory` WHERE owner_id = ?i AND on_sale = 0' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
return ( $user -> strength * 4 + $itemsWeight [ 'all_weight' ]);
2018-01-28 16:40:49 +00:00
}
2018-12-12 12:35:08 +00:00
/**
* Надеюсь временная заглушка , которая объединяет get_meshok () и другую выдачу одной строкой .
* @ return string
*/
function getItemsMassaInfo ()
{
2018-12-27 14:46:00 +00:00
$i_row = db :: c () -> query ( 'SELECT SUM(`massa`) AS `massa`, SUM(`gmeshok`) AS `massa_bonus` FROM `inventory` WHERE `setsale` = 0 AND `owner` = ?i' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2018-12-12 12:35:08 +00:00
$u_row = db :: c () -> query ( 'SELECT `sila` FROM `users` WHERE `id` = ?i' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2020-06-23 20:24:15 +00:00
if ( $i_row [ 'massa' ] > $u_row [ 'sila' ] * 4 + $i_row [ 'massa_bonus' ]) {
2018-12-27 14:46:00 +00:00
return " <span style='color:maroon;'> " . $i_row [ 'massa' ] . " </span>/ " . ( $u_row [ 'sila' ] * 4 + $i_row [ 'massa_bonus' ]);
2020-06-23 20:24:15 +00:00
} else {
return $i_row [ 'massa' ] . " / " . ( $u_row [ 'sila' ] * 4 + $i_row [ 'massa_bonus' ]);
}
2018-12-12 12:35:08 +00:00
}
2018-01-28 16:40:49 +00:00
function addlog ( $id , $log )
{
$fp = fopen ( " backup/logs/battle " . $id . " .txt " , " a " );
flock ( $fp , LOCK_EX );
fputs ( $fp , $log );
fflush ( $fp );
flock ( $fp , LOCK_UN );
fclose ( $fp );
unset ( $id , $log );
}
2020-07-03 15:36:06 +00:00
function star_sign ( $date )
2018-01-28 16:40:49 +00:00
{
2020-07-03 15:36:06 +00:00
/*
* 1 aries
* 2 taurus
* 3 gemini
* 4 cancer
* 5 leo
* 6 virgo
* 7 libra
* 8 scorpio
* 9 sagittarios
* 10 capricorn
* 11 aquarius
* 12 pisches
*/
$zodiac [ 356 ] = " 10 " ;
$zodiac [ 326 ] = " 09 " ;
$zodiac [ 296 ] = " 08 " ;
$zodiac [ 266 ] = " 07 " ;
$zodiac [ 235 ] = " 06 " ;
$zodiac [ 203 ] = " 05 " ;
$zodiac [ 172 ] = " 04 " ;
$zodiac [ 140 ] = " 03 " ;
$zodiac [ 111 ] = " 02 " ;
$zodiac [ 78 ] = " 01 " ;
$zodiac [ 51 ] = " 12 " ;
$zodiac [ 20 ] = " 11 " ;
$zodiac [ 0 ] = " 10 " ;
2020-07-03 15:56:44 +00:00
$dayOfYear = date ( " z " , strtotime ( $date ));
$isLeapYear = date ( " L " , strtotime ( $date )); //Высокосный?
2020-08-30 00:09:53 +00:00
if ( $isLeapYear && $dayOfYear > 59 ) {
2020-07-03 15:46:11 +00:00
-- $dayOfYear ;
2020-07-03 15:36:06 +00:00
}
foreach ( $zodiac as $day => $sign ) {
2020-07-03 15:46:11 +00:00
if ( $dayOfYear > $day ) {
break ;
}
2018-12-27 14:46:00 +00:00
}
2020-07-03 15:36:06 +00:00
return $sign ;
2018-01-28 16:40:49 +00:00
}
function SolveExp ( $at_id , $def_id , $damage )
{
2018-02-27 02:48:51 +00:00
$mods = [ 'bloodb' => 1.2 , 'btl_1' => 1 , 'btl_2' => 0.5 , 'btl_3' => 0.05 ];
$baseexp = [ " 0 " => " 2 " , " 1 " => " 5 " , " 2 " => " 10 " , " 3 " => " 15 " , " 4 " => " 30 " , " 5 " => " 60 " , " 6 " => " 90 " , " 7 " => " 115 " , " 8 " => " 300 " , " 9 " => " 400 " , " 10 " => " 500 " , " 11 " => " 600 " , " 12 " => " 700 " , " 13 " => " 800 " , " 14 " => " 900 " , " 15 " => " 1000 " , " 16 " => " 1100 " , " 17 " => " 1200 " , " 18 " => " 1300 " , " 19 " => " 1400 " , " 20 " => " 1500 " , " 21 " => " 1600 " ];
2018-12-10 20:16:42 +00:00
$expmf = 0 ;
$bot_active = false ;
$bot_def = false ;
2018-01-28 16:40:49 +00:00
if ( $at_id > _BOTSEPARATOR_ ) {
2020-06-23 19:10:00 +00:00
$bots = db :: c () -> query ( 'SELECT * FROM bots WHERE id = ?i' , $at_id ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
$at_id = $bots [ 'prototype' ];
$bot_active = true ;
}
2018-02-27 02:48:51 +00:00
$at = db :: c () -> query ( 'SELECT `level` FROM `users` WHERE `id` = ?i' , $at_id ) -> fetch_assoc ();
$def = db :: c () -> query ( 'SELECT `level` FROM `users` WHERE `id` = ?i' , $def_id ) -> fetch_assoc ();
2020-06-23 19:10:00 +00:00
$at_cost = db :: c () -> query ( 'SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i' , $at_id ) -> fetch_assoc_array ();
$def_cost = db :: c () -> query ( 'SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i' , $def_id ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
if ( $at_id > _BOTSEPARATOR_ ) {
2020-06-23 19:10:00 +00:00
$table_name = 'bots' ;
2018-01-28 16:40:49 +00:00
} else {
2020-06-23 19:10:00 +00:00
$table_name = 'users' ;
2018-01-28 16:40:49 +00:00
}
2020-06-23 19:10:00 +00:00
$bat_raw = db :: c () -> query ( 'SELECT battle FROM ?f WHERE id = ?i' , $table_name , $at_id ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
$bat = $bat_raw [ 'battle' ];
2018-02-27 02:48:51 +00:00
$bt = db :: c () -> query ( 'SELECT `blood`,`type`,`t1`,`t2` FROM `battle` WHERE `id` = ?i' , $bat ) -> fetch_assoc ();
2018-01-28 16:40:49 +00:00
if ( $def_id > _BOTSEPARATOR_ ) {
2020-06-23 19:10:00 +00:00
$bots = db :: c () -> query ( 'SELECT * FROM bots WHERE id = ?i' , $def_id ) -> fetch_assoc_array ();
2018-01-28 16:40:49 +00:00
$def_id = $bots [ 'prototype' ];
$bot_def = true ;
}
if ( $bt [ 'blood' ]) {
2018-02-27 02:48:51 +00:00
$expmf = $mods [ 'bloodb' ];
2018-01-28 16:40:49 +00:00
}
$filebtl = '/tmp/' . $at_id . '.btl' ;
if ( $bt [ 'type' ] == 1 && file_exists ( $filebtl )) {
$btfl = fopen ( $filebtl , 'r' );
$contents = fread ( $btfl , filesize ( $filebtl ));
fclose ( $btfl );
$cnt = substr_count ( $contents , $def_id );
$exmod = 1 ;
if ( $cnt <= 1 ) {
$exmod = $mods [ 'btl_1' ];
} elseif ( $cnt == 2 ) {
$exmod = $mods [ 'btl_2' ];
} elseif ( $cnt > 2 ) {
$exmod = $mods [ 'btl_3' ];
}
$expmf = $expmf * $exmod ;
}
2018-02-27 02:48:51 +00:00
$standart = [
" 0 " => 1 ,
" 1 " => 1 ,
" 2 " => 15 ,
" 3 " => 111 ,
" 4 " => 265 ,
" 5 " => 526 ,
" 6 " => 882 ,
" 7 " => 919 ,
" 8 " => 919 ,
" 9 " => 919 ,
" 10 " => 919 ,
" 11 " => 919 ,
" 12 " => 919 ,
" 13 " => 919 , " 14 " => 919 , " 15 " => 919 , " 16 " => 919 , " 17 " => 919 , " 18 " => 919 , " 19 " => 919 , " 20 " => 919 , " 21 " => 919 , " 22 " => 919 , " 23 " => 919 , " 24 " => 919 , " 25 " => 919 ];
2018-01-28 16:40:49 +00:00
$mfit = ( $at_cost [ 0 ] / ( $standart [ $at [ 'level' ]] / 3 ));
if ( $mfit < 0.8 ) {
$mfit = 0.8 ;
}
if ( $mfit > 1.5 ) {
$mfit = 1.5 ;
}
$pls = count ( explode ( " ; " , $bt [ 't1' ])) + count ( explode ( " ; " , $bt [ 't2' ]));
if ( $pls > 2 ) {
2020-06-23 20:24:15 +00:00
$mfbot = $bot_active ? 0.3 : 1 ;
$mfbot2 = $bot_def ? 0.7 : 1 ;
2018-01-28 16:40:49 +00:00
} else {
$mfbot = 1 ;
$mfbot2 = 1 ;
}
if ( $expmf == 0 ) {
$expmf = 1 ;
}
2020-06-23 20:24:15 +00:00
return round ((( $baseexp [ $def [ 'level' ]]) * ( $def_cost [ 0 ] / (( $at_cost [ 0 ] + $def_cost [ 0 ]) / 2 )) * ( $damage / $def [ 'maxhp' ]) * $expmf * $mfit * $mfbot * $mfbot2 ) / 3 , 0 );
2018-12-11 10:58:32 +00:00
}
2018-12-11 19:21:49 +00:00
/**
* Апаем стат или мастерство на единицу .
2018-12-27 14:46:00 +00:00
*
2019-09-17 14:37:44 +00:00
* @ param $name - техническое имя параметра , как в базе .
2018-12-11 19:21:49 +00:00
* @ param null $param - выбор что повышать .
2018-12-27 14:46:00 +00:00
*
2018-12-11 20:17:19 +00:00
* @ return void
2018-12-11 19:21:49 +00:00
*/
function addOnePoint ( $name , $param = null )
{
2018-12-11 20:17:19 +00:00
$allowed_stats = [ 'sila' , 'lovk' , 'inta' , 'vinos' , 'intel' , 'mudra' ];
$allowed_mastery = [ 'noj' , 'mec' , 'dubina' , 'topor' , 'mfire' , 'mwater' , 'mair' , 'mearth' , 'mlight' , 'mgray' , 'mdark' ];
$naming = [
'sila' => 'Сила' ,
'lovk' => 'Ловкость' ,
'inta' => 'Интуиция' ,
'vinos' => 'Выносливость' ,
'intel' => 'Интеллект' ,
'mudra' => 'Мудрость' ,
'noj' => 'Владение кинжалами' ,
'mec' => 'Владение мечами' ,
'dubina' => 'Владение дубинами' ,
'topor' => 'Владение топорами' ,
'mfire' => 'Магия огня' ,
'mwater' => 'Магия воды' ,
'mair' => 'Магия воздуха' ,
'mearth' => 'Магия земли' ,
'mlight' => 'Магия света' ,
'mgray' => 'Магия серости' ,
2020-06-23 16:57:16 +00:00
'mdark' => 'Магия тьмы' ,
2018-12-11 20:17:19 +00:00
];
2020-06-23 20:24:15 +00:00
if ( $param == 'stat' && in_array ( $name , $allowed_stats )) {
2018-12-11 19:21:49 +00:00
db :: c () -> query ( 'UPDATE `users` SET ?f = ?f + 1, `stats` = `stats` - 1 WHERE `id` = ?i' , $name , $name , $_SESSION [ 'uid' ]);
2018-12-11 20:33:20 +00:00
echo " <span style='color:darkgreen'>Параметр { $naming [ $name ] } увеличен на 1 ед.</span> " ;
2020-06-23 20:24:15 +00:00
} elseif ( $param == 'mastery' && in_array ( $name , $allowed_mastery )) {
2018-12-11 20:17:19 +00:00
$mastery_level = db :: c () -> query ( 'SELECT ?f FROM `users` WHERE `id` = ?i' , $name , $_SESSION [ 'uid' ]) -> fetch_assoc ();
if ( $mastery_level [ $name ] < 10 ) {
2018-12-11 21:06:04 +00:00
db :: c () -> query ( 'UPDATE `users` SET ?f = ?f + 1, `master` = `master` - 1 WHERE `id` = ?i' , $name , $name , $_SESSION [ 'uid' ]);
2018-12-11 20:33:20 +00:00
echo " <span style='color:darkgreen'>Параметр { $naming [ $name ] } увеличен на 1 ед.</span> " ;
2020-06-23 20:24:15 +00:00
} else {
echo " <span style='color: maroon;'>Ошибка: параметр достиг максимального значения!</span> " ;
}
} else {
return null ;
}
2019-02-15 13:26:42 +00:00
}
2020-06-23 20:24:15 +00:00
function checkIntInRange ( $int , $min = 1 , $max = PHP_INT_MAX )
{
2019-09-17 14:37:44 +00:00
return ( int ) filter_var ( $int , FILTER_VALIDATE_INT , [ 'options' => [ 'min_range' => $min , 'max_range' => $max ]]);
2020-06-23 15:13:20 +00:00
}