Weapons/CrossbowProjectile.cs
namespace Sandbox;

internal class CrossbowProjectile : Projectile, IKillIcon
{
	[Property]
	public Curve Curve { get; set; }

	[Property]
	public float ExplosiveDamage { get; set; } = 70f;

	[Property]
	public float Radius { get; set; } = 128.0f;

	[Property]
	Texture IKillIcon.DisplayIcon { get; set; }

	protected override void OnHit( Collision collision = default )
	{
		CreateEffects( collision.Contact.Point + (collision.Contact.Speed.Normal * 32) );

		// Direct hit, just kill the player
		if ( collision.Other.GameObject.GetComponentInParent<Player>() is Player player && player.IsValid() )
		{
			player.OnDamage( new DamageInfo( 200, Instigator?.Player?.GameObject, GameObject ) );
		}
		else
		{
			// Explode in radius
			Damage.Radius( collision.Contact.Point, Radius, ExplosiveDamage, [DamageTags.Explosion], GameObject, GameObject, Curve, Instigator );
		}

		GameObject.Destroy();
	}

	[Rpc.Broadcast( NetFlags.HostOnly )]
	private void CreateEffects( Vector3 position )
	{
		if ( Application.IsDedicatedServer ) return;

		Effects.SpawnExplosionSmall( position );
	}
}