private async Task <bool> Interact(DiaObject actor)
        {
            //var world = ZetaDia.Globals.WorldId;
            //bool retVal = false;
            //switch (actor.ActorType)
            //{
            //    case ActorType.Gizmo:
            //        switch (actor.ActorInfo.GizmoType)
            //        {
            //            case GizmoType.BossPortal:
            //            case GizmoType.Portal:
            //            case GizmoType.ReturnPortal:
            //                retVal = ZetaDia.Me.UsePower(SNOPower.GizmoOperatePortalWithAnimation, actor.Position);
            //                break;
            //            default:
            //                retVal = ZetaDia.Me.UsePower(SNOPower.Axe_Operate_Gizmo, actor.Position);
            //                break;
            //        }
            //        break;
            //    case ActorType.Monster:
            //        retVal = ZetaDia.Me.UsePower(SNOPower.Axe_Operate_NPC, actor.Position);
            //        break;
            //}

            //if (!ZetaDia.Globals.IsLoadingWorld && world == ZetaDia.Globals.WorldId)
            //{
            //Core.Logger.Debug($"Fallback Interaction Used");
            //actor.Interact();
            //}


            var world = ZetaDia.Globals.WorldId;
            await Coroutine.Sleep(100);

            if (actor == null || !actor.IsFullyValid())
            {
                return(false);
            }

            var ret = actor.Interact();
            await Coroutine.Sleep(_sleepTime);

            if (_isPortal)
            {
                await Coroutine.Sleep(1000);
            }
            if (!ZetaDia.Globals.IsLoadingWorld && world == ZetaDia.Globals.WorldId)
            {
                await Coroutine.Sleep(400);

                if (actor.IsFullyValid())
                {
                    ret = actor.Interact();
                }
            }
            return(ret);
        }
Beispiel #2
0
        public static async Task <bool> MoveToAndInteract(DiaObject obj, float range = -1f)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!obj.IsFullyValid())
            {
                return(false);
            }
            if (range == -1f)
            {
                range = obj.CollisionSphere.Radius;
            }

            if (obj.Position.Distance2D(ZetaDia.Me.Position) > range)
            {
                await MoveTo(obj.Position, obj.Name);
            }

            if (obj.Position.Distance2D(ZetaDia.Me.Position) < range)
            {
                obj.Interact();
            }

            return(true);
        }
        private static async Task <bool> Interact(DiaObject actor)
        {
            if (!actor.IsFullyValid())
            {
                return(false);
            }

            // Doubly-make sure we interact
            var retVal = actor.Interact();
            await Coroutine.Yield();

            return(retVal);
        }
        public static async Task<bool> MoveToAndInteract(DiaObject obj, float range = -1f)
        {
            if (obj == null)
                return false;
            if (!obj.IsFullyValid())
                return false;
            if (range == -1f)
                range = obj.CollisionSphere.Radius;

            if (obj.Position.Distance2D(ZetaDia.Me.Position) > range)
                await MoveTo(obj.Position, obj.Name);

            if (obj.Position.Distance2D(ZetaDia.Me.Position) < range)
                obj.Interact();

            return true;
        }
        /// <summary>
        /// Moves to something and interacts with it
        /// </summary>
        /// <param name="obj">object to interact with</param>
        /// <param name="range">how close to get</param>
        /// <param name="interactLimit">maximum number of times to interact</param>
        public static async Task<bool> Execute(DiaObject obj, float range = -1f, int interactLimit = 5)
        {
            if (obj == null)
                return false;

            if (!obj.IsFullyValid())
                return false;

            if (interactLimit < 1) interactLimit = 5;
            if (range < 0) range = obj.CollisionSphere.Radius;

            if (obj.Position.Distance(ZetaDia.Me.Position) > range)
            {
                if (!await MoveTo.Execute(obj.Position, obj.Name))
                {
                    Logger.Log("MoveTo Failed for {0} ({1}) Distance={2}", obj.Name, obj.ActorSNO, obj.Distance);
                    return false;
                }                    
            }

            var distance = obj.Position.Distance(ZetaDia.Me.Position);
            if (distance <= range || distance - obj.CollisionSphere.Radius <= range)
            {
                for (int i = 1; i <= interactLimit; i++)
                {
                    Logger.LogVerbose("Interacting with {0} ({1}) Attempt={2}", obj.Name, obj.ActorSNO, i);
                    if (obj.Interact() && i > 1)
                        break;

                    await Coroutine.Sleep(500);
                    await Coroutine.Yield();
                }
            }

            // Better to be redundant than failing to interact.

            Navigator.PlayerMover.MoveTowards(obj.Position);
            await Coroutine.Sleep(500);
            obj.Interact();

            Navigator.PlayerMover.MoveStop();
            await Coroutine.Sleep(1000);
            await Interact(obj);
            return true;
        }
