diff --git a/dist/app/Console/Commands/ProcessMatchmaking.php b/dist/app/Console/Commands/ProcessMatchmaking.php index 84816a0..89e9f2a 100644 --- a/dist/app/Console/Commands/ProcessMatchmaking.php +++ b/dist/app/Console/Commands/ProcessMatchmaking.php @@ -10,11 +10,20 @@ use App\Models\Game\Matchmaking\QueuedPlayer; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Cache; use Log; use Psr\Log\LoggerInterface; class ProcessMatchmaking extends Command { + /** + * How long the matchmakign shoudl wait when only one 1v4 or 1v5 could be made before actually making it. + */ + const ONE_VS_FOUR_AND_FIVE_WAIT_TIME = 20; + + const ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY = 'matchmaking_attempt_1v4_1v5'; + /** * The name and signature of the console command. * @@ -78,9 +87,27 @@ public function handle(): void )); $playerCount = $this->getTotalPlayersCount($players); - if ($playerCount->hunters === 1 && ($playerCount->runners === 4 || $playerCount->runners === 5)) - sleep(10); - $playerCount = $this->getTotalPlayersCount($players); + + // If we only have one Hunter and could make a 1v4 or 1v5 we want to wait a bit before making a match. + // because there could be some runners not being fast enough in queue or the matchmaking command running unfortunatly while players are queuing up. + if ($playerCount->hunters === 1 && ($playerCount->runners === 4 || $playerCount->runners === 5)) { + if (Cache::has(static::ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY)) { + /** @var Carbon $firstAttempt */ + $firstAttempt = Cache::get(static::ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY); + if ($firstAttempt->diffInSeconds(Carbon::now()) < static::ONE_VS_FOUR_AND_FIVE_WAIT_TIME){ + return; + } + Cache::forget(static::ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY); + } + else { + Cache::set(static::ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY, Carbon::now()); + return; + } + } + else { + Cache::forget(static::ONE_VS_FOUR_AND_VS_FIVE_FIST_ATTEMPT_CACHE_KEY); + } + $availableMatchConfigs = MatchConfiguration::getAvailableMatchConfigs($playerCount->runners, $playerCount->hunters); if($availableMatchConfigs->isEmpty())