Файл: public_html/quest.php
Строк: 106
<?php
require_once './system/common.php';
require_once './system/functions.php';
require_once './system/user.php';
if (!isset ($user)) {
header('location: /');
exit;
}
$title = 'Задания';
require_once './system/h.php';
if (isset($_SESSION['ok'])){
echo "<div class='ok'><center><img src='/images/icon/ok.png'> $_SESSION[ok]</center></div>";
$_SESSION['ok']=NULL;
}
$set = array (
'max_active_q' => 10, // максимальное количество активных квестов
'time' => 3600 * 6 // время обновления уже выполненых квестов (10 ч)
);
// Place
// 1 - Арена
// 2 - Задания
// 3 - Дуэли
// 4 - Поход
// 5 - Пещера
// 6 - Колизей
// 7 - Долина бессмертных
// 10 - Дуэли
// Обновление неактивных квестов
$q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`complete`="1")');
if (mysql_num_rows ($q) < $set['max_active_q']) {
$i = 0;
while ($user_q = mysql_fetch_array ($q)) {
if ($user_q['time']<time ()) {
$i++;
if ($i < 10) {
mysql_query ('UPDATE `user_q` SET `complete`="0",`c`="0" WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $user_q['q'] . '")');
}
}
}
}
// Обновление новых квестов
$q = mysql_query ('select * from `user_q` WHERE (`user`="'.$user['id'].'") AND (`complete`="0")');
if (mysql_num_rows ($q) < $set['max_active_q']) {
// Обновление квестов
$q = mysql_query ('select * from `quest`');
$i = 0;
while ($quest = mysql_fetch_array ($q)) {
$q_ = mysql_query ('SELECT * FROM `user_q` WHERE (`user`="'.$user['id'].'") AND (`q`="'.$quest['id'].'")');
if (mysql_num_rows ($q_)==0) {
$i++;
if ($i <10) {
mysql_query ('INSERT INTO `user_q` (`user`, `q`) VALUES ("'.$user['id'].'", "'.$quest['id'].'")');
}
}
}
}
echo '
<div class="title">' . $title . '</div>
<div class="block" align="center"><span style="color:#90b0c0;">Выполняй задания и получай отличную награду</span></div>
';
// Выполнение квеста
if (isset ($_GET['complete'])) {
$_GET['complete'] = (int) $_GET['complete'];
$q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $_GET['complete'] . '")');
if (mysql_num_rows ($q)==0) {
header ('location: /quest.php');
exit;
}
$user_q = mysql_fetch_array ($q);
if ($user_q['complete']==1) {
header ('location: /quest.php');
exit;
}
$q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id`="' . $user_q['q'] . '")');
$quest = mysql_fetch_array ($q_);
if ($user_q['c']<$quest['c']) {
header ('location: /quest.php');
exit;
}
if(date('w') != 0 AND date('w') != 6){
require_once('relict.php');
$relik = "<img src='/images/icon/relic.png'> + 1 <br>$name<br><br><img src='$img' width='50' height='50'/>";
$plats = 1;
}else{
$plats = 0;
}
$_SESSION['ok'] = 'Награда: ' . ($quest['_gold'] != 0 ? ' <img src="/images/icon/gold.png" alt=""/> ' . $quest['_gold'] . ' золота' : '') . ($quest['_silver'] != 0 ? ' <img src="/images/icon/silver.png" alt=""/> ' . $quest['_silver'] . ' серебра' : '') . ($quest['_exp'] != 0 ? ' <img src="/images/icon/exp.png" alt=""/> '.$quest['_exp'].' опыта' : '') . ' '.((date('w') != 0 AND date('w') != 6) ? ''.$relik.' ':'').'';
mysql_query ('UPDATE `user_q` SET `complete`="1", `time`="' . ( time () + $set['time'] ) . '" WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $quest['id'] . '")');
mysql_query ('UPDATE `users` SET `g`=`g`+' . $quest['_gold'] . ',`quests`= `quests`+1, `plat`=`plat`+' . $plats . ', `exp`=`exp`+' . $quest['_exp'] . ' WHERE (`id`="' . $user['id'] . '")');
// Place
// 2 - Задания _silver
// Type
// 0 - Выполнить любые задания в хижине мудреца
$q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`complete`="0")');
if (mysql_num_rows ($q) != 0) {
while ($user_q = mysql_fetch_array ($q)) {
//
$q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id`="' . $user_q['q'] . '")');
$quest = mysql_fetch_array ($q_);
if ($quest['place']=='2') {
if ($quest['type']=='0') {
if ($user_q['c']<$quest['c']) {
mysql_query ('UPDATE `user_q` SET `c`=`c`+1 WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $quest['id'] . '")');
}
}
}
}
}
header ('location: /quest.php');
}
///////////////////////
// Список активных квестов
$q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`complete`="0")');
if (mysql_num_rows ($q) != 0) {
while ($user_q = mysql_fetch_array ($q)) {
$q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id`="' . $user_q['q'] . '")');
$quest = mysql_fetch_array ($q_);
if ($user_q['c']>=$quest['c']) {
echo '<div class='menuList'><b style="color:#90c090;">' . $quest['title'] . '</b><br/><span style="font-size:12px;">' . $quest['description'] . '</span><br/><span style="color:#30c030;">Задание выполнено!</span></br><span style="color:#90b0c0;">Награда:</span> ' . ($quest['_gold'] != 0 ? ' <img src="/images/icon/gold.png" alt=""/> ' . $quest['_gold'] . ' золота' : '') . ($quest['_silver'] != 0 ? ' <img src="/images/icon/silver.png" alt=""/> ' . $quest['_silver'] . ' серебра' : '') . ($quest['_exp'] != 0 ? ' <img src="/images/icon/exp.png" alt=""/> ' . $quest['_exp'] . ' опыта' : '') . '
<div style="text-align:center;">';
echo '<a href="/quest.php?complete=' . $quest['id'] . '"><span class="btn"><span class="end"><span class="label">Завершить задание</a></span></span></span></div>';
}
}
}
// Список активных квестов
//////////////////////////
$q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`complete`="0")');
if (mysql_num_rows ($q) == 0) {
echo '<li>Нет активных квестов</li>';
}else {
while ($user_q = mysql_fetch_array ($q)) {
$q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id`="' . $user_q['q'] . '")');
$quest = mysql_fetch_array ($q_);
//$exp_progress = round(($user['exp']/$exp)*100);
$quest_progress = round(($user_q['c']/$quest['c'])*100);
if ($user_q['c']!=$quest['c']) {
echo '<div class="block3"><b style="color:#90c090;">' . $quest['title'] . '</b><br/>
<span style="font-size:12px;">' . $quest['description'] . '</span><br/>
<span style="color:#90b0c0;">Прогресс:</span> ' . ($user_q['c'] . ' из ' . $quest['c'] ). '
<div style="border:1px solid #000; background: #CCCCCC; height: 5px; width:50%">
<div style="background: #fc3; height: 5px; width:'.$quest_progress.'%"></div>
</div>
<br/>
<span style="color:#90b0c0;">Награда:</span> ' . ($quest['_gold'] != 0 ? ' <img src="/images/icon/gold.png" alt=""/> ' . $quest['_gold'] . ' золота' : '') . ($quest['_silver'] != 0 ? ' <img src="/images/icon/silver.png" alt=""/> ' . $quest['_silver'] . ' серебра' : '') . ($quest['_exp'] != 0 ? ' <img src="/images/icon/exp.png" alt=""/> ' . $quest['_exp'] . ' опыта' : '') . '
<div style="text-align:center;">';
switch ($quest['place']) {
case 1:
$self = 'arena';
break;
case 2:
$self = 'quest';
break;
case 3:
$self = 'duel';
break;
case 4:
$self = 'farm';
break;
case 5:
$self = 'cave';
break;
case 6:
$self = 'coliseum';
break;
case 7:
$self = 'undying';
break;
case 8:
$self = 'dryit';
break;
case 9:
$self = 'league';
break;
case 10:
$self = 'duel';
break;
}
echo '<a href="/' . $self . '.php"><span class="btn"><span class="end"><span class="label">Перейти к выполнению</a></span></span></span>';
}
echo '</div>';
}
}
// Список активных квестов
$q = mysql_query ('select * from `user_q` WHERE (`user` = "'.$user['id'].'") AND (`complete` = "1")');
if (mysql_num_rows ($q) != 0) {
while ($user_q = mysql_fetch_array ($q)) {
//
$q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id` = "'.$user_q['q'].'")');
$quest = mysql_fetch_array ($q_);
$t_wait = ceil ( ( $user_q['time']-time () ) / 3600);
echo '
<div class="block3"><span style="color:grey;"><b>' . $quest['title'] . '</b><br/>
<span style="font-size:12px;">
<span style="font-size:12px;">' . $quest['description'] . '</span><br/>
Будет доступно через: ' . ( $t_wait < 1 ? $t_wait . ' мин' : $t_wait . ' час(а/ов)' ) . '</span></span></div>
';
}
}
echo '</div></div></div></div></div>';
require_once './system/f.php';
?>