Advertisement
Guest User

Untitled

a guest
May 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.18 KB | None | 0 0
  1. <?php
  2.  
  3. namespace pgChatGame;
  4.  
  5. use pocketmine\plugin\PluginBase;
  6. use pocketmine\event\Listener;
  7. use pocketmine\utils\Config;
  8. use pocketmine\command\CommandSender;
  9. use pocketmine\command\Command;
  10. use pocketmine\scheduler\PluginTask;
  11. use pocketmine\event\player\PlayerChatEvent;
  12.  
  13. class pgChatGame extends PluginBase implements Listener{
  14.    
  15.     public $enable;
  16.     public $config;
  17.     public $pconfig;
  18.     public $type;
  19.    
  20.     public $task = [];
  21.    
  22.     public function onEnable(){
  23.        
  24.         if(!is_dir($this->getDataFolder())){
  25.            
  26.             mkdir($this->getDataFolder());
  27.         }
  28.         if(!is_dir($this->getDataFolder()."resources")){
  29.            
  30.             mkdir($this->getDataFolder()."resources");
  31.         }
  32.        
  33.         $this->pconfig = new Config($this->getDataFolder()."config.yml", Config::YAML);
  34.         $this->config = new Config($this->getDataFolder()."resources/config.yml", Config::YAML);
  35.        
  36.         $this->getServer()->getPluginManager()->registerEvents($this, $this);
  37.        
  38.         if($this->pconfig->get("запуск") == 0){
  39.            
  40.             $this->getLogger()->info("≈ /chatgame start ≈ для запуска чат-игры");
  41.         }elseif($this->pconfig->get("запуск") == 1){
  42.            
  43.             $this->onQuestion();
  44.         }
  45.     }
  46.    
  47.     public function onDisable(){
  48.        
  49.         $this->pconfig->set("запуск", $this->enable);
  50.         $this->pconfig->save();
  51.     }
  52.    
  53.     public function onCommand(CommandSender $sender, Command $command, $label, array $args){
  54.        
  55.         $cmd = $command->getName();
  56.        
  57.         if($cmd == "chatgame"){
  58.            
  59.             if(!$sender->hasPermission("chatgame.true")){
  60.                
  61.                 $sender->sendMessage("Только для создателей!");
  62.             }else{
  63.                
  64.                 if(!isset($args[0])){
  65.                    
  66.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  67.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  68.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  69.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  70.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  71.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  72.                     $sender->sendMessage("");   //    ДОПИСАТЬ!
  73.                 }else{
  74.                    
  75.                     if($args[0] == "start"){
  76.                        
  77.                         $this->enable = 1;
  78.                         $this->getServer()->getScheduler()->scheduleDelayedTask(new StartGameTimer($this), 20 * 5 /*$this->pconfig->getNested("таймер.ответ")*/);
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.     }
  84.    
  85.     public function onUnswer(PlayerChatEvent $event){
  86.        
  87.         $msg = $event->getMessage();
  88.         $sender = $event->getPlayer();
  89.        
  90.         $this->getServer()->getScheduler()->cancelAllTasks();
  91.        
  92.         if($this->enable == 1){
  93.            
  94.             if($this->type == 1){
  95.                
  96.                 if($msg == $this->task[0] + $this->task[1]){
  97.                    
  98.                     $result = $this->task[0] + $this->task[1];
  99.                 }
  100.             }elseif($this->type == 2){
  101.                
  102.                 if($msg == $this->task[0] - $this->task[1]){
  103.                    
  104.                     $result = $this->task[0] - $this->task[1];
  105.                 }
  106.             }elseif($this->type == 3){
  107.                
  108.                 if($msg == $this->task[0] * $this->task[1]){
  109.                    
  110.                     $result = $this->task[0] * $this->task[1];
  111.                 }
  112.             }
  113.             $sender->sendMessage("{$this->pconfig->get("префикс")} Ты правильно решил пример! Ты выиграл ≈ тут буит приз ≈");
  114.             $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Игрок {$sender->getName()} первый решил пример! Правильный ответ - {$result}!");
  115.             $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Следующий пример через {$this->pconfig->getNested("таймер.ответ")}");
  116.             $this->getServer()->getScheduler()->scheduleDelayedTask(new StartGameTimer($this), 20 * $this->pconfig->getNested("таймер.ответ"));
  117.         }
  118.     }
  119.    
  120.     public function onQuestion(){
  121.        
  122.         $this->type = mt_rand($this->pconfig->getNested("примеры.тип.минимум"), $this->pconfig->getNested("примеры.тип.максимум"));
  123.        
  124.         $this->getServer()->getScheduler()->cancelAllTasks();
  125.        
  126.         $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Внимаение вопрос!");
  127.        
  128.         if($this->type == 1){
  129.        
  130.             $minPlus = mt_rand($this->config->getNested("примеры.сложение.минимум"), $this->config->getNested("примеры.сложение.максимум"));
  131.             $maxPlus = mt_rand($this->config->getNested("примеры.сложение.минимум"), $this->config->getNested("примеры.сложение.максимум"));
  132.             $this->task = [$minPlus, $maxPlus];
  133.            
  134.             $this->getServer()->broadcastMessage("{$this->task[0]} + {$this->task[1]} = ?");
  135.         }elseif($this->type == 2){
  136.        
  137.             $minMinus = mt_rand($this->config->getNested("примеры.вычитание.уменьшаемое.минимум"), $this->config->getNested("примеры.вычитание.уменьшаемое.максимум"));
  138.             $maxMinus = mt_rand($this->config->getNested("примеры.вычитание.вычитаемое.минимум"), $this->config->getNested("примеры.вычитание.вычитаемое.максимум"));
  139.             $this->task = [$minMinus, $maxMinus];
  140.            
  141.             $this->getServer()->broadcastMessage("{$this->task[0]} - {$this->task[1]} = ?");
  142.         }elseif($this->type == 3){
  143.            
  144.             $minMulti = mt_rand($this->config->getNested("примеры.умножение.минимум"), $this->config->getNested("примеры.умножение.максимум"));
  145.             $maxMulti = mt_rand($this->config->getNested("примеры.умножение.минимум"), $this->config->getNested("примеры.умножение.максимум"));
  146.            
  147.             $this->getServer()->broadcastMessage("{$this->task[0]} * {$this->task[1]} = ?");
  148.         }
  149.         $this->getServer()->getScheduler()->scheduleDelayedTask(new UnquestionTimer($this), 20 * $this->pconfig->getNested("таймер.без_ответа"));
  150.     }
  151. }
  152.  
  153. class StartGameTimer extends PluginTask{
  154.    
  155.     public function __construct(pgChatGame $owner){
  156.        
  157.         parent::__construct($owner);
  158.     }
  159.    
  160.     public function onRun($currentTick){
  161.        
  162.         $this->getOwner()->onQuestion();
  163.     }
  164. }
  165.  
  166. class UnquestionTimer extends PluginTask{
  167.    
  168.     public function __construct(pgChatGame $owner){
  169.        
  170.         parent::__construct($owner);
  171.     }
  172.    
  173.     public function onRun($currentTick){
  174.        
  175.         $this->getOwner()->onQuestion();
  176.     }
  177. }
  178.  
  179. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement