function showMatchSumUp(Match $match, $receiver, $time) { $storage = Storage::getInstance(); $getPlayerInfosCallback = function ($login) use($storage) { $p = $storage->getPlayerObject($login); $pathArray = explode('|', $p->ladderStats['PlayerRankings'][0]['Path']); $path = implode('|', array_slice($pathArray, 0, 3)); return (object) array('login' => $login, 'nickname' => $p ? $p->nickName : $login, 'zone' => $p ? array_pop($pathArray) : 'World', 'rank' => $p ? $p->ladderStats['PlayerRankings'][0]['Ranking'] : -1, 'zoneFlag' => sprintf('file://ZoneFlags/Login/%s/country', $login), 'ladderPoints' => $p->ladderStats['PlayerRankings'][0]['Score'], 'echelon' => \ManiaLivePlugins\MatchMakingLobby\Services\PlayerInfo::ComputeEchelon($p->ladderStats['PlayerRankings'][0]['Score'])); }; $sortPlayerCallback = function ($player1, $player2) { if ($player1->ladderPoints == $player2->ladderPoints) { return 0; } return $player1->ladderPoints < $player2->ladderPoints ? 1 : -1; }; $players = array_map($getPlayerInfosCallback, $match->players); usort($players, $sortPlayerCallback); $window = \ManiaLivePlugins\MatchMakingLobby\Windows\StartSoloMatch::Create($receiver); $window->set($players, $time); $window->show(); }
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; }
protected function addPlayerToParty(\Maniaplanet\DedicatedServer\Structures\Player $player, $disable = false) { $path = explode('|', $player->path); if (array_key_exists(1, $path)) { $zone = $path[1]; $this->playerList[$player->login] = array(); $this->playerList[$player->login]['nickname'] = $player->nickName ?: $player->login; $this->playerList[$player->login]['zone'] = $zone; $this->playerList[$player->login]['avatarUrl'] = 'file://Avatars/' . $player->login . '/Default'; $this->playerList[$player->login]['rank'] = $player->ladderStats['PlayerRankings'][0]['Ranking']; $this->playerList[$player->login]['echelon'] = PlayerInfo::ComputeEchelon($player->ladderStats['PlayerRankings'][0]['Score']); $this->playerList[$player->login]['countryFlagUrl'] = sprintf('file://ZoneFlags/Login/%s/country', $player->login); $this->playerList[$player->login]['disable'] = $disable; } }
function onDraw() { switch ($this->state) { case static::STATE_READY: $subStyle = '0F0D'; break; case static::STATE_IN_MATCH: $subStyle = 'FF0D'; break; case static::STATE_BLOCKED: $subStyle = '000D'; break; case static::STATE_NOT_READY: $subStyle = 'F00D'; break; default: $subStyle = ''; } $this->icon->setSize(1, $this->sizeY); $this->icon->setPosition(0, -$this->sizeY / 2); $this->label->setPosition(8, -$this->sizeY / 2); $this->echelonFrame->setPosition($this->sizeX - 1, 0.5); $this->countryFlag->setPosition(2, -$this->sizeY / 2); $this->bg->setSize($this->sizeX, $this->sizeY); $this->hiddenLabel->setText($this->login); $echelon = PlayerInfo::ComputeEchelon($this->ladderPoints); $this->icon->setBgcolor($subStyle); $this->countryFlag->setImage($this->zoneFlagURL, true); $this->echelonLabel->setText($echelon); $this->echelonQuad->setImage(sprintf('file://Media/Manialinks/Common/Echelons/echelon%d.dds', $echelon), true); }
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(); }