internal static void LeaderOutOfGameUpdate() { Leader = Message.GetMessage(); if (Settings.Instance.DebugLogging) { Logr.Debug("Leader OutOfGame: {0}", Leader); } }
private const int RiftPortalSNO = 345935; // X1_OpenWorld_LootRunPortal internal static bool ShouldFollowerOpenRift() { if (Player.IsGreaterRiftStarted) { return(false); } if (ZetaDia.WorldType != Act.OpenWorld) { return(false); } if (SimpleFollow.IsLeader) { // Current profile tag must be OpenRift / QTOpenRiftWrapper var currentBehavior = ProfileManager.CurrentProfileBehavior; if (currentBehavior != null && !currentBehavior.GetType().Name.Contains("OpenRift")) { return(false); } if (!SimpleFollow.Followers.Any()) { return(false); } if (!SimpleFollow.Followers.Any(f => f.Value.HasRiftKeys)) { return(false); } } // In regular rift quests if (ConditionParser.IsActiveQuestAndStep(337492, 1) || ConditionParser.IsActiveQuestAndStep(337492, 3) || ConditionParser.IsActiveQuestAndStep(337492, 13) || ConditionParser.IsActiveQuestAndStep(337492, 16)) { return(false); } var portals = ZetaDia.Actors.GetActorsOfType <GizmoPortal>(true).Where(p => p.ActorSNO == RiftPortalSNO).ToList(); if (portals.Any()) { return(false); } var allFollowersConnected = SimpleFollow.Followers.Count == Social.NumPartyMembers - 1; Logr.Debug("Follower Count={0}, NumPartyMembers={1}", SimpleFollow.Followers.Count, Social.NumPartyMembers); Logr.Debug("HighestTeamRiftKey={0} HighestLevelTieredRiftKey={1}", SimpleFollow.Leader.HighestTeamRiftKey, SimpleFollow.Leader.HighestLevelTieredRiftKey); var result = allFollowersConnected && SimpleFollow.Leader.HighestTeamRiftKey <= SimpleFollow.Leader.HighestLevelTieredRiftKey; Logr.Debug("RequestFollowerOpenRift?={0}", result); return(result); }
public void Update() { if (DateTime.UtcNow.Subtract(LastUpdate).TotalMilliseconds < Settings.Instance.UpdateInterval) { return; } LastUpdate = DateTime.UtcNow; IsInGame = ZetaDia.IsInGame; if (!ZetaDia.IsInGame || ZetaDia.IsLoadingWorld || !ZetaDia.Me.IsValid) { return; } ACDGuid = ZetaDia.Me.ACDGuid; HitpointsCurrent = ZetaDia.Me.HitpointsCurrent; HitpointsCurrentPct = ZetaDia.Me.HitpointsCurrentPct; HitpointsMaxTotal = ZetaDia.Me.HitpointsMaxTotal; Position = ZetaDia.Me.Position; CurrentLevelAreaId = LevelAreaId; CurrentWorldId = ZetaDia.CurrentWorldId; CurrentDynamicWorldId = ZetaDia.CurrentWorldDynamicId; IsInTown = ZetaDia.IsInTown; IsVendoring = BrainBehavior.IsVendoring; IsParticipatingInTieredLootRun = ZetaDia.Me.IsParticipatingInTieredLootRun; InTieredLootRunLevel = ZetaDia.Me.InTieredLootRunLevel; if (_lastLogMessage != ToString()) { _lastLogMessage = ToString(); if (Settings.Instance.DebugLogging) { Logr.Debug("Updated {0}", ToString()); } } }
internal static void PulseInbox() { // Process Messages Queue <Message> messages = new Queue <Message>(); try { lock (Inbox) while (Inbox.ToList().Any()) { Message msg; if (Inbox.TryDequeue(out msg) && msg != null) { messages.Enqueue(msg); } } } catch (Exception ex) { Logr.Log(ex.ToString()); } CleanExpiredFollowers(); while (messages.ToList().Any()) { var message = messages.Dequeue(); if (message == null) { continue; } try { if (message.BattleTagHash != 0) { if (Followers.ContainsKey(message.BattleTagHash)) { Followers[message.BattleTagHash] = message; } else { Followers.Add(message.BattleTagHash, message); } } if (Settings.Instance.DebugLogging) { Logr.Debug("Received follower message: {0}", message); } if (!message.IsInParty && !message.IsInGame && Leader.IsInGame) { Logr.Debug("Inviting {0} ({1}) to the party - Not in game. IsInGame={2} IsInParty={3} NumPartyMembers={4}", message.ActorClass, message.BattleTagHash, message.IsInGame, message.IsInParty, message.NumPartymembers); Social.Instance.CheckInvites(); continue; } if (!message.IsInParty && (message.GameId.FactoryId == 0 && message.GameId.High == 0 && message.GameId.Low == 0) && !Leader.IsInGame) { Logr.Debug("Inviting {0} ({1}) to the party - Needs Invite. IsInGame={2} IsInParty={3} NumPartyMembers={4}", message.ActorClass, message.BattleTagHash, message.IsInGame, message.IsInParty, message.NumPartymembers); Social.Instance.CheckInvites(); continue; } if (!Leader.GameId.Equals(message.GameId)) { Logr.Debug("Inviting {0} ({1}) to the party - Incorrect Game. IsInGame={2} IsInParty={3} NumPartyMembers={4}", message.ActorClass, message.BattleTagHash, message.IsInGame, message.IsInParty, message.NumPartymembers); Social.Instance.CheckInvites(); continue; } if (Leader.GameId.Equals(message.GameId)) { Social.Instance.CheckCloseSocialWindow(); continue; } Logr.Log("Message response: invalid/unknown state"); } catch (Exception ex) { Logr.Log("Exception receiving update from client!"); Logr.Log(ex.ToString()); return; } } }
internal void CheckInvites() { if (!BotMain.IsRunning) { return; } if (ZetaDia.IsLoadingWorld) { return; } if (ZetaDia.Me != null && !ZetaDia.Me.IsValid) { return; } if (ZetaDia.IsInGame && ZetaDia.Me != null && ZetaDia.Me.IsValid && ZetaDia.Me.IsDead) { return; } if (GameUI.ElementIsVisible(GameUI.BattleNetOK, "BattleNetOK")) { GameUI.SafeCheckClickButtons(); return; } const int recheckDuration = 500; if (!recheckInvites && DateTime.UtcNow.Subtract(lastInviteCheck).TotalMilliseconds < recheckDuration) { return; } lastInviteCheck = DateTime.UtcNow; if (ZetaDia.Service.Party.IsPartyFull) { recheckInvites = false; if (IsSocialWindowOpen) { CloseSocialWindow(); } return; } // Start inviting if (!IsSocialWindowOpen) { Logr.Debug("Opening Social Window"); OpenSocialWindow(); return; } if (IsSocialWindowOpen) { if (Settings.Instance.InviteFriend1 && GameUI.ElementIsVisible(Friend1InviteButton, "Friend 1 Invite")) { GameUI.SafeClick(Friend1InviteButton, ClickDelay.NoDelay, "Friend 1 Invite", 750); recheckInvites = true; return; } if (Settings.Instance.InviteFriend2 && GameUI.ElementIsVisible(Friend2InviteButton, "Friend 2 Invite")) { GameUI.SafeClick(Friend2InviteButton, ClickDelay.NoDelay, "Friend 2 Invite", 750); recheckInvites = true; return; } if (Settings.Instance.InviteFriend3 && GameUI.ElementIsVisible(Friend3InviteButton, "Friend 3 Invite")) { GameUI.SafeClick(Friend3InviteButton, ClickDelay.NoDelay, "Friend 3 Invite", 750); recheckInvites = true; return; } if (Settings.Instance.InviteFriend3 && GameUI.ElementIsVisible(Friend3AlternateInviteButton, "Friend 3 Alternate Invite")) { GameUI.SafeClick(Friend3AlternateInviteButton, ClickDelay.NoDelay, "Friend 3 Invite", 750); recheckInvites = true; return; } if (Settings.Instance.InviteFriend4 && GameUI.ElementIsVisible(Friend4InviteButton, "Friend 4 Invite")) { GameUI.SafeClick(Friend4InviteButton, ClickDelay.NoDelay, "Friend 4 Invite", 750); recheckInvites = true; return; } if (Settings.Instance.InviteFriend4 && GameUI.ElementIsVisible(Friend4AlternateInviteButton, "Friend 4 Alternate Invite")) { GameUI.SafeClick(Friend4AlternateInviteButton, ClickDelay.NoDelay, "Friend 4 Alternate Invite", 750); recheckInvites = true; return; } Logr.Debug("No more invites possible"); recheckInvites = false; CloseSocialWindow(); } }
/// <summary> /// Called by followers through FollowTag->Communicate() /// </summary> private static void ClientUpdate() { if (Enabled) { _updateRunning = true; try { if (Host != null && Host.State == CommunicationState.Opened) { Logr.Log("Shutting down Server Service"); Host.Close(); Host = null; } } catch (Exception ex) { Logr.Error("Error shutting down server service: " + ex); } StartClient(); try { if (Initialized && Leader.GetMillisecondsSinceLastUpdate() >= 250) { // Get the leader message and store it Leader = HttpProxy.GetUpdate(); // Send our follower message to the leader HttpProxy.SendUpdate(_lastMessage); if (LastLeaderUpdateMessage == null || LastLeaderUpdateMessage != Leader) { LastLeaderUpdateMessage = Leader; SetQuestToolsOptionsFromLeader(); if (Settings.Instance.DebugLogging) { Logr.Debug("Leader {0}", Leader.ToString()); } } } } catch (EndpointNotFoundException ex) { Logr.Error("Error 201: Could not get an update from the leader using {0}. Is the leader running? ({1})", HttpFactory.Endpoint.Address.Uri.AbsoluteUri, ex.Message); Initialized = false; } catch (CommunicationException ex) { Logr.Error("Error 202: Could not get an update from the leader using {0}. Is the leader running? ({1})", HttpFactory.Endpoint.Address.Uri.AbsoluteUri, ex.Message); Initialized = false; } catch (Exception ex) { Logr.Error("Error 203: Could not get an update from the leader using {0}. Is the leader running?", HttpFactory.Endpoint.Address.Uri.AbsoluteUri); Initialized = false; Logr.Log(ex.ToString()); } _updateRunning = false; } }
/// <summary> /// Clicks a UI Element after a random interval. /// </summary> /// <param name="uiElement"></param> /// <param name="name"></param> /// <returns></returns> internal static bool SafeClick(UIElement uiElement, ClickDelay delayOption, string name = "", int postClickThreadSleepDuration = 0, bool fireWorldTransferStart = false) { try { if (DateTime.UtcNow.Subtract(_lastClick).TotalMilliseconds < 500) { return(false); } if (ElementIsVisible(uiElement, name)) { if (!String.IsNullOrEmpty(name)) { Logr.Debug("{0} button is visible", name); } else { Logr.Debug("{0}={1} is visible", uiElement.Hash, uiElement.Name); } if (!clickTimer.IsRunning && delayOption == ClickDelay.Delay) { clickTimer.Start(); SetClickTimerRandomVal(); } else if ((ClickTimerRandomReady() && ElementIsVisible(uiElement, name)) || delayOption == ClickDelay.NoDelay) { if (!String.IsNullOrEmpty(name)) { Logr.Log("Clicking {0} button", name); } else { Logr.Log("Clicking {0}={1}", uiElement.Hash, uiElement.Name); } // sleep plugins for a bit if (ZetaDia.IsInGame && fireWorldTransferStart) { GameEvents.FireWorldTransferStart(); } _lastClick = DateTime.UtcNow; uiElement.Click(); //BotMain.PauseFor(TimeSpan.FromMilliseconds(ClickThreadSleepInterval)); //if (postClickThreadSleepDuration > 0) // BotMain.PauseFor(TimeSpan.FromMilliseconds(postClickThreadSleepDuration)); clickTimer.Reset(); } else { Logr.Debug("Pausing bot, waiting for {0}={1}", uiElement.Hash, uiElement.Name); BotMain.PauseWhile(ClickTimerRandomNotReady, 0, ClickTimerTimeout); } } return(true); } catch (Exception ex) { Logr.Log("Error clicking UI button {0}: " + ex.ToString(), name); return(false); } }