info['id'] . '" LIMIT 100')); $pl1 = $pl1[0]; //Если уже более 5 квестов взяли if ($d1 >= $this->free_x) { $r = 0; } unset($d1, $pl1, $sp1); //Если квест уже взяли $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']); //Завершить квесты [ 1,2,3,4,5 ... 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); } //Задержка между выполнением квеста 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); } //Переодичность квеста 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']); //проверка интервалов } //Сколько раз можно пройти квест if (isset($d['tr_raz'])) { $qlst = ActionModel::testCount(["uid = {$u->info['id']}", "vars = start_quest{$pl['id']}"], $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) { $r = 0; } unset($qlst); } //Попыток пройти квест if (isset($d['tr_raz2'])) { $qlst = ActionModel::testCount(["uid = {$u->info['id']}", "vars = start_quest{$pl['id']}", "vals != go", "vals != win"], $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) { $r = 0; } unset($qlst); } return $r; } 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; } /* Взять квест */ public function onlyOnceQuest($quests, $uid) { // Отсеиваем одноразовые квесты $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; } /* Взять квест в пещере */ 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); $u->error = 'Вы успешно получили задание "' . $pl['name'] . '"'; } else { $u->error = 'Не удалось получить данное задание'; } } /* Отказаться от квеста */ 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); $u->error = 'Вы успешно получили задание "' . $pl['name'] . '"'; } else { $u->error = 'Не удалось получить данное задание'; } } /* Инфо о квесте в пещерах */ 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')); //Условия задания которые должны удовлетворять текущим характеристикам //$d = $this->expl($pl['tr_date']); //Действия квеста $d = $this->expl($pl['act_date']); //Поговорить с NPS 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); } //Убить игроков if (isset($d['kill_user'])) { $r += $d['kill_user']; } //Убить ботов 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 = ActionModel::testCount(["uid = {$u->info['id']}", "vars = win_bot_$ex2[0]", "time > {$qst['time']}"], $ex2[1]); } 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); } //Собрать ресурсы if (isset($d['tk_itm'])) { $ex = explode(',', $d['tk_itm']); $i = 0; while ($i < count($ex)) { $ex2 = explode('=', $ex[$i]); $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)); } $r += $ex2[1]; $xrz += $x2; $i++; } } //Собрать трофеи if (isset($d['tkill_itm'])) { $ex = explode(',', $d['tkill_itm']); $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]) { $x2 = ($ex2[1] + round($ex2[1] * 0.15)); } $r += $ex2[1]; $xrz += $x2; $i++; } } if ($r < 1) { $r = '[0/1]'; } else { if ($xrz < 0) { $xrz = 0; } if ($xrz > $r) { $xrz = $r; } $r = '
' . $xrz . '/' . $r . '

'; } return $r; } /* Информация о квесте */ 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')); //Условия задания которые должны удовлетворять текущим характеристикам $d = $this->expl($pl['tr_date']); //Завершить квесты [ 1,2,3,4,5 ... if (isset($d['tr_endq'])) { $t .= 'Завершить квесты: '; $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 .= '
'; unset($qn); } //Из ботов падают предметы [ idbot-itm1=%,itm2=%| if (isset($d['tr_botitm'])) { $t .= 'Из ботов выпадают предметы: