public void Subtract(DRTimeComponent component, int value) { if (component == DRTimeComponent.MONTH || component == DRTimeComponent.DAY) { value--; } time -= MULTIPLIERS[(int)component] * value; }
/// <summary> /// Sets a particular Time Component to a particular value. /// If the value is 'too large' it will trickle over /// </summary> /// <param name="component"></param> public void SetTimeComponent(DRTimeComponent component, int value) { if (component == DRTimeComponent.DAY || component == DRTimeComponent.MONTH) { value--; //Because people start days and months at 1 } //First determine the current value long currentValue = GetTimeComponent(component); //Multiply that by the multiplier currentValue *= MULTIPLIERS[(int)component]; time -= currentValue; //And replace it with our new value time += MULTIPLIERS[(int)component] * value; }
/// <summary> /// Adds a time component to the total /// </summary> /// <param name="component"></param> /// <param name="value"></param> public void Add(DRTimeComponent component, int value) { if (component == DRTimeComponent.MONTH || component == DRTimeComponent.DAY) { value--; } //Store Minute, Month and Year int minute = this.GetTimeComponent(DRTimeComponent.MINUTE); int month = this.GetTimeComponent(DRTimeComponent.MONTH); int day = this.GetTimeComponent(DRTimeComponent.DAY); time += MULTIPLIERS[(int)component] * value; if (minute != this.GetTimeComponent(DRTimeComponent.MINUTE)) { if (MinuteChanged != null) { //Fire the event MinuteChanged(this, null); } } if (month != this.GetTimeComponent(DRTimeComponent.MONTH)) { if (MonthChanged != null) { MonthChanged(this, null); } } if (day != this.GetTimeComponent(DRTimeComponent.DAY)) { if (DayChanged != null) { //Fire the event DayChanged(this, null); } } }
/// <summary> /// Gets some part of the time component based on the multiplier /// </summary> /// <param name="multiplier"></param> /// <returns></returns> public int GetTimeComponent(DRTimeComponent component) { //First we divide time by the multiplier long dividedTime = Math.Abs( time / MULTIPLIERS[(int) component]); int returnValue = 0; //Then, except for years, remainder divide with the multiplier after it if ((int)component >= MULTIPLIERS.Length -1) { return (int)dividedTime; } else { returnValue = (int) (dividedTime % (MULTIPLIERS[(int)component + 1] / MULTIPLIERS[(int)component])); } if (component == DRTimeComponent.DAY || component == DRTimeComponent.MONTH) { //Increment by 1 return returnValue + 1; } return returnValue; }
/// <summary> /// Incremements the Game Time by an amount of minutes /// </summary> /// <param name="minutes"></param> public static void IncrementGameTime(DRTimeComponent timeComponent, int value) { _universeTime.Add(timeComponent, value); }