Example #1
0
        public override bool Simulate(float dt)
        {
            m_time += dt;
            float   num  = MathUtils.Lerp(150f, 20f, MathUtils.Saturate(2f * m_time / 0.5f));
            float   num2 = MathUtils.Pow(0.01f, dt);
            float   s    = MathUtils.Lerp(20f, 0f, MathUtils.Saturate(2f * m_time / 0.5f));
            Vector3 v    = new Vector3(2f, 2f, 1f);

            if (m_time < 0.5f)
            {
                m_toGenerate += num * dt;
            }
            else
            {
                m_toGenerate = 0f;
            }
            bool flag = false;

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle particle = base.Particles[i];
                if (particle.IsActive)
                {
                    flag           = true;
                    particle.Time += dt;
                    if (particle.Time <= particle.Duration)
                    {
                        particle.Position   += particle.Velocity * dt;
                        particle.Velocity   *= num2;
                        particle.Velocity   += v * dt;
                        particle.TextureSlot = (int)MathUtils.Min(9f * particle.Time / particle.Duration, 8f);
                        particle.Size        = new Vector2(0.3f);
                    }
                    else
                    {
                        particle.IsActive = false;
                    }
                }
                else if (m_toGenerate >= 1f)
                {
                    particle.IsActive = true;
                    Vector3 v2 = m_random.Vector3(0f, 1f);
                    particle.Position = m_position + 0.3f * v2;
                    particle.Color    = m_color;
                    particle.Velocity = s * (m_direction + m_random.Vector3(0f, 0.1f)) + 2.5f * v2;
                    particle.Size     = Vector2.Zero;
                    particle.Time     = 0f;
                    particle.Duration = m_random.Float(0.5f, 2f);
                    particle.FlipX    = m_random.Bool();
                    particle.FlipY    = m_random.Bool();
                    m_toGenerate     -= 1f;
                }
            }
            m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f);
            if (!flag && m_time >= 0.5f)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        public static void DrawVrBackground()
        {
            Matrix          hmdMatrix = VrManager.HmdMatrix;
            TexturedBatch3D batch     = m_pr3.TexturedBatch(ContentManager.Get <Texture2D>("Textures/Star"));

            Random.Seed(0);
            for (int i = 0; i < 1500; i++)
            {
                float   f       = MathUtils.Pow(Random.Float(0f, 1f), 6f);
                Color   rGB     = (MathUtils.Lerp(0.05f, 0.4f, f) * Color.White).RGB;
                int     num     = 6;
                Vector3 vector  = Random.Vector3(500f);
                Vector3 vector2 = Vector3.Normalize(Vector3.Cross(vector, Vector3.UnitY)) * num;
                Vector3 up      = Vector3.Normalize(Vector3.Cross(vector2, vector)) * num;
                QueueQuad(batch, vector + hmdMatrix.Translation, vector2, up, rGB);
            }
            TexturedBatch3D batch2 = m_pr3.TexturedBatch(ContentManager.Get <Texture2D>("Textures/Blocks"), useAlphaTest: true, 1, null, null, null, SamplerState.PointClamp);

            for (int j = -8; j <= 8; j++)
            {
                for (int k = -8; k <= 8; k++)
                {
                    float   num2    = 1f;
                    float   num3    = 1f;
                    Vector3 vector3 = new Vector3(((float)j - 0.5f) * num2, 0f, ((float)k - 0.5f) * num2) + new Vector3(MathUtils.Round(hmdMatrix.Translation.X), 0f, MathUtils.Round(hmdMatrix.Translation.Z));
                    float   num4    = Vector3.Distance(vector3, hmdMatrix.Translation);
                    float   num5    = MathUtils.Lerp(1f, 0f, MathUtils.Saturate(num4 / 7f));
                    if (num5 > 0f)
                    {
                        QueueQuad(batch2, vector3, new Vector3(num3, 0f, 0f), new Vector3(0f, 0f, num3), Color.Gray * num5, new Vector2(0.1875f, 0.25f), new Vector2(0.25f, 0.3125f));
                    }
                }
            }
        }
 public override void Update(float dt)
 {
     if (m_random.Float(0f, 1f) < 0.1f * dt)
     {
         m_frequency = m_random.Float(0.33f, 5f) * 0.5f;
     }
     if (m_random.Float(0f, 1f) < m_frequency * dt)
     {
         SubsystemPlayers subsystemPlayers = base.GameWidget.SubsystemGameWidgets.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
         if (subsystemPlayers.PlayersData.Count > 0)
         {
             Vector3 spawnPosition = subsystemPlayers.PlayersData[0].SpawnPosition;
             spawnPosition.X += m_random.Float(-150f, 150f);
             spawnPosition.Y  = m_random.Float(70f, 120f);
             spawnPosition.Z += m_random.Float(-150f, 150f);
             Vector3 direction = m_random.Vector3(1f);
             SetupPerspectiveCamera(spawnPosition, direction, Vector3.UnitY);
         }
     }
     if (m_random.Float(0f, 1f) < 0.5f * m_frequency * dt)
     {
         base.GameWidget.SubsystemGameWidgets.Project.FindSubsystem <SubsystemTimeOfDay>(throwOnError: true).TimeOfDayOffset = m_random.Float(0f, 1f);
     }
     if (m_random.Float(0f, 1f) < 1f * dt * 0.5f)
     {
         GameManager.SaveProject(waitForCompletion: false, showErrorDialog: false);
     }
 }
