private static SortedSet <int> ComputeValues(Object unitParameter, ScheduleUnit unit) { if (unitParameter.IsInt()) { var resultSet = new SortedSet <int>(); resultSet.Add(unitParameter.AsInt()); return(resultSet); } // cron parameters not handled as number sets if (unitParameter is CronParameter) { return(null); } var numberSet = (NumberSetParameter)unitParameter; if (numberSet.IsWildcard(unit.Min(), unit.Max())) { return(null); } var result = numberSet.GetValuesInRange(unit.Min(), unit.Max()); var resultSorted = new SortedSet <int>(); resultSorted.AddAll(result); return(resultSorted); }
/// <summary> /// 创建日程单元 /// </summary> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="cycleType">循环类型</param> /// <param name="week">星期 cycleType为周循环有效</param> /// <returns></returns> public static ScheduleUnit Create(DateTime start, DateTime end , ScheduleCycleType cycleType = ScheduleCycleType.None, int week = 0) { ScheduleUnit unit = new ScheduleUnit(); return((unit.UpdateData(start, end, cycleType, week)) ? unit : null); }
private static ICollection<int> ComputeValues( object unitParameter, ScheduleUnit unit) { ICollection<int> result; if (unitParameter is int) { result = new SortedSet<int>(); result.Add((int) unitParameter); return result; } // cron parameters not handled as number sets if (unitParameter is CronParameter) { return null; } var numberSet = (NumberSetParameter) unitParameter; if (numberSet.IsWildcard(unit.Min(), unit.Max())) { return null; } result = numberSet.GetValuesInRange(unit.Min(), unit.Max()); var resultSorted = new SortedSet<int>(); resultSorted.AddAll(result); return resultSorted; }
/// <summary> Returns minimum valid value for the unit.</summary> /// <returns> maximum unit value /// </returns> public static int Max(this ScheduleUnit value) { switch (value) { case ScheduleUnit.MICROSECONDS: return(999); case ScheduleUnit.MILLISECONDS: return(999); case ScheduleUnit.SECONDS: return(59); case ScheduleUnit.MINUTES: return(59); case ScheduleUnit.HOURS: return(23); case ScheduleUnit.DAYS_OF_MONTH: return(31); case ScheduleUnit.MONTHS: return(12); case ScheduleUnit.DAYS_OF_WEEK: return(6); default: throw new ArgumentOutOfRangeException(nameof(value), value, null); } }
/// <summary>For unit testing, add a single value, changing wildcards to value sets. </summary> /// <param name="element">to add</param> /// <param name="value">to add</param> public void AddValue(ScheduleUnit element, int value) { SortedSet <int> set = _unitValues.Get(element); if (set == null) { set = new SortedSet <int>(); _unitValues.Put(element, set); } set.Add(value); }
/// <summary> /// 构造函数 /// </summary> /// <param name="scheduleId"></param> public ScheduleLocalData(uint scheduleId) { this.scheduleId = scheduleId; table.ScheduleDataBase scheData = TabData; if (null != scheData) { m_scheduleUint = ScheduleUnit.Create(new System.DateTime((int)scheData.startYear, (int)scheData.startMonth, (int)scheData.startDay , (int)scheData.startHour, (int)scheData.startMin, 0) , new System.DateTime((int)scheData.endYear, (int)scheData.endMonth, (int)scheData.endDay , (int)scheData.endHour, (int)scheData.endMin, 0) , CycleType , (int)scheData.week); } }
private void OnNPCSceneLoad() { instancesParent = GameObject.FindGameObjectWithTag(Tags.InstancesParent).transform; spawnsParent = GameObject.FindGameObjectWithTag(Tags.SpawnPointParent).transform; WeekDay day = TimeManager.Instance.currentWeekDay; TimeSlot slot = TimeManager.Instance.currentTimeslot; if (!Enum.TryParse <SceneName>(SceneController.Instance.CurrentScene, out SceneName sceneName)) { return; } foreach (NPCData data in npcDataDictionary.Values) { ScheduleUnit unit = data.currentSchedule.GetScheduleUnit(day, slot); if (unit != null && unit.sceneName == sceneName) { Vector3 pos = spawnsParent.Find(unit.spawnName).position; Instantiate <NPC>(NPCPrefab, pos, Quaternion.identity, instancesParent); } } }
/// <summary> /// 是否dateTime在日程单元内 /// </summary> /// <param name="dateTime"></param> /// <param name="leftSeconds">>如果在日程内leftseonds表示本次日程剩余时间, /// 反之距离下次日程时间,如果为0:表示不在日程内并且没有下个日程</param> /// <returns></returns> public bool IsInSchedule(DateTime dateTime, out long leftSeconds) { return(ScheduleUnit.IsInCycleDateTme(start, end, dateTime, out leftSeconds, cycleType, (DayOfWeek)ValidWeek)); }