Centralized Energy Generation

Energy consumption is now handled by the entity code via the TryConsumeEnergy function, will return false when out of power.
This commit is contained in:
Reinier Vens 2021-03-02 23:02:19 +00:00
commit 56f97d82f9
7 changed files with 120 additions and 54 deletions

View file

@ -153,6 +153,11 @@ public class InstantWeapon : Weapon, IProgressBehavior
_burstTimer += delta;
while (_burstRemaining > 0 && _burstTimer > 0)
{
if (!Entity.TryConsumeEnergy(Energy))
{
_burstRemaining = 0;
return false;
}
// If 1 ammo is consumed per shot in the burst, perform ammo consumption here
// UseAmmo returns false when triggering reload; cancel firing if that is the case
if (!_data.SingleAmmoBurst && !UseAmmo()) return false;
@ -162,7 +167,6 @@ public class InstantWeapon : Weapon, IProgressBehavior
OnFire?.Invoke();
Item.AddHeat(Heat);
Entity.VisibilitySources[this] = Visibility;
Entity.Energy -= Energy;
}
return true;
}