private async Task <bool> Searching()
        {
            CurrentGateScene = DeathGates.CurrentGateScene;

            if (CurrentGateScene == null)
            {
                if (_sceneDataBufferStartTime == DateTime.MinValue)
                {
                    _sceneDataBufferStartTime = DateTime.UtcNow;
                }
                if (DateTime.UtcNow.Subtract(_sceneDataBufferStartTime).TotalSeconds > 15)
                {
                    Core.Logger.Debug("Unable to find a gate scene");
                    State = States.Failed;
                }
                return(false);
            }

            if (CurrentGateScene.SnoId != ZetaDia.Me.CurrentScene.SceneInfo.SNOId)
            {
                Core.Logger.Debug($"Moving to CurrentGateScene {CurrentGateScene} Distance={CurrentGateScene.Distance}");
                State = States.MovingToScene;
                return(false);
            }

            Core.Logger.Debug($"Current Gate Scene is {CurrentGateScene?.Name}.");

            if (!CurrentGateScene.PortalPositions.All(p => _usedGatePositions.Contains(p)))
            {
                TargetGateScene = CurrentGateScene;
            }
            else
            {
                var connectedDeathGateScenes = CurrentGateScene.WorldScene.ConnectedScenes()
                                               .Select(cws => DeathGates.Scenes.FirstOrDefault(s => s.WorldScene == cws.Scene)).ToList();

                TargetGateScene = connectedDeathGateScenes.FirstOrDefault(s => s != null && !s.PortalPositions.Any(p => _usedGatePositions.Contains(p)));
            }

            if (TargetGateScene == null)
            {
                Core.Logger.Debug("A TargetGateScene wasn't found, using gate in current scene");
                TargetGateScene = GetClosestSceneWithUnvisitedGate();
            }

            Core.Logger.Debug($"Target Gate Scene is {TargetGateScene?.Name}");

            TargetGatePosition = DeathGates.SelectGate(CurrentGateScene, TargetGateScene);
            if (TargetGatePosition == Vector3.Zero)
            {
                Core.Logger.Debug($"TargetGatePosition was not found from {CurrentGateScene?.Name} to {TargetGateScene?.Name}");
                State = States.Failed;
                return(false);
            }

            Core.Logger.Debug($"TargetGatePosition found at distance {TargetGatePosition.Distance(AdvDia.MyPosition)} in scene {TargetGateScene?.Name}");
            State = States.MovingToGate;
            return(false);
        }
Example #2
0
        private async Task <bool> SetUsedGatesToIgnored()
        {
            // 'Reference' positions are hardcoded gate positions by SceneSnoId.
            // These allow gate nativation as soon as a scene is discovered.
            // And may be slightly off from actual gate actor positions.

            if (_deathGate != null)
            {
                Core.Logger.Debug($"Added origin gate to ignore list. (DiaGizmo) {_deathGate.Position}");
                _deathGateIgnoreList[_deathGate.Position] = DateTime.UtcNow;
            }

            if (_deathGate?.Position != _deathGatePosition)
            {
                Core.Logger.Debug($"Added origin gate position to ignore list. (Reference) {_deathGatePosition}");
                _deathGateIgnoreList[_deathGatePosition] = DateTime.UtcNow;
            }

            var destinationGate = ActorFinder.FindNearestDeathGate();

            if (destinationGate != null)
            {
                Core.Logger.Debug($"Added destination gate to ignore list (DiaGizmo) {destinationGate}");
                _deathGateIgnoreList[destinationGate.Position] = DateTime.UtcNow;
            }

            var destinationGateReferencePosition = DeathGates.NearestGateToPosition(AdvDia.MyPosition);

            if (destinationGateReferencePosition != Vector3.Zero)
            {
                Core.Logger.Debug($"Added destination gate to ignore list (Reference) {destinationGateReferencePosition}");
                _deathGateIgnoreList[destinationGateReferencePosition] = DateTime.UtcNow;
            }

            return(false);
        }
        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);
                }
            }
        }