예제 #1
0
        public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo)
        {
            if (usedAmmo == null || (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MySniperConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy)
            {
                return(false);
            }

            MyAmmoProperties ammoProperties = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);

            AddProjectile(ammoProperties, this);

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            AddWeaponCue(ammoProperties.ShotSound);

            if (SysUtils.MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE)
            {
                MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.PROJECTILE);
            }

            MyParticleEffect startEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_SmallGunShot);

            startEffect.WorldMatrix = Matrix.CreateWorld(GetMuzzlePosition(), GetForward(), GetUp());

            return(true);
        }
예제 #2
0
        public virtual void Init(MyModelsEnum modelEnum, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoEnum, bool spherePhysics = true)
        {
            base.Init(null, modelEnum, null, null, null, null);

            AmmoType             = ammoEnum;
            m_gameplayProperties = MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)ammoEnum, Faction);
            m_ammoProperties     = MyAmmoConstants.GetAmmoProperties(ammoEnum);

            //  Collision skin
            if (spherePhysics)
            {
                InitSpherePhysics(MyMaterialType.AMMO, ModelLod0, m_gameplayProperties.WeightPerUnit,
                                  MyPhysicsConfig.DefaultAngularDamping, MyConstants.COLLISION_LAYER_DEFAULT,
                                  RigidBodyFlag.RBF_DEFAULT);
            }
            else
            {
                InitBoxPhysics(MyMaterialType.AMMO, ModelLod0, m_gameplayProperties.WeightPerUnit,
                               MyPhysicsConfig.DefaultAngularDamping, MyConstants.COLLISION_LAYER_DEFAULT,
                               RigidBodyFlag.RBF_DEFAULT);
            }

            Physics.GetRBElementList()[0].Flags |= MyElementFlag.EF_MODEL_PREFER_LOD0;

            NeedsUpdate = true;
            RenderObjects[0].SkipIfTooSmall = false;
            CastShadows = false;
            Closed      = true; //Because ammobase instance is going to pool. It is started by Start()

            IsDestructible = true;

            PreloadTextures();
        }
예제 #3
0
        public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo)
        {
            if (usedAmmo == null || (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyMachineGunConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy)
            {
                return(false);
            }

            if (m_smokeEffect == null)
            {
                if (MyCamera.GetDistanceWithFOV(GetPosition()) < 150)
                {
                    m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Autocannon);
                    m_smokeEffect.WorldMatrix = WorldMatrix;
                    m_smokeEffect.OnDelete   += OnSmokeEffectDelete;
                }
            }

            MyAmmoProperties ammoProperties = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);

            if (MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE)
            {
                MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.PROJECTILE);
            }

            AddProjectile(ammoProperties, this);

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            StartLoopSound(ammoProperties.ShotSound);

            return(true);
        }
