private async Task <bool> NotStarted()
 {
     //if (!BountyHelpers.IsActEnabledOnSettings(Act))
     //{
     //    State = States.ActIsDisabled;
     //    return false;
     //}
     if (BountyHelpers.IsActTurninCompleted(Act))
     {
         State = States.Completed;
         return(false);
     }
     if (BountyHelpers.IsActTurninInProgress(Act))
     {
         State = States.TurningInTheActQuest;
         return(false);
     }
     if (!BountyHelpers.AreAllActBountiesSupported(Act))
     {
         State = States.UnsupportedBountyFound;
         return(false);
     }
     State = States.RunningBounties;
     return(false);
 }
Example #2
0
        public static TrinityActor FindActor(SNOActor actorId, int marker = 0, float maxRange = 500, string internalName = "", Func <TrinityActor, bool> condition = null)
        {
            TrinityActor actor = null;

            if (actorId != 0)
            {
                if (marker != 0)
                {
                    actor = BountyHelpers.ScanForActor(actorId, marker, (int)maxRange, condition);
                }
                else
                {
                    actor = BountyHelpers.ScanForActor(actorId, (int)maxRange, condition);
                }
            }
            else if (!string.IsNullOrEmpty(internalName))
            {
                actor = BountyHelpers.ScanForActor(internalName, (int)maxRange, condition);
            }
            else if (actorId == 0 && marker != 0)
            {
                actor = BountyHelpers.GetActorNearMarker(marker, 10f, condition);
            }
            return(actor);
        }
 private async Task <bool> RunningBounties()
 {
     if (_currentBountyCoroutine == null)
     {
         if (_bountyCoroutines.Count != 0)
         {
             _currentBountyCoroutine = _bountyCoroutines[0];
         }
         else
         {
             if (BountyHelpers.IsActTurninInProgress(Act))
             {
                 State = States.TurningInTheActQuest;
                 return(false);
             }
             State = States.Failed;
             return(false);
         }
     }
     if (!await _currentBountyCoroutine.GetCoroutine())
     {
         return(false);
     }
     BountyStatistics.Report();
     ScenesStorage.Reset();
     if (_currentBountyCoroutine.State == BountyCoroutine.States.Failed)
     {
         //Logger.Info("[ActBounties] Looks like the bounty has failed, skipping the rest of the act.");
         State = States.Failed;
         return(false);
     }
     _bountyCoroutines.Remove(_currentBountyCoroutine);
     _currentBountyCoroutine = null;
     return(false);
 }
Example #4
0
            public void UpdateForActor(TrinityActor actor)
            {
                if (actor == null)
                {
                    ActorId        = 0;
                    ActorSno       = 0;
                    ActorName      = string.Empty;
                    StartAnimation = string.Empty;
                    SetPosition(Vector3.Zero);
                    return;
                }

                ActorId        = actor.ActorSnoId;
                ActorSno       = ActorId;
                ActorName      = actor.Name;
                StartAnimation = actor.Animation != 0 ? actor.Animation.ToString() : string.Empty;
                SetPosition(actor.Position);

                var marker = BountyHelpers.GetMarkerNearActor(actor);

                if (marker != null)
                {
                    MarkerHash = marker.NameHash;
                    MarkerType = marker.MarkerType;
                }
                else
                {
                    MarkerHash = 0;
                    MarkerName = string.Empty;
                    MarkerType = WorldMarkerType.None;
                }
            }
Example #5
0
        private void ScanForObjective()
        {
            if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000))
            {
                _objectiveLocation       = _previouslyFoundLocation;
                _previouslyFoundLocation = Vector3.Zero;
                Core.Logger.Debug("[KillUniqueMonster] Returning previous objective location.");
                return;
            }

            if (PluginTime.ReadyToUse(_lastScanTime, 1000))
            {
                _lastScanTime = PluginTime.CurrentMillisecond;
                if (_marker != 0)
                {
                    _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_marker, _objectiveScanRange);
                }
                if (_objectiveLocation == Vector3.Zero && _actorId != 0)
                {
                    _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange);
                }
                if (_objectiveLocation != Vector3.Zero)
                {
                    using (new PerformanceLogger("[KillUniqueMonster] Path to Objective Check", true))
                    {
                        Core.Logger.Log("[KillUniqueMonster] Found the objective at distance {0}",
                                        AdvDia.MyPosition.Distance(_objectiveLocation));

                        ExplorationHelpers.SetExplorationPriority(_objectiveLocation);
                    }
                }
            }
        }
        private void ScanForObjective()
        {
            if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000))
            {
                _objectiveLocation             = _previouslyFoundLocation;
                _previouslyFoundLocation       = Vector3.Zero;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                Logger.Debug("[EnterLevelArea] Returning previous objective location.");

                return;
            }
            if (PluginTime.ReadyToUse(_lastScanTime, 250))
            {
                _lastScanTime = PluginTime.CurrentMillisecond;
                if (_portalMarker != 0)
                {
                    _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_portalMarker, _objectiveScanRange);
                }
                // Belial
                if (_objectiveLocation == Vector3.Zero && _portalActorId == 159574)
                {
                    _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange);
                }
                //if (_objectiveLocation == Vector3.Zero && _portalActorId != 0)
                //{
                //    _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange);
                //}
                if (_objectiveLocation != Vector3.Zero)
                {
                    Logger.Info("[EnterLevelArea] Found the objective at distance {0}", AdvDia.MyPosition.Distance2D(_objectiveLocation));
                }
            }
        }
