public async Task <DateTimeOffset> AddPlayerToQueue(string playerId) { var currentEntry = await _dbContext.MatchmakingEntries.FirstOrDefaultAsync(x => x.PlayerId == playerId); if (currentEntry == null) { currentEntry = new MatchmakingEntry(playerId, DateTime.UtcNow); _dbContext.MatchmakingEntries.Add(currentEntry); _logger.LogInformation("Player joined queue, {@details}", new { PlayerId = playerId, }); } else { currentEntry.LatestJoinDate = DateTime.UtcNow; _logger.LogInformation("Player rejoined queue, {@details}", new { PlayerId = playerId, }); } await _dbContext.SaveChangesAsync(); return(currentEntry.CreatedDate); }
public IActionResult InitiateAutomaticDuel(string deckName) { try { MatchmakingEntry match = matchmaker.FindMatch(requestContext, deckName); if (match != null && match.IsMatched && match.ShouldInitiate) { Task.Run(() => ExecuteDuel(match)); } return(Json(match, new JsonSerializerOptions() { WriteIndented = true })); } catch (SessionTokenNotFoundException nfEx) { return(Unauthorized(nfEx.Message)); } catch (Exception ex) when(ex is InvalidSessionTokenFormatException || ex is SessionExpiredException || ex is ValidationException) { return(BadRequest(ex.Message)); } }
private void ExecuteDuel(MatchmakingEntry match) { try { duelModule.ExecuteDuel(match, ProjectConstants.MaxNumberOfRounds); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public IActionResult GetBattleResult(MatchmakingEntry match) { Assert.NotNull(match, nameof(match)); BattleLog result = duelModule.GetBattleLog(match.MatchID); return(Json(result, new JsonSerializerOptions() { WriteIndented = true })); }
private static GameAvatar FindEnemy(MatchmakingEntry entry, Dictionary <long, GameAvatar> documents) { GameAvatar document = entry.Session.GameAvatar; LogicClientAvatar playerAvatar1 = document.LogicClientAvatar; int totalSecs = TimeUtil.GetTimestamp() - entry.Timestamp; int strength1 = GameMatchmakingManager.CalculateStrength(playerAvatar1); int maxStrengthDiff = 50 + LogicMath.Clamp(totalSecs * 150 / 60, 0, 150); foreach (GameAvatar enemy in documents.Values) { LogicClientAvatar playerAvatar2 = enemy.LogicClientAvatar; #if DEBUG if (ServerCore.Random.Rand(100) <= 95) { continue; } #else if (playerAvatar1.IsInAlliance() && playerAvatar2.IsInAlliance() && playerAvatar1.GetAllianceId().Equals(playerAvatar2.GetAllianceId())) { continue; } int strength2 = GameMatchmakingManager.CalculateStrength(playerAvatar2); if (LogicMath.Abs(strength1 - strength2) >= maxStrengthDiff) { continue; } if (document.HasRecentlyMatchedWithEnemy(enemy.Id)) { continue; } #endif return(enemy); } return(null); }
private static GameAvatar FindEnemy(MatchmakingEntry entry, Dictionary <long, GameAvatar> documents) { return(null); }