Beispiel #1
0
        protected override Composite CreateBehavior_CombatMain()
        {
            return(new Decorator(context => !IsDone,
                                 new PrioritySelector(

                                     // Update values for this BT node visit...
                                     new Action(context =>
            {
                VehicleUnoccupied = FindUnoccupiedVehicle();

                // Figure out our final destination (i.e., a location or a mob)...
                // NB: this can change as we travel.  If our destination is a mob,
                // We can't "see" distant mobs until we get within 100 yards or so of them.
                // Until we close that distance, we'll head towards the provided location.
                // As soon as we "see" the mob, we'll switch to the mob as the destination.
                FinalDestination = Destination;
                FinalDestinationName = "destination";

                if (MobIds.Count() > 0)
                {
                    // If we can see our destination mob, calculate a path to it...
                    var nearestMob = Query.FindMobsAndFactions(MobIds).OrderBy(u => u.Distance).FirstOrDefault() as WoWUnit;
                    if (nearestMob != null)
                    {
                        // Target destination mob as feedback to the user...
                        Utility.Target(nearestMob);

                        FinalDestination = nearestMob.Location;
                        FinalDestinationName = nearestMob.SafeName;
                    }
                }

                return RunStatus.Failure;           // fall thru
            }),


                                     // Proceed if we're not in combat, or are ignoring it...
                                     new Decorator(context => !Me.Combat || IgnoreCombat,
                                                   new PrioritySelector(
                                                       // If we were successfully mounted...
                                                       // and within a few yards of our destination when we were dismounted, we must
                                                       // assume we were auto-dismounted, and the behavior is complete...
                                                       new Decorator(context => DidSuccessfullyMount && !IsInVehicle() &&
                                                                     (WoWMovement.ActiveMover.Location.Distance(FinalDestination) < 15.0),
                                                                     new Action(context => { BehaviorDone(); })),

                                                       // 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)),

                                                       // If we're not in a vehicle, go fetch one...
                                                       new Decorator(context => !IsInVehicle() && Query.IsViable(VehicleUnoccupied),
                                                                     new Sequence(
                                                                         new CompositeThrottleContinue(
                                                                             Throttle.UserUpdate,
                                                                             new Action(context =>
            {
                TreeRoot.StatusText = string.Format("Moving to {0} {1}",
                                                    VehicleUnoccupied.SafeName,
                                                    Me.Combat ? "(ignoring combat)" : "");
            })),
                                                                         new DecoratorContinue(context => VehicleUnoccupied.WithinInteractRange,
                                                                                               new Action(context => { VehicleUnoccupied.Interact(); })),
                                                                         new ActionRunCoroutine(
                                                                             interactUnitContext => UtilityCoroutine.MoveTo(
                                                                                 VehicleUnoccupied.Location,
                                                                                 VehicleUnoccupied.SafeName,
                                                                                 MovementBy))
                                                                         )),

                                                       // If we can't find a vehicle, terminate if requested...
                                                       new CompositeThrottle(
                                                           context => !IsInVehicle() && !Query.IsViable(VehicleUnoccupied),
                                                           Throttle.UserUpdate,
                                                           new Action(context =>
            {
                if (!WaitForVehicle)
                {
                    BehaviorDone(string.Format("No Vehicle, and WaitForVehicle=\"{0}\"", WaitForVehicle));
                }
                else
                {
                    TreeRoot.StatusText = "No vehicles in area--waiting for vehicle to become available.";
                }
            })),


                                                       // Move vehicle to destination...
                                                       new Decorator(context => IsInVehicle(),
                                                                     new PrioritySelector(
                                                                         // If we successfully mounted the vehicle, record the fact...
                                                                         new Decorator(context => !DidSuccessfullyMount,
                                                                                       new Action(context => { DidSuccessfullyMount = true; })),

                                                                         new Decorator(context => !Navigator.AtLocation(FinalDestination),
                                                                                       new ActionRunCoroutine(
                                                                                           interactUnitContext => UtilityCoroutine.MoveTo(
                                                                                               FinalDestination,
                                                                                               FinalDestinationName,
                                                                                               MovementBy))),

                                                                         new Decorator(context => WoWMovement.ActiveMover.IsMoving,
                                                                                       new Action(context => { WoWMovement.MoveStop(); })),

                                                                         // Arrived at destination, use spell if necessary...
                                                                         // NB: We want to make certain movement is settled before we attempt
                                                                         // to cast spell, so we won't be interrupted.
                                                                         new SleepForLagDuration(),
                                                                         CreateSpellBehavior()
                                                                         ))
                                                       )),

                                     // Squelch combat, if requested...
                                     new Decorator(context => IgnoreCombat,
                                                   new ActionAlwaysSucceed())
                                     )));
        }
        protected override Composite CreateBehavior_CombatMain()
        {
            return(new Decorator(context => !IsDone,
                                 new PrioritySelector(

                                     // Update values for this BT node visit...
                                     new Action(context =>
            {
                VehicleUnoccupied = FindUnoccupiedVehicle();

                // Figure out our final destination (i.e., a location or a mob)...
                // NB: this can change as we travel.  If our destination is a mob,
                // We can't "see" distant mobs until we get within 100 yards or so of them.
                // Until we close that distance, we'll head towards the provided location.
                // As soon as we "see" the mob, we'll switch to the mob as the destination.
                FinalDestination = Destination;
                FinalDestinationName = "destination";

                if (MobIds.Count() > 0)
                {
                    // If we can see our destination mob, calculate a path to it...
                    WoWUnit nearestMob = FindUnitsFromIds(MobIds).OrderBy(u => u.Distance).FirstOrDefault();
                    if (nearestMob != null)
                    {
                        // Target destination mob as feedback to the user...
                        if (!Me.GotTarget || (Me.CurrentTarget != nearestMob))
                        {
                            nearestMob.Target();
                        }

                        FinalDestination = nearestMob.Location;
                        FinalDestinationName = nearestMob.Name;
                    }
                }

                return RunStatus.Failure;           // fall thru
            }),


                                     // Proceed if we're not in combat, or are ignoring it...
                                     new Decorator(context => !Me.Combat || IgnoreCombat,
                                                   new PrioritySelector(
                                                       // If we were successfully mounted...
                                                       // and within a few yards of our destination when we were dismounted, we must
                                                       // assume we were auto-dismounted, and the behavior is complete...
                                                       new Decorator(context => DidSuccessfullyMount && !IsInVehicle() &&
                                                                     (Me.Location.Distance(FinalDestination) < 15.0),
                                                                     new Action(context => { BehaviorDone(); })),

                                                       // If we're not in a vehicle, go fetch one...
                                                       new Decorator(context => !IsInVehicle() && IsViable(VehicleUnoccupied),
                                                                     new Sequence(
                                                                         new Action(context =>
            {
                TreeRoot.StatusText = string.Format("Moving to {0} {1}",
                                                    VehicleUnoccupied.Name,
                                                    Me.Combat ? "(ignoring combat)" : "");
            }),
                                                                         new DecoratorContinue(context => VehicleUnoccupied.WithinInteractRange,
                                                                                               new Action(context => { VehicleUnoccupied.Interact(); })),
                                                                         UtilityBehaviorPS_MoveTo(context => VehicleUnoccupied.Location,
                                                                                                  context => VehicleUnoccupied.Name)
                                                                         )),

                                                       // If we successfully mounted the vehicle, record the fact...
                                                       new Decorator(context => IsInVehicle() && !DidSuccessfullyMount,
                                                                     new Action(context => { DidSuccessfullyMount = true; })),

                                                       // Move vehicle to destination...
                                                       UtilityBehaviorPS_MoveTo(context => FinalDestination,
                                                                                context => FinalDestinationName,
                                                                                context => Precision,
                                                                                context => IsInVehicle(),
                                                                                context => LocationObserver()),
                                                       new Decorator(context => Me.IsMoving,
                                                                     new Sequence(
                                                                         new Action(context => { WoWMovement.MoveStop(); }),
                                                                         new WaitContinue(TimeSpan.FromMilliseconds(CastTime), context => false, new ActionAlwaysSucceed())
                                                                         )),

                                                       // Arrived at destination, use spell if necessary...
                                                       CreateSpellBehavior()
                                                       )),

                                     // Squelch combat, if requested...
                                     new Decorator(context => IgnoreCombat,
                                                   new ActionAlwaysSucceed())
                                     )));
        }