Example #7
0
        private List <Act> GetBalanceMaterialActs()
        {
            var matCounts = new Dictionary <Act, long>
            {
                { Act.A1, BountyHelpers.GetActMatsCount(Act.A1) },
                { Act.A2, BountyHelpers.GetActMatsCount(Act.A2) },
                { Act.A3, BountyHelpers.GetActMatsCount(Act.A3) },
                { Act.A4, BountyHelpers.GetActMatsCount(Act.A4) },
                { Act.A5, BountyHelpers.GetActMatsCount(Act.A5) },
            };

            var averageMatsCount = matCounts.Values.Average(m => m);
            var minMatsCount     = matCounts.Values.Min(m => m);
            var maxMatsCount     = matCounts.Values.Max(m => m);

            LogMaterialStats(matCounts, averageMatsCount, minMatsCount, maxMatsCount);

            var eligibleActs = matCounts.Where(kv =>
                                               !_completedActs.Contains(kv.Key) && BountyHelpers.AreAllActBountiesSupported(kv.Key) &&
                                               kv.Value <= averageMatsCount + 1).ToDictionary(kv => kv.Key, kv => kv.Value);

            var orderedActs = eligibleActs.OrderByDescending(p => p.Value).Select(v => v.Key).ToList();

            Core.Logger.Log($"Balance Material Acts: {eligibleActs.Aggregate("", (s, item) => s + $"{item.Key}({item.Value}), ")}");
            return(orderedActs);
        }
 private void ScanForObjective()
 {
     if (PluginTime.ReadyToUse(_lastScanTime, 1000))
     {
         _lastScanTime = PluginTime.CurrentMillisecond;
         if (_actorId != 0)
         {
             _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange);
         }
         if (_objectiveLocation != Vector3.Zero)
         {
             using (new PerformanceLogger("[MoveToObject] Path to Objective Check", true))
             {
                 //if ((Navigator.GetNavigationProviderAs<DefaultNavigationProvider>().CanFullyClientPathTo(_objectiveLocation)))
                 //{
                 Logger.Info("[MoveToObject] Found the objective at distance {0}",
                             AdvDia.MyPosition.Distance2D(_objectiveLocation));
                 //}
                 //else
                 //{
                 //    Logger.Debug("[MoveToObject] Found the objective at distance {0}, but cannot get a path to it.",
                 //        AdvDia.MyPosition.Distance2D(_objectiveLocation));
                 //    _objectiveLocation = Vector3.Zero;
                 //}
             }
         }
     }
 }
Example #9
0
 private bool IsQuestStepComplete()
 {
     if (BountyHelpers.QuestNpcExistsNearMe(80f))
     {
         return(true);
     }
     return(false);
 }
