Exemplo 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);
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            var    aislingDate  = HybrasylTime.ConvertToHybrasyl(Timestamp != LastUpdated ? Timestamp : LastUpdated);
            var    returnstring = Text;
            string markDate     = "";

            if (DisplayTimestamp && DisplaySeason)
            {
                markDate = $"{aislingDate.AgeName} {aislingDate.Year}, {aislingDate.Season}";
            }
            else if (DisplayTimestamp)
            {
                markDate = $"{aislingDate.AgeName} {aislingDate.Year}";
            }

            var maxLength = 254 - 15 - markDate.Length;

            if (Text.Length > maxLength)
            {
                returnstring = Text.Substring(0, maxLength);
            }

            if (Quantity > 0)
            {
                returnstring = $"{returnstring} ({Quantity})";
            }
            if (!Public)
            {
                returnstring = $" - {returnstring}";
            }

            returnstring = $"{returnstring} - {markDate}";
            return(returnstring);
        }
Exemplo n.º 3
0
        public override string ToString()
        {
            var aislingDate  = HybrasylTime.ConvertToHybrasyl(Created != LastUpdated ? Created : LastUpdated);
            var returnstring = Text;
            var markDate     = $"{aislingDate.Age} {aislingDate.Year}, {aislingDate.Season}";

            var maxLength = 254 - 15 - markDate.Length;

            if (Text.Length > maxLength)
            {
                returnstring = Text.Substring(0, maxLength);
            }

            if (Quantity != 0)
            {
                returnstring = $"{returnstring} ({Quantity})";
            }
            if (!Public)
            {
                returnstring = $" - {returnstring}";
            }

            returnstring = $"{returnstring} - {markDate}";
            return(returnstring);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static DateTime ConvertToTerran(HybrasylTime hybrasyltime)
        {
            var thisAge = Game.Config.Time?.Ages?.Where(age => age.Name == hybrasyltime.Age);

            return(thisAge.Count() > 0 ? new DateTime(thisAge.First().StartDate.Ticks + hybrasyltime.TerranTicks) : new DateTime(World.StartDate.Ticks + hybrasyltime.TerranTicks));
        }