Ejemplo n.º 1
0
        public static HybrasylTime ConvertToHybrasyl(DateTime datetime)
        {
            if (datetime.Ticks < World.StartDate.Ticks)
            {
                throw new ArgumentException("Date passed occurs before known time", nameof(datetime));
            }

            var hybrasylTime = new HybrasylTime();
            var thisAge      = Game.Config.Time.Ages.FirstOrDefault(age => age.DateInAge(datetime));
            var timeElapsed  = datetime.Ticks - World.StartDate.Ticks;

            if (thisAge == null)
            {
                hybrasylTime.Age  = DefaultAge;
                hybrasylTime.Year = DefaultYear;
            }
            else
            {
                hybrasylTime.Age  = thisAge.Name;
                timeElapsed       = datetime.Ticks - thisAge.StartDate.Ticks;
                hybrasylTime.Year = thisAge.StartYear;
            }

            hybrasylTime.AdvanceDateFromTerranTicks(timeElapsed);
            return(hybrasylTime);
        }
Ejemplo n.º 2
0
        public static HybrasylTime Now()
        {
            var hybrasylTime = new HybrasylTime();
            var terranNow    = DateTime.Now;
            var timeElapsed  = DateTime.Now.Ticks - World.StartDate.Ticks;

            if (Game.Config.Time.Ages.Count > 0)
            {
                var currentAge = Game.Config.Time.Ages.First(age => age.DateInAge(terranNow));
                if (currentAge == null)
                {
                    // Age configuration is screwy, simply return default age
                    Logger.ErrorFormat("Age configuration is nonsensical, using default age");
                }
                else
                {
                    // Calculate the time that has passed from the start of the current age, to now
                    timeElapsed      = terranNow.Ticks - currentAge.StartDate.Ticks;
                    hybrasylTime.Age = currentAge.Name;
                    if (currentAge.StartYear != 1)
                    {
                        hybrasylTime.Year = currentAge.StartYear;
                    }
                }
            }
            else
            {
                hybrasylTime.Age = Game.Config.Time.ServerStart.DefaultAge != string.Empty
                    ? Game.Config.Time.ServerStart.DefaultAge
                    : DefaultAge;

                if (Game.Config.Time.ServerStart.DefaultYear != 1)
                {
                    hybrasylTime.Year += Game.Config.Time.ServerStart.DefaultYear;
                }
            }

            hybrasylTime.AdvanceDateFromTerranTicks(timeElapsed);

            return(hybrasylTime);
        }