Example #10
0
        private async Task <bool> MovingToExitPortal()
        {
            EnablePulse();
            if (!await NavigationCoroutine.MoveTo(_nextLevelPortalLocation, 15))
            {
                return(false);
            }
            _nextLevelPortalLocation = Vector3.Zero;
            if (NavigationCoroutine.LastResult == CoroutineResult.Failure)
            {
                _portalScanRange = ActorFinder.LowerSearchRadius(_portalScanRange);
                if (_portalScanRange <= 100)
                {
                    _portalScanRange = 100;
                }
                if (_RiftType == RiftType.Nephalem && PluginSettings.Current.NephalemRiftFullExplore &&
                    AdvDia.RiftQuest.Step == RiftStep.Cleared)
                {
                    State = States.SearchingForTownstoneOrExitPortal;
                }
                else
                {
                    State = States.SearchingForExitPortal;
                }
                return(false);
            }
            var portal =
                ZetaDia.Actors.GetActorsOfType <DiaGizmo>(true)
                .Where(g => g.IsFullyValid() && g.IsPortal)
                .OrderBy(g => g.Distance)
                .FirstOrDefault();

            if (portal == null)
            {
                portal = BountyHelpers.GetPortalNearMarkerPosition(_nextLevelPortalLocation);
                if (portal == null)
                {
                    if (_RiftType == RiftType.Nephalem && PluginSettings.Current.NephalemRiftFullExplore &&
                        AdvDia.RiftQuest.Step == RiftStep.Cleared)
                    {
                        State = States.SearchingForTownstoneOrExitPortal;
                    }
                    else
                    {
                        State = States.SearchingForExitPortal;
                    }
                    return(false);
                }
            }
            State = States.EnteringExitPortal;
            _nextLevelPortalSNO      = portal.ActorSNO;
            _prePortalWorldDynamicId = AdvDia.CurrentWorldDynamicId;
            return(false);
        }
        private async Task <bool> Moving()
        {
            if (!await NavigationCoroutine.MoveTo(_objectiveLocation, 12))
            {
                return(false);
            }

            if (AdvDia.MyPosition.Distance(_objectiveLocation) > 30 && NavigationCoroutine.LastResult == CoroutineResult.Failure)
            {
                _previouslyFoundLocation       = _objectiveLocation;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                _objectiveLocation             = Vector3.Zero;
                _objectiveScanRange            = ActorFinder.LowerSearchRadius(_objectiveScanRange);
                if (_objectiveScanRange <= 0)
                {
                    _objectiveScanRange = 50;
                }
                State = States.Searching;
                return(false);
            }

            var portal = ActorFinder.FindGizmo(_portalActorId);

            if (portal == null)
            {
                portal = BountyHelpers.GetPortalNearMarkerPosition(_objectiveLocation);
                if (_portalActorId == 0)
                {
                    _discoveredPortalActorId = portal.ActorSNO;
                }
                //if (_portalActorId != portal.ActorSNO && BountyData.Act == Act.A5)
                //{
                //    Logger.Info("[EnterLevelArea] Was expecting to use portal SNO {0}, using {1} instead.", _portalActorId, portal.ActorSNO);
                //    _portalActorId = portal.ActorSNO;
                //}
            }
            else
            {
                if (portal.Position.Distance(_objectiveLocation) > 15)
                {
                    portal = null;
                }
            }
            if (portal == null)
            {
                State = States.Searching;
                return(false);
            }
            _objectiveLocation = portal.Position;
            State = States.Entering;
            _prePortalWorldDynamicId = AdvDia.CurrentWorldDynamicId;
            return(false);
        }
Example #12
0
        public override async Task <bool> MainTask()
        {
            if (Adventurer.TimeSinceWorldChange < 1000)
            {
                Core.Logger.Debug("[Bounties] Sleeping 1 second due to world change");
                await Coroutine.Sleep(1000);
            }

            if (_currentActBountiesCoroutine == null)
            {
                if (_currentAct != Act.Invalid)
                {
                    if (!BountyHelpers.AreAllActBountiesCompleted(_currentAct))
                    {
                        _currentActBountiesCoroutine = new ActBountiesCoroutine(_currentAct);
                    }
                    else
                    {
                        if (!TrySelectActCoroutine())
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }

            if (!await _currentActBountiesCoroutine.GetCoroutine())
            {
                return(false);
            }

            _completedActs.Add(_currentAct);

            if (_acts.Any())
            {
                _acts.Remove(_currentAct);

                if (_acts.Count == 0)
                {
                    Core.Logger.Log("All Acts Complete");
                    return(true);
                }
            }

            return(TrySelectActCoroutine());
        }
Example #13
0
        private void ScanForObjective()
        {
            if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000))
            {
                _objectiveLocation             = _previouslyFoundLocation;
                _previouslyFoundLocation       = Vector3.Zero;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                Logger.Debug("[MoveToMapMarker] Returning previous objective location.");

                return;
            }
            if (PluginTime.ReadyToUse(_lastScanTime, 1000))
            {
                _lastScanTime = PluginTime.CurrentMillisecond;
                if (_marker != 0)
                {
                    if (_marker == -1)
                    {
                        _objectiveLocation = BountyHelpers.ScanForMarkerLocation(0, _objectiveScanRange);
                    }
                    else
                    {
                        _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_marker, _objectiveScanRange);
                    }
                }
                //if (_objectiveLocation == Vector3.Zero && _actorId != 0)
                //{
                //    _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange);
                //}
                if (_objectiveLocation != Vector3.Zero)
                {
                    using (new PerformanceLogger("[MoveToMapMarker] Path to Objective Check", true))
                    {
                        //if ((Navigator.GetNavigationProviderAs<DefaultNavigationProvider>().CanFullyClientPathTo(_objectiveLocation)))
                        //{
                        Logger.Info("[MoveToMapMarker] Found the objective at distance {0}",
                                    AdvDia.MyPosition.Distance2D(_objectiveLocation));
                        //}
                        //else
                        //{
                        //    Logger.Debug("[MoveToMapMarker] Found the objective at distance {0}, but cannot get a path to it.",
                        //        AdvDia.MyPosition.Distance2D(_objectiveLocation));
                        //    _objectiveLocation = Vector3.Zero;
                        //}
                    }
                }
            }
        }
 private async Task <bool> TurningInTheActQuest()
 {
     if (!await _completeActBountiesCoroutine.GetCoroutine())
     {
         return(false);
     }
     if (BountyHelpers.IsActTurninCompleted(Act))
     {
         State = States.Completed;
     }
     else
     {
         _completeActBountiesCoroutine = new CompleteActBountiesCoroutine(Act);
     }
     return(false);
 }
