Пример #1
0
 /**
  *
  * @param GameLevelModel $lv        	
  */
 public function handleLevelGameOver(GameLevelModel &$lv)
 {
     $start = microtime(true);
     if (!empty($lv->currentMap)) {
         if (count($lv->currentMap->livePlayers) === 0) {
             Server::getInstance()->broadcastMessage(TextFormat::AQUA . "[HG] Game ended without winner!", $lv->currentMap->joinedPlayers);
         }
         if (count($lv->currentMap->livePlayers) > 0) {
             foreach ($lv->currentMap->livePlayers as $gamer) {
                 if ($gamer instanceof GamePlayer) {
                     $lv->level->addSound(new FizzSound($gamer->player), array($gamer->player));
                     $lv->level->addSound(new PopSound($gamer->player), array($gamer->player));
                     if (count($lv->currentMap->livePlayers) === 1) {
                         if (isset($lv->currentMap->playerscores[$gamer->player->getName()])) {
                             $scores = $lv->currentMap->playerscores[$gamer->player->getName()];
                             if ($scores != null) {
                                 $message = TextFormat::WHITE . "Final : ";
                                 $message .= TextFormat::AQUA . "shots " . TextFormat::LIGHT_PURPLE . $scores["shots"] . TextFormat::GRAY . " | ";
                                 $message .= TextFormat::AQUA . "points " . TextFormat::LIGHT_PURPLE . $scores["hits"] . TextFormat::GRAY . " | ";
                                 $message .= "\n";
                                 $winmsg = TextFormat::GOLD . "--------------------------------------\n";
                                 $winmsg .= TextFormat::GOLD . TextFormat::WHITE . " " . TextFormat::BOLD . TextFormat::LIGHT_PURPLE . "BRAVO " . TextFormat::WHITE . "[" . TextFormat::GOLD . $gamer->player->getName() . TextFormat::WHITE . "] Won [" . TextFormat::GOLD . $lv->winnerCoins . TextFormat::WHITE . "] coins \n";
                                 $winmsg .= TextFormat::WHITE . " Level: " . TextFormat::GREEN . $lv->displayName . TextFormat::WHITE . " | Map: " . TextFormat::GREEN . $lv->currentMap->name . "\n";
                                 $winmsg .= TextFormat::GREEN . " " . $message . "\n";
                                 $winmsg .= TextFormat::GOLD . "--------------------------------------\n";
                                 Server::getInstance()->broadcastMessage($winmsg, $lv->currentMap->joinedPlayers);
                                 if (isset($lv->currentMap->playerscores[$gamer->player->getName()])) {
                                     unset($lv->currentMap->playerscores[$gamer->player->getName()]);
                                 }
                                 if (isset($lv->currentMap->votedPlayers[$gamer->player->getName()])) {
                                     unset($lv->currentMap->votedPlayers[$gamer->player->getName()]);
                                 }
                                 $pmap = $lv->currentMap->name;
                                 $recordwins = new HungerGamesRecordWinsTask($this->plugin, $lv, $pmap, $gamer->player->getName(), $scores["hits"]);
                                 $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($recordwins, mt_rand(2, 5));
                                 for ($i = 0; $i < 50; $i++) {
                                     $gamer->player->sendTip(TextFormat::BOLD . TextFormat::GOLD . "[ = V I C T O R Y ! = ]");
                                 }
                             }
                         }
                     } else {
                         if (isset($lv->currentMap->playerscores[$gamer->player->getName()])) {
                             $scores = $lv->currentMap->playerscores[$gamer->player->getName()];
                             if ($scores != null) {
                                 $message = TextFormat::WHITE . "Final : ";
                                 $message .= TextFormat::AQUA . "shots " . TextFormat::LIGHT_PURPLE . $scores["shots"] . TextFormat::GRAY . " | ";
                                 $message .= TextFormat::AQUA . "points " . TextFormat::LIGHT_PURPLE . $scores["hits"] . TextFormat::GRAY . " | ";
                                 $message .= "\n";
                             }
                         }
                         for ($i = 0; $i < 50; $i++) {
                             $gamer->player->sendTip(TextFormat::BOLD . TextFormat::AQUA . "[ * IT'S A DRAW ! * ]");
                         }
                         $drawmsg = TextFormat::RED . "--------------------------------------\n";
                         $drawmsg .= TextFormat::RED . " -more than 1 player remains [" . count($lv->currentMap->livePlayers) . "]\n";
                         $drawmsg .= TextFormat::WHITE . " " . TextFormat::BOLD . TextFormat::YELLOW . "IT's A DRAW " . TextFormat::WHITE . "[" . TextFormat::GOLD . $gamer->player->getName() . TextFormat::WHITE . "]" . TextFormat::WHITE . "- try again?\n";
                         $drawmsg .= TextFormat::GREEN . " " . $message . "\n";
                         $drawmsg .= TextFormat::RED . "--------------------------------------" . "\n";
                         Server::getInstance()->broadcastMessage($drawmsg, $lv->currentMap->joinedPlayers);
                     }
                     $lv->level->addSound(new FizzSound($gamer->player), array($gamer->player));
                     MapPortal::teleportToMap($lv->levelName, $gamer->player);
                     for ($i = 0; $i < 500; $i++) {
                     }
                     MapPortal::safeTeleporting($gamer->player, $lv->currentMap->arenaExitPos);
                     foreach ($lv->currentMap->livePlayers as $gp) {
                         $gamer->showPlayerTo($gp->player);
                     }
                     if (!empty($gamer->player->getInventory())) {
                         HungerGameKit::clearAllInventories($gamer->player);
                         $gamer->player->getInventory()->clearAll();
                         $gamer->player->setHealth(20);
                     }
                     MagicUtil::addEffect($gamer->player, Effect::JUMP, 10);
                     MagicUtil::addParticles($gamer->player->level, "heart", $gamer->player->getPosition(), 30);
                     $players[] = $gamer->player;
                     $lv->level->addSound(new PopSound($gamer->player), $players);
                 }
             }
         }
         try {
             $task = new HungerGamesMapResetTask($this->plugin, $lv->currentMap);
             $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($task, 12);
             foreach ($lv->maps as $mapname) {
                 if (isset($this->plugin->getAvailableArenas()[$mapname])) {
                     $this->plugin->log($lv->name . "> * reset votes for map: " . $mapname);
                     $arena = $this->plugin->getAvailableArenas()[$mapname];
                     $arena->vote = 0;
                     $arena->votedPlayers = [];
                     $this->plugin->getAvailableArenas()[$mapname] = $arena;
                     break;
                 }
             }
             $lv->joinDownCounter = 10;
         } catch (Exception $e) {
             $this->plugin->printError($e);
         }
     }
     $this->plugin->log("#8 " . $lv->name . " handleLevelGameOver took " . (microtime(true) - $start) . " ms");
 }
