Exemplo n.º 1
0
        public IEnumerator OutOfGameTime_UpdatesOnReload(
            [ValueSource(nameof(RealSeconds))] double secondsOutOfGame
            )
        {
            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_UpdatesOnReload));

            //Go to the next frame and then save (to make sure we "discard" the time spent creating the save file)
            yield return(null);

            fortuneFountainSaveData.Save(false);

            //record the time we saved at
            var saveTime = FrameTime.Now;

            var outOfGameTime = TimeSpan.FromSeconds(secondsOutOfGame);

            yield return(TestUtils.WaitFor(outOfGameTime));

            fortuneFountainSaveData.Reload();

            //record the time we loaded at
            var loadTime = FrameTime.Now;

            //make sure that the OOG-time is the difference between loading and saving
            //NOTE: This value will always be slightly larger than secondsOutOfGame due to the time actually spend saving & loading, etc.
            Assert.That(fortuneFountainSaveData,
                        Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(loadTime - saveTime));
        }
Exemplo n.º 2
0
        public void TestSerializeThrowables()
        {
            const string            nickName = nameof(TestSerializeThrowables);
            FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nickName);

            for (int i = 0; i < ValuableDatabase.ValuableTypes.Length; i++)
            {
                // copying `i` into `index` inside the loop 'cus otherwise lambdas can get messed up
                var index        = i;
                var karmaValue   = Random.Range(1, 25);
                var valuableType = ValuableDatabase.ValuableTypes[index];
                Log($"Grabbing a {valuableType} with a value of {karmaValue}");
                fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(valuableType, karmaValue));
                fortuneFountainSaveData.Save(useReSaveDelay: false);

                Log($"before loading throwables:", fortuneFountainSaveData.Hand.Throwables.JoinLines());

                //load the save data we created
                FortuneFountainSaveData loadedSaveData = FortuneFountainSaveData.Load(nickName);

                Log($"original SaveData:", fortuneFountainSaveData);
                Log($"loaded SaveData:", loadedSaveData);

                AssertAll.Of(
                    () => Assert.That(loadedSaveData.ToJson(), Contains.Substring($"\"{nameof(Hand._throwables)}\":")),
                    () => Assert.That(loadedSaveData.Hand.Throwables.Count, Is.EqualTo(index + 1)),
                    () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable,
                                      Has.Property(nameof(ThrowableValuable.ValuableType)).EqualTo(valuableType)),
                    () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable,
                                      Has.Property(nameof(ThrowableValuable.PresentValue)).EqualTo(karmaValue))
                    );
            }
        }
Exemplo n.º 3
0
        public IEnumerator OutOfGameTime_DoesNotUpdateOnSave(
            [ValueSource(nameof(RealSeconds))] double secondsOutOfGame
            )
        {
            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_DoesNotUpdateOnSave));

            var outOfGameSpan = TimeSpan.FromSeconds(secondsOutOfGame);

            //Set the OutOfGameTimeSinceLastThrow (using reflection since the setter is private)
            fortuneFountainSaveData.GetType().GetProperty(nameof(FortuneFountainSaveData.OutOfGameTimeSinceLastThrow))
            ?.SetValue(fortuneFountainSaveData, outOfGameSpan);

            Assert.That(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow, Is.EqualTo(outOfGameSpan));

            const int repetitions = 5;

            for (int rep = 0; rep < repetitions; rep++)
            {
                yield return(new WaitForSecondsRealtime(0.01f));

                fortuneFountainSaveData.Save(false);

                Assert.That(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow, Is.EqualTo(outOfGameSpan),
                            $"[{nameof(rep)}: {rep}] The {nameof(FortuneFountainSaveData.OutOfGameTimeSinceLastThrow)} should not have changed when we {nameof(FortuneFountainSaveData.Save)}-ed!");
            }
        }
Exemplo n.º 4
0
        public void ThrowEmptiesHand()
        {
            FortuneFountainSaveData fortuneFountainSaveData = SimpleSaveData(nameof(ThrowEmptiesHand));

            fortuneFountainSaveData.Hand.Throw();

            Assert.That(fortuneFountainSaveData.Hand.Throwables, Is.Empty);
        }
Exemplo n.º 5
0
        public void TestSerializeEmptyHand()
        {
            const string            nickName = nameof(TestSerializeEmptyHand);
            FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nickName);

            LogUtils.Log(fortuneFountainSaveData);

            Assert.That(fortuneFountainSaveData.ToJson(), Contains.Substring($"\"{nameof(Hand)}\": {{"));
        }