Example #15
0
        public virtual async Task <bool> HandleBeforeCombat()
        {
            /* If standing on/nearby a portal, then assume it is intended to get in there. */
            if (!Core.Player.IsInRift &&
                BountyHelpers.GetPortalNearPosition(ZetaDia.Me.Position) != null)
            {
                Core.Logger.Debug("MainCombatTask Waiting for portal interaction");
                return(false);
            }

            // Wait after elite death until progression globe appears as a valid target or x time has passed.
            if (Core.Rift.IsInRift &&
                await Behaviors.WaitAfterUnitDeath.While(u => u.IsElite &&
                                                         u.Distance < 150 &&
                                                         Core.Targets.Entries.Any(a => a.IsElite &&
                                                                                  a.EliteType != EliteTypes.Minion &&
                                                                                  a.RadiusDistance < 60) &&
                                                         !Core.Targets.Any(p => p.Type == TrinityObjectType.ProgressionGlobe &&
                                                                           p.Distance < 150),
                                                         "Wait for Progression Globe", 1000))
            {
                return(true);
            }

            // Priority movement for progression globes. ** Temporary solution!
            if (TrinityCombat.Targeting.CurrentTarget != null)
            {
                if (await Behaviors.MoveToActor.While(a => a.Type == TrinityObjectType.ProgressionGlobe &&
                                                      !TrinityCombat.Weighting.ShouldIgnore(a) && !a.IsAvoidanceOnPath))
                {
                    return(true);
                }
            }

            // Priority interaction for doors. increases door opening reliability for some edge cases ** Temporary solution!
            if (ZetaDia.Storage.RiftStarted &&
                await Behaviors.MoveToInteract.While(a => a.Type == TrinityObjectType.Door &&
                                                     !a.IsUsed && a.Distance < a.CollisionRadius))
            {
                return(true);
            }

            return(false);
        }
        private void ScanForObjective()
        {
            if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000))
            {
                _objectiveLocation             = _previouslyFoundLocation;
                _previouslyFoundLocation       = Vector3.Zero;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                Core.Logger.Debug("Returning previous objective location.");
                return;
            }
            if (PluginTime.ReadyToUse(_lastScanTime, 1000))
            {
                _lastScanTime = PluginTime.CurrentMillisecond;
                TrinityMarker marker = null;

                if (_markerHash != 0)
                {
                    if (_markerHash == -1)
                    {
                        marker = BountyHelpers.ScanForMarker(0, _objectiveScanRange);
                    }
                    else
                    {
                        marker = BountyHelpers.ScanForMarker(_markerHash, _markerType, _objectiveScanRange);
                    }
                }
                else if (!string.IsNullOrEmpty(_markerName))
                {
                    marker = BountyHelpers.ScanForMarker(_markerName, _objectiveScanRange);
                }
                else if (_markerType != default(WorldMarkerType))
                {
                    marker = BountyHelpers.ScanForMarker(_markerType, _objectiveScanRange);
                }

                if (marker != null && marker.Position != Vector3.Zero)
                {
                    _objectiveLocation = marker.Position;
                    Core.Logger.Log($"[MoveToMapMarker] Found the objective {marker}");
                    ExplorationHelpers.SetExplorationPriority(_objectiveLocation);
                }
                _objectiveLocation = marker?.Position ?? Vector3.Zero;
            }
        }
