Рефакторинг, отказ от $u->testAction('',2) для разрыва зависимости с User::class. Добавлен зачаточный генератор запросов.
This commit is contained in:
+230
-216
@@ -2,6 +2,7 @@
|
||||
|
||||
use Core\Db;
|
||||
use Helper\Conversion;
|
||||
use Model\ActionModel;
|
||||
use User\ItemsModel;
|
||||
|
||||
class Quests
|
||||
@@ -67,16 +68,18 @@ class Quests
|
||||
}
|
||||
//Сколько раз можно пройти квест
|
||||
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) {
|
||||
$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 = $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) {
|
||||
$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);
|
||||
@@ -212,8 +215,7 @@ class Quests
|
||||
$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];
|
||||
$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'];
|
||||
@@ -393,15 +395,17 @@ class Quests
|
||||
if ($d['tr_raz'] == -1) {
|
||||
$t .= 'Сколько еще раз можно выполнить задание: <b><small>бесконечно</small></b><br>';
|
||||
} else {
|
||||
$qlst = $u->testAction('SELECT `id` FROM `actions` WHERE `uid` = "' . $u->info['id'] . '" AND `vars` = "start_quest' . $pl['id'] . '" LIMIT ' . $d['tr_raz'], 2);
|
||||
$t .= 'Сколько раз можно выполнить задание: ' . ($d['tr_raz'] - $qlst[0]) . '<br>';
|
||||
$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);
|
||||
$t .= 'Сколько раз можно выполнить задание: ' . ($d['tr_raz'] - $qlst) . '<br>';
|
||||
}
|
||||
unset($qlst);
|
||||
}
|
||||
//Попыток пройти квест
|
||||
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);
|
||||
$t .= 'Осталось попыток выполнить задание: ' . ($d['tr_raz2'] - $qlst[0]) . '<br>';
|
||||
$qlst = ActionModel::testCount(["uid = {$u->info['id']}", "vars = start_quest{$pl['id']}", "vals != go", "vals != win"], $d['tr_raz2']);
|
||||
//$qlst = $u->testAction('`uid` = "' . $u->info['id'] . '" AND `vars` = "start_quest' . $pl['id'] . '" AND `vals` != "go" AND `vals` != "win" LIMIT ' . $d['tr_raz2'], 2);
|
||||
$t .= 'Осталось попыток выполнить задание: ' . ($d['tr_raz2'] - $qlst) . '<br>';
|
||||
unset($qlst);
|
||||
}
|
||||
|
||||
@@ -479,28 +483,32 @@ class Quests
|
||||
|
||||
//Убить ботов
|
||||
if (isset($d['kill_bot'])) {
|
||||
|
||||
$ex = explode(',', $d['kill_bot']);
|
||||
if (isset($d['all_kill']) && (int)$d['all_kill'] > 0) {
|
||||
$x = '';
|
||||
$ex = explode(',', $d['kill_bot']);
|
||||
$i = 0; # Количество циклов для каждого типа бота.
|
||||
$q = '';
|
||||
$botid = 0;
|
||||
$sqlWhere = [];
|
||||
$sqlParams = [];
|
||||
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] . '" )';
|
||||
$botid = $ex2[0];
|
||||
$sqlWhere[] = "(uid = :uid$i and time > :time$i and vars = :vars$i)";
|
||||
$sqlParams["uid$i"] = $u->info['id'];
|
||||
$sqlParams["time$i"] = $qst['time'];
|
||||
$sqlParams["vars$i"] = "win_bot_$ex2[0]";
|
||||
$i++;
|
||||
}
|
||||
$x2 = $u->testAction($q, 2);
|
||||
$x2 = $x2[0];
|
||||
$sqlWhere = implode(' or ', $sqlWhere);
|
||||
$x2 = ActionModel::testCountCustom($sqlWhere, $sqlParams);
|
||||
|
||||
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>';
|
||||
|
||||
$botlogin = Db::getValue('select login from test_bot where id = ?', [$botid]);
|
||||
if (isset($botlogin)) {
|
||||
$x .= ' • <b>' . $botlogin . '</b> [' . $x2 . '/' . $d['all_kill'] . ']<br>';
|
||||
} else {
|
||||
$x .= ' • <b>' . $pl['name'] . '</b> [' . $x2 . '/' . $d['all_kill'] . ']<br>';
|
||||
}
|
||||
@@ -509,13 +517,12 @@ class Quests
|
||||
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'])) {
|
||||
$botlogin = Db::getValue('select login from test_bot where id = ?', [$ex2[0]]);
|
||||
if (isset($botlogin)) {
|
||||
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];
|
||||
$x2 = ActionModel::testCount(["uid = {$u->info['id']}", "vars = win_bot_$ex2[0]", "time > {$qst['time']}"], $ex2[1]);
|
||||
}
|
||||
$x .= ' • <b>' . $bot2['login'] . '</b> [' . $x2 . '/' . $ex2[1] . ']<br>';
|
||||
$x .= ' • <b>' . $botlogin . '</b> [' . $x2 . '/' . $ex2[1] . ']<br>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@@ -525,7 +532,7 @@ class Quests
|
||||
$x = trim($x, ', ');
|
||||
$t .= 'Убить ботов: <br>' . $x;
|
||||
}
|
||||
unset($x, $ex, $x2, $bot2, $ex2);
|
||||
unset($x, $ex, $x2, $ex2, $botlogin);
|
||||
}
|
||||
|
||||
//Собрать ресурсы
|
||||
@@ -585,72 +592,86 @@ class Quests
|
||||
public function testquest(): void
|
||||
{
|
||||
global $u;
|
||||
if ($u->info['battle'] == 0 && $u->room['name'] != 'Башня Смерти') {
|
||||
$sp = mysql_query('SELECT * FROM `actions` WHERE `uid` = "' . $u->info['id'] . '" AND `vars` LIKE "%start_quest%" AND `vals` = "go" LIMIT 100');
|
||||
if ($u->info['battle'] != 0 || $u->room['name'] === 'Башня Смерти') {
|
||||
return;
|
||||
}
|
||||
|
||||
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'));
|
||||
$sp = mysql_query('SELECT * FROM `actions` WHERE `uid` = "' . $u->info['id'] . '" AND `vars` LIKE "%start_quest%" AND `vals` = "go" LIMIT 100');
|
||||
|
||||
$g = 1;
|
||||
//Действия квеста
|
||||
$d = $this->expl($pl['act_date']);
|
||||
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'));
|
||||
|
||||
//Поговорить с NPS
|
||||
if (isset($d['dlg_nps'])) {
|
||||
$g = 1;
|
||||
//Действия квеста
|
||||
$d = $this->expl($pl['act_date']);
|
||||
|
||||
//Поговорить с NPS
|
||||
if (isset($d['dlg_nps'])) {
|
||||
$g = 0;
|
||||
unset($x);
|
||||
}
|
||||
|
||||
//Убить игроков
|
||||
if (isset($d['kill_user'])) {
|
||||
$x = 0;
|
||||
if ($x < $d['kill_user']) {
|
||||
$g = 0;
|
||||
unset($x);
|
||||
}
|
||||
|
||||
//Убить игроков
|
||||
if (isset($d['kill_user'])) {
|
||||
$x = 0;
|
||||
if ($x < $d['kill_user']) {
|
||||
//$d['kill_user'] - стольких нужно убить
|
||||
unset($x);
|
||||
}
|
||||
//Убить ботов
|
||||
if (isset($d['kill_bot'])) {
|
||||
$ex = explode(',', $d['kill_bot']);
|
||||
$ii = 0; // Количество циклов для каждого типа бота.
|
||||
$smth2 = 0; // неизвестное.
|
||||
$sqlFilter = [];
|
||||
$sqlParams = [];
|
||||
while ($ii < count($ex)) {
|
||||
$ex2 = explode('=', $ex[$ii]);
|
||||
$smth2 = $ex2[1];
|
||||
$sqlFilter[] = "(uid = :uid$ii and time > :time$ii and vars = :vars$ii)";
|
||||
$sqlParams["uid$ii"] = $u->info['id'];
|
||||
$sqlParams["time$ii"] = $pl2['time'];
|
||||
$sqlFilter["vars$ii"] = "win_bot_$ex2[0]";
|
||||
$ii++;
|
||||
}
|
||||
$sqlFilter = implode(' or ', $sqlFilter);
|
||||
if (isset($d['all_kill']) && $d['all_kill'] > 0) {
|
||||
$x2 = ActionModel::testCountCustom($sqlFilter, $sqlParams, $d['all_kill']);
|
||||
if ($x2 < $d['all_kill']) {
|
||||
$g = 0;
|
||||
}
|
||||
//$d['kill_user'] - стольких нужно убить
|
||||
unset($x);
|
||||
}
|
||||
//Убить ботов
|
||||
if (isset($d['kill_bot'])) {
|
||||
$ex = explode(',', $d['kill_bot']);
|
||||
$ii = 0; // Количество циклов для каждого типа бота.
|
||||
$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++;
|
||||
} else {
|
||||
$x2 = ActionModel::testCountCustom($sqlFilter, $sqlParams, $smth2);
|
||||
if (!isset($d['all_kill']) && $x2 < $smth2) {
|
||||
$g = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//Собрать ресурсы
|
||||
if (isset($d['tk_itm'])) {
|
||||
$g = $this->collect_01(explode(',', $d['tk_itm']), $u);
|
||||
}
|
||||
//Собирание трофеев
|
||||
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'];
|
||||
//Собрать ресурсы
|
||||
if (isset($d['tk_itm'])) {
|
||||
$g = $this->collect_01(explode(',', $d['tk_itm']), $u);
|
||||
}
|
||||
//Собирание трофеев
|
||||
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');
|
||||
$status = $this->winQuest($u->info['id'], $pl, $pl2['time']);
|
||||
//Отправляем сообщение в чат
|
||||
if ($status) {
|
||||
$chatDto = new ChatMessage();
|
||||
$chatDto->setRoom($u->info['room']);
|
||||
$chatDto->setTo($u->info['login']);
|
||||
$chatDto->setText($status);
|
||||
$chatDto->setType(5);
|
||||
(new Chat())->sendMsg($chatDto);
|
||||
}
|
||||
echo $pl['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,125 +709,117 @@ class Quests
|
||||
|
||||
# Функция отвечает за ПРОВЕРКУ на ЗАВЕРШЕНИЕ квестов для ПОДЗЕМОК
|
||||
|
||||
private function winQuest($pl)
|
||||
private function winQuest($uid, $pl, $time): string
|
||||
{
|
||||
global $u, $c, $magic;
|
||||
global $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++;
|
||||
}
|
||||
}
|
||||
// Забираем трофеи
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
$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'] != '') {
|
||||
$t .= '' . $d['add_rep'] . ' ед. репутации ' . $pl['city'] . ', ';
|
||||
$rep = mysql_fetch_array(mysql_query('SELECT * FROM `rep` WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'));
|
||||
|
||||
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) {
|
||||
$magic->addEffect($u->info['id'], $j[$i], 1);
|
||||
}
|
||||
$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);
|
||||
if (!isset($pl['id'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$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]);
|
||||
$x2 = ActionModel::testCount(["uid = $uid", "vars = win_bot_$ex[2]", "time > $time"], $ex2[1]);
|
||||
ItemsModel::deleteItemsById($ex2[0], $ex2[1]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// Забираем трофеи
|
||||
if (isset($d['tkill_itm'])) {
|
||||
$ex = explode(',', $d['tkill_itm']);
|
||||
$i = 0;
|
||||
while ($i < count($ex)) {
|
||||
$ex2 = explode('=', $ex[$i]);
|
||||
$x2 = ActionModel::testCount(["uid = $uid", "vars = win_bot_$ex[2]", "time > $time"], $ex2[1]);
|
||||
ItemsModel::deleteItemsById($ex2[0], $ex2[1]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$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']) {
|
||||
$d['add_rep'] = $d['add_rep'] + (int)$ex2[1];
|
||||
$x2 = ActionModel::testCount(["uid = $uid", "vars = win_bot_$ex[2]", "time > $time"], $d['all_kill']);
|
||||
$i++;
|
||||
}
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
unset($x, $i, $ii, $ex, $x2, $bot2, $ex2);
|
||||
if ($pl['city'] != '') {
|
||||
$t .= '' . $d['add_rep'] . ' ед. репутации ' . $pl['city'] . ', ';
|
||||
$rep = mysql_fetch_array(mysql_query('SELECT * FROM `rep` WHERE `id` = "' . $uid . '" LIMIT 1'));
|
||||
|
||||
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` = "' . $uid . '" 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) {
|
||||
$magic->addEffect($uid, $j[$i], 1);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($d['add_cr'])) {
|
||||
$t .= '' . $d['add_cr'] . ' кр., ';
|
||||
mysql_query('UPDATE `users` SET `money` = `money`+' . $d['add_cr'] . ' WHERE `id` = "' . $uid . '" LIMIT 1');
|
||||
}
|
||||
|
||||
if ($t != '') {
|
||||
$t = rtrim($t, ', ');
|
||||
$r = 'Задание <b>' . $pl['name'] . '</b> было успешно выполнено! Вы получили награду: ' . $t . '.';
|
||||
unset($t);
|
||||
} else {
|
||||
$r = 'Задание <b>' . $pl['name'] . '</b> было успешно выполнено!';
|
||||
}
|
||||
|
||||
return "<small>$r</small>";
|
||||
}
|
||||
|
||||
public function questCheckEnd($pl)
|
||||
public function questCheckEnd($pl): int
|
||||
{
|
||||
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'));
|
||||
@@ -836,29 +849,31 @@ class Quests
|
||||
if (isset($d['kill_bot'])) {
|
||||
$ex = explode(',', $d['kill_bot']);
|
||||
$i = 0; # Количество циклов для каждого типа бота.
|
||||
$q = '';
|
||||
$smth1 = 0; // неизвестно что.
|
||||
$sqlFilter = [];
|
||||
$sqlParams = [];
|
||||
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] . '" )';
|
||||
$smth1 = $ex2[1];
|
||||
$sqlFilter[] = "(uid = :uid$i and time > :time$i and vars = :vars$i)";
|
||||
$sqlParams[":uid$i"] = $u->info['id'];
|
||||
$sqlParams[":time$i"] = $quest['time'];
|
||||
$sqlParams[":vars$i"] = "win_bot_$ex2[0]";
|
||||
$i++;
|
||||
}
|
||||
$sqlFilter = implode(' or ', $sqlFilter);
|
||||
if (isset($d['all_kill']) && (int)$d['all_kill'] > 0) {
|
||||
$x2 = $u->testAction($q, 2);
|
||||
if ((int)$d['all_kill'] <= $x2[0]) {
|
||||
$x2 = ActionModel::testCountCustom($sqlFilter, $sqlParams);
|
||||
if ((int)$d['all_kill'] <= $x2) {
|
||||
$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]) {
|
||||
$x2 = ActionModel::testCountCustom($sqlFilter, $sqlParams, $smth1);
|
||||
$x2 = min($smth1, $x2);
|
||||
if ($x2 < $smth1) {
|
||||
$g = 0;
|
||||
}
|
||||
}
|
||||
@@ -886,10 +901,10 @@ class Quests
|
||||
$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))) {
|
||||
if ($x2 <= ((int)$ex2[1] + round($ex2[1] * 0.15))) {
|
||||
$ex2[1] = $x2;
|
||||
} else {
|
||||
$ex2[1] = ($ex2[1] + round($ex2[1] * 0.15));
|
||||
$ex2[1] = ((int)$ex2[1] + round($ex2[1] * 0.15));
|
||||
}
|
||||
}
|
||||
if ($x2 < $ex2[1]) {
|
||||
@@ -928,10 +943,10 @@ class Quests
|
||||
$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))) {
|
||||
if ($x2 <= ((int)$ex2[1] + round($ex2[1] * 0.15))) {
|
||||
$ex2[1] = $x2;
|
||||
} else {
|
||||
$ex2[1] = ($ex2[1] + round($ex2[1] * 0.15));
|
||||
$ex2[1] = ((int)$ex2[1] + round($ex2[1] * 0.15));
|
||||
}
|
||||
}
|
||||
$d['add_rep'] = (int)$d['add_rep'] * (int)$ex2[1];
|
||||
@@ -953,9 +968,8 @@ class Quests
|
||||
$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);
|
||||
$d['add_rep'] = $d['add_rep'] + (int)$ex2[1];
|
||||
$x2 = ActionModel::testCount(["uid = {$u->info['id']}", "vars = win_bot_$ex2[0]", "time > {$action['time']}"], $d['all_kill']);
|
||||
$i++;
|
||||
}
|
||||
$ii++;
|
||||
|
||||
Reference in New Issue
Block a user