<?php
//
//
#Автор: Jquery
#telegram: @justin_olivier
//
//
//генерации
$generrat = (float)microtime();
//
//
//Показ ошибок
/*
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
*/
//
//
//Отключаем ошибки
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
//
//
//Старт тайм зоны
date_default_timezone_set('Europe/Moscow');
//
//
//запускаем ссесию
session_start();
//
//
//запускаем буфер
ob_start();
//
//
//Кодировка
mb_internal_encoding('UTF-8');
//
//
//Главная директория
define('ROOT', dirname(__DIR__));
//
//
//адрес сайта
$sites = 'https://'.$_SERVER['HTTP_HOST'];
//
//
//Автозагрузка классов
function autoload($class) {
	$file = ROOT.'/inc/function/'.$class.'.php';
	if (file_exists($file)):
		require $file;
	else:
		$message = sprintf("Кажется где-то потерял файл: %s", $file);
		die($message); exit;
	endif;
}
if (function_exists('spl_autoload_register')):
	spl_autoload_register('autoload');
endif;

//
//
$core = new core();
$user = $core->getData();
//
//
//Фильтры
require_once(ROOT.'/inc/function/filter.php');
//
//
//Параметры игрока
require_once(ROOT.'/inc/function/function_params.php');
//
//
//Время
require_once(ROOT.'/inc/function/time.php');
//
//
//Пагинация
require_once(ROOT.'/inc/function/pagenation.php');
//
//
//Тело страницы
require_once(ROOT.'/inc/function/body.php');
//
//
//Уровень игроков
//
//
$user_level = array(
'1' => '10',
'2' => '30',
'3' => '60',
'4' => '90',
'5' => '120',
'6' => '150',
'7' => '180',
'8' => '210',
'9' => '240',
'10' => '270',
'11' => '540',
'12' => '1080',
'13' => '2160',
'14' => '4320',
'15' => '8640',
'16' => '17280',
'17' => '25000',
'18' => '50000',
'19' => '100000',
'20' => '200000',
'21' => '400000',
'22' => '800000',
'23' => '1600000',
'24' => '3200000',
'25' => '6400000',
'26' => '12800000',
'27' => '23600000',
'28' => '47200000',
'29' => '94400000',
'30' => '198000000'
);
//
//
$otvar_type = array('1' => 'Обычный','2' => 'Зачарованный','3' => 'Магический','4' => 'Эксклюзивный','5' => 'Божественный');
//
//
if($user['id'] >= 1 && $user['level'] <= 29 && $user['exp'] >= $user_level[$user['level']]){
//
//
if($user['level'] == 1)$lvl = 2; else $lvl = 1;
//
//
$medal2 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(2,$user['id']));
if($medal2['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal2['id']));
//
//
$medal3 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(3,$user['id']));
if($medal3['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal3['id']));
//
//
$medal4 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(4,$user['id']));
if($medal4['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal4['id']));
//
//
$medal5 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(5,$user['id']));
if($medal5['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal5['id']));
//
//
$medal6 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(6,$user['id']));
if($medal6['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal6['id']));
//
//
$medal7 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(7,$user['id']));
if($medal7['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal7['id']));
//
//
$medal8 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(8,$user['id']));
if($medal8['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal8['id']));
//
//
$medal9 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(9,$user['id']));
if($medal9['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal9['id']));
//
//
$medal10 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(10,$user['id']));
if($medal10['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal10['id']));
//
//
$medal11 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(11,$user['id']));
if($medal11['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($lvl,$medal11['id']));
//
//
$text = 'Поздравляем, выполучили новый '.($user['level']+1).' уровень![br]10 [img='.$sites.'/css/img/gold.png]16[/img] и 1000 [img='.$sites.'/css/img/silver.png]16[/img] в подарок!';
DB::$dbs->query('INSERT INTO `notification` SET `text` = ?,`time` = ?,`id_user` = ?',array($text,time(),$user['id']));
DB::$dbs->query("UPDATE `users` SET `level` = `level` + ?, `notif` = ?, `gold` = `gold` + ?, `silver` = `silver` + ?, `exp` = `exp` - ? WHERE `id` = ? LIMIT 1", array(1,1,10,1000,$user_level[$user['level']],$user['id']));
//
//
header("location:?");
//
exit();
}
//
//
//Задания
$task_sql = DB::$dbs->query("SELECT * FROM `task` ORDER BY `id` ASC"); 
//
foreach ($task_sql as $sqlls => $im){
$quest = DB::$dbs->queryFetch("SELECT * FROM `task_user` WHERE `id_task` = ? AND `id_user` = ? ORDER BY `id` DESC LIMIT 1", array($im['id'],$user['id']));
if(!$quest && $user['id'] >= 1){
DB::$dbs->query("INSERT INTO `task_user` SET `id_user` = ?, `id_task` = ?, `max_coll` = ?", array($user['id'],$im['id'],$im['coll']));
}
}
//
//
//
//
//титулы
$titul_sql = DB::$dbs->query("SELECT * FROM `titul` ORDER BY `id` ASC"); 
//
foreach ($titul_sql as $sqlls => $im){
$quest2 = DB::$dbs->queryFetch("SELECT * FROM `titul_user` WHERE `id_titul` = ? AND `id_user` = ? ORDER BY `id` DESC LIMIT 1", array($im['id'],$user['id']));
if(!$quest2 && $user['id'] >= 1){
DB::$dbs->query("INSERT INTO `titul_user` SET `id_user` = ?, `id_titul` = ?, `max_coll` = ?", array($user['id'],$im['id'],$im['coll']));
}
}
//
//
//Достижения
$medal_sql = DB::$dbs->query("SELECT * FROM `medal` ORDER BY `id` ASC"); 
//
foreach ($medal_sql as $sqlls => $im){
$quest1 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? ORDER BY `id` DESC LIMIT 1", array($im['id'],$user['id']));
if(!$quest1 && $user['id'] >= 1){
DB::$dbs->query("INSERT INTO `medal_user` SET `id_user` = ?, `id_task` = ?, `max_coll` = ?", array($user['id'],$im['id'],$im['coll']));
}
}
//
//
$ban_type = array('', 'Предупреждение', 'Блокировка чата и почты', 'Блокировка аккаунта');
$ban_cause = array('', 'Реклама сторонних ресурсов', 'Спам в почте', 'Спам в чате', 'Продажа аккаунта, ордена', 'Покупка аккаунта, ордена', 'Мошенничество', 'Использование багов', 'Обсуждение действий администрации', 'Обсуждение на тему политики', 'Оскорбление/Мат');
//
//
$liga_type = array('','Новичков','Наемников','Рыцарей','Храбрейших','Великих');
$liga_bonus = array('','0%','10%','15%','20%','25%');
