Ejemplo n.º 1
0
 public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
 {
     if (m_random.Bool(0.15f))
     {
         dropValues.Add(new BlockDropValue
         {
             Value = 23,
             Count = 1
         });
         showDebris = true;
     }
     else
     {
         base.GetDropValues(subsystemTerrain, oldValue, newValue, toolLevel, dropValues, out showDebris);
     }
 }
Ejemplo n.º 2
0
        public float ApplyArmorProtection(float attackPower)
        {
            float        num  = m_random.UniformFloat(0f, 1f);
            ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head));
            float        num2 = ((MekClothingBlock)BlocksManager.Blocks[1011]).Durability + 1;
            List <int>   list = new List <int>(GetClothes(slot));

            for (int i = 0; i < list.Count; i++)
            {
                int          value        = list[i];
                MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(value));
                float        x            = (num2 - (float)BlocksManager.Blocks[1011].GetDamage(value)) / num2 * clothingData.Sturdiness;
                float        num3         = MathUtils.Min(attackPower * MathUtils.Saturate(clothingData.ArmorProtection), x);
                if (num3 > 0f)
                {
                    attackPower -= num3;
                    if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                    {
                        float x2          = num3 / clothingData.Sturdiness * num2 + 0.001f;
                        int   damageCount = (int)(MathUtils.Floor(x2) + (float)(m_random.Bool(MathUtils.Remainder(x2, 1f)) ? 1 : 0));
                        list[i] = BlocksManager.DamageItem(value, damageCount);
                    }
                    if (!string.IsNullOrEmpty(clothingData.ImpactSoundsFolder))
                    {
                        m_subsystemAudio.PlayRandomSound(clothingData.ImpactSoundsFolder, 1f, m_random.UniformFloat(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f);
                    }
                }
            }
            int num4 = 0;

            while (num4 < list.Count)
            {
                if (Terrain.ExtractContents(list[num4]) != 1011)
                {
                    list.RemoveAt(num4);
                    m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                }
                else
                {
                    num4++;
                }
            }
            SetClothes(slot, list);
            return(MathUtils.Max(attackPower, 0f));
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
        public static TerrainBrush CreateMimosaBrush(Random random, float size)
        {
            TerrainBrush terrainBrush = new TerrainBrush();
            int          value        = m_treeTrunksByType[4];
            int          value2       = m_treeLeavesByType[4];

            terrainBrush.AddRay(0, -1, 0, 0, 0, 0, 1, 1, 1, value);
            List <Point3> list = new List <Point3>();
            float         num  = random.Float(0f, (float)Math.PI * 2f);

            for (int i = 0; i < 3; i++)
            {
                float   radians = num + (float)i * MathUtils.DegToRad(120f);
                Vector3 v       = Vector3.Transform(Vector3.Normalize(new Vector3(1f, random.Float(1f, 1.5f), 0f)), Matrix.CreateRotationY(radians));
                int     num2    = random.Int((int)(0.7f * size), (int)size);
                Point3  p       = new Point3(0, 0, 0);
                Point3  item    = new Point3(Vector3.Round(new Vector3(p) + v * num2));
                terrainBrush.AddRay(p.X, p.Y, p.Z, item.X, item.Y, item.Z, 1, 1, 1, value);
                list.Add(item);
            }
            foreach (Point3 item2 in list)
            {
                float num3 = random.Float(0.3f * size, 0.45f * size);
                int   num4 = (int)MathUtils.Ceiling(num3);
                for (int j = item2.X - num4; j <= item2.X + num4; j++)
                {
                    for (int k = item2.Y - num4; k <= item2.Y + num4; k++)
                    {
                        for (int l = item2.Z - num4; l <= item2.Z + num4; l++)
                        {
                            int   num5 = MathUtils.Abs(j - item2.X) + MathUtils.Abs(k - item2.Y) + MathUtils.Abs(l - item2.Z);
                            float num6 = ((new Vector3(j, k, l) - new Vector3(item2)) * new Vector3(1f, 1.7f, 1f)).Length();
                            if (num6 <= num3 && (num3 - num6 > 1f || num5 <= 2 || random.Bool(0.7f)) && !terrainBrush.GetValue(j, k, l).HasValue)
                            {
                                terrainBrush.AddCell(j, k, l, value2);
                            }
                        }
                    }
                }
            }
            terrainBrush.Compile();
            return(terrainBrush);
        }
