public static bool ChangeAgentInteractionState(AgentInteractionState agentInteractionState, bool WaitAMomentbeforeNextAction = false, string LogMessage = null) { try { // // if _ArmStateToSet matches also do this stuff... // switch (agentInteractionState) { case AgentInteractionState.Done: break; case AgentInteractionState.Idle: break; } } catch (Exception ex) { Logging.Log(_States.CurrentArmState.ToString(), "Exception [" + ex + "]", Logging.Red); return false; } try { _lastAgentActionStateChange = DateTime.UtcNow; if (_States.CurrentAgentInteractionState != agentInteractionState) { _States.CurrentAgentInteractionState = agentInteractionState; if (WaitAMomentbeforeNextAction) _lastAgentAction = DateTime.UtcNow; else AgentInteraction.ProcessState(); } return true; } catch (Exception ex) { Logging.Log(_States.CurrentAgentInteractionState.ToString(), "Exception [" + ex + "]", Logging.Red); return false; } }
public void CloseConversation() { var agentWindow = Agent.Window; if (agentWindow == null) { Logging.Log("AgentInteraction: Done"); State = AgentInteractionState.Done; return; } agentWindow.Close(); }
public void ProcessState() { // Wait a bit before doing "things" if (DateTime.Now < _nextAction) return; switch (State) { case AgentInteractionState.Idle: case AgentInteractionState.Done: break; case AgentInteractionState.StartConversation: Agent.InteractWith(); Logging.Log("AgentInteraction: Waiting for conversation"); State = AgentInteractionState.WaitForConversation; break; case AgentInteractionState.WaitForConversation: WaitForConversation(); break; case AgentInteractionState.ReplyToAgent: ReplyToAgent(); break; case AgentInteractionState.WaitForMission: WaitForMission(); break; case AgentInteractionState.AcceptMission: AcceptMission(); break; case AgentInteractionState.DeclineMission: DeclineMission(); break; case AgentInteractionState.CloseConversation: CloseConversation(); break; } }
private void WaitForMission() { var agentWindow = Agent.Window; if (agentWindow == null || !agentWindow.IsReady) return; var journalWindow = Cache.Instance.GetWindowByName("journal"); if (journalWindow == null) { if (DateTime.Now.Subtract(_lastMissionOpenRequest).TotalSeconds > 10) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenJournal); _lastMissionOpenRequest = DateTime.Now; } return; } var mission = Cache.Instance.DirectEve.AgentMissions.FirstOrDefault(m => m.AgentId == AgentId); if (mission == null) return; var missionName = Cache.Instance.FilterPath(mission.Name); if (!ForceAccept) { // Is the mission offered? if (mission.State == (int) MissionState.Offered && (mission.Type == "Courier" || mission.Type == "Mining" || mission.Type == "Trade" || Settings.Instance.Blacklist.Any(m => m.ToLower() == missionName.ToLower()))) { Logging.Log("AgentInteraction: Declining courier/mining/trade/blacklisted mission [" + missionName + "]"); State = AgentInteractionState.DeclineMission; _nextAction = DateTime.Now.AddSeconds(7); return; } } var html = agentWindow.Objective; if (html.Contains("The route generated by current autopilot settings contains low security systems!")) { if (Purpose != AgentInteractionPurpose.AmmoCheck) Logging.Log("AgentInteraction: Declining low-sec mission"); State = AgentInteractionState.DeclineMission; _nextAction = DateTime.Now.AddSeconds(7); return; } var loadedAmmo = false; var missionXmlPath = Path.Combine(Settings.Instance.MissionsPath, missionName + ".xml"); if (File.Exists(missionXmlPath)) { Logging.Log("AgentInteraction: Loading mission xml [" + missionName + "]"); try { var missionXml = XDocument.Load(missionXmlPath); var damageTypes = missionXml.XPathSelectElements("//damagetype").Select(e => (DamageType) Enum.Parse(typeof (DamageType), (string) e, true)); if (damageTypes.Any()) { LoadSpecificAmmo(damageTypes.Distinct()); loadedAmmo = true; } } catch (Exception ex) { Logging.Log("AgentInteraction: Error parsing damage types for mission [" + mission.Name + "], " + ex.Message); } } if (!loadedAmmo) { Logging.Log("AgentInteraction: Detecting damage type for [" + missionName + "]"); Cache.Instance.DamageType = GetMissionDamageType(html); LoadSpecificAmmo(new[] {Cache.Instance.DamageType}); } if (Purpose == AgentInteractionPurpose.AmmoCheck) { Logging.Log("AgentInteraction: Closing conversation"); State = AgentInteractionState.CloseConversation; return; } if (mission.State == (int) MissionState.Offered) { Logging.Log("AgentInteraction: Accepting mission [" + missionName + "]"); State = AgentInteractionState.AcceptMission; _nextAction = DateTime.Now.AddSeconds(7); } else // If we already accepted the mission, close the convo { Logging.Log("AgentInteraction: Mission [" + missionName + "] already accepted"); Logging.Log("AgentInteraction: Closing conversation"); State = AgentInteractionState.CloseConversation; _nextAction = DateTime.Now.AddSeconds(7); } }
private void WaitForConversation() { var agentWindow = Agent.Window; if (agentWindow == null || !agentWindow.IsReady) return; if (Purpose == AgentInteractionPurpose.AmmoCheck) { Logging.Log("AgentInteraction: Checking ammo type"); State = AgentInteractionState.WaitForMission; } else { Logging.Log("AgentInteraction: Replying to agent"); State = AgentInteractionState.ReplyToAgent; _nextAction = DateTime.Now.AddSeconds(7); } }
private void ReplyToAgent() { var agentWindow = Agent.Window; if (agentWindow == null || !agentWindow.IsReady) return; var responses = agentWindow.AgentResponses; if (responses == null || responses.Count == 0) return; var request = responses.FirstOrDefault(r => r.Text.Contains(RequestMission)); var complete = responses.FirstOrDefault(r => r.Text.Contains(CompleteMission)); var view = responses.FirstOrDefault(r => r.Text.Contains(ViewMission)); var accept = responses.FirstOrDefault(r => r.Text.Contains(Accept)); var decline = responses.FirstOrDefault(r => r.Text.Contains(Decline)); if (complete != null) { if (Purpose == AgentInteractionPurpose.CompleteMission) { // Complete the mission, close convo Logging.Log("AgentInteraction: Saying [Complete Mission]"); complete.Say(); Logging.Log("AgentInteraction: Closing conversation"); State = AgentInteractionState.CloseConversation; _nextAction = DateTime.Now.AddSeconds(7); } else { Logging.Log("AgentInteraction: Waiting for mission"); // Apparently someone clicked "accept" already State = AgentInteractionState.WaitForMission; _nextAction = DateTime.Now.AddSeconds(7); } } else if (request != null) { if (Purpose == AgentInteractionPurpose.StartMission) { // Request a mission and wait for it Logging.Log("AgentInteraction: Saying [Request Mission]"); request.Say(); Logging.Log("AgentInteraction: Waiting for mission"); State = AgentInteractionState.WaitForMission; _nextAction = DateTime.Now.AddSeconds(7); } else { Logging.Log("AgentInteraction: Unexpected dialog options"); State = AgentInteractionState.UnexpectedDialogOptions; } } else if (view != null) { // View current mission Logging.Log("AgentInteraction: Saying [View Mission]"); view.Say(); _nextAction = DateTime.Now.AddSeconds(7); // No state change } else if (accept != null || decline != null) { if (Purpose == AgentInteractionPurpose.StartMission) { Logging.Log("AgentInteraction: Waiting for mission"); State = AgentInteractionState.WaitForMission; // Dont say anything, wait for the mission _nextAction = DateTime.Now.AddSeconds(7); } else { Logging.Log("AgentInteraction: Unexpected dialog options"); State = AgentInteractionState.UnexpectedDialogOptions; } } }
private void DeclineMission() { // If we are doing an ammo check then Decline Mission is an end-state! if (Purpose == AgentInteractionPurpose.AmmoCheck) return; var agentWindow = Agent.Window; if (agentWindow == null || !agentWindow.IsReady) return; var responses = agentWindow.AgentResponses; if (responses == null || responses.Count == 0) return; var decline = responses.FirstOrDefault(r => r.Text.Contains(Decline)); if (decline == null) return; // Decline and request a new mission Logging.Log("AgentInteraction: Saying [Decline]"); decline.Say(); Logging.Log("AgentInteraction: Replying to agent"); State = AgentInteractionState.ReplyToAgent; _nextAction = DateTime.Now.AddSeconds(7); }
private void AcceptMission() { var agentWindow = Agent.Window; if (agentWindow == null || !agentWindow.IsReady) return; var responses = agentWindow.AgentResponses; if (responses == null || responses.Count == 0) return; var accept = responses.FirstOrDefault(r => r.Text.Contains(Accept)); if (accept == null) return; Logging.Log("AgentInteraction: Saying [Accept]"); accept.Say(); Logging.Log("AgentInteraction: Closing conversation"); State = AgentInteractionState.CloseConversation; _nextAction = DateTime.Now.AddSeconds(7); }