예제 #4
0
        public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo)
        {
            if (usedAmmo == null || (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyShotgunConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy)
            {
                return(false);
            }

            MyAmmoProperties ammoProperties = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);

            FireShotGunShot(ammoProperties);

            return(true);
        }
        // Start shooting on the presented target in the queue:
        public override bool StartShooting()
        {
            // start shooting this kind of ammo ...
            if (!base.StartShooting())
            {
                return(false);
            }

            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < (MyMachineGunConstants.SHOT_INTERVAL_IN_MILISECONDS /* * 0.75f*/))
            {
                return(false);
            }

            // Set muzzle flashes:
            m_muzzleFlashLength = MyMwcUtils.GetRandomFloat(4, 6);
            m_muzzleFlashRadius = MyMwcUtils.GetRandomFloat(1.2f, 2.0f);

            // Increse smoke to generate
            IncreaseSmoke();

            // Make random trajectories for the bullet:
            Matrix worldMatrix = WorldMatrix;

            // get muzzel flash positions:
            List <MyModelDummy> muzzles = GetMuzzleFlashMatrix();

            m_activeMuzzle = muzzles.Count == 1 ? 0 : MyMwcUtils.GetRandomInt(muzzles.Count);

            m_muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix);

            if (m_shotSmoke == null)
            {
                m_shotSmoke            = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_LargeGunShot);
                m_shotSmoke.AutoDelete = false;
            }
            m_shotSmoke.UserEmitterScale = m_smokeToGenerate;
            m_shotSmoke.WorldMatrix      = Matrix.CreateTranslation(m_muzzleFlashPosition);
            m_shotSmoke.UserScale        = 5;

            GetWeaponBase().PlayShootingSound();

            // Shoot projectiles
            AddProjectile(MyAmmoConstants.GetAmmoProperties(GetAmmoType()), m_muzzleFlashPosition);

            // dont decrease ammo count ...
            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            return(true);
        }
        void OnProjectileHit(ref MyEventProjectileHit msg)
        {
            MyEntity target;

            if (MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.TargetEntityId), out target))
            {
                MyEntity source;
                if (!msg.SourceEntityId.HasValue || !MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.SourceEntityId.Value), out source))
                {
                    source = null;
                }
                var ammo = MyAmmoConstants.GetAmmoProperties(msg.AmmoType);

                target.DoDamage(ammo.HealthDamage, ammo.ShipDamage, ammo.EMPDamage, ammo.DamageType, ammo.AmmoType, source);
                MyProjectile.ApplyProjectileForce(target, msg.Position, Vector3.Normalize(msg.Direction), !(target is MySmallShipBot));
            }
        }
예제 #7
0
        public void Explode(MyEntity collideEntity)
        {
            if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive)
            { //make flying shrapnels
                int shrapnels = MyCannonShotConstants.PROXIMITY_SHRAPNELS_COUNT;
                while (shrapnels-- > 0)
                {
                    Vector3 projectileForwardVector = MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, MathHelper.TwoPi);
                    //MyProjectiles.Add(
                    //  MyAmmoConstants.GetAmmoProperties(MyAmmoPropertiesEnum.Shrapnel),
                    //Parent, GetPosition(), Vector3.Zero, projectileForwardVector, false, 3, this);

                    MyProjectiles.Add(
                        MyAmmoConstants.GetAmmoProperties(MyAmmoPropertiesEnum.Shrapnel),
                        Parent, GetPosition(), Vector3.Zero, projectileForwardVector, false, 3, this);
                }
            }

            Explode();
        }