Ejemplo n.º 5
0
        public static TreeType?GenerateRandomTreeType(Random random, int temperature, int humidity, int y, float densityMultiplier = 1f)
        {
            TreeType?result = null;
            float    num    = random.Float() * CalculateTreeProbability(TreeType.Oak, temperature, humidity, y);
            float    num2   = random.Float() * CalculateTreeProbability(TreeType.Birch, temperature, humidity, y);
            float    num3   = random.Float() * CalculateTreeProbability(TreeType.Spruce, temperature, humidity, y);
            float    num4   = random.Float() * CalculateTreeProbability(TreeType.TallSpruce, temperature, humidity, y);
            float    num5   = random.Float() * CalculateTreeProbability(TreeType.Mimosa, temperature, humidity, y);
            float    num6   = MathUtils.Max(MathUtils.Max(num, num2, num3, num4), num5);

            if (num6 > 0f)
            {
                if (num6 == num)
                {
                    result = TreeType.Oak;
                }
                if (num6 == num2)
                {
                    result = TreeType.Birch;
                }
                if (num6 == num3)
                {
                    result = TreeType.Spruce;
                }
                if (num6 == num4)
                {
                    result = TreeType.TallSpruce;
                }
                if (num6 == num5)
                {
                    result = TreeType.Mimosa;
                }
            }
            if (result.HasValue && random.Bool(densityMultiplier * CalculateTreeDensity(result.Value, temperature, humidity, y)))
            {
                return(result);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            int data = Terrain.ExtractData(oldValue);

            if (GetSize(data) == 2)
            {
                BlockDropValue item = new BlockDropValue
                {
                    Value = Terrain.MakeBlockValue(173, 0, 6),
                    Count = Random.Int(1, 2)
                };
                dropValues.Add(item);
                if (!GetIsWild(data))
                {
                    int num = Random.Int(1, 2);
                    for (int i = 0; i < num; i++)
                    {
                        item = new BlockDropValue
                        {
                            Value = Terrain.MakeBlockValue(205, 0, 0),
                            Count = 1
                        };
                        dropValues.Add(item);
                    }
                    if (Random.Bool(0.5f))
                    {
                        item = new BlockDropValue
                        {
                            Value = Terrain.MakeBlockValue(248),
                            Count = 1
                        };
                        dropValues.Add(item);
                    }
                }
            }
            showDebris = true;
        }
Ejemplo n.º 7
0
 public void Update(float dt)
 {
     m_fireSound.Volume = MathUtils.Lerp(m_fireSound.Volume, SettingsManager.SoundsVolume * FireSoundVolume, MathUtils.Saturate(3f * Time.FrameDuration));
     if (m_fireSound.Volume > 0.5f * AudioManager.MinAudibleVolume)
     {
         m_fireSound.Play();
     }
     else
     {
         m_fireSound.Pause();
     }
     m_waterSound.Volume = MathUtils.Lerp(m_waterSound.Volume, SettingsManager.SoundsVolume * WaterSoundVolume, MathUtils.Saturate(3f * Time.FrameDuration));
     if (m_waterSound.Volume > 0.5f * AudioManager.MinAudibleVolume)
     {
         m_waterSound.Play();
     }
     else
     {
         m_waterSound.Pause();
     }
     m_magmaSound.Volume = MathUtils.Lerp(m_magmaSound.Volume, SettingsManager.SoundsVolume * MagmaSoundVolume, MathUtils.Saturate(3f * Time.FrameDuration));
     if (m_magmaSound.Volume > 0.5f * AudioManager.MinAudibleVolume)
     {
         m_magmaSound.Play();
     }
     else
     {
         m_magmaSound.Pause();
     }
     if (m_magmaSound.State == SoundState.Playing && m_random.Bool(0.2f * dt))
     {
         SubsystemAudio.PlayRandomSound("Audio/Sizzles", m_magmaSound.Volume, m_random.Float(-0.2f, 0.2f), 0f, 0f);
     }
     FireSoundVolume  = 0f;
     WaterSoundVolume = 0f;
     MagmaSoundVolume = 0f;
 }
Ejemplo n.º 8
0
        public void Update(float dt)
        {
            if (m_subsystemGameInfo.TotalElapsedGameTime > m_precipitationEndTime)
            {
                if (m_precipitationEndTime == 0.0)
                {
                    if (m_subsystemGameInfo.WorldSettings.StartingPositionMode == StartingPositionMode.Hard)
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(2f, 3f));
                        m_lightningIntensity     = m_random.Float(0.5f, 1f);
                    }
                    else
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(3f, 6f));
                        m_lightningIntensity     = m_random.Float(0.33f, 0.66f);
                    }
                }
                else
                {
                    m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(5f, 45f));
                    m_lightningIntensity     = ((m_random.Float(0f, 1f) < 0.5f) ? m_random.Float(0.33f, 1f) : 0f);
                }
                m_precipitationEndTime = m_precipitationStartTime + (double)(60f * m_random.Float(3f, 6f));
            }
            float num = (float)MathUtils.Max(0.0, MathUtils.Min(m_subsystemGameInfo.TotalElapsedGameTime - m_precipitationStartTime, m_precipitationEndTime - m_subsystemGameInfo.TotalElapsedGameTime));

            GlobalPrecipitationIntensity = (m_subsystemGameInfo.WorldSettings.AreWeatherEffectsEnabled ? MathUtils.Saturate(num * 0.04f) : 0f);
            if (GlobalPrecipitationIntensity == 1f && SubsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                TerrainChunk[] allocatedChunks = SubsystemTerrain.Terrain.AllocatedChunks;
                for (int i = 0; i < allocatedChunks.Length; i++)
                {
                    TerrainChunk terrainChunk = allocatedChunks[m_random.Int(0, allocatedChunks.Length - 1)];
                    if (terrainChunk.State < TerrainChunkState.InvalidVertices1 || !m_random.Bool(m_lightningIntensity * 0.0002f))
                    {
                        continue;
                    }
                    int     num2   = terrainChunk.Origin.X + m_random.Int(0, 15);
                    int     num3   = terrainChunk.Origin.Y + m_random.Int(0, 15);
                    Vector3?vector = null;
                    for (int j = num2 - 8; j < num2 + 8; j++)
                    {
                        for (int k = num3 - 8; k < num3 + 8; k++)
                        {
                            int topHeight = SubsystemTerrain.Terrain.GetTopHeight(j, k);
                            if (!vector.HasValue || (float)topHeight > vector.Value.Y)
                            {
                                vector = new Vector3(j, topHeight, k);
                            }
                        }
                    }
                    if (vector.HasValue)
                    {
                        SubsystemSky.MakeLightningStrike(vector.Value);
                        return;
                    }
                }
            }
            if (Time.PeriodicEvent(0.5, 0.0))
            {
                float num4 = 0f;
                if (GlobalPrecipitationIntensity > 0f)
                {
                    float num5 = 0f;
                    foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions)
                    {
                        int     num6    = Terrain.ToCell(listenerPosition.X) - 5;
                        int     num7    = Terrain.ToCell(listenerPosition.Z) - 5;
                        int     num8    = Terrain.ToCell(listenerPosition.X) + 5;
                        int     num9    = Terrain.ToCell(listenerPosition.Z) + 5;
                        Vector3 vector2 = default(Vector3);
                        for (int l = num6; l <= num8; l++)
                        {
                            for (int m = num7; m <= num9; m++)
                            {
                                PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(l, m);
                                if (precipitationShaftInfo.Type == PrecipitationType.Rain && precipitationShaftInfo.Intensity > 0f)
                                {
                                    vector2.X = (float)l + 0.5f;
                                    vector2.Y = MathUtils.Max(precipitationShaftInfo.YLimit, listenerPosition.Y);
                                    vector2.Z = (float)m + 0.5f;
                                    float num10    = vector2.X - listenerPosition.X;
                                    float num11    = 8f * (vector2.Y - listenerPosition.Y);
                                    float num12    = vector2.Z - listenerPosition.Z;
                                    float distance = MathUtils.Sqrt(num10 * num10 + num11 * num11 + num12 * num12);
                                    num5 += m_subsystemAudio.CalculateVolume(distance, 1.5f) * precipitationShaftInfo.Intensity;
                                }
                            }
                        }
                    }
                    num4 = MathUtils.Max(num4, num5);
                }
                m_targetRainSoundVolume = MathUtils.Saturate(1.5f * num4 / m_rainVolumeFactor);
            }
            m_rainSound.Volume = MathUtils.Saturate(MathUtils.Lerp(m_rainSound.Volume, SettingsManager.SoundsVolume * m_targetRainSoundVolume, 5f * dt));
            if (m_rainSound.Volume > AudioManager.MinAudibleVolume)
            {
                m_rainSound.Play();
            }
            else
            {
                m_rainSound.Pause();
            }
        }