Пример #2
0
 public function handlePlayerLeaveTheGame(Player $player)
 {
     if ($player != null) {
         foreach ($this->plugin->gameLevelManager->levels as &$lv) {
             if ($lv instanceof GameLevelModel) {
                 if (count($lv->joinedPlayers) > 0) {
                     if (isset($lv->joinedPlayers[$player->getName()])) {
                         unset($lv->joinedPlayers[$player->getName()]);
                         $this->plugin->log("[HG]gamelevelmanager handlePlayerLeaveTheGame: " . $player->getName() . " |  remains: " . count($lv->joinedPlayers));
                         if (count($lv->joinedPlayers) === 0 || count($lv->joinedPlayers) === 1) {
                             if ($lv->currentStep === GameLevelModel::STATUS_MAP_SELECTION || $lv->currentStep === GameLevelModel::STEP_WAITING) {
                                 $this->plugin->openGate($lv);
                                 $this->plugin->log("[HG] No player left in portal - reset portal state | " . $lv->type . " | " . $lv->name);
                                 $lv->joinDownCounter = $lv->joinDownCounterReset;
                                 $lv->status = GameLevelModel::STATUS_AVAILABLE;
                                 $lv->currentStep = GameLevelModel::STEP_JOINING;
                             }
                         }
                         // @FIXE ME remove votes
                         foreach ($this->plugin->arenaManager->arenas as &$arena) {
                             if ($arena instanceof MapArenaModel) {
                                 if (isset($arena->votedPlayers[$player->getName()])) {
                                     unset($arena->votedPlayers[$player->getName()]);
                                     if ($arena->vote >= 1) {
                                         $arena->vote--;
                                     }
                                     break;
                                 }
                             }
                         }
                     }
                     if (!empty($lv->currentMap)) {
                         if (isset($lv->currentMap->livePlayers[$player->getName()])) {
                             unset($lv->currentMap->livePlayers[$player->getName()]);
                             $recordloss = new HungerGamesRecordLossTask($this->plugin, $lv, $player->getName());
                             $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($recordloss, 30);
                         }
                         if (isset($lv->currentMap->joinedPlayers[$player->getName()])) {
                             unset($lv->currentMap->joinedPlayers[$player->getName()]);
                         }
                         if (isset($lv->currentMap->votedPlayers[$player->getName()])) {
                             unset($lv->currentMap->votedPlayers[$player->getName()]);
                         }
                         break;
                     }
                 }
             }
         }
     }
     // @FIXME
     if (!empty($player->getInventory() && $player->isAlive())) {
         HungerGameKit::clearAllInventories($player);
     }
 }