Player/Tools/MortarTool.cs
namespace PlanetMeat;

[Title( "Mortar" ), Icon( "flare" )]
public sealed class MortarTool : PlayerTool, IUpgradeableAttack, IUpgradeableStrike
{
	private static GameObject ExplosionPrefab => GameObject.GetPrefab( "tools/strike/strike_explosion.prefab" );

	public const float MORTAR_TOOL_COOLDOWN = 7.5f;
	public override float BaseCooldown => MORTAR_TOOL_COOLDOWN;

	public ValueAggregator<int> AggregateDamage => field ??= ValueAggregator<int>.FromImprovement( "mortar_dmg", 10 );
	public ValueAggregator<int> AggregateSize => field ??= ValueAggregator<int>.FromImprovement( "mortar_size", 100 );
	public ValueAggregator<float> AggregateSpeed => field ??= ValueAggregator<float>.FromImprovement( "mortar_speed", 0.2f );
	public ValueAggregator<float> AggregateAccuracy => field ??= ValueAggregator<float>.FromImprovement( "mortar_acc", 0.2f );

	protected override IWorldRing NextWorldRing => StrikeRing.Create( WorldPosition, this.GetStrikeSize(), this.GetStrikeScatterDistance() );

	public override void OnPlaceEnded( Vector3 position )
	{
		base.OnPlaceEnded( position );
		if ( IsUsable )
		{
			StartCooldown();

			var finalPosition = position + this.GetNextStrikeScatter();
			var finalRadius = this.GetStrikeSize();
			var finalDuration = 1.0f / this.GetStrikeSpeed();

			(CreateWorldRing( position ) as StrikeRing).ZeroInOn( finalPosition, finalRadius, finalDuration );
			if ( ExplosionPrefab.Clone( finalPosition ).Components.Get<DelayedExplosion>() is DelayedExplosion explosion )
			{
				explosion.ApplyConfig(
					finalDuration,
					this.GetAttackDamage(),
					finalRadius
				);
				explosion.Blame( GameObject );
			}
		}
	}
}