///<summary> /// Adds a volume of blood along with the maximum normal reagents ///</summary> public void AddFreshBlood(ReagentMix bloodPool, float amount) { // Currently only does blood and required reagents, should at nutriments and other common gases var bloodToAdd = new ReagentMix(BloodType, amount); bloodToAdd.Add(CirculatedReagent, bloodType.GetGasCapacity(bloodToAdd)); bloodPool.Add(bloodToAdd); }
/// <summary> /// Handles the body part's consumption of required reagents (eg oxygen) /// </summary> protected virtual void ConsumeReagents() { //Heal if blood saturation consumption is fine, otherwise do damage float bloodSaturation = 0; float bloodCap = bloodType.GetGasCapacity(BloodContainer.CurrentReagentMix); if (bloodCap > 0) { float foreignCap = bloodType.GetGasCapacityForeign(BloodContainer.CurrentReagentMix); var ratioNativeBlood = bloodCap / (bloodCap + foreignCap); bloodSaturation = BloodContainer[requiredReagent] * ratioNativeBlood / bloodCap; } // Numbers could use some tweaking, maybe consumption goes down when unconscious? if (!isBloodReagentConsumed) { return; } float consumed = BloodContainer.CurrentReagentMix.Subtract(requiredReagent, bloodReagentConsumed * bloodThroughput); // Adds waste product (eg CO2) if any, currently always 1:1, could add code to change the ratio if (wasteReagent) { BloodContainer.CurrentReagentMix.Add(wasteReagent, consumed); } var info = HealthMaster.CirculatorySystem.BloodInfo; float damage; if (bloodSaturation < info.BLOOD_REAGENT_SATURATION_BAD) { //Deals damage that ramps to 1 as blood saturation levels drop, halved if unconscious if (bloodSaturation <= 0) { damage = 1f; } else if (bloodSaturation < info.BLOOD_REAGENT_SATURATION_CRITICAL) { // Arbitrary damage formula, could use anything here damage = 1 * (1 - Mathf.Sqrt(bloodSaturation)); } else { damage = 1; } } else if (bloodSaturation > 2) { //There is more oxygen in the organ than the blood can hold //Blood might be oversaturated, we might have the wrong blood, maybe do something here damage = 0; } else { if (bloodSaturation > info.BLOOD_REAGENT_SATURATION_OKAY) { OxyHeal(BloodContainer.CurrentReagentMix, BloodContainer[requiredReagent] * (bloodSaturation - info.BLOOD_REAGENT_SATURATION_OKAY)); } //We already consumed some earlier as well damage = -1; } AffectDamage(damage, (int)DamageType.Oxy); }