예제 #8
0
        //  Update position, check collisions, etc.
        //  Return false if projectile dies/timeouts in this tick.
        public bool Update()
        {
            //  Projectile was killed , but still not last time drawn, so we don't need to do update (we are waiting for last draw)
            if (m_state == MyProjectileStateEnum.KILLED)
            {
                return(true);
            }

            //  Projectile was killed and last time drawn, so we can finally remove it from buffer
            if (m_state == MyProjectileStateEnum.KILLED_AND_DRAWN)
            {
                if (m_trailEffect != null)
                {
                    // stop the trail effect
                    m_trailEffect.Stop();
                    m_trailEffect = null;
                }

                return(false);
            }

            Vector3 position = m_position;

            m_position += m_velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_velocity  = m_externalVelocity * m_externalAddition + m_directionNormalized * m_speed;
            if (m_externalAddition < 1.0f)
            {
                m_externalAddition *= 0.5f;
            }

            //  Distance timeout
            float trajectoryLength = Vector3.Distance(m_position, m_origin);

            if (trajectoryLength >= m_maxTrajectory)
            {
                if (m_trailEffect != null)
                {
                    // stop the trail effect
                    m_trailEffect.Stop();
                    m_trailEffect = null;
                }

                m_state = MyProjectileStateEnum.KILLED;
                return(true);
            }

            if (m_trailEffect != null)
            {
                m_trailEffect.WorldMatrix = Matrix.CreateTranslation(m_position);
            }

            m_checkIntersectionIndex++;
            m_checkIntersectionIndex = m_checkIntersectionIndex % CHECK_INTERSECTION_INTERVAL;

            //check only each n-th intersection
            if (m_checkIntersectionIndex != 0)
            {
                return(true);
            }

            //  Calculate hit point, create decal and throw debris particles
            Vector3 lineEndPosition = position + CHECK_INTERSECTION_INTERVAL * (m_velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS);

            MyLine line = new MyLine(m_positionChecked ? position : m_origin, lineEndPosition, true);

            m_positionChecked = true;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()");
            MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignorePhysObject, null, false);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyEntity physObject = intersection != null ? intersection.Value.Entity : null;

            if (physObject != null)
            {
                while (physObject.Physics == null && physObject.Parent != null)
                {
                    physObject = physObject.Parent;
                }
            }

            if ((intersection != null) && (physObject != null) && (physObject.Physics.CollisionLayer != MyConstants.COLLISION_LAYER_UNCOLLIDABLE) && m_ignorePhysObject != physObject)
            {
                MyIntersectionResultLineTriangleEx intersectionValue = intersection.Value;

                bool isPlayerShip = MySession.PlayerShip == physObject;

                MyMaterialType materialType = isPlayerShip ? MyMaterialType.PLAYERSHIP : physObject.Physics.MaterialType;

                //material properties
                MyMaterialTypeProperties materialProperties = MyMaterialsConstants.GetMaterialProperties(materialType);

                bool isProjectileGroupKilled = false;

                if (m_sharedGroup != null)
                {
                    isProjectileGroupKilled = m_sharedGroup.Killed;
                    m_sharedGroup.Killed    = true;
                }

                if (!isProjectileGroupKilled)
                {
                    //  Play bullet hit cue
                    MyAudio.AddCue3D(m_ammoProperties.IsExplosive ? materialProperties.ExpBulletHitCue : materialProperties.BulletHitCue, intersectionValue.IntersectionPointInWorldSpace, Vector3.Zero, Vector3.Zero, Vector3.Zero);
                }

                float decalAngle = MyMwcUtils.GetRandomRadian();

                //  If we hit the glass of a miner ship, we need to create special bullet hole decals
                //  drawn from inside the cockpit and change phys object so rest of the code will think we hit the parent
                //  IMPORTANT: Intersection between projectile and glass is calculated only for mining ship in which player sits. So for enemies this will be never calculated.
                if (intersection.Value.Entity is MyCockpitGlassEntity)
                {
                    if (!isProjectileGroupKilled)
                    {
                        MyCockpitGlassDecalTexturesEnum bulletHoleDecalTexture;
                        float bulletHoleDecalSize;

                        if (MyMwcUtils.GetRandomBool(3))
                        {
                            bulletHoleDecalTexture = MyCockpitGlassDecalTexturesEnum.BulletHoleOnGlass;
                            bulletHoleDecalSize    = 0.25f;
                        }
                        else
                        {
                            bulletHoleDecalTexture = MyCockpitGlassDecalTexturesEnum.BulletHoleSmallOnGlass;
                            bulletHoleDecalSize    = 0.1f;
                        }

                        //  Place bullet hole decal on player's cockpit glass (seen from inside the ship)
                        MyCockpitGlassDecals.Add(bulletHoleDecalTexture, bulletHoleDecalSize, decalAngle, 1.0f, ref intersectionValue, false);

                        //  Create hit particles throwed into the cockpit (it's simulation of broken glass particles)
                        //  IMPORTANT: This particles will be relative to miner ship, so we create them in object space coordinates and update them by object WorldMatrix every time we draw them
                        //MyParticleEffects.CreateHitParticlesGlass(ref intersectionValue.IntersectionPointInObjectSpace, ref intersectionValue.NormalInWorldSpace, ref line.Direction, physObject.Parent);
                    }
                }

                //  If this was "mine", it must explode
                else if (physObject is MyMineBase)
                {
                    m_state = MyProjectileStateEnum.KILLED;
                    if (!IsDummy)
                    {
                        (physObject as MyAmmoBase).Explode();
                    }
                    return(true);
                }

                //  If this was missile, cannon shot, it must explode if it is not mine missile
                else if (physObject is MyAmmoBase)
                {
                    if (((MyAmmoBase)physObject).OwnerEntity == m_ignorePhysObject)
                    {
                        m_state = MyProjectileStateEnum.KILLED;
                        if (!IsDummy)
                        {
                            (physObject as MyAmmoBase).Explode();
                        }
                        return(true);
                    }
                }

                else if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && physObject is MyStaticAsteroid && !physObject.IsDestructible)
                {
                    if (this.m_ammoProperties.IsExplosive || (this.m_ammoProperties.AmmoType == MyAmmoType.Explosive && this.m_weapon is Weapons.MyShotGun))
                    {
                        HUD.MyHud.ShowIndestructableAsteroidNotification();
                    }
                }

                else if (!isProjectileGroupKilled && !isPlayerShip)
                {
                    //  Create smoke and debris particle at the place of voxel/model hit
                    m_ammoProperties.OnHitParticles(ref intersectionValue.IntersectionPointInWorldSpace, ref intersectionValue.Triangle.InputTriangleNormal, ref line.Direction, physObject, m_weapon, OwnerEntity);

                    MySurfaceImpactEnum surfaceImpact;
                    if (intersectionValue.Entity is MyVoxelMap)
                    {
                        var voxelMap   = intersectionValue.Entity as MyVoxelMap;
                        var voxelCoord = voxelMap.GetVoxelCenterCoordinateFromMeters(ref intersectionValue.IntersectionPointInWorldSpace);
                        var material   = voxelMap.GetVoxelMaterial(ref voxelCoord);
                        if (material == MyMwcVoxelMaterialsEnum.Indestructible_01 ||
                            material == MyMwcVoxelMaterialsEnum.Indestructible_02 ||
                            material == MyMwcVoxelMaterialsEnum.Indestructible_03 ||
                            material == MyMwcVoxelMaterialsEnum.Indestructible_04 ||
                            material == MyMwcVoxelMaterialsEnum.Indestructible_05_Craters_01)
                        {
                            surfaceImpact = MySurfaceImpactEnum.INDESTRUCTIBLE;
                        }
                        else
                        {
                            surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
                        }
                    }
                    else if (intersectionValue.Entity is MyStaticAsteroid)
                    {
                        surfaceImpact = MySurfaceImpactEnum.INDESTRUCTIBLE;
                    }
                    else
                    {
                        surfaceImpact = MySurfaceImpactEnum.METAL;
                    }

                    m_ammoProperties.OnHitMaterialSpecificParticles(ref intersectionValue.IntersectionPointInWorldSpace, ref intersectionValue.Triangle.InputTriangleNormal, ref line.Direction, physObject, surfaceImpact, m_weapon);
                }

                if (!(physObject is MyExplosionDebrisBase) && physObject != MySession.PlayerShip)
                {
                    //  Decal size depends on material. But for mining ship create smaller decal as original size looks to large on the ship.
                    float decalSize = MyMwcUtils.GetRandomFloat(materialProperties.BulletHoleSizeMin,
                                                                materialProperties.BulletHoleSizeMax);

                    //  Place bullet hole decal
                    float randomColor = MyMwcUtils.GetRandomFloat(0.5f, 1.0f);

                    MyDecals.Add(
                        materialProperties.BulletHoleDecal,
                        decalSize,
                        decalAngle,
                        new Vector4(randomColor, randomColor, randomColor, 1),
                        false,
                        ref intersectionValue,
                        0.0f,
                        m_ammoProperties.DecalEmissivity, MyDecalsConstants.DECAL_OFFSET_BY_NORMAL);
                }

                if (!(physObject is MyVoxelMap) && !IsDummy)
                {
                    ApplyProjectileForce(physObject, intersectionValue.IntersectionPointInWorldSpace, m_directionNormalized, isPlayerShip);
                }


                //  If this object is miner ship, then shake his head little bit
                if (physObject is MySmallShip && !IsDummy)
                {
                    MySmallShip minerShip = (MySmallShip)physObject;
                    minerShip.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_PROJECTILE_HIT);
                }



                //Handle damage

                MyEntity damagedObject = intersectionValue.Entity;

                // not a very nice way to damage actual prefab associated with the large ship weapon (if MyPrefabLargeWeapon is reworked, it might change)
                if (damagedObject is MyLargeShipBarrelBase)
                {
                    damagedObject = damagedObject.Parent;
                }
                if (damagedObject is MyLargeShipGunBase)
                {
                    MyLargeShipGunBase physObj = damagedObject as MyLargeShipGunBase;
                    if (physObj.PrefabParent != null)
                    {
                        damagedObject = physObj.PrefabParent;
                    }
                }

                //  Decrease health of stricken object
                if (!IsDummy)
                {
                    damagedObject.DoDamage(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, m_ammoProperties.DamageType, m_ammoProperties.AmmoType, m_ignorePhysObject);
                    if (MyMultiplayerGameplay.IsRunning)
                    {
                        var ammo = MyAmmoConstants.FindAmmo(m_ammoProperties);
                        MyMultiplayerGameplay.Static.ProjectileHit(damagedObject, intersectionValue.IntersectionPointInWorldSpace, this.m_directionNormalized, ammo, this.OwnerEntity);
                    }
                }

                if (m_trailEffect != null)
                {
                    // stop the trail effect
                    m_trailEffect.Stop();
                    m_trailEffect = null;
                }

                //  Kill this projectile (set the position to intersection point, so we draw trail polyline only up to this point)
                m_position = intersectionValue.IntersectionPointInWorldSpace;
                m_state    = MyProjectileStateEnum.KILLED;

                return(true);
            }

            return(true);
        }