Beispiel #6
0
        private static async Task <bool> Interact(DiaObject actor)
        {
            if (!actor.IsFullyValid())
            {
                return(false);
            }

            bool retVal = false;

            switch (actor.ActorType)
            {
            case ActorType.Gizmo:
                switch (actor.ActorInfo.GizmoType)
                {
                case GizmoType.BossPortal:
                case GizmoType.Portal:
                case GizmoType.ReturnPortal:
                    retVal = ZetaDia.Me.UsePower(SNOPower.GizmoOperatePortalWithAnimation, actor.Position);
                    break;

                default:
                    retVal = ZetaDia.Me.UsePower(SNOPower.Axe_Operate_Gizmo, actor.Position);
                    break;
                }
                break;

            case ActorType.Monster:
                retVal = ZetaDia.Me.UsePower(SNOPower.Axe_Operate_NPC, actor.Position);
                break;
            }

            // Doubly-make sure we interact
            actor.Interact();
            await Coroutine.Sleep(100);

            return(retVal);
        }
        /// <summary>
        /// Moves to something and interacts with it
        /// </summary>
        /// <param name="obj">object to interact with</param>
        /// <param name="interactLimit">maximum number of times to interact</param>
        public static async Task <bool> Execute(DiaObject obj, int interactLimit = 5)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!obj.IsFullyValid())
            {
                return(false);
            }

            if (interactLimit < 1)
            {
                interactLimit = 5;
            }

            if (Core.Player.IsInTown)
            {
                GameUI.CloseVendorWindow();
            }

            return(await CommonCoroutines.MoveAndInteract(obj, () => IsInteracting || interactLimit-- < 0) == CoroutineResult.Running);
        }
        /// <summary>
        /// Moves to something and interacts with it
        /// </summary>
        /// <param name="obj">object to interact with</param>
        /// <param name="range">how close to get</param>
        /// <param name="interactLimit">maximum number of times to interact</param>
        public static async Task <bool> Execute(DiaObject obj, float range = -1f, int interactLimit = 5)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!obj.IsFullyValid())
            {
                return(false);
            }

            if (interactLimit < 1)
            {
                interactLimit = 5;
            }
            if (range < 0)
            {
                range = obj.InteractDistance;
            }

            if (Core.Player.IsInTown)
            {
                GameUI.CloseVendorWindow();
            }

            if (obj.Position.Distance(ZetaDia.Me.Position) > range)
            {
                Navigator.PlayerMover.MoveTowards(obj.Position);

                if (!await MoveTo.Execute(obj.Position, obj.Name))
                {
                    Core.Logger.Log("MoveTo Failed for {0} ({1}) Distance={2}", obj.Name, obj.ActorSnoId, obj.Distance);
                    return(false);
                }
            }

            var distance = obj.Position.Distance(ZetaDia.Me.Position);

            if (distance <= range || distance - obj.InteractDistance <= range)
            {
                for (var i = 1; i <= interactLimit; i++)
                {
                    Core.Logger.Verbose("Interacting with {0} ({1}) Attempt={2}", obj.Name, obj.ActorSnoId, i);
                    if (obj.Interact() && i > 1)
                    {
                        break;
                    }

                    await Coroutine.Yield();
                }
            }

            // Better to be redundant than failing to interact.

            Navigator.PlayerMover.MoveTowards(obj.Position);
            await Coroutine.Yield();

            obj.Interact();

            Navigator.PlayerMover.MoveStop();
            await Coroutine.Yield();

            await Interact(obj);

            return(true);
        }
