コード例 #1
0
ファイル: Plugin.cs プロジェクト: herbfunk/Funky
        public void OnInitialize()
        {
            Logger.DBLog.DebugFormat("fBaseXtensions OnInitialize Started");

            if (File.Exists(FolderPaths.PluginPath + @"\CombatRoutine.cs"))
            {
                try
                {
                    if (File.Exists(FolderPaths.RoutinePath + @"\CombatRoutine.cs"))
                    {
                        File.Delete(FolderPaths.RoutinePath + @"\CombatRoutine.cs");
                    }

                    File.Copy(FolderPaths.PluginPath + @"\CombatRoutine.cs", FolderPaths.RoutinePath + @"\CombatRoutine.cs");
                    Logger.DBLog.DebugFormat("fBaseXtensions Copied Combat Routine");
                }
                catch (Exception ex)
                {
                    Logger.DBLog.DebugFormat("fBaseXtensions Copy Combat Routine Threw Exception", ex);
                }
            }

            Settings = new PluginSettings();
            PluginSettings.LoadSettings();
            TheCache.ObjectIDCache = new IDCache();
            CharacterControl.OrginalGameDifficultySetting = CharacterSettings.Instance.GameDifficulty;
            BotMain.OnStart += EventHandling.OnBotStart;
            BotMain.OnStop  += EventHandling.OnBotStop;
            CustomConditions.Initialize();
            ObjectCache.FakeCacheObject = new CacheObject(Vector3.Zero, TargetType.None, 0d, "Fake Target", 1f);
            CharacterSettings.Instance.PropertyChanged += CharacterControl.OnDBCharacterSettingPropertyChanged;
            Logger.Write("Init Logger Completed!");
            Logger.DBLog.DebugFormat("fBaseXtensions OnInitialize Finished");
        }
コード例 #2
0
        private static void OnGameJoined(object obj, EventArgs args)
        {
            Logger.Write(LogLevel.Event, "OnJoinGame Event");

            CharacterSettings.Instance.GameDifficulty = CharacterControl.OrginalGameDifficultySetting;
            CharacterControl.GameDifficultyChanged    = false;

            CheckGameIDChange();
        }
コード例 #3
0
        private static void OnGameChanged(object obj, EventArgs args)
        {
            Logger.Write(LogLevel.Event, "OnGameChanged Event");

            if (FunkyBaseExtension.PluginIsEnabled)
            {
                FunkyGame.ResetBot();
            }

            CheckGameIDChange();

            string currentProfilePath = ProfileManager.CurrentProfile.Path;

            ProfileManager.Load(currentProfilePath);
            Navigator.SearchGridProvider.Update();
        }
コード例 #4
0
        private static void OnProfileChanged(object obj, EventArgs args)
        {
            Logger.Write(LogLevel.Event, "OnProfileChanged Event");
            string sThisProfile = ProfileManager.CurrentProfile.Path;

            if (FunkyGame.CurrentStats != null && !CharacterControl.AltHeroGamblingEnabled)
            {
                FunkyGame.CurrentStats.ProfileChanged(sThisProfile);
                Stats.Stats.WriteProfileTrackerOutput(ref FunkyGame.CurrentStats);
            }
            FunkyGame.Game.ObjectCustomWeights.Clear();
            SettingCluster.ClusterSettingsTag             = FunkyBaseExtension.Settings.Cluster;
            FunkyGame.Game.QuestMode                      = false;
            SettingLOSMovement.LOSSettingsTag             = FunkyBaseExtension.Settings.LOSMovement;
            MonitorSettings.MonitorSettingsTag            = FunkyBaseExtension.Settings.Monitoring;
            SettingAdventureMode.AdventureModeSettingsTag = FunkyBaseExtension.Settings.AdventureMode;
        }
コード例 #5
0
        private static void OnGameLeft(object obj, EventArgs args)
        {
            Logger.Write(LogLevel.Event, "OnLeaveGame Event");

            if (FunkyGame.CurrentStats != null)
            {
                FunkyGame.CurrentStats.CurrentProfile.UpdateRangeVariables();
            }

            FunkyGame.CurrentGameID = new GameId();
            FunkyGame.AdventureMode = false;
            //FunkyGame.ShouldRefreshAccountDetails = true;

            if (FunkyBaseExtension.PluginIsEnabled)
            {
                FunkyGame.ResetGame();
            }
        }
