boost rework wip

This commit is contained in:
ntr committed 2023-08-15 14:35:49 +10:00
1 parent 46d742dfa8
commit fddf8552c2
3 files changed
+286 -340

No files matched your search

+50 -70
View File
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum Output {
@@ -9,6 +11,10 @@ public enum Output {
}
public class PowerUnit {
static float stablisation = 75f;
public float Stabilisation => stablisation;
// Outputs
static float baseOutput = 25.0f;
static float initialAcceleration = 2f * baseOutput;
static float initialDeceleration = 4f * baseOutput;
@@ -18,94 +24,71 @@ public class PowerUnit {
float deceleration = initialDeceleration;
float strafing = initialStrafing;
// public float Acceleration => acceleration;
// public float Deceleration => deceleration;
// public float Strafing => strafing;
// Shields
static float initialShieldMax = 5000f;
float shieldCurrent = initialShieldMax;
float shieldMax = initialShieldMax;
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
int boostMax = 2;
int boostCharges = 0;
static float stablisation = 75f;
public float Acceleration => acceleration;
public float Deceleration => deceleration;
public float Strafing => strafing;
public float Shield => shieldCurrent;
public float ShieldMax => shieldMax;
public float Stabilisation => stablisation;
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
public string BoostsAvailable => $"{boostCharges}";
public bool BoostRecharging => boostCharges < boostMax;
float ShieldRegen => (shieldMax / 5f) * Time.fixedDeltaTime;
public void Init() {
boostCharges = 0;
// Boost
List<(Output output, double expiresAt)> boostActive = new();
static double boostFullChargeSeconds = 10f;
static double boostDurationSeconds = 2f;
double boostMax = 2f * boostDurationSeconds;
double boostAvailable = 0f;
// public string BoostAvailable => $"{boostAvailable}";
public string BoostAvailable => $"{((boostAvailable / boostMax) * 100f):0}";
public float Acceleration =>
acceleration + boostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
public float Deceleration =>
deceleration + boostActive.Count(b => b.output == Output.Deceleration) * baseOutput;
public float Strafing =>
strafing + boostActive.Count(b => b.output == Output.Strafing) * baseOutput;
double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime;
public void Reset() {
shieldCurrent = initialShieldMax;
acceleration = initialAcceleration;
deceleration = initialDeceleration;
strafing = initialStrafing;
boostActive = new();
}
// Regeneration of boosts is tracked by the ShipControls
// it has to handle tracking the coroutines etc
public void BoostGenerate() {
boostCharges = Math.Min(boostCharges + 1, boostMax);
Debug.Log($"Boosts available {boostCharges}");
public void Deploy(Output output) {
boostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
}
public bool BoostDeploy(Output output) {
if (boostCharges < 1)
return false;
public void Tick() {
// remove expired boosts
boostActive = boostActive.Where(b => b.expiresAt > Time.timeAsDouble).ToList();
float newOutput = output switch {
Output.Acceleration => BoostDeployAcceleration(),
Output.Deceleration => BoostDeployDeceleration(),
Output.Strafing => BoostDeployStrafing(),
Output.Shield => BoostDeployShields(),
_ => 0f,
double delta = boostActive.Count switch {
// if there are no boosts active we can increase the store
0 => BoostRegen,
// if there are active boosts we deplete it
int count => count * Time.fixedDeltaTime,
};
// Boosts are immediately used and tracked here
boostCharges--;
double next = Math.Min(boostAvailable + delta, boostMax);
boostAvailable = Math.Max(0f, next);
Debug.Log($"Set {output} to {newOutput}");
return true;
}
float BoostDeployAcceleration() => acceleration += baseOutput;
float BoostDeployDeceleration() => deceleration += baseOutput;
float BoostDeployStrafing() => strafing += baseOutput;
float BoostDeployShields() {
float shieldFrac = shieldMax / shieldCurrent;
shieldMax = 7000f;
shieldCurrent = shieldMax * shieldFrac;
ShieldRegenRecalculate();
return shieldMax;
}
public void BoostEnd(Output output) {
float newOutput = output switch {
Output.Acceleration => BoostEndAcceleration(),
Output.Deceleration => BoostEndDeceleration(),
Output.Strafing => BoostEndStrafing(),
Output.Shield => BoostEndShields(),
_ => 0f,
};
Debug.Log($"Set {output} to {newOutput}");
}
float BoostEndAcceleration() => acceleration -= baseOutput;
float BoostEndDeceleration() => deceleration -= baseOutput;
float BoostEndStrafing() => strafing -= baseOutput;
float BoostEndShields() {
float shieldFrac = shieldMax / shieldCurrent;
shieldMax = 5000f;
shieldCurrent = shieldMax * shieldFrac;
ShieldRegenRecalculate();
return shieldMax;
shieldMax = initialShieldMax + boostActive.Count(b => b.output == Output.Shield) * 1000f;
shieldCurrent = Math.Min(shieldCurrent + ShieldRegen, shieldMax);
}
// returns whether shield depleted
@@ -113,7 +96,4 @@ public class PowerUnit {
shieldCurrent = shieldCurrent - amt;
return shieldCurrent < 0f;
}
public void ShieldRegenerate() => shieldCurrent = Math.Min(shieldCurrent + shieldRegen, shieldMax);
void ShieldRegenRecalculate() => shieldRegen = (shieldMax / 5f) * Time.fixedDeltaTime;
}