public void SetAttributesNoParent()
 {
     switch (this.ModuleType)
     {
         case ShipModuleType.Turret:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.InstalledWeapon.isTurret = true;
             break;
         case ShipModuleType.MainGun:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.isMainGun = true;
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             break;
         case ShipModuleType.MissileLauncher:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             break;
         case ShipModuleType.Drone:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             break;
         case ShipModuleType.Spacebomb:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             break;
     }
     this.Health = this.HealthMax;
 }
        //Added by McShooterz: modifies weapon stats to reflect weapon tag bonuses
        private float ModifiedWeaponStat(Weapon weapon, string stat)
        {
            float value=0;

            switch (stat)
            {
                case "damage":
                    value = weapon.DamageAmount;
                    break;
                case "range":
                    value = weapon.Range;
                    break;
                case "speed":
                    value = weapon.ProjectileSpeed;
                    break;
                case "firedelay":
                    value = weapon.fireDelay;
                    break;
                case "armor":
                    value = weapon.EffectVsArmor;
                    break;
                case "shield":
                    value = weapon.EffectVSShields;
                    break;
            }

            if (weapon.Tag_Missile)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Missile"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Energy)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Energy"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Torpedo)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Torpedo"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Kinetic)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Kinetic"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Hybrid)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Hybrid"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Railgun)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Railgun"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Explosive)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Explosive"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Guided)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Guided"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Intercept)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Intercept"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_PD)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["PD"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_SpaceBomb)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Spacebomb"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_BioWeapon)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["BioWeapon"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Drone)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Drone"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Subspace)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Subspace"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Warp)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Warp"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Cannon)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Cannon"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Beam)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Beam"].ShieldDamage;
                        break;
                }
            }
            if (weapon.Tag_Bomb)
            {
                switch (stat)
                {
                    case "damage":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].Damage;
                        break;
                    case "range":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].Range;
                        break;
                    case "speed":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].Speed;
                        break;
                    case "firedelay":
                        value -= value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].Rate;
                        break;
                    case "armor":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].ArmorDamage;
                        break;
                    case "shield":
                        value += value * EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).data.WeaponTags["Bomb"].ShieldDamage;
                        break;
                }
            }
            return value;
        }
 public static Weapon GetWeapon(string uid)
 {
     Weapon w = new Weapon()
     {
         FakeExplode = Ship_Game.ResourceManager.WeaponsDict[uid].FakeExplode,
         Animated = Ship_Game.ResourceManager.WeaponsDict[uid].Animated,
         AnimationPath = Ship_Game.ResourceManager.WeaponsDict[uid].AnimationPath,
         BeamPowerCostPerSecond = Ship_Game.ResourceManager.WeaponsDict[uid].BeamPowerCostPerSecond,
         BeamThickness = Ship_Game.ResourceManager.WeaponsDict[uid].BeamThickness,
         BeamDuration = Ship_Game.ResourceManager.WeaponsDict[uid].BeamDuration,
         BombPopulationKillPerHit = Ship_Game.ResourceManager.WeaponsDict[uid].BombPopulationKillPerHit,
         BombTroopDamage_Max = Ship_Game.ResourceManager.WeaponsDict[uid].BombTroopDamage_Max,
         BombTroopDamage_Min = Ship_Game.ResourceManager.WeaponsDict[uid].BombTroopDamage_Min,
         DamageAmount = Ship_Game.ResourceManager.WeaponsDict[uid].DamageAmount,
         DamageRadius = Ship_Game.ResourceManager.WeaponsDict[uid].DamageRadius,
         EMPDamage = Ship_Game.ResourceManager.WeaponsDict[uid].EMPDamage,
         ExpColor = Ship_Game.ResourceManager.WeaponsDict[uid].ExpColor,
         explodes = Ship_Game.ResourceManager.WeaponsDict[uid].explodes,
         FireArc = Ship_Game.ResourceManager.WeaponsDict[uid].FireArc,
         FireCone = Ship_Game.ResourceManager.WeaponsDict[uid].FireCone,
         fireCueName = Ship_Game.ResourceManager.WeaponsDict[uid].fireCueName,
         fireDelay = Ship_Game.ResourceManager.WeaponsDict[uid].fireDelay,
         Frames = Ship_Game.ResourceManager.WeaponsDict[uid].Frames,
         HitPoints = Ship_Game.ResourceManager.WeaponsDict[uid].HitPoints,
         InFlightCue = Ship_Game.ResourceManager.WeaponsDict[uid].InFlightCue,
         isBeam = Ship_Game.ResourceManager.WeaponsDict[uid].isBeam,
         isMainGun = Ship_Game.ResourceManager.WeaponsDict[uid].isMainGun,
         isTurret = Ship_Game.ResourceManager.WeaponsDict[uid].isTurret,
         Light = Ship_Game.ResourceManager.WeaponsDict[uid].Light,
         LoopAnimation = Ship_Game.ResourceManager.WeaponsDict[uid].LoopAnimation,
         MassDamage = Ship_Game.ResourceManager.WeaponsDict[uid].MassDamage,
         ModelPath = Ship_Game.ResourceManager.WeaponsDict[uid].ModelPath,
         MuzzleFlash = Ship_Game.ResourceManager.WeaponsDict[uid].MuzzleFlash,
         Name = Ship_Game.ResourceManager.WeaponsDict[uid].Name,
         OrdinanceRequiredToFire = Ship_Game.ResourceManager.WeaponsDict[uid].OrdinanceRequiredToFire,
         particleDelay = Ship_Game.ResourceManager.WeaponsDict[uid].particleDelay,
         PowerDamage = Ship_Game.ResourceManager.WeaponsDict[uid].PowerDamage,
         PowerRequiredToFire = Ship_Game.ResourceManager.WeaponsDict[uid].PowerRequiredToFire,
         ProjectileCount = Ship_Game.ResourceManager.WeaponsDict[uid].ProjectileCount,
         ProjectileRadius = Ship_Game.ResourceManager.WeaponsDict[uid].ProjectileRadius,
         ProjectileSpeed = Ship_Game.ResourceManager.WeaponsDict[uid].ProjectileSpeed,
         ProjectileTexturePath = Ship_Game.ResourceManager.WeaponsDict[uid].ProjectileTexturePath,
         Range = Ship_Game.ResourceManager.WeaponsDict[uid].Range,
         RepulsionDamage = Ship_Game.ResourceManager.WeaponsDict[uid].RepulsionDamage,
         Scale = Ship_Game.ResourceManager.WeaponsDict[uid].Scale,
         ShieldPenChance = Ship_Game.ResourceManager.WeaponsDict[uid].ShieldPenChance,
         SiphonDamage = Ship_Game.ResourceManager.WeaponsDict[uid].SiphonDamage,
         ToggleSoundName = Ship_Game.ResourceManager.WeaponsDict[uid].ToggleSoundName,
         TroopDamageChance = Ship_Game.ResourceManager.WeaponsDict[uid].TroopDamageChance,
         UID = Ship_Game.ResourceManager.WeaponsDict[uid].UID,
         WeaponEffectType = Ship_Game.ResourceManager.WeaponsDict[uid].WeaponEffectType,
         WeaponType = Ship_Game.ResourceManager.WeaponsDict[uid].WeaponType,
         IsRepairDrone = Ship_Game.ResourceManager.WeaponsDict[uid].IsRepairDrone,
         HitsFriendlies = Ship_Game.ResourceManager.WeaponsDict[uid].HitsFriendlies,
         BombHardDamageMax = Ship_Game.ResourceManager.WeaponsDict[uid].BombHardDamageMax,
         BombHardDamageMin = Ship_Game.ResourceManager.WeaponsDict[uid].BombHardDamageMin,
         HardCodedAction = Ship_Game.ResourceManager.WeaponsDict[uid].HardCodedAction,
         TruePD = Ship_Game.ResourceManager.WeaponsDict[uid].TruePD,
         SalvoCount = Ship_Game.ResourceManager.WeaponsDict[uid].SalvoCount,
         SalvoTimer = Ship_Game.ResourceManager.WeaponsDict[uid].SalvoTimer,
         PlaySoundOncePerSalvo = Ship_Game.ResourceManager.WeaponsDict[uid].PlaySoundOncePerSalvo,
         EffectVsArmor = Ship_Game.ResourceManager.WeaponsDict[uid].EffectVsArmor,
         EffectVSShields = Ship_Game.ResourceManager.WeaponsDict[uid].EffectVSShields,
         RotationRadsPerSecond = Ship_Game.ResourceManager.WeaponsDict[uid].RotationRadsPerSecond,
         Tag_Beam = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Beam,
         Tag_Energy = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Energy,
         Tag_Explosive = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Explosive,
         Tag_Guided = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Guided,
         Tag_Hybrid = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Hybrid,
         Tag_Intercept = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Intercept,
         Tag_Kinetic = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Kinetic,
         Tag_Missile = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Missile,
         Tag_Railgun = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Railgun,
         Tag_Warp = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Warp,
         Tag_Torpedo = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Torpedo,
         Tag_Subspace = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Subspace,
         Tag_Cannon = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Cannon,
         Tag_Bomb = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Bomb,
         Tag_Drone = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Drone,
         Tag_BioWeapon = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_BioWeapon,
         Tag_PD = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_PD,
         Tag_Array = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Array,
         Tag_Flak = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Flak,
         Tag_Tractor = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_Tractor,
         Tag_SpaceBomb = Ship_Game.ResourceManager.WeaponsDict[uid].Tag_SpaceBomb,
         ECMResist = Ship_Game.ResourceManager.WeaponsDict[uid].ECMResist,
         Excludes_Fighters = Ship_Game.ResourceManager.WeaponsDict[uid].Excludes_Fighters,
         Excludes_Corvettes = Ship_Game.ResourceManager.WeaponsDict[uid].Excludes_Corvettes,
         Excludes_Capitals = Ship_Game.ResourceManager.WeaponsDict[uid].Excludes_Capitals,
         Excludes_Stations = Ship_Game.ResourceManager.WeaponsDict[uid].Excludes_Stations,
         isRepairBeam = Ship_Game.ResourceManager.WeaponsDict[uid].isRepairBeam,
         ExplosionRadiusVisual = Ship_Game.ResourceManager.WeaponsDict[uid].ExplosionRadiusVisual,
         TerminalPhaseAttack = Ship_Game.ResourceManager.WeaponsDict[uid].TerminalPhaseAttack,
         TerminalPhaseDistance = Ship_Game.ResourceManager.WeaponsDict[uid].TerminalPhaseDistance,
         TerminalPhaseSpeedMod = Ship_Game.ResourceManager.WeaponsDict[uid].TerminalPhaseSpeedMod,
         ArmourPen = Ship_Game.ResourceManager.WeaponsDict[uid].ArmourPen,
         RangeVariance = Ship_Game.ResourceManager.WeaponsDict[uid].RangeVariance,
         ExplosionFlash = Ship_Game.ResourceManager.WeaponsDict[uid].ExplosionFlash,
         AltFireMode = Ship_Game.ResourceManager.WeaponsDict[uid].AltFireMode,
         AltFireTriggerFighter = Ship_Game.ResourceManager.WeaponsDict[uid].AltFireTriggerFighter,
         SecondaryFire = Ship_Game.ResourceManager.WeaponsDict[uid].SecondaryFire
     };
     return w;
 }
 public void SetAttributesByType()
 {
     switch (this.ModuleType)
     {
         case ShipModuleType.Turret:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.InstalledWeapon.isTurret = true;
             this.Parent.Weapons.Add(this.InstalledWeapon);
             break;
         case ShipModuleType.MainGun:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.isMainGun = true;
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.Parent.Weapons.Add(this.InstalledWeapon);
             break;
         case ShipModuleType.MissileLauncher:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.Parent.Weapons.Add(this.InstalledWeapon);
             break;
         case ShipModuleType.Colony:
             this.Parent.isColonyShip = true;
             break;
         case ShipModuleType.Bomb:
             this.Parent.BombBays.Add(this);
             break;
         case ShipModuleType.Drone:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.Parent.Weapons.Add(this.InstalledWeapon);
             break;
         case ShipModuleType.Spacebomb:
             this.InstalledWeapon = ResourceManager.GetWeapon(ResourceManager.ShipModulesDict[this.UID].WeaponType);
             this.InstalledWeapon.moduleAttachedTo = this;
             this.InstalledWeapon.SetOwner(this.Parent);
             this.InstalledWeapon.Center = this.Center;
             this.isWeapon = true;
             this.Parent.Weapons.Add(this.InstalledWeapon);
             break;
     }
     if ((double)this.shield_power_max > 0.0)
     {
         this.shield = new Shield();
         this.shield.World = Matrix.Identity * Matrix.CreateScale(2f) * Matrix.CreateRotationZ(this.Rotation) * Matrix.CreateTranslation(this.Center.X, this.Center.Y, 0.0f);
         this.shield.Owner = (GameplayObject)this;
         this.shield.displacement = 0.0f;
         this.shield.texscale = 2.8f;
         this.shield.Rotation = this.Rotation;
         lock (GlobalStats.ShieldLocker)
             ShieldManager.shieldList.Add(this.shield);
     }
     if (this.IsSupplyBay)
     {
         if (this.Parent.Role == "freighter")
             this.Parent.Role = "supply";
         this.Parent.IsSupplyShip = true;
     }
     this.Health = this.HealthMax;
 }
        private void DoRepairDroneLogic(Weapon w)
        {
            try
            {
                if (this.Owner.loyalty.GetShips().Where<Ship>((Ship ship) =>
                    {
                        if (ship.Health / ship.HealthMax >= 0.95f || !ship.Active)
                        {
                            return false;
                        }
                        return Vector2.Distance(this.Owner.Center, ship.Center) < 20000f;
                    }).Count<Ship>() == 0)
                {
                    return;
                }
            }
            catch
            {
                return;
            }
            //bool flag = false;
            //for (int x = 0; x < this.Owner.loyalty.GetShips().Count; x++)
            //{
            //    Ship ship;
            //    try
            //    {
            //        ship = this.Owner.loyalty.GetShips()[x];
            //    }
            //    catch { continue; }
            //    if (ship.Health == ship.HealthMax || ship.Health / ship.HealthMax >= 0.95f)
            //        continue;
            //    if (Vector2.Distance(this.Owner.Center, ship.Center) < 20000f)
            //    {
            //        flag = true;
            //        break;
            //    }

            //}

            //if (!flag)
            //    return;
            using (IEnumerator<Ship> enumerator = this.Owner.GetAI().FriendliesNearby.Where<Ship>((Ship ship) => {
                if (Vector2.Distance(this.Owner.Center, ship.Center) >= 20000f || !ship.Active)
                {
                    return false;
                }
                return ship.Health / ship.HealthMax < 0.95f;
            }).OrderBy<Ship, float>((Ship ship) => Vector2.Distance(this.Owner.Center, ship.Center)).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    Ship friendliesNearby = enumerator.Current;
                    Vector2 target = this.findVectorToTarget(w.Center, friendliesNearby.Center);
                    target.Y = target.Y * -1f;
                    w.FireDrone(Vector2.Normalize(target));
                }
            }
        }
        private void FireOnTargetNonVisible(Weapon w, GameplayObject fireTarget)
        {
            if (this.Owner.Ordinance < w.OrdinanceRequiredToFire || this.Owner.PowerCurrent < w.PowerRequiredToFire)
            {
                return;
            }
            w.timeToNextFire = w.fireDelay;
            if (w.IsRepairDrone)
            {
                return;
            }
            if (TargetShip == null || !TargetShip.Active || TargetShip.dying || !w.TargetValid(TargetShip.Role)
                || TargetShip.engineState == Ship.MoveState.Warp || !this.Owner.CheckIfInsideFireArc(w, TargetShip))
                return;
            Ship owner = this.Owner;
            owner.Ordinance = owner.Ordinance - w.OrdinanceRequiredToFire;
            Ship powerCurrent = this.Owner;
            powerCurrent.PowerCurrent = powerCurrent.PowerCurrent - w.PowerRequiredToFire;
            powerCurrent.PowerCurrent -= w.BeamPowerCostPerSecond * w.BeamDuration;

            this.Owner.InCombatTimer = 15f;
            if (fireTarget is Projectile)
            {
                fireTarget.Damage(w.GetOwner(), w.DamageAmount);
                return;
            }
            if (!(fireTarget is Ship))
            {
                if (fireTarget is ShipModule)
                {
                    w.timeToNextFire = w.fireDelay;
                    IOrderedEnumerable<ModuleSlot> sortedList =
                        from slot in (fireTarget as ShipModule).GetParent().ExternalSlots
                        orderby Vector2.Distance(slot.module.Center, this.Owner.Center)
                        select slot;
                    float damage = w.DamageAmount;
                    if (w.isBeam)
                    {
                        damage = damage * 90f;
                    }
                    if (w.SalvoCount > 0)
                    {
                        damage = damage * (float)w.SalvoCount;
                    }
                    sortedList.First<ModuleSlot>().module.Damage(this.Owner, damage);
                }
                return;
            }
            w.timeToNextFire = w.fireDelay;
            if ((fireTarget as Ship).ExternalSlots.Count == 0)
            {
                (fireTarget as Ship).Die(null, true);
                return;
            }
            float nearest = 0;
            ModuleSlot ClosestES = null;
            foreach (ModuleSlot ES in (fireTarget as Ship).ExternalSlots)
            {
                if (ES.module.ModuleType == ShipModuleType.Dummy || !ES.module.Active || ES.module.Health <= 0)
                    continue;
                float temp = Vector2.Distance(ES.module.Center, w.GetOwner().Center);
                if (nearest == 0 || temp < nearest)
                {
                    nearest = temp;
                    ClosestES = ES;
                }
            }
            if (ClosestES == null)
                return;
            // List<ModuleSlot>
            IEnumerable<ModuleSlot> ExternalSlots = (fireTarget as Ship).ExternalSlots.Where(close => close.module.Active && close.module.quadrant == ClosestES.module.quadrant && close.module.Health > 0);//.ToList();   //.OrderByDescending(shields=> shields.Shield_Power >0);//.ToList();
            if ((fireTarget as Ship).shield_power > 0f)
            {
                for (int i = 0; i < (fireTarget as Ship).GetShields().Count; i++)
                {
                    if ((fireTarget as Ship).GetShields()[i].Active && (fireTarget as Ship).GetShields()[i].shield_power > 0f)
                    {
                        float damage = w.DamageAmount;
                        if (w.isBeam)
                        {
                            damage = damage * 90f;
                        }
                        if (w.SalvoCount > 0)
                        {
                            damage = damage * (float)w.SalvoCount;
                        }
                        (fireTarget as Ship).GetShields()[i].Damage(this.Owner, damage);
                        return;
                    }
                }
                return;
            }
            //this.Owner.GetSystem() != null ? this.Owner.GetSystem().RNG : ArtificialIntelligence.universeScreen.DeepSpaceRNG)).RandomBetween(0f, 100f) <= 50f ||
            if (ExternalSlots.ElementAt(0).module.shield_power > 0f)
            {
                for (int i = 0; i < ExternalSlots.Count(); i++)
                {
                    if (ExternalSlots.ElementAt(i).module.Active && ExternalSlots.ElementAt(i).module.shield_power <= 0f)
                    {
                        float damage = w.DamageAmount;
                        if (w.isBeam)
                        {
                            damage = damage * 90f;
                        }
                        if (w.SalvoCount > 0)
                        {
                            damage = damage * (float)w.SalvoCount;
                        }
                        ExternalSlots.ElementAt(i).module.Damage(this.Owner, damage);
                        return;
                    }
                }
                return;
            }

            for (int i = 0; i < ExternalSlots.Count(); i++)
            {
                if (ExternalSlots.ElementAt(i).module.Active && ExternalSlots.ElementAt(i).module.shield_power <= 0f)
                {
                    float damage = w.DamageAmount;
                    if (w.isBeam)
                    {
                        damage = damage * 90f;
                    }
                    if (w.SalvoCount > 0)
                    {
                        damage = damage * (float)w.SalvoCount;
                    }
                    ExternalSlots.ElementAt(i).module.Damage(this.Owner, damage);
                    return;
                }
            }
        }
        public void CalculateAndFire(Weapon weapon, GameplayObject target, bool SalvoFire)
        {
            //moved this code a little lower as it does not work in some situations
            //if (this.Owner.speed == 0 && target.Velocity.Length() == 0)
            //{
            //    Vector2 fireatstationary = Vector2.Zero;
            //    fireatstationary = Vector2.Normalize(this.findVectorToTarget(weapon.Center, target.Center));
            //    if (SalvoFire)
            //        weapon.FireSalvo(fireatstationary, target);
            //    else
            //        weapon.Fire(fireatstationary, target);
            //    return;

            //}

            float distance = Vector2.Distance(weapon.Center, target.Center) + target.Velocity.Length()==0?0: 500;
            Vector2 dir = (Vector2.Normalize(this.findVectorToTarget(weapon.Center, target.Center)) * (weapon.ProjectileSpeed + this.Owner.Velocity.Length()));
            float timeToTarget = distance / dir.Length();
            Vector2 projectedPosition = target.Center;
            //this.moduleTarget = target as ShipModule;
            ShipModule moduleTarget = target as ShipModule;
            if (target is Projectile)
            {
                projectedPosition = target.Center + (target.Velocity * timeToTarget);
                distance = Vector2.Distance(weapon.Center, projectedPosition);
                dir = (Vector2.Normalize(this.findVectorToTarget(weapon.Center, projectedPosition)) * (weapon.ProjectileSpeed + this.Owner.Velocity.Length()));
                timeToTarget = distance / dir.Length();
                projectedPosition = target.Center + ((target.Velocity * timeToTarget) * 0.85f);
            }
            else if (moduleTarget !=null)
            {
                if (moduleTarget.GetParent().Velocity.Length() > 0.0f)
                projectedPosition = target.Center + ((target as ShipModule).GetParent().Velocity * timeToTarget);
                else
                    projectedPosition = target.Center ;
                if (projectedPosition != target.Center && (target as ShipModule).GetParent().Velocity.Length() <= 0)
                {
                    System.Diagnostics.Debug.WriteLine("missing and correcting");
                    //moved docs target correction here.
                    Vector2 fireatstationary = Vector2.Zero;
                    fireatstationary = Vector2.Normalize(this.findVectorToTarget(weapon.Center, target.Center));
                    if (SalvoFire)
                        weapon.FireSalvo(fireatstationary, target);
                    else
                        weapon.Fire(fireatstationary, target);
                    return;

                }
                distance = Vector2.Distance(weapon.Center, projectedPosition);
                if (moduleTarget.GetParent().Velocity.Length() > 0.0f)
                dir = (Vector2.Normalize(this.findVectorToTarget(weapon.Center, projectedPosition)) * (weapon.ProjectileSpeed + this.Owner.Velocity.Length()));
                else
                {
                    dir = this.findVectorToTarget(weapon.Center, projectedPosition);

                }
                timeToTarget = distance / dir.Length();
                projectedPosition = target.Center + (moduleTarget.GetParent().Velocity * timeToTarget);
            }

            dir = this.findVectorToTarget(weapon.Center, projectedPosition);
            dir.Y = dir.Y * -1f;
            if (moduleTarget ==null  || moduleTarget.GetParent().Velocity.Length() >0)
            dir = Vector2.Normalize(dir);

            if (SalvoFire)
                weapon.FireSalvo(dir, target);
            else
                weapon.Fire(dir, target);
        }
 private void DoRepairBeamLogic(Weapon w)
 {
     //foreach (Ship ship in w.GetOwner().loyalty.GetShips()
     foreach (Ship ship in this.FriendliesNearby
         .Where(ship => ship.Active && ship != w.GetOwner()
             && ship.Health / ship.HealthMax <.9f
             && Vector2.Distance(this.Owner.Center, ship.Center) <= w.Range + 500f)
             .OrderBy(ship => ship.Health))
     {
         if (ship != null)
         {
             w.FireTargetedBeam(ship);
             return;
         }
     }
 }
        public bool CheckRangeToTarget(Weapon w, GameplayObject target)
        {
            if (target == null || !target.Active || target.Health <= 0)
                return false;
            if (this.engineState == MoveState.Warp)
                return false;
            Ship targetship = target as Ship;
            ShipModule targetModule = target as ShipModule;
            if (targetship == null && targetModule != null)
                targetship = targetModule.GetParent();
            if (targetship != null)
            {
                if (targetship.engineState == MoveState.Warp
                    || targetship.dying
                    || !targetship.Active
                    || targetship.ExternalSlots.Count <= 0
                    || !w.TargetValid(targetship.Role)

                    )
                    return false;
            }
            Vector2 PickedPos = target.Center;
            //radius = target.Radius;
            //added by gremlin attackrun compensator
            float modifyRangeAR = 50f;
            Vector2 pos = PickedPos;
            if (w.PrimaryTarget && !w.isBeam && this.GetAI().CombatState == CombatState.AttackRuns && this.maxWeaponsRange < 2000 && w.SalvoCount > 0)
            {
                modifyRangeAR = this.speed;
                if (modifyRangeAR < 50)
                    modifyRangeAR = 50;
            }
            if (Vector2.Distance(pos, w.moduleAttachedTo.Center) > w.GetModifiedRange() + modifyRangeAR)//+radius)
            {
                return false;
            }
            return true;
        }
 public DroneAI(Projectile owner)
 {
     this.Owner = owner;
     this.w = ResourceManager.GetWeapon("RepairBeam");
 }
 //Added by McShooterz
 public bool CheckIfInsideFireArc(Weapon w, Vector2 PickedPos, float Rotation)
 {
     if(Vector2.Distance(w.moduleAttachedTo.Center, PickedPos) > w.GetModifiedRange() + 50f)
     {
         return false;
     }
     float halfArc = w.moduleAttachedTo.FieldOfFire / 2f;
     Vector2 toTarget = PickedPos - w.Center;
     float radians = (float)Math.Atan2((double)toTarget.X, (double)toTarget.Y);
     float angleToMouse = 180f - MathHelper.ToDegrees(radians);
     float facing = w.moduleAttachedTo.facing + MathHelper.ToDegrees(Rotation);
     if (facing > 360f)
     {
         facing = facing - 360f;
     }
     float difference = 0f;
     difference = Math.Abs(angleToMouse - facing);
     if (difference > halfArc)
     {
         if (angleToMouse > 180f)
         {
             angleToMouse = -1f * (360f - angleToMouse);
         }
         if (facing > 180f)
         {
             facing = -1f * (360f - facing);
         }
         difference = Math.Abs(angleToMouse - facing);
     }
     if (difference < halfArc )//&& Vector2.Distance(w.moduleAttachedTo.Center, PickedPos) < w.GetModifiedRange() + 50f)
     {
         return true;
     }
     return false;
 }
        //Added by McShooterz
        public bool CheckIfInsideFireArc(Weapon w, Ship ship)
        {
            Vector2 PickedPos = ship.Center;
            float radius = ship.radius;
            GlobalStats.WeaponArcChecks = GlobalStats.WeaponArcChecks + 1;
            float modifyRangeAR = 50f;
            float distance =Vector2.Distance(w.moduleAttachedTo.Center, PickedPos) ;
            if (!w.isBeam && this.GetAI().CombatState == CombatState.AttackRuns && w.SalvoTimer > 0 && distance / w.SalvoTimer < w.GetOwner().speed) //&& this.maxWeaponsRange < 2000
            {

                modifyRangeAR = this.speed * w.SalvoTimer;

                if (modifyRangeAR < 50)
                    modifyRangeAR = 50;

            }
            if (distance > w.GetModifiedRange() + modifyRangeAR + radius)
            {
                return false;
            }
            float halfArc = w.moduleAttachedTo.FieldOfFire / 2f;
            Vector2 toTarget = PickedPos - w.Center;
            float radians = (float)Math.Atan2((double)toTarget.X, (double)toTarget.Y);
            float angleToMouse = 180f - MathHelper.ToDegrees(radians);
            float facing = w.moduleAttachedTo.facing + MathHelper.ToDegrees(base.Rotation);
            if (facing > 360f)
            {
                facing = facing - 360f;
            }
            float difference = 0f;
            difference = Math.Abs(angleToMouse - facing);
            if (difference > halfArc)
            {
                if (angleToMouse > 180f)
                {
                    angleToMouse = -1f * (360f - angleToMouse);
                }
                if (facing > 180f)
                {
                    facing = -1f * (360f - facing);
                }
                difference = Math.Abs(angleToMouse - facing);
            }
            //float modifyRangeAR = 50f;
            //if (!w.isBeam && this.GetAI().CombatState == CombatState.AttackRuns && this.maxWeaponsRange < 2000 && w.SalvoTimer > 0)
            //{
            //    modifyRangeAR = this.speed * w.SalvoTimer;
            //}
            if (difference < halfArc )//&& Vector2.Distance(w.moduleAttachedTo.Center, PickedPos) < w.GetModifiedRange() + modifyRangeAR)
            {
                return true;
            }
            return false;
        }
        public bool CheckIfInsideFireArc(Weapon w, Vector3 PickedPos )
        {
            //added by gremlin attackrun compensator
            float modifyRangeAR = 50f;
            Vector2 pos = new Vector2(PickedPos.X, PickedPos.Y);
            if (!w.isBeam && this.GetAI().CombatState == CombatState.AttackRuns && this.maxWeaponsRange < 2000 && w.SalvoCount > 0)
            {
                modifyRangeAR = this.speed;
                if (modifyRangeAR < 50)
                    modifyRangeAR = 50;
            }
            if (Vector2.Distance(pos, w.moduleAttachedTo.Center) > w.GetModifiedRange() + modifyRangeAR )
            {
                return false;
            }

            float halfArc = w.moduleAttachedTo.FieldOfFire / 2f;
            Vector2 toTarget = pos - w.Center;
            float radians = (float)Math.Atan2((double)toTarget.X, (double)toTarget.Y);
            float angleToMouse = 180f - MathHelper.ToDegrees(radians);
            float facing = w.moduleAttachedTo.facing + MathHelper.ToDegrees(base.Rotation);
            if (facing > 360f)
            {
                facing = facing - 360f;
            }
            float difference = 0f;
            difference = Math.Abs(angleToMouse - facing);
            if (difference > halfArc)
            {
                if (angleToMouse > 180f)
                {
                    angleToMouse = -1f * (360f - angleToMouse);
                }
                if (facing > 180f)
                {
                    facing = -1f * (360f - facing);
                }
                difference = Math.Abs(angleToMouse - facing);
            }

            if (difference < halfArc)// && Vector2.Distance(base.Position, pos) < w.GetModifiedRange() + modifyRangeAR)
            {
                return true;
            }
            return false;
        }
        //Added by McShooterz
        public bool CheckIfInsideFireArc(Weapon w, GameplayObject target)
        {
            if (!CheckRangeToTarget(w, target))
                return false;
            if (w.Tag_Guided && w.RotationRadsPerSecond > 3f)
                return true;
            Vector2 PickedPos = target.Center;
            Vector2 pos = PickedPos;
            float halfArc = w.moduleAttachedTo.FieldOfFire / 2f;
            Vector2 toTarget = pos - w.Center;
            float radians = (float)Math.Atan2((double)toTarget.X, (double)toTarget.Y);
            float angleToMouse = 180f - MathHelper.ToDegrees(radians);
            float facing = w.moduleAttachedTo.facing + MathHelper.ToDegrees(base.Rotation);
            if (facing > 360f)
            {
                facing = facing - 360f;
            }
            float difference = 0f;
            difference = Math.Abs(angleToMouse - facing);
            if (difference > halfArc)
            {
                if (angleToMouse > 180f)
                {
                    angleToMouse = -1f * (360f - angleToMouse);
                }
                if (facing > 180f)
                {
                    facing = -1f * (360f - facing);
                }
                difference = Math.Abs(angleToMouse - facing);
            }

            if (difference < halfArc)// && Vector2.Distance(base.Position, pos) < w.GetModifiedRange() + modifyRangeAR)
            {
                return true;
            }
            return false;
        }
        public ShipModule GetRandomInternalModule(Weapon source)
        {
            float nearest=0;
            float temp;

            Vector2 center = source.GetOwner() != null ? source.GetOwner().Center : source.Center;
            ModuleSlot ClosestES=null;

            foreach(ModuleSlot ES in this.ExternalSlots)
            {
                if (ES.module.ModuleType == ShipModuleType.Dummy || !ES.module.Active || ES.module.Health <=0)
                    continue;
                temp = Vector2.Distance(ES.module.Center, center);
                if (nearest == 0 || temp < nearest )
                {
                    nearest = temp;
                    ClosestES = ES;
                }
            }
            byte level = 0;
            if (ClosestES == null)
            {
                System.Diagnostics.Debug.WriteLine(string.Concat("GetRandomInternal: ClosestES was null: ExternalCount:",this.ExternalSlots.Count," Name: " ,this.VanityName ));
                return null;
            }
            if (source.GetOwner() != null)
                level = (byte)source.GetOwner().Level;

            lock (this.AttackerTargetting)
            {
                if (this.AttackerTargetting == null || !this.AttackerTargetting.Contains(ClosestES))
                    if (level > 1)
                    {
                        float Damageradius = Vector2.Distance(ClosestES.module.Center, this.Center); //16 * (7 - level);//
                        this.AttackerTargetting.Clear();
                        foreach (ModuleSlot slot in this.ModuleSlotList)
                        {
                            if (slot != null && slot.module.ModuleType != ShipModuleType.Dummy
                                                       && slot.module.Active && slot.module.Health > 0.0 && (!slot.module.isExternal || slot.module.quadrant == ClosestES.module.quadrant)
                                                       && Vector2.Distance(slot.module.Center, ClosestES.module.Center) < Damageradius)
                            {
                                this.AttackerTargetting.Add(slot);
                            }

                        }
                        this.AttackerTargetting = this.AttackerTargetting.OrderByDescending(slot => slot.module.TargetValue + (slot.module.Health < slot.module.HealthMax ? 1 : 0))

                               .ToList();
                    }
                    else
                    {
                        float Damageradius = Vector2.Distance(ClosestES.module.Center, this.Center);
                        this.AttackerTargetting.Clear();
                        foreach (ModuleSlot slot in this.ModuleSlotList)
                        {
                            if (slot != null && slot.module.ModuleType != ShipModuleType.Dummy
                                                       && slot.module.Active && slot.module.Health > 0.0 && (!slot.module.isExternal || slot.module.quadrant == ClosestES.module.quadrant)
                                                       && Vector2.Distance(slot.module.Center, ClosestES.module.Center) < Damageradius)
                            {
                                this.AttackerTargetting.Add(slot);
                            }

                        }
                    }
            }
            if (this.AttackerTargetting.Count == 0)
            {
                if (this.ExternalSlots.Count == 0)
                    return null;
                else return this.ExternalSlots[0].module;
            }

            {

                if (this.AttackerTargetting.Count == 0)
                    return null;
                int randomizer = this.AttackerTargetting.Count() / (level + 1);
                return this.AttackerTargetting[HelperFunctions.GetRandomIndex(randomizer)].module;
            }
        }