/// <summary> /// Leaves the game if gold inactivity timer is tripped /// </summary> internal bool GoldInactiveLeaveGame() { if (_leaveGameTimer.IsRunning && _leaveGameTimer.ElapsedMilliseconds < 12000) { return(true); } // Fixes a race condition crash. Zomg! Thread.Sleep(5000); if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid || ZetaDia.IsLoadingWorld) { _isLeavingGame = false; _leaveGameInitiated = false; Logger.Log(TrinityLogLevel.Info, LogCategory.GlobalHandler, "GoldInactiveLeaveGame called but not in game!"); return(false); } if (!BotMain.IsRunning) { return(false); } if (!_isLeavingGame && !_leaveGameInitiated) { // Exit the game and reload the profile PlayerMover.LastRestartedGame = DateTime.UtcNow; Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Gold Inactivity timer tripped - Anti-stuck measures exiting current game."); // Reload this profile ProfileManager.Load(ProfileManager.CurrentProfile.Path); Trinity.ResetEverythingNewGame(); _isLeavingGame = true; return(true); } if (!_leaveGameInitiated && _isLeavingGame) { _leaveGameTimer.Start(); ZetaDia.Service.Party.LeaveGame(true); Logger.Log(TrinityLogLevel.Info, LogCategory.GlobalHandler, "GoldInactiveLeaveGame initiated LeaveGame"); return(true); } if (DateTime.UtcNow.Subtract(PlayerMover.LastRestartedGame).TotalSeconds <= 12) { Logger.Log(TrinityLogLevel.Info, LogCategory.GlobalHandler, "GoldInactiveLeaveGame waiting for LeaveGame"); return(true); } _isLeavingGame = false; _leaveGameInitiated = false; Logger.Log(TrinityLogLevel.Info, LogCategory.GlobalHandler, "GoldInactiveLeaveGame finished"); return(false); }
// 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); }