Ejemplo n.º 9
0
 public void Update(float dt)
 {
     if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || !m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled)
     {
         m_fluDuration = 0f;
         m_fluOnset    = 0f;
         return;
     }
     if (m_fluDuration > 0f)
     {
         m_fluOnset = 0f;
         float num = 1f;
         if (m_componentPlayer.ComponentVitalStats.Temperature > 16f)
         {
             num = 2f;
         }
         else if (m_componentPlayer.ComponentVitalStats.Temperature > 12f)
         {
             num = 1.5f;
         }
         else if (m_componentPlayer.ComponentVitalStats.Temperature < 8f)
         {
             num = 0.5f;
         }
         m_fluDuration = MathUtils.Max(m_fluDuration - num * dt, 0f);
         if (m_componentPlayer.ComponentHealth.Health > 0f && !m_componentPlayer.ComponentSleep.IsSleeping && m_subsystemTime.PeriodicGameTimeEvent(5.0, -0.0099999997764825821) && m_subsystemTime.GameTime - m_lastEffectTime > 13.0)
         {
             FluEffect();
         }
     }
     else if (m_componentPlayer.ComponentVitalStats.Temperature < 6f)
     {
         float num2 = 13f;
         m_fluOnset += dt;
         if (m_fluOnset > 120f)
         {
             num2 = 9f;
             if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0) && m_random.Bool(0.025f))
             {
                 StartFlu();
             }
             if (m_subsystemTime.GameTime - m_lastMessageTime > 60.0)
             {
                 m_lastMessageTime = m_subsystemTime.GameTime;
                 m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
             }
         }
         if (m_fluOnset > 60f && m_subsystemTime.PeriodicGameTimeEvent(num2, -0.0099999997764825821) && m_random.Bool(0.75f))
         {
             Sneeze();
         }
     }
     else
     {
         m_fluOnset = 0f;
     }
     if ((m_coughDuration > 0f || m_sneezeDuration > 0f) && m_componentPlayer.ComponentHealth.Health > 0f && !m_componentPlayer.ComponentSleep.IsSleeping)
     {
         m_coughDuration  = MathUtils.Max(m_coughDuration - dt, 0f);
         m_sneezeDuration = MathUtils.Max(m_sneezeDuration - dt, 0f);
         float num3 = MathUtils.DegToRad(MathUtils.Lerp(-35f, -65f, SimplexNoise.Noise(4f * (float)MathUtils.Remainder(m_subsystemTime.GameTime, 10000.0))));
         m_componentPlayer.ComponentLocomotion.LookOrder = new Vector2(m_componentPlayer.ComponentLocomotion.LookOrder.X, MathUtils.Clamp(num3 - m_componentPlayer.ComponentLocomotion.LookAngles.Y, -3f, 3f));
         if (m_random.Bool(2f * dt))
         {
             m_componentPlayer.ComponentBody.ApplyImpulse(-1.2f * m_componentPlayer.ComponentCreatureModel.EyeRotation.GetForwardVector());
         }
     }
     if (m_blackoutDuration > 0f)
     {
         m_blackoutDuration = MathUtils.Max(m_blackoutDuration - dt, 0f);
         m_blackoutFactor   = MathUtils.Min(m_blackoutFactor + 0.5f * dt, 0.95f);
     }
     else if (m_blackoutFactor > 0f)
     {
         m_blackoutFactor = MathUtils.Max(m_blackoutFactor - 0.5f * dt, 0f);
     }
     m_componentPlayer.ComponentScreenOverlays.BlackoutFactor = MathUtils.Max(m_blackoutFactor, m_componentPlayer.ComponentScreenOverlays.BlackoutFactor);
 }