Exemplo n.º 6
0
        public void ThrowSingleRemovesThrowable()
        {
            FortuneFountainSaveData fortuneFountainSaveData = SimpleSaveData(nameof(ThrowSingleRemovesThrowable));

            var toBeThrown = fortuneFountainSaveData.Hand.Throwables[0];

            toBeThrown.Flick();

            CollectionAssert.DoesNotContain(fortuneFountainSaveData.Hand.Throwables, toBeThrown);
        }
Exemplo n.º 7
0
        private static FortuneFountainSaveData SimpleSaveData(string nickName)
        {
            FortuneFountainSaveData fortuneFountainSaveData = new FortuneFountainSaveData(nickName);

            fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(ValuableType.Coin, 10));
            fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(ValuableType.Coin, 20));
            fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(ValuableType.Coin, 30));

            Assume.That(fortuneFountainSaveData.Hand.Throwables, Is.Not.Empty);

            return(fortuneFountainSaveData);
        }
Exemplo n.º 8
0
        public void TestInGameTimeSinceLastThrowWithoutSaving(
            [ValueSource(nameof(Seconds))] double secondsInGame
            )
        {
            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(TestInGameTimeSinceLastThrowWithoutSaving));

            var inGameTime = TimeSpan.FromSeconds(secondsInGame);

            fortuneFountainSaveData.Hand.LastThrowTime = FrameTime.Now - inGameTime;
            Assert.That(fortuneFountainSaveData.InGameTimeSinceLastThrow,
                        Is.InRange(inGameTime.Multiply(0.999), inGameTime.Multiply(1.001)));
        }
Exemplo n.º 9
0
        public void ThrowOneTwice()
        {
            var save1 = new FortuneFountainSaveData(nameof(ThrowOneTwice));

            save1.Hand.AddToHand(new ThrowableValuable(ValuableType.Coin, 1));

            save1.Hand.Throw();
            Assert.That(save1.Karma, Is.EqualTo(1));
            Assert.That(save1.Hand.Throwables, Is.Empty);

            save1.Hand.Throw();
            Assert.That(save1.Karma, Is.EqualTo(1));
        }
Exemplo n.º 10
0
        public static PrimaryKeyedList <ValuableType, PlayerValuable> GetUniformPlayerValuables(
            FortuneFountainSaveData saveData, double rate = 1)
        {
            var keyedList = new PrimaryKeyedList <ValuableType, PlayerValuable>();

            foreach (var valuableType in ValuableDatabase.ValuableTypes)
            {
                keyedList.Add(new PlayerValuable(saveData, valuableType));
                keyedList[valuableType].Rate = rate;
            }

            return(keyedList);
        }
Exemplo n.º 11
0
        public IEnumerator OutOfGameTime_MultipleSessionsWithoutThrowing()
        {
            const float sessionSeconds   = 2f;
            const int   numberOfSessions = 2;
            var         sessionSpan      = TimeSpan.FromSeconds(sessionSeconds);

            locations = Locations.None;

            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_MultipleSessionsWithoutThrowing));

            yield return(null);

            fortuneFountainSaveData.Save(false);
            var realTimeNowAtSave = FrameTime.Now;

            Assert.That(fortuneFountainSaveData,
                        Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(TimeSpan.Zero),
                        $"We haven't waited yet, so there shouldn't be any {nameof(FortuneFountainSaveData.OutOfGameTimeSinceLastThrow)}!");

            Assert.That(fortuneFountainSaveData,
                        Has.Property(nameof(fortuneFountainSaveData.LastSaveTime)).EqualTo(realTimeNowAtSave));

            var expectedOutOfGameTime = TimeSpan.Zero;

            for (int session = 0; session < numberOfSessions; session++)
            {
                yield return(TestUtils.WaitForRealtime(sessionSpan));

                fortuneFountainSaveData.Reload();
                var realTimeNowAtReload = FrameTime.Now;

                Assert.That(realTimeNowAtReload, Is.Not.EqualTo(realTimeNowAtSave));

                var frameTimeDuration = realTimeNowAtReload - realTimeNowAtSave;

                expectedOutOfGameTime += frameTimeDuration;

                Assert.That(
                    fortuneFountainSaveData,
                    Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow))
                    .EqualTo(expectedOutOfGameTime)
                    );

                yield return(TestUtils.WaitForRealtime(sessionSpan));

                fortuneFountainSaveData.Save(false);
                realTimeNowAtSave = FrameTime.Now;
            }
        }