Example #4
0
        public void AddNote(Color color)
        {
            int      num = 0;
            Particle particle;

            while (true)
            {
                if (num < base.Particles.Length)
                {
                    particle = base.Particles[num];
                    if (!base.Particles[num].IsActive)
                    {
                        break;
                    }
                    num++;
                    continue;
                }
                return;
            }
            particle.IsActive         = true;
            particle.Position         = m_position;
            particle.Color            = Color.White;
            particle.Size             = new Vector2(0.1f);
            particle.TimeToLive       = m_random.Float(1f, 1.5f);
            particle.Velocity         = 3f * (m_direction + m_random.Vector3(0.5f));
            particle.BaseColor        = color;
            particle.TextureSlot      = m_random.Int(0, base.TextureSlotsCount * base.TextureSlotsCount - 1);
            particle.BillboardingMode = ParticleBillboardingMode.Vertical;
        }
Example #5
0
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(neighborX, neighborY, neighborZ);

            if (cellContents != 0 && cellContents != 18)
            {
                return;
            }
            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0));
            if (!m_random.Bool(0.25f))
            {
                return;
            }
            int   num  = 0;
            int   num2 = 0;
            float max  = m_treasureData.Sum((TreasureData t) => t.Probability);
            float num3 = m_random.Float(0f, max);

            TreasureData[] treasureData = m_treasureData;
            for (int i = 0; i < treasureData.Length; i++)
            {
                TreasureData treasureData2 = treasureData[i];
                num3 -= treasureData2.Probability;
                if (num3 <= 0f)
                {
                    num  = treasureData2.Value;
                    num2 = m_random.Int(1, treasureData2.MaxCount);
                    break;
                }
            }
            if (num != 0 && num2 > 0)
            {
                for (int j = 0; j < num2; j++)
                {
                    m_subsystemPickables.AddPickable(num, 1, new Vector3(x, y, z) + m_random.Vector3(0.1f, 0.4f) + new Vector3(0.5f), Vector3.Zero, null);
                }
                int num4 = m_random.Int(3, 6);
                for (int k = 0; k < num4; k++)
                {
                    m_subsystemPickables.AddPickable(248, 1, new Vector3(x, y, z) + m_random.Vector3(0.1f, 0.4f) + new Vector3(0.5f), Vector3.Zero, null);
                }
            }
        }
Example #6
0
        public HitValueParticleSystem(Vector3 position, Vector3 velocity, Color color, string text)
            : base(1)
        {
            Random   random = new Random();
            Particle obj    = base.Particles[0];

            obj.IsActive   = true;
            obj.Position   = position;
            obj.TimeToLive = 0.9f;
            obj.Velocity   = velocity + random.Vector3(0.75f) * new Vector3(1f, 0f, 1f) + 0.5f * Vector3.UnitY;
            obj.BaseColor  = color;
            obj.Text       = text;
        }
