mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-09 11:45:18 -05:00
Added Matchmaking Register endpoint, this endpoints sets a game from 'Created' to 'Open' when the host has laoded the map, so that palyers can start to join.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
use App\Enums\Game\Matchmaking\QueueStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\Matchmaking\QueueRequest;
|
||||
use App\Http\Requests\Api\Matchmaking\RegisterMatchRequest;
|
||||
use App\Http\Responses\Api\Matchmaking\MatchData;
|
||||
use App\Http\Responses\Api\Matchmaking\MatchProperties;
|
||||
use App\Http\Responses\Api\Matchmaking\QueueData;
|
||||
@@ -31,7 +32,6 @@ public function getRegions()
|
||||
public function queue(QueueRequest $request)
|
||||
{
|
||||
$this->processQueue();
|
||||
$this->processGames();
|
||||
if($request->checkOnly)
|
||||
return json_encode($this->checkQueueStatus($request));
|
||||
|
||||
@@ -45,25 +45,31 @@ public function matchInfo(string $matchId)
|
||||
if($foundGame === null)
|
||||
return ['status' => 'Error', 'message' => 'Match not found.'];
|
||||
|
||||
$response = new MatchData();
|
||||
|
||||
$response->matchId = $foundGame->id;
|
||||
$response->creationDateTime = $foundGame->created_at->getTimestamp();
|
||||
$response->status = $foundGame->status;
|
||||
$response->creator = $foundGame->creator?->id;
|
||||
|
||||
$players = $foundGame->players;
|
||||
$response->players = $players->pluck('id')->toArray();
|
||||
$response->sideA = $players->where('pivot.side', MatchmakingSide::Hunter->value)->pluck('id')->toArray();
|
||||
$response->sideB = $players->where('pivot.side', MatchmakingSide::Runner->value)->pluck('id')->toArray();
|
||||
|
||||
$response->props = new MatchProperties(
|
||||
$foundGame->matchConfiguration,
|
||||
);
|
||||
$response = MatchData::fromGame($foundGame);
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function register(RegisterMatchRequest $request, string $matchId)
|
||||
{
|
||||
$foundGame = Game::find($matchId);
|
||||
$foundGame->session_settings = $request->sessionSettings;
|
||||
$foundGame->status = MatchStatus::Opened;
|
||||
$foundGame->save();
|
||||
|
||||
return json_encode(MatchData::fromGame($foundGame));
|
||||
}
|
||||
|
||||
public function seedFileGet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function seedFilePost()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function checkQueueStatus(QueueRequest $request): QueueResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
@@ -99,7 +105,6 @@ protected function checkQueueStatus(QueueRequest $request): QueueResponse
|
||||
/** @var Game $foundGame */
|
||||
$foundGame = $foundGame->first();
|
||||
$response = new QueueResponse();
|
||||
$matchData = new MatchData();
|
||||
|
||||
if($foundGame->status === MatchStatus::Opened) {
|
||||
$response->queueData = new QueueData(
|
||||
@@ -111,22 +116,7 @@ protected function checkQueueStatus(QueueRequest $request): QueueResponse
|
||||
else
|
||||
$response->status = QueueStatus::Matched;
|
||||
|
||||
$matchData->matchId = $foundGame->id;
|
||||
$matchData->category = $request->category;
|
||||
$matchData->creationDateTime = $foundGame->created_at->getTimestamp();
|
||||
$matchData->status = $foundGame->status;
|
||||
$matchData->creator = $foundGame->creator?->id;
|
||||
|
||||
$players = $foundGame->players;
|
||||
$matchData->players = $players->pluck('id')->toArray();
|
||||
$matchData->sideA = $players->where('pivot.side', MatchmakingSide::Hunter->value)->pluck('id')->toArray();
|
||||
$matchData->sideB = $players->where('pivot.side', MatchmakingSide::Runner->value)->pluck('id')->toArray();
|
||||
|
||||
$matchData->props = new MatchProperties(
|
||||
$foundGame->matchConfiguration,
|
||||
);
|
||||
|
||||
$response->matchData = $matchData;
|
||||
$response->matchData = MatchData::fromGame($foundGame);
|
||||
|
||||
return $response;
|
||||
}
|
||||
@@ -204,7 +194,7 @@ protected function processQueue(): void
|
||||
rsort($hunterGroupsSet, SORT_NUMERIC);
|
||||
|
||||
$newGame = new Game();
|
||||
$newGame->status = MatchStatus::Opened;
|
||||
$newGame->status = MatchStatus::Created;
|
||||
$newGame->matchConfiguration()->associate($selectedConfig);
|
||||
$newGame->save();
|
||||
|
||||
@@ -223,22 +213,8 @@ protected function processQueue(): void
|
||||
|
||||
$newGame->addQueuedPlayer($runners[$foundQueuedPlayer]);
|
||||
}
|
||||
}
|
||||
|
||||
private function processGames()
|
||||
{
|
||||
$games = Game::where('status', '=', MatchStatus::Opened)->get();
|
||||
|
||||
foreach ($games as $game) {
|
||||
if($game->remainingPlayerCount()->getTotal() == 0) {
|
||||
$hunter = $game->players()->firstWhere('side', '=', MatchmakingSide::Hunter->value);
|
||||
$game->creator()->associate($hunter);
|
||||
$game->status = MatchStatus::Created;
|
||||
$game->save();
|
||||
}
|
||||
|
||||
//Todo: Handle games with missing users later
|
||||
}
|
||||
$newGame->determineHost();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user