Ejemplo n.º 10
0
        public void Hit(ComponentBody componentBody, Vector3 hitPoint, Vector3 hitDirection)
        {
            if (Hit1 != null)
            {
                Hit1(componentBody, hitPoint, hitDirection); return;
            }
            if (!(m_subsystemTime.GameTime - m_lastHitTime > 0.6600000262260437))
            {
                return;
            }
            m_lastHitTime = m_subsystemTime.GameTime;
            Block block = BlocksManager.Blocks[Terrain.ExtractContents(ActiveBlockValue)];

            if (!CanUseTool(ActiveBlockValue))
            {
                ComponentPlayer?.ComponentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), block.PlayerLevelRequired, block.GetDisplayName(m_subsystemTerrain, ActiveBlockValue)), Color.White, blinking: true, playNotificationSound: true);
                Poke(forceRestart: false);
                return;
            }
            float num  = 0f;
            float num2 = 1f;

            if (ActiveBlockValue != 0)
            {
                num  = block.GetMeleePower(ActiveBlockValue) * AttackPower * m_random.Float(0.8f, 1.2f);
                num2 = block.GetMeleeHitProbability(ActiveBlockValue);
            }
            else
            {
                num  = AttackPower * m_random.Float(0.8f, 1.2f);
                num2 = 0.66f;
            }
            bool flag;

            if (ComponentPlayer != null)
            {
                m_subsystemAudio.PlaySound("Audio/Swoosh", 1f, m_random.Float(-0.2f, 0.2f), componentBody.Position, 3f, autoDelay: false);
                flag = m_random.Bool(num2);
                num *= ComponentPlayer.ComponentLevel.StrengthFactor;
            }
            else
            {
                flag = true;
            }
            if (flag)
            {
                AttackBody(componentBody, ComponentCreature, hitPoint, hitDirection, num, isMeleeAttack: true);
                DamageActiveTool(1);
            }
            else if (ComponentCreature is ComponentPlayer)
            {
                HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + ComponentCreature.ComponentBody.Velocity, Color.White, LanguageControl.Get(fName, 2));
                base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem);
            }
            if (ComponentCreature.PlayerStats != null)
            {
                ComponentCreature.PlayerStats.MeleeAttacks++;
                if (flag)
                {
                    ComponentCreature.PlayerStats.MeleeHits++;
                }
            }
            Poke(forceRestart: false);
        }
        public override bool Simulate(float dt)
        {
            if (m_subsystemWeather.SubsystemTime.GameTime - m_lastUpdateTime > 1.0 || MathUtils.Abs(m_lastSkylightIntensity - m_subsystemWeather.SubsystemSky.SkyLightIntensity) > 0.1f)
            {
                m_lastUpdateTime        = m_subsystemWeather.SubsystemTime.GameTime;
                m_lastSkylightIntensity = m_subsystemWeather.SubsystemSky.SkyLightIntensity;
                PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(Point.X, Point.Y);
                m_intensity         = precipitationShaftInfo.Intensity;
                m_yLimit            = precipitationShaftInfo.YLimit;
                m_topmostValue      = m_subsystemWeather.SubsystemTerrain.Terrain.GetCellValue(Point.X, precipitationShaftInfo.YLimit - 1, Point.Y);
                m_topmostBelowValue = m_subsystemWeather.SubsystemTerrain.Terrain.GetCellValue(Point.X, precipitationShaftInfo.YLimit - 2, Point.Y);
            }
            Camera activeCamera = m_gameWidget.ActiveCamera;

            if (!m_isEmpty || (m_intensity > 0f && (float)m_yLimit < activeCamera.ViewPosition.Y + 5f))
            {
                Vector2 v   = Vector2.Normalize(new Vector2(activeCamera.ViewDirection.X, activeCamera.ViewDirection.Z));
                Vector2 v2  = Vector2.Normalize(new Vector2((float)Point.X + 0.5f - activeCamera.ViewPosition.X + 0.7f * v.X, (float)Point.Y + 0.5f - activeCamera.ViewPosition.Z + 0.7f * v.Y));
                float   num = Vector2.Dot(v, v2);
                m_isVisible = (num > 0.5f);
                if (m_isVisible)
                {
                    if (m_needsInitialize)
                    {
                        m_needsInitialize = false;
                        Initialize();
                    }
                    float y    = activeCamera.ViewPosition.Y;
                    float num2 = y - 5f;
                    float num3 = y + 5f;
                    float num4 = 0f;
                    float num5 = 0f;
                    if (m_lastViewY.HasValue)
                    {
                        if (y < m_lastViewY.Value)
                        {
                            num4 = num2;
                            num5 = m_lastViewY.Value - 5f;
                        }
                        else
                        {
                            num4 = m_lastViewY.Value + 5f;
                            num5 = num3;
                        }
                    }
                    else
                    {
                        num4 = num2;
                        num5 = num3;
                    }
                    float num6 = (num5 - num4) / 10f * (float)m_particles.Length * m_intensity;
                    int   num7 = (int)num6 + ((m_random.Float(0f, 1f) < num6 - (float)(int)num6) ? 1 : 0);
                    m_lastViewY = y;
                    m_toCreate += (float)m_particles.Length * m_intensity / 10f * m_averageSpeed * dt;
                    m_isEmpty   = true;
                    float num8 = (m_precipitationType == PrecipitationType.Rain) ? 0f : 0.03f;
                    for (int i = 0; i < m_particles.Length; i++)
                    {
                        Particle particle = m_particles[i];
                        if (particle.IsActive)
                        {
                            if (particle.YLimit == 0f && particle.Position.Y <= (float)m_yLimit + num8)
                            {
                                RaycastParticle(particle);
                            }
                            bool flag = particle.YLimit != 0f && particle.Position.Y <= particle.YLimit + num8;
                            if (!flag && particle.Position.Y >= num2 && particle.Position.Y <= num3)
                            {
                                particle.Position.Y -= particle.Speed * dt;
                                m_isEmpty            = false;
                                continue;
                            }
                            particle.IsActive = false;
                            if (particle.GenerateSplash && flag)
                            {
                                if (m_precipitationType == PrecipitationType.Rain && m_random.Bool(0.5f))
                                {
                                    m_subsystemWeather.RainSplashParticleSystem.AddSplash(m_topmostValue, new Vector3(particle.Position.X, particle.YLimit + num8, particle.Position.Z), m_subsystemWeather.RainColor);
                                }
                                if (m_precipitationType == PrecipitationType.Snow)
                                {
                                    m_subsystemWeather.SnowSplashParticleSystem.AddSplash(m_topmostValue, new Vector3(particle.Position.X, particle.YLimit + num8, particle.Position.Z), m_size, m_subsystemWeather.SnowColor, particle.TextureSlot);
                                }
                            }
                        }
                        else if (num7 > 0)
                        {
                            particle.Position.X = (float)Point.X + m_random.Float(0f, 1f);
                            particle.Position.Y = m_random.Float(num4, num5);
                            particle.Position.Z = (float)Point.Y + m_random.Float(0f, 1f);
                            particle.IsActive   = (particle.Position.Y >= (float)m_yLimit);
                            particle.YLimit     = 0f;
                            num7--;
                        }
                        else if (m_toCreate >= 1f)
                        {
                            particle.Position.X = (float)Point.X + m_random.Float(0f, 1f);
                            particle.Position.Y = m_random.Float(num3 - m_averageSpeed * dt, num3);
                            particle.Position.Z = (float)Point.Y + m_random.Float(0f, 1f);
                            particle.IsActive   = (particle.Position.Y >= (float)m_yLimit);
                            particle.YLimit     = 0f;
                            m_toCreate         -= 1f;
                        }
                    }
                    m_toCreate -= MathUtils.Floor(m_toCreate);
                }
                else
                {
                    m_needsInitialize = true;
                }
            }
            return(false);
        }
