Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace pgChatGame;
- use pocketmine\plugin\PluginBase;
- use pocketmine\event\Listener;
- use pocketmine\utils\Config;
- use pocketmine\command\CommandSender;
- use pocketmine\command\Command;
- use pocketmine\scheduler\PluginTask;
- use pocketmine\event\player\PlayerChatEvent;
- class pgChatGame extends PluginBase implements Listener{
- public $enable;
- public $config;
- public $pconfig;
- public $type;
- public $task = [];
- public function onEnable(){
- if(!is_dir($this->getDataFolder())){
- mkdir($this->getDataFolder());
- }
- if(!is_dir($this->getDataFolder()."resources")){
- mkdir($this->getDataFolder()."resources");
- }
- $this->pconfig = new Config($this->getDataFolder()."config.yml", Config::YAML);
- $this->config = new Config($this->getDataFolder()."resources/config.yml", Config::YAML);
- $this->getServer()->getPluginManager()->registerEvents($this, $this);
- if($this->pconfig->get("запуск") == 0){
- $this->getLogger()->info("≈ /chatgame start ≈ для запуска чат-игры");
- }elseif($this->pconfig->get("запуск") == 1){
- $this->onQuestion();
- }
- }
- public function onDisable(){
- $this->pconfig->set("запуск", $this->enable);
- $this->pconfig->save();
- }
- public function onCommand(CommandSender $sender, Command $command, $label, array $args){
- $cmd = $command->getName();
- if($cmd == "chatgame"){
- if(!$sender->hasPermission("chatgame.true")){
- $sender->sendMessage("Только для создателей!");
- }else{
- if(!isset($args[0])){
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- $sender->sendMessage(""); // ДОПИСАТЬ!
- }else{
- if($args[0] == "start"){
- $this->enable = 1;
- $this->getServer()->getScheduler()->scheduleDelayedTask(new StartGameTimer($this), 20 * 5 /*$this->pconfig->getNested("таймер.ответ")*/);
- }
- }
- }
- }
- }
- public function onUnswer(PlayerChatEvent $event){
- $msg = $event->getMessage();
- $sender = $event->getPlayer();
- $this->getServer()->getScheduler()->cancelAllTasks();
- if($this->enable == 1){
- if($this->type == 1){
- if($msg == $this->task[0] + $this->task[1]){
- $result = $this->task[0] + $this->task[1];
- }
- }elseif($this->type == 2){
- if($msg == $this->task[0] - $this->task[1]){
- $result = $this->task[0] - $this->task[1];
- }
- }elseif($this->type == 3){
- if($msg == $this->task[0] * $this->task[1]){
- $result = $this->task[0] * $this->task[1];
- }
- }
- $sender->sendMessage("{$this->pconfig->get("префикс")} Ты правильно решил пример! Ты выиграл ≈ тут буит приз ≈");
- $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Игрок {$sender->getName()} первый решил пример! Правильный ответ - {$result}!");
- $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Следующий пример через {$this->pconfig->getNested("таймер.ответ")}");
- $this->getServer()->getScheduler()->scheduleDelayedTask(new StartGameTimer($this), 20 * $this->pconfig->getNested("таймер.ответ"));
- }
- }
- public function onQuestion(){
- $this->type = mt_rand($this->pconfig->getNested("примеры.тип.минимум"), $this->pconfig->getNested("примеры.тип.максимум"));
- $this->getServer()->getScheduler()->cancelAllTasks();
- $this->getServer()->broadcastMessage("{$this->pconfig->get("префикс")} Внимаение вопрос!");
- if($this->type == 1){
- $minPlus = mt_rand($this->config->getNested("примеры.сложение.минимум"), $this->config->getNested("примеры.сложение.максимум"));
- $maxPlus = mt_rand($this->config->getNested("примеры.сложение.минимум"), $this->config->getNested("примеры.сложение.максимум"));
- $this->task = [$minPlus, $maxPlus];
- $this->getServer()->broadcastMessage("{$this->task[0]} + {$this->task[1]} = ?");
- }elseif($this->type == 2){
- $minMinus = mt_rand($this->config->getNested("примеры.вычитание.уменьшаемое.минимум"), $this->config->getNested("примеры.вычитание.уменьшаемое.максимум"));
- $maxMinus = mt_rand($this->config->getNested("примеры.вычитание.вычитаемое.минимум"), $this->config->getNested("примеры.вычитание.вычитаемое.максимум"));
- $this->task = [$minMinus, $maxMinus];
- $this->getServer()->broadcastMessage("{$this->task[0]} - {$this->task[1]} = ?");
- }elseif($this->type == 3){
- $minMulti = mt_rand($this->config->getNested("примеры.умножение.минимум"), $this->config->getNested("примеры.умножение.максимум"));
- $maxMulti = mt_rand($this->config->getNested("примеры.умножение.минимум"), $this->config->getNested("примеры.умножение.максимум"));
- $this->getServer()->broadcastMessage("{$this->task[0]} * {$this->task[1]} = ?");
- }
- $this->getServer()->getScheduler()->scheduleDelayedTask(new UnquestionTimer($this), 20 * $this->pconfig->getNested("таймер.без_ответа"));
- }
- }
- class StartGameTimer extends PluginTask{
- public function __construct(pgChatGame $owner){
- parent::__construct($owner);
- }
- public function onRun($currentTick){
- $this->getOwner()->onQuestion();
- }
- }
- class UnquestionTimer extends PluginTask{
- public function __construct(pgChatGame $owner){
- parent::__construct($owner);
- }
- public function onRun($currentTick){
- $this->getOwner()->onQuestion();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement