Esempio n. 1
0
 protected function runReplacerMaker()
 {
     $matchesNeedingBackup = $this->matchMakingService->getMatchesNeedingBackup($this->storage->serverLogin, $this->scriptName, $this->titleIdString);
     if ($matchesNeedingBackup) {
         $this->backupNeeded = true;
         $potentialBackups = $this->getMatchablePlayers();
         $allyService = $this->allyService;
         $storage = $this->storage;
         //removing player which has allies from the potential backups
         $potentialBackups = array_filter($potentialBackups, function ($login) use($storage, $allyService) {
             $obj = $storage->getPlayerObject($login);
             if ($obj) {
                 return !count($allyService->get($obj->login));
             }
         });
         if ($potentialBackups) {
             foreach ($matchesNeedingBackup as $match) {
                 $potentialBackupsForMatch = array_filter($potentialBackups, function ($backup) use($match) {
                     return !in_array($backup, $match->players);
                 });
                 /** @var Match $match */
                 $quitters = $this->matchMakingService->getMatchQuitters($match->id);
                 foreach ($quitters as $quitter) {
                     $backup = $this->matchMaker->getBackup($quitter, $potentialBackupsForMatch);
                     if ($backup) {
                         \ManiaLive\Utilities\Logger::debug(sprintf('match %d, %s will replace %s', $match->id, $backup, $quitter));
                         $this->matchMakingService->updatePlayerState($quitter, $match->id, Services\PlayerInfo::PLAYER_STATE_REPLACER_PROPOSED);
                         $this->replacers[$backup] = $quitter;
                         $teamId = $match->getTeam($quitter);
                         $this->matchMakingService->addMatchPlayer($match->id, $backup, $teamId);
                         $this->gui->createLabel($this->gui->getBackUpLaunchText($match), $backup, 0, false, false);
                         $this->setShortKey($backup, array($this, 'onPlayerCancelReplacement'));
                         $this->replacerCountDown[$backup] = 7;
                         //Unset this replacer for next iteration
                         unset($potentialBackupsForMatch[array_search($backup, $potentialBackupsForMatch)]);
                         unset($potentialBackups[array_search($backup, $potentialBackups)]);
                     }
                 }
             }
         } else {
             $this->setNotReadyLabel();
         }
         unset($potentialBackups);
     } else {
         $this->backupNeeded = false;
     }
 }