示例#1
0
        //  Every child of this base class must implement Shot() method, which shots projectile or missile.
        //  Method returns true if something was shot. False if not (because interval between two shots didn't pass)
        public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo)
        {
            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyCannonConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy)
            {
                return(false);
            }

            //  Throw ship backward (by deviated vector)
            this.Parent.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE,
                                         MyUtilRandomVector3ByDeviatingVector.GetRandom(Vector3.Backward, MathHelper.ToRadians(5)) * MyMwcUtils.GetRandomFloat(40000, 50000), null, null);

            //  Play missile launch cue (one-time)
            //AddWeaponCue(MySoundCuesEnum.WepMissileLaunch3d);
            AddWeaponCue(MySoundCuesEnum.WepCannon3d);

            Vector3 forwardVelocity = MyMath.ForwardVectorProjection(this.WorldMatrix.Forward, GetParentMinerShip().Physics.LinearVelocity);
            //Vector3 forwardVelocity = this.WorldMatrix.Forward;

            Vector3 deviatedVector = GetDeviatedVector(MinerWars.AppCode.Game.Gameplay.MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType));

            var cannonShotStartPos = GetPosition() + WorldMatrix.Forward * WorldVolume.Radius;

            cannonShotStartPos = CorrectPosition(cannonShotStartPos, deviatedVector, Parent);

            //  Create and fire missile - but deviate missile direction be random angle
            MyCannonShots.Add(cannonShotStartPos, forwardVelocity, deviatedVector, usedAmmo, (MySmallShip)Parent);

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            m_lastSmokePosition = GetSmokePosition();

            //  We shot one missile
            return(true);
        }
示例#2
0
        //  Kills this missile. Must be called at her end (after explosion or timeout)
        public override void Close()
        {
            base.Close();

            if (m_collidedEntity != null)
            {
                m_collidedEntity.OnClose -= m_collidedEntityClosedHandler;
                m_collidedEntity          = null;
            }

            //  Free the light
            if (m_light != null)
            {
                MyLights.RemoveLight(m_light);
                m_light = null;
            }

            //  Stop thruster cue
            if ((m_thrusterCue != null) && (m_thrusterCue.Value.IsPlaying == true))
            {
                m_thrusterCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate);
            }

            if (m_smokeEffect != null)
            {
                m_smokeEffect.Stop();
                m_smokeEffect = null;
            }

            MyCannonShots.Remove(this);
        }