Example #17
0
 private void ScanForObjective()
 {
     if (_marker != 0)
     {
         _center = BountyHelpers.ScanForMarkerLocation(_marker, OBJECTIVE_SCAN_RANGE);
     }
     if (_center == Vector3.Zero && _actorId != 0)
     {
         _center = BountyHelpers.ScanForActorLocation(_actorId, OBJECTIVE_SCAN_RANGE);
     }
     if (_center == Vector3.Zero)
     {
         _center = AdvDia.MyPosition;
     }
     if (_center != Vector3.Zero)
     {
         Logger.Info("[ClearAreaForNSeconds] Found the objective at distance {0}", AdvDia.MyPosition.Distance2D(_center));
     }
 }
Example #18
0
        private async Task <bool> NotStarted()
        {
            await Coroutine.Sleep(1000);

            if (!BountyHelpers.IsActTurninInProgress(_act))
            {
                State = States.AlreadyDone;
                return(false);
            }

            if (IsInZone)
            {
                State = States.TownRun;
                return(false);
            }
            State = States.ReturningToTown;
            Core.Logger.Log("[CompleteActBounties] Time to return to the town and claim our prize, huzzah!");
            return(false);
        }
 private void ScanForObjective()
 {
     if (PluginTime.ReadyToUse(_lastScanTime, 1000))
     {
         _lastScanTime = PluginTime.CurrentMillisecond;
         if (_marker != 0)
         {
             _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_marker, _objectiveScanRange);
         }
         if (_objectiveLocation == Vector3.Zero && _actorId != 0)
         {
             _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange);
         }
         if (_objectiveLocation != Vector3.Zero)
         {
             Logger.Info("[InteractWithUnit] Found the objective at distance {0}", AdvDia.MyPosition.Distance2D(_objectiveLocation));
         }
     }
 }
Example #20
0
        private async Task <bool> GetCoroutine()
        {
            if (_isDone)
            {
                return(true);
            }

            if (PluginEvents.TimeSinceWorldChange < 1000)
            {
                Logger.Debug("[RunActBountiesTag] Sleeping 1 second due to world change");
                await Coroutine.Sleep(1000);
            }

            if (_bounties == null || _bounties.Count == 0)
            {
                if (BountyHelpers.AreAllActBountiesCompleted(Act))
                {
                    if (await _completeActBountiesCoroutine.GetCoroutine())
                    {
                        _isDone = true;
                        return(true);
                    }
                    return(true);
                }
                _isDone = true;
                return(true);
            }
            _currentBounty = _bounties.FirstOrDefault();
            if (_currentBounty != null)
            {
                if (_currentBounty.State != BountyCoroutine.States.Completed && _currentBounty.State != BountyCoroutine.States.Failed)
                {
                    return(await _currentBounty.GetCoroutine());
                }
                ScenesStorage.Reset();

                _bounties.Remove(_currentBounty);
                BountyStatistics.Report();
            }
            return(true);
        }
 private void ScanForObjective()
 {
     if (PluginTime.ReadyToUse(_lastScanTime, 1000))
     {
         _lastScanTime = PluginTime.CurrentMillisecond;
         if (_marker != 0)
         {
             _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_marker, _objectiveScanRange);
         }
         if (_objectiveLocation == Vector3.Zero && _actorId != 0)
         {
             var actor = ActorFinder.FindGizmo(_actorId);
             if (actor != null && !actor.HasBeenOperated)
             {
                 _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange);
             }
         }
         if (_objectiveLocation != Vector3.Zero)
         {
             Core.Logger.Log("[InteractWithGizmo] Found the objective at distance {0}", AdvDia.MyPosition.Distance(_objectiveLocation));
         }
     }
 }
