Advertisement
Guest User

Untitled

a guest
Jul 1st, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.54 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Windows.Forms;
  4. using CommonBehaviors.Actions;
  5. using LazyBoxer.Helpers;
  6. using Styx;
  7. using Styx.CommonBot;
  8. using Styx.CommonBot.POI;
  9. using Styx.CommonBot.Routines;
  10. using Styx.Helpers;
  11. using Styx.Pathing;
  12. using Styx.TreeSharp;
  13. using Styx.WoWInternals;
  14. using Styx.WoWInternals.WoWObjects;
  15. using Action = Styx.TreeSharp.Action;
  16.  
  17. namespace LazyBoxer.Behaviors
  18. {
  19.     static class Looting
  20.     {
  21.         private static LocalPlayer Me { get { return StyxWoW.Me; } }
  22.         private static WoWUnit CT { get { return Me.CurrentTarget; } }
  23.        
  24.         private static WoWUnit _lootableObject = null;
  25.         private static bool tempTryAgain = false;
  26.  
  27.         private static WoWUnit _mobToLoot = null;
  28.         public static WoWUnit Lootable
  29.         {
  30.             get
  31.             {
  32.                 if (Setting.Instance.Loot.OK())
  33.                 {
  34.                     try
  35.                     {
  36.                         if (_mobToLoot != null && _mobToLoot.IsValid && !Timers.AutoExpire("mob to loot", 4000)) { return _mobToLoot; }
  37.                         _mobToLoot = ObjectManager.GetObjectsOfTypeFast<WoWUnit>().Where(o => o.Distance < Misc.InteractRange && o.Lootable && o.CanLoot && !Blacklist.Contains(o.Guid, BlacklistFlags.Loot)).OrderBy(o => o.Distance).FirstOrDefault();
  38.  
  39.                         return _mobToLoot;
  40.                     }
  41.                     catch (Exception e)
  42.                     {
  43.                         Console.WriteLine(e);
  44.                     }
  45.                 }
  46.  
  47.                 return null;
  48.             }
  49.         }
  50.  
  51.         // Only loot if we have at least 1 regular bag slow free
  52.         public static Composite CreateLootingBehavior()
  53.         {
  54.             return
  55.                 new Decorator(ret=> Me.FreeNormalBagSlots > 1,
  56.                     new PrioritySelector(
  57.  
  58.                         // Don't loot if our bags are full
  59.                         new Decorator(ret => Setting.Instance.Loot.OK() && !Me.IsCasting && !Me.IsChanneling && !Me.Combat && !Me.Looting && Lootable != null && Me.FreeNormalBagSlots <= 1,
  60.                                       new PrioritySelector(
  61.                                           new Action(c => Log.FailLog("Bags are full, no longer attempting to loot mobs."))
  62.                                           )
  63.                             ),
  64.  
  65.                         // Loot mob
  66.                         new Decorator(ret => Setting.Instance.Loot.OK() && !Misc.IsUserControllingMovement && !Me.IsCasting && !Me.IsChanneling && !Me.Combat && !Me.Looting && Lootable != null,
  67.                                       new PrioritySelector(
  68.                                           new Action(c => {Log.Info("Lootable mob found : " + Lootable.Name); return RunStatus.Failure; }),
  69.                                           new Action(c => { TreeRoot.StatusText = string.Format("Looting {0}", Lootable.Name); return RunStatus.Failure; }),
  70.  
  71.                                           // Hostile mob in our path and we've flagged it for death!
  72.                                           new Decorator(ret =>Lootable.IsValid && Common.HostileMobInOurPath(Lootable.Distance + 7) != null && Common.HostileMobInOurPath(Lootable.Distance + 5).Distance < 30 && Me.GotTarget && BotPoi.Current.Type == PoiType.Kill,
  73.                                                         new Sequence(
  74.  
  75.                                                             // Stop moving
  76.                                                             new DecoratorContinue(ret => Me.IsMoving, Movement.CreateEnsureMovementStoppedBehavior()),
  77.                                                             new WaitContinue(2, ret => !Me.IsMoving, new ActionAlwaysSucceed()),
  78.  
  79.                                                             // Clear navigator so we don't jump
  80.                                                             new Action(context => Navigator.Clear()),
  81.  
  82.                                                             // Call the CC pull logic      
  83.                                                             new Decorator(ret => RoutineManager.Current.PullBehavior != null, RoutineManager.Current.PullBehavior),
  84.  
  85.                                                             // Call the CC combat logic as some CCs may not have pull logic
  86.                                                             new Decorator(ret => RoutineManager.Current.PullBehavior != null, RoutineManager.Current.CombatBehavior)
  87.                                                             )),
  88.  
  89.                                          
  90.                            
  91.  
  92.                                           // Move closer to the object
  93.                                           new Decorator(ret => !Me.Combat && Lootable.Distance > Lootable.InteractRange * 0.85f, Movement.CreateMoveToLocationBehavior(ret => Lootable.Location, true, ret => Lootable.InteractRange * 0.55f)),
  94.  
  95.                                           // Attack mobs in front of us if we're moving to harvest
  96.                                           new Decorator(ret => Me.IsMoving && Common.HostileMobInOurPath(Lootable.Distance + 7) != null && !Me.IsCasting && Lootable.Distance > Lootable.InteractRange * 0.85f,
  97.                                                         new Throttle(2,
  98.                                                                      new Sequence(
  99.                                                                          new Action(context =>
  100.                                                                              {
  101.                                                                                  Log.Info(string.Format("Hostile mob in our path, {0}, we need to kill it", Common.HostileMobInOurPath(Lootable.Distance + 5).Name));
  102.                                                                                  Common.HostileMobInOurPath(Lootable.Distance + 5).Target();
  103.                                                                                  BotPoi.Current = new BotPoi(Common.HostileMobInOurPath(Lootable.Distance + 5), PoiType.Kill);
  104.  
  105.                                                                              })
  106.                                                                          )
  107.                                                             )),
  108.  
  109.  
  110.                                           // if we're moving then and we're in interact range then stop
  111.                                           new Decorator(ret => Lootable.Distance <= Lootable.InteractRange * 0.85f && Me.IsMoving,
  112.                                                         new Sequence(
  113.                                                             Movement.CreateEnsureMovementStoppedBehavior(),
  114.  
  115.                                                             // wait up to 2 seconds for us to register as stopped moving. WoW and HB tend to see this differently
  116.                                                             new Wait(2, ret => !Me.IsMoving, new ActionAlwaysSucceed())
  117.                                                             )
  118.                                               ),
  119.  
  120.                                           // If we're close enough to interact with the object then do so
  121.                                           new Decorator(ret => Lootable.Distance <= Lootable.InteractRange * 0.99f && !Me.IsMoving,
  122.                                                         new Sequence(
  123.  
  124.                                                             new Action(c => TreeRoot.StatusText = string.Format("Looting {0}", Lootable.Name)),
  125.  
  126.                                                             // Finally interact with it
  127.                                                             new Action(c =>
  128.                                                                 {
  129.                                                                     _lootableObject = null;
  130.                                                                     tempTryAgain = false;
  131.                                                                     _lootableObject = Lootable;
  132.                                                                     Lootable.Interact();
  133.                                                                     Blacklist.Add(_lootableObject.Guid, BlacklistFlags.Loot, TimeSpan.FromMinutes(60));
  134.                                                                     Navigator.Clear();
  135.                                                                 }),
  136.  
  137.                                                             // wait for Looting to start, max 2 seconds
  138.                                                             new Wait(2, ret => Me.Looting, new ActionAlwaysSucceed()),
  139.  
  140.                                                             // wait while we looting. Max 5 seconds
  141.                                                             new WaitContinue(4, ret => !Me.Looting, new ActionAlwaysSucceed()),
  142.  
  143.                                                             // Looting has finished, but wait 1 more second
  144.                                                             new WaitContinue(1, ret => false, new ActionAlwaysSucceed()),
  145.  
  146.                                                             // Black list so we don't try to loot again for min 1 minute
  147.                                                             new Action(c => Blacklist.Add(_lootableObject.Guid, BlacklistFlags.Loot, TimeSpan.FromMinutes(2))),
  148.                                                             //new Action(c => { _lootableObject = null; }),
  149.  
  150.                                                             // If we're still looting at this point cancel it!
  151.                                                             new DecoratorContinue(ret => Me.Looting, new Action(context =>
  152.                                                                 {
  153.                                                                     Log.Info("Still looting after a few seconds, trying something...");
  154.                                                                     tempTryAgain = true;
  155.                                                                     KeyboardManager.PressKey((char) Keys.Escape);
  156.                                                                     //_lootableObject.Interact();
  157.                                                                 })),
  158.  
  159.                                                             // try looting a second time. This is typically caused by too many people looting the same object at once
  160.                                                             new DecoratorContinue(ret=> tempTryAgain && _lootableObject.IsValid,
  161.                                                                                   new Sequence(
  162.                                                                                       new Action(context => Log.Info("Second attempt at looting, see if this works...")),
  163.                                                                                       new Action(context => _lootableObject.Interact()),
  164.                                                                                       new Wait(2, ret => Me.Looting, new ActionAlwaysSucceed()),
  165.                                                                                       new Action(context => tempTryAgain = false)
  166.                                                                                       )
  167.                                                                 ),
  168.  
  169.                                                             new WaitContinue(3, ret => !Me.Looting, new ActionAlwaysSucceed()),
  170.  
  171.                                                             new Action(c => { _lootableObject = null; }),
  172.                                            
  173.                                                             // If we're still looting press ESC to cancel it
  174.                                                             new DecoratorContinue(ret => Me.Looting, new Action(context => { Log.Info("Still looting, pressing ESC"); KeyboardManager.PressKey((char)Keys.Escape); })),
  175.  
  176.                                                             // clear variable
  177.                                                             // clear all navigation as we tend to jump after we've looted
  178.                                                             new Action(c => {Navigator.Clear(); return RunStatus.Success; })
  179.  
  180.                                                             )
  181.                                               )
  182.  
  183.                                           )
  184.  
  185.                             ))
  186.                     );
  187.         }
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement