public override object ToContract()
        {
            var c = new ActiveDiseasesAndInjuriesContract();

            c.ActiveDiseases = ActiveDiseases.ConvertAll(x => (ActiveDiseaseContract)x.ToContract()).ToArray();
            c.ActiveInjuries = ActiveInjuries.ConvertAll(x => (ActiveInjuryContract)x.ToContract()).ToArray();

            return(c);
        }
Esempio n. 2
0
        public object GetActiveOrScheduled <T>(DateTime currentTime)
            where T : class
        {
            if (typeof(T).IsSubclassOf(typeof(DiseaseDefinitionBase)))
            {
                return(ActiveDiseases.ToList().FirstOrDefault(x => (x.IsActiveNow || x.DiseaseStartTime >= currentTime) && x.Disease.GetType() == typeof(T)));
            }

            if (typeof(T).IsSubclassOf(typeof(InjuryBase)))
            {
                return(ActiveInjuries.ToList().FirstOrDefault(x => (x.IsActiveNow || x.InjuryTriggerTime >= currentTime) && x.Injury.GetType() == typeof(T)));
            }

            return(null);
        }
Esempio n. 3
0
        public object GetActive <T>()
            where T : class
        {
            if (typeof(T).IsSubclassOf(typeof(DiseaseDefinitionBase)))
            {
                return(ActiveDiseases.ToList().FirstOrDefault(x => x.IsActiveNow && x.Disease.GetType() == typeof(T)));
            }

            if (typeof(T).IsSubclassOf(typeof(InjuryBase)))
            {
                return(ActiveInjuries.ToList().FirstOrDefault(x => x.IsActiveNow && x.Injury.GetType() == typeof(T)));
            }

            return(null);
        }
Esempio n. 4
0
        private void CreateAndLinkActiveDiseasesAndInjuries(Guid?worstDiseaseId, List <ActiveDiseaseSnippet> diseasesData, List <ActiveInjurySnippet> injuriesData)
        {
            ActiveInjuries.Clear();
            ActiveDiseases.Clear();

            var injuriesMapping = new Dictionary <Guid, Guid>(); // old id, new id

            foreach (var injData in injuriesData)
            {
                var inj = new ActiveInjury(_gc);

                inj.RestoreState(injData);

                injuriesMapping.Add(injData.InjuryId, inj.Injury.Id);

                ActiveInjuries.Add(inj);
            }

            var diseasesMapping = new Dictionary <Guid, Guid>(); // old id, new id

            foreach (var diseaseData in diseasesData)
            {
                var injKey    = diseaseData.InjuryId.HasValue ? (injuriesMapping.ContainsKey(diseaseData.InjuryId.Value) ? injuriesMapping[diseaseData.InjuryId.Value] : (Guid?)null) : (Guid?)null;
                var linkedInj = injKey.HasValue ? ActiveInjuries.FirstOrDefault(x => x.Injury.Id == injKey.Value) : null;
                var disease   = new ActiveDisease(_gc, linkedInj);

                disease.RestoreState(diseaseData);

                diseasesMapping.Add(diseaseData.DiseaseId, disease.Disease.Id);

                ActiveDiseases.Add(disease);
            }

            var diseaseKey   = worstDiseaseId.HasValue ? (diseasesMapping.ContainsKey(worstDiseaseId.Value) ? diseasesMapping[worstDiseaseId.Value] : (Guid?)null) : (Guid?)null;
            var worstDisease = diseaseKey.HasValue ? ActiveDiseases.FirstOrDefault(x => x.Disease.Id == diseaseKey.Value) : null;

            WorstDisease = worstDisease?.Disease;

            injuriesMapping.Clear();
            diseasesMapping.Clear();
        }
Esempio n. 5
0
        public IStateSnippet GetState()
        {
            var state = new HealthStateSnippet
            {
                BloodPressureTop         = this.BloodPressureTop,
                BloodPressureBottom      = this.BloodPressureBottom,
                HeartRate                = this.HeartRate,
                BloodPercentage          = this.BloodPercentage,
                FoodPercentage           = this.FoodPercentage,
                WaterPercentage          = this.WaterPercentage,
                OxygenPercentage         = this.OxygenPercentage,
                StaminaPercentage        = this.StaminaPercentage,
                FatiguePercentage        = this.FatiguePercentage,
                BodyTemperature          = this.BodyTemperature,
                LastSleepTime            = this.LastSleepTime,
                CheckTime                = this.CheckTime,
                IsBloodLoss              = this.IsBloodLoss,
                IsActiveInjury           = this.IsActiveInjury,
                IsActiveDisease          = this.IsActiveDisease,
                IsFoodDisgust            = this.IsFoodDisgust,
                IsSleepDisorder          = this.IsSleepDisorder,
                CannotRun                = this.CannotRun,
                IsLegFracture            = this.IsLegFracture,
                ActiveDiseasesWorstLevel = this.ActiveDiseasesWorstLevel,
                WorstDiseaseId           = this.WorstDisease?.Id
            };

            var diseases = ActiveDiseases.ConvertAll(x => (ActiveDiseaseSnippet)x.GetState());
            var injuries = ActiveInjuries.ConvertAll(x => (ActiveInjurySnippet)x.GetState());

            state.ChildStates.Add("ActiveDiseasesAndInjuries", new ActiveDiseasesAndInjuriesSnippet {
                ActiveDiseases = diseases,
                ActiveInjuries = injuries
            });

            return(state);
        }