/// <summary> /// Apply a change to this vital, and return how much was consumed. /// </summary> public double ApplyChange(double amount, IVitalsContactReactor reactor = null) { double oldval = vitalData.Value; double newval = vitalData.Value + amount; if (!ReferenceEquals(reactor, null) && reactor.AllowOverload) { double maxValue = vitalDef.MaxValue; if (oldval >= maxValue) { return(0); } if (newval > maxValue) { newval = maxValue; } } else { double fullValue = vitalDef.FullValue; if (oldval >= fullValue) { return(0); } if (newval > fullValue) { newval = fullValue; } } Value = newval; double diff = newval - oldval; ///// reset regen/decay based on gain/loss //if (diff > 0) // DisruptDecay(); //else if (diff < 0) // DisruptRegen(); return(diff); }
/// <summary> /// Get the results of ApplyChange without actually applying them. /// </summary> public double TestApplyChange(double charge, IVitalsContactReactor iVitalsAffector) { double oldval = vitalData.Value; double newval = vitalData.Value + charge; if (!ReferenceEquals(iVitalsAffector, null) && iVitalsAffector.AllowOverload) { double maxValue = vitalDef.MaxValue; if (oldval >= maxValue) { return(0); } if (newval > maxValue) { newval = maxValue; } } else { double fullValue = vitalDef.MaxValue; if (oldval >= fullValue) { return(0); } if (newval > fullValue) { newval = fullValue; } } double diff = newval - oldval; return(diff); }
public double TestApplyChange(IVitalsContactReactor iVitalsAffector, ContactEvent contactEvent) { double charge = iVitalsAffector.DischargeValue(contactEvent.contactType); return(TestApplyChange(charge, iVitalsAffector)); }