public function getBackup($missingPlayer, array $players = array())
 {
     if ($players) {
         $playersObject = array_map('\\ManiaLivePlugins\\MatchMakingLobby\\Services\\PlayerInfo::Get', $players);
         $quitterInfo = PlayerInfo::Get($missingPlayer);
         // Sort ready players to have the one with the same level
         usort($playersObject, function (PlayerInfo $p1, PlayerInfo $p2) use($quitterInfo) {
             $dist1 = abs($quitterInfo->ladderPoints - $p1->ladderPoints);
             $dist2 = abs($quitterInfo->ladderPoints - $p2->ladderPoints);
             if ($dist1 == $dist2) {
                 return 0;
             }
             return $dist1 < $dist2 ? -1 : 1;
         });
         $player = array_shift($playersObject);
         //If distance is too big, no replacer
         if (abs($player->ladderPoints - $quitterInfo->ladderPoints) < $this->maxDistanceBackup) {
             return $player->login;
         }
     }
     return false;
 }
Example #2
0
 protected function getAveragePlayerLadder()
 {
     $logins = $this->matchMakingService->getPlayersPlaying($this->storage->serverLogin);
     $points = array();
     foreach ($logins as $login) {
         $player = Services\PlayerInfo::Get($login);
         if ($player) {
             $points[] = $player->ladderPoints;
         }
     }
     foreach (array_merge($this->storage->players, $this->storage->spectators) as $player) {
         $points[] = $player->ladderStats['PlayerRankings'][0]['Score'];
     }
     return count($points) == 0 ? 0.0 : array_sum($points) / count($points);
 }
 /**
  * update the Player list
  * @param string $login
  * @param string[] $blockedPlayerList
  */
 final function updatePlayerList(array $blockedPlayerList, $setLocalAllyAction, $unsetLocalAllyAction, $maxAllyCount, $player = '')
 {
     if ($player) {
         $playerLists = Windows\PlayerList::Get($player);
     } else {
         $playerLists = Windows\PlayerList::GetAll();
     }
     foreach ($playerLists as $playerList) {
         $recipient = $playerList->getRecipient();
         $allies = \ManiaLivePlugins\MatchMakingLobby\Services\AllyService::getInstance()->getAll($recipient);
         $loginsWithUnsetAction = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) {
             if ($a->type == \ManiaLivePlugins\MatchMakingLobby\Services\Ally::TYPE_LOCAL) {
                 return $a->login;
             }
         }, $allies);
         $loginsWithNoAction = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) {
             if ($a->type == \ManiaLivePlugins\MatchMakingLobby\Services\Ally::TYPE_GENERAL) {
                 return $a->login;
             }
         }, $allies);
         $bilateralAllies = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) {
             if ($a->isBilateral) {
                 return $a->login;
             }
         }, $allies);
         $storage = Storage::getInstance();
         foreach (array_merge($storage->players, $storage->spectators) as $player) {
             if (PlayerInfo::Get($player->login)->isAway()) {
                 continue;
             }
             $ladderPoints = $player->ladderStats['PlayerRankings'][0]['Score'];
             $playerInfo = PlayerInfo::Get($player->login);
             $state = Player::STATE_NOT_READY;
             if ($playerInfo->isReady()) {
                 $state = Player::STATE_READY;
             }
             if ($playerInfo->isInMatch) {
                 $state = Player::STATE_IN_MATCH;
             }
             if (array_key_exists($player->login, $blockedPlayerList)) {
                 $state = Player::STATE_BLOCKED;
             }
             if ($player->login == $recipient) {
                 $action = null;
                 $isAlly = false;
             } elseif (in_array($player->login, $loginsWithNoAction)) {
                 $action = null;
                 $isAlly = true;
             } elseif (in_array($player->login, $loginsWithUnsetAction)) {
                 $action = $unsetLocalAllyAction;
                 $isAlly = true;
             } else {
                 $action = count($allies) >= $maxAllyCount ? null : $setLocalAllyAction;
                 $isAlly = false;
             }
             $isBilateral = in_array($player->login, $bilateralAllies);
             $playerList->setPlayer($player->login, $player->nickName, $ladderPoints, $state, $action, $isAlly, $isBilateral);
         }
     }
     Windows\PlayerList::RedrawAll();
 }