Esempio n. 1
0
        private bool IsProfileBusy()
        {
            ProfileBehavior currentProfileBehavior = null;

            try
            {
                if (ProfileManager.CurrentProfileBehavior != null)
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                }
            }
            catch (Exception ex)
            {
                Core.Logger.Log("Exception while checking for current profile behavior!");
                Core.Logger.Log(LogCategory.GlobalHandler, ex.ToString());
            }
            if (currentProfileBehavior != null)
            {
                Type   profileBehaviortype = currentProfileBehavior.GetType();
                string behaviorName        = profileBehaviortype.Name;
                if (profileBehaviortype == typeof(UseTownPortalTag) ||
                    profileBehaviortype == typeof(WaitTimerTag) ||
                    behaviorName.ToLower().Contains("townrun") ||
                    behaviorName.ToLower().Contains("townportal") ||
                    behaviorName.ToLower().Contains("leave") ||
                    behaviorName.ToLower().Contains("wait"))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        public static int GetProfileActorSNO()
        {
            if (!ZetaDia.IsInGame)
            {
                return(-1);
            }

            if (ProfileManager.CurrentProfileBehavior == null)
            {
                return(-1);
            }

            ProfileBehavior currentBehavior = ProfileManager.CurrentProfileBehavior;

            int id = -1;

            if (currentBehavior == null)
            {
                return(id);
            }
            foreach (PropertyInfo pi in currentBehavior.GetType().GetProperties().ToList().Where(pi => pi.Name == "actorid"))
            {
                id = (int)pi.GetValue(currentBehavior, null);
            }

            return(id);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns if we're trying to TownRun or if profile tag is UseTownPortalTag
        /// </summary>
        /// <returns></returns>
        internal static bool IsTryingToTownPortal()
        {
            if (DateTime.UtcNow.Subtract(lastTownPortalCheckTime).TotalMilliseconds < Trinity.Settings.Advanced.CacheRefreshRate)
            {
                return(lastTownPortalCheckResult);
            }

            bool result = false;

            if (Trinity.IsReadyToTownRun)
            {
                result = true;
            }

            if (Trinity.ForceVendorRunASAP)
            {
                result = true;
            }

            if (TownRunCheckTimer.IsRunning)
            {
                result = true;
            }

            ProfileBehavior CurrentProfileBehavior = null;

            try
            {
                if (ProfileManager.CurrentProfileBehavior != null)
                {
                    CurrentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogCategory.UserInformation, "Exception while checking for TownPortal!");
                Logger.Log(LogCategory.GlobalHandler, ex.ToString());
            }
            if (CurrentProfileBehavior != null)
            {
                Type   profileBehaviortype = CurrentProfileBehavior.GetType();
                string behaviorName        = profileBehaviortype.Name;
                if ((profileBehaviortype == typeof(UseTownPortalTag) ||
                     profileBehaviortype == typeof(WaitTimerTag) ||
                     behaviorName.ToLower().Contains("townrun") ||
                     behaviorName.ToLower().Contains("townportal")))
                {
                    result = true;
                }
            }

            if (BrainBehavior.IsVendoring)
            {
                result = true;
            }

            lastTownPortalCheckTime   = DateTime.UtcNow;
            lastTownPortalCheckResult = result;
            return(result);
        }
Esempio n. 4
0
 public static void SetChildrenDone(this ProfileBehavior behavior)
 {
     behavior?.GetChildren()?.ForEach(b =>
     {
         (b as IEnhancedProfileBehavior)?.Done();
     });
 }
Esempio n. 5
0
        /// <summary>
        /// Checks to make sure the current profile behavior hasn't exceeded the allocated timeout
        /// </summary>
        private void ProfileBehaviorTimeout()
        {
            if (currentBehavior == null)
            {
                currentBehavior    = ProfileManager.CurrentProfileBehavior;
                lastBehaviorChange = DateTime.Now;
            }
            else if (DateTime.Now.Subtract(lastBehaviorChange) > behaviorTimeout && currentBehavior != ProfileManager.CurrentProfileBehavior)
            {
                Logging.Write("[QuestTools] Behavior Timeout: {0} exceeded for Profile: {1} Behavior: {2}",
                              behaviorTimeout,
                              ProfileManager.CurrentProfile.Name,
                              currentBehavior
                              );

                currentBehavior    = null;
                lastBehaviorChange = DateTime.Now;
                ProfileManager.Load(Zeta.CommonBot.ProfileManager.CurrentProfile.Path);
            }
            else
            {
                currentBehavior    = Zeta.CommonBot.ProfileManager.CurrentProfileBehavior;
                lastBehaviorChange = DateTime.Now;
            }
        }
Esempio n. 6
0
        private static bool IsProfileBusy()
        {
            ProfileBehavior currentProfileBehavior = null;

            try
            {
                if (ProfileManager.CurrentProfileBehavior != null)
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Exception while checking for current profile behavior! {0}", ex);
            }
            if (currentProfileBehavior != null)
            {
                var profileBehaviortype = currentProfileBehavior.GetType();
                var behaviorName        = profileBehaviortype.Name;
                if (profileBehaviortype == typeof(UseTownPortalTag) ||
                    profileBehaviortype == typeof(WaitTimerTag) ||
                    behaviorName.ToLower().Contains("townrun") ||
                    behaviorName.ToLower().Contains("townportal") ||
                    behaviorName.ToLower().Contains("leave") ||
                    behaviorName.ToLower().Contains("wait"))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// This is a thread running on the leader bot to watch the current profile behavior, to speed up followers going to the right place at the right time
        /// </summary>
        internal static void BehaviorWatcher()
        {
            try
            {
                if (Enabled && !IsFollower)
                {
                    ProfileBehavior currentBehavior = ProfileManager.CurrentProfileBehavior;
                    if (currentBehavior != null)
                    {
                        if (currentBehavior.GetType().Name.ToLower().Contains("town"))
                        {
                            Leader.IsInTown = true;
                        }
                        if (currentBehavior.GetType().Name.ToLower().Contains("leavegame"))
                        {
                            Leader.IsInGame = false;
                        }

                        // The profile position for look-ahead
                        Leader.ProfilePosition = Message.GetProfilePosition();
                        Leader.ProfileActorSNO = Message.GetProfileActorSNO();
                    }

                    if (BrainBehavior.IsVendoring)
                    {
                        Leader.IsInTown = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Logr.Log("Exception in BehaviorWatcher: {0}", ex);
            }
        }
Esempio n. 8
0
        public static float GetProfilePathPrecision()
        {
            float pathPrecision = 10f;

            if (!ZetaDia.IsInGame)
            {
                return(pathPrecision);
            }

            if (ProfileManager.CurrentProfileBehavior == null)
            {
                return(pathPrecision);
            }

            ProfileBehavior currentBehavior = ProfileManager.CurrentProfileBehavior;

            if (currentBehavior == null)
            {
                return(pathPrecision);
            }
            foreach (PropertyInfo pi in currentBehavior.GetType().GetProperties().ToList())
            {
                object val = null;
                if (pi.Name == "PathPrecision")
                {
                    val = pi.GetValue(currentBehavior, null);
                }

                if (val != null && val is float)
                {
                    pathPrecision = (float)val;
                }
            }
            return(pathPrecision);
        }
Esempio n. 9
0
 public static void CopyTo(this ProfileBehavior a, ProfileBehavior b)
 {
     b.QuestId     = a.QuestId;
     b.StepId      = a.StepId;
     b.StatusText  = a.StatusText;
     b.IgnoreReset = a.IgnoreReset;
     b.QuestName   = a.QuestName;
 }
Esempio n. 10
0
        public ProfileBehaviorLogger(ProfileBehavior profileBehavior)
        {
            if (profileBehavior == null)
            {
                throw new ArgumentNullException("profileBehavior");
            }

            this.profileBehavior = profileBehavior;
        }
Esempio n. 11
0
 public static void SetChildrenDone(this ProfileBehavior behavior)
 {
     behavior.GetChildren().ForEach(b =>
     {
         if (b is IEnhancedProfileBehavior)
         {
             (b as IEnhancedProfileBehavior).Done();
         }
     });
 }
 public static void Queue(ProfileBehavior behavior, string name = "")
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         name = behavior.ToString();
     }
     Queue(new List <ProfileBehavior> {
         behavior
     }, ret => true, name);
 }
Esempio n. 13
0
        public ExCoroutineAction(Func <object, Coroutine> coroutineProducer, ProfileBehavior behavior)
        {
            if (coroutineProducer == null)
            {
                throw new ArgumentNullException("coroutineProducer");
            }

            this.coroutineProducer = coroutineProducer;
            this.behavior          = behavior;
        }
Esempio n. 14
0
		public ExCoroutineAction(Func<object, Coroutine> coroutineProducer, ProfileBehavior behavior)
		{
			if (coroutineProducer == null)
			{
				throw new ArgumentNullException("coroutineProducer");
			}

			this.coroutineProducer = coroutineProducer;
			this.behavior = behavior;
		}
Esempio n. 15
0
        public static List <ProfileBehavior> GetChildren(this ProfileBehavior behavior)
        {
            var result = new List <ProfileBehavior>();

            if (behavior is INodeContainer)
            {
                result = (behavior as INodeContainer).GetNodes().ToList();
            }

            return(result);
        }
Esempio n. 16
0
        public static List <ProfileBehavior> GetChildren(this ProfileBehavior behavior)
        {
            var result    = new List <ProfileBehavior>();
            var container = behavior as INodeContainer;

            if (container != null)
            {
                result = container.GetNodes().ToList();
            }

            return(result);
        }
Esempio n. 17
0
        /// <summary>
        /// Attempts to get complex behavior from the tag. Will return null if tags are not
        /// <see cref="IfTag"/> or <see cref="WhileTag"/> implementations of the <see cref="ProfileBehavior"/> class
        /// </summary>
        /// <param name="behavior"></param>
        /// <returns></returns>
        private Composite GetProfileBehaviorTree(ProfileBehavior behavior)
        {
            var       ifBehavior    = behavior as IfTag;
            var       whileBehavior = behavior as WhileTag;
            Composite bodyBehavior;

            if (ifBehavior != null)
            {
                bodyBehavior = new Decorator(
                    (r) => ScriptManager.GetCondition(ifBehavior.Condition).Invoke(),
                    new Sequence(
                        this.GetProfileBehaviorCollectionBehavior(ifBehavior.Body).ToArray()
                        )
                    );
            }
            else if (whileBehavior != null)
            {
                bodyBehavior = new WhileLoop(
                    (r) => ScriptManager.GetCondition(whileBehavior.Condition).Invoke(),
                    this.GetProfileBehaviorCollectionBehavior(whileBehavior.Body).ToArray()
                    );
            }
            else
            {
                bodyBehavior = (Composite)behavior.InvokePrivateMethod <Composite>("CreateBehavior", null);
            }

            return(new PrioritySelector(
                       new ActionRunOnce(
                           (r) =>
            {
                try
                {
                    behavior.InvokePrivateMethod("UpdateBehavior");
                    behavior.Start();
                }
                catch
                {
                    // TODO: Get a better understanding of how RB starts the profile behaviors during behavior execution
                }

                return RunStatus.Failure;
            }
                           ),
                       bodyBehavior,
                       new ActionAlwaysSucceed()
                       ));
        }
Esempio n. 18
0
        /// <summary>
        /// Attempts to get complex behavior from the tag. Will return null if tags are not
        /// <see cref="IfTag"/> or <see cref="WhileTag"/> implementations of the <see cref="ProfileBehavior"/> class
        /// </summary>
        /// <param name="behavior"></param>
        /// <returns></returns>
        private Composite GetProfileBehaviorTree(ProfileBehavior behavior)
        {
            var ifBehavior = behavior as IfTag;
            var whileBehavior = behavior as WhileTag;
            Composite bodyBehavior;

            if (ifBehavior != null)
            {
                bodyBehavior = new Decorator(
                    (r) => ScriptManager.GetCondition(ifBehavior.Condition).Invoke(),
                    new Sequence(
                        this.GetProfileBehaviorCollectionBehavior(ifBehavior.Body).ToArray()
                        )
                    );
            }
            else if (whileBehavior != null)
            {
                bodyBehavior = new WhileLoop(
                    (r) => ScriptManager.GetCondition(whileBehavior.Condition).Invoke(),
                    this.GetProfileBehaviorCollectionBehavior(whileBehavior.Body).ToArray()
                );
            }
            else
            {
                bodyBehavior = (Composite) behavior.InvokePrivateMethod<Composite>("CreateBehavior", null);
            }

            return new PrioritySelector(
                new ActionRunOnce(
                    (r) =>
                    {
                        try
                        {
                            behavior.InvokePrivateMethod("UpdateBehavior");
                            behavior.Start();
                        }
                        catch
                        {
                            // TODO: Get a better understanding of how RB starts the profile behaviors during behavior execution
                        }

                        return RunStatus.Failure;
                    }
                ),
                bodyBehavior,
                new ActionAlwaysSucceed()
            );
        }
Esempio n. 19
0
        ///<summary>
        ///Tracks Current Profile Behavior and sets IsRunningOOCBehavior depending on the current Type of behavior.
        ///</summary>
        internal void CheckCurrentProfileBehavior()
        {
            if (DateTime.Now.Subtract(LastProfileBehaviorCheck).TotalMilliseconds > 450)
            {
                LastProfileBehaviorCheck = DateTime.Now;

                if (currentProfileBehavior == null ||
                    ProfileManager.CurrentProfileBehavior != null &&
                    ProfileManager.CurrentProfileBehavior.Behavior != null &&
                    currentProfileBehavior.Behavior.Guid != ProfileManager.CurrentProfileBehavior.Behavior.Guid)
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                    Logger.Write(LogLevel.Event, "Profile Behavior Changed To {0}", currentProfileBehavior.GetType().ToString());

                    Type profileTagType = currentProfileBehavior.GetType();
                    if (oocDBTags.Contains(profileTagType))
                    {
                        if (InteractiveTags.Contains(profileTagType))
                        {
                            ProfileBehaviorIsOOCInteractive = true;
                            Logger.DBLog.DebugFormat("Interactable Profile Tag!");

                            InteractableCachedObject = GetInteractiveCachedObject(currentProfileBehavior);
                            if (InteractableCachedObject != null)
                            {
                                Logger.DBLog.DebugFormat("Found Cached Interactable Server Object");
                            }
                        }
                        else
                        {
                            ProfileBehaviorIsOOCInteractive = false;
                            InteractableCachedObject        = null;
                        }

                        Logger.DBLog.DebugFormat("Current Profile Behavior has enabled OOC Behavior.");
                        IsRunningOOCBehavior = true;
                    }
                    else
                    {
                        ProfileBehaviorIsOOCInteractive = false;
                        InteractableCachedObject        = null;
                        IsRunningOOCBehavior            = false;
                    }
                }
            }
        }
Esempio n. 20
0
        public static Vector3 GetProfilePosition()
        {
            if (!ZetaDia.IsInGame)
            {
                return(Vector3.Zero);
            }

            if (ProfileManager.CurrentProfileBehavior == null)
            {
                return(Vector3.Zero);
            }

            ProfileBehavior currentBehavior = ProfileManager.CurrentProfileBehavior;

            Vector3 pos = Vector3.Zero;

            if (currentBehavior != null)
            {
                foreach (PropertyInfo pi in currentBehavior.GetType().GetProperties().ToList())
                {
                    if (pi.Name == "X")
                    {
                        pos.X = (float)pi.GetValue(currentBehavior, null);
                    }
                    if (pi.Name == "Y")
                    {
                        pos.Y = (float)pi.GetValue(currentBehavior, null);
                    }
                    if (pi.Name == "Z")
                    {
                        pos.Z = (float)pi.GetValue(currentBehavior, null);
                    }
                }
            }

            return(pos);
        }
Esempio n. 21
0
        ///<summary>
        ///Tracks Current Profile Behavior and sets IsRunningOOCBehavior depending on the current Type of behavior.
        ///</summary>
        internal void CheckCurrentProfileBehavior(bool forceUpdate = false)
        {
            if (forceUpdate || DateTime.Now.Subtract(LastProfileBehaviorCheck).TotalMilliseconds > 250)
            {
                LastProfileBehaviorCheck = DateTime.Now;

                if ((currentProfileBehavior == null && ProfileManager.CurrentProfileBehavior != null && ProfileManager.CurrentProfileBehavior.Behavior != null) ||
                    (ProfileManager.CurrentProfileBehavior != null && ProfileManager.CurrentProfileBehavior.Behavior != null && currentProfileBehavior != null && currentProfileBehavior.Behavior.Guid != ProfileManager.CurrentProfileBehavior.Behavior.Guid))
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                    Logger.Write(LogLevel.Event, "Profile Behavior Changed To {0} [{1}]", currentProfileBehavior.GetType().ToString(), currentProfileBehavior.StatusText);

                    Type profileTagType = currentProfileBehavior.GetType();

                    PreviousProfileBehaviorType = CurrentProfileBehaviorType;
                    CurrentProfileBehaviorType  = GetProfileBehaviorType(profileTagType);

                    if (OnProfileBehaviorChange != null)
                    {
                        OnProfileBehaviorChange(CurrentProfileBehaviorType);
                    }
                }
            }
        }
Esempio n. 22
0
        ///<summary>
        ///Tracks Current Profile Behavior and sets IsRunningOOCBehavior depending on the current Type of behavior.
        ///</summary>
        internal void CheckCurrentProfileBehavior(bool forceUpdate=false)
        {
            if (forceUpdate || DateTime.Now.Subtract(LastProfileBehaviorCheck).TotalMilliseconds > 250)
            {
                LastProfileBehaviorCheck = DateTime.Now;

                if ((currentProfileBehavior == null && ProfileManager.CurrentProfileBehavior != null && ProfileManager.CurrentProfileBehavior.Behavior != null)
                     || (ProfileManager.CurrentProfileBehavior != null && ProfileManager.CurrentProfileBehavior.Behavior != null && currentProfileBehavior != null && currentProfileBehavior.Behavior.Guid != ProfileManager.CurrentProfileBehavior.Behavior.Guid))
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                    Logger.Write(LogLevel.Event, "Profile Behavior Changed To {0} [{1}]", currentProfileBehavior.GetType().ToString(), currentProfileBehavior.StatusText);

                    Type profileTagType = currentProfileBehavior.GetType();

                    PreviousProfileBehaviorType = CurrentProfileBehaviorType;
                    CurrentProfileBehaviorType = GetProfileBehaviorType(profileTagType);

                    if (OnProfileBehaviorChange != null)
                        OnProfileBehaviorChange(CurrentProfileBehaviorType);
                }
            }
        }
Esempio n. 23
0
        internal static CacheObject GetInteractiveCachedObject(ProfileBehavior tag)
        {
            Type TagType = tag.GetType();

            if (InteractiveTags.Contains(TagType))
            {
                if (TagType == typeof(UseWaypointTag))
                {
                    UseWaypointTag tagWP           = (UseWaypointTag)tag;
                    var            WaypointObjects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == 6442);
                    foreach (CacheObject item in WaypointObjects)
                    {
                        if (item.Position.Distance(tagWP.Position) < 100f)
                        {
                            //Found matching waypoint object!
                            return(item);
                        }
                    }
                }
                else if (TagType == typeof(UseObjectTag))
                {
                    UseObjectTag tagUseObj = (UseObjectTag)tag;
                    if (tagUseObj.ActorId > 0)
                    {                    //Using SNOID..
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == tagUseObj.ActorId);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return(item);
                        }
                    }
                    else
                    {                    //use position to match object
                        Vector3 tagPosition = tagUseObj.Position;
                        var     Objects     = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.Position.Distance(tagPosition) <= 100f);
                        foreach (CacheObject item in Objects)
                        {
                            //Found matching object!
                            return(item);
                        }
                    }
                }
                else if (TagType == typeof(UsePortalTag))
                {
                    UsePortalTag tagUsePortal = (UsePortalTag)tag;
                    if (tagUsePortal.ActorId > 0)
                    {                    //Using SNOID..
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == tagUsePortal.ActorId);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return(item);
                        }
                    }
                    else
                    {                    //use position to match object
                        Vector3 tagPosition = tagUsePortal.Position;
                        var     Objects     = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.Position.Distance(tagPosition) <= 100f);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return(item);
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 24
0
 public ExCoroutineAction(Func <object, CoroutineTask> taskProducer, ProfileBehavior behavior)
     : this(obj => taskProducer(obj).Run(), behavior)
 {
 }
