Abstract BulletInfo component that defines shooting behavior. It provides an abstract Shoot method, a helper to compute random spread vectors, and logic to decide whether to spawn a tracer based on per-shot chance and a global shot budget.
using System;
namespace SWB.Base;
public abstract class BulletInfo : Component
{
public abstract void Shoot( Weapon weapon, bool isPrimary, Vector3 spreadOffset );
public Vector3 GetRandomSpread( float spread )
{
return (Vector3.Random + Vector3.Random + Vector3.Random + Vector3.Random) * spread * 0.25f;
}
public virtual bool ShouldSpawnTracer( ShootInfo shootInfo )
{
if ( shootInfo.BulletTracerParticle is null )
return false;
var randVal = Random.Shared.NextDouble();
if ( randVal >= shootInfo.BulletTracerChance ) return false;
// ⛔ THE PER-SHOT BUDGET, NOT A SECOND CHANCE ROLL. Chance thins tracers
// statistically and cannot bound them: at 0.33 a 96-projectile Olympia burst still
// draws about 32 clones in one frame. This bounds the count outright.
return NZombies.BulletTracers.TakeShotBudget();
}
}