Example #1
0
 void StartEffect()
 {
     StopEffect();
     MyParticlesManager.TryCreateParticleEffect((int)EffectId, out m_toolEffect);
     m_toolEffectLight = CreatePrimaryLight();
     UpdateEffect();
 }
 void StartSecondaryEffect()
 {
     StopSecondaryEffect();
     MyParticlesManager.TryCreateParticleEffect((int)SecondaryEffectId, out m_toolSecondaryEffect);
     m_toolEffectLight = CreateSecondaryLight();
     UpdateEffect();
 }
Example #3
0
 private void DisposeEffects()
 {
     nearEffects.ForEach((a) => MyParticlesManager.RemoveParticleEffect(a));
     nearEffects.Clear();
     farEffects.ForEach((a) => MyParticlesManager.RemoveParticleEffect(a));
     farEffects.Clear();
 }
Example #4
0
 internal void SetDamageEffect(bool show)
 {
     if (MyFakes.SHOW_DAMAGE_EFFECTS && BlockDefinition.DamageEffectID != null && MySandboxGame.Static.EnableDamageEffects)
     {
         if (!show && m_damageEffect != null)
         {//stop
             m_damageEffect.Stop();
             m_damageEffect = null;
             if (!m_wasUpdatedEachFrame)
             {
                 NeedsUpdate &= ~MyEntityUpdateEnum.EACH_FRAME;
             }
         }
         if (show && m_damageEffect == null)
         {//start
             if (MyParticlesManager.TryCreateParticleEffect((int)BlockDefinition.DamageEffectID, out m_damageEffect))
             {
                 m_damageEffect.UserScale = Model.BoundingBox.Perimeter * .01f;//scale to size of item
                 setDamageWorldMatrix();
                 m_damageEffect.OnDelete  += damageEffect_OnDelete;
                 m_damageEffect.AutoDelete = false;
             }
             m_wasUpdatedEachFrame = (NeedsUpdate & MyEntityUpdateEnum.EACH_FRAME) != 0;
             //Debug.Assert(!m_wasUpdatedEachFrame, "may not t NeedUpdate correctly!");
             NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
         }
     }
 }
Example #5
0
        void Effect(MatrixD worldMatrix, Vector3 forward,
                    float scale,
                    float offset_down,
                    float offset_back)
        {
            if (effect == null)
            {
                MyParticlesManager.TryCreateParticleEffect("Bubbles", out effect, false);
            }

            if (effect != null)
            {
                MatrixD world = worldMatrix;
                world.Forward = forward;

                // offset
                if (offset_down > 0f)
                {
                    world.Translation += worldMatrix.Down * offset_down;
                }

                if (offset_back > 0f)
                {
                    world.Translation += worldMatrix.Backward * offset_back;
                }

                effect.WorldMatrix = world;
                effect.UserScale   = scale;
            }
        }
Example #6
0
        public static void ProcessParticleEffect(Effects effectData)
        {
            MyParticleEffect effect;
            var particleMatrix = MatrixD.CreateWorld(effectData.Coords, effectData.ParticleForwardDir, effectData.ParticleUpDir);
            var particleCoords = effectData.Coords;

            if (MyParticlesManager.TryCreateParticleEffect(effectData.ParticleId, ref particleMatrix, ref particleCoords, uint.MaxValue, out effect) == false)
            {
                return;
            }

            effect.UserScale = effectData.ParticleScale;

            if (effectData.ParticleMaxTime > 0)
            {
                //effect.DurationMin = effectData.ParticleMaxTime;
                //effect.DurationMax = effectData.ParticleMaxTime;
            }

            if (effectData.ParticleColor != Vector3D.Zero)
            {
                //var newColor = new Vector4((float)effectData.ParticleColor.X, (float)effectData.ParticleColor.Y, (float)effectData.ParticleColor.Z, 1);
                //effect.UserColorMultiplier = newColor;
            }

            effect.Velocity = effectData.Velocity;
            //effect.Loop = false;
        }
        public override void OnDestroy()
        {
            if (MyFakes.SHOW_DAMAGE_EFFECTS)
            {
                //particle effect
                if (BlockDefinition.DestroyEffect.Length > 0)
                {
                    if (BlockDefinition.RatioEnoughForDamageEffect(SlimBlock.BuildIntegrity / SlimBlock.MaxIntegrity))//grinded down
                    {
                        return;
                    }
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect(BlockDefinition.DestroyEffect, out effect))
                    {
                        effect.Loop        = false;
                        effect.WorldMatrix = WorldMatrix;
                    }
                }

                //sound effect
                if (!BlockDefinition.DestroySound.Equals(MySoundPair.Empty))
                {
                    MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                    if (emitter != null)
                    {
                        emitter.Entity = this;
                        emitter.PlaySound(BlockDefinition.DestroySound);
                    }
                }
            }
            base.OnDestroy();
        }
