Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Windows.Forms;
- using CommonBehaviors.Actions;
- using LazyBoxer.Helpers;
- using Styx;
- using Styx.CommonBot;
- using Styx.CommonBot.POI;
- using Styx.CommonBot.Routines;
- using Styx.Helpers;
- using Styx.Pathing;
- using Styx.TreeSharp;
- using Styx.WoWInternals;
- using Styx.WoWInternals.WoWObjects;
- using Action = Styx.TreeSharp.Action;
- namespace LazyBoxer.Behaviors
- {
- static class Looting
- {
- private static LocalPlayer Me { get { return StyxWoW.Me; } }
- private static WoWUnit CT { get { return Me.CurrentTarget; } }
- private static WoWUnit _lootableObject = null;
- private static bool tempTryAgain = false;
- private static WoWUnit _mobToLoot = null;
- public static WoWUnit Lootable
- {
- get
- {
- if (Setting.Instance.Loot.OK())
- {
- try
- {
- if (_mobToLoot != null && _mobToLoot.IsValid && !Timers.AutoExpire("mob to loot", 4000)) { return _mobToLoot; }
- _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();
- return _mobToLoot;
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- return null;
- }
- }
- // Only loot if we have at least 1 regular bag slow free
- public static Composite CreateLootingBehavior()
- {
- return
- new Decorator(ret=> Me.FreeNormalBagSlots > 1,
- new PrioritySelector(
- // Don't loot if our bags are full
- new Decorator(ret => Setting.Instance.Loot.OK() && !Me.IsCasting && !Me.IsChanneling && !Me.Combat && !Me.Looting && Lootable != null && Me.FreeNormalBagSlots <= 1,
- new PrioritySelector(
- new Action(c => Log.FailLog("Bags are full, no longer attempting to loot mobs."))
- )
- ),
- // Loot mob
- new Decorator(ret => Setting.Instance.Loot.OK() && !Misc.IsUserControllingMovement && !Me.IsCasting && !Me.IsChanneling && !Me.Combat && !Me.Looting && Lootable != null,
- new PrioritySelector(
- new Action(c => {Log.Info("Lootable mob found : " + Lootable.Name); return RunStatus.Failure; }),
- new Action(c => { TreeRoot.StatusText = string.Format("Looting {0}", Lootable.Name); return RunStatus.Failure; }),
- // Hostile mob in our path and we've flagged it for death!
- 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,
- new Sequence(
- // Stop moving
- new DecoratorContinue(ret => Me.IsMoving, Movement.CreateEnsureMovementStoppedBehavior()),
- new WaitContinue(2, ret => !Me.IsMoving, new ActionAlwaysSucceed()),
- // Clear navigator so we don't jump
- new Action(context => Navigator.Clear()),
- // Call the CC pull logic
- new Decorator(ret => RoutineManager.Current.PullBehavior != null, RoutineManager.Current.PullBehavior),
- // Call the CC combat logic as some CCs may not have pull logic
- new Decorator(ret => RoutineManager.Current.PullBehavior != null, RoutineManager.Current.CombatBehavior)
- )),
- // Move closer to the object
- new Decorator(ret => !Me.Combat && Lootable.Distance > Lootable.InteractRange * 0.85f, Movement.CreateMoveToLocationBehavior(ret => Lootable.Location, true, ret => Lootable.InteractRange * 0.55f)),
- // Attack mobs in front of us if we're moving to harvest
- new Decorator(ret => Me.IsMoving && Common.HostileMobInOurPath(Lootable.Distance + 7) != null && !Me.IsCasting && Lootable.Distance > Lootable.InteractRange * 0.85f,
- new Throttle(2,
- new Sequence(
- new Action(context =>
- {
- Log.Info(string.Format("Hostile mob in our path, {0}, we need to kill it", Common.HostileMobInOurPath(Lootable.Distance + 5).Name));
- Common.HostileMobInOurPath(Lootable.Distance + 5).Target();
- BotPoi.Current = new BotPoi(Common.HostileMobInOurPath(Lootable.Distance + 5), PoiType.Kill);
- })
- )
- )),
- // if we're moving then and we're in interact range then stop
- new Decorator(ret => Lootable.Distance <= Lootable.InteractRange * 0.85f && Me.IsMoving,
- new Sequence(
- Movement.CreateEnsureMovementStoppedBehavior(),
- // wait up to 2 seconds for us to register as stopped moving. WoW and HB tend to see this differently
- new Wait(2, ret => !Me.IsMoving, new ActionAlwaysSucceed())
- )
- ),
- // If we're close enough to interact with the object then do so
- new Decorator(ret => Lootable.Distance <= Lootable.InteractRange * 0.99f && !Me.IsMoving,
- new Sequence(
- new Action(c => TreeRoot.StatusText = string.Format("Looting {0}", Lootable.Name)),
- // Finally interact with it
- new Action(c =>
- {
- _lootableObject = null;
- tempTryAgain = false;
- _lootableObject = Lootable;
- Lootable.Interact();
- Blacklist.Add(_lootableObject.Guid, BlacklistFlags.Loot, TimeSpan.FromMinutes(60));
- Navigator.Clear();
- }),
- // wait for Looting to start, max 2 seconds
- new Wait(2, ret => Me.Looting, new ActionAlwaysSucceed()),
- // wait while we looting. Max 5 seconds
- new WaitContinue(4, ret => !Me.Looting, new ActionAlwaysSucceed()),
- // Looting has finished, but wait 1 more second
- new WaitContinue(1, ret => false, new ActionAlwaysSucceed()),
- // Black list so we don't try to loot again for min 1 minute
- new Action(c => Blacklist.Add(_lootableObject.Guid, BlacklistFlags.Loot, TimeSpan.FromMinutes(2))),
- //new Action(c => { _lootableObject = null; }),
- // If we're still looting at this point cancel it!
- new DecoratorContinue(ret => Me.Looting, new Action(context =>
- {
- Log.Info("Still looting after a few seconds, trying something...");
- tempTryAgain = true;
- KeyboardManager.PressKey((char) Keys.Escape);
- //_lootableObject.Interact();
- })),
- // try looting a second time. This is typically caused by too many people looting the same object at once
- new DecoratorContinue(ret=> tempTryAgain && _lootableObject.IsValid,
- new Sequence(
- new Action(context => Log.Info("Second attempt at looting, see if this works...")),
- new Action(context => _lootableObject.Interact()),
- new Wait(2, ret => Me.Looting, new ActionAlwaysSucceed()),
- new Action(context => tempTryAgain = false)
- )
- ),
- new WaitContinue(3, ret => !Me.Looting, new ActionAlwaysSucceed()),
- new Action(c => { _lootableObject = null; }),
- // If we're still looting press ESC to cancel it
- new DecoratorContinue(ret => Me.Looting, new Action(context => { Log.Info("Still looting, pressing ESC"); KeyboardManager.PressKey((char)Keys.Escape); })),
- // clear variable
- // clear all navigation as we tend to jump after we've looted
- new Action(c => {Navigator.Clear(); return RunStatus.Success; })
- )
- )
- )
- ))
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement