Example #1
0
 public void PlayIdleSound(bool skipIfRecentlyPlayed)
 {
     if (!string.IsNullOrEmpty(m_idleSound) && m_subsystemTime.GameTime > m_lastSoundTime + (double)(skipIfRecentlyPlayed ? 12f : 1f))
     {
         m_lastSoundTime = m_subsystemTime.GameTime;
         m_subsystemAudio.PlayRandomSound(m_idleSound, 1f, m_random.Float(-0.1f, 0.1f), m_componentCreature.ComponentBody.Position, m_idleSoundMinDistance, autoDelay: false);
     }
 }
Example #2
0
        public void ExplodeFireworks(Vector3 position, int data)
        {
            for (int i = 0; i < 3; i++)
            {
                Vector3 v = new Vector3(m_random.Float(-3f, 3f), -15f, m_random.Float(-3f, 3f));
                if (m_subsystemTerrain.Raycast(position, position + v, useInteractionBoxes: false, skipAirBlocks: true, null).HasValue)
                {
                    return;
                }
            }
            FireworksBlock.Shape shape = FireworksBlock.GetShape(data);
            float flickering           = FireworksBlock.GetFlickering(data) ? 0.66f : 0f;
            float particleSize         = (FireworksBlock.GetAltitude(data) > 0) ? 1.1f : 1f;
            Color color = FireworksBlock.FireworksColors[FireworksBlock.GetColor(data)];

            m_subsystemParticles.AddParticleSystem(new FireworksParticleSystem(position, color, shape, flickering, particleSize));
            m_subsystemAudio.PlayRandomSound("Audio/FireworksPop", 1f, m_random.Float(-0.4f, 0f), position, 80f, autoDelay: true);
            m_subsystemNoise.MakeNoise(position, 1f, 60f);
        }
Example #3
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemSky         = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_howlSoundName        = valuesDictionary.GetValue <string>("HowlSoundName");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Howl");
         }
         if (m_subsystemSky.SkyLightIntensity < 0.1f)
         {
             if (m_random.Float(0f, 1f) < 0.015f * m_subsystemTime.GameTimeDelta)
             {
                 m_importanceLevel = m_random.Float(1f, 3f);
             }
         }
         else
         {
             m_importanceLevel = 0f;
         }
     }, null);
     m_stateMachine.AddState("Howl", delegate
     {
         m_howlTime     = 0f;
         m_howlDuration = m_random.Float(5f, 6f);
         m_componentPathfinding.Stop();
         m_importanceLevel = 10f;
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(m_componentCreature.ComponentLocomotion.LookOrder.X, 2f);
         float num = m_howlTime + m_subsystemTime.GameTimeDelta;
         if (m_howlTime <= 0.5f && num > 0.5f)
         {
             m_subsystemAudio.PlayRandomSound(m_howlSoundName, 1f, m_random.Float(-0.1f, 0.1f), m_componentCreature.ComponentBody.Position, 10f, autoDelay: true);
         }
         m_howlTime = num;
         if (m_howlTime >= m_howlDuration)
         {
             m_importanceLevel = 0f;
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);

            if (terrainRaycastResult.HasValue)
            {
                if (terrainRaycastResult.Value.CellFace.Face == 4)
                {
                    int   cellValue = m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z);
                    int   num       = Terrain.ExtractContents(cellValue);
                    Block block     = BlocksManager.Blocks[num];
                    switch (num)
                    {
                    case 2:
                    {
                        int value2 = Terrain.ReplaceContents(cellValue, 168);
                        m_subsystemTerrain.ChangeCell(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, value2);
                        m_subsystemAudio.PlayRandomSound("Audio/Impacts/Dirt", 0.5f, 0f, new Vector3(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z), 3f, autoDelay: true);
                        Vector3 position2 = new Vector3((float)terrainRaycastResult.Value.CellFace.X + 0.5f, (float)terrainRaycastResult.Value.CellFace.Y + 1.25f, (float)terrainRaycastResult.Value.CellFace.Z + 0.5f);
                        m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, position2, cellValue, 0.5f));
                        break;
                    }

                    case 8:
                    {
                        int value = Terrain.ReplaceContents(cellValue, 2);
                        m_subsystemTerrain.ChangeCell(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, value);
                        m_subsystemAudio.PlayRandomSound("Audio/Impacts/Plant", 0.5f, 0f, new Vector3(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z), 3f, autoDelay: true);
                        Vector3 position = new Vector3((float)terrainRaycastResult.Value.CellFace.X + 0.5f, (float)terrainRaycastResult.Value.CellFace.Y + 1.2f, (float)terrainRaycastResult.Value.CellFace.Z + 0.5f);
                        m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, position, cellValue, 0.75f));
                        break;
                    }
                    }
                }
                componentMiner.DamageActiveTool(1);
                return(true);
            }
            return(false);
        }
        public float ApplyArmorProtection(float attackPower)
        {
            float        num  = m_random.Float(0f, 1f);
            ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head));
            float        num2 = ((ClothingBlock)BlocksManager.Blocks[203]).Durability + 1;
            List <int>   list = new List <int>(GetClothes(slot));

            for (int i = 0; i < list.Count; i++)
            {
                int          value        = list[i];
                ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                float        x            = (num2 - (float)BlocksManager.Blocks[203].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.Float(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f);
                    }
                }
            }
            int num4 = 0;

            while (num4 < list.Count)
            {
                if (Terrain.ExtractContents(list[num4]) != 203)
                {
                    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));
        }
Example #6
0
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            m_subsystemAudio.PlayRandomSound("Audio/Whistle", 1f, m_random.Float(-0.2f, 0f), ray.Position, 4f, autoDelay: true);
            m_subsystemNoise.MakeNoise(componentMiner.ComponentCreature.ComponentBody, 0.5f, 30f);
            DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>();

            m_subsystemBodies.FindBodiesAroundPoint(new Vector2(componentMiner.ComponentCreature.ComponentBody.Position.X, componentMiner.ComponentCreature.ComponentBody.Position.Z), 64f, dynamicArray);
            float num = float.PositiveInfinity;
            List <ComponentBody> list = new List <ComponentBody>();

            foreach (ComponentBody item in dynamicArray)
            {
                ComponentSummonBehavior componentSummonBehavior = item.Entity.FindComponent <ComponentSummonBehavior>();
                if (componentSummonBehavior != null && componentSummonBehavior.IsEnabled)
                {
                    float num2 = Vector3.Distance(item.Position, componentMiner.ComponentCreature.ComponentBody.Position);
                    if (num2 > 4f && componentSummonBehavior.SummonTarget == null)
                    {
                        list.Add(item);
                        num = MathUtils.Min(num, num2);
                    }
                    else
                    {
                        componentSummonBehavior.SummonTarget = componentMiner.ComponentCreature.ComponentBody;
                    }
                }
            }
            foreach (ComponentBody item2 in list)
            {
                ComponentSummonBehavior componentSummonBehavior2 = item2.Entity.FindComponent <ComponentSummonBehavior>();
                if (componentSummonBehavior2 != null && Vector3.Distance(item2.Position, componentMiner.ComponentCreature.ComponentBody.Position) < num + 4f)
                {
                    componentSummonBehavior2.SummonTarget = componentMiner.ComponentCreature.ComponentBody;
                }
            }
            componentMiner.DamageActiveTool(1);
            return(true);
        }
Example #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;
 }
        public override void Update(float dt)
        {
            if (m_componentCreature.ComponentBody.IsSneaking)
            {
                m_sneakFactor = MathUtils.Min(m_sneakFactor + 2f * dt, 1f);
            }
            else
            {
                m_sneakFactor = MathUtils.Max(m_sneakFactor - 2f * dt, 0f);
            }
            if ((m_componentSleep != null && m_componentSleep.IsSleeping) || m_componentCreature.ComponentHealth.Health <= 0f)
            {
                m_lieDownFactorEye   = MathUtils.Min(m_lieDownFactorEye + 1f * dt, 1f);
                m_lieDownFactorModel = MathUtils.Min(m_lieDownFactorModel + 3f * dt, 1f);
            }
            else
            {
                m_lieDownFactorEye   = MathUtils.Max(m_lieDownFactorEye - 1f * dt, 0f);
                m_lieDownFactorModel = MathUtils.Max(m_lieDownFactorModel - 3f * dt, 0f);
            }
            bool  flag           = true;
            bool  flag2          = true;
            float footstepsPhase = m_footstepsPhase;

            if (m_componentCreature.ComponentLocomotion.LadderValue.HasValue)
            {
                m_footstepsPhase += 1.5f * m_walkAnimationSpeed * m_componentCreature.ComponentBody.Velocity.Length() * dt;
                flag2             = false;
            }
            else if (!m_componentCreature.ComponentLocomotion.IsCreativeFlyEnabled)
            {
                float num = m_componentCreature.ComponentLocomotion.SlipSpeed ?? (m_componentCreature.ComponentBody.Velocity.XZ - m_componentCreature.ComponentBody.StandingOnVelocity.XZ).Length();
                if (num > 0.5f)
                {
                    base.MovementAnimationPhase += num * dt * m_walkAnimationSpeed;
                    m_footstepsPhase            += 1f * m_walkAnimationSpeed * num * dt;
                    flag  = false;
                    flag2 = false;
                }
            }
            if (flag)
            {
                float num2 = 0.5f * MathUtils.Floor(2f * base.MovementAnimationPhase);
                if (base.MovementAnimationPhase != num2)
                {
                    if (base.MovementAnimationPhase - num2 > 0.25f)
                    {
                        base.MovementAnimationPhase = MathUtils.Min(base.MovementAnimationPhase + 2f * dt, num2 + 0.5f);
                    }
                    else
                    {
                        base.MovementAnimationPhase = MathUtils.Max(base.MovementAnimationPhase - 2f * dt, num2);
                    }
                }
            }
            if (flag2)
            {
                m_footstepsPhase = 0f;
            }
            float          num3           = 0f;
            ComponentMount componentMount = (m_componentRider != null) ? m_componentRider.Mount : null;

            if (componentMount != null)
            {
                ComponentCreatureModel componentCreatureModel = componentMount.Entity.FindComponent <ComponentCreatureModel>();
                if (componentCreatureModel != null)
                {
                    base.Bob = componentCreatureModel.Bob;
                    num3     = base.Bob;
                }
                m_headingOffset = 0f;
            }
            else
            {
                float x = MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase);
                num3 = m_walkBobHeight * MathUtils.Sqr(x);
                float num4 = 0f;
                if (m_componentCreature.ComponentLocomotion.LastWalkOrder.HasValue && m_componentCreature.ComponentLocomotion.LastWalkOrder != Vector2.Zero)
                {
                    num4 = Vector2.Angle(Vector2.UnitY, m_componentCreature.ComponentLocomotion.LastWalkOrder.Value);
                }
                m_headingOffset += MathUtils.NormalizeAngle(num4 - m_headingOffset) * MathUtils.Saturate(8f * m_subsystemTime.GameTimeDelta);
                m_headingOffset  = MathUtils.NormalizeAngle(m_headingOffset);
            }
            float num5 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);

            base.Bob += num5 * (num3 - base.Bob);
            base.IsAttackHitMoment = false;
            if (base.AttackOrder)
            {
                m_punchFactor = MathUtils.Min(m_punchFactor + 4f * dt, 1f);
                float punchPhase = m_punchPhase;
                m_punchPhase = MathUtils.Remainder(m_punchPhase + dt * 2f, 1f);
                if (punchPhase < 0.5f && m_punchPhase >= 0.5f)
                {
                    base.IsAttackHitMoment = true;
                    m_punchCounter++;
                }
            }
            else
            {
                m_punchFactor = MathUtils.Max(m_punchFactor - 4f * dt, 0f);
                if (m_punchPhase != 0f)
                {
                    if (m_punchPhase > 0.5f)
                    {
                        m_punchPhase = MathUtils.Remainder(MathUtils.Min(m_punchPhase + dt * 2f, 1f), 1f);
                    }
                    else if (m_punchPhase > 0f)
                    {
                        m_punchPhase = MathUtils.Max(m_punchPhase - dt * m_punchPhase, 0f);
                    }
                }
            }
            m_rowLeft  = base.RowLeftOrder;
            m_rowRight = base.RowRightOrder;
            if ((m_rowLeft || m_rowRight) && componentMount != null && componentMount.ComponentBody.ImmersionFactor > 0f && MathUtils.Floor(1.1000000238418579 * m_subsystemTime.GameTime) != MathUtils.Floor(1.1000000238418579 * (m_subsystemTime.GameTime - (double)m_subsystemTime.GameTimeDelta)))
            {
                m_subsystemAudio.PlayRandomSound("Audio/Rowing", m_random.Float(0.4f, 0.6f), m_random.Float(-0.3f, 0.2f), m_componentCreature.ComponentBody.Position, 3f, autoDelay: true);
            }
            float num6 = MathUtils.Floor(m_footstepsPhase);

            if (m_footstepsPhase > num6 && footstepsPhase <= num6)
            {
                if (!m_componentCreature.ComponentBody.IsSneaking)
                {
                    m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 8f);
                }
                if (!m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(1f))
                {
                    m_footstepsPhase = 0f;
                }
            }
            m_aimHandAngle               = base.AimHandAngleOrder;
            m_inHandItemOffset           = Vector3.Lerp(m_inHandItemOffset, base.InHandItemOffsetOrder, 10f * dt);
            m_inHandItemRotation         = Vector3.Lerp(m_inHandItemRotation, base.InHandItemRotationOrder, 10f * dt);
            base.AttackOrder             = false;
            base.RowLeftOrder            = false;
            base.RowRightOrder           = false;
            base.AimHandAngleOrder       = 0f;
            base.InHandItemOffsetOrder   = Vector3.Zero;
            base.InHandItemRotationOrder = Vector3.Zero;
            base.Update(dt);
        }
Example #9
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);
        }
        public void Update(float dt)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
            float  num  = MathUtils.Pow(0.5f, dt);
            float  num2 = MathUtils.Pow(0.001f, dt);

            m_tmpPlayers.Clear();
            foreach (ComponentPlayer componentPlayer in m_subsystemPlayers.ComponentPlayers)
            {
                if (componentPlayer.ComponentHealth.Health > 0f)
                {
                    m_tmpPlayers.Add(componentPlayer);
                }
            }
            foreach (Pickable pickable in m_pickables)
            {
                if (pickable.ToRemove)
                {
                    m_pickablesToRemove.Add(pickable);
                }
                else
                {
                    Block  block = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)];
                    int    num3  = m_pickables.Count - m_pickablesToRemove.Count;
                    float  num4  = MathUtils.Lerp(300f, 90f, MathUtils.Saturate((float)num3 / 60f));
                    double num5  = totalElapsedGameTime - pickable.CreationTime;
                    if (num5 > (double)num4)
                    {
                        pickable.ToRemove = true;
                    }
                    else
                    {
                        TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Z));
                        if (chunkAtCell != null && chunkAtCell.State > TerrainChunkState.InvalidContents4)
                        {
                            Vector3 position = pickable.Position;
                            Vector3 vector   = position + pickable.Velocity * dt;
                            if (!pickable.FlyToPosition.HasValue && num5 > 0.5)
                            {
                                foreach (ComponentPlayer tmpPlayer in m_tmpPlayers)
                                {
                                    ComponentBody componentBody = tmpPlayer.ComponentBody;
                                    Vector3       v             = componentBody.Position + new Vector3(0f, 0.75f, 0f);
                                    float         num6          = (v - pickable.Position).LengthSquared();
                                    if (num6 < 3.0625f)
                                    {
                                        bool       flag      = Terrain.ExtractContents(pickable.Value) == 248;
                                        IInventory inventory = tmpPlayer.ComponentMiner.Inventory;
                                        if (flag || ComponentInventoryBase.FindAcquireSlotForItem(inventory, pickable.Value) >= 0)
                                        {
                                            if (num6 < 1f)
                                            {
                                                if (flag)
                                                {
                                                    tmpPlayer.ComponentLevel.AddExperience(pickable.Count, playSound: true);
                                                    pickable.ToRemove = true;
                                                }
                                                else
                                                {
                                                    pickable.Count = ComponentInventoryBase.AcquireItems(inventory, pickable.Value, pickable.Count);
                                                    if (pickable.Count == 0)
                                                    {
                                                        pickable.ToRemove = true;
                                                        m_subsystemAudio.PlaySound("Audio/PickableCollected", 0.7f, -0.4f, pickable.Position, 2f, autoDelay: false);
                                                    }
                                                }
                                            }
                                            else if (!pickable.StuckMatrix.HasValue)
                                            {
                                                pickable.FlyToPosition = v + 0.1f * MathUtils.Sqrt(num6) * componentBody.Velocity;
                                            }
                                        }
                                    }
                                }
                            }
                            if (pickable.FlyToPosition.HasValue)
                            {
                                Vector3 v2   = pickable.FlyToPosition.Value - pickable.Position;
                                float   num7 = v2.LengthSquared();
                                if (num7 >= 0.25f)
                                {
                                    pickable.Velocity = 6f * v2 / MathUtils.Sqrt(num7);
                                }
                                else
                                {
                                    pickable.FlyToPosition = null;
                                }
                            }
                            else
                            {
                                FluidBlock surfaceBlock;
                                float?     surfaceHeight;
                                Vector2?   vector2 = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z), out surfaceBlock, out surfaceHeight);
                                if (!pickable.StuckMatrix.HasValue)
                                {
                                    TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                                    if (terrainRaycastResult.HasValue)
                                    {
                                        int contents = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z));
                                        SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                                        for (int i = 0; i < blockBehaviors.Length; i++)
                                        {
                                            blockBehaviors[i].OnHitByProjectile(terrainRaycastResult.Value.CellFace, pickable);
                                        }
                                        if (m_subsystemTerrain.Raycast(position, position, useInteractionBoxes: false, skipAirBlocks: true, (int value2, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value2)].IsCollidable).HasValue)
                                        {
                                            int num8  = Terrain.ToCell(position.X);
                                            int num9  = Terrain.ToCell(position.Y);
                                            int num10 = Terrain.ToCell(position.Z);
                                            int num11 = 0;
                                            int num12 = 0;
                                            int num13 = 0;
                                            int?num14 = null;
                                            for (int j = -3; j <= 3; j++)
                                            {
                                                for (int k = -3; k <= 3; k++)
                                                {
                                                    for (int l = -3; l <= 3; l++)
                                                    {
                                                        if (!BlocksManager.Blocks[m_subsystemTerrain.Terrain.GetCellContents(j + num8, k + num9, l + num10)].IsCollidable)
                                                        {
                                                            int num15 = j * j + k * k + l * l;
                                                            if (!num14.HasValue || num15 < num14.Value)
                                                            {
                                                                num11 = j + num8;
                                                                num12 = k + num9;
                                                                num13 = l + num10;
                                                                num14 = num15;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            if (num14.HasValue)
                                            {
                                                pickable.FlyToPosition = new Vector3(num11, num12, num13) + new Vector3(0.5f);
                                            }
                                            else
                                            {
                                                pickable.ToRemove = true;
                                            }
                                        }
                                        else
                                        {
                                            Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
                                            bool  flag2 = vector2.HasValue && vector2.Value != Vector2.Zero;
                                            if (plane.Normal.X != 0f)
                                            {
                                                float num16 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.Y) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(0f - num16, num16, num16);
                                            }
                                            if (plane.Normal.Y != 0f)
                                            {
                                                float num17 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(num17, 0f - num17, num17);
                                                if (flag2)
                                                {
                                                    pickable.Velocity.Y += 0.1f * plane.Normal.Y;
                                                }
                                            }
                                            if (plane.Normal.Z != 0f)
                                            {
                                                float num18 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Y)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(num18, num18, 0f - num18);
                                            }
                                            vector = position;
                                        }
                                    }
                                }
                                else
                                {
                                    Vector3 vector3 = pickable.StuckMatrix.Value.Translation + pickable.StuckMatrix.Value.Up * block.ProjectileTipOffset;
                                    if (!m_subsystemTerrain.Raycast(vector3, vector3, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable).HasValue)
                                    {
                                        pickable.Position    = pickable.StuckMatrix.Value.Translation;
                                        pickable.Velocity    = Vector3.Zero;
                                        pickable.StuckMatrix = null;
                                    }
                                }
                                if (surfaceBlock is WaterBlock && !pickable.SplashGenerated)
                                {
                                    m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 6f, autoDelay: true);
                                    pickable.SplashGenerated = true;
                                }
                                else if (surfaceBlock is MagmaBlock && !pickable.SplashGenerated)
                                {
                                    m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true);
                                    pickable.ToRemove        = true;
                                    pickable.SplashGenerated = true;
                                    m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                                }
                                else if (surfaceBlock == null)
                                {
                                    pickable.SplashGenerated = false;
                                }
                                if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(pickable.GetHashCode() % 100) / 100.0) && (m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)) == 104 || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z))))
                                {
                                    m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true);
                                    pickable.ToRemove = true;
                                    m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                                }
                                if (!pickable.StuckMatrix.HasValue)
                                {
                                    if (vector2.HasValue && surfaceHeight.HasValue)
                                    {
                                        float num19 = surfaceHeight.Value - pickable.Position.Y;
                                        float num20 = MathUtils.Saturate(3f * num19);
                                        pickable.Velocity.X += 4f * dt * (vector2.Value.X - pickable.Velocity.X);
                                        pickable.Velocity.Y -= 10f * dt;
                                        pickable.Velocity.Y += 10f * (1f / block.Density * num20) * dt;
                                        pickable.Velocity.Z += 4f * dt * (vector2.Value.Y - pickable.Velocity.Z);
                                        pickable.Velocity.Y *= num2;
                                    }
                                    else
                                    {
                                        pickable.Velocity.Y -= 10f * dt;
                                        pickable.Velocity   *= num;
                                    }
                                }
                            }
                            pickable.Position = vector;
                        }
                    }
                }
            }
            foreach (Pickable item in m_pickablesToRemove)
            {
                m_pickables.Remove(item);
                if (this.PickableRemoved != null)
                {
                    this.PickableRemoved(item);
                }
            }
            m_pickablesToRemove.Clear();
        }
