Beispiel #1
0
        private void FireShotGunShot(MyAmmoProperties ammoProperties)
        {
            int   currentRound = ammoProperties.ProjectileGroupSize;
            float deviateAngle = ammoProperties.DeviateAngle;

            //  Create one projectile - but deviate projectile direction be random angle
            if (IsThisGunFriendly())
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy;
            }
            else
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyBotOnPlayer;
            }

            while (currentRound-- > 0)
            {
                Vector3 projectileForwardVector = MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle);

                float billboardSize = ammoProperties.AmmoType == MyAmmoType.Explosive ? 2 : 1;

                MyProjectiles.AddShotgun(ammoProperties, Parent, m_positionMuzzleInWorldSpace, Vector3.Zero /* Parent.Physics.LinearVelocity*/,
                                         projectileForwardVector, currentRound % MyShotgunConstants.PROJECTILE_GROUP_SIZE == 0, 2, this, billboardSize, Parent);
            }

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            AddWeaponCue(ammoProperties.ShotSound);
        }
Beispiel #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();
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
        protected void AddProjectile(MyAmmoProperties ammoProperties, Vector3 muzzlePosition)
        {
            float deviateAngle = ammoProperties.DeviateAngle;

            Vector3 projectileForwardVector = GetDeviatedVector(ammoProperties);

            Vector3 velocity = ((MyLargeShipGunBase)Parent).PrefabParent.Parent.Physics.LinearVelocity;

            MyProjectiles.Add(ammoProperties, Parent, muzzlePosition, velocity, projectileForwardVector, false, 1.0f, this, ((MyLargeShipGunBase)Parent).WeaponOwner);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        protected Vector3 GetDeviatedVector(MyAmmoProperties ammoProperties)
        {
            float deviateAngle = ammoProperties.DeviateAngle;

            //  Create one projectile - but deviate projectile direction be random angle
            if (IsThisGunFriendly())
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy;
            }
            else
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyBotOnPlayer;
            }

            return(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle));
        }
        protected Vector3 GetDeviatedVector(MyAmmoProperties ammoProperties)
        {
            float deviateAngle = ammoProperties.DeviateAngle;

            //  Create one projectile - but deviate projectile direction be random angle
            if (((Parent as MyGunBase).IsThisGunFriendly() || MyGuiScreenGamePlay.Static.ControlledEntity == (Parent as MyLargeShipGunBase).PrefabParent))
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy;
            }
            else
            {
                deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyLargeWeaponOnPlayer;
                deviateAngle += GetDeviatedAngleByDamageRatio();
            }

            return(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle));
        }
Beispiel #9
0
        //  Add new projectile to the list
        public static void Add(MyAmmoProperties ammoProperties, MyEntity ignorePhysObject, Vector3 origin, Vector3 initialVelocity, Vector3 directionNormalized, bool groupStart, float thicknessMultiplier, MyEntity weapon, MyEntity ownerEntity = null)
        {
            MyProjectile newProjectile = m_projectiles.Allocate();

            if (newProjectile != null)
            {
                newProjectile.Start(
                    ammoProperties,
                    ignorePhysObject,
                    origin,
                    initialVelocity,
                    directionNormalized,
                    groupStart,
                    thicknessMultiplier,
                    weapon
                    );
                newProjectile.OwnerEntity = ownerEntity != null ? ownerEntity : ignorePhysObject;
            }
        }
Beispiel #10
0
        //  Add new projectile to the list
        public static void AddShotgun(MyAmmoProperties ammoProperties, MyEntity ignorePhysObject, Vector3 origin, Vector3 initialVelocity, Vector3 directionNormalized, bool groupStart, float thicknessMultiplier, MyEntity weapon, float frontBillboardSize, MyEntity ownerEntity = null)
        {
            MyProjectile newProjectile = m_projectiles.Allocate();

            if (newProjectile != null)
            {
                newProjectile.Start(
                    ammoProperties,
                    ignorePhysObject,
                    origin,
                    initialVelocity,
                    directionNormalized,
                    groupStart,
                    thicknessMultiplier,
                    weapon
                    );

                newProjectile.BlendByCameraDirection = true;
                newProjectile.FrontBillboardMaterial = MyTransparentMaterialEnum.ShotgunParticle;
                newProjectile.LengthMultiplier       = 2;
                newProjectile.FrontBillboardSize     = frontBillboardSize;
                newProjectile.OwnerEntity            = ownerEntity != null ? ownerEntity : ignorePhysObject;
            }
        }
