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 IdleObject(Component IdleComponent) { if (IdleComponent is IIdleAction) { this.IdleInterface = IdleComponent as IIdleAction; this.gameObject = IdleComponent.gameObject; } }