Example #8
0
        private void CreateCollisionSparks()
        {
            float distSq = MyDrillConstants.DRILL_HAND_REAL_LENGTH * MyDrillConstants.DRILL_HAND_REAL_LENGTH;
            var   origin = m_drillBase.Sensor.Center;

            m_objectInDrillingRange = false;
            foreach (var entry in m_drillBase.Sensor.EntitiesInRange)
            {
                const float sparksMoveDist = 0.1f;

                var pt = entry.Value.DetectionPoint;
                if (Vector3.DistanceSquared(pt, origin) < distSq)
                {
                    m_objectInDrillingRange = true;
                    if (Vector3.DistanceSquared(m_lastSparksPosition, pt) > sparksMoveDist * sparksMoveDist)
                    {
                        m_lastSparksPosition = pt;
                        MyParticleEffect effect;
                        if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.CollisionSparksHandDrill, out effect))
                        {
                            effect.WorldMatrix = MatrixD.CreateWorld(pt, PositionComp.WorldMatrix.Forward, PositionComp.WorldMatrix.Up);
                            effect.UserScale   = 0.3f;
                        }
                        else
                        {
                            // here we sould probably play some collision sound
                        }
                    }
                    break;
                }
            }
        }
        static MyParticleEffect GetEffectForWeapon(MyEntity weapon, int effectID)
        {
            Dictionary <int, MyParticleEffect> effects;

            m_hitParticles.TryGetValue(weapon, out effects);
            if (effects == null)
            {
                effects = new Dictionary <int, MyParticleEffect>();
                m_hitParticles.Add(weapon, effects);
            }

            MyParticleEffect effect;

            effects.TryGetValue(effectID, out effect);

            if (effect == null)
            {
                if (MyParticlesManager.TryCreateParticleEffect(effectID, out effect))
                {
                    effects.Add(effectID, effect);
                    effect.Tag       = weapon;
                    effect.OnDelete += new EventHandler(effect_OnDelete);
                }
            }
            else
            {
                effect.Restart();
            }

            return(effect);
        }
 public void Update()
 {
     if (m_particleId < 0)
     {
         return;
     }
     if (m_effect == null || m_effect.IsStopped)
     {
         if (m_playedOnce && m_loop == false)
         {
             m_canBeDeleted = true;
         }
         else
         {
             if (m_timer > 0f)
             {
                 m_timer -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
             }
             else
             {
                 m_playedOnce   = true;
                 m_canBeDeleted = !MyParticlesManager.TryCreateParticleEffect(m_particleId, out m_effect);
                 if (m_effect != null)
                 {
                     m_effect.WorldMatrix = m_entity.WorldMatrix;
                 }
                 if (m_spawnTimeMax > 0f)
                 {
                     m_timer = MyUtils.GetRandomFloat(m_spawnTimeMin, m_spawnTimeMax);
                 }
                 else
                 {
                     m_timer = 0;
                 }
             }
         }
     }
     else
     {
         if (m_effect != null)
         {
             float time = m_effect.GetElapsedTime();
             if (m_duration > 0f && time >= m_duration)
             {
                 m_effect.Stop();
             }
             else
             {
                 if (m_originPoint != null)
                 {
                     m_effect.WorldMatrix = MatrixD.Multiply(MatrixD.Normalize(m_originPoint.Matrix), m_entity.WorldMatrix);
                 }
                 else
                 {
                     m_effect.WorldMatrix = m_entity.WorldMatrix;
                 }
             }
         }
     }
 }
