protected virtual void CreateProjectiles(Vector2 direction, GameplayObject target, bool playSound)
 {
     if (target != null && (target is ShipModule) && (target as ShipModule).GetParent().Role == "fighter" && this.AltFireMode && this.AltFireTriggerFighter && this.SecondaryFire != null)
     {
         Weapon AltFire = ResourceManager.GetWeapon(this.SecondaryFire);
         Projectile projectile;
         if (this.owner.Projectiles.pendingRemovals.TryPop(out projectile))
         {
             projectile.ProjectileRecreate(this.owner, direction, this.moduleAttachedTo);
             projectile.range = AltFire.Range;
             projectile.weapon = this;
             projectile.explodes = AltFire.explodes;
             projectile.damageAmount = AltFire.DamageAmount;
             projectile.damageRadius = AltFire.DamageRadius;
             projectile.explosionradiusmod = AltFire.ExplosionRadiusVisual;
             projectile.Health = AltFire.HitPoints;
             projectile.speed = AltFire.ProjectileSpeed;
             projectile.WeaponEffectType = AltFire.WeaponEffectType;
             projectile.WeaponType = AltFire.WeaponType;
             projectile.RotationRadsPerSecond = AltFire.RotationRadsPerSecond;
             projectile.ArmorPiercing = (byte)AltFire.ArmourPen;
         }
         else
             projectile = new Projectile(this.owner, direction, this.moduleAttachedTo)
             {
                 range = AltFire.Range,
                 weapon = this,
                 explodes = AltFire.explodes,
                 damageAmount = AltFire.DamageAmount,
                 damageRadius = AltFire.DamageRadius,
                 explosionradiusmod = AltFire.ExplosionRadiusVisual,
                 Health = AltFire.HitPoints,
                 speed = AltFire.ProjectileSpeed,
                 WeaponEffectType = AltFire.WeaponEffectType,
                 WeaponType = AltFire.WeaponType,
                 RotationRadsPerSecond = AltFire.RotationRadsPerSecond,
                 ArmorPiercing = (byte)AltFire.ArmourPen,
             };
         //damage increase by level
         if (this.owner.Level > 0)
         {
             projectile.damageAmount += projectile.damageAmount * (float)this.owner.Level * 0.05f;
         }
         if (AltFire.RangeVariance)
         {
             projectile.range *= RandomMath.RandomBetween(0.9f, 1.1f);
         }
         //Hull bonus damage increase
         if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses)
         {
             HullBonus mod;
             if (ResourceManager.HullBonuses.TryGetValue(this.owner.shipData.Hull, out mod))
                 projectile.damageAmount += projectile.damageAmount * mod.DamageBonus;
         }
         projectile.LoadContent(AltFire.ProjectileTexturePath, AltFire.ModelPath);
         AltFire.ModifyProjectile(projectile);
         if (AltFire.Tag_Guided)
             projectile.InitializeMissile(projectile.speed, direction, target);
         else
             projectile.Initialize(projectile.speed, direction, this.moduleAttachedTo.Center);
         projectile.Radius = this.ProjectileRadius;
         if (AltFire.Animated == 1)
         {
             string remainder = 0.ToString("00000.##");
             projectile.texturePath = string.Concat(AltFire.AnimationPath, remainder);
         }
         //if(HelperFunctions.GetRandomIndex((int)(Ship.universeScreen.Lag *100)) <2)
         if (Weapon.universeScreen.viewState == UniverseScreen.UnivScreenState.ShipView && this.owner.InFrustum && playSound)
         {
             projectile.DieSound = true;
             if (!string.IsNullOrEmpty(this.ToggleSoundName) && (this.ToggleCue == null || this.ToggleCue != null && !this.ToggleCue.IsPlaying))
             {
                 this.ToggleSoundOn = true;
                 this.ToggleCue = AudioManager.GetCue(AltFire.ToggleSoundName);
                 this.ToggleCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                 this.ToggleCue.Play();
                 if (AltFire.fireCue != null)
                 {
                     //Added by McShooterz: Use sounds from new sound dictionary
                     SoundEffect soundeffect = null;
                     if (ResourceManager.SoundEffectDict.TryGetValue(AltFire.fireCueName,out soundeffect))
                     {
                         AudioManager.PlaySoundEffect(soundeffect, Weapon.audioListener, this.owner.emitter, 0.5f);
                     }
                     else
                     {
                         this.fireCue = AudioManager.GetCue(this.fireCueName);
                         if (!this.owner.isPlayerShip())
                         {
                             this.fireCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                         }
                         this.lastFireSound = 0f;
                         if (this.fireCue != null)
                         {
                             this.fireCue.Play();
                         }
                     }
                 }
             }
             if (!string.IsNullOrEmpty(ResourceManager.WeaponsDict[AltFire.UID].dieCue))
             {
                 projectile.dieCueName = ResourceManager.WeaponsDict[AltFire.UID].dieCue;
             }
             if (!string.IsNullOrEmpty(this.InFlightCue))
             {
                 projectile.InFlightCue = AltFire.InFlightCue;
             }
             if (this.ToggleCue == null && this.owner.ProjectilesFired.Count < 30)
             {
                 this.lastFireSound = 0f;
                 this.owner.ProjectilesFired.Add(new ProjectileTracker());
                 //Added by McShooterz: Use sounds from new sound dictionary
                 if (ResourceManager.SoundEffectDict.ContainsKey(AltFire.fireCueName))
                 {
                     AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict[fireCueName], Weapon.audioListener, this.owner.emitter, 0.5f);
                 }
                 else
                 {
                     this.fireCue = AudioManager.GetCue(this.fireCueName);
                     if (!this.owner.isPlayerShip())
                     {
                         this.fireCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                     }
                     if (this.fireCue != null)
                     {
                         this.fireCue.Play();
                     }
                 }
             }
         }
         projectile.isSecondary = true;
         this.owner.Projectiles.Add(projectile);
         projectile = null;
     }
     else
     {
         Projectile projectile;
         if (this.owner.Projectiles.pendingRemovals.TryPop(out projectile))
         {
             projectile.ProjectileRecreate(this.owner, direction, this.moduleAttachedTo);
             projectile.range = this.Range;
             projectile.weapon = this;
             projectile.explodes = this.explodes;
             projectile.damageAmount = this.DamageAmount;
             projectile.damageRadius = this.DamageRadius;
             projectile.explosionradiusmod = this.ExplosionRadiusVisual;
             projectile.Health = this.HitPoints;
             projectile.speed = this.ProjectileSpeed;
             projectile.WeaponEffectType = this.WeaponEffectType;
             projectile.WeaponType = this.WeaponType;
             projectile.RotationRadsPerSecond = this.RotationRadsPerSecond;
             projectile.ArmorPiercing = (byte)this.ArmourPen;
         }
         projectile = new Projectile(this.owner, direction, this.moduleAttachedTo)
         {
             range = this.Range,
             weapon = this,
             explodes = this.explodes,
             damageAmount = this.DamageAmount,
             damageRadius = this.DamageRadius,
             explosionradiusmod = this.ExplosionRadiusVisual,
             Health = this.HitPoints,
             speed = this.ProjectileSpeed,
             WeaponEffectType = this.WeaponEffectType,
             WeaponType = this.WeaponType,
             RotationRadsPerSecond = this.RotationRadsPerSecond,
             ArmorPiercing = (byte)this.ArmourPen,
         };
         //damage increase by level
         if (this.owner.Level > 0)
         {
             projectile.damageAmount += projectile.damageAmount * (float)this.owner.Level * 0.05f;
         }
         if (this.RangeVariance)
         {
             projectile.range *= RandomMath.RandomBetween(0.9f, 1.1f);
         }
         //Hull bonus damage increase
         if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses)
         {
             HullBonus mod;
             if (ResourceManager.HullBonuses.TryGetValue(this.owner.shipData.Hull, out mod))
                 projectile.damageAmount += projectile.damageAmount * mod.DamageBonus;
         }
         projectile.LoadContent(this.ProjectileTexturePath, this.ModelPath);
         this.ModifyProjectile(projectile);
         if (this.Tag_Guided)
             projectile.InitializeMissile(projectile.speed, direction, target);
         else
             projectile.Initialize(projectile.speed, direction, this.moduleAttachedTo.Center);
         projectile.Radius = this.ProjectileRadius;
         if (this.Animated == 1)
         {
             string remainder = 0.ToString("00000.##");
             projectile.texturePath = string.Concat(this.AnimationPath, remainder);
         }
         if (Weapon.universeScreen.viewState == UniverseScreen.UnivScreenState.ShipView && this.owner.InFrustum && playSound)
         {
             projectile.DieSound = true;
             if (!string.IsNullOrEmpty(this.ToggleSoundName) && (this.ToggleCue == null || this.ToggleCue != null && !this.ToggleCue.IsPlaying))
             {
                 this.ToggleSoundOn = true;
                 this.ToggleCue = AudioManager.GetCue(this.ToggleSoundName);
                 this.ToggleCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                 this.ToggleCue.Play();
                 if (this.fireCue != null)
                 {
                     //Added by McShooterz: Use sounds from new sound dictionary
                     if (ResourceManager.SoundEffectDict.ContainsKey(this.fireCueName))
                     {
                         AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict[fireCueName], Weapon.audioListener, this.owner.emitter, 0.5f);
                     }
                     else
                     {
                         this.fireCue = AudioManager.GetCue(this.fireCueName);
                         if (!this.owner.isPlayerShip())
                         {
                             this.fireCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                         }
                         this.lastFireSound = 0f;
                         if (this.fireCue != null)
                         {
                             this.fireCue.Play();
                         }
                     }
                 }
             }
             if (!string.IsNullOrEmpty(ResourceManager.WeaponsDict[this.UID].dieCue))
             {
                 projectile.dieCueName = ResourceManager.WeaponsDict[this.UID].dieCue;
             }
             if (!string.IsNullOrEmpty(this.InFlightCue))
             {
                 projectile.InFlightCue = this.InFlightCue;
             }
             if (this.ToggleCue == null && this.owner.ProjectilesFired.Count < 30)
             {
                 this.lastFireSound = 0f;
                 this.owner.ProjectilesFired.Add(new ProjectileTracker());
                 //Added by McShooterz: Use sounds from new sound dictionary
                 if (ResourceManager.SoundEffectDict.ContainsKey(this.fireCueName))
                 {
                     AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict[fireCueName], Weapon.audioListener, this.owner.emitter, 0.5f);
                 }
                 else
                 {
                     this.fireCue = AudioManager.GetCue(this.fireCueName);
                     if (!this.owner.isPlayerShip())
                     {
                         this.fireCue.Apply3D(Weapon.audioListener, this.owner.emitter);
                     }
                     if (this.fireCue != null)
                     {
                         this.fireCue.Play();
                     }
                 }
             }
         }
         this.owner.Projectiles.Add(projectile);
         projectile = null;
     }
 }
 public Projectile LoadProjectiles(Vector2 direction, Ship owner)
 {
     Projectile projectile = new Projectile(owner, direction)
     {
         range = this.Range,
         weapon = this,
         explodes = this.explodes,
         damageAmount = this.DamageAmount
     };
     projectile.explodes = this.explodes;
     projectile.damageRadius = this.DamageRadius;
     projectile.explosionradiusmod = this.ExplosionRadiusVisual;
     projectile.speed = this.ProjectileSpeed;
     projectile.WeaponEffectType = this.WeaponEffectType;
     projectile.WeaponType = this.WeaponType;
     projectile.Initialize(this.ProjectileSpeed, direction, owner.Center);
     projectile.Radius = this.ProjectileRadius;
     projectile.LoadContent(this.ProjectileTexturePath, this.ModelPath);
     if (owner.GetSystem() != null && owner.GetSystem().isVisible || owner.isInDeepSpace)
     {
         int numberSameWeapons = 0;
         //this.toggleTimer = 0f;
         foreach (Weapon w in owner.Weapons)
         {
             if (w == this || !(w.Name == this.Name) || w.timeToNextFire > 0f)
             {
                 continue;
             }
             numberSameWeapons++;
         }
         projectile.DieSound = true;
         if (!string.IsNullOrEmpty(ResourceManager.WeaponsDict[this.UID].dieCue))
         {
             projectile.dieCueName = ResourceManager.WeaponsDict[this.UID].dieCue;
         }
         if (!string.IsNullOrEmpty(this.InFlightCue))
         {
             projectile.InFlightCue = this.InFlightCue;
         }
     }
     return projectile;
 }