Exemplo n.º 12
0
        public void TestFirstValuableEnabledOnNewSave()
        {
            const string nickName = nameof(TestFirstValuableEnabledOnNewSave);
            var          fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nickName);

            const ValuableType expectedFirstValuableType = 0;

            Assert.That(fortuneFountainSaveData.PlayerValuables,
                        Has.Some.Property(nameof(PlayerValuable.ValuableType)).EqualTo(expectedFirstValuableType),
                        $"The new save file didn't contain PlayerValuable type 0 ({expectedFirstValuableType})!");

            Assert.That(fortuneFountainSaveData.PlayerValuables.Count, Is.EqualTo(1),
                        "The save file contained extra player valuables!");
        }
Exemplo n.º 13
0
        public IEnumerator TestCompleteButUncheckedGenDuringPreviousSession(
            [Values(4)] int uniformValuableGenerationRate,
            [Values(2)] int itemsPerWait
            )
        {
            GameManager.SaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(TestCompleteButUncheckedGenDuringPreviousSession));

            //Set the uniform gen rates to a decent number, so that we don't have to wait very long to get meaningful results
            GameManager.SaveData.PlayerValuables =
                TestData.GetUniformPlayerValuables(GameManager.SaveData, uniformValuableGenerationRate);
            var   genInterval = GameManager.SaveData.PlayerValuables[0].GenerateInterval;
            float genWait     = (float)genInterval.TotalSeconds;

            //Create the generation counters
            var genCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            //Wait long enough to generate something (but DON'T check for it)
            yield return(new WaitForSecondsRealtime(genWait * itemsPerWait));

            //Save the game - still without checking for any generation
            GameManager.SaveData.Save(false);

            //Wait long enough that we COULD have generated something if we were playing; then reload
            yield return(new WaitForSecondsRealtime(genWait * itemsPerWait));

            GameManager.SaveData.Reload();

            //Wait long enough to generate something during THIS session as well
            yield return(new WaitForSecondsRealtime(genWait * itemsPerWait));

            //Make sure that we still haven't generated anything, and that that LastGenerationTime values haven't changed
            Assert.That(genCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Amount = 0, Events = 0
            }));

            //Check for generation
            var itemsGenerated = GameManager.SaveData.PlayerValuables.CheckGenerate();

            //Assert that we've now had exactly 1 generation event, where we generated 2 * itemsPerWait
            Assert.That(genCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Amount = 2 * itemsPerWait, Events = 1
            }));
            Assert.That(itemsGenerated, Has.All.EqualTo(2 * itemsPerWait));
        }
Exemplo n.º 14
0
        public IEnumerator LastThrowTime()
        {
            FortuneFountainSaveData fortuneFountainSaveData = new FortuneFountainSaveData(nameof(LastThrowTime));

            Assert.That(fortuneFountainSaveData.Hand.LastThrowTime, Is.EqualTo(FrameTime.Now));

            var initialTime = fortuneFountainSaveData.Hand.LastThrowTime;

            yield return(new WaitForSecondsRealtime(0.001f));

            fortuneFountainSaveData.Hand.Throw();

            Assert.That(fortuneFountainSaveData.Hand.LastThrowTime, Is.EqualTo(FrameTime.Now));
            Assert.That(fortuneFountainSaveData.Hand.LastThrowTime, Is.Not.EqualTo(initialTime));
        }
Exemplo n.º 15
0
        public void TestGenerateInterval(
            [ValueSource(nameof(rates))] double rateInItemsPerSecond
            )
        {
            var saveData = new FortuneFountainSaveData(nameof(TestGenerateInterval));
            var pv       = new PlayerValuable(saveData, ValuableType.Coin)
            {
                Rate = rateInItemsPerSecond
            };

            Assert.That(TimeSpan.FromSeconds(1).Divide(pv.GenerateInterval),
                        Is.InRange(Math.Floor(rateInItemsPerSecond), rateInItemsPerSecond * 1.00001));

            Assert.That(pv.GenerateInterval,
                        Is.EqualTo(TimeSpan.FromTicks((long)(TimeSpan.TicksPerSecond / rateInItemsPerSecond))));
        }
