private void SendMessage(ulong channelId) { var message = botConfig.msgText; dota.SendChannelMessage(channelId, message); }
/// <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); } }