Example #11
0
        private void SpawnEjection()
        {
            var eInfo    = Ejector.Info;
            var ejectDef = ActiveAmmoDef.AmmoDef.Ejection;

            if (ejectDef.Type == WeaponDefinition.AmmoDef.AmmoEjectionDef.SpawnType.Item && System.Session.IsServer)
            {
                var delay = (uint)ejectDef.CompDef.Delay;
                if (delay <= 0)
                {
                    MyFloatingObjects.Spawn(ActiveAmmoDef.AmmoDef.Const.EjectItem, eInfo.Position, eInfo.Direction, MyPivotUp, null, EjectionSpawnCallback);
                }
                else
                {
                    System.Session.FutureEvents.Schedule(EjectionDelayed, null, delay);
                }
            }
            else if (System.Session.HandlesInput)
            {
                var particle = ActiveAmmoDef.AmmoDef.AmmoGraphics.Particles.Eject;
                MyParticleEffect ejectEffect;
                var matrix = MatrixD.CreateTranslation(eInfo.Position);

                if (MyParticlesManager.TryCreateParticleEffect(particle.Name, ref matrix, ref eInfo.Position, uint.MaxValue, out ejectEffect))
                {
                    //ejectEffect.UserColorMultiplier = particle.Color;
                    var scaler = 1;
                    ejectEffect.UserRadiusMultiplier = particle.Extras.Scale * scaler;
                    //var scale = particle.ShrinkByDistance ? MathHelper.Clamp(MathHelper.Lerp(1, 0, Vector3D.Distance(System.Session.CameraPos, eInfo.Position) / particle.Extras.MaxDistance), 0.05f, 1) : 1;
                    //ejectEffect.UserScale = (float)scale * scaler;
                    ejectEffect.Velocity = eInfo.Direction * ActiveAmmoDef.AmmoDef.Ejection.Speed;
                }
            }
        }
Example #12
0
        private void UpdateEmitters()
        {
            var toRemove = new HashSet <IMySlimBlock>();

            foreach (KeyValuePair <IMySlimBlock, MyParticleEffect> e in _emitters)
            {
                Vector3D pos = e.Key.GetPosition();

                bool closed = e.Key.Closed();
                bool zero   = Vector3D.IsZero(pos);

                if (closed || zero)
                {
                    //if(zero)
                    //MyAPIGateway.Utilities.ShowMessage("Emitter", $"{closed}:{zero}");
                    toRemove.Add(e.Key);
                    e.Value.Stop();
                    MyParticlesManager.RemoveParticleEffect(e.Value);
                    continue;
                }
                MatrixD mat = e.Value.WorldMatrix;
                mat.Translation     = pos;
                e.Value.WorldMatrix = mat;
            }

            foreach (IMySlimBlock r in toRemove)
            {
                _emitters.Remove(r);
            }
        }
Example #13
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);
        }
Example #14
0
        public static void AddNewEmitters(Dictionary <IMySlimBlock, int> newEmitters)
        {
            List <KeyValuePair <IMySlimBlock, int> > eList = newEmitters.Where(e => Vector3D.DistanceSquared(e.Key.GetPosition(), MyAPIGateway.Session.Camera.Position) < 10000).ToList();

            eList.Shuffle();

            //_effect.UserScale = 0.5f * Grid.GridSize;
            //Vector3 normal = -Vector3.Normalize(Grid.Physics.LinearVelocity);
            //MatrixD effectMatrix = MatrixD.CreateWorld(Grid.GridIntegerToWorld(kpair.Value), normal, Vector3.CalculatePerpendicularVector(normal));
            //effectMatrix.Translation = Grid.GridIntegerToWorld(kpair.Value);
            //_effect.WorldMatrix = effectMatrix;

            for (var index = 0; index < eList.Count; index++)
            {
                KeyValuePair <IMySlimBlock, int> e = eList[index];
                if (!_emitters.ContainsKey(e.Key))
                {
                    MyParticleEffect eff;
                    MyParticlesManager.TryCreateParticleEffect(e.Value, out eff);
                    var mat = new MatrixD();
                    mat.Translation = e.Key.GetPosition();

                    eff.WorldMatrix = mat;
                    eff.Start(e.Value, eff.Name);
                    if (e.Key.CubeGrid.GridSizeEnum == MyCubeSize.Small)
                    {
                        eff.UserEmitterScale = 0.1f;
                    }
                    _emitters.Add(e.Key, eff);
                }
            }
        }
