• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Use XP boosts and stims

    Discussion in 'Community Developer Forum' started by trasser, Mar 23, 2016.

    1. trasser

      trasser New Member

      Joined:
      Sep 15, 2014
      Messages:
      91
      Likes Received:
      0
      Trophy Points:
      0
      Hi ppsl,

      Any1 can build plugin for using XP boost and stims?

      Im not coder but i think is simple. U can use OpenBox plugin as base and part of Joe routine:

      1. Check items in inventory with name contains "Boost" and "Stim"
      2. Check buffs on char with name contains "Boost" and "Stim"
      3. Use or not items.

      Code:
              public static void CheckForXPBoost()
              {
                  if (!UseXPBoosters) return;
      
                  try
                  {
                      bool XPBuffed = false;
                      TorItem tiu = null;
      
                      using ((UseFramelocks ? BuddyTor.Memory.AcquireFrame() : null))
                      {
                          foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Experience Boost")) { XPBuffed = true; break; }
                          if (!XPBuffed && Me.Level<55)
                          {
                              foreach (TorItem ti in Me.InventoryEquipment)
                              {
                                  if (ti.Name.Contains("Experience Boost")) 
                                  {
                                      ti.Use();
                                      ti.Interact();
                                      tiu = ti;
                                      Thread.Sleep(500);
                                      break;
                                  }
                              }
                          }
                      }
                      if (tiu!=null) Logger.Write("XP Booster [" + tiu.Name + "] found in inventory and used.");
                  }
       
    2. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      Maybe, I'm working on a few things but this would be a good addition to the relic manager. Basically rewrite relic manager to working, add this code which isn't everything but close enough work with. I'll think about it but not sure if I'll have time to work on it.
       
    3. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      Lol i think i made something for this a while back, but gave shit along the way around 4.0.
      I implemented this in Defaultcombat but at 4.0 it gave me logger.write issues i had no interest in solving :)

      The best way is implementing this in DC, because then we can add adrenals into the routine.

      [edit]
      or was it pure?!?
      [/edit]
       
    4. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      So i modified the Rest.cs somewhat
      Code:
              private static Composite Stims
              {
                  get
                  {
                      Logger.Write("Checking for Stims.");
                      bool StimBuffed = false;
                      bool StimUsed = false;
                      TorItem tiu = null;
      
                      using (BuddyTor.Memory.AcquireFrame())
                      {
                          return new Action(delegate
                          {
                              foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Stim")) { StimBuffed = true; break; }
                              if (!StimBuffed)
                              {
                                  var Attrs = ("Command;Fortitude;Versatile").Split(';');
                                  foreach (TorItem ti in Me.InventoryEquipment)
                                  {
                                      bool AttrIn = false;
                                      foreach (string attr in Attrs) if (ti != null && !ti.IsDeleted && ti.Name.Contains(attr)) { AttrIn = true; break; }
                                      if (AttrIn && ti != null && !ti.IsDeleted && ti.Name != null && ti.Name.Contains(" Stim"))
                                      {
                                          bool UseIt = false;
                                          if (ti.Name.Contains("Command") || ti.Name.Contains("Fortitude") || ti.Name.Contains("Versatile"))
                                          {
                                              UseIt = true;
                                              if (UseIt)
                                              {
                                                  ti.Use();
                                                  ti.Interact();
                                                  tiu = ti;
                                                  StimUsed = true;
                                                  Thread.Sleep(500);
                                                  break;
                                              }
                                              if (StimUsed) Logger.Write("Stim -" + tiu.Name + "- found in inventory and used.");
                                              return RunStatus.Success;
                                          }
                                      }
                                  }
                              }
                              return RunStatus.Failure;
                          });
                      }
                  }
              }
      
      
              public static Composite HandleRest
      		{
      			get
      			{
      				return new PrioritySelector(
      					ReviveCompanion,
      					Rejuvenate,
                          Stims
      					);
      			}
      		}
      
      It will run and use stims, but it will not for some reason use Logger.Write lines
      If i write a Logger.Write line before the foreach (Toreffect...) line the log is being spammed with that logger.write line.
      Didnt had time tonight to finish it, so maybe someone else can pick it up tonight.

      Using xp boosts should be the same code, so lets fix this first part :)
       
    5. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      Original code has logging outside the foreach loop which would make sense. See you have the foreach loop and then you break out of it so you don't run any additional code there, you exit it and would run anything after the foreach loop. Your logging and success needs to go where you have return RunStatus.Failure; Just nest a if/else there for success or failure and you should be on the money.
       
    6. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      Didn't test this as I'm working on some other stuff but this should work correctly.

      Code:
              private static Composite Stims
              {
                  get
                  {
                      Logger.Write("Checking for Stims.");
                      bool StimBuffed = false;
                      bool StimUsed = false;
                      TorItem tiu = null;
      
                      using (BuddyTor.Memory.AcquireFrame())
                      {
                          return new Action(delegate
                          {
                              foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Stim")) { StimBuffed = true; break; }
                              if (!StimBuffed)
                              {
                                  var Attrs = ("Command;Fortitude;Versatile").Split(';');
                                  foreach (TorItem ti in Me.InventoryEquipment)
                                  {
                                      bool AttrIn = false;
                                      foreach (string attr in Attrs) if (ti != null && !ti.IsDeleted && ti.Name.Contains(attr)) { AttrIn = true; break; }
                                      if (AttrIn && ti != null && !ti.IsDeleted && ti.Name != null && ti.Name.Contains(" Stim"))
                                      {
                                          bool UseIt = false;
                                          if (ti.Name.Contains("Command") || ti.Name.Contains("Fortitude") || ti.Name.Contains("Versatile"))
                                          {
                                              UseIt = true;
                                              if (UseIt)
                                              {
                                                  ti.Use();
                                                  ti.Interact();
                                                  tiu = ti;
                                                  StimUsed = true;
                                                  Thread.Sleep(500);
                                                  break;
                                              }
      
                                          }
                                      }
                                  }
      
                              }
                              if (StimUsed)
                              {
                                  Logger.Write("Stim -" + tiu.Name + "- found in inventory and used.");
                                  return RunStatus.Success;
                              }
                              return RunStatus.Failure;
                          });
                      }
                  }
              }
      
      
              public static Composite HandleRest
              {
                  get
                  {
                      return new PrioritySelector(
                          ReviveCompanion,
                          Rejuvenate,
                          Stims
                          );
                  }
              }
      
       
    7. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      Thanks W, will look into it tonight and complete it.
       
    8. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      So the code does work to some extend.
      it does use a stim, when we dont have the buff. Then it reports this to the log with the Logger.Write.
      BUT, when the bot is doing nothing (between fights, between movements or whatever) its spamming the log with that line.
      If i put a Logger.Write on other places, it also stays in that loop.
      So for some reason, it doesnt report back as success and gets out of the use stim function.

      I understand what the code does, but the "get", "delegate" and "Runstatus" are new to me.
      So i think the problem of the code lies with that part.
      If i would revert it to oldskool If then else statements, wouldnt that give me the same, or do i really need the get, delegate and runstatus?

      Also i switched from Notepad++ to Visual studio, and VS is bitching about dependancies.
      For some reason it doesnt see Torobject and stuff thats coming from BW and Greymagic (if im correct).
      I attached them newly to the project and removing the old, but still gives the same.

      Sorry for some noob questions, but i really like to get into this stuff.
       
    9. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      I would have to look deeper into the code and test with a bunch of low level stims I could click off. Dependencies yes I was thinking of writing a article to get people started here. On the right in your solution explorer with everything open go to references. Right click and new reference. Now go to browse and hit the browse button. Select your buddywing.exe and it will then reference buddywing and all of your code will stop complaining. This also adds autocomplete for buddywing functions.

      I think I know why it's looping, right before runstatus.success try resetting the StimUsed = false see were creating it and then were setting it to true but we never revert it back to false.
       
    10. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      Thanks for the reply! Actually a dumb bug hehe :)

      Code:
              private static Composite Stims
              {
                  get
                  {
                      // Setting the variables StimBuffed and StimUsed to False and setting the variable TorItem tiu to "null"
                      bool StimBuffed = false;
                      bool StimUsed = false;
                      TorItem tiu = null;
      
                      // Framelocking for accurate detection
                      using (BuddyTor.Memory.AcquireFrame())
                      {
                          // Dont know what Action delegate means                    
                          return new Action(delegate
                          {
                              // starting a loop in TorEffect checking for buffs in every effect that game has. Here it checks for the names that contain "Stim". If we find it then we set Stimbuffed to true and exit the 
                              foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Stim")) { StimBuffed = true; break; }
                              // If we dont have the stim buff, we are going to search for it in the inventory and use it.
                              if (!StimBuffed)
                              {
                                  var Attrs = ("Command;Fortitude;Versatile").Split(';');
                                  // Starting a loop to check for a stim that has the text containing the above line in the entire inventory.
                                  foreach (TorItem ti in Me.InventoryEquipment)
                                  {
                                      bool AttrIn = false;
                                      foreach (string attr in Attrs) if (ti != null && !ti.IsDeleted && ti.Name.Contains(attr)) { AttrIn = true; break; }
                                      if (AttrIn && ti != null && !ti.IsDeleted && ti.Name != null && ti.Name.Contains(" Stim"))
                                      {
                                          bool UseIt = false;
                                          // If we have found it and it contains the text parts we previously mentioned, we are going to use it.
                                          // Cant we use the already implemented UseItem for this?!?
                                          if (ti.Name.Contains("Command") || ti.Name.Contains("Fortitude") || ti.Name.Contains("Versatile"))
                                          {
                                              UseIt = true;
                                              if (UseIt)
                                              {
                                                  ti.Use();
                                                  ti.Interact();
                                                  tiu = ti;
                                                  StimUsed = true;
                                                  Thread.Sleep(500);
                                                  break;
                                              }
      
                                          }
                                      }
                                  }
      
                              }
                              // If we have used our Stim, we are going to write this to the log and kill this function
                              if (StimUsed)
                              {
                                  Logger.Write("Stim -" + tiu.Name + "- found in inventory and used.");
                                  StimUsed = false;
                                  return RunStatus.Success;
                              }
                              return RunStatus.Failure;
                          });
                      }
                  }
              }
      
      
              public static Composite HandleRest
              {
                  get
                  {
                      return new PrioritySelector(
                          ReviveCompanion,
                          Rejuvenate,
                          Stims
                          );
                  }
              }
      
      I commented in the code, so others may find help in this.
      The problem i had in the last code was, if im correct and i got wireds explanation correctly, The bot loops constantly through the coding.
      The stim part is called and if we dont have the stim buff, we get buffed. but if we are buffed within the same botrun, it keeps spamming the stim we used, because we didnt reset it at the end.
      Still weird thow, as its ignoring the code at the beginning of the stims function where we are setting the variables...

      Nonetheless, im gonna check it out tonight.

      -edit-
      Wouldnt Stimbuffed be required before the Runstatus.Succes:
      Code:
                              if (StimUsed)
                              {
                                  Logger.Write("Stim -" + tiu.Name + "- found in inventory and used.");
                                  StimBuffed = false;
                                  StimUsed = false;
                                  return RunStatus.Success;
                              }
      
      Then everything is reset.
       
      Last edited: Mar 25, 2016
    11. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      Confirmed, the code works, with your latest addition!
       
    12. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      Yeah see first run through you create it and set the initial value, when it goes through again it's already created and retains the value that was last set. Just have to toggle it. I have made that mistake a few times around. Some people will reset the values in the beginning like they do in the Targeting.cs code. They create the value and then reset values before the initial checks.
       
    13. wired203

      wired203 Community Developer

      Joined:
      Jan 22, 2015
      Messages:
      391
      Likes Received:
      1
      Trophy Points:
      18
      Don't know if you can move threads or not but this would be a good one for Developer since it's not a plugin. Looks good though, should help out a lot of people.
       
    14. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      Thread moved to developer section for learning purposes.
       
    15. Cryogenesis

      Cryogenesis Moderator Moderator

      Joined:
      Jul 13, 2010
      Messages:
      2,128
      Likes Received:
      13
      Trophy Points:
      38
      And for learning purposes, here is the full rest.cs code i changed for stims and xp boosters:
      Code:
      // Copyright (C) 2011-2015 Bossland GmbH
      // See the file LICENSE for the source code's detailed license
      
      using System;
      using System.Diagnostics;
      using System.Runtime.InteropServices;
      using System.Threading;
      using Buddy.BehaviorTree;
      using Buddy.CommonBot;
      using Buddy.Swtor;
      using Buddy.Swtor.Objects;
      using DefaultCombat.Core;
      using Action = Buddy.BehaviorTree.Action;
      
      namespace DefaultCombat.Helpers
      {
      	public static class Rest
      	{
      		private static int _swtorpid; // For Mounting and Spell Cancel/Stop
      		private static IntPtr _swtorhWnd;
      
      		private static TorPlayer Me
      		{
      			get { return BuddyTor.Me; }
      		}
      
      		private static Composite ReviveCompanion
      		{
      			get
      			{
      				return new PrioritySelector(
      					new Decorator(ret => Me.Companion != null && Me.Companion.IsDead,
      						new PrioritySelector(
      							Spell.WaitForCast(),
      							CommonBehaviors.MoveAndStop(location => Me.Companion.Position, 0.2f, true),
      							Spell.Cast("Revive Companion", on => Me.Companion, when => Me.Companion.Distance <= 0.3f)
      							))
      					);
      			}
      		}
      
      		private static Composite Rejuvenate
      		{
      			get
      			{
      				using (BuddyTor.Memory.AcquireFrame())
      				{
      					return new Action(delegate
      					{
      						if (NeedRest())
      						{
      							SetProcessAttrs();
      							if (BuddyTor.Me.IsMoving) Input.MoveStopAll();
      							while (KeepResting())
      							{
      								if (!Me.IsCasting)
      									AbilityManager.Cast(Me.RejuvenateAbilityName(), Me);
      
      								Thread.Sleep(100);
      							}
      							if (Me.IsCasting)
      							{
      								SendMessage(_swtorhWnd, 0x100, (IntPtr) (char) 0x1b, (IntPtr) 0);
      								Thread.Sleep(100);
      							}
      							return RunStatus.Success;
      						}
      
      						return RunStatus.Failure;
      					});
      				}
      			}
      		}
      
              private static Composite Stims
              {
                  get
                  {
                      bool StimBuffed = false;
                      bool StimUsed = false;
                      TorItem tiu = null;
      
                      using (BuddyTor.Memory.AcquireFrame())
                      {
                          return new Action(delegate
                          {
                              foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Stim")) { StimBuffed = true; break; }
                              if (!StimBuffed)
                              {
                                  var Attrs = ("Command;Fortitude;Versatile;Skill;Might;Resolve;Reflex").Split(';');
                                  foreach (TorItem ti in Me.InventoryEquipment)
                                  {
                                      bool AttrIn = false;
                                      foreach (string attr in Attrs) if (ti != null && !ti.IsDeleted && ti.Name.Contains(attr)) { AttrIn = true; break; }
                                      if (AttrIn && ti != null && !ti.IsDeleted && ti.Name != null && ti.Name.Contains(" Stim"))
                                      {
                                          bool UseIt = false;
                                          if (ti.Name.Contains("Command") || ti.Name.Contains("Fortitude") || ti.Name.Contains("Versatile") || ti.Name.Contains("Skill") || ti.Name.Contains("Might") || ti.Name.Contains("Resolve") || ti.Name.Contains("Reflex"))
                                          {
                                              UseIt = true;
                                              if (UseIt)
                                              {
                                                  ti.Use();
                                                  ti.Interact();
                                                  tiu = ti;
                                                  StimUsed = true;
                                                  Thread.Sleep(500);
                                                  break;
                                              }
                                          }
                                      }
                                  }
                              }
                              if (StimUsed)
                              {
                                  Logger.Write("Stim -" + tiu.Name + "- found in inventory and used.");
                                  StimUsed = false;
                                  return RunStatus.Success;
                              }
                              return RunStatus.Failure;
                          });
                      }
                  }
              }
      
              private static Composite XPBoost
              {
                  get
                  {
                      bool XPBuffed = false;
                      bool XPUsed = false;
                      TorItem tia = null;
      
                      using (BuddyTor.Memory.AcquireFrame())
                      {
                          return new Action(delegate
                          {
                              foreach (TorEffect te in Me.Buffs) if (te.Name.Contains("Experience Boost")) { XPBuffed = true; break; }
                              if (!XPBuffed && Me.Level < 65)
                              {
                                  foreach (TorItem ti in Me.InventoryEquipment)
                                  {
                                      bool UseIt = false;
                                      if (ti.Name.Contains("Experience Boost"))
                                      {
                                          UseIt = true;
                                          if (UseIt)
                                          {
                                              tia = ti;
                                              ti.Use();
                                              ti.Interact();
                                              XPUsed = true;
                                              Thread.Sleep(500);
                                              break;
                                          }
                                      }
                                  }
                              }
                              if (XPUsed)
                              {
                                  Logger.Write("XP Booster -" + tia.Name + "- found in inventory and used.");
                                  XPUsed = false;
                                  return RunStatus.Success;
                              }
                              return RunStatus.Failure;
                          });
                      }
                  }
              }
      
              public static Composite HandleRest
      		{
      			get
      			{
      				return new PrioritySelector(
      					ReviveCompanion,
      					Rejuvenate,
                          Stims,
                          XPBoost
      					);
      			}
      		}
      
      		[DllImport("user32.dll")]
      		private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
      
      		// Used for mounting/keysend
      
      		[DllImport("user32.dll")]
      		private static extern bool SetForegroundWindow(IntPtr hWnd);
      
      		public static int NormalizedResource()
      		{
      			if (Me.AdvancedClass == AdvancedClass.None)
      			{
      				switch (Me.Class)
      				{
      					//Add cases needed for reverse basic classes
      					case CharacterClass.BountyHunter:
      						return 100 - (int) Me.ResourcePercent();
      					case CharacterClass.Warrior:
      						return 100;
      					case CharacterClass.Knight:
      						return 100;
      					default:
      						return (int) Me.ResourcePercent();
      				}
      			}
      			switch (Me.AdvancedClass)
      			{
      				//Add cases needed for reverse Advance classes
      				case AdvancedClass.Mercenary:
      					return 100 - (int) Me.ResourcePercent();
      				case AdvancedClass.Powertech:
      					return 100 - (int) Me.ResourcePercent();
      				case AdvancedClass.Juggernaut:
      					return 100;
      				case AdvancedClass.Marauder:
      					return 100;
      				case AdvancedClass.Guardian:
      					return 100;
      				case AdvancedClass.Sentinel:
      					return 100;
      				default:
      					return (int) Me.ResourcePercent();
      			}
      		}
      
      		public static bool NeedRest()
      		{
      			var resource = NormalizedResource();
      			return !DefaultCombat.MovementDisabled && !Me.InCombat && (resource < 50 || Me.HealthPercent < 90
      																	   || (Me.Companion != null && !Me.Companion.IsDead && Me.Companion.HealthPercent < 90));
      		}
      
      		public static void SetProcessAttrs()
      		{
      			var torMem = 0;
      			foreach (var proc in Process.GetProcesses())
      				if (proc.ProcessName.Contains("swtor") && proc.MainWindowTitle.Contains("Star Wars"))
      
      					if (proc.PrivateMemorySize64 > torMem)
      					{
      						_swtorpid = proc.Id;
      						torMem = (int) proc.NonpagedSystemMemorySize64;
      						_swtorhWnd = proc.MainWindowHandle;
      					}
      		}
      
      		public static bool KeepResting()
      		{
      			var resource = NormalizedResource();
      			return !DefaultCombat.MovementDisabled && !Me.InCombat && (resource < 100 || Me.HealthPercent < 100
      																	   || (Me.Companion != null && !Me.Companion.IsDead && Me.Companion.HealthPercent < 100));
      		}
      	}
      }
      
       

    Share This Page