internal void AssertSpeciesVitalIsCorrect(SpeciesVital actualSpeciesVital, IList <AnimalMetric> expectedAnimalMetrics, IList <MetricInteraction> expectedMetricInteractions, IList <Interaction> expectedInteractions) { var expectedAnimalMetricMatch = expectedAnimalMetrics.FirstOrDefault(animalMetric => animalMetric.MetricId == actualSpeciesVital.VitalId && animalMetric.AnimalId == actualSpeciesVital.SpeciesId); Assert.IsNotNull(expectedAnimalMetricMatch, $"No match found in expected AnimalMetrics for SpeciesVital with SpeciedVitalId = {actualSpeciesVital.VitalId} and SpeciesId = {actualSpeciesVital.SpeciesId}"); Assert.AreEqual(actualSpeciesVital.RequiredAttentiveness, expectedAnimalMetricMatch.RequiredAttentiveness); AssertSpeciesCareActionsAreCorrect(actualSpeciesVital.VitalId, actualSpeciesVital.RequiredCareActions, expectedMetricInteractions, expectedInteractions); }
private PetVital Build(PetMetric petMetric, SpeciesVital speciesVital) { var neglectPeriod = DateTime.UtcNow - petMetric.LastInteractionTime; var healthDeclineDuringNeglect = CalculateNeglectImpact(petMetric, neglectPeriod, speciesVital); return(new PetVital() { Health = petMetric.Value - healthDeclineDuringNeglect, LastTimeCaredFor = petMetric.LastInteractionTime, TimeNeglectedFor = neglectPeriod, HealthDeclineDuringNeglect = healthDeclineDuringNeglect, VitalName = speciesVital.Name, VitalStats = speciesVital, PetVitalId = petMetric.MetricId, PetId = petMetric.PetId, }); }
public PetVital Rebuild(PetMetric petMetric, SpeciesVital animalVital, SpeciesCareAction speciesCareAction) { //This will recalculate the health based on last time interacted with. We then add the positive affect of the interaction var oldVital = Build(petMetric, animalVital); //Todo - straight return, this is just for debug var newVital = new PetVital() { Health = RecalculateMetric(oldVital.Health, petMetric, speciesCareAction), //We recalculate this LastTimeCaredFor = DateTime.UtcNow, //Gets refreshed TimeNeglectedFor = TimeSpan.FromSeconds(1), HealthDeclineDuringNeglect = 0, //No decline yet VitalName = animalVital.Name, VitalStats = animalVital, PetVitalId = animalVital.VitalId, PetId = petMetric.PetId }; return(newVital); }
//TODO UNIT TEST private int CalculateNeglectImpact(PetMetric petMetric, TimeSpan neglectPeriod, SpeciesVital speciesVital) { var metric = _metricRepository.Find(petMetric.MetricId); var value = petMetric.Value; var rate = 1 / metric.NaturalChangeOverTime; //How frequently we apply the NaturalChangeOverTime rate (not an even distribution) var frequencyTimespan = speciesVital.RequiredAttentiveness.ToTimeSpan(); var numberOfNeglectedPeriods = neglectPeriod.DividedBy(frequencyTimespan); for (int i = 0; i == numberOfNeglectedPeriods; i++) { if (metric.Type == MetricType.DecreasesWithTime) { value -= (value * rate); } if (metric.Type == MetricType.IncreasesWithTime) { value += (value * rate); } } return(value); }