예제 #9
0
        public override bool StartShooting()
        {
            if (!base.StartShooting())
            {
                return(false);
            }

            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyAutocanonConstants.SHOT_INTERVAL_IN_MILISECONDS)
            {
                return(false);
            }

            // Set muzzle flashes:
            m_muzzleFlashLength = MyMwcUtils.GetRandomFloat(4, 6);
            m_muzzleFlashRadius = MyMwcUtils.GetRandomFloat(1.2f, 2.0f);

            // Increse smoke to generate
            IncreaseSmoke();

            // Make random trajectories for the bullet:
            Matrix worldMatrix = WorldMatrix;
            // get muzzle flashes:
            List <MyModelDummy> muzzles = GetMuzzleFlashMatrix();

            muzzleFlashPosition1 = MyUtils.GetTransform(muzzles[0].Matrix.Translation, ref worldMatrix);
            muzzleFlashPosition2 = MyUtils.GetTransform(muzzles[1].Matrix.Translation, ref worldMatrix);

            // if (!IsControlledByPlayer())
            {
                if (m_shotSmoke == null)
                {
                    m_shotSmoke            = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_LargeGunShot);
                    m_shotSmoke.AutoDelete = false;
                }
                m_shotSmoke.UserEmitterScale = m_smokeToGenerate;
                m_shotSmoke.WorldMatrix      = Matrix.CreateTranslation(muzzleFlashPosition1);

                if (m_shotSmoke2 == null)
                {
                    m_shotSmoke2            = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_LargeGunShot);
                    m_shotSmoke2.AutoDelete = false;
                }
                m_shotSmoke2.UserEmitterScale = m_smokeToGenerate;
                m_shotSmoke2.WorldMatrix      = Matrix.CreateTranslation(muzzleFlashPosition2);
            }

            int randSoundSource = MyMwcUtils.GetRandomInt(2);

            MySoundCue?shootingSound = GetWeaponBase().UnifiedWeaponCueGet(MySoundCuesEnum.WepMachineGunNormFire3d);

            if (shootingSound == null || !shootingSound.Value.IsPlaying)
            {
                GetWeaponBase().UnifiedWeaponCueSet(Audio.MySoundCuesEnum.WepMachineGunNormFire3d,
                                                    MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMachineGunNormFire3d, randSoundSource == 1 ? muzzleFlashPosition1 : muzzleFlashPosition2, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero));
                //MyAudio.AddCue3D(Audio.MySoundCuesEnum.WepAutocanonFire3d, randSoundSource == 1 ? muzzleFlashPosition1 : muzzleFlashPosition2, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero));
            }

            AddProjectile(MyAmmoConstants.GetAmmoProperties(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic), muzzleFlashPosition1);
            AddProjectile(MyAmmoConstants.GetAmmoProperties(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic), muzzleFlashPosition2);

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            return(true);
        }
