public function addPlayer(Gamer $gamer, int &$fault = MatchJoinFault::SUCCESS) : bool { $config = $this->getMatchConfig(); // prerequisites if ($this->state !== MatchState::OPEN) { $fault = MatchJoinFault::CLOSED; return false; } if ($gamer->getModule() !== $this->game) { $fault = MatchJoinFault::NOT_IN_GAME; return false; } if (!$this->hasJoinPermission($gamer->getPlayer())) { $fault = MatchJoinFault::NO_PERM; return false; } if (count($this->players) >= $config->maxPlayers) { $fault = MatchJoinFault::FULL; return false; } if (count($this->players) >= $config->semiMaxPlayers and !$this->hasSemiFullPermission($gamer->getPlayer())) { $fault = MatchJoinFault::SEMI_FULL; return false; } // add $this->players[$gamer->getId()] = $gamer; // recalculate players $count = count($this->players); if ($count >= $this->getMatchConfig()->minPlayers) { // we can start the timer now $this->startTimer = $config->maxWaitTime * 2; } elseif ($count >= $config->maxPlayers) { $this->startTimer = $config->minWaitTime; } elseif ($this->startTimer < $config->minWaitTime) { $this->startTimer = $config->minWaitTime; } return true; }
public function addSpectator(Gamer $gamer, int &$fault = MatchJoinFault::SUCCESS) : bool { if (!$this->hasSpectatePermission($gamer->getPlayer())) { $fault = MatchJoinFault::NO_PERM; return false; } if ($gamer->getModule() !== $this->game) { $fault = MatchJoinFault::NOT_IN_GAME; return false; } $this->spectators[$gamer->getId()] = $gamer; $gamer->getPlayer()->teleport($this->getMatchConfig()->getNextSpectatorJoinPosition()); return true; }