Файл: public_html/core/modules.func.php
Строк: 671
<?php
$max_rating = 30000;
function updateCaveAttack()
{
global $db, $u;
if($u['cave_attacks'] == 10)
{
$db->query("UPDATE `users` SET `cave_attacks` = `cave_attacks` - '1', `cave_restore_time` = '".(time()+600)."' WHERE `id` = '".$u['id']."'");
}
else
{
$db->query("UPDATE `users` SET `cave_attacks` = `cave_attacks` - '1' WHERE `id` = '".$u['id']."'");
}
return true;
}
function restoreCaveAttack()
{
global $db, $u;
if($u['cave_attacks'] < 10)
{
if($u['cave_restore_time'] <= time())
{
if($u['cave_attacks'] == 9)
{
$db->query("UPDATE `users` SET `cave_attacks` = `cave_attacks` + '1' WHERE `id` = '".$u['id']."'");
redirect('/caves');
}
else
{
$db->query("UPDATE `users` SET `cave_attacks` = `cave_attacks` + '1', `cave_restore_time` = `cave_restore_time` + '600' WHERE `id` = '".$u['id']."'");
redirect('/caves');
}
}
}
return true;
}
function getChanceDropResource()
{
$chance = rand(1,100);
if($chance >=1 && $chance <= 5)
{
return rand(1,4);
}
else
{
return 0;
}
}
function dropResource($type)
{
global $db, $u;
$count = rand(1,2);
$db->query("UPDATE `resources` SET `count` = `count` + '".$count."' WHERE `resource_type` = '".$type."'");
campaignUpdate($u['id'],4,3,$count,[0],[0]);
return ['resources' => $count, 'restype' => $type];
}
function getExp()
{
global $db, $u;
$damage = rand(1000,5000);
$exp = floor($damage/100);
$vipBoost = getVipBoost($u['id']);
$leagueBoost = getLeagueBonus($u['id']);
updateUserStats($u['id'], $exp, 0, 0);
return ['damage' => $damage, "exp" => round($exp*$vipBoost->exp*$leagueBoost['exp'])];
}
function getMegaBonus()
{
global $db, $u;
if($u['cave_bonus'] == 1)
{
$chance = rand(1,100);
if($chance == 50)
{
$db->query("UPDATE `users` SET `cave_bonus` = '0' WHERE `id` = '".$u['id']."'");
updateUserStats($u['id'], 0, 0, 50);
$message = ['chest' => 1];
}
}
else
{
$message = null;
}
return $message;
}
function getGems()
{
global $db, $u;
$chance = rand(1,20);
if($chance == 10)
{
updateUserStats($u['id'], 0, 0, 1);
$message = ['gems' => 1];
}
else
{
$message = null;
}
return $message;
}
function addResources()
{
global $db, $u;
$resources = ['res1', 'res2', 'res3', 'res4'];
for($i=0;$i<4;$i++)
{
$resource = $db->query("SELECT * FROM `resources` WHERE `resource_type` = '".$resources[$i]."' AND `user` = '".$u['id']."'")->num_rows;
if($resource == 0) $db->query("INSERT INTO `resources` (`user`,`resource_type`) VALUES ('".$u['id']."', '".$resources[$i]."')");
}
}
function getRandOpponentForBattleground($issetOpponent = 0)
{
global $db, $u;
$player = $db->query("SELECT * FROM `battleground_players` WHERE `battle` = '".$u['battleground_id']."' AND `user` = '".$u['id']."'")->fetch_object();
if($issetOpponent == 0)
{
$randOpponent = $db->query("SELECT * FROM `battleground_players` WHERE `battle` = '".$u['battleground_id']."' AND `user` != '".$u['id']."' AND `health` > '0' ORDER BY RAND() LIMIT 1")->fetch_object();
$db->query("UPDATE `battleground_players` SET `opponent` = '".$randOpponent->user."' WHERE `battle` = '".$u['battleground_id']."' AND `user` = '".$u['id']."'");
}
else
{
$randOpponent = $db->query("SELECT * FROM `battleground_players` WHERE `battle` = '".$u['battleground_id']."' AND `user` != '".$u['id']."' AND `user` != '".$player->opponent."' AND `health` > '0' ORDER BY RAND() LIMIT 1")->fetch_object();
$db->query("UPDATE `battleground_players` SET `opponent` = '".$randOpponent->user."' WHERE `battle` = '".$u['battleground_id']."' AND `user` = '".$u['id']."'");
}
return true;
}
function updateBattleGroundRating($user_id, $rate, $type)
{
global $db;
$us = $db->query("SELECT * FROM `users` WHERE `id` = '".$user_id."'")->fetch_object();
if($type == '+')
{
$rating = $rate;
$db->query("UPDATE `users` SET `battleground_rating` = `battleground_rating` + '".$rating."' WHERE `id` = '".$user_id."'");
campaignUpdate($user_id,3,4,$rate,[0],[0]);
campaignUpdate($user_id,5,1,$rate,[0],[0]);
}
else
{
if($rate >= $us->battleground_rating) $rating = $us->battleground_rating;
else $rating = $rate;
$db->query("UPDATE `users` SET `battleground_rating` = `battleground_rating` - '".$rating."' WHERE `id` = '".$user_id."'");
}
return true;
}
function issetLocationBattles()
{
global $db, $u;
$battles = $db->query("SELECT * FROM `locations_battles` WHERE `user` = '".$u['id']."'")->num_rows;
if($battles > 0)
{
$btl = $db->query("SELECT * FROM `locations_battles` WHERE `user` = '".$u['id']."' LIMIT 1")
->fetch_object();
return redirect('/locations/'.$btl->location.'/battle');
}
else
{
return false;
}
}
function locationResult($btl_id, $loc_id, $mob_name)
{
global $db, $u, $memcache;
$battle = $db->query("SELECT * FROM `locations_battles` WHERE `id` = '".$btl_id."'");
if($battle->num_rows == 0) return false;
$battle = $battle->fetch_object();
$mob = $db->query("SELECT * FROM `locations_mobs` WHERE `id` = '".$battle->mob."'")->fetch_object();
$vipBoost = getVipBoost($u['id']);
$leagueBoost = getLeagueBonus($u['id']);
if($battle->my_health > 0 && $battle->mob_health <= 0)
{
$crown = dropCrowns();
if($crown == 1) $crownMsg = '1 корона, ';
else $crownMsg = null;
$resultMsg = 'Вы победили '.$mob->name.'! Награда: '.$crownMsg.round($mob->exp*$vipBoost->exp*$leagueBoost['exp']).' опыта и '.round($mob->silver*$vipBoost->silver*$leagueBoost['exp']).' серебра!';
updateUserStats($u['id'], $mob->exp, $mob->silver, 0);
$db->query("UPDATE `locations_mobs` SET `cooldown_time` = '".(time()+15)."' WHERE `id` = '".$battle->mob."'");
$db->query("DELETE FROM `locations_battles` WHERE `id` = '".$btl_id."'");
campaignUpdate($u['id'],2,4,1,['Йорогумо'],[$mob_name]);
campaignUpdate($u['id'],3,3,1,['Kaппa'],[$mob_name]);
campaignUpdate($u['id'],6,4,1,['Менехуне'],[$mob_name]);
questUpdate($u['id'],2);
return redirect('/locations', $resultMsg);
}
elseif($battle->my_health <= 0 && $battle->mob_health <= 0)
{
$resultMsg = 'Ничья! Награда: '.round(5*$vipBoost->exp*$leagueBoost['exp']).' опыта и '.round(10*$vipBoost->silver*$leagueBoost['exp']).' серебра!';
updateUserStats($u['id'], 5, 10, 0);
$memcache->delete('log_'.$u['id'].'',0);
$db->query("DELETE FROM `locations_battles` WHERE `id` = '".$btl_id."'");
return redirect('/locations', $resultMsg);
}
elseif($battle->my_health <= 0 && $battle->mob_health > 0)
{
$resultMsg = 'Вы проиграли!';
$memcache->delete('log_'.$u['id'].'',0);
$db->query("DELETE FROM `locations_battles` WHERE `id` = '".$btl_id."'");
return redirect('/locations/'.$loc_id, $resultMsg);
}
}
function updateAllianceExp($uid, $exp)
{
global $db;
$us_info = $db->query("SELECT * FROM `users` WHERE `id` = '".$uid."'")->fetch_object();
$db->query("UPDATE `alliances` SET `exp` = `exp` + '".$exp."' WHERE `id` = '".$us_info->alliance_id."'");
$db->query("UPDATE `alliance_members` SET `exp` = `exp` + '".$exp."' WHERE `alliance` = '".$us_info->alliance_id."' AND `user` = '".$uid."'");
campaignUpdate($uid,7,3,$exp,[0],[0]);
return true;
}
function getDamage($userDamage, $opponentDefense, $out=0)
{
if($userDamage > $opponentDefense)
{
$min_damage = round($userDamage/2);
$max_damage = round($userDamage/1.5);
}
elseif($userDamage == $opponentDefense)
{
$min_damage = round($userDamage/4);
$max_damage = round($userDamage/3);
}
else
{
$min_damage = round($userDamage/6);
$max_damage = round($userDamage/5);
}
if($out == 1) return ['min_damage' => $min_damage, 'max_damage' => $max_damage];
else return rand($min_damage, $max_damage);
}
function updateUserStats($user_id, $exp, $silver, $gems)
{
global $db;
$user = $db->query("SELECT * FROM `users` WHERE `id` = '".$user_id."'")->fetch_object();
$vip = getVipBoost($user_id);
$leagueBoost = getLeagueBonus($user_id);
$altarBoost = getAltarBoost($id);
$finalExp = $exp*$vip->exp*$leagueBoost['exp']+round($exp*$altarBoost->exp);
$finalSilver = $silver*$vip->silver*$leagueBoost['silver']+round($silver*$altarBoost->silver);
$finalGems = $gems;
if($user->alliance_id != 0) updateAllianceExp($user_id, $finalExp);
$db->query("UPDATE `users` SET `exp` = `exp` + '".$finalExp."', `silver` = `silver` + '".$finalSilver."', `gold` = `gold` + '".$finalGems."' WHERE `id` = '".$user->id."'");
return true;
}
function allianceStatus($status)
{
global $u;
if($status == 0)
{
if($u['alliance_id'] != 0) redirect('/alliance/my');
}
else
{
if($u['alliance_id'] == 0) redirect('/alliance');
}
}
function allianceInfo($alliance_id, $column)
{
global $db;
$allianceInfo = $db->query("SELECT * FROM `alliances` WHERE `id` = '".$alliance_id."'");
if($allianceInfo->num_rows == 0) return 'error';
$allianceInfo = $allianceInfo->fetch_object();
return $allianceInfo->$column;
}
function loggingAllianceAction($msg)
{
global $db, $u;
$db->query("INSERT INTO `alliance_journal` (alliance, msg, time) VALUES ('".$u['alliance_id']."', '".$msg."', '".time()."')");
}
function getAllianceReward($level)
{
global $db;
$exp = 1000;
$silver = 2000;
$gems = 10;
if($level > 1)
{
$levels = $db->query("SELECT * FROM `alliance_chest_levels` WHERE `level` <= '".$level."'");
while($l = $levels->fetch_object())
{
$exp += $l->alliance_exp;
$silver += $l->alliance_silver;
$gems += $l->alliance_gems;
}
}
return ['exp' => $exp, 'silver' => $silver, 'gems' => $gems];
}
function getUserReward($level)
{
global $db;
$exp = 100;
$silver = 200;
$gems = 1;
if($level > 1)
{
$levels = $db->query("SELECT * FROM `alliance_chest_levels` WHERE `level` <= '".$level."'");
while($l = $levels->fetch_object())
{
$exp += $l->user_exp;
$silver += $l->user_silver;
$gems += $l->user_gems;
}
}
return ['exp' => $exp, 'silver' => $silver, 'gems' => $gems];
}
function dropCrowns()
{
global $db, $u;
$event = $db->query("SELECT * FROM `events_config` WHERE `event_name` = 'alliance_chest'")->fetch_object();
if($event->status == 1)
{
$rand = rand(1,3);
if($rand == 2)
{
$db->query("UPDATE `alliances` SET `chest_crowns` = `chest_crowns` + '1' WHERE `id` = '".$u['alliance_id']."'");
$db->query("UPDATE `alliance_members` SET `crowns` = `crowns` + '1' WHERE `alliance` = '".$u['alliance_id']."' AND `user` = '".$u['id']."'");
campaignUpdate($u['id'],7,1,1,[0],[0]);
return 1;
}
else return 0;
}
}
function captureResult($id)
{
global $db;
$btl = $db->query("SELECT * FROM `capture_battles` WHERE `id` = '".$id."'")->fetch_object();
if($btl->status == 'battle' && ($btl->endtime <= time() || $btl->tower_health <= 0))
{
$players = $db->query("SELECT * FROM `capture_players` WHERE `battle` = '".$id."'");
if($btl->side1_damage > $btl->side2_damage) $winner = 1;
elseif($btl->side1_damage == $btl->side2_damage) $winner = 0;
else $winner = 2;
$exp = rand(1000,2500);
$silver = rand(2000,5000);
if($winner != 0)
{
$winner_exp = round($exp*1.5);
$winner_silver = round($silver*1.5);
}
if($winner == 0)
{
while($pl = $players->fetch_object())
{
updateUserStats($pl->user, $exp, $silver, 0);
$captureResult = 'Ничья! Награда: '.$exp.' опыта и '.$silver.' серебра!';
$db->query("UPDATE `users` SET `capture_result` = '".$captureResult."' WHERE `id` = '".$pl->user."'");
}
}
else
{
while($pl = $players->fetch_object())
{
if($pl->side == $winner)
{
updateUserStats($pl->user, $winner_exp, $winner_silver, 0);
$captureResult = 'Победа! Награда: '.$winner_exp.' опыта и '.$winner_silver.' серебра!';
}
else
{
updateUserStats($pl->user, $exp, $silver, 0);
$captureResult = 'Поражение! Награда: '.$exp.' опыта и '.$silver.' серебра!';
}
$db->query("UPDATE `users` SET `capture_result` = '".$captureResult."' WHERE `id` = '".$pl->user."'");
}
}
$db->query("UPDATE `capture_battles` SET `status` = 'end' WHERE `id` = '".$btl->id."'");
}
return true;
}
function setTutorialNum($num)
{
global $u, $db;
$db->query("UPDATE `users` SET `tutorial` = '".$num."' WHERE `id` = '".$u['id']."'");
return true;
}
function campaignUpdate($uId, $chapter, $quest, $count, $requirement, $result)
{
global $db;
$u = $db->query("SELECT * FROM `users` WHERE `id` = '".$uId."'")->fetch_assoc();
if($chapter == $u['campaign_chapter'])
{
$questUser = $db->query("SELECT * FROM `campaign_user` WHERE `user` = '".$u['id']."' AND `quest` = '".$quest."' AND `chapter` = '".$chapter."'");
if($questUser->num_rows == 0)
{
$db->query("INSERT INTO `campaign_user` (user, chapter, quest) VALUES ('".$u['id']."', '".$chapter."', '".$quest."')");
}
$qU = $questUser->fetch_object();
$questInfo = $db->query("SELECT * FROM `campaign_quests` WHERE `chapter` = '".$chapter."' AND `quest` = '".$quest."'")->fetch_object();
if($requirement == $result && $qU->count < $questInfo->target)
{
$db->query("UPDATE `campaign_user` SET `count` = `count` + '".$count."' WHERE `user` = '".$u['id']."' AND `quest` = '".$quest."' AND `chapter` = '".$chapter."'");
}
}
return true;
}
function addQuest()
{
global $u, $db;
$quests = $db->query("SELECT * FROM `quests` WHERE `stage` = '1'");
while($qu = $quests->fetch_object())
{
$qUs = $db->query("SELECT * FROM `quest_user` WHERE `quest` = '".$qu->quest."' AND `user` = '".$u['id']."'");
if($qUs->num_rows == 0)
{
$db->query("INSERT INTO `quest_user` (user, quest, stage) VALUES ('".$u['id']."', '".$qu->quest."', '1')");
}
}
return true;
}
function questUpdate($uid, $quest_id, $count=1)
{
global $db;
$quest = $db->query("SELECT * FROM `quest_user` WHERE `quest` = '".$quest_id."' AND `user` = '".$uid."'")->fetch_object();
if($quest->rewarded == 0)
{
$db->query("UPDATE `quest_user` SET `count` = `count` + '".$count."' WHERE `id` = '".$quest->id."'");
}
}
function getVipBoost($uId)
{
global $db;
$us = $db->query("SELECT * FROM `users` WHERE `id` = '".$uId."'")->fetch_object();
if($us->vip_type == 1) return (object) ['exp' => 1.15, 'silver' => 1.15, 'params' => 30];
elseif($us->vip_type == 2) return (object) ['exp' => 1.5, 'silver' => 1.5, 'params' => 70];
elseif($us->vip_type == 3) return (object) ['exp' => 2, 'silver' => 2, 'params' => 300];
else return (object) ['exp' => 1, 'silver' => 1, 'params' => 0];
}
function updateVipStatus()
{
global $db, $u;
if($u['vip_type'] > 0 && $u['vip_time'] <= time()) $db->query("UPDATE `users` SET `vip_type` = '0', `vip_time` = '0' WHERE `id` = '".$u['id']."'");
return true;
}
function checkReferals()
{
global $db;
$refs = $db->query("SELECT * FROM `referals` WHERE `rewarded` = '0'");
while($r = $refs->fetch_object())
{
$usInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$r->referal."'")->fetch_object();
if($usInfo->level >= 15)
{
$db->query("UPDATE `referals` SET `rewarded` = '1' WHERE `id` = '".$r->id."'");
updateUserStats($r->user,0,0,5);
updateUserStats($r->referal,0,0,20);
}
}
}
function getCompletedCampaignOrQuest($type)
{
global $db, $u;
if($type == 'campaign')
{
$count = 0;
$camp_quest = $db->query("SELECT * FROM `campaign_user` WHERE `chapter` = '".$u['campaign_chapter']."' AND `user` = '".$u['id']."'");
while($cq = $camp_quest->fetch_object())
{
$camp = $db->query("SELECT * FROM `campaign_quests` WHERE `chapter` = '".$u['campaign_chapter']."' AND `quest` = '".$cq->quest."'")->fetch_object();
if($cq->count >= $camp->target) $count++;
}
if($count >= $camp_quest->num_rows) return 1;
else return 0;
}
elseif($type == 'tasks')
{
$count = 0;
$questUser = $db->query("SELECT * FROM `quest_user` WHERE `user` = '".$u['id']."' AND `rewarded` = '0'");
while($qU = $questUser->fetch_object())
{
$questInfo = $db->query("SELECT * FROM `quests` WHERE `quest` = '".$qU->quest."' AND `stage` = '".$qU->stage."'")->fetch_object();
if($qU->count >= $questInfo->target) $count++;
}
if($count > 0) return 1;
else return 0;
}
}
function setUserStats()
{
global $db, $u;
if($u['health_stat'] != get_health($u['id']) || $u['power_stat'] != get_power($u['id']) || $u['block_stat'] != get_block($u['id']))
{
$db->query("UPDATE `users` SET `health_stat` = '".get_health($u['id'])."', `power_stat` = '".get_power($u['id'])."', `block_stat` = '".get_block($u['id'])."' WHERE `id` = '".$u['id']."'");
}
return true;
}
function setAntiSpamTime($time)
{
global $db, $u;
$db->query("UPDATE `users` SET `antispam` = '".(time()+$time)."' WHERE `id` = '".$u['id']."'");
return true;
}
function getLeagueBonus($uId)
{
global $db, $max_rating;
$userInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$uId."'")->fetch_object();
if($userInfo->battleground_rating >= $max_rating)
{
$league = $db->query("SELECT * FROM `battleground_leagues` WHERE `id` >= '10' LIMIT 1")->fetch_object();
}
else
{
$league = $db->query("SELECT * FROM `battleground_leagues` WHERE `min_rating` >= '".$u['battleground_rating']."' LIMIT 1")->fetch_object();
}
$bonus = 1+($league->exp_bonus/100);
return ['exp' => $bonus, 'silver' => $bonus];
}
function dropStar($uId)
{
global $db;
$chance = rand(1,2);
if($chance == 1)
{
$db->query("UPDATE `users` SET `stars` = `stars` + '1' WHERE `id` = '".$uId."'");
return 1;
}
return 0;
}
function getAvatar($id, $width=110, $height=160)
{
global $db;
$userInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$id."'")->fetch_object();
if($userInfo->avatar == '0.jpg')
{
if($userInfo->sex == 0) $avatar = '/0.png';
else $avatar = '/1.png';
}
else $avatar = '/images/avatars/'.$userInfo->avatar;
return '<img src="'.$avatar.'" width="'.$width.'" height="'.$height.'">';
}
function isDungeon()
{
global $db, $u;
$issetLeader = $db->query("SELECT * FROM `dungeon_battles` WHERE `leader` = '".$u['id']."'");
$issetBtl = $db->query("SELECT * FROM `dungeon_players` WHERE `user` = '".$u['id']."'");
if($issetLeader->num_rows > 0)
{
$issetLeaderQ = $issetLeader->fetch_object();
redirect('/dungeon/battle/'.$issetLeaderQ->id);
}
if($issetBtl->num_rows > 0)
{
$issetBtlQ = $issetBtl->fetch_object();
redirect('/dungeon/battle/'.$issetBtlQ->battle);
}
return true;
}
function addStageMobs($battle, $dungeon, $stage)
{
global $db;
$mob = $db->query("SELECT * FROM `dungeon_stages` WHERE `dungeon` = '".$dungeon."' AND `stage` = '".$stage."'")
->fetch_object();
for($i=0;$i<$mob->count;$i++)
{
$db->query("INSERT INTO `dungeon_mobs` (`battle`,`stage`,`health`,`attack_cd`) VALUES ('".$battle."', '".$stage."', '".$mob->health."', '".(time()+rand(3,10))."')");
}
return true;
}
function getSkillBonus($skill)
{
global $u;
if($skill == 'heal')
{
$heal_percent = ceil(get_health($u['id'])*0.1);
$hh_percent = ceil(get_health($u['id'])*0.01);
$skill_bonus = $heal_percent+($hh_percent*(($u['heal_skill'] == 1) ? 0 : ($u['heal_skill']-1)));
}
else
{
$arrow_percent = ceil(get_power($u['id'])*0.03);
$skill_bonus = (get_power($u['id'])*2)+($arrow_percent*(($u['arrow_skill'] == 1) ? 0 : ($u['arrow_skill']-1)));
}
return $skill_bonus;
}
function dungeonMobAttacks()
{
global $db;
$attacks = [' ударил', ' зацепил', ' порезал'];
$dungeons = $db->query("SELECT * FROM `dungeon_battles` WHERE `status` = 'battle'");
if($dungeons->num_rows > 0)
{
while($dung = $dungeons->fetch_object())
{
$mob = $db->query("SELECT * FROM `dungeon_stages` WHERE `dungeon` = '".$dung->dungeon."' AND `stage` = '".$dung->stage."'")->fetch_object();
$mobs = $db->query("SELECT * FROM `dungeon_mobs` WHERE `battle` = '".$dung->id."' AND `health` > '0'");
while($m = $mobs->fetch_object())
{
if($m->attack_cd <= time())
{
$cd = rand(3,10);
$randPlayer = $db->query("SELECT * FROM `dungeon_players` WHERE `health` > '0' AND `battle` = '".$dung->id."' ORDER BY RAND() LIMIT 1")->fetch_object();
$dmg = getDamage($mob->damage, get_block($randPlayer->user));
$db->query("UPDATE `dungeon_players` SET `health` = `health` - '".$dmg."' WHERE `id` = '".$randPlayer->id."'");
$db->query("UPDATE `dungeon_mobs` SET `attack_cd` = '".(time()+$cd)."' WHERE `id` = '".$m->id."'");
$log = $mob->mob_name.$attacks[rand(0,2)].' '.name($randPlayer->user).' на '.$dmg.'.';
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('dungeon', '".$dung->id."', '".$log."', '".time()."')");
}
}
}
}
return true;
}
function setTextColor($author, $text)
{
global $db;
$usInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$author."'")->fetch_object();
if($usInfo->admin == 2) $color = 'orange';
elseif($usInfo->admin == 3) $color = 'lightblue';
else $color = 'white';
return '<font color="'.$color.'">'.$text.'</font>';
}
function getTrainCost($level)
{
$costs = [null,null,100,150,200,250,300,350,400,450,10,650,850,1050,1250,1450,1650,1850,2050,2250,25,2750,3250,
3750,4250,4750,5250,5750,6250,6750,50,7500,8250,9000,9750,10500,11250,12000,12750,13500,75,14500,15500,16500,
17500,18500,19500,20500,21500,22500,100,24000,25500,27000,28500,30000,31500,33000,34500,36000,150,38000,
40000,42000,44000,46000,48000,50000,52000,54000,200,57000,60000,63000,66000,69000,72000,75000,78000,81000,
300,85500,90000,94500,99000,103500,108000,112500,117000,121500,500,127500,133500,139500,145500,151500,157500,
163500,169500,175500,750];
return $costs[$level+1];
}
function ifNotExistTower()
{
global $u, $db;
$query = $db->query("SELECT * FROM `towers` WHERE `user` = '".$u['id']."'");
if($query->num_rows == 0)
{
$db->query("INSERT INTO `towers` (`user`) VALUES ('".$u['id']."')");
}
return true;
}
function getGremlinParams($level, $wizardLevel)
{
$cost = [null,null,600,800,1000,1200,2400,4800,9600,19200,38400,76800,153600,307200,614400,1228800];
$income = [null,50,110,362,790,1790,2685,4028,6041,9062,13593,20389,30584,45876,68814,103221];
$time = [null,3,5,7,10,15,23,34,51,76,114,171,256,384,577,865,1297];
$wizardBonus = getWizardParams($wizardLevel);
return ['nextLevelCost' => $cost[$level+1], 'currentIncome' => $income[$level]+$wizardBonus['currentIncome'], 'nextLevelIncome' => $income[$level+1]+$wizardBonus['currentIncome'], 'currentTime' => $time[$level], 'nextLevelTime' => $time[$level+1]];
}
function getHunterParams($level, $wizardLevel)
{
$cost = [null,null,600,800,1000,1200,2400,4800,9600,19200,38400,76800,153600,307200,614400,1228800];
$income = [null,880,1320,1980,2970,4455,6683,10024,15036,22553,33830,50745,76118,114177,171265,256897];
$time = [null,30,40,53,70,92,121,159,209,274,359,471,618,810,1062,1392];
$wizardBonus = getWizardParams($wizardLevel);
return ['nextLevelCost' => $cost[$level+1], 'currentIncome' => $income[$level]+$wizardBonus['currentIncome'], 'nextLevelIncome' => $income[$level+1]+$wizardBonus['currentIncome'], 'currentTime' => $time[$level], 'nextLevelTime' => $time[$level+1]];
}
function getWizardParams($level)
{
$cost = [null,null,5,10,15,17,19,20,22,25,27,30,33,36,39,43,48,52,57,63,69,76,84,92,101,112,123,135,148,163,179,197,217,238,262,288,317,349,384,422,464];
$params = [null,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,410];
$income = [null,90,117,153,199,259,337,439,571,743,966,1256,1633,2123,2760,3588,4665,6065,7885,10251,13327,17326,22524,29282,38067,49488,64335,83636,108727,141346,183750,238875,310538,403700,524810,682253,886929,1153008,1498911,1948585,2533160];
return ['nextLevelCost' => $cost[$level+1], 'currentParams' => $params[$level], 'nextLevelParams' => $params[$level+1], 'currentIncome' => $income[$level], 'nextLevelIncome' => $income[$level+1]];
}
function setStage($stage, $battle)
{
global $db;
$players = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$battle."'");
$bossHealth = 0;
while($pl = $players->fetch_object())
{
$db->query("UPDATE `demons_players` SET `health` = '".get_health($pl->user)."', `opponent` = '0' WHERE `id` = '".$pl->id."'");
$bossHealth += $pl->health;
}
if($stage == 'mobs')
{
$mobsCount = $players->num_rows*2;
$mobsAttack = 100;
$mobsBlock = 150;
$mobsHealth = 3000;
for($i=0;$i<$mobsCount;$i++)
{
$db->query("INSERT INTO `demons_mobs` (`battle`,`health`,`attack`,`defense`,`stage`) VALUES ('".$battle."', '".$mobsHealth."', '".$mobsAttack."', '".$mobsBlock."', 'mobs')");
}
$db->query("UPDATE `demons_battles` SET `stage` = 'mobs' WHERE `id` = '".$battle."'");
}
elseif($stage == 'boss')
{
$bH = round($bossHealth*1.5);
$bA = 250;
$bB = 250;
$db->query("INSERT INTO `demons_mobs` (`battle`,`health`,`attack`,`defense`,`stage`) VALUES ('".$battle."', '".$bH."', '".$bA."', '".$bB."', 'boss')");
$db->query("UPDATE `demons_battles` SET `stage` = 'boss' WHERE `id` = '".$battle."'");
$db->query("DELETE FROM `battle_logs` WHERE `type` = 'demons-mobs' AND `battle` = '".$battle."'");
}
elseif($stage == 'players')
{
$db->query("UPDATE `demons_battles` SET `stage` = 'players' WHERE `id` = '".$battle."'");
$db->query("DELETE FROM `battle_logs` WHERE `type` = 'demons-boss' AND `battle` = '".$battle."'");
}
return true;
}
function demonsMobAttack()
{
global $db,$u;
$btl = $db->query("SELECT * FROM `demons_battles` WHERE `status` = 'battle' LIMIT 1")->fetch_object();
$mobs = $db->query("SELECT * FROM `demons_mobs` WHERE `stage` = '".$btl->stage."' AND `battle` = '".$btl->id."' AND `health` > '0'");
while($m = $mobs->fetch_object())
{
if($m->attack_cd < time())
{
$attackCD = time()+rand(5,20);
$randPlayer = $db->query("SELECT * FROM `demons_players` WHERE `health` > '0' AND `battle` = '".$btl->id."' ORDER BY RAND() LIMIT 1")->fetch_object();
$damage = getDamage($m->attack, get_block($randPlayer->user));
if($btl->stage == 'mobs') $name = 'Прислужник Демона';
else $name = 'Демон';
$stage = 'demons-'.$btl->stage;
if($damage >= $randPlayer->health) $logMsg = $name.' убил '.name($randPlayer->user).'.';
else $logMsg = $name.' ударил '.name($randPlayer->user).' на '.$damage.'.';
$db->query("UPDATE `demons_players` SET `health` = `health` - '".$damage."' WHERE `id` = '".$randPlayer->id."'");
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('".$stage."', '".$btl->id."', '".$logMsg."', '".time()."')");
$db->query("UPDATE `demons_mobs` SET `attack_cd` = '".$attackCD."' WHERE `id` = '".$m->id."'");
}
}
return true;
}
function startDemons()
{
global $db;
$btl = $db->query("SELECT * FROM `demons_battles` WHERE `status` = 'prepare' ORDER BY `id` DESC LIMIT 1")->fetch_object();
if($btl->starttime <= time())
{
$players = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$btl->id."'");
$mobsCount = $players->num_rows*2;
$mobsAttack = 100;
$mobsBlock = 150;
$mobsHealth = 3000;
for($i=0;$i<$mobsCount;$i++)
{
$db->query("INSERT INTO `demons_mobs` (`battle`,`health`,`attack`,`defense`,`stage`) VALUES ('".$btl->id."', '".$mobsHealth."', '".$mobsAttack."', '".$mobsBlock."', 'mobs')");
}
$db->query("UPDATE `demons_battles` SET `stage` = 'mobs', `status` = 'battle' WHERE `id` = '".$btl->id."'");
}
}