Example #7
0
 public void AddSplash(int value, Vector3 position, Color color)
 {
     for (int i = 0; i < base.Particles.Length; i++)
     {
         Particle particle = base.Particles[i];
         if (!particle.IsActive)
         {
             Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)];
             particle.IsActive  = true;
             particle.Position  = position;
             particle.BaseColor = color;
             if (block is WaterBlock)
             {
                 particle.Position.Y      += 0.05f;
                 particle.BaseSize1        = 0.02f;
                 particle.BaseSize2        = 0.09f;
                 particle.Duration         = (particle.TimeToLive = m_random.Float(0.3f, 0.5f));
                 particle.Velocity         = Vector3.Zero;
                 particle.Gravity          = 0f;
                 particle.BillboardingMode = ParticleBillboardingMode.Horizontal;
                 particle.FadeFactor       = 1.6f;
             }
             else if (block.IsCollidable)
             {
                 particle.BaseSize1        = 0.03f;
                 particle.BaseSize2        = 0.08f;
                 particle.Duration         = (particle.TimeToLive = m_random.Float(0.25f, 0.3f));
                 particle.Velocity         = m_random.Float(0.7f, 0.9f) * Vector3.UnitY;
                 particle.Gravity          = -10f;
                 particle.BillboardingMode = ParticleBillboardingMode.Camera;
                 particle.FadeFactor       = 2.8f;
             }
             else if (m_random.Bool(0.33f))
             {
                 particle.BaseSize1        = m_random.Float(0.015f, 0.025f);
                 particle.BaseSize2        = particle.BaseSize1;
                 particle.Duration         = (particle.TimeToLive = m_random.Float(0.25f, 0.3f));
                 particle.Velocity         = m_random.Vector3(0f, 1.5f) * new Vector3(1f, 0f, 1f);
                 particle.Gravity          = -10f;
                 particle.BillboardingMode = ParticleBillboardingMode.Camera;
                 particle.FadeFactor       = 2.8f;
             }
             break;
         }
     }
     m_isActive = true;
 }
        public override bool Simulate(float dt)
        {
            int num  = Terrain.ToCell(Position.X);
            int num2 = Terrain.ToCell(Position.Y);
            int num3 = Terrain.ToCell(Position.Z);
            int x    = 0;

            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num + 1, num2, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num - 1, num2, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 + 1, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 - 1, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 + 1));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 - 1));
            Color white = Color.White;
            float num4  = LightingManager.LightIntensityByLightValue[x];

            white  *= num4;
            white.A = byte.MaxValue;
            dt      = MathUtils.Clamp(dt, 0f, 0.1f);
            float num5 = MathUtils.Pow(0.03f, dt);

            m_duration += dt;
            if (m_duration > 3.5f)
            {
                IsStopped = true;
            }
            float num6 = MathUtils.Saturate(1.3f * SimplexNoise.Noise(3f * m_duration + (float)(GetHashCode() % 100)) - 0.3f);
            float num7 = 30f * num6;

            m_toGenerate += num7 * dt;
            bool flag = false;

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle particle = base.Particles[i];
                if (particle.IsActive)
                {
                    flag = true;
                    particle.TimeToLive -= dt;
                    if (particle.TimeToLive > 0f)
                    {
                        Vector3 position = particle.Position;
                        Vector3 vector   = position + particle.Velocity * dt;
                        TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                        if (terrainRaycastResult.HasValue)
                        {
                            Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
                            vector = position;
                            if (plane.Normal.X != 0f)
                            {
                                particle.Velocity *= new Vector3(-0.05f, 0.05f, 0.05f);
                            }
                            if (plane.Normal.Y != 0f)
                            {
                                particle.Velocity *= new Vector3(0.05f, -0.05f, 0.05f);
                            }
                            if (plane.Normal.Z != 0f)
                            {
                                particle.Velocity *= new Vector3(0.05f, 0.05f, -0.05f);
                            }
                        }
                        particle.Position    = vector;
                        particle.Velocity.Y += -9.81f * dt;
                        particle.Velocity   *= num5;
                        particle.Color      *= MathUtils.Saturate(particle.TimeToLive);
                        particle.TextureSlot = (int)(8.99f * MathUtils.Saturate(3f - particle.TimeToLive));
                    }
                    else
                    {
                        particle.IsActive = false;
                    }
                }
                else if (!IsStopped && m_toGenerate >= 1f)
                {
                    Vector3 v = m_random.Vector3(0f, 1f);
                    particle.IsActive   = true;
                    particle.Position   = Position + 0.05f * v;
                    particle.Color      = Color.MultiplyColorOnly(white, m_random.Float(0.7f, 1f));
                    particle.Velocity   = MathUtils.Lerp(1f, 2.5f, num6) * Vector3.Normalize(Direction + 0.25f * v);
                    particle.TimeToLive = 3f;
                    particle.Size       = new Vector2(0.1f);
                    particle.FlipX      = m_random.Bool();
                    particle.FlipY      = m_random.Bool();
                    m_toGenerate       -= 1f;
                }
            }
            if (IsStopped)
            {
                return(!flag);
            }
            return(false);
        }
Example #9
0
        public static void AttackBody(ComponentBody target, ComponentCreature attacker, Vector3 hitPoint, Vector3 hitDirection, float attackPower, bool isMeleeAttack)
        {
            if (attacker != null && attacker is ComponentPlayer && target.Entity.FindComponent <ComponentPlayer>() != null && !target.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true).WorldSettings.IsFriendlyFireEnabled)
            {
                attacker.Entity.FindComponent <ComponentGui>(throwOnError: true).DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: true, playNotificationSound: true);
                return;
            }
            if (attackPower > 0f)
            {
                ComponentClothing componentClothing = target.Entity.FindComponent <ComponentClothing>();
                if (componentClothing != null)
                {
                    attackPower = componentClothing.ApplyArmorProtection(attackPower);
                }
                ComponentLevel componentLevel = target.Entity.FindComponent <ComponentLevel>();
                if (componentLevel != null)
                {
                    attackPower /= componentLevel.ResilienceFactor;
                }
                ComponentHealth componentHealth = target.Entity.FindComponent <ComponentHealth>();
                if (componentHealth != null)
                {
                    float  num = attackPower / componentHealth.AttackResilience;
                    string cause;
                    if (attacker != null)
                    {
                        string str          = attacker.KillVerbs[s_random.Int(0, attacker.KillVerbs.Count - 1)];
                        string attackerName = attacker.DisplayName;
                        cause = string.Format(LanguageControl.Get(fName, 4), attackerName, LanguageControl.Get(fName, str));
                    }
                    else
                    {
                        switch (s_random.Int(0, 5))
                        {
                        case 0:
                            cause = LanguageControl.Get(fName, 5);
                            break;

                        case 1:
                            cause = LanguageControl.Get(fName, 6);
                            break;

                        case 2:
                            cause = LanguageControl.Get(fName, 7);
                            break;

                        case 3:
                            cause = LanguageControl.Get(fName, 8);
                            break;

                        case 4:
                            cause = LanguageControl.Get(fName, 9);
                            break;

                        default:
                            cause = LanguageControl.Get(fName, 10);
                            break;
                        }
                    }
                    float health = componentHealth.Health;
                    componentHealth.Injure(num, attacker, ignoreInvulnerability: false, cause);
                    if (num > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound("Audio/Impacts/Body", 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                        float num2 = (health - componentHealth.Health) * componentHealth.AttackResilience;
                        if (attacker is ComponentPlayer && num2 > 0f)
                        {
                            string text2 = (0f - num2).ToString("0", CultureInfo.InvariantCulture);
                            HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + attacker.ComponentBody.Velocity, Color.White, text2);
                            target.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem);
                        }
                    }
                }
                ComponentDamage componentDamage = target.Entity.FindComponent <ComponentDamage>();
                if (componentDamage != null)
                {
                    float num3 = attackPower / componentDamage.AttackResilience;
                    componentDamage.Damage(num3);
                    if (num3 > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound(componentDamage.DamageSoundName, 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                    }
                }
            }
            float num4 = 0f;
            float x    = 0f;

            if (isMeleeAttack && attacker != null)
            {
                float num5 = (attackPower >= 2f) ? 1.25f : 1f;
                float num6 = MathUtils.Pow(attacker.ComponentBody.Mass / target.Mass, 0.5f);
                float x2   = num5 * num6;
                num4 = 5.5f * MathUtils.Saturate(x2);
                x    = 0.25f * MathUtils.Saturate(x2);
            }
            else if (attackPower > 0f)
            {
                num4 = 2f;
                x    = 0.2f;
            }
            if (num4 > 0f)
            {
                target.ApplyImpulse(num4 * Vector3.Normalize(hitDirection + s_random.Vector3(0.1f) + 0.2f * Vector3.UnitY));
                ComponentLocomotion componentLocomotion = target.Entity.FindComponent <ComponentLocomotion>();
                if (componentLocomotion != null)
                {
                    componentLocomotion.StunTime = MathUtils.Max(componentLocomotion.StunTime, x);
                }
            }
        }
