Ejemplo n.º 1
0
        protected override Composite CreateBehavior()
        {
            return _root ??
                (_root = new PrioritySelector(
                    new Decorator(c => Counter > NumOfTimes,
                        new Action(c =>
                        {
                            TreeRoot.StatusText = "Finished!";
                            if (GoHomeButton > 0)
                            {
                                Lua.DoString("CastPetAction({0})", GoHomeButton);
                            }
                            _isBehaviorDone = true;
                            return RunStatus.Success;
                        })
                    ),

                    new Decorator(c => NpcVehicleList.Count > 0 && !InVehicle,
                        new Action(c =>
                        {
                            if (!NpcVehicleList[0].WithinInteractRange)
                            {
                                Navigator.MoveTo(NpcVehicleList[0].Location);
                                TreeRoot.StatusText = "Moving To Vehicle - " + NpcVehicleList[0].Name + " Yards Away: " + NpcVehicleList[0].Location.Distance(Me.Location);
                            }
                            else
                            {
                                NpcVehicleList[0].Interact();
                                MountedPoint = Me.Location;
                            }

                        })
                    ),
                    new Decorator(c => InVehicle && SpellType == 1,
                        new Action(c =>
                        {
                            if (NpcList.Count == 0 || NpcList[0].Location.Distance(VehicleList[0].Location) > 15)
                            {
                                TreeRoot.StatusText = "Waiting for Mob to Come Into Range or Appear.";
                                return RunStatus.Running;
                            }
                            else if (NpcList.Count >= 1 && NpcList[0].Location.Distance(VehicleList[0].Location) <= 15)
                            {
                                TreeRoot.StatusText = "Attacking: " + NpcList[0].Name + ", AttackButton: " + AttackButton;
                                NpcList[0].Target();
                                Lua.DoString("CastPetAction({0})", AttackButton);
                                Thread.Sleep(WaitTime);
                                Counter++;
                                return RunStatus.Success;
                            }
                            return RunStatus.Running;
                        })),

                    new Decorator(c => InVehicle && SpellType == 2,
                        new Action(c =>
                        {
                            if (NpcList.Count >= 1)
                            {
                                Thread.Sleep(OftenToUse);

                                TreeRoot.StatusText = "Attacking: " + NpcList[0].Name + ", AttackButton: " + AttackButton + ", Times Used: " + Counter;

                                if ((Counter > NumOfTimes && QuestId == 0) || (Me.QuestLog.GetQuestById((uint)QuestId) != null && Me.QuestLog.GetQuestById((uint)QuestId).IsCompleted && QuestId > 0))
                                {
                                    Lua.DoString("VehicleExit()");
                                    _isBehaviorDone = true;
                                    return RunStatus.Success;
                                }
                                NpcList[0].Target();
                                Lua.DoString("CastPetAction({0})", AttackButton);
                                LegacySpellManager.ClickRemoteLocation(NpcList[0].Location);
                                Thread.Sleep(WaitTime);
                                Counter++;
                                return RunStatus.Running;                                
                            }
                            return RunStatus.Running;
                        })),

                   new Decorator(c => InVehicle && SpellType == 3,
                       new PrioritySelector(
                           ret => NpcList.OrderBy(u => u.DistanceSqr).FirstOrDefault(u => Me.Transport.IsSafelyFacing(u)),
                            new Decorator(
                                ret => ret != null,
                                new PrioritySelector(
                                    new Decorator(
                                        ret => Me.CurrentTarget == null || Me.CurrentTarget != (WoWUnit)ret,
                                        new Action(ret => ((WoWUnit)ret).Target())),
                                    new Decorator(
                                        ret => !Me.Transport.IsSafelyFacing(((WoWUnit)ret),10),
                                        new Action(ret => Me.CurrentTarget.Face())),
                                    new Action(ret =>
                                        {
                                            Vector3 v = Me.CurrentTarget.Location - StyxWoW.Me.Location;
                                            v.Normalize();
                                            Lua.DoString(string.Format(
                                                "local pitch = {0}; local delta = pitch - VehicleAimGetAngle(); VehicleAimIncrement(delta); CastPetAction({1});",
                                                Math.Asin(v.Z).ToString(CultureInfo.InvariantCulture), AttackButton));

                                            Thread.Sleep(WaitTime);
                                            Counter++;
                                            return RunStatus.Success;         
                                        }))))),
          
                    new Decorator(c => InVehicle && SpellType == 4,
                        new Action(c =>
                        {
                            if (NpcList.Count >= 1)
                            {
                                using (new FrameLock())
                                {
                                    if ((Counter > NumOfTimes && QuestId == 0) || (Me.QuestLog.GetQuestById((uint)QuestId) != null && Me.QuestLog.GetQuestById((uint)QuestId).IsCompleted && QuestId > 0))
                                    {
                                        Lua.DoString("VehicleExit()");
                                        _isBehaviorDone = true;
                                        return RunStatus.Success;
                                    }
                                    NpcList[0].Target();
                                    WoWMovement.ClickToMove(NpcList[0].Location);
                                    Lua.DoString("CastPetAction({0})", AttackButton);
                                    LegacySpellManager.ClickRemoteLocation(NpcList[0].Location);
                                    Counter++;
                                    return RunStatus.Running;
                                }
                            }
                            return RunStatus.Running;
                        }))
                ));
        }
        protected override Composite CreateBehavior()
        {
            return(_root ??
                   (_root = new PrioritySelector(
                        new Decorator(c => (Counter > NumOfTimes) || Me.IsQuestComplete(QuestId),
                                      new Action(c =>
            {
                TreeRoot.StatusText = "Finished!";
                if (GoHomeButton > 0)
                {
                    Lua.DoString("CastPetAction({0})", GoHomeButton);
                }
                _isBehaviorDone = true;
                return RunStatus.Success;
            })
                                      ),

                        // Enable combat while not in a vehicle
                        new Decorator(ctx => (LevelBot.BehaviorFlags & BehaviorFlags.Combat) == 0 && !Query.IsInVehicle(),
                                      new Action(ctx => LevelBot.BehaviorFlags |= BehaviorFlags.Combat)),

                        // Disable combat while in a vehicle
                        new Decorator(ctx => (LevelBot.BehaviorFlags & BehaviorFlags.Combat) != 0 && Query.IsInVehicle(),
                                      new Action(ctx => LevelBot.BehaviorFlags &= ~BehaviorFlags.Combat)),

                        new Decorator(c => NpcVehicleList.Any() && !Query.IsInVehicle(),
                                      new Action(c =>
            {
                if (!NpcVehicleList[0].WithinInteractRange)
                {
                    Navigator.MoveTo(NpcVehicleList[0].Location);
                    TreeRoot.StatusText = "Moving To Vehicle - " + NpcVehicleList[0].SafeName + " Yards Away: " + NpcVehicleList[0].Location.Distance(Me.Location);
                }
                else
                {
                    NpcVehicleList[0].Interact();
                    MountedPoint = Me.Location;
                }
            })
                                      ),
                        new Decorator(c => SpellType == 1, new ActionRunCoroutine(ctx => TypeOneVehicleBehavior())),

                        new Decorator(c => SpellType == 2, new ActionRunCoroutine(ctx => TypeTwoVehicleBehavior())),

                        new Decorator(c => Query.IsInVehicle() && SpellType == 3,
                                      new PrioritySelector(
                                          ret => NpcList.OrderBy(u => u.DistanceSqr).FirstOrDefault(u => Me.Transport.IsSafelyFacing(u)),
                                          new Decorator(
                                              ret => ret != null,
                                              new PrioritySelector(
                                                  new Decorator(
                                                      ret => Me.CurrentTarget == null || Me.CurrentTarget != (WoWUnit)ret,
                                                      new Action(ret => ((WoWUnit)ret).Target())),
                                                  new Decorator(
                                                      ret => !Me.Transport.IsSafelyFacing(((WoWUnit)ret), 10),
                                                      new Action(ret => Me.CurrentTarget.Face())),
                                                  new Sequence(
                                                      new Action(
                                                          ctx =>
            {
                Vector3 v = Vector3.Normalize(Me.CurrentTarget.Location - StyxWoW.Me.Location);
                Lua.DoString(
                    string.Format(
                        "local pitch = {0}; local delta = pitch - VehicleAimGetAngle(); VehicleAimIncrement(delta); CastPetAction({1});",
                        Math.Asin(v.Z).ToString(CultureInfo.InvariantCulture),
                        AttackButton));
            }),
                                                      new Sleep(WaitTime),
                                                      new Action(ctx => Counter++)))))),

                        new Decorator(c => SpellType == 4,
                                      new Action(c =>
            {
                if (!Query.IsInVehicle())
                {
                    return RunStatus.Failure;
                }

                if (Counter > NumOfTimes && QuestId == 0 || Me.IsQuestComplete(QuestId))
                {
                    Lua.DoString("VehicleExit()");
                    _isBehaviorDone = true;
                    return RunStatus.Success;
                }

                var target = NpcList.FirstOrDefault();

                if (target != null)
                {
                    if (Me.CurrentTargetGuid != target.Guid)
                    {
                        target.Target();
                    }
                    WoWMovement.ClickToMove(target.Location);
                    Lua.DoString("CastPetAction({0})", AttackButton);
                    SpellManager.ClickRemoteLocation(target.Location);
                    Counter++;
                }
                return RunStatus.Running;
            })),

                        new Decorator(c => SpellType == 5,
                                      new Action(c =>
            {
                if (!Query.IsInVehicle())
                {
                    return RunStatus.Failure;
                }

                if (Counter > NumOfTimes && QuestId == 0 || Me.IsQuestComplete(QuestId))
                {
                    Lua.DoString("VehicleExit()");
                    _isBehaviorDone = true;
                    return RunStatus.Success;
                }
                var target = NpcList.FirstOrDefault();

                if (target != null)
                {
                    if (Me.CurrentTargetGuid != target.Guid)
                    {
                        target.Target();
                    }
                    WoWMovement.ConstantFace(Me.CurrentTargetGuid);
                    Lua.DoString("CastPetAction({0})", AttackButton);
                    if (QuestId == 0)
                    {
                        Counter++;
                    }
                }

                var target2 = NpcListSecondary.FirstOrDefault();
                if (target2 != null)
                {
                    if (Me.CurrentTargetGuid != target2.Guid)
                    {
                        target2.Target();
                    }
                    WoWMovement.ConstantFace(Me.CurrentTargetGuid);
                    Lua.DoString("CastPetAction({0})", AttackButton);
                    if (QuestId == 0)
                    {
                        Counter++;
                    }
                }

                Lua.DoString("CastPetAction({0})", AttackButton2);

                return RunStatus.Running;
            }))
                        )));
        }