// 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) { LastShotId = null; float missileLauncherShotInterval = float.MaxValue; switch (usedAmmo.AmmoType) { case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_EMP: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection: missileLauncherShotInterval = MyGuidedMissileConstants.MISSILE_LAUNCHER_SHOT_INTERVAL_IN_MILISECONDS; break; default: throw new ArgumentOutOfRangeException(); } if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileLauncherShotInterval && !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); Vector3 forwardVelocity = MyMath.ForwardVectorProjection(this.WorldMatrix.Forward, GetParentMinerShip().Physics.LinearVelocity); // Create and fire missile - but deviate missile direction be random angle Vector3 deviatedVector = GetDeviatedVector(MinerWars.AppCode.Game.Gameplay.MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType)); // correct missile start position if it would intersect some entity Vector3 missileStartPosition = m_positionMuzzleInWorldSpace; missileStartPosition = CorrectPosition(missileStartPosition, deviatedVector, Parent); if (MinerWars.AppCode.Game.Managers.Session.MySession.Static.Is2DSector) { forwardVelocity.Y = 0; deviatedVector.Y = 0; } var missile = MyMissiles.Add(usedAmmo.AmmoType, missileStartPosition, forwardVelocity, deviatedVector, LocalMatrix.Translation, Parent, ((MySmallShip)Parent).TargetEntity, isDummy: this.IsDummy); if (missile != null) { missile.EntityId = MyEntityIdentifier.AllocateId(); MyEntityIdentifier.AddEntityWithId(missile); LastShotId = missile.EntityId; GetParentMinerShip().LastMissileFired = missile; } //MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_lastSmokePosition = GetSmokePosition(); if (SysUtils.MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE) { MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.MISSILE); } // We shot one missile return(true); }
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); }