Example #11
0
        public void Update(float dt)
        {
            CollisionVelocityChange = Vector3.Zero;
            Velocity      += m_totalImpulse;
            m_totalImpulse = Vector3.Zero;
            if (m_parentBody != null || m_velocity.LengthSquared() > 9.99999944E-11f || m_directMove != Vector3.Zero)
            {
                m_stoppedTime = 0f;
            }
            else
            {
                m_stoppedTime += dt;
                if (m_stoppedTime > 0.5f && !Time.PeriodicEvent(0.25, 0.0))
                {
                    return;
                }
            }
            Vector3      position    = base.Position;
            TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(position.X), Terrain.ToCell(position.Z));

            if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4)
            {
                Velocity = Vector3.Zero;
                return;
            }
            m_bodiesCollisionBoxes.Clear();
            FindBodiesCollisionBoxes(position, m_bodiesCollisionBoxes);
            m_movingBlocksCollisionBoxes.Clear();
            FindMovingBlocksCollisionBoxes(position, m_movingBlocksCollisionBoxes);
            if (!MoveToFreeSpace())
            {
                ComponentHealth componentHealth = base.Entity.FindComponent <ComponentHealth>();
                if (componentHealth != null)
                {
                    componentHealth.Injure(1f, null, ignoreInvulnerability: true, "Crushed");
                }
                else
                {
                    base.Project.RemoveEntity(base.Entity, disposeEntity: true);
                }
                return;
            }
            if (IsGravityEnabled)
            {
                m_velocity.Y -= 10f * dt;
                if (ImmersionFactor > 0f)
                {
                    float num = ImmersionFactor * (1f + 0.03f * MathUtils.Sin((float)MathUtils.Remainder(2.0 * m_subsystemTime.GameTime, 6.2831854820251465)));
                    m_velocity.Y += 10f * (1f / Density * num) * dt;
                }
            }
            float num2 = MathUtils.Saturate(AirDrag.X * dt);
            float num3 = MathUtils.Saturate(AirDrag.Y * dt);

            m_velocity.X *= 1f - num2;
            m_velocity.Y *= 1f - num3;
            m_velocity.Z *= 1f - num2;
            if (IsWaterDragEnabled && ImmersionFactor > 0f && ImmersionFluidBlock != null)
            {
                Vector2?vector  = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(position.X), Terrain.ToCell(position.Y), Terrain.ToCell(position.Z));
                Vector3 vector2 = vector.HasValue ? new Vector3(vector.Value.X, 0f, vector.Value.Y) : Vector3.Zero;
                float   num4    = 1f;
                if (ImmersionFluidBlock.FrictionFactor != 1f)
                {
                    num4 = ((SimplexNoise.Noise((float)MathUtils.Remainder(6.0 * Time.FrameStartTime + (double)(GetHashCode() % 1000), 1000.0)) > 0.5f) ? ImmersionFluidBlock.FrictionFactor : 1f);
                }
                float f  = MathUtils.Saturate(WaterDrag.X * num4 * ImmersionFactor * dt);
                float f2 = MathUtils.Saturate(WaterDrag.Y * num4 * dt);
                m_velocity.X = MathUtils.Lerp(m_velocity.X, vector2.X, f);
                m_velocity.Y = MathUtils.Lerp(m_velocity.Y, vector2.Y, f2);
                m_velocity.Z = MathUtils.Lerp(m_velocity.Z, vector2.Z, f);
                if (m_parentBody == null && vector.HasValue && !StandingOnValue.HasValue)
                {
                    if (WaterTurnSpeed > 0f)
                    {
                        float   s       = MathUtils.Saturate(MathUtils.Lerp(1f, 0f, m_velocity.Length()));
                        Vector2 vector3 = Vector2.Normalize(vector.Value) * s;
                        base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, WaterTurnSpeed * (-1f * vector3.X + 0.71f * vector3.Y) * dt);
                    }
                    if (WaterSwayAngle > 0f)
                    {
                        base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, WaterSwayAngle * (float)MathUtils.Sin((double)(200f / Mass) * m_subsystemTime.GameTime));
                    }
                }
            }
            if (m_parentBody != null)
            {
                Vector3 v = Vector3.Transform(ParentBodyPositionOffset, m_parentBody.Rotation) + m_parentBody.Position - position;
                m_velocity    = ((dt > 0f) ? (v / dt) : Vector3.Zero);
                base.Rotation = ParentBodyRotationOffset * m_parentBody.Rotation;
            }
            StandingOnValue    = null;
            StandingOnBody     = null;
            StandingOnVelocity = Vector3.Zero;
            Vector3 velocity = m_velocity;
            float   num5     = m_velocity.Length();

            if (num5 > 0f)
            {
                float x    = 0.45f * MathUtils.Min(BoxSize.X, BoxSize.Y, BoxSize.Z) / num5;
                float num6 = dt;
                while (num6 > 0f)
                {
                    float num7 = MathUtils.Min(num6, x);
                    MoveWithCollision(num7, m_velocity * num7 + m_directMove);
                    m_directMove = Vector3.Zero;
                    num6        -= num7;
                }
            }
            CollisionVelocityChange = m_velocity - velocity;
            if (IsGroundDragEnabled && StandingOnValue.HasValue)
            {
                m_velocity = Vector3.Lerp(m_velocity, StandingOnVelocity, 6f * dt);
            }
            if (!StandingOnValue.HasValue)
            {
                IsSneaking = false;
            }
            UpdateImmersionData();
            if (ImmersionFluidBlock is WaterBlock && ImmersionDepth > 0.3f && !m_fluidEffectsPlayed)
            {
                m_fluidEffectsPlayed = true;
                m_subsystemAudio.PlayRandomSound("Audio/WaterFallIn", m_random.Float(0.75f, 1f), m_random.Float(-0.3f, 0f), position, 4f, autoDelay: true);
                m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f));
            }
            else if (ImmersionFluidBlock is MagmaBlock && ImmersionDepth > 0f && !m_fluidEffectsPlayed)
            {
                m_fluidEffectsPlayed = true;
                m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, position, 4f, autoDelay: true);
                m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f));
            }
            else if (ImmersionFluidBlock == null)
            {
                m_fluidEffectsPlayed = false;
            }
        }
        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();
        }
        public override void Update(float dt)
        {
            float footstepsPhase = m_footstepsPhase;
            float num            = m_componentCreature.ComponentLocomotion.SlipSpeed ?? Vector3.Dot(m_componentCreature.ComponentBody.Velocity, m_componentCreature.ComponentBody.Matrix.Forward);

            if (m_canCanter && num > 0.7f * m_componentCreature.ComponentLocomotion.WalkSpeed)
            {
                m_gait = Gait.Canter;
                base.MovementAnimationPhase += num * dt * 0.7f * m_walkAnimationSpeed;
                m_footstepsPhase            += 0.7f * m_walkAnimationSpeed * num * dt;
            }
            else if (m_canTrot && num > 0.5f * m_componentCreature.ComponentLocomotion.WalkSpeed)
            {
                m_gait = Gait.Trot;
                base.MovementAnimationPhase += num * dt * m_walkAnimationSpeed;
                m_footstepsPhase            += 1.25f * m_walkAnimationSpeed * num * dt;
            }
            else if (MathUtils.Abs(num) > 0.2f)
            {
                m_gait = Gait.Walk;
                base.MovementAnimationPhase += num * dt * m_walkAnimationSpeed;
                m_footstepsPhase            += 1.25f * m_walkAnimationSpeed * num * dt;
            }
            else
            {
                m_gait = Gait.Walk;
                base.MovementAnimationPhase = 0f;
                m_footstepsPhase            = 0f;
            }
            float num2 = 0f;

            if (m_gait == Gait.Canter)
            {
                num2 = (0f - m_walkBobHeight) * 1.5f * MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase);
            }
            else if (m_gait == Gait.Trot)
            {
                num2 = m_walkBobHeight * 1.5f * MathUtils.Sqr(MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase));
            }
            else if (m_gait == Gait.Walk)
            {
                num2 = (0f - m_walkBobHeight) * MathUtils.Sqr(MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase));
            }
            float num3 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);

            base.Bob += num3 * (num2 - base.Bob);
            if (m_gait == Gait.Canter && m_useCanterSound)
            {
                float num4 = MathUtils.Floor(m_footstepsPhase);
                if (m_footstepsPhase > num4 && footstepsPhase <= num4)
                {
                    string footstepSoundMaterialName = m_subsystemSoundMaterials.GetFootstepSoundMaterialName(m_componentCreature);
                    if (!string.IsNullOrEmpty(footstepSoundMaterialName) && footstepSoundMaterialName != "Water")
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Footsteps/CanterDirt", 0.75f, m_random.Float(-0.25f, 0f), m_componentCreature.ComponentBody.Position, 3f, autoDelay: true);
                    }
                }
            }
            else
            {
                float num5 = MathUtils.Floor(m_footstepsPhase);
                if (m_footstepsPhase > num5 && footstepsPhase <= num5)
                {
                    m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(1f);
                }
            }
            if (base.FeedOrder)
            {
                m_feedFactor = MathUtils.Min(m_feedFactor + 2f * dt, 1f);
            }
            else
            {
                m_feedFactor = MathUtils.Max(m_feedFactor - 2f * dt, 0f);
            }
            base.IsAttackHitMoment = false;
            if (base.AttackOrder)
            {
                m_buttFactor = MathUtils.Min(m_buttFactor + 4f * dt, 1f);
                float buttPhase = m_buttPhase;
                m_buttPhase = MathUtils.Remainder(m_buttPhase + dt * 2f, 1f);
                if (buttPhase < 0.5f && m_buttPhase >= 0.5f)
                {
                    base.IsAttackHitMoment = true;
                }
            }
            else
            {
                m_buttFactor = MathUtils.Max(m_buttFactor - 4f * dt, 0f);
                if (m_buttPhase != 0f)
                {
                    if (m_buttPhase > 0.5f)
                    {
                        m_buttPhase = MathUtils.Remainder(MathUtils.Min(m_buttPhase + dt * 2f, 1f), 1f);
                    }
                    else if (m_buttPhase > 0f)
                    {
                        m_buttPhase = MathUtils.Max(m_buttPhase - dt * 2f, 0f);
                    }
                }
            }
            base.FeedOrder   = false;
            base.AttackOrder = false;
            base.Update(dt);
        }
 public void Update(float dt)
 {
     if (m_firePointsCopy.Count == 0)
     {
         m_firePointsCopy.Count += m_fireData.Count;
         m_fireData.Keys.CopyTo(m_firePointsCopy.Array, 0);
         m_copyIndex        = 0;
         m_lastScanDuration = (float)(m_subsystemTime.GameTime - m_lastScanTime);
         m_lastScanTime     = m_subsystemTime.GameTime;
         if (m_firePointsCopy.Count == 0)
         {
             m_fireSoundVolume = 0f;
         }
     }
     if (m_firePointsCopy.Count > 0)
     {
         float num  = MathUtils.Min(1f * dt * (float)m_firePointsCopy.Count + m_remainderToScan, 50f);
         int   num2 = (int)num;
         m_remainderToScan = num - (float)num2;
         int num3 = MathUtils.Min(m_copyIndex + num2, m_firePointsCopy.Count);
         while (m_copyIndex < num3)
         {
             if (m_fireData.TryGetValue(m_firePointsCopy.Array[m_copyIndex], out FireData value))
             {
                 int x    = value.Point.X;
                 int y    = value.Point.Y;
                 int z    = value.Point.Z;
                 int num4 = Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z));
                 m_fireSoundIntensity += 1f / (m_subsystemAudio.CalculateListenerDistanceSquared(new Vector3(x, y, z)) + 0.01f);
                 if ((num4 & 1) != 0)
                 {
                     value.Time0 -= m_lastScanDuration;
                     if (value.Time0 <= 0f)
                     {
                         QueueBurnAway(x, y, z + 1, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + expansionProbability.Key.X, y + expansionProbability.Key.Y, z + 1 + expansionProbability.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 2) != 0)
                 {
                     value.Time1 -= m_lastScanDuration;
                     if (value.Time1 <= 0f)
                     {
                         QueueBurnAway(x + 1, y, z, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability2 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability2.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + 1 + expansionProbability2.Key.X, y + expansionProbability2.Key.Y, z + expansionProbability2.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 4) != 0)
                 {
                     value.Time2 -= m_lastScanDuration;
                     if (value.Time2 <= 0f)
                     {
                         QueueBurnAway(x, y, z - 1, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability3 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability3.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + expansionProbability3.Key.X, y + expansionProbability3.Key.Y, z - 1 + expansionProbability3.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 8) != 0)
                 {
                     value.Time3 -= m_lastScanDuration;
                     if (value.Time3 <= 0f)
                     {
                         QueueBurnAway(x - 1, y, z, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability4 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability4.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x - 1 + expansionProbability4.Key.X, y + expansionProbability4.Key.Y, z + expansionProbability4.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if (num4 == 0)
                 {
                     value.Time5 -= m_lastScanDuration;
                     if (value.Time5 <= 0f)
                     {
                         QueueBurnAway(x, y - 1, z, value.FireExpandability * 0.85f);
                     }
                 }
             }
             m_copyIndex++;
         }
         if (m_copyIndex >= m_firePointsCopy.Count)
         {
             m_fireSoundVolume = 0.75f * m_fireSoundIntensity;
             m_firePointsCopy.Clear();
             m_fireSoundIntensity = 0f;
         }
     }
     if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0))
     {
         int num5 = 0;
         int num6 = 0;
         foreach (KeyValuePair <Point3, float> item in m_toBurnAway)
         {
             Point3 key    = item.Key;
             float  value2 = item.Value;
             base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, Terrain.ReplaceContents(0, 0));
             if (value2 > 0.25f)
             {
                 for (int i = 0; i < 5; i++)
                 {
                     Point3 point = CellFace.FaceToPoint3(i);
                     SetCellOnFire(key.X + point.X, key.Y + point.Y, key.Z + point.Z, value2);
                 }
             }
             float num7 = m_subsystemViews.CalculateDistanceFromNearestView(new Vector3(key));
             if (num5 < 15 && num7 < 24f)
             {
                 m_subsystemParticles.AddParticleSystem(new BurntDebrisParticleSystem(base.SubsystemTerrain, key.X, key.Y, key.Z));
                 num5++;
             }
             if (num6 < 4 && num7 < 16f)
             {
                 m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.25f, 0.25f), new Vector3(key.X, key.Y, key.Z), 3f, autoDelay: true);
                 num6++;
             }
         }
         foreach (KeyValuePair <Point3, float> item2 in m_toExpand)
         {
             SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value);
         }
         m_toBurnAway.Clear();
         m_toExpand.Clear();
     }
     m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume);
 }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            IInventory inventory        = componentMiner.Inventory;
            int        activeBlockValue = componentMiner.ActiveBlockValue;
            int        num = Terrain.ExtractContents(activeBlockValue);

            if (num == 90)
            {
                object obj = componentMiner.Raycast(ray, RaycastMode.Gathering);
                if (obj is TerrainRaycastResult)
                {
                    CellFace cellFace  = ((TerrainRaycastResult)obj).CellFace;
                    int      cellValue = base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
                    int      num2      = Terrain.ExtractContents(cellValue);
                    int      data      = Terrain.ExtractData(cellValue);
                    Block    block     = BlocksManager.Blocks[num2];
                    if (block is WaterBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value = Terrain.ReplaceContents(activeBlockValue, 91);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                    if (block is MagmaBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value2 = Terrain.ReplaceContents(activeBlockValue, 93);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value2, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                }
                else if (obj is BodyRaycastResult)
                {
                    ComponentUdder componentUdder = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentUdder>();
                    if (componentUdder != null && componentUdder.Milk(componentMiner))
                    {
                        int value3 = Terrain.ReplaceContents(activeBlockValue, 110);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value3, 1);
                        }
                        m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, autoDelay: true);
                    }
                    return(true);
                }
            }
            if (num == 91)
            {
                TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult.HasValue && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(18)))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        int value4 = Terrain.ReplaceContents(activeBlockValue, 90);
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, value4, 1);
                    }
                    return(true);
                }
            }
            if (num == 93)
            {
                TerrainRaycastResult?terrainRaycastResult2 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult2.HasValue)
                {
                    if (componentMiner.Place(terrainRaycastResult2.Value, Terrain.MakeBlockValue(92)))
                    {
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            int value5 = Terrain.ReplaceContents(activeBlockValue, 90);
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value5, 1);
                        }
                    }
                    return(true);
                }
            }
            switch (num)
            {
            case 110:
            case 245:
                return(true);

            case 251:
            case 252:
                return(true);

            case 128:
            case 129:
            {
                TerrainRaycastResult?terrainRaycastResult3 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging);
                if (terrainRaycastResult3.HasValue)
                {
                    CellFace cellFace2  = terrainRaycastResult3.Value.CellFace;
                    int      cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                    int      num3       = Terrain.ExtractContents(cellValue2);
                    Block    block2     = BlocksManager.Blocks[num3];
                    if (block2 is IPaintableBlock)
                    {
                        Vector3 normal   = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face);
                        Vector3 position = terrainRaycastResult3.Value.HitPoint();
                        int?    num4     = (num == 128) ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue)));
                        Color   color    = num4.HasValue ? SubsystemPalette.GetColor(base.SubsystemTerrain, num4) : new Color(128, 128, 128, 128);
                        int     value6   = ((IPaintableBlock)block2).Paint(base.SubsystemTerrain, cellValue2, num4);
                        base.SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6);
                        componentMiner.DamageActiveTool(1);
                        m_subsystemAudio.PlayRandomSound("Audio/Paint", 0.4f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentBody.Position, 2f, autoDelay: true);
                        m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(base.SubsystemTerrain, position, normal, color));
                    }
                    return(true);
                }
                break;
            }
            }
            return(false);
        }
