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

@ -67,6 +67,12 @@ public class ConstantWeapon : Weapon, IProgressBehavior
base.Execute(delta);
if (_firing)
{
if (!Entity.TryConsumeEnergy(Context.Evaluate(_data.Energy, Item.EquippableItem, Entity) * delta))
{
_firing = false;
OnStopFiring?.Invoke();
return false;
}
if (_data.AmmoType != Guid.Empty)
{
if (_reloading)
@ -111,7 +117,6 @@ public class ConstantWeapon : Weapon, IProgressBehavior
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta);
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
Entity.Energy -= Context.Evaluate(_data.Energy, Item.EquippableItem, Entity) * delta;
}
return true;
}