Example #10
0
        public void TryAddPoint(int x, int y, int z, int axis, float currentPressure, bool isIncendiary, List <ProcessPoint> toProcess, SparseSpatialArray <bool> processed)
        {
            if (processed.Get(x, y, z))
            {
                return;
            }
            int cellValue = m_subsystemTerrain.Terrain.GetCellValue(x, y, z);
            int num       = Terrain.ExtractContents(cellValue);

            if (num != 0)
            {
                int   num2 = (int)(MathUtils.Hash((uint)(x + 913 * y + 217546 * z)) % 100u);
                float num3 = MathUtils.Lerp(1f, 2f, (float)num2 / 100f);
                if (num2 % 8 == 0)
                {
                    num3 *= 3f;
                }
                Block block = BlocksManager.Blocks[num];
                float num4  = m_pressureByPoint.Get(x - 1, y, z) + m_pressureByPoint.Get(x + 1, y, z) + m_pressureByPoint.Get(x, y - 1, z) + m_pressureByPoint.Get(x, y + 1, z) + m_pressureByPoint.Get(x, y, z - 1) + m_pressureByPoint.Get(x, y, z + 1);
                float num5  = MathUtils.Max(block.ExplosionResilience * num3, 1f);
                float num6  = num4 / num5;
                if (num6 > 1f)
                {
                    int newValue = Terrain.MakeBlockValue(0);
                    m_subsystemTerrain.DestroyCell(0, x, y, z, newValue, noDrop: true, noParticleSystem: true);
                    bool  flag        = false;
                    float probability = (num6 > 5f) ? 0.95f : 0.75f;
                    if (m_random.Bool(probability))
                    {
                        flag = TryExplodeBlock(x, y, z, cellValue);
                    }
                    if (!flag)
                    {
                        CalculateImpulseAndDamage(new Vector3((float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f), 60f, 2f * num4, out Vector3 impulse, out float _);
                        bool flag2 = false;
                        List <BlockDropValue> list = new List <BlockDropValue>();
                        block.GetDropValues(m_subsystemTerrain, cellValue, newValue, 0, list, out bool _);
                        if (list.Count == 0)
                        {
                            list.Add(new BlockDropValue
                            {
                                Value = cellValue,
                                Count = 1
                            });
                            flag2 = true;
                        }
                        foreach (BlockDropValue item in list)
                        {
                            int num7 = Terrain.ExtractContents(item.Value);
                            if (!(BlocksManager.Blocks[num7] is FluidBlock))
                            {
                                float num8 = (m_projectilesCount < 40) ? 1f : ((m_projectilesCount < 60) ? 0.5f : ((m_projectilesCount >= 80) ? 0.125f : 0.25f));
                                if (m_random.Float(0f, 1f) < num8)
                                {
                                    Vector3 velocity = impulse + m_random.Vector3(0.05f * impulse.Length());
                                    if (m_projectilesCount >= 1)
                                    {
                                        velocity *= m_random.Float(0.5f, 1f);
                                        velocity += m_random.Vector3(0.2f * velocity.Length());
                                    }
                                    float      num9       = flag2 ? 0f : MathUtils.Lerp(1f, 0f, (float)m_projectilesCount / 20f);
                                    Projectile projectile = m_subsystemProjectiles.AddProjectile(item.Value, new Vector3((float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f), velocity, m_random.Vector3(0f, 20f), null);
                                    projectile.ProjectileStoppedAction = ((!(m_random.Float(0f, 1f) < num9)) ? ProjectileStoppedAction.Disappear : ProjectileStoppedAction.TurnIntoPickable);
                                    if (m_random.Float(0f, 1f) < 0.5f && m_projectilesCount < 35)
                                    {
                                        float num10 = (num4 > 60f) ? m_random.Float(3f, 7f) : m_random.Float(1f, 3f);
                                        if (isIncendiary)
                                        {
                                            num10 += 10f;
                                        }
                                        m_subsystemProjectiles.AddTrail(projectile, Vector3.Zero, new SmokeTrailParticleSystem(15, m_random.Float(0.75f, 1.5f), num10, isIncendiary ? new Color(255, 140, 192) : Color.White));
                                        projectile.IsIncendiary = isIncendiary;
                                    }
                                    m_generatedProjectiles.Add(projectile, value: true);
                                    m_projectilesCount++;
                                }
                            }
                        }
                    }
                }
                else
                {
                    m_surroundingPressureByPoint.Set(x, y, z, new SurroundingPressurePoint
                    {
                        Pressure     = num4,
                        IsIncendiary = isIncendiary
                    });
                    if (block.IsCollidable)
                    {
                        return;
                    }
                }
            }
            toProcess.Add(new ProcessPoint
            {
                X    = x,
                Y    = y,
                Z    = z,
                Axis = axis
            });
            processed.Set(x, y, z, value: true);
        }
        public void Update(float dt)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;

            foreach (Projectile projectile in m_projectiles)
            {
                if (projectile.ToRemove)
                {
                    m_projectilesToRemove.Add(projectile);
                }
                else
                {
                    Block block = BlocksManager.Blocks[Terrain.ExtractContents(projectile.Value)];
                    if (totalElapsedGameTime - projectile.CreationTime > 40.0)
                    {
                        projectile.ToRemove = true;
                    }
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Z));
                    if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4)
                    {
                        projectile.NoChunk = true;
                        if (projectile.TrailParticleSystem != null)
                        {
                            projectile.TrailParticleSystem.IsStopped = true;
                        }
                    }
                    else
                    {
                        projectile.NoChunk = false;
                        Vector3              position             = projectile.Position;
                        Vector3              vector               = position + projectile.Velocity * dt;
                        Vector3              v                    = block.ProjectileTipOffset * Vector3.Normalize(projectile.Velocity);
                        BodyRaycastResult?   bodyRaycastResult    = m_subsystemBodies.Raycast(position + v, vector + v, 0.2f, (ComponentBody body, float distance) => true);
                        TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position + v, vector + v, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                        bool flag = block.DisintegratesOnHit;
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            CellFace?                cellFace       = terrainRaycastResult.HasValue ? new CellFace?(terrainRaycastResult.Value.CellFace) : null;
                            ComponentBody            componentBody  = bodyRaycastResult.HasValue ? bodyRaycastResult.Value.ComponentBody : null;
                            SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(projectile.Value));
                            for (int i = 0; i < blockBehaviors.Length; i++)
                            {
                                flag |= blockBehaviors[i].OnHitAsProjectile(cellFace, componentBody, projectile);
                            }
                            projectile.ToRemove |= flag;
                        }
                        Vector3?vector2 = null;
                        if (bodyRaycastResult.HasValue && (!terrainRaycastResult.HasValue || bodyRaycastResult.Value.Distance < terrainRaycastResult.Value.Distance))
                        {
                            if (projectile.Velocity.Length() > 10f)
                            {
                                ComponentMiner.AttackBody(bodyRaycastResult.Value.ComponentBody, projectile.Owner, bodyRaycastResult.Value.HitPoint(), Vector3.Normalize(projectile.Velocity), block.GetProjectilePower(projectile.Value), isMeleeAttack: false);
                                if (projectile.Owner != null && projectile.Owner.PlayerStats != null)
                                {
                                    projectile.Owner.PlayerStats.RangedHits++;
                                }
                            }
                            if (projectile.IsIncendiary)
                            {
                                bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(projectile?.Owner, m_random.Float(6f, 8f));
                            }
                            vector = position;
                            projectile.Velocity        *= -0.05f;
                            projectile.Velocity        += m_random.Vector3(0.33f * projectile.Velocity.Length());
                            projectile.AngularVelocity *= -0.05f;
                        }
                        else if (terrainRaycastResult.HasValue)
                        {
                            CellFace cellFace2 = terrainRaycastResult.Value.CellFace;
                            int      cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                            int      num       = Terrain.ExtractContents(cellValue);
                            Block    block2    = BlocksManager.Blocks[num];
                            float    num2      = projectile.Velocity.Length();
                            SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                            for (int j = 0; j < blockBehaviors2.Length; j++)
                            {
                                blockBehaviors2[j].OnHitByProjectile(cellFace2, projectile);
                            }
                            if (num2 > 10f && m_random.Float(0f, 1f) > block2.ProjectileResilience)
                            {
                                m_subsystemTerrain.DestroyCell(0, cellFace2.X, cellFace2.Y, cellFace2.Z, 0, noDrop: true, noParticleSystem: false);
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (projectile.IsIncendiary)
                            {
                                m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, 1f);
                                Vector3 vector3 = projectile.Position - 0.75f * Vector3.Normalize(projectile.Velocity);
                                for (int k = 0; k < 8; k++)
                                {
                                    Vector3 v2 = (k == 0) ? Vector3.Normalize(projectile.Velocity) : m_random.Vector3(1.5f);
                                    TerrainRaycastResult?terrainRaycastResult2 = m_subsystemTerrain.Raycast(vector3, vector3 + v2, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => true);
                                    if (terrainRaycastResult2.HasValue)
                                    {
                                        m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult2.Value.CellFace.X, terrainRaycastResult2.Value.CellFace.Y, terrainRaycastResult2.Value.CellFace.Z, 1f);
                                    }
                                }
                            }
                            if (num2 > 5f)
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (block.IsStickable && num2 > 10f && m_random.Bool(block2.ProjectileStickProbability))
                            {
                                Vector3 v3 = Vector3.Normalize(projectile.Velocity);
                                float   s  = MathUtils.Lerp(0.1f, 0.2f, MathUtils.Saturate((num2 - 15f) / 20f));
                                vector2 = position + terrainRaycastResult.Value.Distance * Vector3.Normalize(projectile.Velocity) + v3 * s;
                            }
                            else
                            {
                                Plane plane = cellFace2.CalculatePlane();
                                vector = position;
                                if (plane.Normal.X != 0f)
                                {
                                    projectile.Velocity *= new Vector3(-0.3f, 0.3f, 0.3f);
                                }
                                if (plane.Normal.Y != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, -0.3f, 0.3f);
                                }
                                if (plane.Normal.Z != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, 0.3f, -0.3f);
                                }
                                float num3 = projectile.Velocity.Length();
                                projectile.Velocity         = num3 * Vector3.Normalize(projectile.Velocity + m_random.Vector3(num3 / 6f, num3 / 3f));
                                projectile.AngularVelocity *= -0.3f;
                            }
                            MakeProjectileNoise(projectile);
                        }
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            if (flag)
                            {
                                m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, projectile.Position, projectile.Value, 1f));
                            }
                            else if (!projectile.ToRemove && (vector2.HasValue || projectile.Velocity.Length() < 1f))
                            {
                                if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.TurnIntoPickable)
                                {
                                    int num4 = BlocksManager.DamageItem(projectile.Value, 1);
                                    if (num4 != 0)
                                    {
                                        if (vector2.HasValue)
                                        {
                                            CalculateVelocityAlignMatrix(block, vector2.Value, projectile.Velocity, out Matrix matrix);
                                            m_subsystemPickables.AddPickable(num4, 1, projectile.Position, Vector3.Zero, matrix);
                                        }
                                        else
                                        {
                                            m_subsystemPickables.AddPickable(num4, 1, position, Vector3.Zero, null);
                                        }
                                    }
                                    projectile.ToRemove = true;
                                }
                                else if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.Disappear)
                                {
                                    projectile.ToRemove = true;
                                }
                            }
                        }
                        float num5 = projectile.IsInWater ? MathUtils.Pow(0.001f, dt) : MathUtils.Pow(block.ProjectileDamping, dt);
                        projectile.Velocity.Y      += -10f * dt;
                        projectile.Velocity        *= num5;
                        projectile.AngularVelocity *= num5;
                        projectile.Position         = vector;
                        projectile.Rotation        += projectile.AngularVelocity * dt;
                        if (projectile.TrailParticleSystem != null)
                        {
                            if (!m_subsystemParticles.ContainsParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem))
                            {
                                m_subsystemParticles.AddParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem);
                            }
                            Vector3 v4 = (projectile.TrailOffset != Vector3.Zero) ? Vector3.TransformNormal(projectile.TrailOffset, Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length())) : Vector3.Zero;
                            projectile.TrailParticleSystem.Position = projectile.Position + v4;
                            if (projectile.IsInWater)
                            {
                                projectile.TrailParticleSystem.IsStopped = true;
                            }
                        }
                        bool flag2 = IsWater(projectile.Position);
                        if (projectile.IsInWater != flag2)
                        {
                            if (flag2)
                            {
                                float num6 = new Vector2(projectile.Velocity.X + projectile.Velocity.Z).Length();
                                if (num6 > 6f && num6 > 4f * MathUtils.Abs(projectile.Velocity.Y))
                                {
                                    projectile.Velocity   *= 0.5f;
                                    projectile.Velocity.Y *= -1f;
                                    flag2 = false;
                                }
                                else
                                {
                                    projectile.Velocity *= 0.2f;
                                }
                                float?surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z));
                                if (surfaceHeight.HasValue)
                                {
                                    m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, new Vector3(projectile.Position.X, surfaceHeight.Value, projectile.Position.Z), large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 6f, autoDelay: true);
                                    MakeProjectileNoise(projectile);
                                }
                            }
                            projectile.IsInWater = flag2;
                        }
                        if (IsMagma(projectile.Position))
                        {
                            m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, projectile.Position, large: false));
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                        if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(projectile.GetHashCode() % 100) / 100.0) && (m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f), Terrain.ToCell(projectile.Position.Z)) || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f) - 1, Terrain.ToCell(projectile.Position.Z))))
                        {
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                    }
                }
            }
            foreach (Projectile item in m_projectilesToRemove)
            {
                if (item.TrailParticleSystem != null)
                {
                    item.TrailParticleSystem.IsStopped = true;
                }
                m_projectiles.Remove(item);
                if (this.ProjectileRemoved != null)
                {
                    this.ProjectileRemoved(item);
                }
            }
            m_projectilesToRemove.Clear();
        }