コード例 #6
0
        public static RunStatus BeginNewGameProfile()
        {
            if (DateTime.Now.Subtract(LastActionTaken).TotalMilliseconds > RandomWaitTimeMilliseconds)
            {
                string NewGameProfile = FolderPaths.PluginPath + @"Behaviors\CharacterMule\NewGame.xml";
                if (ProfileManager.CurrentProfile.Path != NewGameProfile)
                {
                    if (File.Exists(NewGameProfile))
                    {
                        Logger.Write(LogLevel.OutOfGame, "Loading NewGame profile");
                        ProfileManager.Load(NewGameProfile);
                        CharacterSettings.Instance.MonsterPowerLevel = 0;
                    }
                }
                else
                {
                    return(RunStatus.Success);
                }

                LastActionTaken = DateTime.Now;
            }
            return(RunStatus.Running);
        }
コード例 #7
0
 private static void OnPlayerDeath(object obj, EventArgs args)
 {
     Logger.Write(LogLevel.Event, "OnPlayerDied Event");
     FunkyGame.ResetBot();
 }
コード例 #8
0
        // **********************************************************************************************
        // *****                Actually deal with a stuck - find an unstuck point etc.             *****
        // **********************************************************************************************
        public static Vector3 UnstuckHandler(Vector3 vMyCurrentPosition, Vector3 vOriginalDestination)
        {
            // Update the last time we generated a path
            timeStartedUnstuckMeasure = DateTime.Now;



            // 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 (iTimesReachedStuckPoint > 0)
            {
                vSafeMovementLocation = Vector3.Zero;
                iTimesReachedStuckPoint++;
                // Reset the path and allow a whole "New" unstuck generation next cycle
                iTimesReachedStuckPoint = 0;
                // And cancel unstucking for 9 seconds so DB can try to navigate
                iCancelUnstuckerForSeconds = (9 * iTotalAntiStuckAttempts);
                if (iCancelUnstuckerForSeconds < 20)
                {
                    iCancelUnstuckerForSeconds = 20;
                }
                timeCancelledUnstuckerFor = DateTime.Now;
                Navigator.Clear();
                Logger.DBLog.DebugFormat("[Funky] Clearing old route and trying new path find to: " + vOldMoveToTarget.ToString());
                Navigator.MoveTo(vOldMoveToTarget, "original destination", false);
                return(vSafeMovementLocation);
            }

            // Only try an unstuck 10 times maximum in XXX period of time
            if (Vector3.Distance(vOriginalDestination, vMyCurrentPosition) >= 700f)
            {
                Logger.DBLog.InfoFormat("[Funky] You are " + Vector3.Distance(vOriginalDestination, vMyCurrentPosition).ToString(CultureInfo.InvariantCulture) + " distance away from your destination.");
                Logger.DBLog.InfoFormat("[Funky] This is too far for the unstucker, and is likely a sign of ending up in the wrong map zone.");
                Logger.DBLog.InfoFormat("Reloading current profile");
                ProfileManager.Load(ProfileManager.CurrentProfile.Path);
            }
            if (iTotalAntiStuckAttempts <= 8)
            {
                //Check cache for barricades..
                if (ObjectCache.Objects.OfType <CacheDestructable>().Any(CO => CO.RadiusDistance <= 12f))
                {
                    Logger.DBLog.InfoFormat("[Funky] Found nearby barricade, flagging barricade destruction!");
                    ShouldHandleObstacleObject = true;
                }

                Logger.DBLog.InfoFormat("[Funky] Your bot got stuck! Trying to unstuck (attempt #" + iTotalAntiStuckAttempts.ToString(CultureInfo.InvariantCulture) + " of 8 attempts)");
                Logger.DBLog.DebugFormat("(destination=" + vOriginalDestination.ToString() + ", which is " + Vector3.Distance(vOriginalDestination, vMyCurrentPosition).ToString(CultureInfo.InvariantCulture) + " distance away)");

                Logger.Write(LogLevel.Movement, "Stuck Flags: {0}", FunkyGame.Hero.Stuckflags.ToString());

                bool FoundRandomMovementLocation = FunkyGame.Navigation.AttemptFindSafeSpot(out vSafeMovementLocation, Vector3.Zero, PointCheckingFlags.RaycastWalkable);

                // Temporarily log stuff
                if (iTotalAntiStuckAttempts == 1 && FunkyBaseExtension.Settings.Debugging.LogStuckLocations)
                {
                    string outputPath = FolderPaths.LoggingFolderPath + @"\Stucks.log";

                    FileStream LogStream = File.Open(outputPath, FileMode.Append, FileAccess.Write, FileShare.Read);
                    using (StreamWriter LogWriter = new StreamWriter(LogStream))
                    {
                        LogWriter.WriteLine(DateTime.Now.ToString(CultureInfo.InvariantCulture) + ": Original Destination=" + vOldMoveToTarget.ToString() + ". Current player position when stuck=" + vMyCurrentPosition.ToString());
                        LogWriter.WriteLine("Profile Name=" + ProfileManager.CurrentProfile.Name);
                    }
                }

                if (iTotalAntiStuckAttempts == 2)
                {
                    //Navigator.Clear();
                    Logger.DBLog.InfoFormat("Using Navigator StuckHandler To Generate Vector3");
                    vSafeMovementLocation       = Navigator.StuckHandler.GetUnstuckPos();
                    FoundRandomMovementLocation = true;
                }

                // Now count up our stuck attempt generations
                iTotalAntiStuckAttempts++;

                if (FoundRandomMovementLocation)
                {
                    return(vSafeMovementLocation);
                }
                Navigator.Clear();
                Navigator.MoveTo(vOriginalDestination, "original destination", false);
                iCancelUnstuckerForSeconds = 40;
                timeCancelledUnstuckerFor  = DateTime.Now;
                return(Vector3.Zero);
            }

            iTimesReachedMaxUnstucks++;
            iTotalAntiStuckAttempts   = 1;
            vSafeMovementLocation     = Vector3.Zero;
            vOldPosition              = Vector3.Zero;
            iTimesReachedStuckPoint   = 0;
            timeLastRecordedPosition  = DateTime.Today;
            timeStartedUnstuckMeasure = DateTime.Today;
            int iSafetyLoops = 0;

            if (iTimesReachedMaxUnstucks == 1)
            {
                Navigator.Clear();

                Logger.DBLog.InfoFormat("[Funky] Anti-stuck measures now attempting to kickstart DB's path-finder into action.");
                if (Vector3.Distance(vOriginalDestination, vMyCurrentPosition) >= 200f)
                {
                    iTimesReachedMaxUnstucks++;
                }
                else
                {
                    Navigator.MoveTo(vOriginalDestination, "original destination", false);
                    iCancelUnstuckerForSeconds = 40;
                    timeCancelledUnstuckerFor  = DateTime.Now;
                    return(vSafeMovementLocation);
                }
            }

            if (iTimesReachedMaxUnstucks == 2)
            {
                Logger.DBLog.InfoFormat("[Funky] Anti-stuck measures failed. Now attempting to reload current profile.");
                ExitGameBehavior.ShouldExitGame = true;
            }
            // Exit the game and reload the profile
            if (FunkyBaseExtension.Settings.Debugging.RestartGameOnLongStucks && DateTime.Now.Subtract(timeLastRestartedGame).TotalMinutes >= 15)
            {
                timeLastRestartedGame           = DateTime.Now;
                ExitGameBehavior.ShouldExitGame = true;
            }
            else
            {
                Logger.DBLog.InfoFormat("[Funky] Unstucking measures failed. Now stopping Trinity unstucker for 12 minutes to inactivity timers to kick in or DB to auto-fix.");
                iCancelUnstuckerForSeconds = 720;
                timeCancelledUnstuckerFor  = DateTime.Now;
                return(vSafeMovementLocation);
            }
            return(vSafeMovementLocation);
        }