Вход Регистрация
Файл: wenr.online/app/town/fight.php
Строк: 188
<?php

if (!$user->isAuth()) {
    
redirect('/');
    exit;
}



 

    
$town $db->prepare('select * from town where id = ?');
    
$town -> execute([Clean :: int($_GET['id'])]);
    
$town $town -> fetch(PDO :: FETCH_OBJ);
    
    
    
$clan $db->prepare('select * from clan where id = ?');
    
$clan -> execute([$user->get()->clan]);
    
$clan $clan ->fetch(PDO :: FETCH_OBJ);
    
    
    


    
            if(!isset(
$clan->id)){
                
Notif :: error('Для участия в битве за трон вы должны состоять в клане','/town');
                exit;
            }
    
    if(!isset(
$town->id)){
        
redirect('/town');
        exit;
    }
    
   
   if(isset(
$_GET['control'])){
       
redirect('/town/control?id='.$town->id);
       exit;
   }
   
   
   
     if(isset(
$_GET['end']) and $user->get()->user_id == $clan->user or $user->get()->user_id == $clan->zam){
       
       
       if(
$town->user == $user->get()->clan){
           
Notif :: error('Вы не можете осадить город вашего клана','/town/fight?id='.$town->id);
           exit;
       }
     
       
       if(
$town->attack_time time()){
           
Notif :: error('Город «'.$town->name.'» не находится под осадой','/town/fight?id='.$town->id);
           exit;
       }
       
        
$win $db->prepare('update `town` set `attack_user` = ?, `attack_time` = ? where `id` = ?');
            
$win -> execute([
            
0,
            
0,
            
$town->id
            
            
]);
       
   
Notif :: message('Вы сняли осаду с города','/town/fight?id='.$town->id);
   exit;
   
     }
     
     
     
   if(isset(
$_GET['attack'])){
       
       if(
$user->get()->user_id != $clan->user and $user->get()->user_id != $clan->zam){
           
           
Notif :: error('Осадить город может только глава клана и капитан.','/town/fight?id='.$town->id);
           exit;
       }
       
       if(
$town->user == $user->get()->user_id){
           
Notif :: error('Вы не можете осадить город своего клана','/town/fight?id='.$town->id);
           exit;
       }
     
       
       if(
$town->attack_time time()){
           
Notif :: error('Город «'.$town->name.'» уже находится под осадой','/town/fight?id='.$town->id);
           exit;
       }
       
       
       if(
$town->def/$user->get()->warrior){
           
Notif :: error('Для осады города «'.$town->name.'» нужно минимум '.intval($town->def/5).' воинов ','/town/fight?id='.$town->id);
           exit;
       }
       
       
       
$attack $db->prepare('update `town` set `attack_time` = ?, `attack_user` = ? where `id` = ?');
       
$attack -> execute([time()+3600,$user->get()->clan,$town->id]);
       
notifSend(clan_info($town->user)->user,'Клан «'.$clan->name.'» осадил город «'.$town->name.'»');
       
Notif :: message('Вы осадили город «'.$town->name.'» ','/town/fight?id='.$town->id);
       exit;
       
   }
    
    
    
    if(isset(
$_GET['war'])){
       
     
       
       if(
$town->attack_time time() or $user->get()->clan != $town->attack_user){
           
Notif :: error('Город «'.$town->name.'» не находится под осадой','/town/fight?id='.$town->id);
           exit;
       }
       
       
       
$useruron $user->get()->warrior+$user->get()->catapult*5+$user->get()->ram*5-$town->def;
       if(
$useruron 0$useruron 0;
       
       
$townuron $town->warrior+rand(1,20);
       
       if(
$townuron $user->get()->warrior$townuron $user->get()->warrior;
      
       
       
       
$attack $db->prepare('update `town` set `def` = ?, `warrior` = ? where `id` = ?');
       
$attack -> execute([$town->def-$useruron,$town->def-$useruron,$town->id]);
       
       
$usattack $db->prepare('update `users` set `warrior` = ? where `user_id` = ?');
       
$usattack -> execute([
                
$user->get()->warrior-$townuron,
                
$user->get()->user_id
                
]);
                
        
$db->query('update `town` set `def` = 0 where `def' 0);
        
$db->query('update `town` set `warrior` = 0 where `warrior' 0);
        
        
$db->query('update `users` set `catapult` = 0 where `catapult' 0);
        
$db->query('update `users` set `warrior` = 0 where `warrior' 0);
        
$db->query('update `users` set `ram` = 0 where `ram' 0);
        
        
         if(
$townuron $user->get()->warrior or $user->get()->warrior == 0){
             
             
            
$lose $db->prepare('update `town` set `attack_user` = ?, `attack_time` = ? where `id` = ?');
            
$lose -> execute([
            
0,
            
0,
            
$town->id
            
            
]);
            
Notif :: message('Вы проиграли битву за город «'.$town->name.'»','/town/fight?id='.$town->id);
            exit;
        }
        
        if(
$useruron $town->warrior){
            
            
notifSend(clan_info($town->user)->user,'Клан «'.$clan->name.'» захватил ваш город «'.$town->name.'»');
            
            
$win $db->prepare('update `town` set `user` = ?, `attack_user` = ?, `attack_time` = ? where `id` = ?');
            
$win -> execute([$clan->id,
            
0,
            
0,
            
$town->id
            
            
]);
            
            
            
            
Notif :: message('Вы успешно захватили город «'.$town->name.'»','/town/fight?id='.$town->id);
            exit;
        }
        
       
        
        
       
       
Notif :: message('Вы атаковали город «'.$town->name.'». '.$town->name.' потерял '.$useruron.' воинов, вы - '.$townuron.' воинов','/town/fight?id='.$town->id);
       exit;
       
   }
    
   
    
    function 
hp_pr($hp,$max_hp){
        global 
$town;
        
        return 
intval($town->def/$town->max_def*100);
    }
    
    
    function 
secToArray($secs)
{
    
$res = array();
    
$res['minutes'] = floor($secs 60);
    
$res['secs'] = $secs 60;
    
$res json_encode($res);
    return 
json_decode($res);
}
  
  
  function 
button(){
      global 
$user,$town;
      if(
$town->user == $user->get()->clan$return 'Управление';
      if(
$town->user != $user->get()->clan$return 'Взять в осаду';
      return 
$return;
  }
  
  
  function 
button_url(){
      global 
$user,$town;
      if(
$town->user == $user->get()->clan$return =  'control';
      if(
$town->user != $user->get()->clan$return =  'attack';
      return 
$return;
  }
    
    echo 
$template->render('town.fight', ['town'   =>  $town'clan'=>$clan'array' => ['Форт','Цитадель','Замок']]);
Онлайн: 1
Реклама