Exemplo n.º 1
0
        public Vector3 FindLocation(Vector3 ptOrigin)
        {
            DateTime startFind              = DateTime.UtcNow;
            int      countPointsChecked     = 0;
            int      countFailDiff          = 0;
            int      countFailTrace         = 0;
            int      countFailToPointNav    = 0;
            int      countFailRange         = 0;
            int      countFailSafe          = 0;
            int      countFailToPointLoS    = 0;
            int      countFailToMobLoS      = 0;
            TimeSpan spanTrace              = TimeSpan.Zero;
            TimeSpan spanNav                = TimeSpan.Zero;
            double   furthestNearMobDistSqr = 0f;
            Vector3  ptFurthest             = Vector3.Zero;
            float    facingFurthest         = 0f;

            bool    reallyCheckRangeToLineOfSightMob = CheckRangeToLineOfSightMob && Me.GotTarget;
            Vector3 ptAdjOrigin = ptOrigin;
            // ptAdjOrigin.Z += 1f;   // comment out origin adjustment since using GetTraceLinePos()

            Vector3        ptDestination = new Vector3();
            List <Vector3> mobLocations  = new List <Vector3>();
            float          arcIncrement  = ((float)Math.PI * 2) / RaysToCheck;

            mobLocations = AllEnemyMobLocationsToCheck;
            double minSafeDistSqr = MinSafeDistance * MinSafeDistance;

            float baseDestinationFacing;

            if (PreferredDirection == Direction.None && MobToRunFrom != null)
            {
                baseDestinationFacing = Styx.Helpers.WoWMathHelper.CalculateNeededFacing(MobToRunFrom.Location, Me.Location);
            }
            else if (PreferredDirection == Direction.Frontwards)
            {
                baseDestinationFacing = Me.RenderFacing;
            }
            else // if (PreferredDirection == Disengage.Direction.Backwards)
            {
                baseDestinationFacing = Me.RenderFacing + (float)Math.PI;
            }

            L.debugLog("SafeArea: facing {0:F0} degrees, looking for safespot towards {1:F0} degrees", C.DefensiveColor,
                       WoWMathHelper.RadiansToDegrees(Me.RenderFacing),
                       WoWMathHelper.RadiansToDegrees(baseDestinationFacing)
                       );

            for (int arcIndex = 0; arcIndex < RaysToCheck; arcIndex++)
            {
                // rather than tracing around the circle, toggle between clockwise and counter clockwise for each test
                // .. so we favor a position furthest away from mob
                float checkFacing = baseDestinationFacing;
                if ((arcIndex & 1) == 0)
                {
                    checkFacing += arcIncrement * (arcIndex >> 1);
                }
                else
                {
                    checkFacing -= arcIncrement * ((arcIndex >> 1) + 1);
                }

                checkFacing = WoWMathHelper.NormalizeRadian(checkFacing);
                for (float distFromOrigin = MinScanDistance; distFromOrigin <= MaxScanDistance; distFromOrigin += IncrementScanDistance)
                {
                    countPointsChecked++;

                    ptDestination = ptOrigin.RayCast(checkFacing, distFromOrigin);

                    L.debugLog("SafeArea: checking {0:F1} degrees at {1:F1} yds", WoWMathHelper.RadiansToDegrees(checkFacing), distFromOrigin);

                    DateTime start     = DateTime.UtcNow;
                    bool     failTrace = MeshTraceline(Me.Location, ptDestination);
                    spanTrace += DateTime.UtcNow - start;

                    bool failNav;
                    if (DirectPathOnly)
                    {
                        failNav = failTrace;
                        spanNav = spanTrace;
                    }
                    else
                    {
                        start   = DateTime.UtcNow;
                        failNav = false;
                        //failNav = !Navigator.CanNavigateFully(Me.Location, ptDestination);
                        spanNav += DateTime.UtcNow - start;
                    }

                    if (failTrace)
                    {
                        countFailTrace++;
                    }

                    if (failTrace != failNav)
                    {
                        countFailDiff++;
                    }

                    if (failNav)
                    {
                        // L.debugLog( Color.Cyan, "Safe Location failed navigation check for degrees={0:F1} dist={1:F1}", RadiansToDegrees(checkFacing), distFromOrigin);
                        countFailToPointNav++;
                        continue;
                    }

                    Vector3 ptNearest = NearestMobLoc(ptDestination, mobLocations);
                    if (ptNearest == Vector3.Zero)
                    {
                        if (furthestNearMobDistSqr < minSafeDistSqr)
                        {
                            furthestNearMobDistSqr = minSafeDistSqr;
                            ptFurthest             = ptDestination; // set best available if others fail
                            facingFurthest         = checkFacing;
                        }
                    }
                    else
                    {
                        double mobDistSqr = ptDestination.Distance2DSquared(ptNearest);
                        if (furthestNearMobDistSqr < mobDistSqr)
                        {
                            furthestNearMobDistSqr = mobDistSqr;
                            ptFurthest             = ptDestination; // set best available if others fail
                            facingFurthest         = checkFacing;
                        }
                        if (mobDistSqr <= minSafeDistSqr)
                        {
                            countFailSafe++;
                            continue;
                        }
                    }

                    if (reallyCheckRangeToLineOfSightMob && RangeToLineOfSightMob < ptDestination.Distance(LineOfSightMob.Location) - LineOfSightMob.MeleeDistance())
                    {
                        countFailRange++;
                        continue;
                    }

                    if (CheckLineOfSightToSafeLocation)
                    {
                        Vector3 ptAdjDest = ptDestination;
                        ptAdjDest.Z += 1f;
                        if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptAdjOrigin, ptAdjDest))
                        {
                            // L.debugLog( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
                            countFailToPointLoS++;
                            continue;
                        }
                    }

                    if (CheckSpellLineOfSightToMob && LineOfSightMob != null)
                    {
                        if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSpellSight(ptDestination, LineOfSightMob.GetTraceLinePos()))
                        {
                            if (!Styx.WoWInternals.World.GameWorld.IsInLineOfSight(ptDestination, LineOfSightMob.GetTraceLinePos()))
                            {
                                // L.debugLog( Color.Cyan, "Mob-free location failed line of sight check for degrees={0:F1} dist={1:F1}", degreesFrom, distFromOrigin);
                                countFailToMobLoS++;
                                continue;
                            }
                        }
                    }

                    L.debugLog("SafeArea: Found mob-free location ({0:F1} yd radius) at degrees={1:F1} dist={2:F1} on point check# {3} at {4}, {5}, {6}", MinSafeDistance, WoWMathHelper.RadiansToDegrees(checkFacing), distFromOrigin, countPointsChecked, ptDestination.X, ptDestination.Y, ptDestination.Z);
                    L.debugLog("SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
                    L.debugLog("SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
                    L.debugLog("SafeArea: stats for ({0:F1} yd radius) found within {1:F1} yds ({2} checked, {3} nav, {4} not safe, {5} range, {6} pt los, {7} mob los, {8} mesh trace)", MinSafeDistance, MaxScanDistance, countPointsChecked, countFailToPointNav, countFailSafe, countFailRange, countFailToPointLoS, countFailToMobLoS, countFailTrace);
                    return(ptDestination);
                }
            }

            L.debugLog("SafeArea: No mob-free location ({0:F1} yd radius) found within {1:F1} yds ({2} checked, {3} nav, {4} not safe, {5} range, {6} pt los, {7} mob los, {8} mesh trace)", MinSafeDistance, MaxScanDistance, countPointsChecked, countFailToPointNav, countFailSafe, countFailRange, countFailToPointLoS, countFailToMobLoS, countFailTrace);
            if (ChooseSafestAvailable && ptFurthest != Vector3.Zero)
            {
                L.debugLog("SafeArea: choosing best available spot in {0:F1} yd radius where closest mob is {1:F1} yds", MinSafeDistance, Math.Sqrt(furthestNearMobDistSqr));
                L.debugLog("SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
                L.debugLog("SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
                return(ChooseSafestAvailable ? ptFurthest : Vector3.Zero);
            }

            L.debugLog("SafeArea: processing took {0:F0} ms", (DateTime.UtcNow - startFind).TotalMilliseconds);
            L.debugLog("SafeArea: meshtrace took {0:F0} ms / fullynav took {1:F0} ms", spanTrace.TotalMilliseconds, spanNav.TotalMilliseconds);
            return(Vector3.Zero);
        }
Exemplo n.º 2
0
        private static async Task <bool> TrappingBehavior(bool inCombat)
        {
            if (TargetManager.CombatType != TargetManager.CombatFlags.Trapping ||
                !TargetManager.CombatObject.Trappable)
            {
                return(false);
            }


            bool withinTrapDistance = TargetManager.CombatObject.Distance <= TargetManager.PullDistance;
            var  traps = nearbyTraps;

            if (traps.Count == 0 && withinTrapDistance)
            {
                if (Player.Inventory.Trap != null)
                {
                    if (Player.Inventory.Trap.ref_WoWItem.Usable &&
                        !Player.Inventory.Trap.OnCooldown)
                    {
                        TreeRoot.StatusText = "Trapping Behavior";
                        Player.Inventory.Trap.Use();
                        await CommonCoroutines.SleepForRandomUiInteractionTime();

                        return(true);
                    }
                }
            }

            if (inCombat)
            {
                TreeRoot.StatusText = "Trapping Behavior";

                //We want to move the target to our trap..
                //  -If we don't have aggro than we should move to the target
                //  -Else we should wait near our trap.

                if (!TargetManager.CombatObject.IsTargetingMe)
                {
                    //Wait for movement..
                    if (!withinTrapDistance)
                    {
                        return(false);
                    }
                }
                else
                {
                    //Move to nearest trap..
                    if (traps.Count > 0)
                    {
                        var nearestTrap = traps[0];
                        var distance    = nearestTrap.Location.Distance(TargetManager.CombatObject.Location);
                        if (distance > 1.5f || _trapMovement == null)
                        {
                            if (_trapMovement == null || _trapMovement.CurrentMovementQueue.Count == 0)
                            {
                                //Get the current side facing flipped!
                                float requiredFacingDegrees = WoWMathHelper.RadiansToDegrees(
                                    WoWMathHelper.CalculateNeededFacing(
                                        TargetManager.CombatObject.Location, nearestTrap.Location));



                                _trapMovement =
                                    new Movement(
                                        nearestTrap.GetSidePoint(requiredFacingDegrees, 8f),
                                        5f,
                                        "Trap Point");
                            }


                            if (_trapMovement != null)
                            {
                                await _trapMovement.MoveTo();
                            }
                            return(true);
                        }
                    }
                }
            }
            else if (withinTrapDistance) //Not in Combat
            {
                if (RoutineManager.Current.CombatBehavior != null &&
                    await RoutineManager.Current.CombatBehavior.ExecuteCoroutine())
                {
                    TreeRoot.StatusText = "Combat Behavior";
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public static Composite CreateDisengageBehavior()
        {
            return
                (new Decorator(
                     ret => IsDisengageNeeded(),
                     new Sequence(
                         new ActionDebugString(ret => "face away from or towards safespot as needed"),
                         new Action(delegate
            {
                if (useRocketJump)
                {
                    needFacing = Styx.Helpers.WoWMathHelper.CalculateNeededFacing(Me.Location, safeSpot);
                }
                else
                {
                    needFacing = Styx.Helpers.WoWMathHelper.CalculateNeededFacing(safeSpot, Me.Location);
                }

                needFacing = WoWMathHelper.NormalizeRadian(needFacing);
                float rotation = WoWMathHelper.NormalizeRadian(Math.Abs(needFacing - Me.RenderFacing));
                Logger.Write(Color.Cyan, "DIS: turning {0:F0} degrees {1} safe landing spot",
                             WoWMathHelper.RadiansToDegrees(rotation), useRocketJump ? "towards" : "away from");
                Me.SetFacing(needFacing);
            }),

                         new ActionDebugString(ret => "wait for facing to complete"),
                         new PrioritySelector(
                             new Wait(new TimeSpan(0, 0, 1), ret => Me.IsDirectlyFacing(needFacing), new ActionAlwaysSucceed()),
                             new Action(ret =>
            {
                Logger.Write(Color.Cyan, "DIS: timed out waiting to face safe spot - need:{0:F4} have:{1:F4}", needFacing, Me.RenderFacing);
                return RunStatus.Failure;
            })
                             ),

                         // stop facing
                         new Action(ret =>
            {
                Logger.Write(Color.Cyan, "DIS: cancel facing now we point the right way");
                WoWMovement.StopFace();
            }),

                         new ActionDebugString(ret => "set time of disengage just prior"),
                         new Sequence(
                             new PrioritySelector(
                                 new Decorator(ret => !useRocketJump, Spell.BuffSelf("Disengage")),
                                 new Decorator(ret => useRocketJump, Spell.BuffSelf("Rocket Jump")),
                                 new Action(ret => Logger.Write(Color.Cyan, "DIS: {0} cast appears to have failed", useRocketJump ? "Rocket Jump" : "Disengage"))
                                 ),
                             new Action(ret =>
            {
                NextDisengageAllowed = DateTime.Now.Add(new TimeSpan(0, 0, 0, 0, 750));
                Logger.Write(Color.Cyan, "DIS: finished {0} cast", useRocketJump ? "Rocket Jump" : "Disengage");
                if (Kite.IsKitingActive())
                {
                    Kite.EndKiting(String.Format("BP: Interrupted by {0}", useRocketJump ? "Rocket Jump" : "Disengage"));
                }
                return RunStatus.Success;
            })
                             )

                         )
                     ));
        }