private static double GetSquareDistance(WowPoint p1, WowPoint p2) { double dx = p1.X - p2.X, dy = p1.Y - p2.Y; return((dx * dx) + (dy * dy)); }
public RouteInfoPoi(WowPoint wowPoint, string name, string color, double radius) { Location = wowPoint; Name = name; Color = color; Radius = radius; }
// square distance from a WowPoint to a segment private static double GetSquareSegmentDistance(WowPoint p, WowPoint p1, WowPoint p2) { var x = p1.X; var y = p1.Y; var dx = p2.X - x; var dy = p2.Y - y; if (!dx.Equals(0.0) || !dy.Equals(0.0)) { var t = ((p.X - x) * dx + (p.Y - y) * dy) / (dx * dx + dy * dy); if (t > 1) { x = p2.X; y = p2.Y; } else if (t > 0) { x += dx * t; y += dy * t; } } dx = p.X - x; dy = p.Y - y; return((dx * dx) + (dy * dy)); }
private bool AdjustNextPointToClosest() { if (wayPoints.Count < 2) { return(false); } var A = wayPoints.Pop(); var B = wayPoints.Peek(); var result = GetClosestPointOnLineSegment(A.Vector2(), B.Vector2(), new Vector2((float)this.playerReader.XCoord, (float)this.playerReader.YCoord)); var newPoint = new WowPoint(result.X, result.Y); if (WowPoint.DistanceTo(newPoint, wayPoints.Peek()) >= 4) { wayPoints.Push(newPoint); logger.LogInformation($"Adjusted resume point"); return(false); } else { logger.LogInformation($"Skipped next point in path"); // skiped next point return(true); } }
private async Task RefillRouteToNextWaypoint(bool forceUsePathing) { if (wayPoints.Count == 0) { RefillWaypoints(); } this.routeToWaypoint.Clear(); var location = new WowPoint(playerReader.XCoord, playerReader.YCoord); var heading = DirectionCalculator.CalculateHeading(location, wayPoints.Peek()); await playerDirection.SetDirection(heading, wayPoints.Peek(), "Reached waypoint").ConfigureAwait(false); //Create path back to route var distance = WowPoint.DistanceTo(location, wayPoints.Peek()); if (forceUsePathing || distance > 200) { await this.stopMoving.Stop(); var path = await this.pather.FindRouteTo(this.playerReader, wayPoints.Peek()); path.Reverse(); path.ForEach(p => this.routeToWaypoint.Push(p)); } this.ReduceRoute(); if (this.routeToWaypoint.Count == 0) { this.routeToWaypoint.Push(this.wayPoints.Peek()); } this.stuckDetector.SetTargetLocation(this.routeToWaypoint.Peek()); }
private void RefillWaypoints(bool findClosest = false) { if (firstLoad) { // start path at closest point firstLoad = false; var closestPoint = pointsList.OrderBy(p => WowPoint.DistanceTo(playerReader.PlayerLocation, p)).FirstOrDefault(); for (int i = 0; i < pointsList.Count; i++) { wayPoints.Push(pointsList[i]); if (pointsList[i] == closestPoint) { break; } } } else { if (findClosest) { pointsList.ForEach(p => wayPoints.Push(p)); AdjustNextPointToClosest(); } else { pointsList.ForEach(p => wayPoints.Push(p)); } } }
public async Task <List <WowPoint> > FindRoute(int map, WowPoint fromPoint, WowPoint toPoint) { if (!Enabled) { logger.LogWarning($"Pathing is disabled, please check the messages when the bot started."); return(new List <WowPoint>()); } await Task.Delay(0); var sw = new Stopwatch(); sw.Start(); service.SetLocations(service.GetWorldLocation(map, (float)fromPoint.X, (float)fromPoint.Y), service.GetWorldLocation(map, (float)toPoint.X, (float)toPoint.Y)); var path = service.DoSearch(PatherPath.Graph.PathGraph.eSearchScoreSpot.A_Star_With_Model_Avoidance); if (path == null) { logger.LogWarning($"LocalPathingApi: Failed to find a path from {fromPoint} to {toPoint}"); return(new List <WowPoint>()); } else { logger.LogInformation($"Finding route from {fromPoint} map {map} to {toPoint} took {sw.ElapsedMilliseconds} ms."); } var worldLocations = path.locations.Select(s => service.ToMapAreaSpot(s.X, s.Y, s.Z, map)); var result = worldLocations.Select(l => new WowPoint(l.X, l.Y)).ToList(); return(result); }
private void UnstuckIfNeeded(WowPoint playerLoc, DoActionType currentAction) { if (currentAction == DoActionType.Move) { unstuckDictionary.Add(DateTime.UtcNow, playerLoc); if (unstuckDictionary.Count >= 2) { if (unstuckDictionary.Count > 100) // sufficiently big value (until this method is called once per second) { unstuckDictionary.Remove(unstuckDictionary.Keys.First()); } KeyValuePair <DateTime, WowPoint> last = unstuckDictionary.Last(); KeyValuePair <DateTime, WowPoint> first = unstuckDictionary.LastOrDefault(l => (last.Key - l.Key).TotalSeconds >= 5); if (!first.Equals(default(KeyValuePair <DateTime, WowPoint>))) { if (last.Value.Distance(first.Value) < 1f) { this.LogPrint($"We are stuck at {playerLoc}. Trying to unstuck..."); game.Jump(); } } } } else { unstuckDictionary.Clear(); } }
private static List <WowPoint> FillPathToCorpse(WowPoint closestRoutePointToCorpse, WowPoint pathStartPoint, List <WowPoint> routePoints) { var pathToCorpse = new List <WowPoint>(); var startPathPointIndex = 0; var endPathPointIndex = 0; for (int i = 0; i < routePoints.Count; i++) { if (routePoints[i] == pathStartPoint) { startPathPointIndex = i; } if (routePoints[i] == closestRoutePointToCorpse) { endPathPointIndex = i; } } if (startPathPointIndex < endPathPointIndex) { for (int i = startPathPointIndex; i <= endPathPointIndex; i++) { pathToCorpse.Add(routePoints[i]); } } return(pathToCorpse); }
private void GetSpecialBaitBuffFromNatPagle() { this.LogPrint("Searching for Nat Pagle, id:85984"); var npcs = new List <WowNpc>(); game.GetGameObjects(null, null, npcs); var natPagle = npcs.FirstOrDefault(npc => npc.EntryID == 85984); if (natPagle != null) { this.LogPrint($"Nat Pagle is found, guid: {natPagle.GUID}, moving to him..."); game.Move2D(natPagle.Location, 4f, 2000, false, false); Thread.Sleep(500); this.LogPrint("Opening dialog window with Nat..."); natPagle.Interact(); Thread.Sleep(2000); game.SelectDialogOption("Обычная приманка для рыбы?"); // todo: is it possible to localize it? Thread.Sleep(1500); var gossipText = Wowhead.GetItemInfo(SPECIAL_BAITS.First(baitFish => Wowhead.GetItemInfo(baitFish.Key).Name == settings.SpecialBait).Value).Name; game.SelectDialogOption(gossipText); Thread.Sleep(1500); var goodFishingPoint = new WowPoint(2024.49f, 191.33f, 83.86f); this.LogPrint($"Moving to fishing point [{goodFishingPoint}]"); game.Move2D(goodFishingPoint, 2f, 2000, false, false); var water = new WowPoint((float)(Utilities.Rnd.NextDouble() * 5 + 2032.5f), (float)(Utilities.Rnd.NextDouble() * 5 + 208.5f), 82f); this.LogPrint($"Facing water [{water}]"); game.Face(water); } }
public void Go(WowPoint dest, float precision, GameInterface game) { if (isRunning) { throw new InvalidOperationException("Script is already running"); } else { //unstuckDictionary = new Dictionary<DateTime, WowPoint>(); this.game = game; isRunning = true; precision2D = precision; precision3D = precision * 3; loopPath = false; startFromNearestPoint = false; counter = 0; actionsList = new List <DoAction> { new DoAction() { ActionType = DoActionType.Move, WowPoint = dest } }; this.LogPrint($"Go(): destination: {dest}; precision2D: {precision2D}; precision3D: {precision3D}"); DoAction(); isRunning = false; } }
public override void OnActionEvent(object sender, ActionEventArgs e) { NeedsToReset = true; points.Clear(); this.corpseLocation = new WowPoint(0, 0); LastEventReceived = DateTime.Now; }
public override async Task PerformAction() { var targetLocation = this.classConfiguration.WrongZone.ExitZoneLocation; SendActionEvent(new ActionEventArgs(GoapKey.fighting, false)); await Task.Delay(200); input.SetKeyState(ConsoleKey.UpArrow, true, false, "FollowRouteAction 5"); if (this.playerReader.Bits.PlayerInCombat) { return; } if ((DateTime.Now - LastActive).TotalSeconds > 10) { this.stuckDetector.SetTargetLocation(targetLocation); } var location = new WowPoint(playerReader.XCoord, playerReader.YCoord); var distance = WowPoint.DistanceTo(location, targetLocation); var heading = DirectionCalculator.CalculateHeading(location, targetLocation); if (lastDistance < distance) { await playerDirection.SetDirection(heading, targetLocation, "Further away"); } else if (!this.stuckDetector.IsGettingCloser()) { // stuck so jump input.SetKeyState(ConsoleKey.UpArrow, true, false, "FollowRouteAction 6"); await Task.Delay(100); if (HasBeenActiveRecently()) { await this.stuckDetector.Unstick(); } else { await Task.Delay(1000); logger.LogInformation("Resuming movement"); } } else // distance closer { var diff1 = Math.Abs(RADIAN + heading - playerReader.Direction) % RADIAN; var diff2 = Math.Abs(heading - playerReader.Direction - RADIAN) % RADIAN; if (Math.Min(diff1, diff2) > 0.3) { await playerDirection.SetDirection(heading, targetLocation, "Correcting direction"); } } lastDistance = distance; LastActive = DateTime.Now; }
public async Task <List <WowPoint> > FindRoute(int map, WowPoint fromPoint, WowPoint toPoint) { if (targetMapId == 0) { targetMapId = map; } try { logger.LogInformation($"Finding route from {fromPoint} map {map} to {toPoint} map {targetMapId}..."); var url = $"{api}MapRoute?map1={map}&x1={fromPoint.X}&y1={fromPoint.Y}&map2={targetMapId}&x2={toPoint.X}&y2={toPoint.Y}"; var sw = new Stopwatch(); sw.Start(); using (var handler = new HttpClientHandler()) { using (var client = new HttpClient(handler)) { var responseString = await client.GetStringAsync(url); logger.LogInformation($"Finding route from {fromPoint} map {map} to {toPoint} took {sw.ElapsedMilliseconds} ms."); var path = JsonConvert.DeserializeObject <IEnumerable <WorldMapAreaSpot> >(responseString); var result = path.Select(l => new WowPoint(l.X, l.Y)).ToList(); return(result); } } } catch (Exception ex) { logger.LogError(ex, $"Finding route from {fromPoint} to {toPoint}"); Console.WriteLine(ex); return(new List <WowPoint>()); } }
public async Task <Tuple <bool, bool> > FoundTargetWhileMoved() { bool hadToMove = false; var startedMoving = await wait.InterruptTask(200, () => lastPosition != playerReader.PlayerLocation); if (!startedMoving.Item1) { Log($" Goto corpse({startedMoving.Item2}ms) - Wait till player become stil!"); hadToMove = true; } while (IsPlayerMoving(lastPosition)) { lastPosition = playerReader.PlayerLocation; if (!await Wait(100, EnteredCombat())) { if (await AquiredTarget()) { return(Tuple.Create(true, hadToMove)); } } } return(Tuple.Create(false, hadToMove)); }
public async Task SetDirection(double desiredDirection, WowPoint point, string source, int ignoreDistance) { var location = new WowPoint(playerReader.XCoord, playerReader.YCoord); var distance = WowPoint.DistanceTo(location, point); if (!string.IsNullOrEmpty(source)) { Log($"SetDirection:- {source} Desired: {desiredDirection.ToString("0.000")}, Current: {playerReader.Direction.ToString("0.000")}, distance: {distance.ToString("0.000")}"); } if (distance < ignoreDistance) { Log("Too close, ignoring direction change."); return; } var key = GetDirectionKeyToPress(desiredDirection); TurnUsingTimedPress(desiredDirection, key); //await TurnAndReadActualDirection(desiredDirection, key); await Task.Delay(1); LastSetDirection = DateTime.Now; }
public async Task <List <WowPoint> > FindRoute(int uiMapId, WowPoint fromPoint, WowPoint toPoint) { await Task.Delay(0); throw new NotImplementedException(); //return new List<WowPoint>(); }
internal static float AngleHorizontal(WowProcess process, WowPoint point) { WoWPlayerMe me = ObjectMgr.Pulse(process); var angle = Convert.ToSingle(Math.Atan2(Convert.ToDouble(point.Y) - Convert.ToDouble(me.Location.Y), Convert.ToDouble(point.X) - Convert.ToDouble(me.Location.X))); angle = NegativeAngle(angle); return(angle); }
public static double CalculateHeading(WowPoint from, WowPoint to) { //logger.LogInformation($"from: ({from.X},{from.Y}) to: ({to.X},{to.Y})"); var target = Math.Atan2(to.X - from.X, to.Y - from.Y); return(Math.PI + target); }
public CombatUtil(ILogger logger, ConfigurableInput input, Wait wait, PlayerReader playerReader) { this.logger = logger; this.input = input; this.wait = wait; this.playerReader = playerReader; outOfCombat = !playerReader.Bits.PlayerInCombat; lastPosition = playerReader.PlayerLocation; }
public void GoWait(WowPoint dest, float precision, GameInterface game, int timeoutMs = 30000) { Stopwatch stopwatch = new Stopwatch(); WoWPlayerMe me = game.GetGameObjects(); while (me != null && me.Location.Distance(dest) > precision && timeoutMs > 0) { stopwatch.Restart(); Go(dest, precision, game); timeoutMs -= (int)stopwatch.ElapsedMilliseconds; } }
private async Task BlinkIfMage() { var location = new WowPoint(playerReader.XCoord, playerReader.YCoord); var distance = WowPoint.DistanceTo(location, routeToWaypoint.Peek()); if (this.classConfiguration.Blink.ConsoleKey != 0 && this.playerReader.ManaPercentage > 90 && this.playerReader.PlayerLevel < 40 && distance > 200 ) { await wowProcess.KeyPress(this.classConfiguration.Blink.ConsoleKey, 120, this.classConfiguration.Blink.Name); } }
private static double DistanceTo(WowPoint l1, WowPoint l2) { var x = l1.X - l2.X; var y = l1.Y - l2.Y; x = x * 100; y = y * 100; var distance = Math.Sqrt((x * x) + (y * y)); //logger.LogInformation($"distance:{x} {y} {distance.ToString()}"); return(distance); }
public Vector3 GetWorldLocation(int uiMapId, WowPoint p, bool flipXY) { var worldMapArea = areas[uiMapId]; if (flipXY) { return(new Vector3(worldMapArea.ToWorldX((float)p.Y), worldMapArea.ToWorldY((float)p.X), (float)p.Z)); } else { var worldX = worldMapArea.ToWorldX((float)p.X); var worldY = worldMapArea.ToWorldY((float)p.Y); return(new Vector3(worldX, worldY, (float)p.Z)); } }
public void OnPulse() { WoWPlayerMe locaPlayer = game.GetGameObjects(null, players, npcs); if (locaPlayer.Alive) { WowPlayer unitPlayer = players.FirstOrDefault(i => i.Alive && i.GUID == guid); WowNpc unitNpc = npcs.FirstOrDefault(i => i.Alive && i.GUID == guid); WowPoint? POILocation = unitPlayer != null ? unitPlayer.Location : unitNpc?.Location; if (POILocation.HasValue && POILocation.Value.Distance(locaPlayer.Location) > SettingsInstance.MaxDistance) { // game.Move2D(WowPoint.GetNearestPoint(locaPlayer.Location, POILocation.Value, 1f), SettingsInstance.Precision, 1000, true, false); libNavigator.Go(WowPoint.GetNearestPoint(locaPlayer.Location, POILocation.Value, 1f), (float)SettingsInstance.Precision, game); } } }
private void ReduceRoute() { if (routeToWaypoint.Any()) { var location = new WowPoint(playerReader.XCoord, playerReader.YCoord); var distance = WowPoint.DistanceTo(location, routeToWaypoint.Peek()); while (distance < PointReachedDistance() && routeToWaypoint.Any()) { routeToWaypoint.Pop(); if (routeToWaypoint.Any()) { distance = WowPoint.DistanceTo(location, routeToWaypoint.Peek()); } } } }
protected override async Task InteractWithTarget() { WowPoint location = this.playerReader.PlayerLocation; var bagItems = this.bagReader.BagItems.Count; for (int i = 0; i < 5; i++) { // press interact key await this.wowProcess.KeyPress(this.classConfiguration.VendorTarget.ConsoleKey, 200); if (!string.IsNullOrEmpty(this.playerReader.Target)) { await this.wowProcess.KeyPress(this.classConfiguration.Interact.ConsoleKey, 200); } else { logger.LogError($"Error: No target has been selected. Key {this.classConfiguration.VendorTarget.ConsoleKey} should be /tar an NPC."); break; } System.Threading.Thread.Sleep(3000); } if (location.X == this.playerReader.PlayerLocation.X && location.X == this.playerReader.PlayerLocation.Y && bagItems <= this.bagReader.BagItems.Count) { // we didn't move. logger.LogError("Error: We didn't move!. Failed to interact with vendor. Try again in 10 seconds."); failedVendorAttempts++; await Task.Delay(10000); } else if (bagItems <= this.bagReader.BagItems.Count) { // we didn't move. logger.LogError("Error: We didn't sell anything.. Try again in 10 seconds."); failedVendorAttempts++; await Task.Delay(10000); } if (failedVendorAttempts == 5) { logger.LogError("Too many failed vendor attempts. Bot stopped."); this.SendActionEvent(new ActionEventArgs(GoapKey.abort, true)); } }
internal bool IsMoving() { var currentDistanceToTarget = WowPoint.DistanceTo(this.playerReader.PlayerLocation, targetLocation); if (Math.Abs(currentDistanceToTarget - previousDistanceToTarget) > 1) { ResetStuckParameters(); previousDistanceToTarget = currentDistanceToTarget; return(true); } if ((DateTime.Now - timeOfLastSignificantMovement).TotalSeconds > 3) { logger.LogInformation("We seem to be stuck!"); return(false); } return(true); }
private async Task MoveCloserToTarget(int pressDuration) { var distance = WowPoint.DistanceTo(playerReader.PlayerLocation, this.GetTargetLocation()); var lastDistance = distance; while (distance <= lastDistance && distance > 5) { logger.LogInformation($"Distance to vendor spot = {distance}"); lastDistance = distance; var heading = DirectionCalculator.CalculateHeading(playerReader.PlayerLocation, this.GetTargetLocation()); await playerDirection.SetDirection(heading, this.GetTargetLocation(), "Correcting direction", 0); await this.wowProcess.KeyPress(ConsoleKey.UpArrow, pressDuration); await this.stopMoving.Stop(); distance = WowPoint.DistanceTo(playerReader.PlayerLocation, this.GetTargetLocation()); } }
public async Task PressKey(ConsoleKey key, string description = "", int duration = 300) { if (lastKeyPressed == classConfiguration.Interact.ConsoleKey) { var distance = WowPoint.DistanceTo(classConfiguration.Interact.LastClickPostion, this.playerReader.PlayerLocation); if (distance > 1) { logger.LogInformation($"Stop moving: We have moved since the last interact: {distance}"); await wowProcess.TapStopKey(); classConfiguration.Interact.SetClicked(); await Task.Delay(300); } } await wowProcess.KeyPress(key, duration, description); lastKeyPressed = key; }