Exemplo n.º 16
0
        public void ThrowResetsOutOfGameTime()
        {
            FortuneFountainSaveData fortuneFountainSaveData = UglySaveData(nameof(ThrowResetsOutOfGameTime));

            var outOfGameSpan = TimeSpan.FromDays(500);

            ReflectionUtils.SetVariableValue(fortuneFountainSaveData,
                                             nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow), outOfGameSpan);

            Assert.That(fortuneFountainSaveData,
                        Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(outOfGameSpan));

            fortuneFountainSaveData.Hand.Throw();

            Assert.That(fortuneFountainSaveData,
                        Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(TimeSpan.Zero));
        }
Exemplo n.º 17
0
        public void PostThrowSingleKarma()
        {
            FortuneFountainSaveData fortuneFountainSaveData = UglySaveData(nameof(PostThrowSingleKarma));

            double expectedKarmaTotal = 0;

            var throwablesCopy = fortuneFountainSaveData.Hand.ThrowableValuables.Copy();

            foreach (var throwable in throwablesCopy)
            {
                expectedKarmaTotal += throwable.PresentValue;

                throwable.Flick();

                Assert.That(fortuneFountainSaveData.Karma, Is.EqualTo(expectedKarmaTotal));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///     "Starts" the game, doing things such as loading the appropriate save file.
        /// </summary>
        private void LoadFortuneFountain()
        {
            SaveFileName = GetAppropriateSaveFileName();

            if (Application.isEditor && ClearDevSaveFileOnPlay)
            {
                ClearDevSaveFile();
            }

            //attempt to load the save data; if we can't, create a new one
            if (!FortuneFountainSaveData.TryLoad(SaveFileName, out SaveData))
            {
                LogUtils.Log($"No save file exists with the {nameof(FortuneFountainSaveData.Nickname)} {SaveFileName}, so we're creating a new one...");
                SaveData = FortuneFountainSaveData.NewSaveFile(SaveFileName);
            }

            LogUtils.Log(SaveData);
        }
Exemplo n.º 19
0
        public void ThrowResetsGenerateTimeUtilized()
        {
            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(ThrowResetsGenerateTimeUtilized));

            fortuneFountainSaveData.PlayerValuables = TestData.GetUniformPlayerValuables(fortuneFountainSaveData);

            var utilizedTime = TimeSpan.FromSeconds(1);

            fortuneFountainSaveData.PlayerValuables.ForEach(it => it.GenerateTimeUtilized = utilizedTime);

            Assert.That(fortuneFountainSaveData.PlayerValuables,
                        Has.All.Property(nameof(PlayerValuable.GenerateTimeUtilized)).EqualTo(utilizedTime));

            fortuneFountainSaveData.Hand.Throw();

            Assert.That(fortuneFountainSaveData.PlayerValuables,
                        Has.All.Property(nameof(PlayerValuable.GenerateTimeUtilized)).EqualTo(TimeSpan.Zero));
        }
Exemplo n.º 20
0
        public void TestGenerateIsLimitedByRate()
        {
            const string nickName = nameof(TestGenerateIsLimitedByRate);

            GameManager.SaveData = FortuneFountainSaveData.NewSaveFile(nickName);

            var generateCounter = 0;

            PlayerValuable.GeneratePlayerValuableEvent += (valuable, amount) => generateCounter++;

            LogUtils.Log(GameManager.SaveData.PlayerValuables[0]);
            LogUtils.Log(JsonConvert.SerializeObject(GameManager.SaveData.PlayerValuables[0]));

            for (var i = 0; i < 10; i++)
            {
                GameManager.SaveData.PlayerValuables.CheckGenerate();
                Assert.That(generateCounter, Is.EqualTo(0), $"Error on {i + 1}th generation!");
            }
        }
Exemplo n.º 21
0
        public IEnumerator EventSubscribersPersistAfterReloadMultiple()
        {
            GameManager.SaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(EventSubscribersPersistAfterReloadMultiple));
            var eventWasTriggered = false;

            PlayerValuable.GeneratePlayerValuableEvent += (valuable, amount) => eventWasTriggered = true;

            yield return(new WaitForSecondsRealtime((float)GameManager.SaveData.PlayerValuables[0].GenerateInterval
                                                    .TotalSeconds));

            GameManager.SaveData.Save(false);
            GameManager.SaveData.Reload();
            GameManager.SaveData.Reload();
            GameManager.SaveData.Reload();
            GameManager.SaveData.PlayerValuables.CheckGenerate();

            Assert.True(eventWasTriggered);
        }
