using AlienAttack.MonoGame.Things.Enemies.Ships; using AlienAttack.MonoGame.Things.Muzzles; namespace AlienAttack.MonoGame.Things.Weapons; public class ConfigurableWeapon(WeaponDef def, WeaponState state) : Weapon { public override int FireThreshold => state.FireThreshold; public override void Fire(Sprite owner, SpriteUpdateContext context) { if (owner is not Ship ship) return; foreach (var shot in def.Pattern.Shots) { // muzzle local -> world var muzzleLocal = ship.GetMuzzleLocal(shot.Muzzle); // make a fast lookup var muzzleWorld = MuzzleMath.GetMuzzleWorld(ship, muzzleLocal); // speed upgrade float vx = shot.Velocity.X * state.SpeedMultiplier; float vy = shot.Velocity.Y * state.SpeedMultiplier; // center bullet on muzzle + pattern offset var pos = MuzzleMath.CenterBulletOn(muzzleWorld, def.Bullet.Width, def.Bullet.Height) + shot.Offset; var bullet = def.Bullet.Create(pos.X, pos.Y, vx, vy, owner); // optional: apply damage bonus generically //bullet.Damage += state.DamageBonus; context.SpawnSprite(bullet); } //context.AudioManager.PlayPlayerFire(); // or use _def.FireSfxKey -> audio routing if (owner is Player) { context.AudioManager.PlayPlayerFire(def.Bullet.Kind); } else { context.AudioManager.PlayEnemyFire(def.Bullet.Kind); } } }