Merge pull request #57 from Deathgarden-Rebirth/no_scav_left_behind

Force 1v5 and 1v6 matches with exact playercount in queue
This commit is contained in:
Vari 2025-06-17 21:21:30 +02:00 committed by GitHub
commit 258ac3776c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View File

@ -83,7 +83,7 @@ public function handle(): void
if($availableMatchConfigs->isEmpty())
return;
$selectedConfig = MatchConfiguration::selectRandomConfigByWeight($availableMatchConfigs);
$selectedConfig = MatchConfiguration::selectMatchConfig($availableMatchConfigs, $playerCount->runners, $playerCount->hunters);
// Should never happen, but just to be careful
if($selectedConfig === null)

View File

@ -368,7 +368,8 @@ protected function removeUserFromGame(User $user, Game $game)
{
$game->players()->detach($user);
if($game->players->count() !== 0)
// Delete the game if the creator deletes themselfes sice we had one case where the matchmaking broke due to a game being stuck like this.
if($game->players->count() !== 0 && $game->creator_user_id !== $user->id)
return;
$game->delete();

View File

@ -44,8 +44,24 @@ public static function getAvailableMatchConfigs(int $runnerCount, int $hunterCou
->get();
}
public static function selectRandomConfigByWeight(Collection &$collection): MatchConfiguration|null
public static function selectMatchConfig(Collection &$collection, int $runnerCount, int $hunterCount): MatchConfiguration|null
{
$filteredConfigs = new Collection();
if ($hunterCount === 1 && $runnerCount >= 6){
$filteredConfigs = $collection->filter(function (MatchConfiguration $config) use ($runnerCount, $hunterCount) {
return $config->runners >= 6 && $config->hunters === $hunterCount;
});
}
else if ($hunterCount === 1 && $runnerCount >= 4){
$filteredConfigs = $collection->filter(function (MatchConfiguration $config) use ($runnerCount, $hunterCount) {
return $config->runners === $runnerCount && $config->hunters === $hunterCount;
});
}
if ($filteredConfigs->isNotEmpty())
$collection = $filteredConfigs;
$weightSum = $collection->sum('weight');
$random = random_int(1, $weightSum);
$selectWalk = 0;