public void InitializeMissile(float initialSpeed, Vector2 direction, GameplayObject Target)
 {
     this.direction = direction;
     if (this.moduleAttachedTo != null)
     {
         this.Center = this.moduleAttachedTo.Center;
     }
     this.velocity = (initialSpeed * direction) + (this.owner != null ? this.owner.Velocity : Vector2.Zero);
     this.radius = 1f;
     this.velocityMaximum = initialSpeed + (this.Owner != null ? this.Owner.Velocity.Length() : 0f);
     this.duration = this.range / initialSpeed * 2f;
     this.initialDuration = this.duration;
     if (this.moduleAttachedTo != null)
     {
         this.Center = this.moduleAttachedTo.Center;
         if (this.moduleAttachedTo.facing == 0f)
         {
             this.rotation = this.Owner.Rotation;
         }
         else
         {
             this.rotation = MathHelper.ToRadians(HelperFunctions.findAngleToTarget(this.moduleAttachedTo.Center, this.moduleAttachedTo.Center + this.velocity));
         }
     }
     if (this.weapon.Animated == 1)
     {
         this.switchFrames = this.initialDuration / (float)this.weapon.Frames;
         if (this.weapon.LoopAnimation == 1)
         {
             this.AnimationFrame = (int)((this.system != null ? this.system.RNG : Ship.universeScreen.DeepSpaceRNG)).RandomBetween(0f, (float)(this.weapon.Frames - 1));
         }
     }
     Projectile projectile1 = this;
     projectile1.particleDelay = projectile1.particleDelay + this.weapon.particleDelay;
     if (this.weapon.Tag_Guided)
     {
         this.missileAI = new MissileAI(this);
         this.missileAI.SetTarget(Target);
     }
     if (this.ProjSO !=null &&(this.WeaponType == "Missile" || this.WeaponType == "Drone" || this.WeaponType == "Rocket") && (this.system != null && this.system.isVisible || this.isInDeepSpace))
     {
         this.wasAddedToSceneGraph = true;
         lock (GlobalStats.ObjectManagerLocker)
         {
             Projectile.universeScreen.ScreenManager.inter.ObjectManager.Submit(this.ProjSO);
         }
     }
     if (this.system == null)
     {
         Projectile.universeScreen.DSProjectilesToAdd.Add(this);
         UniverseScreen.DeepSpaceManager.CollidableProjectiles.Add(this);
     }
     else
     {
         //lock (GlobalStats.BucketLock)
         {
             this.system.spatialManager.CollidableProjectiles.Add(this);
             this.system.spatialManager.RegisterObject(this);
             this.system.spatialManager.CollidableObjects.Add(this);
         }
     }
     base.Initialize();
 }
 public void InitializePlanet(float initialSpeed, Vector2 direction, Vector2 pos)
 {
     this.zStart = -2500f;
     this.direction = direction;
     if (this.moduleAttachedTo == null)
     {
         this.Center = pos;
     }
     else
     {
         this.Center = this.moduleAttachedTo.Center;
     }
     this.velocity = (initialSpeed * direction) + (this.owner != null ? this.owner.Velocity : Vector2.Zero);
     this.radius = 1f;
     this.velocityMaximum = initialSpeed + (this.owner != null ? this.owner.Velocity.Length() : 0f);
     this.velocity = Vector2.Normalize(this.velocity) * this.velocityMaximum;
     this.duration = this.range / initialSpeed * 1.25f;
     this.initialDuration = this.duration;
     if (this.weapon.Animated == 1)
     {
         this.switchFrames = this.initialDuration / (float)this.weapon.Frames;
         if (this.weapon.LoopAnimation == 1)
         {
             this.AnimationFrame = (int)((this.system != null ? this.system.RNG : Ship.universeScreen.DeepSpaceRNG)).RandomBetween(0f, (float)(this.weapon.Frames - 1));
         }
     }
     Projectile projectile1 = this;
     projectile1.particleDelay = projectile1.particleDelay + this.weapon.particleDelay;
     if (this.weapon.Tag_Guided)
     {
         this.missileAI = new MissileAI(this);
     }
     if ((this.WeaponType == "Missile" || this.WeaponType == "Drone" || this.WeaponType == "Rocket") && (this.system != null && this.system.isVisible || this.isInDeepSpace) && this.ProjSO != null)
     {
         this.wasAddedToSceneGraph = true;
         lock (GlobalStats.ObjectManagerLocker)
         {
             Projectile.universeScreen.ScreenManager.inter.ObjectManager.Submit(this.ProjSO);
         }
     }
     if (this.system == null)
     {
         Projectile.universeScreen.DSProjectilesToAdd.Add(this);
         UniverseScreen.DeepSpaceManager.CollidableProjectiles.Add(this);
     }
     else
     {
         //lock (GlobalStats.BucketLock)
         {
             this.system.spatialManager.CollidableProjectiles.Add(this);
             this.system.spatialManager.CollidableObjects.Add(this);
         }
     }
     base.Initialize();
 }
 public void Initialize(float initialSpeed, Vector2 direction, Vector2 pos)
 {
     DebugInfoScreen.ProjCreated = DebugInfoScreen.ProjCreated + 1;
     this.direction = direction;
     this.velocity = initialSpeed * direction;
     if (this.moduleAttachedTo == null)
     {
         this.Center = pos;
         this.rotation = MathHelper.ToRadians(HelperFunctions.findAngleToTarget(this.Center, this.Center + this.velocity));
     }
     else
     {
         this.Center = this.moduleAttachedTo.Center;
         this.rotation = MathHelper.ToRadians(HelperFunctions.findAngleToTarget(this.moduleAttachedTo.Center, this.moduleAttachedTo.Center + this.velocity));
     }
     this.radius = 1f;
     this.velocityMaximum = initialSpeed + (this.Owner != null ? this.Owner.Velocity.Length() : 0f);
     this.velocity = Vector2.Normalize(this.velocity) * this.velocityMaximum;
     this.duration = this.range / initialSpeed * 1.2f;
     this.initialDuration = this.duration;
     if (this.weapon.Animated == 1)
     {
         this.switchFrames = this.initialDuration / (float)this.weapon.Frames;
         if (this.weapon.LoopAnimation == 1)
         {
             if (Ship.universeScreen != null)
             {
                 this.AnimationFrame = (int)((this.system != null ? this.system.RNG : Ship.universeScreen.DeepSpaceRNG)).RandomBetween(0f, (float)(this.weapon.Frames - 1));
             }
             else
             {
                 this.AnimationFrame = (int)RandomMath.RandomBetween(0f, (float)(this.weapon.Frames - 1));
             }
         }
     }
     if (this.owner.loyalty.data.ArmorPiercingBonus > 0 && (this.weapon.WeaponType == "Missile" || this.weapon.WeaponType == "Ballistic Cannon"))
     {
         this.ArmorPiercing += (byte)this.owner.loyalty.data.ArmorPiercingBonus;
     }
     Projectile projectile1 = this;
     projectile1.particleDelay = projectile1.particleDelay + this.weapon.particleDelay;
     if (this.weapon.Tag_Guided)
     {
         this.missileAI = new MissileAI(this);
     }
     if (this.WeaponType != "Missile" && this.WeaponType != "Drone" && this.WeaponType != "Rocket" || (this.system == null || !this.system.isVisible) && !this.isInDeepSpace)
     {
         if (this.owner != null && this.owner.loyalty.data.Traits.Blind > 0)
         {
             int Random = 0;
             Random = (Ship.universeScreen != null ? (int)((this.system != null ? this.system.RNG : Ship.universeScreen.DeepSpaceRNG)).RandomBetween(0f, 10f) : (int)RandomMath.RandomBetween(0f, 10f));
             if (Random <= 1)
             {
                 this.Miss = true;
             }
         }
     }
     else if (this.ProjSO != null)
     {
         this.wasAddedToSceneGraph = true;
         lock (GlobalStats.ObjectManagerLocker)
         {
             if (Projectile.universeScreen != null)
             {
                 Projectile.universeScreen.ScreenManager.inter.ObjectManager.Submit(this.ProjSO);
             }
         }
     }
     if (this.system == null)
     {
         UniverseScreen.DeepSpaceManager.CollidableProjectiles.Add(this);
         if (this.weapon.Tag_Intercept && Projectile.universeScreen != null)
         {
             Projectile.universeScreen.DSProjectilesToAdd.Add(this);
         }
     }
     else
     {
         //lock (GlobalStats.BucketLock)
         {
             this.system.spatialManager.CollidableProjectiles.Add(this);
             if (this.system.spatialManager.CellSize > 0)
             {
                 this.system.spatialManager.RegisterObject(this);
             }
             if (this.weapon.Tag_Intercept)
             {
                 this.system.spatialManager.CollidableObjects.Add(this);
             }
         }
     }
     base.Initialize();
 }