Example #15
0
        public static void CheckAndRemoveEmitters(Dictionary <IMySlimBlock, int> newEmitters)
        {
            var toRemove = new HashSet <IMySlimBlock>();

            foreach (KeyValuePair <IMySlimBlock, MyParticleEffect> e in _emitters)
            {
                if (MyAPIGateway.Session.Camera != null)
                {
                    if (Vector3D.DistanceSquared(MyAPIGateway.Session.Camera.Position, e.Value.WorldMatrix.Translation) > 200 * 200)
                    {
                        toRemove.Add(e.Key);
                        MyParticlesManager.RemoveParticleEffect(e.Value);
                        continue;
                    }
                }

                if (!newEmitters.ContainsKey(e.Key))
                {
                    toRemove.Add(e.Key);
                    MyParticlesManager.RemoveParticleEffect(e.Value);
                }
            }

            foreach (IMySlimBlock r in toRemove)
            {
                _emitters.Remove(r);
            }
        }
Example #16
0
        public void Start(Vector3 direction, int?trailEffectId)
        {
            this.Physics.LinearVelocity  = direction;
            this.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomFloat(0.2f, 1.5f), MyMwcUtils.GetRandomFloat(0.2f, 1.5f), 0);

            if (m_size == 0)
            {
                m_size = this.WorldVolume.Radius;
            }

            if (trailEffectId != null)
            {
                m_trailEffect                      = MyParticlesManager.CreateParticleEffect(trailEffectId.Value);
                m_trailEffect.AutoDelete           = true;
                m_trailEffect.UserScale            = this.WorldVolume.Radius / 10;
                m_trailEffect.UserBirthMultiplier /= 2;
                m_trailEffect.WorldMatrix          = this.WorldMatrix;// worldMatrix;
            }

            m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxMeteorFly, this.GetPosition(), this.GetForward(), Vector3.Up, direction);
            m_startTime  = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            if (MyMultiplayerGameplay.IsHosting)
            {
                MyMultiplayerGameplay.Static.NewEntity(GetObjectBuilder(true), WorldMatrix);
            }
        }
Example #17
0
        private void SetWeather(Dictionary <string, int> density)
        {
            DisposeEffects();
            Random r = new Random();

            foreach (string key in density.Keys)
            {
                for (int n = 0; n < density[key]; n++)
                {
                    MyParticleEffect near, far;
                    if (MyParticlesManager.TryCreateParticleEffect("Equinox_Weather_" + key + "_Near", out near))
                    {
                        near.UserRadiusMultiplier = (float)(1 + (r.NextDouble() * 2 - 1) * 0.1);
                        near.UserBirthMultiplier  = (float)(1 + (r.NextDouble() * 2 - 1) * 0.1);
                        nearEffects.Add(near);
                    }
                    else
                    {
                        Logging.Instance.Log("Failed to create near effect for {0}", key);
                    }
                    if (MyParticlesManager.TryCreateParticleEffect("Equinox_Weather_" + key + "_Far", out far))
                    {
                        far.UserRadiusMultiplier = (float)(1 + (r.NextDouble() * 2 - 1) * 0.1);

                        far.UserBirthMultiplier = (float)(1 + (r.NextDouble() * 2 - 1) * 0.1);
                        farEffects.Add(far);
                    }
                    else
                    {
                        Logging.Instance.Log("Failed to create far effect for {0}", key);
                    }
                }
            }
        }
Example #18
0
            private void DestroyMeteor()
            {
                MyParticleEffect impactParticle;

                if (InParticleVisibleRange && MyParticlesManager.TryCreateParticleEffect("Meteorit_Smoke1AfterHit", out impactParticle))
                {
                    impactParticle.WorldMatrix = Entity.WorldMatrix;
                    impactParticle.UserScale   = 5 * MyUtils.GetRandomFloat(0.8f, 1.2f);
                }
                if (m_dustEffect != null)
                {
                    m_dustEffect.Stop();
                    if (MySession.Static.EnvironmentHostility != MyEnvironmentHostilityEnum.CATACLYSM_UNREAL)
                    {
                        m_dustEffect.Close(false);
                        if (InParticleVisibleRange && m_particleVectorUp != Vector3.Zero && MyParticlesManager.TryCreateParticleEffect("Meteorit_Smoke1AfterHit", out m_dustEffect))
                        {
                            MatrixD m = MatrixD.CreateWorld(Entity.WorldMatrix.Translation, m_particleVectorForward, m_particleVectorUp);
                            m_dustEffect.WorldMatrix = m;
                        }
                    }
                    m_dustEffect = null;
                }
                if (m_dustEffect != null)
                {
                    m_dustEffect.Stop();
                    m_dustEffect = null;
                }
                PlayExplosionSound();
            }
        private void EmpDrawExplosion()
        {
            _effect?.Stop();
            var epiCenter = EmpWork.EpiCenter;
            var rangeCap  = EmpWork.RangeCap;
            var radius    = (float)(rangeCap * 0.01);
            var scale     = 7f;

            if (radius < 7)
            {
                scale = radius;
            }

            var matrix = MatrixD.CreateTranslation(epiCenter);

            MyParticlesManager.TryCreateParticleEffect(6666, out _effect, ref matrix, ref epiCenter, uint.MaxValue, true); // 15, 16, 24, 25, 28, (31, 32) 211 215 53
            if (_effect == null)
            {
                EmpWork.EmpDrawComplete();
                return;
            }

            if (Enforced.Debug >= 2)
            {
                Log.Line($"[EmpDraw] scale:{scale} - radius:{radius} - rangeCap:{rangeCap}");
            }

            _effect.UserRadiusMultiplier = radius;
            _effect.UserScale            = scale;

            //TODO fix if keens add support again
            //_effect.UserColorMultiplier = new Vector4(255, 255, 255, 10);
            _effect.Play();
            EmpWork.EmpDrawComplete();
        }
