<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }
$time = time();
// Кэш юзера с ID арены. Если нету, выгоняем в очередь
$my_arena = readcache('element_users'.$user['lost_id'].'arena_tvt');
if (!$my_arena) { header('Location: /arena?tvt'); exit; }
// Кэш арены. Если нету, выгоняем в очередь
$arena = readcache('element_arena_tvt_teamid'.$my_arena);
if (!$arena) { header('Location: /arena?tvt'); exit; }
// Журнал боя
$journal = readcache('element_arena_tvt_teamid'.$my_arena.'journal');
// Определяем в какой мы команде. Жив/мертв
if (!empty($arena['team_1'][$user['lost_id']])) { $my_team = 'team_1'; $my_life = true; }
else if (!empty($arena['team_1_kick'][$user['lost_id']])) { $my_team = 'team_1'; $my_life = false; }
else if (!empty($arena['team_2'][$user['lost_id']])) { $my_team = 'team_2'; $my_life = true; }
else { $my_team = 'team_2'; $my_life = false; }
$no_team = ($my_team == 'team_1') ? 'team_2' : 'team_1';
$count_team = array('team_1' => count($arena['team_1']), 'team_2' => count($arena['team_2']));
// Если бой активный, играем иначе показываем результат
if ($arena['other']['active'] == 0) {
// Определяем что делать. Ждать начала, или же играть
$game = ($time > $arena['other']['timer']) ? true : false;
$title = 'Арена: Лига стихий';
require_once './element_include/element_head.php';
require_once './element_function/element_function_battle.php';
echo '<body><div class="p5">';
// Играем
if ($game) {
$timer = $arena['other']['timer'];
// Если я жив, играем, иначе показываем остальных
if ($my_life) {
$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 ($arena[$my_team][$user['lost_id']]['target'] == 0) {
$rand_target = array_rand($arena[$no_team]);
$arena[$my_team][$user['lost_id']]['target'] = $rand_target;
$target_user = cache_user($rand_target);
$update = true;
} else $target_user = cache_user($arena[$my_team][$user['lost_id']]['target']);
// Атакуем врага
if ($go == 'attaka') {
$no_abil_zeml = AbilitiesZemlya($target_user['lost_abilities_zemlya'], $target_user['lost_race'], false, $target_user['lost_id']);
// Смена цели
if (isset($_GET['target'])) {
$rand_target = array_rand($arena[$no_team]);
$arena[$my_team][$user['lost_id']]['target'] = $rand_target;
$target_user = cache_user($rand_target);
}
// Активация Огненной силы
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[$target_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[$target_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[$target_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_team][$target_user['lost_id']]['other_hp'] / 100) * $abil_vosd['add_hp']);
$my_ras_hp = $arena[$my_team][$user['lost_id']]['other_hp'] - $arena[$my_team][$user['lost_id']]['battle_hp'];
if ($add_hp > $my_ras_hp) $add_hp = $my_ras_hp;
$arena[$no_team][$target_user['lost_id']]['battle_hp'] = $arena[$no_team][$target_user['lost_id']]['battle_hp'] - $add_hp;
$arena[$my_team][$user['lost_id']]['battle_hp'] = $arena[$my_team][$user['lost_id']]['battle_hp'] + $add_hp;
$journal[$user['lost_id']][KeyJournalMassiv($timer)] = '<span class="lngreen">Вы забрали у <span class="bold">'.$target_user['lost_login'].' '.$add_hp.'</span> здоровья</span>';
$journal[$target_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[$target_user['lost_id']][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> активировал '.$image['image'].' <span class="bold">Земляную стойкость</span></span>';
}
$uron = GenerationUron($user['lost_params_strlen'], $arena[$my_team][$user['lost_id']]['time_udar'], $abil_ogon['add_procent'], $abil_voda['add_procent'], $no_abil_zeml['add_procent'], GenerationProtection($target_user['lost_params_protection']));
// Данные врага
$arena[$no_team][$target_user['lost_id']]['battle_hp'] = $arena[$no_team][$target_user['lost_id']]['battle_hp'] - $uron;
$arena[$no_team][$target_user['lost_id']]['uron'] = $arena[$no_team][$target_user['lost_id']]['uron'] + $uron;
// Мои данные
$arena[$my_team][$user['lost_id']]['battle_uron'] = $arena[$my_team][$user['lost_id']]['battle_uron'] + $uron;
$arena[$my_team][$user['lost_id']]['time_udar'] = microtime();
$arena[$my_team][$user['lost_id']]['uron'] = 0;
// Запись в журнал боя
$journal[$user['lost_id']][KeyJournalMassiv($timer)] = 'Вы ударили <span class="yellow1 bold">'.$target_user['lost_login'].'</span> на <span class="yellow1 bold">'.$uron.'</span> урон '.(($abil_voda['add_procent'] > 0) ? 'крит' : '');
$journal[$target_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>';
// Если я его убил
if ($arena[$no_team][$target_user['lost_id']]['battle_hp'] <= 0) {
// Заносим в список мертых и удаляем со списка живих
$arena[$no_team.'_kick'][$target_user['lost_id']] = $arena[$no_team][$target_user['lost_id']];
unset($arena[$no_team][$target_user['lost_id']]);
// Запись в журнал боя о его смерти
$journal['other'][KeyJournalMassiv($timer)] = '<span class="yellow1"><span class="bold">'.$user['lost_login'].'</span> убил <span class="bold">'.$target_user['lost_login'].'</span></span>';
// Удаляем таргейт
$arena[$my_team][$user['lost_id']]['target'] = 0;
// Если они все убиты
if (count($arena[$no_team]) == 0) {
// Заканчиваем бой
$arena['other']['active'] = 1;
// Игроки команды победителей и проигравших
$team_win = $arena[$my_team] + $arena[$my_team.'_kick'];
$team_los = $arena[$no_team] + $arena[$no_team.'_kick'];
// Выдаем награду победителям
foreach ($team_win as $id_user => $value) {
$cache_user = cache_user($id_user);
$cache_user['lost_arena_tvt_rating'] = $cache_user['lost_arena_tvt_rating'] + 1;
update_money_exp($cache_user, 0, 0, 1, 0);
// Обновляем задания
$user_quests = user_quests($cache_user['lost_id']);
$count_quests = quests_id_count('arena_tvt_5');
if ($user_quests['arena_tvt_5'] < $count_quests) {
$user_quests['arena_tvt_5'] = $user_quests['arena_tvt_5'] + 1;
if ($user_quests['arena_tvt_5'] == $count_quests) $user_quests['lost_new'] = $user_quests['lost_new'] + 1;
writecache('element_quests_user'.$cache_user['lost_id'], $user_quests);
quests_list_update($cache_user['lost_id']);
}
}
// Выдаем награду проигравшим
foreach ($team_los as $id_user => $value) {
$cache_user = cache_user($id_user);
$cache_user['lost_arena_tvt_rating'] = $cache_user['lost_arena_tvt_rating'] - 1;
update_money_exp($cache_user, 0, 0, 0, 0);
// Обновляем задания
$user_quests = user_quests($cache_user['lost_id']);
$count_quests = quests_id_count('arena_tvt_5');
if ($user_quests['arena_tvt_5'] < $count_quests) {
$user_quests['arena_tvt_5'] = $user_quests['arena_tvt_5'] + 1;
if ($user_quests['arena_tvt_5'] == $count_quests) $user_quests['lost_new'] = $user_quests['lost_new'] + 1;
writecache('element_quests_user'.$cache_user['lost_id'], $user_quests);
quests_list_update($cache_user['lost_id']);
}
}
// Запись в журнал о конце боя
$journal['other'][KeyJournalMassiv($timer)] = '<span class="lngreen bold">Бой закончен!</span>';
// Перезапись кэша
writecache('element_arena_tvt_teamid'.$my_arena.'journal', $journal);
writecache('element_arena_tvt_teamid'.$my_arena, $arena);
header('Location: /arena/tvt/battle');
exit;
}
// Перезапись кэша
writecache('element_arena_tvt_teamid'.$my_arena.'journal', $journal);
writecache('element_arena_tvt_teamid'.$my_arena, $arena);
header('Location: /arena/tvt/battle');
exit;
}
writecache('element_arena_tvt_teamid'.$my_arena.'journal', $journal);
writecache('element_arena_tvt_teamid'.$my_arena, $arena);
$update = false;
} else $uron = 0;
$my_user = array('user_race' => $user['lost_race'], 'user_hp' => $arena[$my_team][$user['lost_id']]['battle_hp'],
'user_other_hp' => $arena[$my_team][$user['lost_id']]['other_hp'], 'user_name' => $user['lost_login'],
'user_uron' => $arena[$my_team][$user['lost_id']]['uron'], 'user_add_hp' => $add_hp);
$no_user = array('user_race' => $target_user['lost_race'], 'user_hp' => $arena[$no_team][$target_user['lost_id']]['battle_hp'],
'user_other_hp' => $arena[$no_team][$target_user['lost_id']]['other_hp'], 'user_name' => $target_user['lost_login'],
'user_uron' => $uron, 'user_add_hp' => 0);
echo '<div class="small mb5 cntr yellow1">';
echo '<img src="/images/icons/arena_team_1.gif"> Наши: '.$count_team[$my_team].' ';
echo '<img src="/images/icons/arena_team_2.gif"> Враги: '.$count_team[$no_team].' ';
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, true, 'w15', '30', 0, '/arena/tvt/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>';
if ($update) writecache('element_arena_tvt_teamid'.$my_arena, $arena);
} else {
// Погиб. Жду окончания боя
echo '<div class="mb5 small error1 cntr">Вы погибли в бою. Ждите окончания боя.';
echo '<br/><a class="button w40 mt5" href="/arena/tvt/battle">Обновить</a></div>';
echo '<div class="yellow1 mb5 mt5 small cntr">Моя команда:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach($arena[$my_team] as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="moderator small fr"><img src="/images/icons/heatpoints.png"> <span class="bold">'.$value['battle_hp'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</div>';
echo '<div class="yellow1 mb5 mt5 small cntr">Противники:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach($arena[$no_team] as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="moderator small fr"><img src="/images/icons/heatpoints.png"> <span class="bold">'.$value['battle_hp'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</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>';
}
}
} else {
echo '<div class="yellow1 mb5 small cntr">Бой начнется через '.($arena['other']['timer'] - time()).' секунд';
echo '<br/><a class="button w40 mt5" href="/arena/tvt/battle">Обновить</a></div>';
echo '<div class="yellow1 mb5 mt5 small cntr">Моя команда:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach($arena[$my_team] as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="moderator small fr">Рейтинг: <span class="bold">'.$cache_user['lost_arena_tvt_rating'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</div>';
echo '<div class="yellow1 mb5 mt5 small cntr">Противники:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach($arena[$no_team] as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="moderator small fr">Рейтинг: <span class="bold">'.$cache_user['lost_arena_tvt_rating'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</div>';
}
require_once './element_include/element_foot_user_battle_true.php';
exit;
} else {
writecache('element_users_battle'.$user['lost_id'], '');
$title = 'Арена: Лига стихий';
require_once './element_include/element_head.php';
require_once './element_function/element_function_battle.php';
echo '<body><div class="p5">';
echo '<div class="cntr title bold">'.(($count_team[$my_team] == 0) ? '<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">';
$statistika = $arena[$my_team] + $arena[$my_team.'_kick'];
echo 'Нанесено урона в бою: '.$statistika[$user['lost_id']]['battle_uron'];
echo (($count_team[$no_team] == 0) ? '<br/>Ирридий: <img src="/images/icons/irridyi.png">+1' : '');
echo (($count_team[$no_team] == 0) ? '<br/>Рейтинг: '.$user['lost_arena_tvt_rating'].' (+1)' : '<br/><span class="error1">Рейтинг: '.$user['lost_arena_tvt_rating'].' (-1)</span>').'';
echo '</div>';
echo '<div class="hr w80 mlra mb5 mt5"></div>';
echo '<div class="cntr small"><a class="button w50 mt5" href="/arena?tvt">На арену</a></div>';
if ($count_team['team_1'] == 0) { $losse = 'team_1'; $wins = 'team_2'; } else { $losse = 'team_2'; $wins = 'team_1'; }
echo '<div class="yellow1 mb5 mt5 small cntr">Победители:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach(($arena[$wins] + $arena[$wins.'_kick']) as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="moderator small fr">Рейтинг: <span class="bold">'.$cache_user['lost_arena_tvt_rating'].', <img src="/images/icons/irridyi.png">+1, '.$value['battle_uron'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</div>';
echo '<div class="yellow1 mb5 mt5 small cntr">Проигравшие:</div>';
echo '<div class="nfl p5 mb5 mt5 small mlra">';
$i = 1;
foreach(($arena[$losse] + $arena[$losse.'_kick']) as $user_id => $value) {
$odd = (($i % 2) ? ' odd' : '');
$cache_user = cache_user($user_id);
echo '<div class="ml5 mr5">
<a class="bl p5 block'.$odd.'" href="/user?id='.$user_id.'">
<span class="ccc small fr">Рейтинг: <span class="bold">'.$cache_user['lost_arena_tvt_rating'].', '.$value['battle_uron'].'</span></span>
<span class="small mb5 yellow1"><span class="white">'.$i.'.</span>
'.ikonka_user($cache_user['lost_race'], ((!empty($online[$user_id])) ? 'online' : 'offline')).'
'.$cache_user['lost_login'].'</span>
</a>
</div>';
$i++;
}
echo '</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';
}
?>