Added a small grace period to survival mechanic to allow easier start of the game.
This commit is contained in:
@@ -6,6 +6,7 @@ public class SurvivalState
|
||||
private const float ThirstDrainPerSecond = 0.018f;
|
||||
private const float PassiveEnergyDrainPerSecond = 0.01f;
|
||||
private const float AutoConsumeThreshold = 30f;
|
||||
private const double GracePeriodSeconds = 900.0;
|
||||
|
||||
public float hunger = 100f;
|
||||
public float thirst = 100f;
|
||||
@@ -18,14 +19,19 @@ public class SurvivalState
|
||||
public bool isDead = false;
|
||||
public string deathReason = "";
|
||||
public string currentStatus = "";
|
||||
public double elapsedSeconds = 0;
|
||||
public bool gracePeriodEnabled = true;
|
||||
|
||||
public void Update(double delta)
|
||||
{
|
||||
if (isDead) return;
|
||||
|
||||
hunger = Math.Clamp(hunger - HungerDrainPerSecond * (float)delta, 0f, maxHunger);
|
||||
thirst = Math.Clamp(thirst - ThirstDrainPerSecond * (float)delta, 0f, maxThirst);
|
||||
energy = Math.Clamp(energy - PassiveEnergyDrainPerSecond * (float)delta, 0f, maxEnergy);
|
||||
elapsedSeconds += delta;
|
||||
float drainModifier = IsInGracePeriod() ? 0.35f : 1f;
|
||||
|
||||
hunger = Math.Clamp(hunger - HungerDrainPerSecond * drainModifier * (float)delta, 0f, maxHunger);
|
||||
thirst = Math.Clamp(thirst - ThirstDrainPerSecond * drainModifier * (float)delta, 0f, maxThirst);
|
||||
energy = Math.Clamp(energy - PassiveEnergyDrainPerSecond * drainModifier * (float)delta, 0f, maxEnergy);
|
||||
|
||||
TryAutoConsumeFood();
|
||||
TryAutoConsumeWater();
|
||||
@@ -106,6 +112,14 @@ public class SurvivalState
|
||||
|
||||
private void CheckDeath()
|
||||
{
|
||||
if (IsInGracePeriod())
|
||||
{
|
||||
hunger = Math.Max(hunger, 1f);
|
||||
thirst = Math.Max(thirst, 1f);
|
||||
energy = Math.Max(energy, 1f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hunger <= 0f)
|
||||
{
|
||||
KillPlayer("Starved");
|
||||
@@ -131,4 +145,9 @@ public class SurvivalState
|
||||
currentStatus = "Survival failed: " + reason;
|
||||
GameData.canMove = false;
|
||||
}
|
||||
|
||||
private bool IsInGracePeriod()
|
||||
{
|
||||
return gracePeriodEnabled && elapsedSeconds < GracePeriodSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user