Просмотр файла element_arena_pvp_battle.php

Размер файла: 13.04Kb
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }
	require_once './element_function/element_function_battle.php';

	// ID моей арены
	$my_pvp_id = readcache('element_users'.$user['lost_id'].'arena_pvp');
	if (!$my_pvp_id) { header('Location: /arena?pvp'); exit; }
	
	// Кэш с параметрами боя
	$arena = readcache('element_arena_pvp_teamid'.$my_pvp_id);
	if (!$arena) { header('Location: /arena?pvp'); exit; }
	
	if ($arena['user_1']['user'] == $user['lost_id']) { $my_user = 'user_1'; $no_user = 'user_2'; } else { $my_user = 'user_2'; $no_user = 'user_1'; }
	
	$cache_user = cache_user($arena[$no_user]['user']);
	
	$journal = readcache('element_arena_pvp_teamid'.$my_pvp_id.'journal');
	
	$timer = $arena['other']['timer'];
	
	// Если бой идет, играем, иначе показываем результат
	if ($arena['other']['active']) {
		
		$title = 'Арена: Золотая лига'; 
		require_once './element_include/element_head.php';
		echo '<body><div class="p5">';
		
		// Если тек. время. больше записанного, играем, иначе показываем отсчет к началу боя
		if (time() >= $arena['other']['timer']) {
			$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;
			
			if ($go == 'attaka') {
				// Активация Огненной силы
				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']);
					$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1">Вы активировали '.$image['image'].' <span class="bold">Огненную силу</span></span>';
					$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> активировал '.$image['image'].' <span class="bold">Огненную силу</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']);
					$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1">Вы активировали '.$image['image'].' <span class="bold">Водяной крит</span></span>';
					$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> активировал '.$image['image'].' <span class="bold">Водяной крит</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']);
					$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1">Вы активировали '.$image['image'].' <span class="bold">Ловушку ветра</span></span>';
					$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> активировал '.$image['image'].' <span class="bold">Ловушку ветра</span></span>';
						
					// Если шанс сработал, забираем хп
					if ($abil_vosd['add_hp'] > 0) {
						$add_hp = (int)(($arena[$no_user]['other_hp'] / 100) * $abil_vosd['add_hp']);
						$my_ras_hp = $arena[$my_user]['other_hp'] - $arena[$my_user]['battle_hp'];
						if ($add_hp > $my_ras_hp) $add_hp = $my_ras_hp;
						$arena[$no_user]['battle_hp'] = $arena[$no_user]['battle_hp'] - $add_hp;
						$arena[$my_user]['battle_hp'] = $arena[$my_user]['battle_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>';
					} else $journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="error1">Умение не сработало</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']);
					$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1">Вы активировали '.$image['image'].' <span class="bold">Земляную стройкость</span></span>';
					$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> активировал '.$image['image'].' <span class="bold">Земляную стойкость</span></span>';
				}
				
				$no_abil_zeml = AbilitiesZemlya($cache_user['lost_abilities_zemlya'], $cache_user['lost_race'], false, $cache_user['lost_id']);
			
				$uron = GenerationUron($user['lost_params_strlen'], $arena[$my_user]['time_udar'], $abil_ogon['add_procent'], $abil_voda['add_procent'], $no_abil_zeml['add_procent'], GenerationProtection($cache_user['lost_params_protection']));
				
				// Данные врага
				$arena[$no_user]['battle_hp'] = $arena[$no_user]['battle_hp'] - $uron;
				$arena[$no_user]['uron'] = $arena[$no_user]['uron'] + $uron;
				
				// Запись в журнал боя
				$journal[$user['lost_id']][KeyJournalMassiv($timer)] = 'Вы ударили <span class="yellow1 bold">'.$cache_user['lost_login'].'</span> на <span class="yellow1 bold">'.$uron.'</span> урон '.(($abil_voda['add_procent'] > 0) ? 'крит' : '');
				$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="error1"><span class="bold">'.$user['lost_login'].'</span> ударил Вас на <span class="bold">'.$uron.'</span> урон '.(($abil_voda['add_procent'] > 0) ? 'крит' : '').'</span>';
				
				// Мои данные
				$arena[$my_user]['battle_uron'] = $arena[$my_user]['battle_uron'] + $uron;
				$arena[$my_user]['time_udar'] = microtime();
				$arena[$my_user]['uron'] = 0;
				
					// Если я его убил
					if ($arena[$no_user]['battle_hp'] <= 0) {
						$arena['other']['active'] = false; 		// Заканчиваем бой
						
						// Кэш с золотом. Убираем золото с массива
						$cache_gold = readcache('element_arena_pvp_gold');
						if (is_array($cache_gold)) {
							unset($cache_gold[$cache_user['lost_id']]);
							unset($cache_gold[$user['lost_id']]);
						}
						
						// Сколько выдать золота
						$golda = (int)(($arena['other']['gold'] / 100) * 90);
						$golda1 = $golda + $arena['other']['gold'];
						
						// Обновляем данные врага
						$cache_user['lost_arena_pvp_rating'] = $cache_user['lost_arena_pvp_rating'] - 1;
						update_money_exp($cache_user, 0, 0, 0, 0);
						
						// Обновляем данные мои
						$user['lost_arena_pvp_rating'] = $user['lost_arena_pvp_rating'] + 1;
						update_money_exp($user, 0, 0, 1, $golda1);
						
						// Запись в журнал боя о его смерти
						$journal['other'][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> убил <span class="bold">'.$cache_user['lost_login'].'</span></span>';
						$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="admin bold">Вы победили. Награда: <img src="/images/icons/gold.png">'.$golda.' золота</span>';
						$journal[$cache_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="error1 bold">Вы проиграли <img src="/images/icons/gold.png">'.$golda.' золота</span>';
						
						// Перезапись кэша
						writecache('element_arena_pvp_teamid'.$my_pvp_id.'journal', $journal);
						writecache('element_arena_pvp_teamid'.$my_pvp_id, $arena);
						writecache('element_arena_pvp_gold', $cache_gold);
						header('Location: /arena/pvp/battle');
						exit;
					}
				
				writecache('element_arena_pvp_teamid'.$my_pvp_id.'journal', $journal);
				writecache('element_arena_pvp_teamid'.$my_pvp_id, $arena);
			} else $uron = 0;
			
			
			$my_user = array('user_race' => $user['lost_race'], 'user_hp' => $arena[$my_user]['battle_hp'], 
					   'user_other_hp' => $arena[$my_user]['other_hp'], 'user_name' => $user['lost_login'],
					   'user_uron' => $arena[$my_user]['uron'], 'user_add_hp' => $add_hp);
				
			$no_user = array('user_race' => $cache_user['lost_race'], 'user_hp' => $arena[$no_user]['battle_hp'], 
					   'user_other_hp' => $arena[$no_user]['other_hp'], 'user_name' => $cache_user['lost_login'],
					   'user_uron' => $uron, 'user_add_hp' => 0);
			
			echo '<div class="small mb5 cntr yellow1">';
			echo 'Ставка:  <img src="/images/icons/gold.png">'.$arena['other']['gold'].', ';
			echo '<img src="/images/icons/clock.gif"> '.date("i:s", mktime(0, 0, (time() - $arena['other']['timer'])));
			echo '</div>';
			
			EchoTableUsersBattle($my_user, $no_user);
			EchoAbiliteBattle($abil_ogon, $abil_voda, $abil_vosd, $abil_zeml, false, 'w19', '35', 0, '/arena/pvp/battle');
				
			$user_journal = $journal['other'] + $journal[$user['lost_id']];
			krsort($user_journal);
	
				if (count($user_journal) > 0) {
					echo '<div class="yellow1 mb5 mt5 small cntr">Журнал боя:</div>';
					echo '<div class="nfl p5 mb5 small mlra">';
						foreach (array_slice($user_journal, 0, 10, true) as $value) {
							echo '<span class="white">'.$value.'<span><br/>';
						}
					echo '</div>';
				}
				echo '<div class="mb5 small error1 cntr"><a class="button w60" href="/">Выйти с боя</a></div>';	
		
		} else {
			echo '<div class="yellow1 mb5 small cntr">Бой начнется через '.($arena['other']['timer'] - time()).' секунд';
			echo '<br/><a class="button w40 mt5" href="/arena/pvp/battle">Обновить</a></div>';
			echo '<div class="hr w90 mlra mt5 mb5"></div>';
			echo '<div class="white mb5 small cntr">Противник: '.ikonka_user($user['lost_race'], 'online').' <a class="yellow1" href="/user?id='.$cache_user['lost_id'].'">'.$cache_user['lost_login'].'</a>, рейтинг: '.$cache_user['lost_arena_pvp_rating'];
			echo '</div>';
		}
		
		require_once './element_include/element_foot_user_battle_true.php';
		exit;
		
	} else {
		writecache('element_users_battle'.$user['lost_id'], '');	
		$wins = (($arena[$my_user]['battle_hp'] > 0) ? true : false);
		$golda = (int)(($arena['other']['gold'] / 100) * 90);
		
		$title = 'Арена: Золотая лига'; 
		require_once './element_include/element_head.php';
		echo '<body><div class="p5">';
		echo '<div class="cntr title bold">'.((!$wins) ? '<span class="red">Вы проиграли!</span>' : '<span class="lngreen">Вы выиграли!</span>').'</div>';
		echo '<div class="hr w80 mlra mb5 mt5"></div>';
		
		echo '<div class="cntr bold moderator small">';
		echo 'Нанесено урона в бою: '.$arena[$my_user]['battle_uron'].'<br/>';
		echo (($wins) ? 'Золото: <img src="/images/icons/gold.png">+'.$golda : '<span class="error1">Золото: <img src="/images/icons/gold.png">-'.$arena['other']['gold'].'</span>');
		echo (($wins) ? '<br/>Ирридий: <img src="/images/icons/irridyi.png">+1' : '');
		echo (($wins) ? '<br/>Рейтинг: '.$user['lost_arena_pvp_rating'].' (+1)' : '<br/><span class="error1">Рейтинг: '.$user['lost_arena_pvp_rating'].' (-1)</span>').'';
		echo '</div>';
		echo '<div class="hr w80 mlra mb5 mt5"></div>';
		
		echo '<div class="cntr small"><a class="button w50 mb5" href="/arena?pvp">На арену</a></div>';
		
		$user_journal = $journal['other'] + $journal[$user['lost_id']];
		krsort($user_journal);
	
			if (count($user_journal) > 0) {
				echo '<div class="yellow1 mb5 mt5 small cntr">Журнал боя:</div>';
				echo '<div class="nfl p5 mb5 small mlra">';
					foreach (array_slice($user_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';
		exit;
	}
	
?>