public bool OnApplianceTaken(IGameController gc, ApplianceInfo applianceInfo, ActiveDisease disease) { var treatedStage = disease.TreatedStage; if (treatedStage == null) { treatedStage = disease.GetActiveStage(gc.WorldTime.Value); } if (treatedStage == null) { return(false); } var isTreatedLevel = treatedStage.Level == _treatedLevel; var isApplied = _treatments.Any(treatment => treatment.OnApplianceTaken(gc, applianceInfo, disease)); 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); }
private void CheckIfTreatmentFinished(ActiveDisease disease) { if (_inTimeConsumedCount == _countToConsume) { IsFinished = true; if (OnTreatmentEnded != null) { OnTreatmentEnded.Invoke(); } if (!IsNodePart) { disease.DeclareDiseaseTreated(); disease.Invert(); Events.NotifyAll(l => l.DiseaseHealed(disease.Disease)); } //("Disease treatment finished."); } else { //("Disease treatment continued. Healing."); if (!IsNodePart && IsStarted) { Events.NotifyAll(l => l.DiseaseHealingContinued(disease.Disease)); } } }
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); }
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); }