Ejemplo n.º 1
0
        /// <summary> Validate Owned Animal state, whenever the animal is requested via the API validate the Animal doesn't need degradation on it's stats </summary>
        /// <returns> bool value representing whether it successfully validated and or degraded the <seealso cref="AnimalOwnership"> object </returns>
        private bool ValidateAndDegradeAnimal(AnimalOwnership ownedAnimal)
        {
            //New Animals with a default timestamp which is less than this year could be generated via auto creation, so set their update time to now.
            if (ownedAnimal.LastUpdated.Year < YEAR_OF_PRODUCTION)
            {
                //Animal is freshly made, set the last updated time to now and continue
                return(UpdateAnimal(ownedAnimal));
            }

            //Calculate the degradation multipler
            int degradationMultiplier = (int)Math.Floor((DateTime.Now - ownedAnimal.LastUpdated).TotalMilliseconds / DEGRADING_TIMEFRAME_IN_MILLISECONDS);

            //Min the degradation multiplier against a defined max value
            degradationMultiplier = Math.Min(MAX_DEGRADATION, degradationMultiplier);

            //Check if we need to apply stat degradation
            if (degradationMultiplier > 0)
            {
                //Degrade the animals stats providing the multiplier (time degradation times).
                ownedAnimal.DegradeStats(degradationMultiplier);

                //Return updated animal
                return(UpdateAnimal(ownedAnimal));
            }

            //Validation complete without any modifications to Animal status
            return(true);
        }
Ejemplo n.º 2
0
        private void TestStatDegradation(AnimalOwnership ownedAnimal, Animal animal, int multiplier)
        {
            int currentHappiness = ownedAnimal.Happiness;
            int currentHunger    = ownedAnimal.Hunger;

            ownedAnimal.DegradeStats(multiplier);

            Assert.Equal(currentHappiness -= (animal.HappinessDecrease * multiplier), ownedAnimal.Happiness);
            Assert.Equal(currentHunger    += (animal.HungerIncrease * multiplier), ownedAnimal.Hunger);
        }
Ejemplo n.º 3
0
        public void TestDegradeStatsByInappropriateValue()
        {
            AnimalOwnership ownedAnimal          = context.AnimalOwnership.Find(ID_TO_FIND);
            Animal          ownedAnimalDefintion = context.Animal.Find(ownedAnimal.AnimalId);

            ownedAnimal.Animal = ownedAnimalDefintion;

            int multiplier       = -1;
            int currentHunger    = ownedAnimal.Hunger;
            int currentHappiness = ownedAnimal.Happiness;

            ownedAnimal.DegradeStats(multiplier);

            Assert.Equal(currentHunger, ownedAnimal.Hunger);
            Assert.Equal(currentHappiness, ownedAnimal.Happiness);
        }