• Visit Rebornbuddy
  • Disposing Current Combat Routine Behaviors/Hooks

    Discussion in 'Community Developer Forum' started by newb23, Oct 24, 2016.

    1. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Good evening,

      I am attempting to write a plugin that subscribes to RoutineManager.PickRoutineFired in order to build a combat routine switcher, based on use pre-chosen options per class.

      While the selection and switching process works, I am having trouble getting it to properly dispose the previous routine, and load the new one. Specifically, the combat behaviors.

      If I am to call the following within the RoutinePickFired Method, it does technically work, but is very clunky and very dirty, and straight does not work from time to time. (Too slow to re-start on the child task - thus failing to restart the botbase)

      Code:
                  if (BotManager.Current.EnglishName != "Order Bot" && BotManager.Current.Name != "Lisbeth" && BotManager.Current.Name != "ExFateBot")                
                       Task.Factory.StartNew(async () =>
                      {
                          Task.Run(async () =>
                          {
                              await TreeRoot.StopGently(" " + "Preparing to switch Combat Routine.");
                              BotManager.SetCurrent(BotManager.Bots.FirstOrDefault(r => r.Name == botBaseName));
                              Logger.SwitcharooLog("Starting Botbase!");
                              TreeRoot.Start();
                          });
                      });

      However, Trying to clear hooks, replace them with ActionAlwaysFails, or anything short of stopping, and starting the botbase itself leads to the same issue: The previous combat routine behaviors being loaded and used.

      Example:
      Code:
                      
                      RoutineManager.Current.ShutDown();                
                      RoutineManager.Current.Dispose();
                      TreeHooks.Instance.ClearHook("PreCombatBuff");
                      TreeHooks.Instance.ClearHook("Heal");
                      TreeHooks.Instance.ClearHook("Pull");
                      TreeHooks.Instance.ClearHook("CombatBuff");
                      TreeHooks.Instance.ClearHook("Combat");
                      TreeHooks.Instance.ClearHook("Combat");
                      TreeHooks.Instance.ClearHook("Rest");
      
      (OR Treehooks.Instance.ClearAll(); in place of all of the above clears)
      
      
                      RoutineManager.PreferedRoutine = Utilities.RoutineManager.GetRoutine();
                      RoutineManager.Current.Initialize();
                      Logger.SwitcharooLog("New Routine Chosen, restarting");
      So, my question is this: What is the proper way to dispose of the combat routine being switched from, and replace it with the one being switched to?

      Thank you!
       
    2. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83
      1) Don't use taskfactory etc, our coroutines are not meant to interact with them in that way
      2) Don't stop the bot to change it
      3) It's not your job to dispose of the routines.

      The only thing your supposed todo in pickroutinefired is set routinemanager.PreferedRoutine
       
    3. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      I have edited the Plugin to do only the following:

      Code:
              
      public static async Task ChangeRoutine(string botBaseName)        
              {
                  RoutineManager.PreferedRoutine = Utilities.RoutineManager.GetRoutine();
                  Logger.SwitcharooLog("New Routine Chosen, restarting");
              }
      I used only Ultima and Kupo for this series of testing in addition to Combat Assist as supplied with the bot in a mostly clean environment, and it appears that there is still something not switching quite right. In the case of Kupo, I do not know the rotations to be honest, but I would think for at least BLM it would be doing more than what you see in the forthcoming log, and for Ultima, it was doing a couple of abilities, then stopping completely, regardless of the class that was loaded.
       

      Attached Files:

    4. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83

      The event handler should not be async.
       
    5. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83
      After looking at the log, its probably a bug with ultima.
       
    6. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Changing it to non async, and in fact removing it entirely into it's original calling method as follows yields the same vein of result as above.

      Code:
              private static void RoutinePickFired(object sender, EventArgs eventArgs)
              {
                  RoutineManager.PreferedRoutine = Utilities.RoutineManager.GetRoutine();
                  Logger.SwitcharooLog("New Routine Chosen, restarting");
              }
      
      EDIT: Saw the mention of a bug with Ultima. I will try it with an "unsupported" class to verify if things are different, and grab some of the other routines provided here on the forums.
       
    7. newb23

      newb23 Community Developer

      Joined:
      Nov 26, 2014
      Messages:
      397
      Likes Received:
      15
      Trophy Points:
      18
      Everything appears to be in order now and it does appear to be a bug in Ultima as other routines are working as expected, thank you very much for your help.

      Now, I know this is a very, very simple plugin, but would there be interest in taking it, and incorporating it into RebornBuddy itself?

      I can have the design refitted into only using standard WPF controls (I have some custom controls for the comboboxes - easily removed), and leave most of the other stuff in-tact, saving you the trouble of needing to do it yourself. Granted, the majority of this plugin is just setting PreferredRoutine through a series of Comboboxes...
       
      Last edited: Oct 24, 2016

    Share This Page