Esempio n. 25
0
 public static bool AreChildrenDone(this ProfileBehavior behavior)
 {
     return(behavior?.GetChildren()?.All(b => b.IsDone) ?? false);
 }
Esempio n. 26
0
 private static bool CheckBehaviorIsDone(ProfileBehavior profileBehavior)
 {
     return profileBehavior.IsDone;
 }
Esempio n. 27
0
 private static bool CheckBehaviorIsDone(ProfileBehavior profileBehavior)
 {
     return(profileBehavior.IsDone);
 }
Esempio n. 28
0
        /// <summary>
        /// Check if we are stuck or not by simply checking for position changing max once every 3 seconds
        /// </summary>
        /// <param name="vMyCurrentPosition"></param>
        /// <param name="checkDuration"></param>
        /// <returns></returns>
        public static bool UnstuckChecker(Vector3 vMyCurrentPosition, int checkDuration = 3000)
        {
            // set checkDuration to 30 sec while in town or vendoring, just to avoid annoyances
            if (ZetaDia.Me.IsInTown || GilesTrinity.ForceVendorRunASAP || Zeta.CommonBot.Logic.BrainBehavior.IsVendoring)
            {
                checkDuration = 15000;
            }

            // Keep checking distance changes every 3 seconds
            if (DateTime.Now.Subtract(TimeLastRecordedPosition).TotalMilliseconds >= checkDuration)
            {
                if (ZetaDia.Me.IsInTown && (UIElements.VendorWindow.IsVisible || UIElements.SalvageWindow.IsVisible))
                {
                    UnStuckCheckerLastResult = false;
                    return(UnStuckCheckerLastResult);
                }

                if (checkDuration >= 3000)
                {
                    TimeLastRecordedPosition = DateTime.Now;
                }

                ProfileBehavior c = null;

                try
                {
                    if (ProfileManager.CurrentProfileBehavior != null)
                    {
                        c = ProfileManager.CurrentProfileBehavior;
                    }
                }
                catch { }

                if (c != null && c.GetType() == typeof(WaitTimerTag))
                {
                    vOldPosition = Vector3.Zero;
                    GoldInactivity.ResetCheckGold();
                    UnStuckCheckerLastResult = false;
                    return(UnStuckCheckerLastResult);
                }

                Zeta.Internals.UIElement vendorWindow = Zeta.Internals.UIElements.VendorWindow;

                // We're not stuck if we're doing stuff!
                if (ZetaDia.Me.IsInConversation || ZetaDia.IsPlayingCutscene || ZetaDia.IsLoadingWorld || (vendorWindow.IsValid && vendorWindow.IsVisible))
                {
                    vOldPosition = Vector3.Zero;
                    GoldInactivity.ResetCheckGold();
                    UnStuckCheckerLastResult = false;
                    return(UnStuckCheckerLastResult);
                }

                AnimationState aState = ZetaDia.Me.CommonData.AnimationState;
                // We're not stuck if we're doing stuff!
                if (aState == AnimationState.Attacking ||
                    aState == AnimationState.Casting ||
                    aState == AnimationState.Channeling)
                {
                    vOldPosition = Vector3.Zero;
                    GoldInactivity.ResetCheckGold();
                    UnStuckCheckerLastResult = false;
                    return(UnStuckCheckerLastResult);
                }

                if (vOldPosition != Vector3.Zero && vOldPosition.Distance(vMyCurrentPosition) <= 4f)
                {
                    UnStuckCheckerLastResult = true;
                    return(UnStuckCheckerLastResult);
                }

                if (checkDuration >= 3000)
                {
                    vOldPosition = vMyCurrentPosition;
                }
            }

            // Return last result if within the specified timeframe
            return(false);
        }