Ejemplo n.º 12
0
        public bool Eat(int value)
        {
            int   num  = Terrain.ExtractContents(value);
            Block obj  = BlocksManager.Blocks[num];
            float num2 = obj.GetNutritionalValue(value);
            float sicknessProbability = obj.GetSicknessProbability(value);

            if (num2 > 0f)
            {
                if (m_componentPlayer.ComponentSickness.IsSick && sicknessProbability > 0f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                    return(false);
                }
                if (Food >= 0.98f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                    return(false);
                }
                m_subsystemAudio.PlayRandomSound("Audio/Creatures/HumanEat", 1f, m_random.Float(-0.2f, 0.2f), m_componentPlayer.ComponentBody.Position, 2f, 0f);
                if (m_componentPlayer.ComponentSickness.IsSick)
                {
                    num2 *= 0.75f;
                }
                Food += num2;
                m_satiation.TryGetValue(num, out float value2);
                value2          += MathUtils.Max(num2, 0.5f);
                m_satiation[num] = value2;
                if (m_componentPlayer.ComponentSickness.IsSick)
                {
                    m_componentPlayer.ComponentSickness.NauseaEffect();
                }
                else if (sicknessProbability >= 0.5f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (sicknessProbability > 0f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 4), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (value2 > 2.5f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 5), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (value2 > 2f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 6), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (Food > 0.85f)
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 7), Color.White, blinking: true, playNotificationSound: true);
                }
                else
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 8), Color.White, blinking: true, playNotificationSound: false);
                }
                if (m_random.Bool(sicknessProbability) || value2 > 3.5f)
                {
                    m_componentPlayer.ComponentSickness.StartSickness();
                }
                m_componentPlayer.PlayerStats.FoodItemsEaten++;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
        public void MatureSapling(SaplingData saplingData)
        {
            if (!(m_subsystemGameInfo.TotalElapsedGameTime >= saplingData.MatureTime))
            {
                return;
            }
            int          x            = saplingData.Point.X;
            int          y            = saplingData.Point.Y;
            int          z            = saplingData.Point.Z;
            TerrainChunk chunkAtCell  = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z - 6);
            TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z + 6);
            TerrainChunk chunkAtCell3 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z - 6);
            TerrainChunk chunkAtCell4 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z + 6);

            if (chunkAtCell != null && chunkAtCell.State == TerrainChunkState.Valid && chunkAtCell2 != null && chunkAtCell2.State == TerrainChunkState.Valid && chunkAtCell3 != null && chunkAtCell3.State == TerrainChunkState.Valid && chunkAtCell4 != null && chunkAtCell4.State == TerrainChunkState.Valid)
            {
                int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z);
                if (cellContents == 2 || cellContents == 8)
                {
                    if (base.SubsystemTerrain.Terrain.GetCellLight(x, y + 1, z) >= 9)
                    {
                        bool flag = false;
                        for (int i = x - 1; i <= x + 1; i++)
                        {
                            for (int j = z - 1; j <= z + 1; j++)
                            {
                                int cellContents2 = base.SubsystemTerrain.Terrain.GetCellContents(i, y - 1, j);
                                if (BlocksManager.Blocks[cellContents2] is WaterBlock)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        float num = 0f;
                        if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative)
                        {
                            num = 1f;
                        }
                        else
                        {
                            int num2 = base.SubsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
                            int num3 = base.SubsystemTerrain.Terrain.GetHumidity(x, z);
                            if (flag)
                            {
                                num2 = (num2 + 10) / 2;
                                num3 = MathUtils.Max(num3, 12);
                            }
                            num = 2f * PlantsManager.CalculateTreeProbability(saplingData.Type, num2, num3, y);
                        }
                        if (m_random.Bool(num))
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0, 0, 0));
                            if (!GrowTree(x, y, z, saplingData.Type))
                            {
                                base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                            }
                        }
                        else
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                        }
                    }
                    else if (m_subsystemGameInfo.TotalElapsedGameTime > saplingData.MatureTime + 1200.0)
                    {
                        base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                    }
                }
                else
                {
                    base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                }
            }
            else
            {
                saplingData.MatureTime = m_subsystemGameInfo.TotalElapsedGameTime;
            }
        }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            base.GetDropValues(subsystemTerrain, oldValue, newValue, toolLevel, dropValues, out showDebris);
            int data = Terrain.ExtractData(oldValue);

            if (BasePumpkinBlock.GetSize(data) == 7 && !BasePumpkinBlock.GetIsDead(data) && Random.Bool(0.5f))
            {
                dropValues.Add(new BlockDropValue
                {
                    Value = 248,
                    Count = 1
                });
            }
        }