예제 #10
0
        public override bool StartShooting()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyLargeShipMissileLauncherBarrel::StartShooting");

            LastShotId = null;

            int missileShotInterval = 0;

            MyLargeShipGunBase.GetMissileAmmoParams(GetAmmoType(), ref missileShotInterval);
            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileShotInterval)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                return(false);
            }

            m_burstFinish = false;
            while (!m_burstFinish)
            {
                if (!base.StartShooting())
                {
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    return(false);
                }

                if (m_groupMask == null)
                {
                    MyPhysics.physicsSystem.GetRigidBodyModule().GetGroupMaskManager().GetGroupMask(ref m_groupMask);
                }

                MyEntity target = ((MyLargeShipGunBase)Parent).GetTarget();

                List <MyModelDummy> muzzles = GetMuzzleFlashMatrix();
                m_activeMuzzle = --m_burstToFire;

                Matrix  worldMatrix         = WorldMatrix;
                Vector3 muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix);


                if (IsControlledByPlayer())
                {
                    //target = MySession.PlayerShip.TargetEntity as MySmallShip;
                    target = MyEnemyTargeting.SwitchNextTarget(true);
                }

                if (target != null || IsControlledByPlayer())
                {
                    MySoundCue?shootingSound = GetWeaponBase().UnifiedWeaponCueGet(MySoundCuesEnum.WepMissileLaunch3d);
                    if (shootingSound == null || !shootingSound.Value.IsPlaying)
                    {
                        GetWeaponBase().UnifiedWeaponCueSet(Audio.MySoundCuesEnum.WepMissileLaunch3d,
                                                            MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero));
                        //MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero);
                    }

                    Vector3 deviateVector = GetDeviatedVector(MyAmmoConstants.GetAmmoProperties(GetAmmoType()));

                    var missile = MyMissiles.Add(GetAmmoType(), muzzleFlashPosition + 2 * WorldMatrix.Forward, WorldMatrix.Forward * 2.0f, deviateVector, Vector3.Zero, this, target, SearchingDistance, isLightWeight: true);
                    if (missile.GuidedInMultiplayer)
                    {
                        missile.EntityId = MyEntityIdentifier.AllocateId();
                        MyEntityIdentifier.AddEntityWithId(missile);
                        LastShotId = missile.EntityId;
                    }
                }


                if (m_burstToFire <= 0)
                {
                    m_burstFireTime_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_burstToFire      = m_burstFireCount;
                    m_burstFinish      = true;
                }
                if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_burstFireTime_ms) > m_burstFireTimeLoadingIntervalConst_ms)
                {
                    m_burstFinish = false;
                }

                if (!IsControlledByPlayer())
                {
                    m_burstFinish = true;
                }
            }

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return(true);
        }