Esempio n. 29
0
        internal static CacheObject GetInteractiveCachedObject(ProfileBehavior tag)
        {
            Type TagType = tag.GetType();
            if (InteractiveTags.Contains(TagType))
            {
                if (TagType == typeof(UseWaypointTag))
                {
                    UseWaypointTag tagWP = (UseWaypointTag)tag;
                    var WaypointObjects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == 6442);
                    foreach (CacheObject item in WaypointObjects)
                    {
                        if (item.Position.Distance(tagWP.Position) < 100f)
                        {
                            //Found matching waypoint object!
                            return item;
                        }
                    }
                }
                else if (TagType == typeof(UseObjectTag))
                {
                    UseObjectTag tagUseObj = (UseObjectTag)tag;
                    if (tagUseObj.ActorId > 0)
                    {//Using SNOID..
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == tagUseObj.ActorId);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return item;
                        }

                    }
                    else
                    {//use position to match object
                        Vector3 tagPosition = tagUseObj.Position;
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.Position.Distance(tagPosition) <= 100f);
                        foreach (CacheObject item in Objects)
                        {
                            //Found matching object!
                            return item;
                        }
                    }
                }
                else if (TagType == typeof(UsePortalTag))
                {
                    UsePortalTag tagUsePortal = (UsePortalTag)tag;
                    if (tagUsePortal.ActorId > 0)
                    {//Using SNOID..
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.SNOID == tagUsePortal.ActorId);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return item;
                        }

                    }
                    else
                    {//use position to match object
                        Vector3 tagPosition = tagUsePortal.Position;
                        var Objects = Bot.Game.Profile.InteractableObjectCache.Values.Where(obj => obj.Position.Distance(tagPosition) <= 100f);
                        foreach (CacheObject item in Objects.OrderBy(obj => obj.Position.Distance(Bot.Character.Data.Position)))
                        {
                            //Found matching object!
                            return item;
                        }
                    }
                }
            }

            return null;
        }
