2022-12-19 20:22:19 +00:00
< ? php
2023-08-10 14:51:16 +00:00
use Core\Db ;
2023-12-01 21:27:45 +00:00
use Helper\Conversion ;
2023-04-15 22:54:07 +00:00
use User\ItemsModel ;
2022-12-19 20:22:19 +00:00
class Quests
{
private $free_x = 28 ;
2023-01-10 16:29:32 +00:00
/* Проверка доступности квеста */
2022-12-19 20:22:19 +00:00
public function testGood ( $pl )
{
global $u ;
if ( ! is_array ( $pl )) {
$pl = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `quests` WHERE `id` = "' . $pl . '" LIMIT 1' ));
}
$r = 1 ;
$d1 = 0 ;
$sp1 = mysql_fetch_array ( mysql_query ( 'SELECT COUNT(`id`) FROM `actions` WHERE `vars` LIKE "%start_quest%" AND `vals` = "go" AND `uid` = "' . $u -> info [ 'id' ] . '" LIMIT 100' ));
$pl1 = $pl1 [ 0 ];
2023-01-10 16:29:32 +00:00
//Если уже более 5 квестов взяли
2022-12-19 20:22:19 +00:00
if ( $d1 >= $this -> free_x ) {
$r = 0 ;
}
unset ( $d1 , $pl1 , $sp1 );
2023-01-10 16:29:32 +00:00
//Если квест уже взяли
2022-12-19 20:22:19 +00:00
$qlst = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`vals` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" ORDER BY `id` DESC LIMIT 1' ));
if ( isset ( $qlst [ 'id' ]) && $qlst [ 'vals' ] != 'win' && $qlst [ 'vals' ] != 'end' && $qlst [ 'vals' ] != 'bad' ) {
$r = 0 ;
}
unset ( $qlst , $qlst2 );
$d = $this -> expl ( $pl [ 'tr_date' ]);
2023-01-10 16:29:32 +00:00
//Завершить квесты [ 1,2,3,4,5 ...
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_endq' ])) {
$i = 0 ;
$e = explode ( ',' , $d [ 'tr_endq' ]);
while ( $i < count ( $e )) {
$qlst = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`vals` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $e [ $i ] . '" AND `vals` = "win" ORDER BY `id` DESC LIMIT 1' ));
if ( ! isset ( $qlst [ 'id' ])) {
$r = 0 ;
}
$i ++ ;
}
unset ( $qn , $qlst , $qlst2 );
}
2023-01-10 16:29:32 +00:00
//Задержка между выполнением квеста
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_zdr' ])) {
$qlst = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` != "go" ORDER BY `time` DESC LIMIT 1' ));
if ( $qlst [ 'time' ] + ( $d [ 'tr_zdr' ] * 60 * 60 ) - time () > 0 ) {
$r = 0 ;
}
unset ( $qlst );
}
2023-01-10 16:29:32 +00:00
//Переодичность квеста
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_tm1' ])) {
$d [ 'tr_tm1' ] = str_replace ( 'd' , date ( 'd' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm1' ] = str_replace ( 'm' , date ( 'm' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm1' ] = str_replace ( 'y' , date ( 'y' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm2' ] = str_replace ( 'd' , date ( 'd' ), $d [ 'tr_tm2' ]);
$d [ 'tr_tm2' ] = str_replace ( 'm' , date ( 'm' ), $d [ 'tr_tm2' ]);
$d [ 'tr_tm2' ] = str_replace ( 'y' , date ( 'y' ), $d [ 'tr_tm2' ]);
2023-01-10 16:29:32 +00:00
//проверка интервалов
2022-12-19 20:22:19 +00:00
}
2023-01-10 16:29:32 +00:00
//Сколько раз можно пройти квест
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_raz' ])) {
$qlst = $u -> testAction ( 'SELECT `id` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" LIMIT ' . $d [ 'tr_raz' ], 2 );
if ( $d [ 'tr_raz' ] > 0 && $d [ 'tr_raz' ] - $qlst [ 0 ] <= 0 ) {
$r = 0 ;
}
unset ( $qlst );
}
2023-01-10 16:29:32 +00:00
//Попыток пройти квест
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_raz2' ])) {
$qlst = $u -> testAction ( 'SELECT `id` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` != "go" AND `vals` != "win" LIMIT ' . $d [ 'tr_raz2' ], 2 );
if ( $d [ 'tr_raz2' ] - $qlst [ 0 ] <= 0 ) {
$r = 0 ;
}
unset ( $qlst );
}
return $r ;
}
2023-08-10 14:51:16 +00:00
private function expl ( $d )
{
$i = 0 ;
$dr = [];
$e = explode ( ':|:' , $d );
while ( $i < count ( $e )) {
$t = explode ( ':=:' , $e [ $i ]);
if ( isset ( $t [ 0 ])) {
$dr [ $t [ 0 ]] = $t [ 1 ];
}
$i ++ ;
}
return $dr ;
}
/* Взять квест */
2022-12-19 20:22:19 +00:00
public function onlyOnceQuest ( $quests , $uid )
2023-01-10 16:29:32 +00:00
{ // Отсеиваем одноразовые квесты
2022-12-19 20:22:19 +00:00
$result = [];
$rep = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `rep` WHERE `id` = "' . $uid ));
foreach ( $quests as $quest ) {
$ok = true ;
$t = $this -> expl ( $quest [ 'tr_date' ]);
if ( isset ( $t [ 'only_once' ]) && $t [ 'only_once' ] == " 1 " ) {
$ins = mysql_fetch_array ( mysql_query ( 'SELECT COUNT(`id`) as sum FROM `actions` WHERE `uid` = "' . $uid . '" AND `vars` = "start_quest' . $quest [ 'id' ] . '" AND (`vals` = "go" OR `vals` = "end")' ));
} else {
$ins = mysql_fetch_array ( mysql_query ( 'SELECT COUNT(`id`) as sum FROM `actions` WHERE `uid` = "' . $uid . '" AND `vars` = "start_quest' . $quest [ 'id' ] . '" AND `vals` = "go" ' ));
if ( $ins [ 'sum' ] > 0 ) {
$ins [ 'sum' ] = 'delete' ;
}
}
if ( $ins [ 'sum' ] == 'delete' ) {
$ok = false ;
} elseif (
isset ( $ins ) &&
$ins [ 'sum' ] >= 1 &&
$rep [ 'rep' . $quest [ 'city' ]] < 10000
) {
$ok = false ;
} elseif (
isset ( $ins ) &&
$ins [ 'sum' ] >= 2 &&
$rep [ 'rep' . $quest [ 'city' ]] <= 24999 &&
$rep [ 'rep' . $quest [ 'city' ]] >= 10000 ) {
$ok = false ;
} else {
$result [] = $quest ;
}
unset ( $ins , $t , $ok );
}
return $result ;
}
2023-08-10 14:51:16 +00:00
/* Взять квест в пещере */
2022-12-19 20:22:19 +00:00
public function startq ( $id , $val = null )
{
global $c , $u ;
$pl = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `quests` WHERE (`city` = "" OR `city` = "' . $u -> info [ 'city' ] . '") AND `delete` = "0" AND `min_lvl` <= ' . $u -> info [ 'level' ] . ' AND `max_lvl` >= ' . $u -> info [ 'level' ] . ' AND (`align` = "0" OR `align` = "' . floor ( $u -> info [ 'align' ]) . '") AND `id` = "' . mysql_real_escape_string ( $id ) . '" LIMIT 1' ));
if ( isset ( $pl [ 'id' ])) {
$u -> addAction ( time (), 'start_quest' . $pl [ 'id' ], 'go' , null , $val );
2023-01-10 16:29:32 +00:00
$u -> error = 'Вы успешно получили задание "' . $pl [ 'name' ] . '"' ;
2022-12-19 20:22:19 +00:00
} else {
2023-01-10 16:29:32 +00:00
$u -> error = 'Н е удалось получить данное задание' ;
2022-12-19 20:22:19 +00:00
}
}
2023-08-10 14:51:16 +00:00
/* Отказаться от квеста */
2022-12-19 20:22:19 +00:00
public function startq_dn ( $id , $val = null )
{
global $c , $u ;
$pl = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `quests` WHERE `delete` = "0" AND `min_lvl` <= ' . $u -> info [ 'level' ] . ' AND `max_lvl` >= ' . $u -> info [ 'level' ] . ' AND (`align` = "0" OR `align` = "' . floor ( $u -> info [ 'align' ]) . '") AND `id` = "' . mysql_real_escape_string ( $id ) . '" LIMIT 1' ));
if ( isset ( $pl [ 'id' ])) {
if ( $val == null )
$u -> addAction ( time (), 'start_quest' . $pl [ 'id' ], 'go' );
else
$u -> addAction ( time (), 'start_quest' . $pl [ 'id' ], 'go' , $u -> info [ 'id' ], $val );
2023-01-10 16:29:32 +00:00
$u -> error = 'Вы успешно получили задание "' . $pl [ 'name' ] . '"' ;
2022-12-19 20:22:19 +00:00
} else {
2023-01-10 16:29:32 +00:00
$u -> error = 'Н е удалось получить данное задание' ;
2022-12-19 20:22:19 +00:00
}
}
2023-01-10 16:29:32 +00:00
/* Инфо о квесте в пещерах */
2023-08-10 14:51:16 +00:00
2022-12-19 20:22:19 +00:00
public function infoDng ( $pl )
{
global $u ;
$r = 0 ;
$xrz = 0 ;
$qst = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` = "go" LIMIT 1' ));
2023-01-10 16:29:32 +00:00
//Условия задания которые должны удовлетворять текущим характеристикам
2022-12-19 20:22:19 +00:00
//$d = $this->expl($pl['tr_date']);
2023-01-10 16:29:32 +00:00
//Действия квеста
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'act_date' ]);
2023-01-10 16:29:32 +00:00
//Поговорить с NPS
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'dlg_nps' ])) {
$i7 = 0 ;
$x3 = explode ( ',' , $d [ 'dlg_nps' ]);
while ( $i7 < count ( $x3 )) {
$x4 = explode ( '=' , $x3 [ $i7 ]);
if ( $x4 [ 0 ] > 0 ) {
$r ++ ;
}
$i7 ++ ;
}
unset ( $x1 , $x3 , $x4 , $i7 );
}
2023-01-10 16:29:32 +00:00
//Убить игроков
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_user' ])) {
$r += $d [ 'kill_user' ];
}
2023-01-10 16:29:32 +00:00
//Убить ботов
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_bot' ])) {
$x = '' ;
$ex = explode ( ',' , $d [ 'kill_bot' ]);
$i = 0 ;
while ( $i < count ( $ex )) {
$x2 = 0 ;
$ex2 = explode ( '=' , $ex [ $i ]);
$bot2 = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `test_bot` WHERE `id` = "' . $ex2 [ 0 ] . '" LIMIT 1' ));
if ( isset ( $bot2 [ 'id' ])) {
if ( isset ( $qst [ 'id' ])) {
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $qst [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $ex2 [ 1 ], 2 );
$x2 = 0 + $x2 [ 0 ];
}
if ( isset ( $d [ 'all_kill' ]) && $d [ 'all_kill' ] > 0 ) {
$r = $d [ 'all_kill' ];
} else {
$r += $ex2 [ 1 ];
}
$xrz += $x2 ;
}
$i ++ ;
}
unset ( $x , $ex , $x2 , $bot2 , $ex2 );
}
2023-01-10 16:29:32 +00:00
//Собрать ресурсы
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tk_itm' ])) {
$ex = explode ( ',' , $d [ 'tk_itm' ]);
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' , [( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
$x2 = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
2022-12-19 20:22:19 +00:00
}
$r += $ex2 [ 1 ];
2023-08-10 14:51:16 +00:00
$xrz += $x2 ;
2022-12-19 20:22:19 +00:00
$i ++ ;
}
}
2023-01-10 16:29:32 +00:00
//Собрать трофеи
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tkill_itm' ])) {
$ex = explode ( ',' , $d [ 'tkill_itm' ]);
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where maidin = ? and item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' ,
[ $pl [ 'city' ], ( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
$x2 = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
2022-12-19 20:22:19 +00:00
}
$r += $ex2 [ 1 ];
2023-08-10 14:51:16 +00:00
$xrz += $x2 ;
2022-12-19 20:22:19 +00:00
$i ++ ;
}
}
if ( $r < 1 ) {
$r = '[0/1]' ;
} else {
if ( $xrz < 0 ) {
$xrz = 0 ;
}
if ( $xrz > $r ) {
$xrz = $r ;
}
$r = ' < table style = " display:inline-block; " border = " 0 " cellspacing = " 0 " cellpadding = " 0 " height = " 10 " >< tr >< td valign = " middle " width = " 120 " style = " padding-top:12px " >
2023-01-10 16:29:32 +00:00
< div style = " position:relative; " >< div id = " vhp-1234500000' . $pl['id'] . ' " title = " Выполнение задания " align = " left " class = " seehp " style = " position:absolute; top:-10px; width:120px; height:10px; z-index:12; " > ' . $xrz . ' / ' . $r . ' </ div >
2023-03-31 18:30:14 +00:00
< div title = " Выполнение задания " class = " hpborder " style = " position:absolute; top:-10px; width:120px; height:9px; z-index:13; " >< img src = " //img.new-combats.tech/1x1.gif " height = " 9 " width = " 1 " ></ div >
< div class = " hp_3 senohp " style = " height:9px; width:120px; position:absolute; top:-10px; z-index:11; " id = " lhp-1234500000' . $pl['id'] . ' " >< img src = " //img.new-combats.tech/1x1.gif " height = " 9 " width = " 1 " ></ div >
< div title = " Выполнение задания " class = " hp_none " style = " position:absolute; top:-10px; width:120px; height:10px; z-index:10; " >< img src = " //img.new-combats.tech/1x1.gif " height = " 10 " ></ div >
2023-08-10 14:51:16 +00:00
</ div ></ td ></ tr ></ table >< br >< script > top . startHpRegen ( " main " , - 1234500000 ' . $pl[' id '] . ' , ' . $xrz . ' , ' . $r . ' , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) </ script > ' ;
2022-12-19 20:22:19 +00:00
}
return $r ;
}
2023-01-10 16:29:32 +00:00
/* Информация о квесте */
2022-12-19 20:22:19 +00:00
public function info ( $pl )
{
global $u ;
$r = '' ;
$t = '' ;
$qst = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` = "go" LIMIT 1' ));
2023-01-10 16:29:32 +00:00
//Условия задания которые должны удовлетворять текущим характеристикам
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'tr_date' ]);
2023-01-10 16:29:32 +00:00
//Завершить квесты [ 1,2,3,4,5 ...
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_endq' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'Завершить квесты: ' ;
2022-12-19 20:22:19 +00:00
$i = 0 ;
$e = explode ( ',' , $d [ 'tr_endq' ]);
while ( $i <= count ( $e )) {
if ( $e [ $i ] > 0 ) {
$qn = mysql_fetch_array ( mysql_query ( 'SELECT `name` FROM `quests` WHERE `id` = "' . $e [ $i ] . '" LIMIT 1' ));
if ( isset ( $qn [ 'name' ])) {
$t .= '"' . $qn [ 'name' ] . '", ' ;
}
}
$i ++ ;
}
$t = trim ( $t , ', ' );
$t .= '<br>' ;
unset ( $qn );
}
2023-01-10 16:29:32 +00:00
//Из ботов падают предметы [ idbot-itm1=%,itm2=%|
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_botitm' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'Из ботов выпадают предметы:<ul>' ;
2022-12-19 20:22:19 +00:00
$e = explode ( '|' , $d [ 'tr_botitm' ]);
$i = 0 ;
while ( $i < count ( $e )) {
$j = 0 ;
$e2 = explode ( '-' , $e [ $i ]);
2023-01-10 16:29:32 +00:00
//$e2[0] - id бота
2022-12-19 20:22:19 +00:00
if ( $e2 [ 0 ] > 0 ) {
$qn = mysql_fetch_array ( mysql_query ( 'SELECT `login` FROM `test_bot` WHERE `id` = "' . $e2 [ 0 ] . '" LIMIT 1' ));
2023-01-10 16:29:32 +00:00
$t .= ' • Из "' . $qn [ 'login' ] . '" выпадает: ' ;
2022-12-19 20:22:19 +00:00
} else {
2023-01-10 16:29:32 +00:00
$t .= ' • Из любых ботов выпадает: ' ;
2022-12-19 20:22:19 +00:00
}
2023-01-10 16:29:32 +00:00
//$e2[1] - предметы
2022-12-19 20:22:19 +00:00
$e3 = explode ( ',' , $e2 [ 1 ]);
while ( $j < count ( $e3 )) {
$e4 = explode ( '=' , $e3 [ $j ]);
2023-01-10 16:29:32 +00:00
//$e4[0] - предмет , $e4[1] - шанс
2022-12-19 20:22:19 +00:00
$qi = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`name`,`img` FROM `items_main` WHERE `id` = "' . $e4 [ 0 ] . '" LIMIT 1' ));
2023-03-31 18:30:14 +00:00
$t .= '<img src="//img.new-combats.tech/i/items/' . $qi [ 'img' ] . '" style="max-height:12px"> <a href="items_info.php?id=' . $qi [ 'id' ] . '" target="_blank">' . $qi [ 'name' ] . '</a>, ' ;
2022-12-19 20:22:19 +00:00
$j ++ ;
}
$t = trim ( $t , ', ' );
$i ++ ;
}
$t .= '<br>' ;
unset ( $qn , $qi , $e2 , $e3 , $e4 );
}
2023-01-10 16:29:32 +00:00
//При выйгрыше падают предметы [ type-itm1=%,itm2=%|
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_winitm' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'После победы выпадают предметы:<br>' ;
2022-12-19 20:22:19 +00:00
$e = explode ( '|' , $d [ 'tr_winitm' ]);
$i = 0 ;
while ( $i < count ( $e )) {
$e2 = explode ( '-' , $e [ $i ]);
$t .= ' • ' ;
2023-01-10 16:29:32 +00:00
//$e2[0] - id бота
2022-12-19 20:22:19 +00:00
if ( $e2 [ 0 ] > 0 ) {
2023-01-10 16:29:32 +00:00
$t .= 'Из людей выпадает: ' ;
2022-12-19 20:22:19 +00:00
} else {
2023-01-10 16:29:32 +00:00
$t .= 'Из ботов выпадает: ' ;
2022-12-19 20:22:19 +00:00
}
2023-01-10 16:29:32 +00:00
//$e2[1] - предметы
2022-12-19 20:22:19 +00:00
$j = 0 ;
$e3 = explode ( ',' , $e2 [ 1 ]);
while ( $j < count ( $e3 )) {
$e4 = explode ( '=' , $e3 [ $j ]);
2023-01-10 16:29:32 +00:00
//$e4[0] - предмет , $e4[1] - шанс
2022-12-19 20:22:19 +00:00
$qi = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`name`,`img` FROM `items_main` WHERE `id` = "' . $e4 [ 0 ] . '" LIMIT 1' ));
2023-03-31 18:30:14 +00:00
$t .= '<img src="//img.new-combats.tech/i/items/' . $qi [ 'img' ] . '" style="max-height:12px"> <a href="items_info.php?id=' . $qi [ 'id' ] . '" target="_blank">' . $qi [ 'name' ] . '</a>, ' ;
2022-12-19 20:22:19 +00:00
$j ++ ;
}
$t = trim ( $t , ', ' );
$t .= '<br>' ;
$i ++ ;
}
unset ( $qn , $qi , $e2 , $e3 , $e4 );
}
2023-01-10 16:29:32 +00:00
//Задержка между выполнением квеста
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_zdr' ])) {
$qlst = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` != "go" LIMIT 1' ));
2023-12-01 21:27:45 +00:00
$t .= 'Задержка между выполнением задания: ' . Conversion :: secondsToTimeout ( $d [ 'tr_zdr' ] * 60 * 60 );
2022-12-19 20:22:19 +00:00
if ( $qlst [ 'time' ] + ( $d [ 'tr_zdr' ] * 60 * 60 ) - time () > 0 ) {
2023-12-01 21:27:45 +00:00
$t .= '<small>(Осталось: ' . Conversion :: secondsToTimeout ( $qlst [ 'time' ] + ( $d [ 'tr_zdr' ] * 60 * 60 ) - time ()) . ' ч.)</small>' ;
2022-12-19 20:22:19 +00:00
}
$t .= '<br>' ;
unset ( $qlst );
}
2023-01-10 16:29:32 +00:00
//Переодичность квеста
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_tm1' ])) {
$d [ 'tr_tm1' ] = str_replace ( 'd' , date ( 'd' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm1' ] = str_replace ( 'm' , date ( 'm' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm1' ] = str_replace ( 'y' , date ( 'y' ), $d [ 'tr_tm1' ]);
$d [ 'tr_tm2' ] = str_replace ( 'd' , date ( 'd' ), $d [ 'tr_tm2' ]);
$d [ 'tr_tm2' ] = str_replace ( 'm' , date ( 'm' ), $d [ 'tr_tm2' ]);
$d [ 'tr_tm2' ] = str_replace ( 'y' , date ( 'y' ), $d [ 'tr_tm2' ]);
2023-01-10 16:29:32 +00:00
$t .= 'Период квеста: ' . $d [ 'tr_tm1' ] . ' - ' . $d [ 'tr_tm2' ] . '<br>' ;
2022-12-19 20:22:19 +00:00
}
2023-01-10 16:29:32 +00:00
//Сколько раз можно пройти квест
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_raz' ])) {
if ( $d [ 'tr_raz' ] == - 1 ) {
2023-01-10 16:29:32 +00:00
$t .= 'Сколько еще раз можно выполнить задание: <b><small>бесконечно</small></b><br>' ;
2022-12-19 20:22:19 +00:00
} else {
$qlst = $u -> testAction ( 'SELECT `id` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" LIMIT ' . $d [ 'tr_raz' ], 2 );
2023-01-10 16:29:32 +00:00
$t .= 'Сколько раз можно выполнить задание: ' . ( $d [ 'tr_raz' ] - $qlst [ 0 ]) . '<br>' ;
2022-12-19 20:22:19 +00:00
}
unset ( $qlst );
}
2023-01-10 16:29:32 +00:00
//Попыток пройти квест
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tr_raz2' ])) {
$qlst = $u -> testAction ( 'SELECT `id` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` != "go" AND `vals` != "win" LIMIT ' . $d [ 'tr_raz2' ], 2 );
2023-01-10 16:29:32 +00:00
$t .= 'Осталось попыток выполнить задание: ' . ( $d [ 'tr_raz2' ] - $qlst [ 0 ]) . '<br>' ;
2022-12-19 20:22:19 +00:00
unset ( $qlst );
}
if ( $t != '' ) {
2023-01-10 16:29:32 +00:00
$r .= '<b>Условия задания:</b><br>' . $t . '<br>' ;
2022-12-19 20:22:19 +00:00
$t = '' ;
}
2023-01-10 16:29:32 +00:00
//Награда за квест
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'win_date' ]);
if ( isset ( $d [ 'add_eff' ])) {
$x5 = '' ;
$x3 = explode ( ',' , $d [ 'add_eff' ]);
$x4 = 0 ;
while ( $x4 < count ( $x3 )) {
$x7 = explode ( '=' , $x3 [ $x4 ]);
$x6 = mysql_fetch_array ( mysql_query ( 'SELECT `id2`,`mname`,`img` FROM `eff_main` WHERE `id2` = "' . $x7 [ 0 ] . '" LIMIT 1' ));
if ( isset ( $x6 [ 'id2' ])) {
2023-03-31 18:30:14 +00:00
$x5 .= '<img width="40" height="25" src="//img.new-combats.tech/i/eff/' . $x6 [ 'img' ] . '" title="' . $x6 [ 'mname' ] . '
2023-12-01 21:27:45 +00:00
Время действия : ' . Conversion::secondsToTimeout($x7[1]) . ' " > ';
2022-12-19 20:22:19 +00:00
}
$x4 ++ ;
}
if ( $x5 != '' ) {
$t .= $x5 . '<br>' ;
}
unset ( $x3 , $x4 , $x5 , $x6 , $x7 );
}
if ( isset ( $d [ 'add_rep' ])) {
2024-01-05 22:14:35 +00:00
$t .= 'Репутация ' . $pl [ 'city' ] . ': ' . $d [ 'add_rep' ] . '<br>' ;
2022-12-19 20:22:19 +00:00
}
if ( isset ( $d [ 'add_repizlom' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'Репутация Излом Х а о с а : ' . $d [ 'add_repizlom' ] . '<br>' ;
2022-12-19 20:22:19 +00:00
}
if ( isset ( $d [ 'add_cr' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'Деньги: ' . $d [ 'add_cr' ] . ' кр.<br>' ;
2022-12-19 20:22:19 +00:00
}
if ( $t != '' ) {
2023-01-10 16:29:32 +00:00
$r = '<b>Награда:</b><br>' . $t . '<br>' . $r ;
2022-12-19 20:22:19 +00:00
$t = '' ;
}
2023-01-10 16:29:32 +00:00
//Действия квеста
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'act_date' ]);
2023-01-10 16:29:32 +00:00
//Поговорить с NPS
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'dlg_nps' ])) {
$i7 = 0 ;
$x3 = explode ( ',' , $d [ 'dlg_nps' ]);
while ( $i7 < count ( $x3 )) {
$x4 = explode ( '=' , $x3 [ $i7 ]);
if ( $x4 [ 0 ] > 0 ) {
$x1 = mysql_fetch_array ( mysql_query ( 'SELECT `text` FROM `dungeon_dialog` WHERE `id` = "' . $x4 [ 0 ] . '" LIMIT 1' ));
if ( ! isset ( $x1 [ 'text' ])) {
2023-01-10 16:29:32 +00:00
$x1 = '<i>незивестно</i>' ;
2022-12-19 20:22:19 +00:00
} else {
$x1 = $x1 [ 'text' ];
}
$x = 0 ;
2023-01-10 16:29:32 +00:00
$t .= 'Поговорить с <b>' . $x1 . '</b>: ' . $x . '/1<br>' ;
2022-12-19 20:22:19 +00:00
}
$i7 ++ ;
}
unset ( $x1 , $x3 , $x4 , $i7 );
}
2023-01-10 16:29:32 +00:00
//Убить игроков
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_user' ])) {
2023-01-10 16:29:32 +00:00
$t .= 'Убить игроков: 0/' . $d [ 'kill_user' ] . '<br>' ;
2022-12-19 20:22:19 +00:00
}
2023-01-10 16:29:32 +00:00
//Убить ботов
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_bot' ])) {
if ( isset ( $d [ 'all_kill' ]) && ( int ) $d [ 'all_kill' ] > 0 ) {
$x = '' ;
$ex = explode ( ',' , $d [ 'kill_bot' ]);
2023-01-10 16:29:32 +00:00
$i = 0 ; # Количество циклов для каждого типа бота.
2022-12-19 20:22:19 +00:00
$q = '' ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
if ( $q != '' ) {
$q .= ' OR ' ;
}
$q .= ' (`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $qst [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" )' ;
$i ++ ;
}
$x2 = $u -> testAction ( $q , 2 );
$x2 = $x2 [ 0 ];
if ( $d [ 'all_kill' ] < $x2 ) {
$x2 = $d [ 'all_kill' ];
}
$bot2 = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `test_bot` WHERE `id` = "' . $ex2 [ 0 ] . '" LIMIT 1' ));
if ( isset ( $bot2 [ 'id' ])) {
$x .= ' • <b>' . $bot2 [ 'login' ] . '</b> [' . $x2 . '/' . $d [ 'all_kill' ] . ']<br>' ;
} else {
$x .= ' • <b>' . $pl [ 'name' ] . '</b> [' . $x2 . '/' . $d [ 'all_kill' ] . ']<br>' ;
}
} else {
$i = 0 ;
while ( $i < count ( $ex )) {
$x2 = 0 ;
$ex2 = explode ( '=' , $ex [ $i ]);
$bot2 = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `test_bot` WHERE `id` = "' . $ex2 [ 0 ] . '" LIMIT 1' ));
if ( isset ( $bot2 [ 'id' ])) {
if ( isset ( $qst [ 'id' ])) {
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $qst [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $ex2 [ 1 ], 2 );
$x2 = 0 + $x2 [ 0 ];
}
$x .= ' • <b>' . $bot2 [ 'login' ] . '</b> [' . $x2 . '/' . $ex2 [ 1 ] . ']<br>' ;
}
$i ++ ;
}
}
if ( $x != '' ) {
$x = trim ( $x , ', ' );
2023-01-10 16:29:32 +00:00
$t .= 'Убить ботов: <br>' . $x ;
2022-12-19 20:22:19 +00:00
}
unset ( $x , $ex , $x2 , $bot2 , $ex2 );
}
2023-01-10 16:29:32 +00:00
//Собрать ресурсы
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tk_itm' ])) {
$ex = explode ( ',' , $d [ 'tk_itm' ]);
$i = 0 ;
$x = '' ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' , [( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
$x2 = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
2022-12-19 20:22:19 +00:00
}
$bot2 = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`name`,`img` FROM `items_main` WHERE `id` = "' . mysql_real_escape_string ( $ex2 [ 0 ]) . '" LIMIT 1' ));
2023-08-10 14:51:16 +00:00
$x .= ' • <a target=_blank href=/item/' . $bot2 [ 'id' ] . ' >' . $bot2 [ 'name' ] . '</a> [' . $x2 . '/' . $ex2 [ 1 ] . ']<br>' ;
2022-12-19 20:22:19 +00:00
$i ++ ;
}
if ( $x != '' ) {
$x = trim ( $x , ', ' );
2023-01-10 16:29:32 +00:00
$t .= 'Собрать ресурсы: <br>' . $x ;
2022-12-19 20:22:19 +00:00
}
}
2023-01-10 16:29:32 +00:00
//Собирание трофеев
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tkill_itm' ])) {
$ex = explode ( ',' , $d [ 'tkill_itm' ]);
$i = 0 ;
$x = '' ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where maidin = ? and item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' ,
[ $pl [ 'city' ], ( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
$x2 = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
2022-12-19 20:22:19 +00:00
}
$bot2 = mysql_fetch_array ( mysql_query ( 'SELECT `id`,`name`,`img` FROM `items_main` WHERE `id` = "' . mysql_real_escape_string ( $ex2 [ 0 ]) . '" LIMIT 1' ));
2023-08-10 14:51:16 +00:00
$x .= ' • <a target=_blank href=/item/' . $bot2 [ 'id' ] . ' >' . $bot2 [ 'name' ] . '</a> [' . $x2 . '/' . $ex2 [ 1 ] . ']<br>' ;
2022-12-19 20:22:19 +00:00
$i ++ ;
}
if ( $x != '' ) {
$x = trim ( $x , ', ' );
2023-01-10 16:29:32 +00:00
$t .= 'Собрать трофеи: <br>' . $x ;
2022-12-19 20:22:19 +00:00
}
}
if ( $t != '' ) {
2023-01-10 16:29:32 +00:00
$r = '<br><b>Действия задания:</b><br>' . $t . '<br>' . $r ;
2022-12-19 20:22:19 +00:00
$t = '' ;
}
if ( $r == '' ) {
2023-01-10 16:29:32 +00:00
$r = 'Дополнительная информация по заданию отсутствует' ;
2022-12-19 20:22:19 +00:00
}
return $r ;
}
2024-01-05 22:14:35 +00:00
public function testquest () : void
2022-12-19 20:22:19 +00:00
{
global $u ;
2023-01-10 16:29:32 +00:00
if ( $u -> info [ 'battle' ] == 0 && $u -> room [ 'name' ] != 'Башня Смерти' ) {
2022-12-19 20:22:19 +00:00
$sp = mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` LIKE "%start_quest%" AND `vals` = "go" LIMIT 100' );
while ( $pl2 = mysql_fetch_array ( $sp )) {
$pl = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `quests` WHERE `id` = "' . ( str_replace ( 'start_quest' , '' , $pl2 [ 'vars' ])) . '" LIMIT 1' ));
$g = 1 ;
2023-01-10 16:29:32 +00:00
//Действия квеста
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'act_date' ]);
2023-01-10 16:29:32 +00:00
//Поговорить с NPS
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'dlg_nps' ])) {
$g = 0 ;
unset ( $x );
}
2023-01-10 16:29:32 +00:00
//Убить игроков
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_user' ])) {
$x = 0 ;
if ( $x < $d [ 'kill_user' ]) {
$g = 0 ;
}
2023-01-10 16:29:32 +00:00
//$d['kill_user'] - стольких нужно убить
2022-12-19 20:22:19 +00:00
unset ( $x );
}
2023-01-10 16:29:32 +00:00
//Убить ботов
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_bot' ])) {
$ex = explode ( ',' , $d [ 'kill_bot' ]);
2023-01-10 16:29:32 +00:00
$ii = 0 ; // Количество циклов для каждого типа бота.
2022-12-19 20:22:19 +00:00
$q = '' ;
while ( $ii < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $ii ]);
if ( $q != '' ) {
$q .= ' OR ' ;
}
$q .= ' (`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $pl2 [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" )' ;
$ii ++ ;
}
if ( isset ( $d [ 'all_kill' ]) && $d [ 'all_kill' ] > 0 ) {
$x2 = $u -> testAction ( $q . ' LIMIT ' . $d [ 'all_kill' ], 2 );
if ( $x2 [ 0 ] < $d [ 'all_kill' ]) {
$g = 0 ;
}
} else {
$x2 = $u -> testAction ( $q . ' LIMIT ' . $ex2 [ 1 ], 2 );
if ( ! isset ( $d [ 'all_kill' ]) && $x2 [ 0 ] < $ex2 [ 1 ]) {
$g = 0 ;
}
}
unset ( $x , $ex , $x2 , $x3 , $bot2 , $ex2 );
}
2023-01-10 16:29:32 +00:00
//Собрать ресурсы
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tk_itm' ])) {
$g = $this -> collect_01 ( explode ( ',' , $d [ 'tk_itm' ]), $u );
}
2023-01-10 16:29:32 +00:00
//Собирание трофеев
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tkill_itm' ])) {
$g = $this -> collect_01 ( explode ( ',' , $d [ 'tkill_itm' ]), $u );
}
if ( $g == 1 ) {
$pl [ 'time' ] = $pl2 [ 'time' ];
$this -> endq ( $pl [ 'id' ], 'win' );
$this -> winQuest ( $pl );
echo $pl [ 'name' ];
}
}
}
}
2023-08-10 14:51:16 +00:00
private function collect_01 ( $arr , $u )
{ // убираю дублирование. х е р пойми что проверяем, хз как назвать.
2022-12-19 20:22:19 +00:00
$i = 0 ;
while ( $i < count ( $arr )) {
$ex2 = explode ( '=' , $arr [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' , [( int ) $arr [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 < $ex2 [ 1 ]) {
2022-12-19 20:22:19 +00:00
return 0 ;
}
$i ++ ;
}
return 1 ;
}
2023-08-10 14:51:16 +00:00
public function endq ( $id , $tp )
{
global $u ;
$pl = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `quests` WHERE `delete` = "0" AND `min_lvl` <= ' . $u -> info [ 'level' ] . ' AND `max_lvl` >= ' . $u -> info [ 'level' ] . ' AND (`align` = "0" OR `align` = "' . floor ( $u -> info [ 'align' ]) . '") AND `id` = "' . mysql_real_escape_string ( $id ) . '" LIMIT 1' ));
$qlst = mysql_fetch_array ( mysql_query ( 'SELECT `id` FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" AND `vals` = "go" ORDER BY `id` DESC LIMIT 1' ));
if ( isset ( $qlst [ 'id' ])) {
if ( $tp == 'end' ) {
mysql_query ( 'UPDATE `actions` SET `vals` = "end" WHERE `id` = "' . $qlst [ 'id' ] . '" LIMIT 1' );
$u -> error = 'Вы успешно отказались от задания "' . $pl [ 'name' ] . '"' ;
} elseif ( $tp == 'win' ) {
mysql_query ( 'UPDATE `actions` SET `vals` = "win" ,`time` = "' . time () . '" WHERE `id` = "' . $qlst [ 'id' ] . '" LIMIT 1' );
}
} else {
$u -> error = 'Н е удалось отказаться от задания ' ;
}
}
# Функция отвечает за ПРОВЕРКУ на ЗАВЕРШЕНИЕ квестов для ПОДЗЕМОК
private function winQuest ( $pl )
{
global $u , $c , $magic ;
if ( isset ( $pl [ 'id' ])) {
$d = $this -> expl ( $pl [ 'act_date' ]);
$d = array_merge ( $d , $this -> expl ( $pl [ 'win_date' ]));
if ( $_COOKIE [ 'login' ] == 'R' || $_COOKIE [ 'login' ] == 'r' ) {
echo '<script>alert("' ;
print_r ( str_replace ( " \n " , ' ' , $d ));
echo '");</script>' ;
die ();
}
// Забираем ресурсы
if ( isset ( $d [ 'tk_itm' ])) {
$ex = explode ( ',' , $d [ 'tk_itm' ]);
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
$ex2 = explode ( '=' , $ex [ $i ]);
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $pl2 [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $ex2 [ 1 ], 2 );
ItemsModel :: deleteItemsById ( $ex2 [ 0 ], $ex2 [ 1 ]);
$i ++ ;
2022-12-19 20:22:19 +00:00
}
}
2023-08-10 14:51:16 +00:00
// Забираем трофеи
if ( isset ( $d [ 'tkill_itm' ])) {
$ex = explode ( ',' , $d [ 'tkill_itm' ]);
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
$ex2 = explode ( '=' , $ex [ $i ]);
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $pl2 [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $ex2 [ 1 ], 2 );
ItemsModel :: deleteItemsById ( $ex2 [ 0 ], $ex2 [ 1 ]);
$i ++ ;
}
2022-12-19 20:22:19 +00:00
}
2023-08-10 14:51:16 +00:00
$t = '' ;
if ( isset ( $d [ 'add_rep' ])) { // Получаем репутацию за квест, если это убийства ботов.
if ( isset ( $d [ 'kill_bot' ]) && isset ( $d [ 'all_kill' ]) && $d [ 'add_rep' ] > 0 ) {
$ex = explode ( ',' , $d [ 'kill_bot' ]);
$ii = 0 ;
$d [ 'add_rep' ] = 0 ;
while ( $ii < count ( $ex )) {
$i = 0 ;
$ex2 = explode ( '=' , $ex [ $i ]);
while ( $i < $d [ 'all_kill' ]) {
$x2 = 0 ;
$d [ 'add_rep' ] = $d [ 'add_rep' ] + $ex2 [ 1 ];
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $pl2 [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $d [ 'all_kill' ], 2 );
$i ++ ;
}
$ii ++ ;
}
}
unset ( $x , $i , $ii , $ex , $x2 , $bot2 , $ex2 );
if ( $pl [ 'city' ] != '' ) {
2024-01-05 22:14:35 +00:00
$t .= '' . $d [ 'add_rep' ] . ' ед. репутации ' . $pl [ 'city' ] . ', ' ;
2023-08-10 14:51:16 +00:00
$rep = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `rep` WHERE `id` = "' . $u -> info [ 'id' ] . '" LIMIT 1' ));
2024-01-05 22:14:35 +00:00
2023-08-10 14:51:16 +00:00
if ( $rep [ 'rep' . $pl [ 'city' ]] < 24999 && $rep [ 'rep' . $pl [ 'city' ]] + $d [ 'add_rep' ] >= 24999 && $pl [ 'kin' ] != 2 ) {
$rep [ 'rep' . $pl [ 'city' ]] = 24999 ;
} else {
$rep [ 'rep' . $pl [ 'city' ]] += $d [ 'add_rep' ];
}
mysql_query ( 'UPDATE `rep` SET `rep' . $pl [ 'city' ] . '` = "' . $rep [ 'rep' . $pl [ 'city' ]] . '" WHERE `id` = "' . $rep [ 'id' ] . '" LIMIT 1' );
}
}
if ( isset ( $d [ 'add_repizlom' ])) {
$t .= '' . $d [ 'add_repizlom' ] . ' ед. репутации Излома Х а о с а , ' ;
$rep = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `rep` WHERE `id` = "' . $u -> info [ 'id' ] . '" LIMIT 1' ));
$rep [ 'repizlom' ] += $d [ 'add_repizlom' ];
if ( $rep [ 'repizlom' ] > 24999 ) {
$rep [ 'repizlom' ] = 24999 ;
}
mysql_query ( 'UPDATE `rep` SET `repizlom` = "' . $rep [ 'repizlom' ] . '" WHERE `id` = "' . $rep [ 'id' ] . '" LIMIT 1' );
}
if ( isset ( $d [ 'add_eff' ])) {
$i = 0 ;
$j = explode ( '=' , $d [ 'add_eff' ]);
while ( $i < count ( $j )) {
if ( $j [ $i ] > 0 ) {
2023-08-14 13:37:37 +00:00
$magic -> addEffect ( $u -> info [ 'id' ], $j [ $i ], 1 );
2023-08-10 14:51:16 +00:00
}
$i ++ ;
}
}
if ( isset ( $d [ 'add_cr' ])) {
$t .= '' . $d [ 'add_cr' ] . ' кр., ' ;
mysql_query ( 'UPDATE `users` SET `money` = `money`+' . $d [ 'add_cr' ] . ' WHERE `id` = "' . $u -> info [ 'id' ] . '" LIMIT 1' );
}
if ( $t != '' ) {
$t = rtrim ( $t , ', ' );
$r = 'Задание <b>' . $pl [ 'name' ] . '</b> было успешно выполнено! Вы получили награду: ' . $t . '.' ;
unset ( $t );
} else {
$r = 'Задание <b>' . $pl [ 'name' ] . '</b> было успешно выполнено!' ;
}
$r = '<small>' . $r . '</small>' ;
//Отправляем сообщение в чат
$chatDto = new ChatMessage ();
$chatDto -> setCity ( $u -> info [ 'city' ]);
$chatDto -> setRoom ( $u -> info [ 'room' ]);
$chatDto -> setTo ( $u -> info [ 'login' ]);
$chatDto -> setText ( $r );
$chatDto -> setType ( 5 );
( new Chat ()) -> sendMsg ( $chatDto );
2022-12-19 20:22:19 +00:00
}
}
public function questCheckEnd ( $pl )
{
global $u ;
$quest = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `actions` WHERE `uid` = "' . $u -> info [ 'id' ] . '" AND `vars` = "start_quest' . $pl [ 'id' ] . '" ORDER BY `time` DESC LIMIT 1' ));
2023-01-10 16:29:32 +00:00
#Проверяем квест, завершен = 0 нет, 1 да.
2022-12-19 20:22:19 +00:00
$r = 0 ;
2023-01-10 16:29:32 +00:00
if ( $u -> info [ 'battle' ] == 0 && $u -> room [ 'name' ] != 'Башня Смерти' ) {
2022-12-19 20:22:19 +00:00
$g = 1 ;
2023-01-10 16:29:32 +00:00
# Действия квеста
2022-12-19 20:22:19 +00:00
$d = $this -> expl ( $pl [ 'act_date' ]);
2023-01-10 16:29:32 +00:00
# Поговорить с NPS
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'dlg_nps' ])) {
$g = 0 ;
unset ( $x );
}
2023-01-10 16:29:32 +00:00
# Убить игроков
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_user' ])) {
$x = 0 ;
if ( $x < $d [ 'kill_user' ]) {
$g = 0 ;
}
unset ( $x );
}
2023-01-10 16:29:32 +00:00
# Убить ботов
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_bot' ])) {
$ex = explode ( ',' , $d [ 'kill_bot' ]);
2023-01-10 16:29:32 +00:00
$i = 0 ; # Количество циклов для каждого типа бота.
2022-12-19 20:22:19 +00:00
$q = '' ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
if ( $q != '' ) {
$q .= ' OR ' ;
}
$q .= ' (`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $quest [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" )' ;
$i ++ ;
}
if ( isset ( $d [ 'all_kill' ]) && ( int ) $d [ 'all_kill' ] > 0 ) {
$x2 = $u -> testAction ( $q , 2 );
if (( int ) $d [ 'all_kill' ] <= $x2 [ 0 ]) {
$x2 = ( int ) $d [ 'all_kill' ];
} else {
$x2 = $x2 [ 0 ];
}
if ( $x2 < ( int ) $d [ 'all_kill' ]) {
$g = 0 ;
}
} else {
$x2 = $u -> testAction ( $q . ' LIMIT ' . $ex2 [ 1 ], 2 );
$x2 = min ( $ex2 [ 1 ], $x2 [ 0 ]);
if ( $x2 < $ex2 [ 1 ]) {
$g = 0 ;
}
}
unset ( $x , $ex , $x2 , $x3 , $bot2 , $ex2 );
}
2023-01-10 16:29:32 +00:00
# Собрать ресурсы
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tk_itm' ])) {
$g = $this -> collect_02 ( explode ( ',' , $d [ 'tk_itm' ]), $u , $pl );
}
2023-01-10 16:29:32 +00:00
# Собирание трофеев
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tkill_itm' ])) {
$g = $this -> collect_02 ( explode ( ',' , $d [ 'tkill_itm' ]), $u , $pl );
}
$r = $g == 1 ? 1 : 0 ;
}
return $r ;
}
2023-08-10 14:51:16 +00:00
private function collect_02 ( $ex , $u , $pl )
{ // убираю дублирование. х е р пойми что проверяем, хз как назвать.
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
$x2 = Db :: getValue ( 'select count(*) from items_users where maidin = ? and item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' ,
[ $pl [ 'city' ], ( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
if ( $x2 <= ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ))) {
$ex2 [ 1 ] = $x2 ;
} else {
$ex2 [ 1 ] = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
}
}
if ( $x2 < $ex2 [ 1 ]) {
return 0 ;
}
$i ++ ;
}
return 1 ;
}
2023-01-10 16:29:32 +00:00
/** Выдача наград за пещеры */
2022-12-19 20:22:19 +00:00
public function questSuccesEnd ( $quest , $action )
{
global $u , $c , $magic ;
$r = '' ;
if ( ! isset ( $quest [ 'id' ])) {
return '' ;
}
$d = $this -> expl ( $quest [ 'act_date' ]);
$d = array_merge ( $d , $this -> expl ( $quest [ 'win_date' ]));
2023-01-10 16:29:32 +00:00
// Забираем ресурсы или трофеи
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'tk_itm' ]) || isset ( $d [ 'tkill_itm' ])) {
$ex = [];
if ( isset ( $d [ 'tk_itm' ])) {
$ex [ 0 ] = explode ( ',' , $d [ 'tk_itm' ]);
}
if ( isset ( $d [ 'tkill_itm' ])) {
$ex [ 1 ] = explode ( ',' , $d [ 'tkill_itm' ]);
}
$i = 0 ;
while ( $i < count ( $ex )) {
$ex2 = explode ( '=' , $ex [ $i ]);
2023-08-10 14:51:16 +00:00
$x2 = Db :: getValue ( 'select count(*) from items_users where maidin = ? and item_id = ? and uid = ? and `delete` in (0,1000) and inTransfer = 0 and inShop = 0' ,
[ $quest [ 'city' ], ( int ) $ex2 [ 0 ], $u -> info [ 'id' ]]);
if ( $x2 >= $ex2 [ 1 ]) {
if ( $x2 <= ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ))) {
$ex2 [ 1 ] = $x2 ;
2022-12-19 20:22:19 +00:00
} else {
$ex2 [ 1 ] = ( $ex2 [ 1 ] + round ( $ex2 [ 1 ] * 0.15 ));
}
}
$d [ 'add_rep' ] = ( int ) $d [ 'add_rep' ] * ( int ) $ex2 [ 1 ];
2023-04-15 22:54:07 +00:00
ItemsModel :: deleteItemsById ( $ex2 [ 0 ], $ex2 [ 1 ]);
2022-12-19 20:22:19 +00:00
$i ++ ;
}
}
$t = '' ;
2023-01-10 16:29:32 +00:00
# Получаем репутацию за квест,
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'add_rep' ])) {
2023-01-10 16:29:32 +00:00
# если это убийства ботов.
2022-12-19 20:22:19 +00:00
if ( isset ( $d [ 'kill_bot' ]) && isset ( $d [ 'all_kill' ]) && $d [ 'add_rep' ] > 0 ) {
$ex = explode ( ',' , $d [ 'kill_bot' ]);
$ii = 0 ;
if ( $quest [ 'kin' ] == 0 ) {
$d [ 'add_rep' ] = 0 ;
while ( $ii < count ( $ex )) {
$i = 0 ;
$ex2 = explode ( '=' , $ex [ $i ]);
while ( $i < $d [ 'all_kill' ]) {
$x2 = 0 ;
$d [ 'add_rep' ] = $d [ 'add_rep' ] + $ex2 [ 1 ];
$x2 = $u -> testAction ( '`uid` = "' . $u -> info [ 'id' ] . '" AND `time` > ' . $action [ 'time' ] . ' AND `vars` = "win_bot_' . $ex2 [ 0 ] . '" LIMIT ' . $d [ 'all_kill' ], 2 );
$i ++ ;
}
$ii ++ ;
}
} else {
$d [ 'add_rep' ] = 1 ;
}
}
unset ( $x , $i , $ii , $ex , $x2 , $bot2 , $ex2 );
$rep = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `rep` WHERE `id` = ' . $u -> info [ 'id' ]));
if ( $quest [ 'city' ] != '' ) {
if ( $this -> stats [ 'more_awards' ] >= 0 ) {
$d [ 'add_rep' ] += $d [ 'add_rep' ] / 100 * 50 ;
}
2024-01-05 22:14:35 +00:00
$t .= '' . $d [ 'add_rep' ] . ' ед. репутации ' . $quest [ 'city' ] . ', ' ;
2022-12-19 20:22:19 +00:00
if (
$rep [ 'rep' . $quest [ 'city' ]] < 24999 &&
$rep [ 'rep' . $quest [ 'city' ]] + $d [ 'add_rep' ] >= 24999 &&
$quest [ 'kin' ] != 2
) {
$rep [ 'rep' . $quest [ 'city' ]] = 24999 ;
} else {
$rep [ 'rep' . $quest [ 'city' ]] += $d [ 'add_rep' ];
}
mysql_query ( 'UPDATE `rep` SET `rep' . $quest [ 'city' ] . '` = "' . $rep [ 'rep' . $quest [ 'city' ]] . '" WHERE `id` = "' . $rep [ 'id' ] . '" LIMIT 1' );
}
}
if ( isset ( $d [ 'add_repizlom' ])) {
2023-01-10 16:29:32 +00:00
$t .= '' . $d [ 'add_repizlom' ] . ' ед. репутации Излома Х а о с а , ' ;
2022-12-19 20:22:19 +00:00
$rep = mysql_fetch_array ( mysql_query ( 'SELECT * FROM `rep` WHERE `id` = "' . $u -> info [ 'id' ] . '" LIMIT 1' ));
$rep [ 'repizlom' ] += $d [ 'add_repizlom' ];
if ( $rep [ 'repizlom' ] > 24999 ) {
$rep [ 'repizlom' ] = 24999 ;
}
mysql_query ( 'UPDATE `rep` SET `repizlom` = "' . $rep [ 'repizlom' ] . '" WHERE `id` = "' . $rep [ 'id' ] . '" LIMIT 1' );
}
if ( isset ( $d [ 'add_eff' ])) {
$i = 0 ;
$j = explode ( '=' , $d [ 'add_eff' ]);
while ( $i < count ( $j )) {
if ( $j [ $i ] > 0 ) {
2023-08-14 13:37:37 +00:00
$magic -> addEffect ( $u -> info [ 'id' ], $j [ $i ], 1 );
2022-12-19 20:22:19 +00:00
}
$i ++ ;
}
}
if ( isset ( $d [ 'add_cr' ])) {
2023-01-10 16:29:32 +00:00
$t .= '' . $d [ 'add_cr' ] . ' кр., ' ;
2022-12-19 20:22:19 +00:00
mysql_query ( 'UPDATE `users` SET `money` = `money`+' . $d [ 'add_cr' ] . ' WHERE `id` = "' . $u -> info [ 'id' ] . '" LIMIT 1' );
}
if ( $t != '' ) {
$t = rtrim ( $t , ', ' );
2023-01-10 16:29:32 +00:00
$r = 'Задание <b>' . $quest [ 'name' ] . '</b> было успешно выполнено! Вы получили награду: ' . $t . '.' ;
2022-12-19 20:22:19 +00:00
unset ( $t );
} else {
2023-01-10 16:29:32 +00:00
$r = 'Задание <b>' . $quest [ 'name' ] . '</b> было успешно выполнено!' ;
2022-12-19 20:22:19 +00:00
}
$r = '<small>' . $r . '</small>' ;
2023-01-10 16:29:32 +00:00
//Отправляем сообщение в чат
2022-12-19 20:22:19 +00:00
mysql_query ( 'UPDATE `actions` SET `vals` = "win" , `time` = "' . time () . '" WHERE `id` = "' . $action [ 'id' ] . '" AND `vals` = "go" LIMIT 1' );
2023-01-28 02:24:37 +00:00
$chatDto = new ChatMessage ();
$chatDto -> setCity ( $u -> info [ 'city' ]);
$chatDto -> setRoom ( $u -> info [ 'room' ]);
$chatDto -> setTo ( $u -> info [ 'login' ]);
$chatDto -> setText ( $r );
$chatDto -> setType ( 5 );
( new Chat ()) -> sendMsg ( $chatDto );
2022-12-19 20:22:19 +00:00
return $r ;
}
}