Example #12
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            switch (state)
            {
            case AimState.InProgress:
            {
                componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 3.2f;
                Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(componentMiner.ActiveBlockValue)];
                ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                if (componentFirstPersonModel != null)
                {
                    componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                    componentFirstPersonModel.ItemOffsetOrder = new Vector3(0f, 0.35f, 0.17f);
                    if (block2 is SpearBlock)
                    {
                        componentFirstPersonModel.ItemRotationOrder = new Vector3(-1.5f, 0f, 0f);
                    }
                }
                if (block2 is SpearBlock)
                {
                    componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(0f, -0.25f, 0f);
                    componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(3.14159f, 0f, 0f);
                }
                break;
            }

            case AimState.Completed:
            {
                Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.4f;
                Vector3 v      = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                if (componentMiner.Inventory == null)
                {
                    break;
                }
                int   activeSlotIndex = componentMiner.Inventory.ActiveSlotIndex;
                int   slotValue       = componentMiner.Inventory.GetSlotValue(activeSlotIndex);
                int   slotCount       = componentMiner.Inventory.GetSlotCount(activeSlotIndex);
                int   num             = Terrain.ExtractContents(slotValue);
                Block block           = BlocksManager.Blocks[num];
                if (slotCount > 0)
                {
                    float num2 = block.ProjectileSpeed;
                    if (componentMiner.ComponentPlayer != null)
                    {
                        num2 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f;
                    }
                    if (m_subsystemProjectiles.FireProjectile(slotValue, vector, v * num2, m_random.Vector3(5f, 10f), componentMiner.ComponentCreature) != null)
                    {
                        componentMiner.Inventory.RemoveSlotItems(activeSlotIndex, 1);
                        m_subsystemAudio.PlaySound("Audio/Throw", m_random.Float(0.2f, 0.3f), m_random.Float(-0.2f, 0.2f), aim.Position, 2f, autoDelay: true);
                        componentMiner.Poke(forceRestart: false);
                    }
                }
                break;
            }
            }
            return(false);
        }