Exemplo n.º 22
0
        public void TestSimpleGeneration(double rate, double secondsSinceLastGenerateCheckAndThrow)
        {
            GameManager.SaveData = FortuneFountainSaveData.NewSaveFile(nameof(TestSimpleGeneration));
            var startTime = FrameTime.Now.AddSeconds(-secondsSinceLastGenerateCheckAndThrow);

            GameManager.SaveData.PlayerValuables    = TestData.GetUniformPlayerValuables(GameManager.SaveData, rate);
            GameManager.SaveData.Hand.LastThrowTime = startTime;
            GameManager.SaveData.LastLoadTime       = startTime;
            ReflectionUtils.SetVariableValue(GameManager.SaveData, nameof(GameManager.SaveData.LastSaveTime),
                                             startTime);
            GameManager.SaveData.PlayerValuables.ForEach(it => it.LastGenerateCheckTime = startTime);

            var generatedItems = GameManager.SaveData.PlayerValuables.CheckGenerate(TimeSpan.MaxValue);
            //TODO: This test probably needs to be revisited so that this can be a cleaner assertion
            var expectedItemsGenerated = secondsSinceLastGenerateCheckAndThrow * rate;

            AssertAll.Of(
                generatedItems,
                Has.All.EqualTo(generatedItems[0]),
                Is.All.InRange(expectedItemsGenerated.Floor(), expectedItemsGenerated.Ceiling())
                );
        }
Exemplo n.º 23
0
        public IEnumerator TestPartialUncheckedItemsGeneratedDuringLastSession(
            [Values(0.5)] double previousGenIntervals,
            [Values(3)] double totalItemsToGenerate
            )
        {
            Assume.That(previousGenIntervals, Is.LessThan(1));
            Assume.That(totalItemsToGenerate, Is.GreaterThan(previousGenIntervals));

            GameManager.SaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(TestPartialUncheckedItemsGeneratedDuringLastSession));
            GameManager.SaveData.PlayerValuables = TestData.GetUniformPlayerValuables(GameManager.SaveData);

            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                                                   previousGenIntervals));

            GameManager.SaveData.Save(false);

            var genCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval, 2));

            GameManager.SaveData.Reload();

            var sleepIntervals = totalItemsToGenerate - previousGenIntervals + 0.5;

            LogUtils.Log($"{nameof(sleepIntervals)} = {sleepIntervals}");
            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                                                   sleepIntervals));

            var itemsGenerated = GameManager.SaveData.PlayerValuables.CheckGenerate();

            Assert.That(itemsGenerated, Has.All.EqualTo(totalItemsToGenerate));
            Assert.That(genCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Amount = (int)totalItemsToGenerate, Events = 1
            }));
        }
Exemplo n.º 24
0
        public void PostThrowHandKarma()
        {
            FortuneFountainSaveData fortuneFountainSaveData = UglySaveData(nameof(PostThrowHandKarma));

            AssertAll.Of(
                () => Assert.That(fortuneFountainSaveData.Karma, Is.EqualTo(0)),
                () => Assert.That(fortuneFountainSaveData.Hand.Throwables, Is.Not.Empty)
                );

            var expectedPostThrowKarma = fortuneFountainSaveData.Hand.KarmaInHand;

            LogUtils.Log(
                $"Before throwing, there is {fortuneFountainSaveData.Karma} karma",
                $"In my hand, there is {fortuneFountainSaveData.Hand.KarmaInHand} karma"
                );

            fortuneFountainSaveData.Hand.Throw();

            AssertAll.Of(
                () => Assert.That(fortuneFountainSaveData.Karma, Is.EqualTo(expectedPostThrowKarma)),
                () => Assert.That(fortuneFountainSaveData.Hand.Throwables, Is.Empty)
                );
        }