Example #16
0
        public void Update(float dt)
        {
            PlayerInput playerInput = ComponentInput.PlayerInput;

            if (ComponentInput.IsControlledByTouch && m_aim.HasValue)
            {
                playerInput.Look = Vector2.Zero;
            }
            if (ComponentMiner.Inventory != null)
            {
                ComponentMiner.Inventory.ActiveSlotIndex += playerInput.ScrollInventory;
                if (playerInput.SelectInventorySlot.HasValue)
                {
                    ComponentMiner.Inventory.ActiveSlotIndex = MathUtils.Clamp(playerInput.SelectInventorySlot.Value, 0, 9);
                }
            }
            ComponentSteedBehavior componentSteedBehavior = null;
            ComponentBoat          componentBoat          = null;
            ComponentMount         mount = ComponentRider.Mount;

            if (mount != null)
            {
                componentSteedBehavior = mount.Entity.FindComponent <ComponentSteedBehavior>();
                componentBoat          = mount.Entity.FindComponent <ComponentBoat>();
            }
            if (componentSteedBehavior != null)
            {
                if (playerInput.Move.Z > 0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = 1;
                    m_speedOrderBlocked = true;
                }
                else if (playerInput.Move.Z < -0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = -1;
                    m_speedOrderBlocked = true;
                }
                else if (MathUtils.Abs(playerInput.Move.Z) <= 0.25f)
                {
                    m_speedOrderBlocked = false;
                }
                componentSteedBehavior.TurnOrder   = playerInput.Move.X;
                componentSteedBehavior.JumpOrder   = (playerInput.Jump ? 1 : 0);
                base.ComponentLocomotion.LookOrder = new Vector2(playerInput.Look.X, 0f);
            }
            else if (componentBoat != null)
            {
                componentBoat.TurnOrder                   = playerInput.Move.X;
                componentBoat.MoveOrder                   = playerInput.Move.Z;
                base.ComponentLocomotion.LookOrder        = new Vector2(playerInput.Look.X, 0f);
                base.ComponentCreatureModel.RowLeftOrder  = (playerInput.Move.X <-0.2f || playerInput.Move.Z> 0.2f);
                base.ComponentCreatureModel.RowRightOrder = (playerInput.Move.X > 0.2f || playerInput.Move.Z > 0.2f);
            }
            else
            {
                base.ComponentLocomotion.WalkOrder = (base.ComponentBody.IsSneaking ? (0.66f * new Vector2(playerInput.SneakMove.X, playerInput.SneakMove.Z)) : new Vector2(playerInput.Move.X, playerInput.Move.Z));
                base.ComponentLocomotion.FlyOrder  = new Vector3(0f, playerInput.Move.Y, 0f);
                base.ComponentLocomotion.TurnOrder = playerInput.Look * new Vector2(1f, 0f);
                base.ComponentLocomotion.JumpOrder = MathUtils.Max(playerInput.Jump ? 1 : 0, base.ComponentLocomotion.JumpOrder);
            }
            base.ComponentLocomotion.LookOrder  += playerInput.Look * (SettingsManager.FlipVerticalAxis ? new Vector2(0f, -1f) : new Vector2(0f, 1f));
            base.ComponentLocomotion.VrLookOrder = playerInput.VrLook;
            base.ComponentLocomotion.VrMoveOrder = playerInput.VrMove;
            int   num   = Terrain.ExtractContents(ComponentMiner.ActiveBlockValue);
            Block block = BlocksManager.Blocks[num];
            bool  flag  = false;

            if (playerInput.Interact.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                if (!ComponentMiner.Use(playerInput.Interact.Value))
                {
                    TerrainRaycastResult?terrainRaycastResult = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Interact.Value, RaycastMode.Interaction);
                    if (terrainRaycastResult.HasValue)
                    {
                        if (!ComponentMiner.Interact(terrainRaycastResult.Value))
                        {
                            if (ComponentMiner.Place(terrainRaycastResult.Value))
                            {
                                m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                                flag           = true;
                                m_isAimBlocked = true;
                            }
                        }
                        else
                        {
                            m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                            flag           = true;
                            m_isAimBlocked = true;
                        }
                    }
                }
                else
                {
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                    flag           = true;
                    m_isAimBlocked = true;
                }
            }
            float num2 = (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) ? 0.1f : 1.4f;

            if (playerInput.Aim.HasValue && block.IsAimable && m_subsystemTime.GameTime - m_lastActionTime > (double)num2)
            {
                if (!m_isAimBlocked)
                {
                    Ray3    value  = playerInput.Aim.Value;
                    Vector3 vector = GameWidget.ActiveCamera.WorldToScreen(value.Position + value.Direction, Matrix.Identity);
                    Point2  size   = Window.Size;
                    if (ComponentInput.IsControlledByVr || (vector.X >= (float)size.X * 0.02f && vector.X < (float)size.X * 0.98f && vector.Y >= (float)size.Y * 0.02f && vector.Y < (float)size.Y * 0.98f))
                    {
                        m_aim = value;
                        if (ComponentMiner.Aim(value, AimState.InProgress))
                        {
                            ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                            m_aim          = null;
                            m_isAimBlocked = true;
                        }
                        else if (!m_aimHintIssued && Time.PeriodicEvent(1.0, 0.0))
                        {
                            Time.QueueTimeDelayedExecution(Time.RealTime + 3.0, delegate
                            {
                                if (!m_aimHintIssued && m_aim.HasValue && !base.ComponentBody.IsSneaking)
                                {
                                    m_aimHintIssued = true;
                                    ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                                }
                            });
                        }
                    }
                    else if (m_aim.HasValue)
                    {
                        ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                        m_aim          = null;
                        m_isAimBlocked = true;
                    }
                }
            }
            else
            {
                m_isAimBlocked = false;
                if (m_aim.HasValue)
                {
                    ComponentMiner.Aim(m_aim.Value, AimState.Completed);
                    m_aim            = null;
                    m_lastActionTime = m_subsystemTime.GameTime;
                }
            }
            flag |= m_aim.HasValue;
            if (playerInput.Hit.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                BodyRaycastResult?bodyRaycastResult = ComponentMiner.Raycast <BodyRaycastResult>(playerInput.Hit.Value, RaycastMode.Interaction);
                if (bodyRaycastResult.HasValue)
                {
                    flag           = true;
                    m_isDigBlocked = true;
                    if (Vector3.Distance(bodyRaycastResult.Value.HitPoint(), base.ComponentCreatureModel.EyePosition) <= 2f)
                    {
                        ComponentMiner.Hit(bodyRaycastResult.Value.ComponentBody, bodyRaycastResult.Value.HitPoint(), playerInput.Hit.Value.Direction);
                    }
                }
            }
            if (playerInput.Dig.HasValue && !flag && !m_isDigBlocked && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                TerrainRaycastResult?terrainRaycastResult2 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Dig.Value, RaycastMode.Digging);
                if (terrainRaycastResult2.HasValue && ComponentMiner.Dig(terrainRaycastResult2.Value))
                {
                    m_lastActionTime = m_subsystemTime.GameTime;
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                }
            }
            if (!playerInput.Dig.HasValue)
            {
                m_isDigBlocked = false;
            }
            if (playerInput.Drop && ComponentMiner.Inventory != null)
            {
                IInventory inventory = ComponentMiner.Inventory;
                int        slotValue = inventory.GetSlotValue(inventory.ActiveSlotIndex);
                int        num3      = inventory.RemoveSlotItems(count: inventory.GetSlotCount(inventory.ActiveSlotIndex), slotIndex: inventory.ActiveSlotIndex);
                if (slotValue != 0 && num3 != 0)
                {
                    Vector3 position = base.ComponentBody.Position + new Vector3(0f, base.ComponentBody.BoxSize.Y * 0.66f, 0f) + 0.25f * base.ComponentBody.Matrix.Forward;
                    Vector3 value2   = 8f * Matrix.CreateFromQuaternion(base.ComponentCreatureModel.EyeRotation).Forward;
                    m_subsystemPickables.AddPickable(slotValue, num3, position, value2, null);
                }
            }
            if (!playerInput.PickBlockType.HasValue || flag)
            {
                return;
            }
            ComponentCreativeInventory componentCreativeInventory = ComponentMiner.Inventory as ComponentCreativeInventory;

            if (componentCreativeInventory == null)
            {
                return;
            }
            TerrainRaycastResult?terrainRaycastResult3 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.PickBlockType.Value, RaycastMode.Digging, raycastTerrain: true, raycastBodies: false, raycastMovingBlocks: false);

            if (!terrainRaycastResult3.HasValue)
            {
                return;
            }
            int value3 = terrainRaycastResult3.Value.Value;

            value3 = Terrain.ReplaceLight(value3, 0);
            int               num4           = Terrain.ExtractContents(value3);
            Block             block2         = BlocksManager.Blocks[num4];
            int               num5           = 0;
            IEnumerable <int> creativeValues = block2.GetCreativeValues();

            if (block2.GetCreativeValues().Contains(value3))
            {
                num5 = value3;
            }
            if (num5 == 0 && !block2.IsNonDuplicable)
            {
                List <BlockDropValue> list = new List <BlockDropValue>();
                block2.GetDropValues(m_subsystemTerrain, value3, 0, int.MaxValue, list, out bool _);
                if (list.Count > 0 && list[0].Count > 0)
                {
                    num5 = list[0].Value;
                }
            }
            if (num5 == 0)
            {
                num5 = creativeValues.FirstOrDefault();
            }
            if (num5 == 0)
            {
                return;
            }
            int num6 = -1;

            for (int i = 0; i < 10; i++)
            {
                if (componentCreativeInventory.GetSlotCapacity(i, num5) > 0 && componentCreativeInventory.GetSlotCount(i) > 0 && componentCreativeInventory.GetSlotValue(i) == num5)
                {
                    num6 = i;
                    break;
                }
            }
            if (num6 < 0)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (componentCreativeInventory.GetSlotCapacity(j, num5) > 0 && (componentCreativeInventory.GetSlotCount(j) == 0 || componentCreativeInventory.GetSlotValue(j) == 0))
                    {
                        num6 = j;
                        break;
                    }
                }
            }
            if (num6 < 0)
            {
                num6 = componentCreativeInventory.ActiveSlotIndex;
            }
            componentCreativeInventory.RemoveSlotItems(num6, int.MaxValue);
            componentCreativeInventory.AddSlotItems(num6, num5, 1);
            componentCreativeInventory.ActiveSlotIndex = num6;
            ComponentGui.DisplaySmallMessage(block2.GetDisplayName(m_subsystemTerrain, value3), Color.White, blinking: false, playNotificationSound: false);
            m_subsystemAudio.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f, 0f);
        }