Guest User

Untitled

a guest
Nov 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using CommonBehaviors.Actions;
  5. using Styx;
  6. using Styx.Logic;
  7. using Styx.Logic.Combat;
  8. using Styx.Logic.Pathing;
  9. using Styx.WoWInternals;
  10. using Styx.WoWInternals.WoWObjects;
  11. using TreeSharp;
  12. using Action = TreeSharp.Action;
  13.  
  14. namespace StratFarm
  15. {
  16.     class StratFarm : BotBase
  17.     {
  18.  
  19.         private WoWPoint EndPoint = new WoWPoint(4033.356, -3411.379, 115.796);
  20.         private WoWPoint StartPoint = new WoWPoint(3587.068, -3637.105, 138.4687);
  21.         private WoWPoint Outside = new WoWPoint(3233.309, -4047.673, 108.4394);
  22.         private WoWPoint ZoneIn = new WoWPoint(3236.226, -4055.726, 108.4661);
  23.         private int[] Gates = new int[] { 175368, 175357, 175356 };
  24.         private int[] Enemies = new int[] { 10437, 10436, 10438, 10417, 10416, 10439, 11030, 10394 };
  25.         private int Acolytes = 10399;
  26.         private int Baron = 45412;
  27.         private bool InstanceReset = false;
  28.         private bool CanKillBaron = false;
  29.  
  30.         private DateTime WaitTime = DateTime.Now;
  31.         private DateTime JumpTime = DateTime.Now;
  32.         Random r = new Random();
  33.  
  34.         public override void Initialize()
  35.         {
  36.             Styx.Logic.LootTargeting.Instance.IncludeTargetsFilter += new IncludeTargetsFilterDelegate(Instance_IncludeTargetsFilter);
  37.         }
  38.  
  39.         public override void Start()
  40.         {
  41.             Lua.Events.AttachEvent("CHAT_MSG_SYSTEM", CHAT_MSG_SYSTEM);
  42.         }
  43.  
  44.         public override void Stop()
  45.         {
  46.             Lua.Events.DetachEvent("CHAT_MSG_SYSTEM", CHAT_MSG_SYSTEM);
  47.         }
  48.  
  49.         void CHAT_MSG_SYSTEM(object context, LuaEventArgs args)
  50.         {
  51.             foreach (object obj in args.Args)
  52.             {
  53.                 if (obj.ToString().Contains("too many inst"))
  54.                 {
  55.                     MoveTo(Outside);
  56.                     SpellManager.Cast("Shadowmeld");
  57.                     WaitTime = DateTime.Now + TimeSpan.FromMinutes(5);
  58.                 }
  59.             }
  60.         }
  61.  
  62.         void Instance_IncludeTargetsFilter(List<WoWObject> incomingUnits, HashSet<WoWObject> outgoingUnits)
  63.         {
  64.             foreach (WoWObject obj in incomingUnits)
  65.             {
  66.                 if (obj.Entry == Baron)
  67.                 {
  68.                     outgoingUnits.Add(obj);
  69.                 }
  70.             }
  71.         }
  72.  
  73.         public override string Name
  74.         {
  75.             get { return "StratFarm"; }
  76.         }
  77.  
  78.         public override PulseFlags PulseFlags
  79.         {
  80.             get { return Styx.PulseFlags.All; }
  81.         }
  82.  
  83.         WoWMovement.MovementDirection[] movedirs = new WoWMovement.MovementDirection[] {
  84.             WoWMovement.MovementDirection.JumpAscend, WoWMovement.MovementDirection.StrafeLeft, WoWMovement.MovementDirection.StrafeRight
  85.         };
  86.         void MoveTo(WoWPoint p)
  87.         {
  88.             if (DateTime.Now > JumpTime)
  89.             {
  90.                 WoWMovement.Move(movedirs[r.Next(0, movedirs.Length + 1)], TimeSpan.FromMilliseconds(250 + r.Next(500)));
  91.                 JumpTime = DateTime.Now + TimeSpan.FromMilliseconds(1000 + r.Next(4000));
  92.             }
  93.             Navigator.MoveTo(p);
  94.         }
  95.  
  96.         private Composite Combat()
  97.         {
  98.             return new PrioritySelector(ctx => ObjectManager.GetObjectsOfType<WoWUnit>(false, false).Where(u => u.IsAlive && u.IsHostile && u.IsTargetingMeOrPet && u.Combat),
  99.                 // make sure we have a target
  100.                 new Decorator(ret => !StyxWoW.Me.GotTarget,
  101.                     new Action(ctx => {
  102.                         WoWUnit unit = ((IEnumerable<WoWUnit>)ctx).FirstOrDefault();
  103.                         if (unit != null)
  104.                             unit.Target();
  105.                     })),
  106.                 // move within 10 yards (or move if not in LOS)
  107.                 new Decorator(ret => StyxWoW.Me.CurrentTarget.Distance > 10 || !StyxWoW.Me.CurrentTarget.InLineOfSightOCD,
  108.                     new Action(ret => MoveTo(StyxWoW.Me.CurrentTarget.Location))),
  109.                 // holy nova if more than 3 mobs on us
  110.                 new Decorator(ctx => ((IEnumerable<WoWUnit>)ctx).Count(u => u.Distance < 10) > 1,
  111.                     new Action(ret => SpellManager.Cast("Holy Nova"))),
  112.                 // stop moving to cast
  113.                 new Decorator(ret => StyxWoW.Me.IsMoving,
  114.                     new Action(ret => Navigator.PlayerMover.MoveStop())),
  115.                 // sw:d
  116.                 new Decorator(ret => StyxWoW.Me.CurrentTarget.HealthPercent < 25 && SpellManager.CanCast("Shadow Word: Death"),
  117.                     new Action(ret => SpellManager.Cast("Shadow Word: Death"))),
  118.                 // face target
  119.                 new Decorator(ret => !StyxWoW.Me.IsSafelyFacing(StyxWoW.Me.CurrentTarget, 70f),
  120.                     new Action(ret => StyxWoW.Me.CurrentTarget.Face())),
  121.                 // spike if we can
  122.                 new Decorator(ret => SpellManager.CanCast("Mind Spike"),
  123.                     new Action(ret => SpellManager.Cast("Mind Spike"))),
  124.                 // wand if we can't
  125.                 new Decorator(ret => StyxWoW.Me.AutoRepeatingSpellId != 5019,
  126.                     new Action(ret => SpellManager.Cast("Shoot")))
  127.             );
  128.         }
  129.  
  130.         private Composite _root;
  131.         public override Composite Root
  132.         {
  133.             get
  134.             {
  135.                 return _root ?? (_root =
  136.                     new PrioritySelector(
  137.                         // if we need to wait
  138.                         new Decorator(ret => WaitTime > DateTime.Now,
  139.                             new ActionAlwaysSucceed()),
  140.  
  141.                         // if we're on a loading screen or something
  142.                         new Decorator(ret => !StyxWoW.IsInGame || !StyxWoW.IsInWorld || !StyxWoW.Me.IsValid || StyxWoW.Me.IsCasting,
  143.                             new ActionAlwaysSucceed()),
  144.                        
  145.                         // we should never be dead but eh, w/e
  146.                         Bots.Grind.LevelBot.CreateDeathBehavior(),
  147.                        
  148.                         // looting
  149.                         new Decorator(ret => LootFrame.Instance.IsVisible,
  150.                             new Action(ret => Lua.DoString("for i=1, GetNumLootItems() do LootSlot(i) ConfirmLootSlot(i) end CloseLoot()"))),
  151.  
  152.                         // if we're in epl, reset instances and run back in
  153.                         new Decorator(ret => StyxWoW.Me.ZoneId == 139,
  154.                             new PrioritySelector(
  155.                                 new Decorator(ret => !InstanceReset,
  156.                                     new Action(ret =>
  157.                                     {
  158.                                         Lua.DoString("ResetInstances()");
  159.                                         InstanceReset = true;
  160.                                         CanKillBaron = false;
  161.                                     })),
  162.                                 new Action(ret => MoveTo(ZoneIn)))),
  163.  
  164.                         // reset the instance reset thingy
  165.                         new Decorator(ret => InstanceReset,
  166.                             new Action(ret => InstanceReset = false)),
  167.  
  168.                         // if we're running into a gate, use it
  169.                         new PrioritySelector(ctx =>
  170.                         {
  171.                             foreach (int id in Gates)
  172.                             {
  173.                                 WoWGameObject obj = ObjectManager.GetObjectsOfType<WoWGameObject>().FirstOrDefault(e => e.Entry == id && !Blacklist.Contains(e));
  174.                                 if (obj != null && obj.CanUseNow() && obj.CanUse())
  175.                                 {
  176.                                     Blacklist.Add(obj, TimeSpan.FromMilliseconds(500));
  177.                                     return obj;
  178.                                 }
  179.                             }
  180.                             return null;
  181.                         },
  182.                             new Decorator(ctx => ctx != null,
  183.                                 new Action(ctx => ((WoWGameObject)ctx).Interact()))),
  184.  
  185.                         // run to the bosses
  186.                         new PrioritySelector(ctx =>
  187.                         {
  188.                             double maxdist = double.MaxValue;
  189.                             WoWUnit enemy = null;
  190.                             foreach (int id in Enemies)
  191.                             {
  192.                                 foreach (WoWUnit unit in ObjectManager.GetObjectsOfType<WoWUnit>().Where(e => e.Entry == id))
  193.                                 {
  194.                                     if (unit == null)
  195.                                     {
  196.                                         continue;
  197.                                     }
  198.                                     else if (!unit.IsAlive)
  199.                                     {
  200.                                         if (unit.Entry == 10394)
  201.                                         {
  202.                                             CanKillBaron = true;
  203.                                         }
  204.                                         WoWUnit a = ObjectManager.GetObjectsOfType<WoWUnit>().FirstOrDefault(e => e.Entry == Acolytes && e.IsAlive && e.Location.Distance(unit.Location) < 60);
  205.                                         if (a != null)
  206.                                         {
  207.                                             enemy = a;
  208.                                             goto endloop;
  209.                                         }
  210.                                     }
  211.                                     else if (unit.Distance < maxdist || enemy == null)
  212.                                     {
  213.                                         maxdist = unit.Distance;
  214.                                         enemy = unit;
  215.                                     }
  216.                                 }
  217.                             }
  218.                             endloop:
  219.                             if (enemy != null && StyxWoW.Me.CurrentTargetGuid != enemy.Guid)
  220.                             {
  221.                                 enemy.Target();
  222.                             }
  223.                             return enemy;
  224.                         },
  225.                             new Decorator(ctx => ctx != null && ((WoWUnit)ctx).IsAlive,
  226.                                 Combat())),
  227.  
  228.                         // move to outside barons house if we can't kill him yet
  229.                         new Decorator(ret => !CanKillBaron && StyxWoW.Me.Location.Distance(EndPoint) > 10,
  230.                             new Action(ret => MoveTo(EndPoint))),
  231.  
  232.                         // kill baron
  233.                         new PrioritySelector(ctx => ObjectManager.GetObjectsOfType<WoWUnit>(false, false).FirstOrDefault(e => e.Entry == Baron),
  234.                             new Decorator(ctx => ctx != null && ((WoWUnit)ctx).IsAlive,
  235.                                 new PrioritySelector(
  236.                                     new Decorator(ctx => StyxWoW.Me.CurrentTargetGuid != ((WoWUnit)ctx).Guid,
  237.                                         new Action(ctx => ((WoWUnit)ctx).Target())),
  238.                                     Combat())),
  239.                             new Decorator(ctx => ctx != null && ((WoWUnit)ctx).Lootable,
  240.                                 new Action(ctx => ((WoWUnit)ctx).Interact()))),
  241.  
  242.                         // failsafe
  243.                         new Decorator(ret => !CanKillBaron,
  244.                             new Action(ret => CanKillBaron = true)),
  245.  
  246.                         // run back towards start
  247.                         new Action(ret => MoveTo(StartPoint))
  248.                         ));
  249.             }
  250.         }
  251.     }
  252. }
Add Comment
Please, Sign In to add comment