Skip to content

Commit

Permalink
fix: set activation cost of continous weapons to energy/sec * livetime
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelZinchenko committed Dec 10, 2023
1 parent ca7e70f commit f7e4a43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ public ContinuousCannon(IWeaponPlatform platform, WeaponStats weaponStats, Facto
_bulletFactory = bulletFactory;
_platform = platform;
_energyConsumption = bulletFactory.Stats.EnergyCost;
_activationCost = bulletFactory.Stats.ActivationCost;
_spread = weaponStats.Spread;

Info = new WeaponInfo(WeaponType.Continuous, _spread, bulletFactory, platform);
}

public override bool CanBeActivated { get { return base.CanBeActivated && (HasActiveBullet || _platform.IsReady && _platform.EnergyPoints.Value > _energyConsumption * 0.5f); } }
public override float Cooldown { get { return Mathf.Max(base.Cooldown, _platform.Cooldown); } }
public override bool CanBeActivated => base.CanBeActivated && (HasActiveBullet || _platform.IsReady);
public override float Cooldown => Mathf.Max(base.Cooldown, _platform.Cooldown);

public WeaponInfo Info { get; private set; }
public IWeaponPlatform Platform { get { return _platform; } }
public float PowerLevel { get { return 1.0f; } }
public IBullet ActiveBullet { get { return HasActiveBullet ? _activeBullet : null; } }
public WeaponInfo Info { get; private set; }
public IWeaponPlatform Platform { get { return _platform; } }
public float PowerLevel { get { return 1.0f; } }
public IBullet ActiveBullet { get { return HasActiveBullet ? _activeBullet : null; } }

protected override void OnUpdateView(float elapsedTime) {}
protected override void OnUpdateView(float elapsedTime) {}

protected override void OnUpdatePhysics(float elapsedTime)
{
Expand All @@ -49,7 +50,7 @@ protected override void OnUpdatePhysics(float elapsedTime)
InvokeTriggers(ConditionType.OnDeactivate);
}
}
else if (Active && CanBeActivated)
else if (Active && CanBeActivated && _platform.EnergyPoints.TryGet(_activationCost))
{
Shot();
InvokeTriggers(ConditionType.OnActivate);
Expand All @@ -66,11 +67,12 @@ private void Shot()
_activeBullet.Lifetime.Restore();
}

private bool HasActiveBullet { get { return _activeBullet.IsActive(); } }
private bool HasActiveBullet { get { return _activeBullet.IsActive(); } }

private IBullet _activeBullet;
private IBullet _activeBullet;
private readonly float _spread;
private readonly float _energyConsumption;
private readonly float _activationCost;
private readonly IWeaponPlatform _platform;
private readonly Factory.IBulletFactory _bulletFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public interface IBulletStats
Color FlashColor { get; }
float FlashTime { get; }

float EnergyCost { get; }
float BulletSpeed { get; }
float EnergyCost { get; }
float ActivationCost { get; }
float BulletSpeed { get; }
float BulletHitRange { get; }
float Recoil { get; }
bool IgnoresShipSpeed { get; }
Expand Down Expand Up @@ -81,9 +82,10 @@ public Component.Systems.Weapons.BulletEffectType EffectType
public float BulletHitRange { get { return _ammunition.Body.Type == BulletType.Continuous ? Range : Range + BodySize; } }
public float BulletSpeed { get { return _ammunition.Body.Velocity * _statModifier.VelocityMultiplier.Value; } }
public float EnergyCost { get { return _ammunition.Body.EnergyCost * _statModifier.EnergyCostMultiplier.Value; } }
public bool IgnoresShipSpeed { get { return _ammunition.Body.Type == BulletType.Static; } }
public bool IgnoresShipSpeed { get { return _ammunition.Body.Type == BulletType.Static; } }
public float ActivationCost => _ammunition.Body.Type == BulletType.Continuous ? EnergyCost * _ammunition.Body.Lifetime : EnergyCost;

public float Recoil
public float Recoil
{
get
{
Expand Down Expand Up @@ -183,10 +185,11 @@ public BulletStatsObsolete(AmmunitionObsoleteStats ammunition)
public float Recoil { get { return _stats.Recoil * SizeMultiplier; } }
public float AreaOfEffect { get { return _stats.AreaOfEffect * SizeMultiplier; } }
public float Velocity { get { return _stats.Velocity; } }
public float EnergyCost { get { return _stats.EnergyCost; } }
public bool IgnoresShipSpeed { get { return _stats.IgnoresShipVelocity; } }
public float EnergyCost { get { return _stats.EnergyCost; } }
public bool IgnoresShipSpeed { get { return _stats.IgnoresShipVelocity; } }
public float ActivationCost => _stats.AmmunitionClass.IsBeam() ? EnergyCost * _stats.LifeTime : EnergyCost;

public float BulletSpeed { get { return Velocity; } }
public float BulletSpeed { get { return Velocity; } }
public float BulletHitRange { get { return Mathf.Max(Range, AreaOfEffect); } }

private float RangeMultiplier { get { return PowerLevel > 0.1f ? PowerLevel : 0f; } }
Expand Down

0 comments on commit f7e4a43

Please sign in to comment.