Exemplo n.º 25
0
        private static FortuneFountainSaveData UglySaveData([NotNull] string nickName)
        {
            var throwables = new List <Throwable>()
            {
                new ThrowableValuable(ValuableType.Coin, 10),
                new ThrowableValuable(ValuableType.Fiduciary, 54),
                new ThrowableValuable(ValuableType.Coin, 87),
                new ThrowableValuable(ValuableType.Gem, 98),
                new ThrowableValuable(ValuableType.Livestock, 12341435),
                new ThrowableValuable(ValuableType.Collectible, 7845687),
                new ThrowableValuable(ValuableType.Metal, 0),
                new ThrowableValuable(ValuableType.Scrip, -123),
                new ThrowableValuable(ValuableType.Coin, 1.5),
                new ThrowableValuable(ValuableType.Scrip, Math.PI),
                new ThrowableValuable(ValuableType.Fiduciary, Math.E),
                new ThrowableValuable(ValuableType.Fiduciary, -238475.52349578),
            };

            FortuneFountainSaveData fortuneFountainSaveData = new FortuneFountainSaveData(nickName)
            {
                Hand =
                {
                    _throwables = throwables
                }
            };

            fortuneFountainSaveData.Hand.FixHierarchy();

            AssertAll.Of(
                fortuneFountainSaveData.Hand.Throwables,
                Is.Not.Empty,
                Has.All.Property(nameof(Throwable.MyHand)).EqualTo(fortuneFountainSaveData.Hand)
                );

            return(fortuneFountainSaveData);
        }
Exemplo n.º 26
0
        public void GrabValuable()
        {
            FortuneFountainSaveData fortuneFountainSaveData = new FortuneFountainSaveData(nameof(GrabValuable));

            foreach (var valuableType in ValuableDatabase.ValuableTypes)
            {
                //assert that it doesn't contain the item before we grab it
                var heldValuableTypes = fortuneFountainSaveData.Hand.Throwables.Select(it => it as ThrowableValuable)
                                        .Where(it => it != null)
                                        .Select(it => it.ValuableType);
                Assert.That(heldValuableTypes, Has.None.EqualTo(valuableType));

                //grab the item
                fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(valuableType, 10));

                //assert that we're now holding it
                Assert.That(
                    fortuneFountainSaveData.Hand.Throwables.Select(it => it as ThrowableValuable)
                    .Where(it => it != null)
                    .Select(it => it.ValuableType),
                    Has.Some.EqualTo(valuableType)
                    );
            }
        }