Esempio n. 30
0
 public ExCoroutineAction(Func <object, Task> taskProducer, ProfileBehavior behavior)
     : this(obj => new Coroutine(() => taskProducer(obj)), behavior)
 {
 }
 public static void Queue(ProfileBehavior profileBehavior, ShouldRunCondition condition)
 {
     Queue(new List <ProfileBehavior> {
         profileBehavior
     }, condition);
 }
Esempio n. 32
0
        /// <summary>
        /// Determines whether or not to leave the game based on the gold inactivity timer
        /// </summary>
        /// <returns></returns>
        internal static bool GoldInactive()
        {
            if (!GilesTrinity.Settings.Advanced.GoldInactivityEnabled)
            {
                // timer isn't enabled so move along!
                ResetCheckGold();
                return(false);
            }
            try
            {
                if (!ZetaDia.IsInGame)
                {
                    ResetCheckGold(); //If not in game, reset the timer
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Not in game, gold inactivity reset", 0);
                    return(false);
                }
                if (ZetaDia.IsLoadingWorld)
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Loading world, gold inactivity reset", 0);
                    return(false);
                }
                if ((DateTime.Now.Subtract(lastCheckBag).TotalSeconds < 5))
                {
                    return(false);
                }

                // sometimes bosses take a LONG time
                if (GilesTrinity.CurrentTarget != null && GilesTrinity.CurrentTarget.IsBoss)
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Current target is boss, gold inactivity reset", 0);
                    ResetCheckGold();
                    return(false);
                }

                if (TownRun.IsTryingToTownPortal())
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Trying to town portal, gold inactivity reset", 0);
                    ResetCheckGold();
                    return(false);
                }
                // Don't go inactive on WaitTimer tags
                ProfileBehavior c = null;
                try
                {
                    if (ProfileManager.CurrentProfileBehavior != null)
                    {
                        c = ProfileManager.CurrentProfileBehavior;
                    }
                }
                catch { }
                if (c != null && c.GetType() == typeof(WaitTimerTag))
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Wait timer tag, gold inactivity reset", 0);
                    ResetCheckGold();
                    return(false);
                }



                lastCheckBag = DateTime.Now;
                int currentcoin = GilesTrinity.PlayerStatus.Coinage;

                if (currentcoin != lastKnowCoin && currentcoin != 0)
                {
                    lastRefreshCoin = DateTime.Now;
                    lastKnowCoin    = currentcoin;
                }
                int notpickupgoldsec = Convert.ToInt32(DateTime.Now.Subtract(lastRefreshCoin).TotalSeconds);
                if (notpickupgoldsec >= GilesTrinity.Settings.Advanced.GoldInactivityTimer)
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.UserInformation, "Gold inactivity after {0}s. Sending abort.", notpickupgoldsec);
                    lastRefreshCoin  = DateTime.Now;
                    lastKnowCoin     = currentcoin;
                    notpickupgoldsec = 0;
                    return(true);
                }
                else if (notpickupgoldsec > 0)
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Gold unchanged for {0}s", notpickupgoldsec);
                }
            }
            catch (Exception e)
            {
                DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, e.Message);
            }
            DbHelper.Log(TrinityLogLevel.Normal, LogCategory.GlobalHandler, "Gold inactivity error - no result", 0);
            return(false);
        }
