Файл: public_html/modules/towers/helper.php
Строк: 187
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include_once ($root.'/core/base.php');
falseauth();
$header = "Башни";
include_once ($root.'/core/head.php');
?>
<style>
.mlra {
margin-left: auto;
margin-right: auto;
}
.mb10 {
margin-bottom: 10px;
}
.wings {
width: 75px;
padding: 0 57px;
font-size: 0;
background-image: url(/images/bg-wings.png);
background-repeat: no-repeat;
}
.img70 {
display: block;
width: 64px;
height: 70px;
font-size: 0;
background-repeat: no-repeat;
}
.w180x {
width: 85%;
}
</style>
<?
$tower = $db->query("SELECT * FROM `towers` WHERE `user` = '".$u['id']."'")->fetch_object();
$gremlinParams = getGremlinParams($tower->gremlin_level, $tower->wizard_level);
$hunterParams = getHunterParams($tower->hunter_level, $tower->wizard_level);
//'.($tower->gremlin_level == 0 ? '<a href="/towers/gremlin">Купить гремлина</a>' : '<a href="/towers/gremlin">Улучшить до '.($tower->gremlin_level+1).' уровня</a>').'
$type = fl($_GET['type']);
$gremlinCost = 5000;
$hunterCost = 15000;
if(!in_array($type, ['gremlin','hunter'])) redirect('/towers');
if(isset($_GET['buy']))
{
$class = $type == 'gremlin' ? 'gremlin_level' : 'hunter_level';
$class_time = $type == 'gremlin' ? 'gremlin_time' : 'hunter_time';
$time = $type == 'gremlin' ? $gremlinParams['nextLevelTime'] : $hunterParams['nextLevelTime'];
$cost = $type == 'gremlin' ? $gremlinCost : $hunterCost;
$level = $type == 'gremlin' ? 10 : 15;
if($tower->$class > 0) redirect('/towers/'.$type, 'Помощник уже куплен!');
if($u['level'] < $level) redirect('/towers', 'Низкий уровень игрока!');
if($u['silver'] < $cost) redirect('/towers', 'Недостаточно серебра');
$db->query("UPDATE `users` SET `silver` = `silver` - '".$cost."' WHERE `id` = '".$u['id']."'");
$db->query("UPDATE `towers` SET `".$class."` = '1', `".$class_time."` = '".(time()+$time*60)."' WHERE `id` = '"
.$tower->id."'");
redirect('/towers/'.$type, 'Помощник куплен!');
}
if(isset($_GET['up']))
{
$class = $type == 'gremlin' ? 'gremlin_level' : 'hunter_level';
$cost = $type == 'gremlin' ? $gremlinParams['nextLevelCost'] : $hunterParams['nextLevelCost'];
$class_time = $type == 'gremlin' ? 'gremlin_time' : 'hunter_time';
$time = $type == 'gremlin' ? $gremlinParams['nextLevelTime'] : $hunterParams['nextLevelTime'];
if($tower->$class == 0) redirect('/towers/'.$type, 'Помощник ещё не куплен!');
if($u['silver'] < $cost) redirect('/towers', 'Недостаточно серебра');
if($tower->$class >= 15) redirect('/towers', 'Максимальный уровень!');
$db->query("UPDATE `users` SET `silver` = `silver` - '".$cost."' WHERE `id` = '".$u['id']."'");
$db->query("UPDATE `towers` SET `".$class."` = `".$class."` + '1', `".$class_time."` = '".(time()+$time*60)."' WHERE `id` = '"
.$tower->id
."'");
redirect('/towers/'.$type, 'Помощник улучшен!');
}
if(isset($_GET['get']))
{
$income = $type == 'gremlin' ? $gremlinParams['currentIncome'] : $hunterParams['currentIncome'];
$gems = $type == 'gremlin' ? ($tower->gremlin_dg == 0 ? $tower->gremlin_level : 0) : ($tower->hunter_dg == 0 ?
$tower->hunter_level : 0);
$time = $type == 'gremlin' ? time()+$gremlinParams['currentTime']*60 : time()+$hunterParams['currentTime']*60;
$time_class = $type == 'gremlin' ? 'gremlin_time' : 'hunter_time';
if($gems > 0) $type_dg = $type == 'gremlin' ? 'gremlin_dg' : 'hunter_dg';
$db->query("UPDATE `towers` SET `daily_gold` = `daily_gold` + '".$gems."', `".$type_dg."` = `".$type_dg."` + '".$gems."' WHERE `id` = '".$tower->id."'");
updateUserStats($u['id'],0,$income,$gems);
$db->query("UPDATE `towers` SET `".$time_class."` = '".$time."' WHERE `id` = '".$tower->id."'");
redirect('/towers', 'Доход собран!');
}
if($type == 'gremlin')
{
echo '
<div class="notice_container"><div class="gborder notice_alert alert-success">Гремлин ('.($tower->gremlin_level == 0 ? 'Гремлин не куплен' : ''.$tower->gremlin_level.' ур. из 15 ур.').')</div></div>
<div class="b">
<center>Маленький, но очень полезный помощник мага</center> </br>
<div class="wings mlra mb10"><div class="brd70"><div class="img70"
style="background-image:url(/images/towers/gremlin.png);
background-size: 100%;"></div></div></div>
<div class="w180x mlra bl">
<div class="pb10 fll nwr left"> '.($tower->gremlin_level == 0 ? 'Дохода нет' : 'Доход: <img src="/images/silver.png" width="16" height="16"> '.$gremlinParams['currentIncome'].' каждые ' .$gremlinParams['currentTime'].' мин.').' </br>
<span class="c_green">'.($tower->gremlin_level < 15 ? 'На след. ур. <img src="/images/silver.png" width="16" height="16"> '.$gremlinParams['nextLevelIncome'].' каждые <img src="/images/ico-hour.png" width="16" height="16"> '.$gremlinParams['nextLevelTime'].' мин.' : '(макс. ур.)').'</br>
</div>
</div>
</br><center>'.($tower->gremlin_level == 0 ? '<a class = "btn _green" href="/towers/gremlin/buy">Купить гремлина за <img src="/images/silver.png" width="16" height="16"> '.$gremlinCost.'</a>' : ($tower->gremlin_level == 15 ? '' : '<a class = "btn _blue" href="/towers/gremlin/up">Улучшить за <img src="/images/silver.png" width="16" height="16"> '.$gremlinParams['nextLevelCost'].'</a>')).'
</center>
</div>';
}
if($type == 'hunter')
{
echo '
<div class="notice_container"><div class="gborder notice_alert alert-success">Охотник ('.($tower->hunter_level == 0 ? 'Охотник не куплен' : ''.$tower->hunter_level.' ур. из 15 ур.').')</div></div>
<div class="b">
<center>Искусный воин и меткий стрелок</center> </br>
<div class="wings mlra mb10"><div class="brd70"><div class="img70"
style="background-image:url(/images/towers/hunter.png);
background-size: 100%;"></div></div></div>
<div class="w180x mlra bl">
<div class="pb10 fll nwr left"> '.($tower->hunter_level == 0 ? 'Дохода нет' : 'Доход: <img src="/images/silver.png" width="16" height="16"> '.$hunterParams['currentIncome'].' каждые ' .$hunterParams['currentTime'].' мин.').' </br>
<span class="c_green">'.($tower->hunter_level < 15 ? 'На след. ур. <img src="/images/silver.png" width="16" height="16"> '.$hunterParams['nextLevelIncome'].' каждые <img src="/images/ico-hour.png" width="16" height="16"> '.$hunterParams['nextLevelTime'].' мин.' : '(макс. ур.)').'</br>
</div>
</div>
</br><center>'.($tower->hunter_level == 0 ? '<a class = "btn _green" href="/towers/hunter/buy">Купить охотника за <img src="/images/silver.png" width="16" height="16"> '.$hunterCost.'</a>' : ($tower->hunter_level == 15 ? '' : '<a class = "btn _blue" href="/towers/hunter/up">Улучшить за <img src="/images/silver.png" width="16" height="16"> '.$hunterParams['nextLevelCost'].'</a>')).'
</center>
</div>';
}
echo'<div class = "line"></div><a href = "/towers"><div class = "b"><center> Назад</center></div></a>';
include_once ($root.'/core/foot.php');