public async Task <DotaGameResult> GetDota(ulong matchId) { var responseFull = await DotaInterface.GetMatchDetailsAsync(matchId); var MatchDetails = responseFull.Data; var Players = MatchDetails.Players.AsEnumerable(); DotaGameResult returnValue = new DotaGameResult() { MatchId = matchId, RadiantWin = MatchDetails.RadiantWin, Duration = MatchDetails.Duration, BarracksStatesDire = MatchDetails.BarracksStatesDire, BarracksStatesRadiant = MatchDetails.BarracksStatesRadiant, TowerStatesDire = MatchDetails.TowerStatesDire, TowerStatesRadiant = MatchDetails.TowerStatesRadiant, PicksAndBans = new List <HeroesPick>(), Players = new List <DotaPlayer>(), StartTime = MatchDetails.StartTime }; foreach (var pb in MatchDetails.PicksAndBans) { var hero = Heroes.FirstOrDefault((h) => h.Id == pb.HeroId); returnValue.PicksAndBans.Add(new HeroesPick() { IsPick = pb.IsPick, Order = pb.Order, Team = pb.Team, HeroId = hero.Id, HeroName = hero.LocalizedName }); } foreach (var player in Players) { var dotaPlayer = DotaPlayerExtension.DefaultInitialize(player); dotaPlayer.HeroName = Heroes.FirstOrDefault((h) => h.Id == player.HeroId)?.LocalizedName; dotaPlayer.SetPlayerItems(player, Items); returnValue.Players.Add(dotaPlayer); } return(returnValue); }
/// <summary> /// Creates a custom lobby and waits for the specified DotaLobbyParams to be met. /// Starts the match. /// Waits for the match to complete. /// </summary> /// <param name="LobbyName">Name of lobby</param> /// <param name="LobbyPassword">Lobby Password</param> /// <param name="parameters">Lobby Start Parameters</param> public void CreateLobby(string LobbyName, string LobbyPassword, DotaLobbyParams parameters) { if (dota.Lobby != null) { UpdateStatus(DotaClientStatus.Warning, "Lobby: Creating a lobby when already in one."); } CMsgPracticeLobbySetDetails details = new CMsgPracticeLobbySetDetails(); details.game_name = LobbyName; details.pass_key = LobbyPassword; details.game_mode = (uint)DOTA_GameMode.DOTA_GAMEMODE_AP; // game mode details.server_region = (uint)ERegionCode.USEast; details.dota_tv_delay = LobbyDotaTVDelay.LobbyDotaTV_300; details.game_version = DOTAGameVersion.GAME_VERSION_CURRENT; details.visibility = DOTALobbyVisibility.DOTALobbyVisibility_Public; dota.CreateLobby(LobbyPassword, details); // wait for lobby to be created while (dota.Lobby == null) { Thread.Sleep(10); } UpdateStatus(DotaClientStatus.Normal, "Lobby: Lobby Created."); UpdateStatus(DotaClientStatus.Normal, "Lobby: Lobby Name: " + LobbyName); UpdateStatus(DotaClientStatus.Normal, "Lobby: Lobby Password: "******"Lobby: Lobby ID: " + dota.Lobby.lobby_id.ToString()); Thread.Sleep(1000); dota.JoinTeam(DOTA_GC_TEAM.DOTA_GC_TEAM_PLAYER_POOL); // move bot to unassigned UpdateStatus(DotaClientStatus.Normal, "Lobby: Moved bot to player pool."); if (OnLobbyCreated != null) { OnLobbyCreated(dota.Lobby.lobby_id); } UpdateStatus(DotaClientStatus.Normal, "Lobby: Waiting for players to connect...."); List <DateTime> NotificationTimeouts = new List <DateTime>(); NotificationTimeouts.Add(DateTime.Now.AddMinutes(1)); NotificationTimeouts.Add(NotificationTimeouts.Last().AddMinutes(1)); NotificationTimeouts.Add(NotificationTimeouts.Last().AddMinutes(1)); NotificationTimeouts.Add(NotificationTimeouts.Last().AddMinutes(1)); NotificationTimeouts.Add(NotificationTimeouts.Last().AddMinutes(1)); NotificationTimeouts.Reverse(); while (true) { List <CDOTALobbyMember> members = dota.Lobby.members; int count = 0; foreach (CDOTALobbyMember member in members) { if (parameters.isReadyPlayer(member)) { count++; } } if (parameters.hasAllPlayers(count)) { break; } Thread.Sleep(1000); if (NotificationTimeouts.Count == 0) { continue; //TODO: cancel the match and reset bot } if (DateTime.Now > NotificationTimeouts[0]) { dota.SendChannelMessage(dota.Lobby.lobby_id, "Players have " + NotificationTimeouts.Count.ToString() + " minute" + (NotificationTimeouts.Count == 1 ? "" : "s") + " to join the lobby."); NotificationTimeouts.RemoveAt(0); } } UpdateStatus(DotaClientStatus.Normal, "Lobby: Starting Lobby."); dota.LaunchLobby(); UpdateStatus(DotaClientStatus.Normal, "Match: Waiting for MatchID."); while (dota.Lobby.match_id == 0) { Thread.Sleep(10); } MatchID = dota.Lobby.match_id; if (OnGameStarted != null) { OnGameStarted(MatchID); } EMatchOutcome outcome = WaitForMatchEnd(); UpdateStatus(DotaClientStatus.Normal, "Match: Result: " + Enum.GetName(typeof(EMatchOutcome), dota.Lobby.match_outcome)); //publish game result if (OnGameFinished != null) { DotaGameResult result = DotaGameResult.Unknown; if (outcome == EMatchOutcome.k_EMatchOutcome_RadVictory) { result = DotaGameResult.Radiant; } else if (outcome == EMatchOutcome.k_EMatchOutcome_DireVictory) { result = DotaGameResult.Dire; } OnGameFinished(result); } }