Example #13
0
        public FireworksParticleSystem(Vector3 position, Color color, FireworksBlock.Shape shape, float flickering, float particleSize)
            : base(300)
        {
            base.Texture           = ContentManager.Get <Texture2D>("Textures/FireworksParticle");
            m_color                = color;
            m_flickering           = flickering;
            base.TextureSlotsCount = 2;
            if (shape == FireworksBlock.Shape.SmallBurst || shape == FireworksBlock.Shape.LargeBurst)
            {
                int num = (shape == FireworksBlock.Shape.SmallBurst) ? 100 : 200;
                while (m_nextParticle < num)
                {
                    Particle particle = base.Particles[m_nextParticle++];
                    particle.IsActive      = true;
                    particle.Position      = position;
                    particle.Size          = new Vector2(0.2f * particleSize);
                    particle.TimeToLive    = ((shape == FireworksBlock.Shape.SmallBurst) ? m_random.Float(0.5f, 2f) : m_random.Float(1f, 3f));
                    particle.Velocity      = m_random.Vector3(0.5f, 1f);
                    particle.Velocity     *= (float)((shape == FireworksBlock.Shape.SmallBurst) ? 16 : 26) * particle.Velocity.LengthSquared();
                    particle.TextureSlot   = m_random.Int(0, 3);
                    particle.FadeRate      = m_random.Float(1f, 3f);
                    particle.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                    particle.RotationSpeed = 0f;
                }
            }
            switch (shape)
            {
            case FireworksBlock.Shape.Circle:
            {
                float num4 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num5 = 150;
                for (int j = 0; j < num5; j++)
                {
                    float    x2   = (float)Math.PI * 2f * (float)j / (float)num5 + num4;
                    Vector3  v2   = new Vector3(MathUtils.Sin(x2) + 0.1f * m_random.Float(-1f, 1f), 0f, MathUtils.Cos(x2) + 0.1f * m_random.Float(-1f, 1f));
                    Particle obj2 = base.Particles[m_nextParticle++];
                    obj2.IsActive      = true;
                    obj2.Position      = position;
                    obj2.Size          = new Vector2(0.2f * particleSize);
                    obj2.TimeToLive    = m_random.Float(1f, 3f);
                    obj2.Velocity      = 20f * v2;
                    obj2.TextureSlot   = m_random.Int(0, 3);
                    obj2.FadeRate      = m_random.Float(1f, 3f);
                    obj2.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                    obj2.RotationSpeed = 0f;
                }
                break;
            }

            case FireworksBlock.Shape.Disc:
            {
                float num10 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num11 = 13;
                for (int m = 0; m <= num11; m++)
                {
                    float num12 = (float)m / (float)num11;
                    int   num13 = (int)MathUtils.Round(num12 * 2f * (float)num11);
                    for (int n = 0; n < num13; n++)
                    {
                        float    x5   = (float)Math.PI * 2f * (float)n / (float)num13 + num10;
                        Vector3  v4   = new Vector3(num12 * MathUtils.Sin(x5) + 0.1f * m_random.Float(-1f, 1f), 0f, num12 * MathUtils.Cos(x5) + 0.1f * m_random.Float(-1f, 1f));
                        Particle obj4 = base.Particles[m_nextParticle++];
                        obj4.IsActive      = true;
                        obj4.Position      = position;
                        obj4.Size          = new Vector2(0.2f * particleSize);
                        obj4.TimeToLive    = m_random.Float(1f, 3f);
                        obj4.Velocity      = 22f * v4;
                        obj4.TextureSlot   = m_random.Int(0, 3);
                        obj4.FadeRate      = m_random.Float(1f, 3f);
                        obj4.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                        obj4.RotationSpeed = 0f;
                    }
                }
                break;
            }

            case FireworksBlock.Shape.Ball:
            {
                float   num14 = m_random.Float(0f, (float)Math.PI * 2f);
                int     num15 = 12;
                Vector3 v5    = default(Vector3);
                for (int num16 = 0; num16 <= num15; num16++)
                {
                    float x6 = (float)Math.PI * (float)num16 / (float)num15;
                    v5.Y = MathUtils.Cos(x6);
                    float num17 = MathUtils.Sin(x6);
                    int   num18 = (int)MathUtils.Round(num17 * 2f * (float)num15);
                    for (int num19 = 0; num19 < num18; num19++)
                    {
                        float x7 = (float)Math.PI * 2f * (float)num19 / (float)num18 + num14;
                        v5.X = num17 * MathUtils.Sin(x7);
                        v5.Z = num17 * MathUtils.Cos(x7);
                        Particle obj5 = base.Particles[m_nextParticle++];
                        obj5.IsActive      = true;
                        obj5.Position      = position;
                        obj5.Size          = new Vector2(0.2f * particleSize);
                        obj5.TimeToLive    = m_random.Float(1f, 3f);
                        obj5.Velocity      = 20f * v5;
                        obj5.TextureSlot   = m_random.Int(0, 3);
                        obj5.FadeRate      = m_random.Float(1f, 3f);
                        obj5.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                        obj5.RotationSpeed = 0f;
                    }
                }
                break;
            }

            case FireworksBlock.Shape.ShortTrails:
            case FireworksBlock.Shape.LongTrails:
            {
                float   num6 = m_random.Float(0f, (float)Math.PI * 2f);
                int     num7 = 3;
                Vector3 v3   = default(Vector3);
                for (int k = 0; k <= num7; k++)
                {
                    float x3   = (float)Math.PI * (float)k / (float)num7;
                    float num8 = MathUtils.Sin(x3);
                    int   num9 = (int)MathUtils.Round(num8 * (float)((shape == FireworksBlock.Shape.ShortTrails) ? 3 : 2) * (float)num7);
                    for (int l = 0; l < num9; l++)
                    {
                        float x4 = (float)Math.PI * 2f * (float)l / (float)num9 + num6;
                        v3.X = num8 * MathUtils.Sin(x4) + 0.3f * m_random.Float(-1f, 1f);
                        v3.Y = MathUtils.Cos(x3) + 0.3f * m_random.Float(-1f, 1f);
                        v3.Z = num8 * MathUtils.Cos(x4) + 0.3f * m_random.Float(-1f, 1f);
                        Particle obj3 = base.Particles[m_nextParticle++];
                        obj3.IsActive            = true;
                        obj3.Position            = position;
                        obj3.Size                = new Vector2(0.25f);
                        obj3.TimeToLive          = m_random.Float(0.5f, 2.5f);
                        obj3.Velocity            = ((shape == FireworksBlock.Shape.ShortTrails) ? (25f * v3) : (35f * v3));
                        obj3.TextureSlot         = m_random.Int(0, 3);
                        obj3.FadeRate            = m_random.Float(1f, 3f);
                        obj3.BaseColor           = m_color * m_random.Float(0.5f, 1f);
                        obj3.GenerationFrequency = ((shape == FireworksBlock.Shape.ShortTrails) ? 1.9f : 2.1f);
                        obj3.RotationSpeed       = m_random.Float(-40f, 40f);
                    }
                }
                break;
            }

            case FireworksBlock.Shape.FlatTrails:
            {
                float num2 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num3 = 13;
                for (int i = 0; i < num3; i++)
                {
                    float    x   = (float)Math.PI * 2f * (float)i / (float)num3 + num2;
                    Vector3  v   = new Vector3(MathUtils.Sin(x) + 0.1f * m_random.Float(-1f, 1f), 0f, MathUtils.Cos(x) + 0.1f * m_random.Float(-1f, 1f));
                    Particle obj = base.Particles[m_nextParticle++];
                    obj.IsActive            = true;
                    obj.Position            = position;
                    obj.Size                = new Vector2(0.25f);
                    obj.TimeToLive          = m_random.Float(0.5f, 2.5f);
                    obj.Velocity            = 25f * v;
                    obj.TextureSlot         = m_random.Int(0, 3);
                    obj.FadeRate            = m_random.Float(1f, 3f);
                    obj.BaseColor           = m_color * m_random.Float(0.5f, 1f);
                    obj.GenerationFrequency = 2.5f;
                    obj.RotationSpeed       = m_random.Float(-40f, 40f);
                }
                break;
            }
            }
        }