View file element_labirint_battle.php

File size: 12.04Kb
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }

	$battle = readcache('element_labirint_duh_user'.$user['lost_id']); 		// Кэш с данными боя
	if (!$battle) { header('Location: /labirint'); exit; }					// Если нет кэша переадр. в лабиринт
	require_once './element_function/element_function_battle.php';
	
	$journal = readcache('element_labirint_journal'.$user['lost_id']);
	if (!is_array($journal)) $journal = array();
	$count_journal = count($journal);
		
		$my_uron = 0;
		$bot_uron = 0;
		
		$abil_ogon = AbilitiesOgon($user['lost_abilities_ogon'], $user['lost_race'], false, $user['lost_id']);
		$abil_voda = AbilitiesVoda($user['lost_abilities_voda'], $user['lost_race'], false, $user['lost_id']);
		$abil_zeml = AbilitiesZemlya($user['lost_abilities_zemlya'], $user['lost_race'], false, $user['lost_id']);
		$abil_vosd = AbilitiesVozdyh($user['lost_abilities_vozduh'], $user['lost_race'], false, $user['lost_id']);
		$add_hp = 0;
		
		$time_bot = explode(' ', $battle['duh']['time_udar']);
		$time_fre = explode(' ', microtime());
		$time_udar_bot = ceil(($time_fre[1] + $time_fre[0]) - ($time_bot[1] + $time_bot[0]));
		$rand_udar_s = 4;
		
		
		if ($time_udar_bot > $rand_udar_s) {
			$other_count_udat = (int)($time_udar_bot / $rand_udar_s);
			
			for($i = 0; $i < $other_count_udat; $i++) {
				$uron = GenerationUron($battle['duh']['str'], $battle['duh']['time_udar'], 0, 0, $abil_zeml['add_procent'], GenerationProtection($user['lost_params_protection']));
				
				$battle['user']['hp'] = $battle['user']['hp'] - $uron;
				array_unshift($journal, '<span class="small red"><img src="/images/icons/arena.gif"> '.$battle['duh']['name'].' ударил '.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' на <span class="bold">'.$uron.'</span> урон</span>');
			
				$bot_uron = $bot_uron + $uron;
				
					if ($battle['user']['hp'] <= 0) {
						require_once './element_function/element_function_labirint.php';
						$chanse = Element_Chance($battle['other']['etap'], 0);	// База шансов
						$labirint = explode(':', $user['lost_labirint']);
						
						$labirint[0] = time() + 3600;
						$labirint[1] = 0;
					
						$user['lost_labirint'] = implode(':', $labirint);
						update_money_exp($user, array('user' => $labirint[6], 'town' => $labirint[8]), $labirint[5], 0, $labirint[7]);
						
						$user_quests = user_quests($user['lost_id']);
						$count_quests = quests_id_count('labirint_3');
							if ($user_quests['labirint_3'] < $count_quests) {
								$user_quests['labirint_3'] = $user_quests['labirint_3'] + 1;
								if ($user_quests['labirint_3'] == $count_quests) $user_quests['lost_new'] = $user_quests['lost_new'] + 1;
								writecache('element_quests_user'.$user['lost_id'], $user_quests);	
								quests_list_update($user['lost_id']);
						}
						
						
						deletecache('element_labirint_journal'.$user['lost_id']);
						deletecache('element_users_battle'.$user['lost_id']);
						deletecache('element_labirint_duh_user'.$user['lost_id']);
						
						header('Location: /labirint?go=duh&lose&cristall='.$labirint[5].'&expoint='.$labirint[6].'&gold='.$labirint[7].'&etap='.$labirint[2]);
						exit; 
					}
			}
			$battle['duh']['time_udar'] = microtime();
		} else {
			$abil_zeml = abilities_race_zemlya(0, $abilities_zeml[2], $abilities_zeml[1], $abilities_zeml[3], $abilities_zeml[4], 0);
		}	
		
		if ($go == 'attaka') {
			$to = (isset($_GET['to'])) ? addslashes(htmlspecialchars($_GET['to'])) : false;
			
			// Активация Огненной силы
			if ($id == 1 AND !$abil_ogon['activate']) {
				$abil_ogon = AbilitiesOgon($user['lost_abilities_ogon'], $user['lost_race'], true, $user['lost_id']);
				$image = quality_item_name($user['lost_abilities_ogon']);
				array_unshift($journal, '<span class="small admin">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' активировал <span class="bold yellow1">'.$image['image'].' огненную силу</span></span>');
			}
			
			// Активация Водяного крита
			if ($id == 2 AND !$abil_voda['activate']) {
				$abil_voda = AbilitiesVoda($user['lost_abilities_voda'], $user['lost_race'], true, $user['lost_id']);
				$image = quality_item_name($user['lost_abilities_voda']);
				array_unshift($journal, '<span class="small admin">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' активировал <span class="bold yellow1">'.$image['image'].' водяной крит</span></span>');
			}
			
			// Активация Ловушки ветра
			if ($id == 3 AND !$abil_vosd['active']) {
				$abil_vosd = AbilitiesVozdyh($user['lost_abilities_vozduh'], $user['lost_race'], true, $user['lost_id']);
				$image = quality_item_name($user['lost_abilities_vozduh']);
				array_unshift($journal, '<span class="small admin">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' активировал <span class="bold yellow1">'.$image['image'].' ловушку ветра</span></span>');
						
				// Если шанс сработал, забираем хп
				if ($abil_vosd['add_hp'] > 0) {
					$add_hp = (int)(($battle['user']['other_hp'] / 100) * $abil_vosd['add_hp']);
					$my_ras_hp = $battle['user']['other_hp'] - $battle['user']['hp'];
					if ($add_hp > $my_ras_hp) $add_hp = $my_ras_hp;
					$battle['duh']['hp'] = $battle['duh']['hp'] - $add_hp;
					$battle['user']['hp'] = $battle['user']['hp'] + $add_hp;
					$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="lngreen">Вы забрали у <span class="bold">'.$cache_user['lost_login'].' '.$add_hp.'</span> здоровья</span>';
					$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="error1"><span class="bold">'.$user['lost_login'].'</span> забрал у Вас <span class="bold">'.$add_hp.'</span> здоровья</span>';
					array_unshift($journal, '<span class="small admin">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' забрал у '.$battle['duh']['name'].' <span class="bold">'.$add_hp.'</span> здоровья</span>');
				}
			}
			
			// Активация Земляной стойкости
			if ($id == 4 AND !$abil_zeml['activate']) {
				$abil_zeml = AbilitiesZemlya($user['lost_abilities_zemlya'], $user['lost_race'], true, $user['lost_id']);
				$image = quality_item_name($user['lost_abilities_zemlya']);
				array_unshift($journal, '<span class="small admin">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' активировал <span class="bold yellow1">'.$image['image'].' земляной щит</span></span>');
			}
			
			$user_uron = GenerationUron($user['lost_params_strlen'], $battle['user']['time_udar'], $abil_ogon['add_procent'], $abil_voda['add_procent'], 0, GenerationProtection($battle['duh']['pr']));
			
			array_unshift($journal, '<span class="small yellow1">'.ikonka_user($user['lost_race'], 'online').' '.$user['lost_login'].' ударил '.$battle['duh']['name'].' на <span class="bold">'.$user_uron.'</span> урон '.(($abit_voda[1]) ? 'крит' : '').'</span>');
			$battle['duh']['hp'] = $battle['duh']['hp'] - $user_uron;
			$battle['user']['time_udar'] = microtime();
			$my_uron = $user_uron;
			
				if ($battle['duh']['hp'] <= 0) {
					require_once './element_function/element_function_labirint.php';
					$chanse = Element_Chance($battle['other']['etap'], 0);	// База шансов
					$labirint = explode(':', $user['lost_labirint']);
					
					$exp = handler_expoint($chanse[3], $user['lost_add_user_exp'], $user['lost_add_town_exp']);
					$crst = handler_cristalls($chanse[2], $user_blessing['nagrada']);
				
					$labirint[2] = $labirint[2] + 1;			// Переходим на +1 этап
					$labirint[5] = $labirint[5] + $crst;		// Добавляем кристаллы
					$labirint[6] = $labirint[6] + $exp['user'];	// Добавляем личный опыт
					$labirint[8] = $labirint[8] + $exp['town'];	// Добавляем городской опыт
					$labirint[4] = 0;							// Забырием духа
					
				
				
					if ($battle['other']['etap'] < 9) {
						if (5 >= rand(1,100)) {
							$labirint[7] = $labirint[7] + $chanse[4];
							$gold = $chanse[4];
						} else $gold = 0;
						
						$user['lost_labirint'] = implode(':', $labirint);

						writecache('element_users_id_'.$user['lost_id'], $user);
						user_list_update($user['lost_id']);
						
						deletecache('element_labirint_journal'.$user['lost_id']);
						deletecache('element_users_battle'.$user['lost_id']);
						deletecache('element_labirint_duh_user'.$user['lost_id']);
						
						header('Location: /labirint?go=duh&cristall='.$chanse[2].'&expoint='.$exp['user'].'&gold='.$gold.'&etap='.$labirint[2].'');
						exit;
					} else {
						$labirint[7] = $labirint[7] + $chanse[4];
						$labirint[0] = time() + 3600;
						$labirint[1] = 0;
					
						$user['lost_labirint'] = implode(':', $labirint);
						update_money_exp($user, array('user' => $labirint[6], 'town' => $labirint[8]), $labirint[5], 0, $labirint[7]);
						
						$user_quests = user_quests($user['lost_id']);
						$count_quests = quests_id_count('labirint_3');
							if ($user_quests['labirint_3'] < $count_quests) {
								$user_quests['labirint_3'] = $user_quests['labirint_3'] + 1;
								if ($user_quests['labirint_3'] == $count_quests) $user_quests['lost_new'] = $user_quests['lost_new'] + 1;
								writecache('element_quests_user'.$user['lost_id'], $user_quests);	
								quests_list_update($user['lost_id']);
						}
						
						$user_quests = user_quests($user['lost_id']);
						$count_quests = quests_id_count('labirint_all');
							if ($user_quests['labirint_all'] < $count_quests) {
								$user_quests['labirint_all'] = $user_quests['labirint_all'] + 1;
								if ($user_quests['labirint_all'] == $count_quests) $user_quests['lost_new'] = $user_quests['lost_new'] + 1;
								writecache('element_quests_user'.$user['lost_id'], $user_quests);	
								quests_list_update($user['lost_id']);
						}
						
						deletecache('element_labirint_journal'.$user['lost_id']);
						deletecache('element_users_battle'.$user['lost_id']);
						deletecache('element_labirint_duh_user'.$user['lost_id']);
						
						header('Location: /labirint?go=duh&win&cristall='.$labirint[5].'&expoint='.$labirint[6].'&gold='.$labirint[7].'&etap='.$labirint[2]);
						exit;
					}
				
				}
			
			writecache('element_labirint_journal'.$user['lost_id'], $journal);	
			writecache('element_labirint_duh_user'.$user['lost_id'], $battle);
		} else {
			writecache('element_labirint_journal'.$user['lost_id'], $journal);	
			writecache('element_labirint_duh_user'.$user['lost_id'], $battle);
		}
	
	
	$my_user = array('user_race' => $user['lost_race'], 'user_hp' => $battle['user']['hp'], 
					 'user_other_hp' => $battle['user']['other_hp'], 'user_name' => $user['lost_login'],
					 'user_uron' => $bot_uron, 'user_add_hp' => $add_hp);
				
	$no_user = array('user_race' => 0, 'user_hp' => $battle['duh']['hp'], 
					 'user_other_hp' => $battle['duh']['other_hp'], 'user_name' => $battle['duh']['name'],
					 'user_uron' => $my_uron, 'user_add_hp' => 0);
	
	$title = 'Лабирите : Бой';
	require_once './element_include/element_head.php';
	echo '<body><div class="p5">';
	
	echo '<div class="cntr small yellow1 mb5">';
	echo 'Этап: '.$battle['other']['etap'].', ';
	echo '<img src="/images/icons/clock.gif"> '.date("i:s", mktime(0, 0, (time() - $battle['other']['time'])));
	echo '</div>';
	
	EchoTableUsersBattle($my_user, $no_user);
	EchoAbiliteBattle($abil_ogon, $abil_voda, $abil_vosd, $abil_zeml, false, 'w19', '35', 0, '/labirint/battle');
	
	if ($count_journal > 0) {
	echo '<div class="nfl p5 mb5 small mlra">';
		foreach (array_slice($journal, 0, 10, true) as $value) {
			echo '<span class="white">'.$value.'<span><br/>';
		}
	echo '</div>';
	}
	
	require_once './element_include/element_foot_user_battle_true.php';
?>