<?php
/* @var $this BattlesController */
/* @var $model BattlesLocations */
$this->pageTitle = BattlesLocations::getNameWithIcon($current->id_location);
?>
<?php if ($current->type_location != 1): ?>
    <img src="/images/icons/quality/<?php echo BattlesLocations::getDominationIcon($user->side); ?>.png" alt="/"> <?php echo $current->participation_now; ?> / <?php echo $current->participation_default; ?> <br />
<?php endif; ?>
<img src="/images/icons/1_1.png" alt="/"> <?php echo Users::getUsersInLocation($current->id_location, 1, 1) ?> 
<img src="/images/icons/1_2.png" alt="+"> <?php echo Users::getUsersInLocation($current->id_location, 1, 2) ?> 
<img src="/images/icons/2_1.png" alt="/"> <?php echo Users::getUsersInLocation($current->id_location, 2, 1) ?> 
<img src="/images/icons/2_2.png" alt="+"> <?php echo Users::getUsersInLocation($current->id_location, 2, 2) ?> 
<br />
<?php if ($current->type_location != 1): ?>
    <?php if ($user->health_now > 0): ?>
        <!--<div class="info">Твой уровень стал слишком высок для этой Башни, для тебя открыты другие локации</div>-->
        <?php if ($user->class == 1): ?>
            <?php if ($current->side_now != $user->side): ?>
                <?php echo CHtml::link('<img src="/images/icons/attack.png" alt="/"> Участвовать в захвате [' . $current->health_now . ']', array('/battles/captureTerritory'), array('class' => 'block')) ?>
            <?php endif; ?>
            <?php echo CHtml::link('<img src="/images/icons/attack.png" alt="/"> Бить врагов', array('/battles/damageRandomEnemy'), array('class' => 'block')) ?>
            <?php if ($user->battle_target): ?>
                <?php echo CHtml::link('<img src="/images/icons/attack.png" alt="/"> Добивать ' . Users::getFullLogin($user->battle_target) . ' [' . $user->idTarget->health_now . ' HP]', array('/battles/damageLastTarget'), array('class' => 'block')) ?>
            <?php endif; ?>
        <?php else: ?>
            <?php if ($user->battle_target && $user->battle_target == Yii::app()->user->id || $user->health_now < Users::calcParam($user->id_user, 'health')): ?>
                <?php echo CHtml::link('<img src="/images/icons/heal.png" alt="+"> Лечить себя [' . Users::getHealthInPercents($user) . '%]', array('/battles/healSelf'), array('class' => 'block')) ?>
            <?php endif; ?>
            <?php echo CHtml::link('<img src="/images/icons/heal.png" alt="+"> Лечить союзников', array('/battles/healRandomFriend'), array('class' => 'block')) ?>
            <?php echo CHtml::link('<img src="/images/icons/energy.png" alt="/"> Жечь энергию врагам', array('/battles/energyDamageRandomEnemy'), array('class' => 'block')) ?>
            <?php if ($user->battle_target): ?>
                <?php if ($user->side == $user->idTarget->side && $user->battle_target != Yii::app()->user->id): ?>
                    <?php echo CHtml::link('<img src="/images/icons/heal.png" alt="+"> Лечить ' . Users::getFullLogin($user->battle_target) . ' [' . Users::getHealthInPercents($user->idTarget) . '%]', array('/battles/healLastTarget'), array('class' => 'block')) ?>
                <?php elseif ($user->side != $user->idTarget->side): ?>
                    <?php echo CHtml::link('<img src="/images/icons/energy.png" alt="/"> Жечь энергию у ' . Users::getFullLogin($user->battle_target) . ' [' . $user->idTarget->energy_now . ' EN]', array('/battles/energyDamageLastTarget'), array('class' => 'block')) ?>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>
        <?php if ($user->bottles > 0 && ($user->health_now < Users::calcParam($user->id_user, 'health') || $user->energy_now < Users::calcParam($user->id_user, 'energy'))): ?>
            <?php if ($user->battle_bottles_time < time()): ?>
                <?php echo CHtml::link('<img src="/images/icons/heal.png" alt="+"> Выпить эликсир', array('/battles/usePotion'), array('class' => 'block')) ?>
            <?php else: ?>
                <?php echo CHtml::link('<img src="/images/icons/heal.png" alt="+"> Выпить эликсир (' . ($user->battle_bottles_time - time()) . ' сек)', array('/battles/usePotion'), array('class' => 'block grey')) ?>
            <?php endif; ?>
        <?php endif; ?>
		<?php if (!empty($ability)): ?>  
            <?php if ($ability->time_active > time()): ?>
                <?php echo CHtml::link('<img src="/images/icons/ability.png" alt="*"> '.$ability->idAbility->name_ability.' (' . ($ability->time_active - time()) . ' сек)', ['/battles/useAbility', 'chosen'=>$ability->chosen], ['class' => 'block text-success']); ?>
            <?php elseif ($ability->time_cooldown > time()): ?>
                <?php echo CHtml::link('<img src="/images/icons/ability.png" alt="*"> '.$ability->idAbility->name_ability.' (' . ($ability->time_cooldown - time()) . ' сек)', ['/battles/useAbility', 'chosen'=>$ability->chosen], ['class' => 'block grey']) ?>            
			<?php else: ?>
                <?php echo CHtml::link('<img src="/images/icons/ability.png" alt="*"> '.$ability->idAbility->name_ability, ['/battles/useAbility', 'chosen'=>$ability->chosen], ['class' => 'block']) ?>
            <?php endif; ?>
		<?php endif; ?>
    <?php else: ?>
        <div class="info">Вы умерли</div>
        <?php echo CHtml::link('<img src="/images/icons/arrow.png" alt="*"> Воскреснуть в столице', array('/battles/rise'), array('class' => 'block')); ?>
    <?php endif; ?>
<?php endif; ?>
<?php if ($user->health_now > 0): ?>    
	<hr>
    <?php if (!$locations): 
    ?>
        <div class="info">Доступных локаций нет</div>
       
   


    <?php else: ?>
        <?php foreach ($locations as $location): ?>
            <?php echo CHtml::link(BattlesLocations::getNameWithIcon($location->near_location, $location->type_navigator), array('/battles/nearLocation', 'id' => $location->near_location), array('class' => 'block')) ?>
        <?php endforeach; ?>
    <?php endif; ?>
<?php endif; ?>
<?php if ($current->type_location == 1): ?>
    <hr>
    <?php echo CHtml::link('<img src="/images/icons/map.png" alt="*"> Планы сражений', array('/battles/maps'), array('class' => 'block')); ?>
<?php endif; ?>
<?php echo BattleHelper::battleLog($user, 1) ?>
