Skip to content

Commit

Permalink
fixes people spontaneously suffocating (#6849)
Browse files Browse the repository at this point in the history
* players now will no longer develop Lung and heart cancer

* made body parts moore forgiving

* Now properly fixed, turns out cancers hard to get rid of

* updated SO
  • Loading branch information
Bod9001 committed Jun 23, 2021
1 parent b466200 commit 746b911
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public class CirculatoryInfo : ScriptableObject
public float HEART_STRENGTH_MAX = 150;

[Tooltip("When saturation of blood reagent falls below this point you'll start to feel symptoms, like being light headed.")]
public float BLOOD_REAGENT_SATURATION_OKAY = 0.92f;
public float BLOOD_REAGENT_SATURATION_OKAY = 0.80f;

[Tooltip("When saturation of blood reagent falls below this point the organism will start taking oxy damage.")]
public float BLOOD_REAGENT_SATURATION_BAD = 0.90f;
public float BLOOD_REAGENT_SATURATION_BAD = 0.70f;

[Tooltip("If we reach critical, the organism will very quickly accumalate oxy damage.")]
public float BLOOD_REAGENT_SATURATION_CRITICAL = 0.80f;
public float BLOOD_REAGENT_SATURATION_CRITICAL = 0.50f;
}
23 changes: 21 additions & 2 deletions UnityProject/Assets/Scripts/Items/Implants/Organs/Heart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override void InternalDamageLogic()
base.InternalDamageLogic();
if(RelatedPart.CurrentInternalBleedingDamage > 50 && alarmedForInternalBleeding == false)
{
Chat.AddActionMsgToChat(RelatedPart.HealthMaster.gameObject,
Chat.AddActionMsgToChat(RelatedPart.HealthMaster.gameObject,
$"You feel a sharp pain in your {RelatedPart.gameObject.ExpensiveName()}!", $"{RelatedPart.HealthMaster.PlayerScriptOwner.visibleName} holds their {RelatedPart.gameObject.ExpensiveName()} in pain!");
alarmedForInternalBleeding = true;
}
Expand All @@ -107,7 +107,26 @@ public void DoHeartBeat(LivingHealthMasterBase healthMaster)
return;
}

Heartbeat(RelatedPart.TotalModified);
var TotalModified = 1f;
foreach (var Modifier in RelatedPart.AppliedModifiers)
{
var toMultiply = 1f;
if (Modifier == RelatedPart.DamageModifier)
{
toMultiply = Mathf.Max(0f,Mathf.Max(RelatedPart.MaxHealth - RelatedPart.TotalDamageWithoutOxyCloneRadStam, 0) / RelatedPart.MaxHealth);
}
else if (Modifier == RelatedPart.HungerModifier)
{
continue;
}
else
{
toMultiply = Mathf.Max(0f, Modifier.Multiplier);
}
TotalModified *= toMultiply;
}

Heartbeat(TotalModified);
}


Expand Down
33 changes: 29 additions & 4 deletions UnityProject/Assets/Scripts/Items/Implants/Organs/Lungs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,28 @@ public override void ImplantPeriodicUpdate()
Vector3Int position = RelatedPart.HealthMaster.ObjectBehaviour.AssumedWorldPositionServer();
MetaDataNode node = MatrixManager.GetMetaDataAt(position);

if (TryBreathing(node, RelatedPart.TotalModified))

var TotalModified = 1f;
foreach (var Modifier in RelatedPart.AppliedModifiers)
{
var toMultiply = 1f;
if (Modifier == RelatedPart.DamageModifier)
{
toMultiply = Mathf.Max(0f,Mathf.Max(RelatedPart.MaxHealth - RelatedPart.TotalDamageWithoutOxyCloneRadStam, 0) / RelatedPart.MaxHealth);
}
else if (Modifier == RelatedPart.HungerModifier)
{
continue;
}
else
{
toMultiply = Mathf.Max(0f, Modifier.Multiplier);
}
TotalModified *= toMultiply;
}


if (TryBreathing(node, TotalModified))
{
AtmosManager.Update(node);
}
Expand Down Expand Up @@ -200,13 +221,17 @@ private bool BreatheIn(GasMix breathGasMix, ReagentMix blood, float efficiency)
// Counterintuitively, in humans respiration is stimulated by pressence of CO2 in the blood, not lack of oxygen
// May want to change this code to reflect that in the future so people don't hyperventilate when they are on nitrous oxide
var inGas = GAS2ReagentSingleton.Instance.GetGasToReagent(requiredGas);
var saturation = (toInhale[inGas] + blood[inGas]) / RelatedPart.bloodType.GetGasCapacity(blood);
if (saturation >=RelatedPart.HealthMaster.CirculatorySystem.BloodInfo.BLOOD_REAGENT_SATURATION_OKAY)
float bloodCap = RelatedPart.bloodType.GetGasCapacity(RelatedPart.BloodContainer.CurrentReagentMix);
float foreignCap = RelatedPart.bloodType.GetGasCapacityForeign( RelatedPart.BloodContainer.CurrentReagentMix);
var ratioNativeBlood = bloodCap / ( bloodCap + foreignCap);
float bloodSaturation = RelatedPart.BloodContainer[RelatedPart.requiredReagent] * ratioNativeBlood / bloodCap;

if (bloodSaturation >=RelatedPart.HealthMaster.CirculatorySystem.BloodInfo.BLOOD_REAGENT_SATURATION_OKAY)
{
currentBreatheCooldown = breatheCooldown; //Slow breathing, we're all good
RelatedPart.HealthMaster.HealthStateController.SetSuffocating(false);
}
else if (saturation <= RelatedPart.HealthMaster.CirculatorySystem.BloodInfo.BLOOD_REAGENT_SATURATION_BAD)
else if (bloodSaturation <= RelatedPart.HealthMaster.CirculatorySystem.BloodInfo.BLOOD_REAGENT_SATURATION_BAD)
{
RelatedPart.HealthMaster.HealthStateController.SetSuffocating(true);
if (Random.value < 0.2)
Expand Down

0 comments on commit 746b911

Please sign in to comment.