private static void btnResetGrid_Click(object sender, RoutedEventArgs e) { try { if (BotMain.IsRunning) { BotMain.Stop(); } if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid) { return; } Thread.Sleep(500); GridSegmentation.Reset(); GridSegmentation.Update(); BrainBehavior.DungeonExplorer.Reset(); BrainBehavior.DungeonExplorer.GetBestRoute(); } catch (Exception ex) { Logger.Log("Could not reset grid: {0}", ex); } }
internal static void Reset(int boxSize = 30, float boxTolerance = 0.05f) { GridSegmentation.Reset(boxSize, boxTolerance); switch (RouteMode) { case RouteMode.SceneDirection: case RouteMode.SceneTSP: SceneSegmentation.Reset(); break; } Update(); }
void btnResetGrid_Click(object sender, RoutedEventArgs e) { if (BotMain.IsRunning) { BotMain.Stop(); } if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid) { return; } System.Threading.Thread.Sleep(500); GridSegmentation.Reset(); GridSegmentation.Update(); BrainBehavior.DungeonExplorer.Reset(); BrainBehavior.DungeonExplorer.GetBestRoute(); }
public MoveResult MoveTo(Vector3 destination, string destinationName = null, bool useRaycast = true, bool useNavigator = false) { if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid || ZetaDia.Me.IsDead || ZetaDia.IsLoadingWorld || !ZetaDia.Service.IsValid || !ZetaDia.WorldInfo.IsValid) { return(MoveResult.Failed); } try { return(Navigator.MoveTo(destination, destinationName, useRaycast)); } catch (Exception ex) { Logger.Log("{0}", ex); GridSegmentation.Reset(); return(MoveResult.Failed); } }
internal static MoveResult NavigateTo(Vector3 moveTarget, string destinationName = "") { using (new PerformanceLogger("NavigateTo")) { Vector3 MyPos = GilesTrinity.PlayerStatus.CurrentPosition; PositionCache.AddPosition(); float distanceToTarget = moveTarget.Distance2D(GilesTrinity.PlayerStatus.CurrentPosition); bool MoveTargetIsInLoS = distanceToTarget <= 90f && !Navigator.Raycast(MyPos, moveTarget); if (distanceToTarget <= 5f || MoveTargetIsInLoS) { if (distanceToTarget <= 5f) { DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Navigator, "Destination within 5f, using MoveTowards", true); } else { DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Navigator, "Destination within LoS, using MoveTowards", true); } Navigator.PlayerMover.MoveTowards(moveTarget); return(MoveResult.Moved); } try { return(Navigator.MoveTo(moveTarget, destinationName, true)); } catch (Exception ex) { Logging.Write("{0}", ex); GridSegmentation.Reset(); return(MoveResult.Failed); } } }
// Actually deal with a stuck - find an unstuck point etc. public static Vector3 UnstuckHandler(Vector3 vMyCurrentPosition, Vector3 vOriginalDestination) { if (Trinity.Settings.Advanced.DisableAllMovement) { return(Vector3.Zero); } // Update the last time we generated a path LastGeneratedStuckPosition = DateTime.UtcNow; Navigator.Clear(); // If we got stuck on a 2nd/3rd/4th "chained" anti-stuck route, then return the old move to target to keep movement of some kind going if (TimesReachedStuckPoint > 0) { vSafeMovementLocation = Vector3.Zero; // Reset the path and allow a whole "New" unstuck generation next cycle TimesReachedStuckPoint = 0; // And cancel unstucking for 9 seconds so DB can try to navigate CancelUnstuckerForSeconds = (9 * TotalAntiStuckAttempts); if (CancelUnstuckerForSeconds < 20) { CancelUnstuckerForSeconds = 20; } LastCancelledUnstucker = DateTime.UtcNow; Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Clearing old route and trying new path find to: " + LastMoveToTarget.ToString()); Navigator.MoveTo(LastMoveToTarget, "original destination", false); return(vSafeMovementLocation); } // Only try an unstuck 10 times maximum in XXX period of time if (Vector3.Distance(vOriginalDestination, vMyCurrentPosition) >= V.F("Unstucker.MaxDistance")) { Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "You are " + Vector3.Distance(vOriginalDestination, vMyCurrentPosition).ToString() + " distance away from your destination."); Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "This is too far for the unstucker, and is likely a sign of ending up in the wrong map zone."); TotalAntiStuckAttempts = 20; } if (TotalAntiStuckAttempts <= 10) { Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Your bot got stuck! Trying to unstuck (attempt #{0} of 10 attempts) {1} {2} {3} {4}", TotalAntiStuckAttempts.ToString(), "Act=\"" + ZetaDia.CurrentAct + "\"", "questId=\"" + ZetaDia.CurrentQuest.QuestSNO + "\"", "stepId=\"" + ZetaDia.CurrentQuest.StepId + "\"", "worldId=\"" + ZetaDia.CurrentWorldId + "\"" ); Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "(destination=" + vOriginalDestination.ToString() + ", which is " + Vector3.Distance(vOriginalDestination, vMyCurrentPosition).ToString() + " distance away)"); /* * Unstucker position */ //vSafeMovementLocation = NavHelper.FindSafeZone(true, TotalAntiStuckAttempts, vMyCurrentPosition); vSafeMovementLocation = NavHelper.SimpleUnstucker(); // Temporarily log stuff if (TotalAntiStuckAttempts == 1 && Trinity.Settings.Advanced.LogStuckLocation) { FileStream LogStream = File.Open(Path.Combine(FileManager.LoggingPath, "Stucks - " + Trinity.Player.ActorClass.ToString() + ".log"), FileMode.Append, FileAccess.Write, FileShare.Read); using (StreamWriter LogWriter = new StreamWriter(LogStream)) { LogWriter.WriteLine(DateTime.UtcNow.ToString() + ": Original Destination=" + LastMoveToTarget.ToString() + ". Current player position when stuck=" + vMyCurrentPosition.ToString()); LogWriter.WriteLine("Profile Name=" + ProfileManager.CurrentProfile.Name); } LogStream.Close(); } // Now count up our stuck attempt generations TotalAntiStuckAttempts++; return(vSafeMovementLocation); } TimesReachedMaxUnstucks++; TotalAntiStuckAttempts = 1; vSafeMovementLocation = Vector3.Zero; LastPosition = Vector3.Zero; TimesReachedStuckPoint = 0; TimeLastRecordedPosition = DateTime.MinValue; LastGeneratedStuckPosition = DateTime.MinValue; // int iSafetyLoops = 0; if (TimesReachedMaxUnstucks == 1) { Navigator.Clear(); GridSegmentation.Reset(); Logger.Log(TrinityLogLevel.Info, LogCategory.Movement, "Anti-stuck measures now attempting to kickstart DB's path-finder into action."); Navigator.MoveTo(vOriginalDestination, "original destination", false); CancelUnstuckerForSeconds = 40; LastCancelledUnstucker = DateTime.UtcNow; return(vSafeMovementLocation); } if (TimesReachedMaxUnstucks == 2) { Logger.Log(TrinityLogLevel.Info, LogCategory.Movement, "Anti-stuck measures failed. Now attempting to reload current profile."); Navigator.Clear(); ProfileManager.Load(Zeta.Bot.ProfileManager.CurrentProfile.Path); Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Anti-stuck successfully reloaded current profile, DemonBuddy now navigating again."); return(vSafeMovementLocation); // Didn't make it to town, so skip instantly to the exit game system //iTimesReachedMaxUnstucks = 3; } // Exit the game and reload the profile if (Trinity.Settings.Advanced.AllowRestartGame && DateTime.UtcNow.Subtract(LastRestartedGame).TotalMinutes >= 5) { LastRestartedGame = DateTime.UtcNow; string sUseProfile = Trinity.FirstProfile; Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Anti-stuck measures exiting current game."); // Load the first profile seen last run ProfileManager.Load(!string.IsNullOrEmpty(sUseProfile) ? sUseProfile : Zeta.Bot.ProfileManager.CurrentProfile.Path); Thread.Sleep(1000); Trinity.ResetEverythingNewGame(); ZetaDia.Service.Party.LeaveGame(true); // Wait for 10 second log out timer if not in town if (!ZetaDia.IsInTown) { Thread.Sleep(15000); } } else { Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Unstucking measures failed. Now stopping Trinity unstucker for 12 minutes to inactivity timers to kick in or DB to auto-fix."); CancelUnstuckerForSeconds = 720; LastCancelledUnstucker = DateTime.UtcNow; return(vSafeMovementLocation); } return(vSafeMovementLocation); }