fix power unit shield bug
This commit is contained in:
1 parent
4e44f33204
commit
09bb5bb1f1
3 files changed
+27
-11
No files matched your search
+19
-6
@@ -32,14 +32,16 @@ public class PowerUnit {
|
||||
static float initialShieldMax = 5000f;
|
||||
float shieldCurrent = initialShieldMax;
|
||||
float shieldMax = initialShieldMax;
|
||||
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
|
||||
static float shieldBoostIncrease = 1000f;
|
||||
static float shieldBoostAmount = 1000f;
|
||||
|
||||
public float Shield => shieldCurrent;
|
||||
public float ShieldMax => shieldMax;
|
||||
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
||||
float ShieldRegen => BoostActive.Count switch {
|
||||
0 => (shieldMax / 5f) * Time.fixedDeltaTime,
|
||||
_ => 0f,
|
||||
|
||||
bool UsingMovementBoost => BoostActive.Any(b => b.output != Output.Shield);
|
||||
float ShieldRegen => UsingMovementBoost switch {
|
||||
false => (shieldMax / 5f) * Time.fixedDeltaTime,
|
||||
true => 0f,
|
||||
};
|
||||
|
||||
// Boost
|
||||
@@ -80,6 +82,8 @@ public class PowerUnit {
|
||||
if (boostAvailable < boostDurationSeconds) return;
|
||||
BoostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
|
||||
boostAvailable -= boostDurationSeconds;
|
||||
|
||||
if (output == Output.Shield) ShieldsBoost();
|
||||
}
|
||||
|
||||
public void Tick() {
|
||||
@@ -104,7 +108,7 @@ public class PowerUnit {
|
||||
boostProgress = Math.Max(0f, next);
|
||||
if (delta > 0f) boostAvailable = boostProgress;
|
||||
|
||||
shieldMax = initialShieldMax + BoostActive.Count(b => b.output == Output.Shield) * 1000f;
|
||||
ShieldsSetMax();
|
||||
shieldCurrent = Math.Min(shieldCurrent + ShieldRegen, shieldMax);
|
||||
}
|
||||
|
||||
@@ -113,4 +117,13 @@ public class PowerUnit {
|
||||
shieldCurrent = shieldCurrent - amt;
|
||||
return shieldCurrent < 0f;
|
||||
}
|
||||
|
||||
void ShieldsBoost() {
|
||||
ShieldsSetMax();
|
||||
shieldCurrent = Math.Min(shieldCurrent + shieldBoostIncrease, shieldMax);
|
||||
}
|
||||
|
||||
void ShieldsSetMax() {
|
||||
shieldMax = initialShieldMax + BoostActive.Count(b => b.output == Output.Shield) * shieldBoostAmount;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user