Ejemplo n.º 16
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime          = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemCreatureSpawn = base.Project.FindSubsystem <SubsystemCreatureSpawn>(throwOnError: true);
     m_componentCreature      = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding   = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     HerdName                  = valuesDictionary.GetValue <string>("HerdName");
     m_herdingRange            = valuesDictionary.GetValue <float>("HerdingRange");
     m_autoNearbyCreaturesHelp = valuesDictionary.GetValue <bool>("AutoNearbyCreaturesHelp");
     m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker)
     {
         CallNearbyCreaturesHelp(attacker, 20f, 30f, isPersistent: false);
     };
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 1f * ((float)(GetHashCode() % 256) / 256f)))
         {
             Vector3?vector2 = FindHerdCenter();
             if (vector2.HasValue)
             {
                 float num = Vector3.Distance(vector2.Value, m_componentCreature.ComponentBody.Position);
                 if (num > 10f)
                 {
                     m_importanceLevel = 1f;
                 }
                 if (num > 12f)
                 {
                     m_importanceLevel = 3f;
                 }
                 if (num > 16f)
                 {
                     m_importanceLevel = 50f;
                 }
                 if (num > 20f)
                 {
                     m_importanceLevel = 250f;
                 }
             }
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Herd");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         m_stateMachine.TransitionTo("Herd");
         if (m_random.Bool(0.5f))
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             m_importanceLevel = 0f;
         }
     }, null, null);
     m_stateMachine.AddState("Herd", delegate
     {
         Vector3?vector = FindHerdCenter();
         if (vector.HasValue && Vector3.Distance(m_componentCreature.ComponentBody.Position, vector.Value) > 6f)
         {
             float speed = (m_importanceLevel > 10f) ? m_random.Float(0.9f, 1f) : m_random.Float(0.25f, 0.35f);
             int maxPathfindingPositions = (m_importanceLevel > 200f) ? 100 : 0;
             m_componentPathfinding.SetDestination(vector.Value, speed, 7f, maxPathfindingPositions, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
         }
         else
         {
             m_importanceLevel = 0f;
         }
     }, delegate
     {
         m_componentCreature.ComponentLocomotion.LookOrder = m_look - m_componentCreature.ComponentLocomotion.LookAngles;
         if (m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
         if (!m_componentPathfinding.Destination.HasValue)
         {
             m_importanceLevel = 0f;
         }
         if (m_random.Float(0f, 1f) < 0.05f * m_dt)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
         }
         if (m_random.Float(0f, 1f) < 1.5f * m_dt)
         {
             m_look = new Vector2(MathUtils.DegToRad(45f) * m_random.Float(-1f, 1f), MathUtils.DegToRad(10f) * m_random.Float(-1f, 1f));
         }
     }, null);
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
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);
        }