Beispiel #9
0
        protected async Task <bool> MoveToObjectiveRoutine()
        {
            if (ZetaDia.Me.IsDead || ZetaDia.IsLoadingWorld)
            {
                Logger.Log("IsDead={0} IsLoadingWorld={1}", ZetaDia.Me.IsDead, ZetaDia.IsLoadingWorld);
                return(false);
            }

            SceneSegmentation.Update();

            if (_route.Any() || _currentRouteDestination != Vector3.Zero)
            {
                return(MoveAlongRoute(_route));
            }

            // If the bot has failed to run directly towards the objective marker too many times
            // We'll blacklist it for 30 seconds to allow adjacent scenes to be explored.
            if (FailedAttempts >= FailedAttemptMax)
            {
                Logger.Log("Blacklisting Objective Marker for 60 seconds");
                BlacklistMarkerExpires = DateTime.UtcNow.AddSeconds(60);
                FailedAttempts         = 0;
                _route = CreateRouteToUnexploredScene();
                return(false);
            }

            // While the bot is currently blacklisted from directly running at the objective
            // Generate a route to go through some nearby scenes
            if (DateTime.UtcNow < BlacklistMarkerExpires)
            {
                _route = CreateRouteToObjective();
                return(false);
            }

            // 'ReachedDestination' is returned when finding a path to destination has failed.
            if (_lastMoveResult == MoveResult.ReachedDestination && _objectiveObject == null)
            {
                if (_miniMapMarker != null && _miniMapMarker.IsValid && _miniMapMarker.IsPointOfInterest)
                {
                    var distance = ZetaDia.Me.Position.Distance(_miniMapMarker.Position);
                    if (distance > 100)
                    {
                        FailedAttempts++;
                        Logger.Log("Direct Pathfinding failed towards Objective Marker. Attempts={0}/{1}", FailedAttempts, FailedAttemptMax);
                    }
                    else if (distance < 30)
                    {
                        Logger.Log("ReachedDestination no Objective found - finished!");
                        _isDone = true;
                        return(true);
                    }
                }
            }

            // Find the objective minimap marker
            FindObjectiveMarker();

            // If the marker is found or was previously found, find a nearby actor
            if (_mapMarkerLastPosition != Vector3.Zero)
            {
                RefreshActorInfo();
            }

            if (_objectiveObject == null && _miniMapMarker == null && Position == Vector3.Zero)
            {
                Logger.Log("Error: Could not find Objective Marker! {0}", Status());
                _isDone = true;
                return(true);
            }

            // Finish if World Changed
            if (ZetaDia.CurrentWorldId != _startWorldId)
            {
                Logger.Log("World changed from {0} to {1}, finished {2}", _startWorldId, ZetaDia.CurrentWorldId, Status());
                _isDone = true;
                return(true);
            }

            // Finish because Objective Found
            if (IsValidObjective() && _objectiveObject is DiaUnit && _objectiveObject.Position.Distance(ZetaDia.Me.Position) <= PathPrecision)
            {
                Logger.Log("We found the objective and its a monster, ending tag so we can kill it. {0}", Status());
                _isDone = true;
                return(true);
            }

            // Objective Object is available
            if (_objectiveObject != null && _objectiveObject.IsFullyValid())
            {
                // Move Closer to Objective Object
                if (_lastMoveResult != MoveResult.ReachedDestination)
                {
                    Logger.Debug("Moving to actor {0} {1}", _objectiveObject.ActorSNO, Status());
                    _lastMoveResult = await CommonCoroutines.MoveTo(_objectiveObject.Position);

                    return(true);
                }

                if (_objectiveObject is GizmoPortal)
                {
                    if (_lastMoveResult == MoveResult.ReachedDestination && _objectiveObject.Distance > InteractRange)
                    {
                        Logger.Log("ReachedDestination but not within InteractRange, finished");
                        _isDone = true;
                        return(true);
                    }
                    if (GameUI.PartyLeaderBossAccept.IsVisible || GameUI.PartyFollowerBossAccept.IsVisible)
                    {
                        Logger.Debug("Party Boss Button visible");
                        return(true);
                    }
                    if (ZetaDia.Me.Movement.IsMoving)
                    {
                        await CommonBehaviors.MoveStop().ExecuteCoroutine();
                    }
                    _objectiveObject.Interact();
                    _completedInteractAttempts++;
                    Logger.Debug("Interacting with portal object {0}, result: {1}", _objectiveObject.ActorSNO, Status());
                    await Coroutine.Sleep(500);

                    GameEvents.FireWorldTransferStart();
                    return(true);
                }
            }

            if (_miniMapMarker != null && ObjectiveObjectIsNullOrInvalid())
            {
                if (_miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) > PathPrecision)
                {
                    Logger.Debug("Moving to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status());
                    _lastMoveResult = await CommonCoroutines.MoveTo(_miniMapMarker.Position);

                    return(true);
                }

                if (_miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) < PathPrecision)
                {
                    Logger.Debug("Successfully Moved to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status());
                    _isDone = true;
                    return(true);
                }
            }
            if (_miniMapMarker == null && Position != Vector3.Zero && Position.Distance(ZetaDia.Me.Position) > PathPrecision)
            {
                _lastMoveResult = CommonCoroutines.MoveTo(Position).Result;
                if (_lastMoveResult == MoveResult.ReachedDestination)
                {
                    Logger.Log("ReachedDestination of Position, minimap marker not found, finished.");
                    _isDone = true;
                    return(true);
                }
            }

            Logger.Error("MoveToObjective Error: marker={0} actorNull={1} actorValid={2} completedInteracts={3} isPortal={4} dist={5} interactRange={6}",
                         _miniMapMarker != null,
                         _objectiveObject != null,
                         (_objectiveObject != null && _objectiveObject.IsFullyValid()),
                         _completedInteractAttempts,
                         IsPortal,
                         (_objectiveObject != null && _objectiveObject.IsFullyValid() ? _objectiveObject.Position.Distance(ZetaDia.Me.Position) : 0f),
                         InteractRange);

            return(false);
        }