private void SpawnEjection()
        {
            var eInfo    = Ejector.Info;
            var ejectDef = ActiveAmmoDef.ConsumableDef.Ejection;

            if (ejectDef.Type == WeaponDefinition.ConsumableDef.AmmoEjectionDef.SpawnType.Item)
            {
                var delay = (uint)ejectDef.CompDef.Delay;
                if (delay <= 0)
                {
                    MyFloatingObjects.Spawn(ActiveAmmoDef.ConsumableDef.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.ConsumableDef.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.ConsumableDef.Ejection.Speed;
                }
            }
        }
 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;
                }
            }
        }
Beispiel #4
0
        public override void DoDamage(float damage, int itemInstanceId, Vector3D position, Vector3 normal, MyDamageType type)
        {
            // CH: TODO: Move the particle effect to definitions
            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.ChipOff_Wood, out effect))
            {
                effect.WorldMatrix = MatrixD.CreateWorld(position, Vector3.CalculatePerpendicularVector(normal), normal);
                effect.AutoDelete  = true;
            }

            if (!Sync.IsServer)
            {
                return;
            }

            MyCutTreeInfo cutTreeInfo = default(MyCutTreeInfo);
            int           index       = -1;

            for (int i = 0; i < m_cutTreeInfos.Count; ++i)
            {
                cutTreeInfo = m_cutTreeInfos[i];
                if (itemInstanceId == cutTreeInfo.ItemInstanceId)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                cutTreeInfo = new MyCutTreeInfo();
                cutTreeInfo.ItemInstanceId = itemInstanceId;

                index = m_cutTreeInfos.Count;
                m_cutTreeInfos.Add(cutTreeInfo);
            }

            cutTreeInfo.LastHit   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            cutTreeInfo.Progress += damage;

            if (cutTreeInfo.Progress >= 1)
            {
                if (type != MyDamageType.Drill)
                {
                    position.Y = m_itemsData[itemInstanceId].Transform.Position.Y;
                }
                CutTree(itemInstanceId, position, normal);
                m_cutTreeInfos.RemoveAtFast(index);
            }
            else
            {
                m_cutTreeInfos[index] = cutTreeInfo;
            }

            return;
        }
Beispiel #5
0
        internal void RunBeam()
        {
            if (FiringWeapon != null)
            {
                var weapon = FiringWeapon.Platform.Weapons[WeaponId];
                var effect = weapon.HitEffects[MuzzleId];
                if (OnScreen != Screen.None)
                {
                    if (effect != null)
                    {
                        var elapsedTime = effect.GetElapsedTime();
                        if (elapsedTime <= 0 || elapsedTime >= 1)
                        {
                            effect.Stop(true);
                            effect = null;
                        }
                    }
                    MatrixD matrix;
                    MatrixD.CreateTranslation(ref Hit.HitPos, out matrix);
                    if (effect == null)
                    {
                        if (!MyParticlesManager.TryCreateParticleEffect(AmmoDef.AmmoGraphics.Particles.Hit.Name, ref matrix, ref Hit.HitPos, uint.MaxValue, out effect))
                        {
                            if (weapon.HitEffects[MuzzleId] != null)
                            {
                                weapon.HitEffects[MuzzleId].Stop();
                                weapon.HitEffects[MuzzleId] = null;
                            }
                            return;
                        }

                        effect.UserRadiusMultiplier = AmmoDef.AmmoGraphics.Particles.Hit.Extras.Scale * 1;
                        effect.UserColorMultiplier  = AmmoDef.AmmoGraphics.Particles.Hit.Color;
                        effect.UserRadiusMultiplier = AmmoDef.AmmoGraphics.Particles.Hit.Extras.Scale * 1;
                        var scale = MathHelper.Lerp(1, 0, (DistanceToLine * 2) / AmmoDef.AmmoGraphics.Particles.Hit.Extras.MaxDistance);
                        effect.UserScale = scale;
                    }
                    else if (effect.IsEmittingStopped)
                    {
                        effect.Play();
                    }

                    effect.WorldMatrix          = matrix;
                    effect.Velocity             = HitVelocity;
                    weapon.HitEffects[MuzzleId] = effect;
                }
                else if (effect != null)
                {
                    effect.Stop(effect.Loop);
                    weapon.HitEffects[MuzzleId] = null;
                }
            }
        }
Beispiel #6
0
        private void spawnImpactParticle(Vector3D pos, Vector3 dir)
        {
            dir.Normalize();
            var matrix = MatrixD.CreateFromTransformScale(Quaternion.CreateFromForwardUp(-dir, Vector3.Up), pos,
                                                          Vector3D.One);

            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect("MaterialHit_Metal_GatlingGun", ref matrix, ref pos, uint.MaxValue, out effect))
            {
                effect.Play();
                effect.UserScale = 0.2f;
            }
        }