예제 #11
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 (GetParentMinerShip() == null)
            {
                return(false);
            }

            //  Allow shoting only at intervals
            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyAutocanonConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy)
            {
                return(false);
            }
            //  Stop 'release cue' if playing
            MySoundCue?autocanonReleaseCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_RELEASE);

            if ((autocanonReleaseCue != null) && (autocanonReleaseCue.Value.IsPlaying == true))
            {
                autocanonReleaseCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate);
            }

            //  Angle of muzzle flash particle
            m_muzzleFlashLength = MyMwcUtils.GetRandomFloat(3, 4) * m_barrel.GetMuzzleSize();
            m_muzzleFlashRadius = MyMwcUtils.GetRandomFloat(1.8f, 2.2f) * m_barrel.GetMuzzleSize();

            //  Increase count of smokes to draw
            SmokesToGenerateIncrease();

            //Use looping cue only in playership
            MySoundCuesEnum attackCue = GetParentMinerShip() == MySession.PlayerShip ? AUTOCANON_ATTACK_LOOP : AUTOCANON_ATTACK;

            //  Start 'attack and loop' cue (shooting)
            MySoundCue?autocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(attackCue);

            if ((autocanonAttackLoopCue == null) || (autocanonAttackLoopCue.Value.IsPlaying == false))
            {
                //MyMwcLog.WriteLine("Adding new AUTOCANNON attack loop");
                GetParentMinerShip().UnifiedWeaponCueSet(
                    attackCue,
                    MyAudio.AddCue2dOr3d(GetParentMinerShip(), attackCue,
                                         m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity));
            }

            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic;

            if (usedAmmo != null) //TODO: bot fires without ammo
            {
                ammoType = usedAmmo.AmmoType;
            }

            MyAmmoProperties ammoProperties = MyAmmoConstants.GetAmmoProperties(ammoType);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyAutocannonGun.Shot add projectile");

            if (MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE)
            {
                MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.PROJECTILE);
            }

            AddProjectile(ammoProperties, this);
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            m_cannonMotorEndPlayed = false;
            m_lastTimeShoot        = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            //  We shot one projectile
            return(true);
        }
