Esempio n. 1
0
        public void OnConsumeItem(InventoryConsumableItemBase item)
        {
            var food = item as FoodItemBase;

            var isSpoiled = food != null && food.IsSpoiled;

            if (_group.IsApplicableToGroup(item) && !isSpoiled)
            {
                _timesTaken.Add(_gc.WorldTime.Value);
            }
        }
Esempio n. 2
0
        public override void OnConsumeItem(InventoryConsumableItemBase item)
        {
            var shouldTriggerDisease = false;

            var water = item as WaterVesselItemBase;

            if (water != null)
            {
                if (!water.IsSafe)
                {
                    shouldTriggerDisease = UnsafeWaterFoodPoisoningChance.WillHappen();
                }
            }
            else
            {
                var food = item as FoodItemBase;
                if (food != null)
                {
                    // Check if food is spoiled
                    if (food.IsSpoiled)
                    {
                        shouldTriggerDisease = food.SpoiledChanceOfFoodPoisoning.WillHappen();
                    }
                    else
                    {
                        shouldTriggerDisease = food.GeneralChanceOfFoodPoisoning.WillHappen();
                    }
                }
                else
                {
                    shouldTriggerDisease = item.SpoiledChanceOfFoodPoisoning.WillHappen();
                }
            }

            if (shouldTriggerDisease)
            {
                var activeFoodPoisoning = _gc.Health.Status.GetActiveOrScheduled <FoodPoisoning>(_gc.WorldTime.Value) as ActiveDisease;

                if (activeFoodPoisoning != null && activeFoodPoisoning.IsHealing && !activeFoodPoisoning.IsSelfHealing)
                {
                    activeFoodPoisoning.InvertBack();
                    return;
                }
                if (activeFoodPoisoning != null)
                {
                    return;
                }

                _gc.Health.Status.ActiveDiseases.Add(new ActiveDisease(_gc, typeof(FoodPoisoning), _gc.WorldTime.Value));
            }
        }
        public bool OnItemConsumed(IGameController gc, InventoryConsumableItemBase consumable, ActiveDisease disease)
        {
            if (disease.TreatedStage == null)
            {
                return(false);
            }

            var isApplied      = _treatments.Any(treatment => treatment.OnItemConsumed(gc, consumable, disease));
            var isTreatedLevel = disease.TreatedStage.Level == _treatedLevel;

            if (isTreatedLevel)
            {
                if (_treatments.All(x => x.IsFinished))
                {
                    _isOverallHealingStarted = true;

                    disease.Invert();

                    disease.DeclareDiseaseTreated();

                    Events.NotifyAll(l => l.DiseaseHealed(disease.Disease));

                    return(true);
                }

                if (_treatments.All(x => x.IsStarted) && !_isOverallHealingStarted)
                {
                    _isOverallHealingStarted = true;

                    disease.Invert();

                    Events.NotifyAll(l => l.DiseaseTreatmentStarted(disease.Disease));

                    return(true);
                }

                if (isApplied && _isOverallHealingStarted)
                {
                    Events.NotifyAll(l => l.DiseaseHealingContinued(disease.Disease));
                }
            }

            return(isApplied);
        }
Esempio n. 4
0
        public void OnConsumeItem(IGameController gc, InventoryConsumableItemBase consumable)
        {
            if (IsTreated)
            {
                return;
            }

            if (TreatedStage != null)
            {
                TreatedStage.OnConsumeItem(gc, consumable, this);
            }
            else
            {
                var stage = GetActiveStage(gc.WorldTime.Value);

                if (stage != null)
                {
                    stage.OnConsumeItem(gc, consumable, this);
                }
            }
        }
Esempio n. 5
0
 public void OnConsumeItem(InventoryConsumableItemBase item)
 {
     _monitors.ForEach(x => x.OnConsumeItem(item));
 }
