Esempio n. 1
0
        private void UpdateClock(bool bigUpdate = false, double daysSinceLastUpdate = 0)
        {
            if (txtTime == null)
            {
                return;
            }
            string timeStr = dndTimeClock.Time.ToString("H:mm:ss") + ", " + dndTimeClock.AsDndDateString();

            if (dndTimeClock.InCombat)
            {
                timeStr = " " + timeStr + " ";
            }

            if (txtTime.Text == timeStr)
            {
                return;
            }

            txtTime.Text = timeStr;

            TimeSpan timeIntoToday      = dndTimeClock.Time - new DateTime(dndTimeClock.Time.Year, dndTimeClock.Time.Month, dndTimeClock.Time.Day);
            double   percentageRotation = 360 * timeIntoToday.TotalMinutes / TimeSpan.FromDays(1).TotalMinutes;

            string afterSpinMp3 = null;

            if (daysSinceLastUpdate > 0.08)              // Short rest or greater
            {
                if (timeIntoToday.TotalHours < 2 || timeIntoToday.TotalHours > 22)
                {
                    afterSpinMp3 = "midnightWolf";
                }
                else if (timeIntoToday.TotalHours > 4 && timeIntoToday.TotalHours < 8)
                {
                    afterSpinMp3 = "morningRooster";
                }
                else if (timeIntoToday.TotalHours > 10 && timeIntoToday.TotalHours < 14)
                {
                    afterSpinMp3 = "birdsNoon";
                }
                else if (timeIntoToday.TotalHours > 16 && timeIntoToday.TotalHours < 20)
                {
                    if (new Random().Next(100) > 50)
                    {
                        afterSpinMp3 = "eveningCrickets";
                    }
                    else
                    {
                        afterSpinMp3 = "lateEveningFrogs";
                    }
                }
                if (lastAmbientSoundPlayed == afterSpinMp3)                  // prevent the same sound from being played twice in a row.
                {
                    afterSpinMp3 = null;
                }
                else
                {
                    lastAmbientSoundPlayed = afterSpinMp3;
                }
            }

            ClockDto clockDto = new ClockDto()
            {
                Time         = timeStr,
                BigUpdate    = bigUpdate,
                Rotation     = percentageRotation,
                InCombat     = dndTimeClock.InCombat,
                FullSpins    = daysSinceLastUpdate,
                AfterSpinMp3 = afterSpinMp3
            };

            string serializedObject = JsonConvert.SerializeObject(clockDto);

            HubtasticBaseStation.UpdateClock(serializedObject);
        }
        public void TestDateStringConversionDayOfYearPlusLeapYears()
        {
            DndTimeClock dndTimeClock = new DndTimeClock();

            int aLeapYear    = 1376;
            int aNonLeapYear = 1374;

            dndTimeClock.SetTime(aLeapYear, 214);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet"));

            dndTimeClock.SetTime(aLeapYear + 1, 214);
            Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet"));
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis"));

            dndTimeClock.SetTime(aLeapYear + 2, 214);
            Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet"));
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis"));

            dndTimeClock.SetTime(aLeapYear + 3, 214);
            Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet"));
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis"));

            dndTimeClock.SetTime(aLeapYear + 4, 214);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet"));
            Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis"));

            dndTimeClock.SetTime(aNonLeapYear, 1);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Hammer"));

            dndTimeClock.SetTime(aNonLeapYear, 122);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Greengrass"));

            dndTimeClock.SetTime(aLeapYear, 122);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Greengrass"));

            dndTimeClock.SetTime(aNonLeapYear, 213);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Midsummer"));

            dndTimeClock.SetTime(aLeapYear, 213);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Midsummer"));

            dndTimeClock.SetTime(aNonLeapYear, 274);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Highharvestide"));

            dndTimeClock.SetTime(aLeapYear, 275);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Highharvestide"));

            dndTimeClock.SetTime(aNonLeapYear, 335);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("The Feast of the Moon"));

            dndTimeClock.SetTime(aLeapYear, 336);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("The Feast of the Moon"));

            dndTimeClock.SetTime(aNonLeapYear, 295);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("21st of Marpenoth"));

            dndTimeClock.SetTime(aLeapYear, 296);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("21st of Marpenoth"));

            dndTimeClock.SetTime(aLeapYear, 366);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("30th of Nightal"));

            dndTimeClock.SetTime(aNonLeapYear, 365);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("30th of Nightal"));

            dndTimeClock.SetTime(aLeapYear, 365);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("29th of Nightal"));

            dndTimeClock.SetTime(aNonLeapYear, 364);
            Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("29th of Nightal"));
        }