Example #20
0
        internal void Draw(MatrixD aboveplayer)
        {
            TargetPosition = positionAlgorithm(aboveplayer);
            AbovePosition  = new MatrixD(TargetPosition)
            {
                Translation = TargetPosition.Translation + TargetPosition.Up * 100
            };

            //TODO hide behind debug bool
            MySimpleObjectDraw.DrawLine(AbovePosition.Translation, TargetPosition.Translation,
                                        VRage.Utils.MyStringId.GetOrCompute("Square"), ref debugLineColor, 0.05f);

            if (ShouldDraw && (effect == null || effect.IsStopped))
            {
                MyParticlesManager.TryCreateParticleEffect("sandstorm", out effect);
                effect.UserScale = 1.0f;
                effect.Loop      = true;
            }

            if (ShouldDraw)
            {
                //TODO why does this work but not just using the TargetPosition =/
                effect.WorldMatrix = MatrixD.CreateWorld(TargetPosition.Translation, TargetPosition.Up, TargetPosition.Forward);
            }
            else
            {
                if (effect != null)
                {
                    effect.Stop();
                }
            }
        }
Example #21
0
        protected void CreateParticles(Vector3D position, bool createDust, bool createSparks, bool createStones)
        {
            if (!m_particleEffectsEnabled)
            {
                return;
            }

            if (createDust)
            {
                if (DustParticles == null)
                {
                    ProfilerShort.Begin(string.Format("Create dust: stones = {0}", createStones));
                    //MyParticleEffectsIDEnum.Smoke_Construction
                    MyParticlesManager.TryCreateParticleEffect(createStones ? (int)m_dustEffectStonesId : (int)m_dustEffectId, out DustParticles);
                    ProfilerShort.End();
                }

                if (DustParticles != null)
                {
                    DustParticles.Near        = m_drillEntity.Render.NearFlag;
                    DustParticles.WorldMatrix = MatrixD.CreateTranslation(position);
                }
            }

            if (createSparks)
            {
                ProfilerShort.Begin("Create sparks");
                if (MyParticlesManager.TryCreateParticleEffect((int)m_sparksEffectId, out SparkEffect))
                {
                    SparkEffect.WorldMatrix = Matrix.CreateTranslation(position);
                    SparkEffect.Near        = m_drillEntity.Render.NearFlag;
                }
                ProfilerShort.End();
            }
        }
Example #22
0
        protected void CreateParticles(Vector3D position, bool createDust, bool createSparks, bool createStones)
        {
            if (m_dustParticles != null && m_dustParticles.IsStopped)
            {
                m_dustParticles = null;
            }

            if (createDust)
            {
                if (m_dustParticles == null)
                {
                    //MyParticleEffectsIDEnum.Smoke_Construction
                    MyParticlesManager.TryCreateParticleEffect(createStones ? (int)m_dustEffectStonesId : (int)m_dustEffectId, out m_dustParticles);
                }

                if (m_dustParticles != null)
                {
                    //m_dustParticles.AutoDelete = false;
                    //m_dustParticles.Near = m_drillEntity.Render.NearFlag;
                    m_dustParticles.WorldMatrix = MatrixD.CreateTranslation(position);
                }
            }

            if (createSparks)
            {
                MyParticleEffect sparks;
                if (MyParticlesManager.TryCreateParticleEffect((int)m_sparksEffectId, out sparks))
                {
                    sparks.WorldMatrix = Matrix.CreateTranslation(position);
                    //sparks.Near = m_drillEntity.Render.NearFlag;
                }
            }
        }
