Exemple #1
0
        public bool Tick(bool autopilotEnabled)
        {
            if (ExecuteUntil > DateTime.UtcNow && CurrentAction != null)
            {
                CurrentAction.Execute();
                return(true);
            }

            if (LastActionExecuted + Cooldown <= DateTime.UtcNow)
            {
                IEnumerable <IIdleAction> filteredActions = IdleActions.Where(e => (!e.AutopilotOnly || autopilotEnabled) && !LastActions.Any(e => e.Value == e.GetType()) || LastActions.Where(x => x.Value == e.GetType() && (DateTime.UtcNow - x.Key).TotalMilliseconds > Rnd.Next(CurrentAction.MinCooldown, CurrentAction.MaxCooldown)).Any());

                if (filteredActions.Any())
                {
                    CurrentAction = filteredActions.ElementAtOrDefault(Rnd.Next(0, filteredActions.Count()));

                    if (CurrentAction != null && CurrentAction.Enter())
                    {
                        LastActionExecuted = DateTime.UtcNow;
                        Cooldown           = TimeSpan.FromMilliseconds(Rnd.Next(MinCooldown, MaxCooldown));
                        ExecuteUntil       = LastActionExecuted + TimeSpan.FromMilliseconds(Rnd.Next(CurrentAction.MinDuration, CurrentAction.MaxDuration));

                        LastActions.Add(new KeyValuePair <DateTime, Type>(LastActionExecuted, CurrentAction.GetType()));

                        CurrentAction.Execute();
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
 public void AddAction(ITrackingAction action)
 {
     lock (actionLocker)
     {
         LastActions.Insert(0, action);
         RevertedActions.Clear();
     }
 }
Exemple #3
0
        public void Dispose()
        {
            if (LastActions.Count != 0)
            {
                Parent?.AddAction(new MultiTrackingAction(LastActions.Reduce().ToList()));
            }

            onDispose(this);

            GC.SuppressFinalize(this);
        }
Exemple #4
0
        public void AddAction(Func <ITrackingAction> action)
        {
            lock (actionLocker)
            {
                using (var logger = new TrackingLoggerScope(Logs, "Add"))
                {
                    var newItem = action();
                    logger.Type = newItem.GetType().Name;
                    LastActions.Insert(0, newItem);
                }

                RevertedActions.Clear();
            }
        }
Exemple #5
0
        public void Remake()
        {
            lock (actionLocker)
            {
                var lastItem = RevertedActions.FirstOrDefault();

                if (lastItem == null)
                {
                    return;
                }

                using (var logger = new TrackingLoggerScope(Logs, "Remake", lastItem.GetType().Name))
                    lastItem.Apply();

                RevertedActions.Remove(lastItem);
                LastActions.Insert(0, lastItem);
            }
        }
Exemple #6
0
        public bool Tick(bool autopilotEnabled)
        {
            if (ExecuteUntil > DateTime.UtcNow && CurrentAction != null)
            {
                CurrentAction.Execute();
                return(true);
            }

            // cleanup old events
            LastActions.RemoveAll(e => e.Key < e.Value.Cooldown);

            if (LastActionExecuted + Cooldown <= DateTime.UtcNow)
            {
                IEnumerable <IIdleAction> filteredActions = IdleActions.Where
                                                            (
                    e => Config.IdleActionsEnabled.TryGetValue(e.ToString(), out bool b) && b &&
                    (!e.AutopilotOnly || autopilotEnabled) &&
                    DateTime.Now > e.Cooldown
                                                            );

                if (filteredActions.Any())
                {
                    CurrentAction = filteredActions.ElementAtOrDefault(Rnd.Next(0, filteredActions.Count()));

                    if (CurrentAction != null && CurrentAction.Enter())
                    {
                        LastActionExecuted = DateTime.UtcNow;

                        Cooldown = TimeSpan.FromMilliseconds(Rnd.Next(MinActionCooldown, MaxActionCooldown));
                        CurrentAction.Cooldown = DateTime.Now + TimeSpan.FromMilliseconds(Rnd.Next(CurrentAction.MinCooldown, CurrentAction.MaxCooldown));
                        ExecuteUntil           = LastActionExecuted + TimeSpan.FromMilliseconds(Rnd.Next(CurrentAction.MinDuration, CurrentAction.MaxDuration));

                        LastActions.Add(new(LastActionExecuted, CurrentAction));

                        CurrentAction.Execute();
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #7
0
 private void ClearTrackingItems()
 {
     LastActions.Clear();
     RevertedActions.Clear();
 }