Example #22
0
        public override async Task <bool> StartTask()
        {
            PluginEvents.CurrentProfileType = ProfileType.Bounty;

            _currentAct = Act.Invalid;
            _currentActBountiesCoroutine = null;
            _completedActs = new List <Act>();

            switch (ActsMode)
            {
            case ActSelectionMode.None:
                var isSelectedActMode = PluginSettings.Current.BountyMode3.HasValue && PluginSettings.Current.BountyMode3.Value;
                _acts = isSelectedActMode ? GetUserSelectedActs() : GetBalanceMaterialActs();
                break;

            case ActSelectionMode.Balance:
                _acts = GetBalanceMaterialActs();
                break;

            case ActSelectionMode.All:
                _acts = GetAllActs();
                break;

            case ActSelectionMode.A1:
                _acts = GetSpecificAct(Act.A1);
                break;

            case ActSelectionMode.A2:
                _acts = GetSpecificAct(Act.A2);
                break;

            case ActSelectionMode.A3:
                _acts = GetSpecificAct(Act.A3);
                break;

            case ActSelectionMode.A4:
                _acts = GetSpecificAct(Act.A4);
                break;

            case ActSelectionMode.A5:
                _acts = GetSpecificAct(Act.A5);
                break;

            default:
                _acts = new List <Act>();
                break;
            }

            foreach (var act in _acts.ToList())
            {
                if (BountyHelpers.AreAllActBountiesCompleted(act))
                {
                    _acts.Remove(act);
                }
                else
                {
                    _completedActs.Add(act);
                }
            }

            return(TrySelectActCoroutine());
        }
        private void ScanForObjective()
        {
            if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000))
            {
                _objectiveLocation             = _previouslyFoundLocation;
                _previouslyFoundLocation       = Vector3.Zero;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                Core.Logger.Debug("[EnterLevelArea] Returning previous objective location.");

                return;
            }
            if (PluginTime.ReadyToUse(_lastScanTime, 250))
            {
                _lastScanTime = PluginTime.CurrentMillisecond;
                if (_portalMarker != 0)
                {
                    if (_objectiveLocation == Vector3.Zero)
                    {
                        // Help with weighting exploration nodes even if its unreachable/unpathable.
                        var markerlocation = BountyHelpers.ScanForMarkerLocation(_portalMarker, 5000);
                        ExplorationHelpers.SetExplorationPriority(markerlocation);
                    }

                    _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_portalMarker, _objectiveScanRange);

                    if (ExplorationData.FortressLevelAreaIds.Contains(AdvDia.CurrentLevelAreaId))
                    {
                        _deathGateLocation = DeathGates.GetBestGatePosition(_objectiveLocation);
                        if (_deathGateLocation != Vector3.Zero)
                        {
                            if (Navigator.StuckHandler.IsStuck && _deathGateLocation.Distance(AdvDia.MyPosition) < 125f)
                            {
                                var nearestGate = ActorFinder.FindNearestDeathGate();
                                if (nearestGate != null)
                                {
                                    Core.Logger.Warn("Found death gate location");
                                    _objectiveLocation = nearestGate.Position;
                                }
                            }
                        }
                    }
                }
                if (_objectives != null && _objectives.Any())
                {
                    BountyHelpers.ObjectiveActor objective;
                    _objectiveLocation = BountyHelpers.TryFindObjectivePosition(_objectives, _objectiveScanRange, out objective);
                    if (objective != null)
                    {
                        _objective          = objective;
                        _portalActorId      = objective.ActorId;
                        _destinationWorldId = objective.DestWorldId;
                    }
                }
                // Belial
                if (_objectiveLocation == Vector3.Zero && _portalActorId == 159574)
                {
                    _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange);
                }
                //if (_objectiveLocation == Vector3.Zero && _portalActorId != 0)
                //{
                //    _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange);
                //}
                if (_objectiveLocation != Vector3.Zero)
                {
                    Core.Logger.Log("[EnterLevelArea] Found the objective at distance {0}", AdvDia.MyPosition.Distance(_objectiveLocation));
                    ExplorationHelpers.SetExplorationPriority(_objectiveLocation);
                }
            }
        }
