query('SELECT * FROM `quests` WHERE `id` = ?i', $pl)->fetch_assoc();
$r = 1;
$qlst = db::c()->query('SELECT `vals` FROM `actions` WHERE `uid` = ?i AND `vars` = "?s"', $uid, 'start_quest' . $pl['id'])->fetch_assoc();
if (db::c()->getAffectedRows() AND !in_array($qlst['vals'], ['win', 'end', 'vals'])) $r = 2;
unset($qlst, $qlst2);
$d = $this->expl($pl['tr_date']);
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` = "' . $uid . '" AND `vars` = "start_quest' . $e[$i] . '" AND `vals` = "win" LIMIT 1'));
if (!isset($qlst['id'])) {
$r = 3;
}
$i++;
}
unset($qn, $qlst, $qlst2);
}
if (isset($d['tr_zdr'])) {
$qlst = mysql_fetch_array(mysql_query('SELECT * FROM `actions` WHERE `uid` = "' . $uid . '" 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 = 4;
}
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 = $this->testAction('SELECT `id` FROM `actions` WHERE `uid` = "' . $uid . '" AND `vars` = "start_quest' . $pl['id'] . '" LIMIT ' . $d['tr_raz'], 2);
if ($d['tr_raz'] > 0 && $d['tr_raz'] - $qlst[0] <= 0) {
$r = 5;
}
unset($qlst);
}
if (isset($d['tr_raz2'])) {
$qlst = $this->testAction('SELECT `id` FROM `actions` WHERE `uid` = "' . $uid . '" 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 = 6;
}
unset($qlst);
}
return $r;
}
public function __clone()
{
trigger_error('Дублирование не допускается.', E_USER_ERROR);
}
public function startq($id, $uid)
{
$pl = db::c()->query('SELECT `id`,`name`,`time` FROM `quests` WHERE `delete` = 0 AND `id` = ?i', $id)->fetch_assoc();
if (db::c()->getAffectedRows()) {
$tms = (time() + 60 * 60 * $pl['time']);
db::c()->query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`, `val`) VALUES (?i,?i,"?s",?i,"?s","?s","?s","?s")',
$uid, time(), 'capitalcity', 0, 'start_quest' . $id, $_SERVER['REMOTE_ADDR'], 'go', $tms);
return 'Вы успешно получили задание "' . $pl['name'] . '"';
} else {
return 'Не удалось получить данное задание ...';
}
}
public function list_quest($pl, $u)
{
$r = '';
$t = '';
$nagr = '';
$tr = '';
$za = '';
$qlst = db::c()->query('SELECT `vals`, `time` FROM `actions` WHERE `uid` = ?i AND `vars` = "?s" ORDER BY `time` DESC', $u, 'start_quest' . $pl['id'])->fetch_assoc();
$ds = $this->expl($pl['win_date']);
if (isset($ds['add_cr'])) $nagr .= "Деньги: {$ds['add_cr']} кр. ";
if (isset($ds['add_point'])) $nagr .= "Репутация: {$ds['add_point']} ед. ";
if (isset($ds['add_exp'])) $nagr .= "Опыт: {$ds['add_exp']} ед. ";
$d = $this->expl($pl['act_date']);
if (isset($d['heal'])) $tr .= "Вылечить {$d['heal']} игроков от травм. ";
if (isset($d['tr_win_haot'])) $tr .= "Выиграть {$d['tr_win_haot']} хаотических поединков. ";
if (isset($d['kill_clone'])) $tr .= "Выиграть {$d['kill_clone']} поединков против своего клона. ";
if (isset($d['tr_win'])) $tr .= "Выйграть {$d['tr_win']} физических поединков против игроков. ";
if (isset($d['kill_bot'])) {
$x = '';
$ex = explode(',', $d['kill_bot']);
$i = 0;
while ($i < count($ex)) {
$ex2 = explode('=', $ex[$i]);
$bot2 = db::c()->query('SELECT `login` FROM `users` WHERE `id` = ?i', $ex2[0])->fetch_assoc();
if (db::c()->getAffectedRows()) $x .= " • {$bot2['login']} {$ex2[1]} ";
$i++;
}
if (!empty($x)) {
$x = trim($x, ', ');
$tr .= "Убить ботов: {$x}";
}
}
if (!empty($tr)) $ts = 'Требования : ' . $tr;
if ($qlst['time'] + ($pl['heal'] * 60 * 60) - time() > 0) {
$tms = $this->timeOut($qlst['time'] + ($pl['heal'] * 60 * 60) - time());
$za = "Задержка еще: {$tms} ";
}
$d = $this->expl($pl['tr_date']);
$r .= <<
{$pl['name']}
{$pl['info']}
Награда: {$nagr}
Время на выполнение: {$pl['time']} ч.
{$ts}{$za}
Задание для [{$pl['min_lvl']}-{$pl['max_lvl']}] уровней, с задержкой {$pl['heal']} ч.
TASK;
return $r;
}
public function info($pl, $uid)
{
$r = '';
$t = '';
$qst = mysql_fetch_array(mysql_query('SELECT * FROM `actions` WHERE `uid` = "' . $uid . '" AND `vars` = "start_quest' . $pl['id'] . '" AND `vals` = "go" LIMIT 1'));
$d = $this->expl($pl['tr_date']);
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);
}
if (isset($d['tr_botitm'])) {
$t .= 'Из ботов выпадают предметы :