Esempio n. 33
0
 public static void ResetChildren(this ProfileBehavior behavior)
 {
     behavior?.GetChildren()?.ForEach(b => b?.ResetCachedDone());
 }
Esempio n. 34
0
		public ExCoroutineAction(Func<object, CoroutineTask> taskProducer, ProfileBehavior behavior)
			: this(obj => taskProducer(obj).Run(), behavior) {}
Esempio n. 35
0
		public ExCoroutineAction(Func<object, Task> taskProducer, ProfileBehavior behavior)
			: this(obj => new Coroutine(() => taskProducer(obj)), behavior) {}
Esempio n. 36
0
        ///<summary>
        ///Tracks Current Profile Behavior and sets IsRunningOOCBehavior depending on the current Type of behavior.
        ///</summary>
        internal void CheckCurrentProfileBehavior()
        {
            if (DateTime.Now.Subtract(LastProfileBehaviorCheck).TotalMilliseconds > 450)
            {
                LastProfileBehaviorCheck = DateTime.Now;

                if (currentProfileBehavior == null
                     || ProfileManager.CurrentProfileBehavior != null
                     && ProfileManager.CurrentProfileBehavior.Behavior != null
                     && currentProfileBehavior.Behavior.Guid != ProfileManager.CurrentProfileBehavior.Behavior.Guid)
                {
                    currentProfileBehavior = ProfileManager.CurrentProfileBehavior;
                    Logger.Write(LogLevel.Event, "Profile Behavior Changed To {0}", currentProfileBehavior.GetType().ToString());

                    Type profileTagType = currentProfileBehavior.GetType();
                    if (oocDBTags.Contains(profileTagType))
                    {
                        if (InteractiveTags.Contains(profileTagType))
                        {
                            ProfileBehaviorIsOOCInteractive = true;
                            Logger.DBLog.DebugFormat("Interactable Profile Tag!");

                            InteractableCachedObject = GetInteractiveCachedObject(currentProfileBehavior);
                            if (InteractableCachedObject != null)
                                Logger.DBLog.DebugFormat("Found Cached Interactable Server Object");

                        }
                        else
                        {
                            ProfileBehaviorIsOOCInteractive = false;
                            InteractableCachedObject = null;
                        }

                        Logger.DBLog.DebugFormat("Current Profile Behavior has enabled OOC Behavior.");
                        IsRunningOOCBehavior = true;
                    }
                    else
                    {
                        ProfileBehaviorIsOOCInteractive = false;
                        InteractableCachedObject = null;
                        IsRunningOOCBehavior = false;
                    }
                }

            }
        }