Esempio n. 6
0
        public bool OnItemConsumed(IGameController gc, InventoryConsumableItemBase consumable, ActiveDisease disease)
        {
            if (IsFinished)
            {
                return(false);
            }

            if (!gc.WorldTime.HasValue)
            {
                return(false);
            }

            if (disease.IsSelfHealing)
            {
                return(false);
            }

            var treatedStage = disease.TreatedStage;

            if (treatedStage == null)
            {
                treatedStage = disease.GetActiveStage(gc.WorldTime.Value);
            }

            if (treatedStage == null)
            {
                return(false);
            }

            var isTreatedLevel = treatedStage.Level == _treatedLevel;

            if (_consumables.Items.Contains(consumable.Name))
            {
                var currentTime = gc.WorldTime.Value;

                if (_consumedTimes.Count == 0)
                {
                    // First consume
                    _inTimeConsumedCount++;
                    _consumedTimes.Add(currentTime);

                    if (isTreatedLevel)
                    {
                        IsFinished = false;

                        CheckIfTreatmentFinished(disease);

                        if (OnTreatmentStarted != null)
                        {
                            OnTreatmentStarted.Invoke();
                        }

                        //("Disease consumables treatment started.");

                        IsStarted = true;

                        if (!IsNodePart && !IsFinished)
                        {
                            //("Overall disease treatment started.");

                            Events.NotifyAll(l => l.DiseaseTreatmentStarted(disease.Disease));

                            // We're starting to heal
                            disease.Invert();
                        }
                    }
                }
                else
                {
                    IsFinished = false;

                    var lastTime = _consumedTimes.Last();
                    var minutes  = (currentTime - lastTime).TotalMinutes;

                    if (minutes <= _timingInGameMinutes + TimingDeltaBetweenAllowedConsuming && minutes >= _timingInGameMinutes - TimingDeltaBetweenAllowedConsuming)
                    {
                        _inTimeConsumedCount++;

                        _consumedTimes.Add(currentTime);

                        if (isTreatedLevel)
                        {
                            CheckIfTreatmentFinished(disease);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
Esempio n. 7
0
 public virtual void OnConsumeItem(InventoryConsumableItemBase item)
 {
 }
 public void OnConsumeItem(InventoryConsumableItemBase pill)
 {
 }
Esempio n. 9
0
 public override void OnConsumeItem(InventoryConsumableItemBase item)
 {
 }
Esempio n. 10
0
        public override void OnConsumeItem(InventoryConsumableItemBase item)
        {
            if (_gc.Weather.Temperature >= NoAnginaTemperature)
            {
                return;
            }

            var water = item as WaterVesselItemBase;

            if (water == null)
            {
                return;
            }

            var activeAngina = _gc.Health.Status.GetActiveOrScheduled <Angina>(_gc.WorldTime.Value) as ActiveDisease;
            var hasFlu       = _gc.Health.Status.HasActive <Flu>();

            if ((activeAngina != null && !activeAngina.IsHealing) || (activeAngina != null && activeAngina.IsSelfHealing))
            {
                return;
            }

            var mustTriggerDisease = false;
            var minutesSinceBoled  = water.LastBoilTime.HasValue ? (_gc.WorldTime.Value - water.LastBoilTime.Value).TotalMinutes : double.MaxValue;
            var fluBonus           = hasFlu ? FluBonus : 0;

            if (_gc.Weather.Temperature <= VeryColdTemperature)
            {
                if (minutesSinceBoled >= MinutesFromBoilVeryColdTemperatureToConsiderAngina)
                {
                    if ((AnginaHighChance + fluBonus).WillHappen())
                    {
                        mustTriggerDisease = true;
                    }
                }
            }

            if (_gc.Weather.Temperature <= ColdTemperature)
            {
                if (minutesSinceBoled >= MinutesFromBoilColdTemperatureToConsiderAngina)
                {
                    if ((AnginaMediumChance + fluBonus).WillHappen())
                    {
                        mustTriggerDisease = true;
                    }
                }
            }

            if (_gc.Weather.Temperature <= MediumTemperature)
            {
                if (minutesSinceBoled >= MinutesFromBoilMediumTemperatureToConsiderAngina)
                {
                    if ((AnginaLowChance + fluBonus).WillHappen())
                    {
                        mustTriggerDisease = true;
                    }
                }
            }

            if (mustTriggerDisease)
            {
                var diseaseStime = _gc.WorldTime.Value.AddMinutes(Helpers.RollDice(AnginaDelayMinutesMin, AnginaDelayMinutesMax));
                _gc.Health.Status.ActiveDiseases.Add(new ActiveDisease(_gc, typeof(Angina), diseaseStime));
            }
        }