/// <summary> /// Check if we're in the same game as the leader, and leave if they're different. /// </summary> public static async Task <bool> LeaveWhenInWrongGame() { if (ZetaDia.IsLoadingWorld || DateTime.UtcNow.Subtract(ChangeMonitor.LastGameJoinedTime).Seconds < 5) { return(false); } // Leaves party when out of game the d3-party leader and not the bot-leader. // Disbands party if leader leaves it. if (Player.IsFollower && Player.IsInParty && ZetaDia.Service.Party.IsPartyLeader && !ZetaDia.IsInGame && GameUI.ElementIsVisible(GameUI.OutOfGameLeavePartyButton) && ZetaDia.Service.Party.CurrentPartyLockReasonFlags == PartyLockReasonFlag.None && DateTime.UtcNow.Subtract(_lastAttemptQuickJoin) > TimeSpan.FromSeconds(10)) { Log.Info("We are a follower but leader of party - leaving party"); GameUI.OutOfGameLeavePartyButton.Click(); Coordination.WaitFor(TimeSpan.FromSeconds(5)); return(true); } if (ZetaDia.IsInGame && Player.IsFollower && !AutoFollow.CurrentLeader.IsMe && !AutoFollow.CurrentLeader.IsInSameGame && !AutoFollow.CurrentLeader.IsLoadingWorld) { Log.Warn("Leader is in a different game, Leave Game!", AutoFollow.CurrentLeader.IsInSameGame); await LeaveGame(); Coordination.WaitFor(TimeSpan.FromSeconds(5)); return(true); } return(false); }
/// <summary> /// Tell other bots to leave their game and wait for them to do so. /// </summary> public static async Task <bool> WaitForPlayersToLeaveGame() { if (Player.IsInParty && !Player.IsInGame && (AutoFollow.CurrentParty.Any(m => m.IsInGame) || !GameUI.ChangeQuestButton.IsEnabled)) { Log.Info("Waiting for party members to leave game"); EventManager.FireEvent(new EventData(EventType.LeavingGame, null, null, true)); Coordination.WaitFor(TimeSpan.FromSeconds(5)); return(true); } return(false); }
/// <summary> /// Leave the party if there are strange people in it. /// </summary> public static async Task <bool> LeavePartyUnknownPlayersInGame() { if (AutoFollow.NumberOfConnectedBots == 0 && !GameUI.ChangeQuestButton.IsEnabled && Settings.Misc.AvoidUnknownPlayers) { Log.Info("Unknown players in the party and no connected bots, leaving party."); GameUI.OutOfGameLeavePartyButton.Click(); Coordination.WaitFor(TimeSpan.FromSeconds(5)); return(true); } return(false); }
/// <summary> /// Clicks the start game button once all players have left the game. /// </summary> public static async Task <bool> StartGameWhenPartyReady() { if (ZetaDia.Service.Party.IsPartyLeader && Player.NumPlayersInParty > 1 && Player.NumPlayersInParty == AutoFollow.NumberOfConnectedBots + 1 && GameUI.PlayGameButton.IsEnabled && Player.NumPlayersInParty == AutoFollow.CurrentParty.Count(p => !p.IsInGame)) { Log.Warn("We're all here, starting game"); GameUI.PlayGameButton.Click(); Coordination.WaitFor(TimeSpan.FromSeconds(2)); return(true); } return(false); }
/// <summary> /// Handle being in a party lobby. /// </summary> public static async Task <bool> JoinGameOrLeaveParty() { if (!ZetaDia.Service.Party.IsPartyLeader && Player.IsInParty && !ZetaDia.IsInGame) { if (!IsLeaderInParty()) { Log.Info("Leaving party, leader is not in this group!"); GameUI.OutOfGameLeavePartyButton.Click(); Coordination.WaitFor(TimeSpan.FromSeconds(2)); } else if (GameUI.PlayGameButton.IsEnabled && AutoFollow.CurrentLeader.IsInGame) { Log.Info("We're in party, leader already in game, joining game!"); GameUI.PlayGameButton.Click(); Coordination.WaitFor(TimeSpan.FromSeconds(2)); return(true); } } return(false); }