예제 #12
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public void Start(Vector3 position, Vector3 initialVelocity, Vector3 directionNormalized, MyMwcObjectBuilder_SmallShip_Ammo usedAmmo, MySmallShip minerShip)
        {
            m_usedAmmo           = usedAmmo;
            m_ammoProperties     = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);
            m_gameplayProperties = MyGameplayConstants.GetGameplayProperties(m_usedAmmo, Faction);
            m_penetratedVoxelMap = null;
            m_wasPenetration     = false;
            m_hasExplosion       = false;
            m_isExploded         = false;
            m_collidedEntity     = null;
            m_collisionPoint     = null;

            Matrix  orientation = GetWorldRotation();
            Vector3 pos         = position;

            //  Play missile thrust cue (looping)
            m_thrusterCue = MyAudio.AddCue3D(MySoundCuesEnum.WepMissileFly, pos, orientation.Forward, orientation.Up, this.Physics.LinearVelocity);

            m_light = MyLights.AddLight();
            if (m_light != null)
            {
                m_light.Start(MyLight.LightTypeEnum.PointLight, GetPosition(), MyMissileHelperUtil.GetCannonShotLightColor(), 1, MyMissileConstants.MISSILE_LIGHT_RANGE);
            }

            m_diffuseColor = m_ammoProperties.TrailColor;

            switch (usedAmmo.AmmoType)
            {
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Basic:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_High_Speed:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Armor_Piercing_Incendiary:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_SAPHEI:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive:
                m_explosionType = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_BioChem:
                m_explosionType = MyExplosionTypeEnum.BIOCHEM_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_EMP:
                m_explosionType = MyExplosionTypeEnum.EMP_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster:
                m_explosionType = MyExplosionTypeEnum.BLASTER_EXPLOSION;
                break;

            default:
                throw new MyMwcExceptionApplicationShouldNotGetHere();
                break;
            }

            this.Physics.Mass = m_gameplayProperties.WeightPerUnit;

            Vector3?correctedDirection = null;

            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                if (minerShip == MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip)
                {
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(minerShip, position, m_ammoProperties.MaxTrajectory);
                }
            }

            if (correctedDirection != null)
            {
                directionNormalized = correctedDirection.Value;
            }

            base.Start(position, initialVelocity, directionNormalized, m_ammoProperties.DesiredSpeed, minerShip);

            if (correctedDirection != null) //override the base class behaviour, update the missile direction
            {
                Matrix ammoWorld = minerShip.WorldMatrix;
                ammoWorld.Translation = position;
                ammoWorld.Forward     = correctedDirection.Value;

                SetWorldMatrix(ammoWorld);
            }

            m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot);
            m_smokeEffect.AutoDelete  = false;
            m_smokeEffect.WorldMatrix = WorldMatrix;
        }