Esempio n. 37
0
 public ExCoroutineAction(Func <object, Task <bool> > taskProducer, ProfileBehavior behavior)
     : this(CreateCoroutineProducer(taskProducer), behavior)
 {
     TaskProducer = taskProducer;
 }
Esempio n. 38
0
        /// <summary>
        /// Prepare ProfileBehavior to be executed as TreeSharp Composite
        /// </summary>
        /// <param name="behavior"></param>
        /// <returns></returns>
        public static Composite Run(this ProfileBehavior behavior)
        {
            var type = behavior.GetType();

            if (behavior is IEnhancedProfileBehavior)
            {
                return((behavior as IEnhancedProfileBehavior).RunEnhanced());
            }

            if (type == typeof(LoadProfileTag))
            {
                return((behavior as LoadProfileTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(LeaveGameTag))
            {
                return((behavior as LeaveGameTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(LogMessageTag))
            {
                return((behavior as LogMessageTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(WaitTimerTag))
            {
                return((behavior as WaitTimerTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(UseWaypointTag))
            {
                return((behavior as UseWaypointTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(ToggleTargetingTag))
            {
                return((behavior as ToggleTargetingTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(IfTag))
            {
                return((behavior as IfTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(WhileTag))
            {
                return((behavior as WhileTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(UseObjectTag))
            {
                return((behavior as UseObjectTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(UsePowerTag))
            {
                return((behavior as UsePowerTag).ToEnhanced().RunEnhanced());
            }

            if (type == typeof(WaitWhileTag))
            {
                return((behavior as WaitWhileTag).ToEnhanced().RunEnhanced());
            }

            Logger.Warn("You attempted to run a tag ({0}) that can't be converted to IEnhancedProfileBehavior ", behavior.GetType());

            return(new Action(ret => RunStatus.Failure));
        }
Esempio n. 39
0
		public ExCoroutineAction(Func<object, Task<bool>> taskProducer, ProfileBehavior behavior)
			: this(CreateCoroutineProducer(taskProducer), behavior)
		{
			TaskProducer = taskProducer;
		}