118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public enum Output {
|
|
Acceleration,
|
|
Deceleration,
|
|
Strafing,
|
|
Shield,
|
|
}
|
|
|
|
public class PowerUnit {
|
|
static float baseOutput = 25.0f;
|
|
static float initialAcceleration = 2f * baseOutput;
|
|
static float initialDeceleration = 4f * baseOutput;
|
|
static float initialStrafing = 1f * baseOutput;
|
|
|
|
float acceleration = initialAcceleration;
|
|
float deceleration = initialDeceleration;
|
|
float strafing = initialStrafing;
|
|
|
|
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 void Init() {
|
|
boostCharges = 0;
|
|
shieldCurrent = initialShieldMax;
|
|
acceleration = initialAcceleration;
|
|
deceleration = initialDeceleration;
|
|
strafing = initialStrafing;
|
|
}
|
|
|
|
// Regeneration of boosts is tracked by the ShipControls
|
|
// it has to handle tracking the coroutines etc
|
|
public void BoostRegenerate() {
|
|
boostCharges = Math.Min(boostCharges + 1, boostMax);
|
|
Debug.Log($"Boosts available {boostCharges}");
|
|
}
|
|
|
|
public bool BoostUse(Output output) {
|
|
if (boostCharges < 1)
|
|
return false;
|
|
|
|
float newOutput = output switch {
|
|
Output.Acceleration => BoostUseAcceleration(),
|
|
Output.Deceleration => BoostUseDeceleration(),
|
|
Output.Strafing => BoostUseStrafing(),
|
|
Output.Shield => BoostUseShields(),
|
|
_ => 0f,
|
|
};
|
|
|
|
// Boosts are immediately used and tracked here
|
|
boostCharges--;
|
|
|
|
Debug.Log($"Set {output} to {newOutput}");
|
|
|
|
return true;
|
|
}
|
|
|
|
float BoostUseAcceleration() => acceleration += baseOutput;
|
|
float BoostUseDeceleration() => deceleration += baseOutput;
|
|
float BoostUseStrafing() => strafing += baseOutput;
|
|
float BoostUseShields() {
|
|
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;
|
|
}
|
|
|
|
// returns whether shield depleted
|
|
public bool ShieldReduce(float amt) {
|
|
shieldCurrent = shieldCurrent - amt;
|
|
return shieldCurrent < 0f;
|
|
}
|
|
|
|
public void ShieldRegenerate() => shieldCurrent = Math.Min(shieldCurrent + shieldRegen, shieldMax);
|
|
void ShieldRegenRecalculate() => shieldRegen = (shieldMax / 5f) * Time.fixedDeltaTime;
|
|
} |