Exemplo n.º 1
0
        public async Task <bool> PerformKiting(IEnumerable <CachedNetworkObject> dangerousObjects, CachedNetworkObject nearestThreat, float dangerRadius, Stopwatch stopwatchToReset = null)
        {
            if (dangerousObjects.Any())
            {
                if (nearestThreat != null && nearestThreat.Distance <= dangerRadius)
                {
                    Log.InfoFormat("[DangerDodger] Initiating kiting.");
                    List <Vector2> positions    = dangerousObjects.Select(o => o.Position.ToVector2()).ToList();
                    Vector2        dangerCenter = GeometryHelper.getAveragePoint(positions);
                    Log.InfoFormat("[DangerDodger] NearestThreat.Name: [{0}], NearestThreat.Position: [{1}], DangerCenter: [{2}]", nearestThreat.Name, nearestThreat.Position, dangerCenter);
                    //The escape angle represents the shortest way out of the danger.
                    double   escapeAngle = GeometryHelper.getAngleBetweenPoints(dangerCenter, LokiPoe.Me.Position.ToVector2());
                    Vector2i newPosition = MoveHelper.CalcSafePosition(escapeAngle, DangerDodgerSettings.Instance.StepLength);

                    if (newPosition != LokiPoe.Me.Position)
                    {
                        //PlayerMover.MoveTowards(newPosition) Does not seem to work when the character is busy.
                        Log.InfoFormat("[DangerDodger] Kiting towards a safer position. CurrentPosition: [{0}], NewPosition: [{1}]", LokiPoe.Me.Position, newPosition);
                        if (!await Coroutines.MoveToLocation(newPosition, 5, 1000))
                        {
                            Log.ErrorFormat("[DangerDodger] Error kiting towards safe position. ");
                        }
                    }
                    return(true);
                }
            }
            else
            {
                if (stopwatchToReset != null)
                {//In some cases, we don't restart the stopwatch when the threat is still nearby. The bot could decide to go pick up some item in the middle of danger zone at any moment ;.;
                    stopwatchToReset.Restart();
                }
            }
            return(false);
        }