Example #23
0
        public override void UpdateOnceBeforeFrame()
        {
            Debug.Assert(Sync.IsServer, "Connector can take objects only on the server!");

            base.UpdateOnceBeforeFrame();
            if (m_entitiesToTake.Count > 0)
            {
                MyParticleEffect effect;
                if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Collector, out effect))
                {
                    effect.WorldMatrix = MatrixD.CreateWorld(m_entitiesToTake.ElementAt(0).PositionComp.GetPosition(), WorldMatrix.Down, WorldMatrix.Forward);
                }
            }
            bool playSound = false;

            foreach (var entity in m_entitiesToTake)
            {
                var floatingEntity = entity as MyFloatingObject;
                this.GetInventory().TakeFloatingObject(entity);
                playSound = true;
            }
            if (playSound)
            {
                m_soundEmitter.PlaySound(m_actionSound);
                MyMultiplayer.RaiseEvent(this, x => x.PlayActionSound);
            }
            //m_entitiesToTake.Clear();
        }
Example #24
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);
        }
Example #25
0
            private void DestroyMeteor()
            {
                MyParticleEffect impactParticle;

                if (InParticleVisibleRange && MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.MeteorAsteroidCollision, out impactParticle))
                {
                    impactParticle.WorldMatrix = Entity.WorldMatrix;
                    impactParticle.UserScale   = MyUtils.GetRandomFloat(1.5f, 2);
                }
                if (m_dustEffect != null)
                {
                    m_dustEffect.Stop();
                    if (m_particleEffectId == (int)MyParticleEffectsIDEnum.MeteorParticle)
                    {
                        m_dustEffect.Close(false);
                        if (InParticleVisibleRange && m_particleVectorUp != Vector3.Zero && MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.MeteorParticleAfterHit, out m_dustEffect))
                        {
                            MatrixD m = MatrixD.CreateWorld(Entity.WorldMatrix.Translation, m_particleVectorForward, m_particleVectorUp);
                            m_dustEffect.WorldMatrix = m;
                        }
                    }
                    m_dustEffect = null;
                }
                PlayExplosionSound();
            }
Example #26
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (CurrentState == MyDrillStateEnum.Drilling)
            {
                if (m_trailEffect == null)
                {
                    m_trailEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Drill_Thermal);

                    //Must be done with handler because we need to set world matrix until effect totally dies
                    m_trailEffect.OnDelete += OnTrailEffectDeleted;
                }
            }
            else
            {
                if (m_trailEffect != null)
                {
                    m_trailEffect.Stop();
                    m_trailEffect = null;
                }
            }

            if (m_trailEffect != null)
            {
                Matrix effectMatrix = Matrix.CreateWorld(m_positionMuzzleInWorldSpace + MySmallShipConstants.ALL_SMALL_SHIP_MODEL_SCALE * 2 * WorldMatrix.Forward, WorldMatrix.Forward, WorldMatrix.Up);
                m_trailEffect.WorldMatrix = effectMatrix;
            }

            if (m_drillHead != null)
            {
                m_drillHead.SetWorldMatrixForCockpit(ref m_worldMatrixForRenderingFromCockpitView);
                m_drillHead.RotationSpeed = -m_rotatingSpeed;
            }
        }
Example #27
0
        private void CreateEffect()
        {
            if (m_effect != null)
            {
                m_effect.Stop();
                m_effect = null;
            }

            if (MyParticlesManager.TryCreateParticleEffect(48, out m_effect))
            {
                Matrix mat;
                Orientation.GetMatrix(out mat);

                var orientation = mat;

                if (IsDepressurizing)
                {
                    orientation.Left    = mat.Right;
                    orientation.Up      = mat.Down;
                    orientation.Forward = mat.Backward;
                }

                orientation             = Matrix.Multiply(orientation, CubeGrid.PositionComp.WorldMatrix.GetOrientation());
                orientation.Translation = CubeGrid.GridIntegerToWorld(Position + mat.Forward / 4f);

                m_effect.WorldMatrix = orientation;

                m_effect.UserScale = 3f;
            }
        }
