private void PerformAction(Action action) { switch (action.State) { case ActionState.Activate: ActivateAction(action); break; case ActionState.ClearPocket: ClearPocketAction(action); break; case ActionState.SalvageBookmark: BookmarkPocketForSalvaging(); _currentAction++; break; case ActionState.Done: // Tell the drones module to retract drones Cache.Instance.IsMissionPocketDone = true; // We do not switch to "done" status if we still have drones out if (Cache.Instance.ActiveDrones.Count() > 0) return; // Add bookmark (before we're done) if(Settings.Instance.CreateSalvageBookmarks) BookmarkPocketForSalvaging(); // Reload weapons ReloadAll(); State = AnomalyControllerState.Done; break; case ActionState.Kill: KillAction(action); break; case ActionState.MoveTo: MoveToAction(action); break; case ActionState.Loot: LootAction(action); break; case ActionState.LootItem: LootItemAction(action); break; case ActionState.Ignore: IgnoreAction(action); break; case ActionState.WaitUntilTargeted: WaitUntilTargeted(action); break; } }
public void ProcessState() { // What? No ship entity? if (Cache.Instance.DirectEve.ActiveShip.Entity == null) return; switch (State) { case AnomalyControllerState.Idle: case AnomalyControllerState.Done: case AnomalyControllerState.Error: break; case AnomalyControllerState.Start: _pocket = 0; // Update x/y/z so that NextPocket wont think we are there yet because its checking (very) old x/y/z cords _lastX = Cache.Instance.DirectEve.ActiveShip.Entity.X; _lastY = Cache.Instance.DirectEve.ActiveShip.Entity.Y; _lastZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z; State = AnomalyControllerState.LoadPocket; break; case AnomalyControllerState.LoadPocket: _pocketActions.Clear(); _pocketActions.AddRange(Cache.Instance.LoadMissionActions(0, _pocket, false)); if (_pocketActions.Count == 0) { // No Pocket action, load default actions Logging.Log("AnomalyController: No mission actions specified, loading default actions"); // Wait for 30 seconds to be targeted _pocketActions.Add(new Action {State = ActionState.WaitUntilTargeted}); _pocketActions[0].AddParameter("timeout", "15"); // Clear the Pocket _pocketActions.Add(new Action {State = ActionState.ClearPocket}); // Is there a gate? var gates = Cache.Instance.EntitiesByName("Acceleration Gate"); if (gates != null && gates.Count() > 0) { // Activate it (Activate action also moves to the gate) _pocketActions.Add(new Action {State = ActionState.Activate}); _pocketActions[_pocketActions.Count - 1].AddParameter("target", "Acceleration Gate"); } else // No, were done _pocketActions.Add(new Action {State = ActionState.Done}); // TODO: Check mission HTML to see if we need to pickup any items // Not a priority, apparently retrieving HTML causes a lot of crashes } Logging.Log("AnomalyController: Pocket loaded, executing the following actions"); foreach (var a in _pocketActions) Logging.Log("AnomalyController: Action." + a); if (Cache.Instance.OrbitDistance != Settings.Instance.OrbitDistance) Logging.Log("AnomalyController: Using custom orbit distance: " + Cache.Instance.OrbitDistance); // Reset pocket information _currentAction = 0; Cache.Instance.IsMissionPocketDone = false; Cache.Instance.IgnoreTargets.Clear(); State = AnomalyControllerState.ExecutePocketActions; break; case AnomalyControllerState.ExecutePocketActions: if (_currentAction >= _pocketActions.Count) { // No more actions, but we're not done?!?!?! Logging.Log("AnomalyController: We're out of actions but did not process a 'Done' or 'Activate' action"); State = AnomalyControllerState.Error; break; } var action = _pocketActions[_currentAction]; var currentAction = _currentAction; PerformAction(action); if (currentAction != _currentAction) { Logging.Log("AnomalyController: Finished Action." + action); if (_currentAction < _pocketActions.Count) { action = _pocketActions[_currentAction]; Logging.Log("AnomalyController: Starting Action." + action); } } if (Settings.Instance.DebugStates) Logging.Log("Action.State = " + action); break; case AnomalyControllerState.NextPocket: var distance = Cache.Instance.DistanceFromMe(_lastX, _lastY, _lastZ); if (distance > (int)Distance.NextPocketDistance) { Logging.Log("AnomalyController: We've moved to the next Pocket [" + Math.Round(distance/1000,0) + "k away]"); // If we moved more then 100km, assume next Pocket _pocket++; State = AnomalyControllerState.LoadPocket; } else if (DateTime.Now.Subtract(_lastActivateAction).TotalMinutes > 2) { Logging.Log("AnomalyController: We've timed out, retry last action"); // We have reached a timeout, revert to ExecutePocketActions (e.g. most likely Activate) State = AnomalyControllerState.ExecutePocketActions; } break; } var newX = Cache.Instance.DirectEve.ActiveShip.Entity.X; var newY = Cache.Instance.DirectEve.ActiveShip.Entity.Y; var newZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z; // For some reason x/y/z returned 0 sometimes if (newX != 0 && newY != 0 && newZ != 0) { // Save X/Y/Z so that NextPocket can check if we actually went to the next Pocket :) _lastX = newX; _lastY = newY; _lastZ = newZ; } }
private void ActivateAction(Action action) { var target = action.GetParameterValue("target"); // No parameter? Although we shouldnt really allow it, assume its the acceleration gate :) if (string.IsNullOrEmpty(target)) target = "Acceleration Gate"; var targets = Cache.Instance.EntitiesByName(target); if (targets == null || targets.Count() == 0) { Logging.Log("AnomalyController.Activate: Can't find [" + target + "] to activate! Stopping Questor!"); State = AnomalyControllerState.Error; return; } var closest = targets.OrderBy(t => t.Distance).First(); if (closest.Distance < (int)Distance.GateActivationRange) { // Tell the drones module to retract drones Cache.Instance.IsMissionPocketDone = true; // We cant activate if we have drones out if (Cache.Instance.ActiveDrones.Count() > 0) return; if (closest.Distance < (int)Distance.WayTooClose) { if ((DateTime.Now.Subtract(_lastOrbit).TotalSeconds > 15)) { closest.Orbit((int)Distance.GateActivationRange); Logging.Log("AnomolyController: Activate: initiating Orbit of [" + closest.Name + "] orbiting at [" + Cache.Instance.OrbitDistance + "]"); _lastOrbit = DateTime.Now; } } Logging.Log(" dist " + closest.Distance); if (closest.Distance >= (int)Distance.WayTooClose) { // Add bookmark (before we activate) if (Settings.Instance.CreateSalvageBookmarks) BookmarkPocketForSalvaging(); // Reload weapons and activate gate to move to the next pocket ReloadAll(); closest.Activate(); // Do not change actions, if NextPocket gets a timeout (>2 mins) then it reverts to the last action Logging.Log("AnomalyController.Activate: Activate [" + closest.Name + "] and change state to 'NextPocket'"); _lastActivateAction = DateTime.Now; State = AnomalyControllerState.NextPocket; } } else if (closest.Distance < (int)Distance.WarptoDistance) { // Move to the target if (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closest.Id) { Logging.Log("AnomalyController.Activate: Approaching target [" + closest.Name + "][ID: " + closest.Id + "]"); closest.Approach(); } } else { // We cant warp if we have drones out if (Cache.Instance.ActiveDrones.Count() > 0) return; if (DateTime.Now.Subtract(_lastAlign ).TotalMinutes > 2) { // Probably never happens closest.AlignTo(); _lastAlign = DateTime.Now; } } }
public void ProcessState() { // What? No ship entity? if (Cache.Instance.DirectEve.ActiveShip.Entity == null) { return; } switch (State) { case AnomalyControllerState.Idle: case AnomalyControllerState.Done: case AnomalyControllerState.Error: break; case AnomalyControllerState.Start: _pocket = 0; // Update x/y/z so that NextPocket wont think we are there yet because its checking (very) old x/y/z cords _lastX = Cache.Instance.DirectEve.ActiveShip.Entity.X; _lastY = Cache.Instance.DirectEve.ActiveShip.Entity.Y; _lastZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z; State = AnomalyControllerState.LoadPocket; break; case AnomalyControllerState.LoadPocket: _pocketActions.Clear(); _pocketActions.AddRange(Cache.Instance.LoadMissionActions(0, _pocket, false)); if (_pocketActions.Count == 0) { // No Pocket action, load default actions Logging.Log("AnomalyController: No mission actions specified, loading default actions"); // Wait for 30 seconds to be targeted _pocketActions.Add(new Action { State = ActionState.WaitUntilTargeted }); _pocketActions[0].AddParameter("timeout", "15"); // Clear the Pocket _pocketActions.Add(new Action { State = ActionState.ClearPocket }); // Is there a gate? var gates = Cache.Instance.EntitiesByName("Acceleration Gate"); if (gates != null && gates.Count() > 0) { // Activate it (Activate action also moves to the gate) _pocketActions.Add(new Action { State = ActionState.Activate }); _pocketActions[_pocketActions.Count - 1].AddParameter("target", "Acceleration Gate"); } else // No, were done { _pocketActions.Add(new Action { State = ActionState.Done }); } // TODO: Check mission HTML to see if we need to pickup any items // Not a priority, apparently retrieving HTML causes a lot of crashes } Logging.Log("AnomalyController: Pocket loaded, executing the following actions"); foreach (var a in _pocketActions) { Logging.Log("AnomalyController: Action." + a); } if (Cache.Instance.OrbitDistance != Settings.Instance.OrbitDistance) { Logging.Log("AnomalyController: Using custom orbit distance: " + Cache.Instance.OrbitDistance); } // Reset pocket information _currentAction = 0; Cache.Instance.IsMissionPocketDone = false; Cache.Instance.IgnoreTargets.Clear(); State = AnomalyControllerState.ExecutePocketActions; break; case AnomalyControllerState.ExecutePocketActions: if (_currentAction >= _pocketActions.Count) { // No more actions, but we're not done?!?!?! Logging.Log("AnomalyController: We're out of actions but did not process a 'Done' or 'Activate' action"); State = AnomalyControllerState.Error; break; } var action = _pocketActions[_currentAction]; var currentAction = _currentAction; PerformAction(action); if (currentAction != _currentAction) { Logging.Log("AnomalyController: Finished Action." + action); if (_currentAction < _pocketActions.Count) { action = _pocketActions[_currentAction]; Logging.Log("AnomalyController: Starting Action." + action); } } if (Settings.Instance.DebugStates) { Logging.Log("Action.State = " + action); } break; case AnomalyControllerState.NextPocket: var distance = Cache.Instance.DistanceFromMe(_lastX, _lastY, _lastZ); if (distance > (int)Distance.NextPocketDistance) { Logging.Log("AnomalyController: We've moved to the next Pocket [" + distance + "]"); // If we moved more then 100km, assume next Pocket _pocket++; State = AnomalyControllerState.LoadPocket; } else if (DateTime.Now.Subtract(_lastActivateAction).TotalMinutes > 2) { Logging.Log("AnomalyController: We've timed out, retry last action"); // We have reached a timeout, revert to ExecutePocketActions (e.g. most likely Activate) State = AnomalyControllerState.ExecutePocketActions; } break; } var newX = Cache.Instance.DirectEve.ActiveShip.Entity.X; var newY = Cache.Instance.DirectEve.ActiveShip.Entity.Y; var newZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z; // For some reason x/y/z returned 0 sometimes if (newX != 0 && newY != 0 && newZ != 0) { // Save X/Y/Z so that NextPocket can check if we actually went to the next Pocket :) _lastX = newX; _lastY = newY; _lastZ = newZ; } }
private void PerformAction(Action action) { switch (action.State) { case ActionState.Activate: ActivateAction(action); break; case ActionState.ClearPocket: ClearPocketAction(action); break; case ActionState.SalvageBookmark: BookmarkPocketForSalvaging(); _currentAction++; break; case ActionState.Done: // Tell the drones module to retract drones Cache.Instance.IsMissionPocketDone = true; // We do not switch to "done" status if we still have drones out if (Cache.Instance.ActiveDrones.Count() > 0) { return; } // Add bookmark (before we're done) if (Settings.Instance.CreateSalvageBookmarks) { BookmarkPocketForSalvaging(); } // Reload weapons ReloadAll(); State = AnomalyControllerState.Done; break; case ActionState.Kill: KillAction(action); break; case ActionState.MoveTo: MoveToAction(action); break; case ActionState.Loot: LootAction(action); break; case ActionState.LootItem: LootItemAction(action); break; case ActionState.Ignore: IgnoreAction(action); break; case ActionState.WaitUntilTargeted: WaitUntilTargeted(action); break; } }
private void ActivateAction(Action action) { var target = action.GetParameterValue("target"); // No parameter? Although we shouldnt really allow it, assume its the acceleration gate :) if (string.IsNullOrEmpty(target)) { target = "Acceleration Gate"; } var targets = Cache.Instance.EntitiesByName(target); if (targets == null || targets.Count() == 0) { Logging.Log("AnomalyController.Activate: Can't find [" + target + "] to activate! Stopping Questor!"); State = AnomalyControllerState.Error; return; } var closest = targets.OrderBy(t => t.Distance).First(); if (closest.Distance < (int)Distance.GateActivationRange) { // Tell the drones module to retract drones Cache.Instance.IsMissionPocketDone = true; // We cant activate if we have drones out if (Cache.Instance.ActiveDrones.Count() > 0) { return; } if (closest.Distance < (int)Distance.WayTooClose) { if ((DateTime.Now.Subtract(_lastOrbit).TotalSeconds > 15)) { closest.Orbit((int)Distance.GateActivationRange); Logging.Log("AnomolyController: Activate: initiating Orbit of [" + closest.Name + "] orbiting at [" + Cache.Instance.OrbitDistance + "]"); _lastOrbit = DateTime.Now; } } Logging.Log(" dist " + closest.Distance); if (closest.Distance >= (int)Distance.WayTooClose) { // Add bookmark (before we activate) if (Settings.Instance.CreateSalvageBookmarks) { BookmarkPocketForSalvaging(); } // Reload weapons and activate gate to move to the next pocket ReloadAll(); closest.Activate(); // Do not change actions, if NextPocket gets a timeout (>2 mins) then it reverts to the last action Logging.Log("AnomalyController.Activate: Activate [" + closest.Name + "] and change state to 'NextPocket'"); _lastActivateAction = DateTime.Now; State = AnomalyControllerState.NextPocket; } } else if (closest.Distance < (int)Distance.WarptoDistance) { // Move to the target if (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closest.Id) { Logging.Log("AnomalyController.Activate: Approaching target [" + closest.Name + "][" + closest.Id + "]"); closest.Approach(); } } else { // We cant warp if we have drones out if (Cache.Instance.ActiveDrones.Count() > 0) { return; } if (DateTime.Now.Subtract(_lastAlign).TotalMinutes > 2) { // Probably never happens closest.AlignTo(); _lastAlign = DateTime.Now; } } }