Вход Регистрация
Файл: wenr.online/app/town/control.php
Строк: 96
<?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(
$town->id) or $town->user != $user->get()->clan){
        
redirect('/town');
        exit;
    }

   
   if(isset(
$_GET['gold'])   and $user->get()->user_id == $clan->user or $user->get()->user_id == $clan->zam){
       
       if(
$town -> gold 1){
           
Notif :: error('В казне города нет золота','/town/control?id='.$town->id);
           exit;
       }
       
       
$up $db->prepare('update `clan` set `gold` = ? where `id` = ?');
       
$up -> execute([$clan->gold+$town->gold,$clan->id]);
       
       
$db->query('update `town` set `gold` = 0 where `id` = '.$town->id);
       
       
Notif :: message('Вы переместили золото из казны города в казну клана','/town/control?id='.$town->id);
       exit;
   }
   
   
   
   if(isset(
$_GET['def'])   and $user->get()->user_id == $clan->user or $user->get()->user_id == $clan->zam){
       
       if(
$town -> def == $town->max_def){
           
Notif :: error('Городу не требуется восстановление','/town/control?id='.$town->id);
           exit;
       }
       
       
       if(
$town->attack_time time()){
           
           
Notif :: error('Невозможно восстановить. Город находится в осаде','/town/control?id='.$town->id);
           exit;
           
       }
       
       
       if(
$clan->gold 1000){
           
           
Notif :: error('Недостаточно золота в казне клана для восстановления','/town/control?id='.$town->id);
           exit;
           
       }
       
       
$up $db->prepare('update `clan` set `gold` = ? where `id` = ?');
       
$up -> execute([$clan->gold-1000,$clan->id]);
       
       
$db->query('update `town` set `def` = `max_def` where `id` = '.$town->id);
       
       
Notif :: message('Вы восстановили защиту города '.$town->name,'/town/control?id='.$town->id);
       exit;
   }
   
   
        
         if(isset(
$_GET['type'])   and $user->get()->user_id == $clan->user or $user->get()->user_id == $clan->zam){
         
$type Clean :: str($_GET['type']);
         
$kol Clean :: int($_GET['kol']);
         
         
$typeArray = ['warrior','max_def','def_type'];
         
         
         
$kolArray = [1,10];
         
         if(!
in_array($type,$typeArray)){
             
redirect('/town');
             exit;
         }
         
         
          if(!
in_array($kol,$kolArray)){
             
redirect('/town');
             exit;
         }
         
         
         
         
$priceArray = ['warrior'=>10,'max_def'=>50,'def_type'=>5000];
         
         
$max 2500;
         
         if(
$type == 'def_type'$max 2;
         
         
         
$price $priceArray[$type]*$kol;
         
         
         if(
$clan->gold $price){
             
Notif :: error('Недостаточно золота в казне клана','/town/control?id='.$town->id);
             exit;
         }
         
         
         if(
$town->$type+$kol $max){
             
Notif :: error('Невозможно купить больше','/town/control?id='.$town->id);
             exit;
         }
         
         
         
$update $db->prepare('update `clan` set `gold` = ? where `id` = ?');
         
$update -> execute([$clan->gold-$price,
                            
$clan->id
                            
]);
                            
                            
            
           
$inv $db->prepare('update town set '.$type.' = ? where id = ?');
           
$inv -> execute([$town->$type+$kol,$town->id]);
           
           
           
           
redirect('/town/control?id='.$town->id);       
           exit;
            }
         
            
     echo 
$template->render('town.control', ['town'   =>  $town'clan'=>$clan'array' => ['Форт','Цитадель','Замок']]);
Онлайн: 1
Реклама