Exemplo n.º 27
0
        public IEnumerator OutOfGameTime_UpdatesOnLoad(
            [ValueSource(nameof(RealSeconds))] double secondsOutOfGame
            )
        {
            FortuneFountainSaveData fortuneFountainSaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_UpdatesOnLoad));

            yield return(null);

            fortuneFountainSaveData.Save(false);

            var saveTime = FrameTime.Now;

            var outOfGameSpan = TimeSpan.FromSeconds(secondsOutOfGame);

            yield return(TestUtils.WaitForRealtime(outOfGameSpan));

            var loadedSaveData = FortuneFountainSaveData.Load(fortuneFountainSaveData.Nickname);

            var loadTime = FrameTime.Now;

            Assert.That(loadedSaveData,
                        Has.Property(nameof(loadedSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(loadTime - saveTime));
        }
Exemplo n.º 28
0
 private void ClearDevSaveFile()
 {
     FortuneFountainSaveData.Delete(DevSaveFileName);
 }
Exemplo n.º 29
0
        public void GenerateEventsLimitedByMaxGenerateTime(
            double generateTimeLimitInSeconds,
            double itemsPerSecond,
            double extraGenerationSeconds
            )
        {
            //the number of items we expect to generate - which should always be limited by maxGenerationSeconds
            var expectedItemsGenerated = generateTimeLimitInSeconds * itemsPerSecond;

            Ignore.Unless(
                () => Assume.That(generateTimeLimitInSeconds, Is.GreaterThan(0),
                                  $"{nameof(generateTimeLimitInSeconds)} must be greater than 0!"),
                () => Assume.That(itemsPerSecond, Is.GreaterThan(0),
                                  $"{nameof(itemsPerSecond)} must be greater than 0!"),
                () => Assume.That(extraGenerationSeconds, Is.GreaterThanOrEqualTo(0),
                                  $"{nameof(extraGenerationSeconds)} must be positive!"),
                () => Assume.That(expectedItemsGenerated, Is.GreaterThanOrEqualTo(1),
                                  $"{nameof(expectedItemsGenerated)} must be at least 1!")
                );

            //this test is very quick and runs a LOT of times, so we should disable logging to prevent it from being crazy slow
            // LogUtils.locations = LogUtils.Locations.None;

            const string nickName = nameof(GenerateEventsLimitedByMaxGenerateTime);

            GameManager.SaveData = FortuneFountainSaveData.NewSaveFile(nickName);


            //Setting up the player data
            GameManager.SaveData.PlayerValuables =
                TestData.GetUniformPlayerValuables(GameManager.SaveData, itemsPerSecond);
            GameManager.SaveData.Hand.LastThrowTime = FrameTime.Now -
                                                      TimeSpan.FromSeconds(generateTimeLimitInSeconds +
                                                                           extraGenerationSeconds);
            GameManager.SaveData.PlayerValuables.ForEach(it =>
                                                         it.LastGenerateCheckTime = GameManager.SaveData.Hand.LastThrowTime);
            GameManager.SaveData.Hand.GenerateTimeLimit = TimeSpan.FromSeconds(generateTimeLimitInSeconds);

            Assert.That(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                        Is.LessThanOrEqualTo(GameManager.SaveData.Hand.GenerateTimeLimit),
                        $"We must have enough time to generate at least one item - i.e. {nameof(PlayerValuable.GenerateInterval)} <= {nameof(Hand.GenerateTimeLimit)}!");

            var genCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            //Generate the items
            GameManager.SaveData.PlayerValuables.CheckGenerate();

            //Check for the proper number of events & actual items generated
            AssertAll.Of(
                () => Assert.That(
                    GroupThrowables(GameManager.SaveData.Hand.Throwables),
                    Has.All.Values().With.Count.InRange(Math.Floor(expectedItemsGenerated),
                                                        Math.Ceiling(expectedItemsGenerated))
                    ),
                () => Assert.That(genCounters,
                                  Has.All.Values().With.Property(nameof(ValuableGenerationCounter.Events)).EqualTo(1)),
                () => Assert.That(genCounters,
                                  Has.All.Values().With.Property(nameof(ValuableGenerationCounter.Amount))
                                  .InRange(Math.Floor(expectedItemsGenerated), Math.Ceiling(expectedItemsGenerated)))
                );
        }
Exemplo n.º 30
0
        public IEnumerator GenerateAllViaCollectionExtension(
            [Values(true, false)] bool checkThrowables
            )
        {
            const string nickName = nameof(TestGenerateIsLimitedByRate);

            GameManager.SaveData = FortuneFountainSaveData.NewSaveFile(nickName);
            GameManager.SaveData.PlayerValuables = TestData.GetUniformPlayerValuables(GameManager.SaveData);

            Assume.That(GameManager.SaveData.PlayerValuables.Count, Is.GreaterThan(1),
                        "We need to test more than 1 valuable type!");
            Assume.That(GameManager.SaveData.PlayerValuables, Has.All.Property("Rate").EqualTo(1),
                        "All valuables should have a generation rate of 1!");

            //Add counter events for each of the valuables
            var generateCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            //Set the LastGenerateTime for each valuable to be their previous interval (that way, they are ready to generate)
            var setTime = FrameTime.Now - GameManager.SaveData.PlayerValuables[0].GenerateInterval;

            GameManager.SaveData.Hand.LastThrowTime = setTime;

            GameManager.SaveData.PlayerValuables.ForEach(it => it.LastGenerateCheckTime = setTime);

            if (checkThrowables)
            {
                Assert.That(GameManager.SaveData.Hand.Throwables.Count, Is.EqualTo(0));
            }

            //Generate stuff
            GameManager.SaveData.PlayerValuables.CheckGenerate();
            Assert.That(generateCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Events = 1, Amount = 1
            }));

            if (checkThrowables)
            {
                Assert.That(GameManager.SaveData.Hand.Throwables.Count,
                            Is.EqualTo(generateCounters.Sum(it => it.Value.Amount)));
            }

            //sleep so we can expect to generate another item
            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval));

            //Generate stuff
            GameManager.SaveData.PlayerValuables.CheckGenerate();
            Assert.That(generateCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Events = 2, Amount = 2
            }));

            if (checkThrowables)
            {
                Assert.That(GameManager.SaveData.Hand.Throwables.Count,
                            Is.EqualTo(generateCounters.Sum(it => it.Value.Amount)));
            }

            //sleep so that we can expect to generate _2_ more items
            yield return
                (TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval.Multiply(2)));

            //Generate stuff
            GameManager.SaveData.PlayerValuables.CheckGenerate();
            Assert.That(generateCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Events = 3, Amount = 4
            }));

            if (checkThrowables)
            {
                Assert.That(GameManager.SaveData.Hand.Throwables,
                            Has.Property(nameof(Hand.Throwables.Count)).EqualTo(generateCounters.Sum(it => it.Value.Amount)));
            }
        }