예제 #13
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public virtual void Start(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum type, Vector3 position, Vector3 initialVelocity, Vector3 direction, Vector3 relativePos, MyEntity minerShip, MyEntity target, float customMaxDistance, bool isDummy, bool isLightWeight)
        {
            m_ammoProperties = MyAmmoConstants.GetAmmoProperties(type);
            m_missileType    = type;
            m_isExploded     = false;
            m_collidedEntity = null;
            m_collisionPoint = null;
            m_maxTrajectory  = customMaxDistance > 0 ? customMaxDistance : m_ammoProperties.MaxTrajectory;
            IsDummy          = isDummy;
            Faction          = minerShip.Faction;

            Vector3?correctedDirection = null;

            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                if (minerShip == MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip)
                {
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(minerShip, position, m_ammoProperties.MaxTrajectory);
                }
            }

            if (correctedDirection != null)
            {
                direction = correctedDirection.Value;
            }

            base.Start(position, initialVelocity, direction, 0, minerShip);

            if (correctedDirection != null) //override the base class behaviour, update the missile direction
            {
                Matrix ammoWorld = minerShip.WorldMatrix;
                ammoWorld.Translation = position;
                ammoWorld.Forward     = correctedDirection.Value;

                SetWorldMatrix(ammoWorld);
            }

            switch (m_missileType)
            {
            //just going forward (deprecated)
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.BIOCHEM_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_EMP:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.EMP_EXPLOSION;
                break;

            //Missile is guided to the nearest enemy in the radius
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection:

            //Missile is guided to the closest enemy in the visible spot
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection:

            //Missile is guided to actual selected target by smallship radar
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection:
                m_initDir.X         = 5.0f * MathHelper.Clamp(relativePos.X, -1, 1);
                m_blendVelocities   = MyGuidedMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout    = MyGuidedMissileConstants.MISSILE_TIMEOUT;
                m_turnSpeed         = MyGuidedMissileConstants.MISSILE_TURN_SPEED;
                m_explosionType     = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                GuidedInMultiplayer = true;
                break;

            default:
                throw new NotImplementedException();
            }


            UpdateTarget(target);


            if (!isLightWeight)
            {
                //  Play missile thrust cue (looping)
                m_thrusterCue = MyAudio.AddCue3D(m_ammoProperties.ShotSound, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, m_initialVelocity);

                m_light = MyLights.AddLight();
                if (m_light != null)
                {
                    m_light.Start(MyLight.LightTypeEnum.PointLight, GetPosition(), MyMissileHelperUtil.GetMissileLightColor(), 1, MyMissileConstants.MISSILE_LIGHT_RANGE);
                }
            }

#if DEBUG_MISSILE
            m_trailDebug.Clear();
#endif

            if (m_missileType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic)
            {
                /*
                 * MyParticleEffect startEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_MissileStart);
                 * startEffect.WorldMatrix = WorldMatrix;
                 */
                m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Missile);
                m_smokeEffect.WorldMatrix = WorldMatrix;
                m_smokeEffect.AutoDelete  = false;
            }
        }