Beispiel #11
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public void Start(MyAmmoProperties ammoProperties, MyEntity ignoreEntity, Vector3 origin, Vector3 initialVelocity, Vector3 directionNormalized,
                          bool groupStart, float thicknessMultiplier, MyEntity weapon
                          )
        {
            if (MySession.Is25DSector)
            {
                directionNormalized.Y = 0;
                directionNormalized.Normalize();
                initialVelocity.Y = 0;
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Projectile.Start");
            m_ammoProperties   = ammoProperties;
            m_state            = MyProjectileStateEnum.ACTIVE;
            m_ignorePhysObject = ignoreEntity;
            m_origin           = origin;
            m_position         = origin;
            m_externalAddition = 1.0f;
            m_weapon           = weapon;

            IsDummy = weapon != null && weapon.IsDummy;

            LengthMultiplier       = 1;
            FrontBillboardMaterial = null;
            FrontBillboardSize     = 1;
            BlendByCameraDirection = false;

            Vector3?correctedDirection = null;

            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                MyEntity entityToCheck;
                if (MyGuiScreenGamePlay.Static.ControlledEntity is MyPrefabLargeWeapon)
                {
                    entityToCheck = (MyGuiScreenGamePlay.Static.ControlledEntity as MyPrefabLargeWeapon).GetGun();
                }
                else
                {
                    entityToCheck = MyGuiScreenGamePlay.Static.ControlledEntity;
                }
                // TODO: Make proper test that source off projectile is player ship, testing ignore object is STUPID!
                if (m_ammoProperties.AllowAimCorrection && (ignoreEntity == entityToCheck)) // Autoaim only available for player
                {
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Projectile.Start autoaim generic");
                    //Intersection ignores children of "ignoreEntity", thus we must not hit our own barrels
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(ignoreEntity, origin, m_ammoProperties.MaxTrajectory);
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                }
            }

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

            m_speed            = ammoProperties.DesiredSpeed * (ammoProperties.SpeedVar > 0.0f ? MyMwcUtils.GetRandomFloat(1 - ammoProperties.SpeedVar, 1 + ammoProperties.SpeedVar) : 1.0f);
            m_externalVelocity = initialVelocity;
            m_velocity         = m_directionNormalized * m_speed;
            m_maxTrajectory    = ammoProperties.MaxTrajectory * MyMwcUtils.GetRandomFloat(0.8f, 1.2f); // +/- 20%


            m_thicknessMultiplier = thicknessMultiplier;

            m_checkIntersectionIndex  = checkIntersectionCounter % CHECK_INTERSECTION_INTERVAL;
            checkIntersectionCounter += 3;
            m_positionChecked         = false;
            m_groupStart              = groupStart;

            if (groupStart)
            {
                m_trailEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Trail_Shotgun);
                m_trailEffect.AutoDelete  = false;
                m_trailEffect.WorldMatrix = Matrix.CreateTranslation(m_position);
            }

            if (groupStart)
            {
                LastProjectileGroup = m_ownGroup;
                m_ownGroup.Killed   = false;
            }

            if (LastProjectileGroup != null && LastProjectileGroup.Killed == false)
            {
                m_sharedGroup = LastProjectileGroup;
            }
            else
            {
                m_sharedGroup = null;
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Beispiel #12
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);
        }
Beispiel #13
0
        protected void AddProjectile(MyAmmoProperties ammoProperties, MyEntity weapon)
        {
            Vector3 projectileForwardVector = GetDeviatedVector(ammoProperties);

            MyProjectiles.Add(ammoProperties, Parent, m_positionMuzzleInWorldSpace, Parent.Physics.LinearVelocity, projectileForwardVector, false, 1.0f, weapon);
        }