Example #24
0
        private ActBountiesCoroutine GetNextAct()
        {
            var bonusAct = ZetaDia.CurrentBonusAct;

            if (PluginSettings.Current.BountyMode0.HasValue && PluginSettings.Current.BountyMode0.Value)
            {
                Logger.Info("[Bounties] Force Bonus Act Mode activated. Attempting to run {0}.", bonusAct);
                if (!BountyHelpers.AreAllActBountiesSupported(bonusAct))
                {
                    Logger.Info("[Bounties] One or more unsupported bounties are detected in the bonus act, restarting the game.");
                    _isDone = true;
                    return(null);
                }
                if (_completedActs.Contains(bonusAct))
                {
                    Logger.Info("[Bounties] It seems like the bonus act is completed or contains an incomplete bounty, restarting the game.");
                    _isDone = true;
                    return(null);
                }
                _currentAct = bonusAct;
                return(new ActBountiesCoroutine(_currentAct));
            }
            else if (PluginSettings.Current.BountyMode1.HasValue && PluginSettings.Current.BountyMode1.Value)
            {
                Logger.Info("[Bounties] Skip Mode activated. Trying to pick the best act.");
                if (BountyHelpers.AreAllActBountiesSupported(bonusAct) && !_completedActs.Contains(bonusAct))
                {
                    _currentAct = bonusAct;
                    return(new ActBountiesCoroutine(_currentAct));
                }
                for (var i = Act.A1; i <= Act.A5; i++)
                {
                    if (_completedActs.Contains(i))
                    {
                        continue;
                    }
                    if (!BountyHelpers.AreAllActBountiesSupported(bonusAct))
                    {
                        continue;
                    }
                    _currentAct = i;
                    return(new ActBountiesCoroutine(_currentAct));
                }
            }
            else if (PluginSettings.Current.BountyMode2.HasValue && PluginSettings.Current.BountyMode2.Value)
            {
                Logger.Info("[Bounties] Balance Mats Mode activated. Trying to pick the best act.");
                var matCounts = new Dictionary <Act, long>
                {
                    { Act.A1, BountyHelpers.GetActMatsCount(Act.A1) },
                    { Act.A2, BountyHelpers.GetActMatsCount(Act.A2) },
                    { Act.A3, BountyHelpers.GetActMatsCount(Act.A3) },
                    { Act.A4, BountyHelpers.GetActMatsCount(Act.A4) },
                    { Act.A5, BountyHelpers.GetActMatsCount(Act.A5) },
                };

                Logger.Info("[Bounties] Current Bounty Mats Counts");
                Logger.Info("[Bounties] Act 1: {0}", matCounts[Act.A1]);
                Logger.Info("[Bounties] Act 2: {0}", matCounts[Act.A2]);
                Logger.Info("[Bounties] Act 3: {0}", matCounts[Act.A3]);
                Logger.Info("[Bounties] Act 4: {0}", matCounts[Act.A4]);
                Logger.Info("[Bounties] Act 5: {0}", matCounts[Act.A5]);

                var averageMatsCount = matCounts.Values.Average(m => m);
                var minMatsCount     = matCounts.Values.Min(m => m);
                var maxMatsCount     = matCounts.Values.Max(m => m);
                Logger.Debug("[Bounties] Average Mats Count: {0}", averageMatsCount);
                const int diff = 8;
                if (averageMatsCount - minMatsCount > diff)
                {
                    averageMatsCount = minMatsCount;
                    Logger.Debug("[Bounties] Average Mats Count - Min Mats Count > {0}", diff);
                }
                else if (maxMatsCount - minMatsCount <= diff)
                {
                    Logger.Debug("[Bounties] Max Mats Count - Min Mats Count <= {0}", diff);
                    averageMatsCount = maxMatsCount;
                }
                Logger.Debug("[Bounties] Will try to run acts with less than or equal to {0} mats.", averageMatsCount + 1);

                var eligibleActs =
                    matCounts.Where(
                        kv =>
                        !_completedActs.Contains(kv.Key) && BountyHelpers.AreAllActBountiesSupported(kv.Key) &&
                        kv.Value <= averageMatsCount + 1).ToDictionary(kv => kv.Key, kv => kv.Value);

                if (eligibleActs.Count == 0)
                {
                    Logger.Info("[Bounties] It seems like we are done with this game, restarting.");
                    _isDone = true;
                    return(null);
                }
                if (eligibleActs.ContainsKey(bonusAct))
                {
                    _currentAct = bonusAct;
                }
                else
                {
                    _currentAct = eligibleActs.OrderBy(kv => kv.Value).First().Key;
                }
                return(new ActBountiesCoroutine(_currentAct));
            }
            else if (PluginSettings.Current.BountyMode3.HasValue && PluginSettings.Current.BountyMode3.Value)
            {
                Logger.Info("[Bounties] Act Selection Mode activated. Trying to pick the best act.");
                if (_acts.Count > 0)
                {
                    _currentAct = _acts.Contains(bonusAct) ? bonusAct : _acts[0];
                    return(new ActBountiesCoroutine(_currentAct));
                }
            }
            return(null);
        }
        private async Task <bool> Moving()
        {
            if (_deathGateLocation != Vector3.Zero)
            {
                if (!await NavigationCoroutine.MoveTo(_deathGateLocation, 5))
                {
                    return(false);
                }

                _deathGateLocation = Vector3.Zero;
            }

            if (!await NavigationCoroutine.MoveTo(_objectiveLocation, 5))
            {
                return(false);
            }

            if (NavigationCoroutine.LastMoveResult == MoveResult.UnstuckAttempt)
            {
                Core.Logger.Debug("Navigation ended with unstuck attempts last result.");
                Navigator.Clear();
            }

            if (AdvDia.MyPosition.Distance(_objectiveLocation) > 50 && NavigationCoroutine.LastResult == CoroutineResult.Failure)
            {
                Core.Logger.Debug("[EnterLevelAreaCoroutine] Navigation ended, extending scan radius to continue searching.");
                NavigationCoroutine.Reset();
                _previouslyFoundLocation       = _objectiveLocation;
                _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond;
                _objectiveLocation             = Vector3.Zero;
                _objectiveScanRange            = ActorFinder.LowerSearchRadius(_objectiveScanRange);
                if (_objectiveScanRange <= 0)
                {
                    _objectiveScanRange = 50;
                }
                State = States.Searching;
                return(false);
            }

            DiaGizmo portal = null;

            if (_portalActorIds != null)
            {
                foreach (var portalid in _portalActorIds)
                {
                    portal = ActorFinder.FindGizmo(portalid);
                    if (portal != null)
                    {
                        _portalActorId = portal.ActorSnoId;
                        break;
                    }
                }
            }
            else
            {
                portal = ActorFinder.FindGizmo(_portalActorId);
            }

            if (portal == null)
            {
                portal = BountyHelpers.GetPortalNearPosition(_objectiveLocation);
                if (portal != null)
                {
                    _discoveredPortalActorId = portal.ActorSnoId;
                }
                else if (_portalActorId == 0)
                {
                    portal = ZetaDia.Actors.GetActorsOfType <GizmoPortal>().OrderBy(d => d.Distance).FirstOrDefault();
                    if (portal != null)
                    {
                        _discoveredPortalActorId = portal.ActorSnoId;
                        Core.Logger.Log($"[EnterLevelArea] Unable to find the portal we needed, using this one instead {portal.Name} ({portal.ActorSnoId})");
                    }
                }
            }

            if (portal == null)
            {
                State = States.Searching;
                return(false);
            }

            _interactRange = portal.CollisionSphere.Radius;
            // Add some tolerance, sometimes the radius is pretty low and it will keep stuck trying to move to it even when it's right besides it.
            _interactRange += ZetaDia.Me.CollisionSphere.Radius;

            Core.Logger.Debug($"[EnterLevelArea] Using interact range from portal: {_interactRange}");

            if (portal.Position.Distance(_objectiveLocation) > _interactRange)
            {
                Core.Logger.Debug($"[EnterLevelArea] Portal is still too far away, something went wrong with NavigationCoroutine");
                await CommonCoroutines.MoveTo(portal.Position);

                State = States.Searching;
                return(false);
            }

            _objectiveLocation = portal.Position;
            State = States.Entering;
            _prePortalWorldDynamicId = AdvDia.CurrentWorldDynamicId;

            Core.PlayerMover.MoveTowards(portal.Position);
            await Coroutine.Sleep(1000);

            return(false);
        }
        private async Task <bool> RunningBounties()
        {
            if (_currentBountyCoroutine == null)
            {
                if (_bountyCoroutines.Count != 0)
                {
                    //if (TrinityPluginSettings.Settings.Advanced.BetaPlayground)
                    //{
                    //    try
                    //    {
                    //        if (Core.Player.IsInParty)
                    //        {
                    //            if (BountyCoroutine.currentRandomizedBounty < 0 ||
                    //                BountyCoroutine.currentRandomizedBounty > _bountyCoroutines.Count)
                    //            {
                    //                BountyCoroutine.currentRandomizedBounty =
                    //                    Randomizer.GetRandomNumber(_bountyCoroutines.Count);
                    //                Core.Logger.Log("[ActBounties] Randomized Bounty Complete.", Act);
                    //            }
                    //        }
                    //        else
                    //            BountyCoroutine.currentRandomizedBounty = 0;

                    //        if (BountyCoroutine.currentRandomizedBounty < 0 ||
                    //            BountyCoroutine.currentRandomizedBounty > _bountyCoroutines.Count)
                    //            BountyCoroutine.currentRandomizedBounty = 0;

                    //        _currentBountyCoroutine = _bountyCoroutines[BountyCoroutine.currentRandomizedBounty];
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        Core.Logger.Log(BountyCoroutine.currentRandomizedBounty + " | " + _bountyCoroutines.Count, Act);
                    //        BountyCoroutine.currentRandomizedBounty = 0;
                    //        _currentBountyCoroutine = _bountyCoroutines[0];
                    //    }
                    //}
                    //else
                    //{
                    _currentBountyCoroutine = _bountyCoroutines[0];
                    //}
                }
                else
                {
                    if (BountyHelpers.IsActTurninInProgress(Act))
                    {
                        State = States.TurningInTheActQuest;
                        return(false);
                    }
                    State = States.Failed;
                    return(false);
                }
            }
            if (!await _currentBountyCoroutine.GetCoroutine())
            {
                return(false);
            }
            BountyStatistics.Report();
            Core.Scenes.Reset();
            if (_currentBountyCoroutine.State == BountyCoroutine.States.Failed)
            {
                //Core.Logger.Log("[ActBounties] Looks like the bounty has failed, skipping the rest of the act.");
                State = States.Failed;
                return(false);
            }
            _bountyCoroutines.Remove(_currentBountyCoroutine);
            _currentBountyCoroutine = null;
            return(false);
        }