Example #28
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (m_elapsedMiliseconds > TimeToActivate && !m_smokeFired)
            {
                StartSmokeEffect();
                Physics.LinearVelocity = Vector3.Zero;
                Explode();

                m_smokeCue = MyAudio.AddCue2dOr3d(this, MySoundCuesEnum.WepBombSmartSmoke,
                                                  GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity);
            }

            if (m_isExploded)
            {
                var effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_SmallGunShot);
                effect.WorldMatrix = this.WorldMatrix;
                effect.UserScale   = 2f;
                MarkForClose();
            }

            if (m_smokeEnded)
            {
                MarkForClose();
            }
            else if (m_smokeFired)
            {
                // Aggro near bots
                MyDangerZones.Instance.NotifyArea(GetPosition(), 300, OwnerEntity);
            }
        }
 private void UpdateParticleEffect()
 {
     if (_effectCachedModel != _reactor.Model)
     {
         _effectCachedModel = _reactor.Model;
         var tmp = new Dictionary <string, IMyModelDummy>();
         _effectCachedModel?.GetDummies(tmp);
         _effectMatrix = tmp.GetValueOrDefault("subpart_PlasmaParticle")?.Matrix; // empty for particle
     }
     if (_reactor.IsWorking && _effectMatrix.HasValue)
     {
         var fractionalOutput = _reactor.CurrentOutput / _reactor.MaxOutput;
         var dTheta           = MAX_RATE * fractionalOutput * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
         _effectMatrix = _effectMatrix.Value * MatrixD.CreateRotationY(dTheta);
         if (_effect == null)
         {
             MyParticlesManager.TryCreateParticleEffect("PlasmaSparks", out _effect); // particle subtype
         }
         _effect.WorldMatrix = _effectMatrix.Value * _reactor.WorldMatrix;
         _effect.Velocity    = _reactor.CubeGrid.Physics?.GetVelocityAtPoint(_effect.WorldMatrix.Translation) ?? Vector3.Right; // rotation
     }
     else
     {
         _effect?.Stop();
         if (_effect != null)
         {
             MyParticlesManager.RemoveParticleEffect(_effect);
         }
         _effect = null;
     }
 }
        // cloned MySlimBlock.CreateConstructionSmokes()
        void CreateConstructionSmokes(MatrixD worldMatrix)
        {
            MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.GetCubeBlockDefinition(BlockDefId);

            if (blockDef == null)
            {
                return;
            }

            float gridSize = MyDefinitionManager.Static.GetCubeSize(blockDef.CubeSize);

            Vector3I min = Vector3I.Zero;
            Vector3I max = blockDef.Size - Vector3I.One;

            Vector3     halfGridSizeVec = new Vector3(gridSize) / 2f;
            BoundingBox boundingBox     = new BoundingBox(min * gridSize - halfGridSizeVec, max * gridSize + halfGridSizeVec);

            if (ModelBB.HasValue)
            {
                boundingBox = ModelBB.Value;

                //BoundingBox bb = BoundingBox.CreateInvalid();
                //Vector3[] modelCorners = ModelBB.Value.GetCorners();
                //foreach(Vector3 position in modelCorners)
                //{
                //    bb = bb.Include(Vector3.Transform(position);
                //}

                //boundingBox = new BoundingBox(bb.Min + boundingBox.Center, bb.Max + boundingBox.Center);
            }

            boundingBox.Inflate(-0.3f);

            Vector3[] corners = boundingBox.GetCorners();
            float     step    = 0.25f;

            for (int v = 0; v < MyOrientedBoundingBox.StartVertices.Length; v++)
            {
                Vector3 vec  = corners[MyOrientedBoundingBox.StartVertices[v]];
                float   n1   = 0f;
                float   n2   = Vector3.Distance(vec, corners[MyOrientedBoundingBox.EndVertices[v]]);
                Vector3 vec2 = step * Vector3.Normalize(corners[MyOrientedBoundingBox.EndVertices[v]] - corners[MyOrientedBoundingBox.StartVertices[v]]);

                while (n1 < n2)
                {
                    Vector3D pos = Vector3D.Transform(vec, worldMatrix);
                    MatrixD  wm  = MatrixD.CreateTranslation(pos);

                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect("AdvancedWelding_Detach", ref wm, ref pos, uint.MaxValue, out effect))
                    {
                        effect.Velocity = Velocity;
                    }

                    n1  += step;
                    vec += vec2;
                }
            }
        }