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); }
public void AddAction(ITrackingAction action) { lock (actionLocker) { LastActions.Insert(0, action); RevertedActions.Clear(); } }
public void Dispose() { if (LastActions.Count != 0) { Parent?.AddAction(new MultiTrackingAction(LastActions.Reduce().ToList())); } onDispose(this); GC.SuppressFinalize(this); }
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(); } }
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); } }
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); }
private void ClearTrackingItems() { LastActions.Clear(); RevertedActions.Clear(); }