Example #1
0
        public void DrawSquares(DrawContext dc)
        {
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, DepthStencilState.None, null, BlendState.AlphaBlend);
            int         count       = flatBatch2D.LineVertices.Count;
            int         count2      = flatBatch2D.TriangleVertices.Count;
            float       num         = (float)MathUtils.Remainder(Time.FrameStartTime + (double)m_timeOffset, 10000.0);
            float       num2        = base.ActualSize.X / 12f;
            float       num3        = (float)(int)base.GlobalColorTransform.A / 255f;

            for (float num4 = 0f; num4 < base.ActualSize.X; num4 += num2)
            {
                for (float num5 = 0f; num5 < base.ActualSize.Y; num5 += num2)
                {
                    float   num6    = 0.35f * MathUtils.Pow(MathUtils.Saturate(SimplexNoise.OctavedNoise(num4 + 1000f, num5, 0.7f * num, 0.5f, 1, 2f, 1f) - 0.1f), 1f) * num3;
                    float   num7    = 0.7f * MathUtils.Pow(SimplexNoise.OctavedNoise(num4, num5, 0.5f * num, 0.5f, 1, 2f, 1f), 3f) * num3;
                    Vector2 corner  = new Vector2(num4, num5);
                    Vector2 corner2 = new Vector2(num4 + num2, num5 + num2);
                    if (num6 > 0.01f)
                    {
                        flatBatch2D.QueueRectangle(corner, corner2, 0f, new Color(0f, 0f, 0f, num6));
                    }
                    if (num7 > 0.01f)
                    {
                        flatBatch2D.QueueQuad(corner, corner2, 0f, new Color(0f, 0f, 0f, num7));
                    }
                }
            }
            flatBatch2D.TransformLines(base.GlobalTransform, count);
            flatBatch2D.TransformTriangles(base.GlobalTransform, count2);
        }
Example #2
0
 public Vector2?CalculateFlowSpeed(int x, int y, int z, out FluidBlock surfaceBlock, out float?surfaceHeight)
 {
     surfaceHeight = GetSurfaceHeight(x, y, z, out surfaceBlock);
     if (surfaceHeight.HasValue)
     {
         y = (int)surfaceHeight.Value;
         int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
         int num       = Terrain.ExtractContents(cellValue);
         if (BlocksManager.Blocks[num] is FluidBlock)
         {
             int     cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x - 1, y, z);
             int     cellValue3 = base.SubsystemTerrain.Terrain.GetCellValue(x + 1, y, z);
             int     cellValue4 = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z - 1);
             int     cellValue5 = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z + 1);
             int     num2       = Terrain.ExtractContents(cellValue2);
             int     num3       = Terrain.ExtractContents(cellValue3);
             int     num4       = Terrain.ExtractContents(cellValue4);
             int     num5       = Terrain.ExtractContents(cellValue5);
             int     level      = FluidBlock.GetLevel(Terrain.ExtractData(cellValue));
             int     num6       = (num2 == num) ? FluidBlock.GetLevel(Terrain.ExtractData(cellValue2)) : level;
             int     num7       = (num3 == num) ? FluidBlock.GetLevel(Terrain.ExtractData(cellValue3)) : level;
             int     num8       = (num4 == num) ? FluidBlock.GetLevel(Terrain.ExtractData(cellValue4)) : level;
             int     num9       = (num5 == num) ? FluidBlock.GetLevel(Terrain.ExtractData(cellValue5)) : level;
             Vector2 vector     = default(Vector2);
             vector.X = MathUtils.Sign(level - num6) - MathUtils.Sign(level - num7);
             vector.Y = MathUtils.Sign(level - num8) - MathUtils.Sign(level - num9);
             Vector2 v = vector;
             if (v.LengthSquared() > 1f)
             {
                 v = Vector2.Normalize(v);
             }
             if (!m_fluidRandomFlowDirections.TryGetValue(new Point3(x, y, z), out Vector2 value))
             {
                 value.X = 0.05f * (2f * SimplexNoise.OctavedNoise((float)x + 0.2f * (float)SubsystemTime.GameTime, z, 0.1f, 1, 1f, 1f) - 1f);
                 value.Y = 0.05f * (2f * SimplexNoise.OctavedNoise((float)x + 0.2f * (float)SubsystemTime.GameTime + 100f, z, 0.1f, 1, 1f, 1f) - 1f);
                 if (m_fluidRandomFlowDirections.Count < 1000)
                 {
                     m_fluidRandomFlowDirections[new Point3(x, y, z)] = value;
                 }
                 else
                 {
                     m_fluidRandomFlowDirections.Clear();
                 }
             }
             v += value;
             return(v * 2f);
         }
     }
     return(null);
 }
Example #3
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain   = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemTime      = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_componentCreature  = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentFishModel = base.Entity.FindComponent <ComponentFishModel>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsOutOfWater())
         {
             m_outOfWaterTime += m_subsystemTime.GameTimeDelta;
         }
         else
         {
             m_outOfWaterTime = 0f;
         }
         if (m_outOfWaterTime > 3f)
         {
             m_importanceLevel = 1000f;
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Jump");
         }
     }, null);
     m_stateMachine.AddState("Jump", null, delegate
     {
         m_componentFishModel.BendOrder = 2f * (2f * MathUtils.Saturate(SimplexNoise.OctavedNoise((float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0), 1.2f * m_componentCreature.ComponentLocomotion.TurnSpeed, 1, 1f, 1f)) - 1f);
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         if (!IsOutOfWater())
         {
             m_importanceLevel = 0f;
         }
         if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.33f, 1f);
             m_direction = new Vector2(MathUtils.Sign(m_componentFishModel.BendOrder.Value), 0f);
         }
         if (!m_componentCreature.ComponentBody.StandingOnValue.HasValue)
         {
             m_componentCreature.ComponentLocomotion.TurnOrder = new Vector2(0f - m_componentFishModel.BendOrder.Value, 0f);
             m_componentCreature.ComponentLocomotion.WalkOrder = m_direction;
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
        public float CalculateOceanShoreDistance(float x, float z)
        {
            float x2 = 0f;
            float x3 = 0f;
            float y  = 0f;
            float y2 = 0f;

            if (m_shoreRoughnessAmplitude.X > 0f)
            {
                x2 = m_shoreRoughnessAmplitude.X * SimplexNoise.OctavedNoise(z + m_shoreRoughnessOffset[0], m_shoreRoughnessFrequency.X, (int)m_shoreRoughnessOctaves.X, 2f, 0.6f);
                x3 = m_shoreRoughnessAmplitude.X * SimplexNoise.OctavedNoise(z + m_shoreRoughnessOffset[1], m_shoreRoughnessFrequency.X, (int)m_shoreRoughnessOctaves.X, 2f, 0.6f);
            }
            if (m_shoreRoughnessAmplitude.Y > 0f)
            {
                y  = m_shoreRoughnessAmplitude.Y * SimplexNoise.OctavedNoise(x + m_shoreRoughnessOffset[2], m_shoreRoughnessFrequency.Y, (int)m_shoreRoughnessOctaves.Y, 2f, 0.6f);
                y2 = m_shoreRoughnessAmplitude.Y * SimplexNoise.OctavedNoise(x + m_shoreRoughnessOffset[3], m_shoreRoughnessFrequency.Y, (int)m_shoreRoughnessOctaves.Y, 2f, 0.6f);
            }
            Vector2 vector  = m_oceanCorner + new Vector2(x2, y);
            Vector2 vector2 = m_oceanCorner + (m_islandSize.HasValue ? m_islandSize.Value : new Vector2(float.MaxValue)) + new Vector2(x3, y2);

            return(MathUtils.Min(x - vector.X, vector2.X - x, z - vector.Y, vector2.Y - z));
        }
Example #5
0
        public void DrawImage(DrawContext dc)
        {
            float num = (float)MathUtils.Remainder(Time.FrameStartTime + (double)m_timeOffset, 10000.0);
            float x   = 2f * SimplexNoise.OctavedNoise(num, 0.02f, 4, 2f, 0.5f) - 1f;
            float y   = 2f * SimplexNoise.OctavedNoise(num + 100f, 0.02f, 4, 2f, 0.5f) - 1f;

            m_position  += 0.03f * new Vector2(x, y) * MathUtils.Min(Time.FrameDuration, 0.1f);
            m_position.X = MathUtils.Remainder(m_position.X, 1f);
            m_position.Y = MathUtils.Remainder(m_position.Y, 1f);
            float           f               = 0.5f * MathUtils.PowSign(MathUtils.Sin(0.21f * num + 2f), 2f) + 0.5f;
            float           num2            = MathUtils.Lerp(0.13f, 0.3f, f);
            float           num3            = num2 / (float)Texture.Height * (float)Texture.Width / base.ActualSize.X * base.ActualSize.Y;
            float           x2              = m_position.X;
            float           y2              = m_position.Y;
            Vector2         zero            = Vector2.Zero;
            Vector2         actualSize      = base.ActualSize;
            Vector2         texCoord        = new Vector2(x2 - num2, y2 - num3);
            Vector2         texCoord2       = new Vector2(x2 + num2, y2 + num3);
            TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(Texture, useAlphaTest: false, 0, DepthStencilState.DepthWrite, null, BlendState.AlphaBlend, SamplerState.LinearWrap);
            int             count           = texturedBatch2D.TriangleVertices.Count;

            texturedBatch2D.QueueQuad(zero, actualSize, 1f, texCoord, texCoord2, base.GlobalColorTransform);
            texturedBatch2D.TransformTriangles(base.GlobalTransform, count);
        }
Example #6
0
        public override void Animate()
        {
            Vector3 position = m_componentCreature.ComponentBody.Position;
            Vector3 vector   = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();

            if (m_componentCreature.ComponentHealth.Health > 0f)
            {
                float num  = 0f;
                float num2 = 0f;
                float num3 = 0f;
                if (base.MovementAnimationPhase != 0f && (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.ImmersionFactor > 0f))
                {
                    float num4 = (Vector3.Dot(m_componentCreature.ComponentBody.Velocity, m_componentCreature.ComponentBody.Matrix.Forward) > 0.75f * m_componentCreature.ComponentLocomotion.WalkSpeed) ? (1.5f * m_walkLegsAngle) : m_walkLegsAngle;
                    float num5 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0f));
                    float num6 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.5f));
                    num  = num4 * num5 + m_kickPhase;
                    num2 = num4 * num6;
                    num3 = MathUtils.DegToRad(5f) * MathUtils.Sin((float)Math.PI * 4f * base.MovementAnimationPhase);
                }
                if (m_kickFactor != 0f)
                {
                    float x = MathUtils.DegToRad(60f) * MathUtils.Sin((float)Math.PI * MathUtils.Sigmoid(m_kickPhase, 5f));
                    num = MathUtils.Lerp(num, x, m_kickFactor);
                }
                float num7 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
                m_legAngle1  += num7 * (num - m_legAngle1);
                m_legAngle2  += num7 * (num2 - m_legAngle2);
                m_headAngleY += num7 * (num3 - m_headAngleY);
                Vector2 vector2 = m_componentCreature.ComponentLocomotion.LookAngles;
                vector2.Y += m_headAngleY;
                if (m_feedFactor > 0f)
                {
                    float y = 0f - MathUtils.DegToRad(35f + 55f * SimplexNoise.OctavedNoise((float)m_subsystemTime.GameTime, 3f, 2, 2f, 0.75f));
                    vector2 = Vector2.Lerp(v2: new Vector2(0f, y), v1: vector2, f: m_feedFactor);
                }
                vector2.X = MathUtils.Clamp(vector2.X, 0f - MathUtils.DegToRad(90f), MathUtils.DegToRad(90f));
                vector2.Y = MathUtils.Clamp(vector2.Y, 0f - MathUtils.DegToRad(90f), MathUtils.DegToRad(50f));
                Vector2 vector3 = Vector2.Zero;
                if (m_neckBone != null)
                {
                    vector3 = 0.4f * vector2;
                    vector2 = 0.6f * vector2;
                }
                SetBoneTransform(m_bodyBone.Index, Matrix.CreateRotationY(vector.X) * Matrix.CreateTranslation(position.X, position.Y + base.Bob, position.Z));
                SetBoneTransform(m_headBone.Index, Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationZ(0f - vector2.X));
                if (m_neckBone != null)
                {
                    SetBoneTransform(m_neckBone.Index, Matrix.CreateRotationX(vector3.Y) * Matrix.CreateRotationZ(0f - vector3.X));
                }
                SetBoneTransform(m_leg1Bone.Index, Matrix.CreateRotationX(m_legAngle1));
                SetBoneTransform(m_leg2Bone.Index, Matrix.CreateRotationX(m_legAngle2));
            }
            else
            {
                float num8  = 1f - base.DeathPhase;
                float num9  = (Vector3.Dot(m_componentFrame.Matrix.Right, base.DeathCauseOffset) > 0f) ? 1 : (-1);
                float num10 = m_componentCreature.ComponentBody.BoundingBox.Max.Y - m_componentCreature.ComponentBody.BoundingBox.Min.Y;
                SetBoneTransform(m_bodyBone.Index, Matrix.CreateTranslation(-0.5f * num10 * base.DeathPhase * Vector3.UnitY) * Matrix.CreateFromYawPitchRoll(vector.X, 0f, (float)Math.PI / 2f * base.DeathPhase * num9) * Matrix.CreateTranslation(0.2f * num10 * base.DeathPhase * Vector3.UnitY) * Matrix.CreateTranslation(position));
                SetBoneTransform(m_headBone.Index, Matrix.Identity);
                if (m_neckBone != null)
                {
                    SetBoneTransform(m_neckBone.Index, Matrix.Identity);
                }
                SetBoneTransform(m_leg1Bone.Index, Matrix.CreateRotationX(m_legAngle1 * num8));
                SetBoneTransform(m_leg2Bone.Index, Matrix.CreateRotationX(m_legAngle2 * num8));
            }
            base.Animate();
        }
Example #7
0
 public override void MeasureOverride(Vector2 parentAvailableSize)
 {
     if (OuterClothing)
     {
         m_modelWidget.Model = CharacterSkinsManager.GetOuterClothingModel(PlayerClass);
     }
     else
     {
         m_modelWidget.Model = CharacterSkinsManager.GetPlayerModel(PlayerClass);
     }
     if (CameraShot == Shot.Body)
     {
         m_modelWidget.ViewPosition = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.46f, -3.2f) : new Vector3(0f, 1.39f, -3.04f));
         m_modelWidget.ViewTarget   = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 0.9f, 0f) : new Vector3(0f, 0.86f, 0f));
         m_modelWidget.ViewFov      = 0.57f;
     }
     else
     {
         if (CameraShot != Shot.Bust)
         {
             throw new InvalidOperationException("Unknown shot.");
         }
         m_modelWidget.ViewPosition = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.5f, -1.05f) : new Vector3(0f, 1.43f, -1f));
         m_modelWidget.ViewTarget   = ((PlayerClass == PlayerClass.Male) ? new Vector3(0f, 1.5f, 0f) : new Vector3(0f, 1.43f, 0f));
         m_modelWidget.ViewFov      = 0.57f;
     }
     if (OuterClothing)
     {
         m_modelWidget.TextureOverride = OuterClothingTexture;
     }
     else
     {
         m_modelWidget.TextureOverride = ((CharacterSkinName != null) ? CharacterSkinsCache.GetTexture(CharacterSkinName) : CharacterSkinTexture);
     }
     if (AnimateHeadSeed != 0)
     {
         int     num    = (AnimateHeadSeed < 0) ? GetHashCode() : AnimateHeadSeed;
         float   num2   = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * (double)num, 10000.0);
         Vector2 vector = default(Vector2);
         vector.X = MathUtils.Lerp(-0.75f, 0.75f, SimplexNoise.OctavedNoise(num2 + 100f, 0.2f, 1, 2f, 0.5f));
         vector.Y = MathUtils.Lerp(-0.5f, 0.5f, SimplexNoise.OctavedNoise(num2 + 200f, 0.17f, 1, 2f, 0.5f));
         Matrix value = Matrix.CreateRotationX(vector.Y) * Matrix.CreateRotationZ(vector.X);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Head").Index, value);
     }
     if (!OuterClothing && AnimateHandsSeed != 0)
     {
         int     num3    = (AnimateHandsSeed < 0) ? GetHashCode() : AnimateHandsSeed;
         float   num4    = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * (double)num3, 10000.0);
         Vector2 vector2 = default(Vector2);
         vector2.X = MathUtils.Lerp(0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 100f, 0.7f, 1, 2f, 0.5f));
         vector2.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 200f, 0.7f, 1, 2f, 0.5f));
         Vector2 vector3 = default(Vector2);
         vector3.X = MathUtils.Lerp(-0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 300f, 0.7f, 1, 2f, 0.5f));
         vector3.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 400f, 0.7f, 1, 2f, 0.5f));
         Matrix value2 = Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationY(vector2.X);
         Matrix value3 = Matrix.CreateRotationX(vector3.Y) * Matrix.CreateRotationY(vector3.X);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Hand1").Index, value2);
         m_modelWidget.SetBoneTransform(m_modelWidget.Model.FindBone("Hand2").Index, value3);
     }
     base.MeasureOverride(parentAvailableSize);
 }
        public override bool OnAim(Vector3 start, Vector3 direction, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    int num2      = slotValue;
                    int num3      = 0;
                    if (num == Musket2Block.Index && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num4 = (float)(m_subsystemTime.GameTime - value);
                        float   num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = (float)((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.00999999977648258 : 0.0299999993294477) + 0.200000002980232 * MathUtils.Saturate((num4 - 6.5f) / 40f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        direction = Vector3.Normalize(direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num4 >= 30f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            if (num4 > 0.2f && !Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), true));
                                m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                ComponentPlayer componentPlayer2 = componentMiner.ComponentPlayer;
                                if (componentPlayer2 != null)
                                {
                                    componentPlayer2.ComponentGui.ShowAimingSights(start, direction);
                                }
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.21f, 0.15f, 0.08f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.4f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.08f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), false));
                                m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            bool    flag   = false;
                            int     value2 = 0;
                            int     num6   = 0;
                            float   s      = 0f;
                            Vector3 vector = Vector3.Zero;
                            Musket2Block.LoadState loadState = Musket2Block.GetLoadState(data);
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                switch (loadState)
                                {
                                case Musket2Block.LoadState.Gunpowder:
                                    flag   = true;
                                    value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.IronBullet));
                                    s      = 320f;
                                    num6   = 1;
                                    vector = new Vector3(0.01f, 0.01f, 0.05f);
                                    goto default;

                                default:
                                    if (loadState == Musket2Block.LoadState.Wad)
                                    {
                                        flag   = true;
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.IronBullet));
                                        s      = 320f;
                                        num6   = 1;
                                        vector = new Vector3(0.01f, 0.01f, 0.05f);
                                    }
                                    break;

                                case Musket2Block.LoadState.Empty:
                                {
                                    ComponentPlayer componentPlayer = componentMiner.ComponentPlayer;
                                    if (componentPlayer != null)
                                    {
                                        componentPlayer.ComponentGui.DisplaySmallMessage("Load bullet first", true, false);
                                    }
                                    break;
                                }
                                }
                            }
                            if (flag)
                            {
                                if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f)
                                {
                                    m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.UniformFloat(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, true);
                                }
                                else
                                {
                                    Vector3 eyePosition = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition;
                                    Matrix  matrix      = componentMiner.ComponentCreature.ComponentBody.Matrix;
                                    Vector3 v2          = eyePosition + matrix.Right * 0.3f;
                                    matrix = componentMiner.ComponentCreature.ComponentBody.Matrix;
                                    Vector3 vector2 = v2 - matrix.Up * 0.2f;
                                    var     vector3 = Vector3.Normalize(vector2 + direction * 10f - vector2);
                                    var     vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
                                    var     v3      = Vector3.Normalize(Vector3.Cross(vector3, vector4));
                                    for (int i = 0; i < num6; i++)
                                    {
                                        Vector3    v4         = m_random.UniformFloat(0f - vector.X, vector.X) * vector4 + m_random.UniformFloat(0f - vector.Y, vector.Y) * v3 + m_random.UniformFloat(0f - vector.Z, vector.Z) * vector3;
                                        Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v4), Vector3.Zero, componentMiner.ComponentCreature);
                                        if (projectile != null)
                                        {
                                            projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
                                        }
                                    }
                                    m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.UniformFloat(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, true);
                                    m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(SubsystemTerrain, vector2 + 0.3f * vector3, vector3));
                                    m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
                                    componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-1f * vector3);
                                }
                                if (loadState == Musket2Block.LoadState.Gunpowder)
                                {
                                    num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetLoadState(Terrain.ExtractData(num2), Musket2Block.LoadState.Empty));
                                }
                                if (loadState == Musket2Block.LoadState.Wad)
                                {
                                    num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetLoadState(Terrain.ExtractData(num2), Musket2Block.LoadState.Gunpowder));
                                }
                                num3 = 1;
                            }
                            if (Musket2Block.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, Musket2Block.SetHammerState(Terrain.ExtractData(num2), false));
                                m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.UniformFloat(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                    if (num2 != slotValue)
                    {
                        inventory.RemoveSlotItems(activeSlotIndex, 1);
                        inventory.AddSlotItems(activeSlotIndex, num2, 1);
                    }
                    if (num3 > 0)
                    {
                        componentMiner.DamageActiveTool(num3);
                    }
                }
            }
            return(false);
        }
Example #9
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    if (num == 191 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num2 = (float)(m_subsystemTime.GameTime - value);
                        float   num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.02f : 0.04f) + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num2 >= 9f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.1f, 0.15f, 0f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.2f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(0f, 0f, 0f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f);
                            if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0))
                            {
                                int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15);
                                inventory.RemoveSlotItems(activeSlotIndex, 1);
                                inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1);
                            }
                            break;
                        }

                        case AimState.Cancelled:
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1);
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            int draw = BowBlock.GetDraw(data);
                            ArrowBlock.ArrowType?arrowType = BowBlock.GetArrowType(data);
                            if (arrowType.HasValue)
                            {
                                Vector3 vector  = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                float   num4    = MathUtils.Lerp(0f, 28f, MathUtils.Pow((float)draw / 15f, 0.75f));
                                if (componentMiner.ComponentPlayer != null)
                                {
                                    num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f;
                                }
                                Vector3 vector3 = Vector3.Zero;
                                if (arrowType == ArrowBlock.ArrowType.WoodenArrow)
                                {
                                    vector3 = new Vector3(0.025f, 0.025f, 0.025f);
                                }
                                if (arrowType == ArrowBlock.ArrowType.StoneArrow)
                                {
                                    vector3 = new Vector3(0.01f, 0.01f, 0.01f);
                                }
                                int     value2  = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY));
                                Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector2, vector4));
                                Vector3 v3      = m_random.Float(0f - vector3.X, vector3.X) * vector4 + m_random.Float(0f - vector3.Y, vector3.Y) * v2 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, (vector2 + v3) * num4, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = BowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, autoDelay: true);
                                }
                            }
                            else
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load an arrow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            int damageCount = 0;
                            if (draw >= 15)
                            {
                                damageCount = 2;
                            }
                            else if (draw >= 4)
                            {
                                damageCount = 1;
                            }
                            componentMiner.DamageActiveTool(damageCount);
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }
        public override void Animate()
        {
            Vector3 position = m_componentCreature.ComponentBody.Position;
            Vector3 vector   = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();

            if (m_componentCreature.ComponentHealth.Health > 0f)
            {
                float num  = 0f;
                float num2 = 0f;
                float num3 = 0f;
                float num4 = 0f;
                float num5 = 0f;
                if (base.MovementAnimationPhase != 0f && (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.ImmersionFactor > 0f))
                {
                    if (m_gait == Gait.Canter)
                    {
                        float num6 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0f));
                        float num7 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.25f));
                        float num8 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.15f));
                        float num9 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.4f));
                        num  = m_walkFrontLegsAngle * m_canterLegsAngleFactor * num6;
                        num2 = m_walkFrontLegsAngle * m_canterLegsAngleFactor * num7;
                        num3 = m_walkHindLegsAngle * m_canterLegsAngleFactor * num8;
                        num4 = m_walkHindLegsAngle * m_canterLegsAngleFactor * num9;
                        num5 = MathUtils.DegToRad(8f) * MathUtils.Sin((float)Math.PI * 2f * base.MovementAnimationPhase);
                    }
                    else if (m_gait == Gait.Trot)
                    {
                        float num10 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0f));
                        float num11 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.5f));
                        float num12 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.5f));
                        float num13 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0f));
                        num  = m_walkFrontLegsAngle * num10;
                        num2 = m_walkFrontLegsAngle * num11;
                        num3 = m_walkHindLegsAngle * num12;
                        num4 = m_walkHindLegsAngle * num13;
                        num5 = MathUtils.DegToRad(3f) * MathUtils.Sin((float)Math.PI * 4f * base.MovementAnimationPhase);
                    }
                    else
                    {
                        float num14 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0f));
                        float num15 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.5f));
                        float num16 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.25f));
                        float num17 = MathUtils.Sin((float)Math.PI * 2f * (base.MovementAnimationPhase + 0.75f));
                        num  = m_walkFrontLegsAngle * num14;
                        num2 = m_walkFrontLegsAngle * num15;
                        num3 = m_walkHindLegsAngle * num16;
                        num4 = m_walkHindLegsAngle * num17;
                        num5 = MathUtils.DegToRad(3f) * MathUtils.Sin((float)Math.PI * 4f * base.MovementAnimationPhase);
                    }
                }
                float num18 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
                m_legAngle1  += num18 * (num - m_legAngle1);
                m_legAngle2  += num18 * (num2 - m_legAngle2);
                m_legAngle3  += num18 * (num3 - m_legAngle3);
                m_legAngle4  += num18 * (num4 - m_legAngle4);
                m_headAngleY += num18 * (num5 - m_headAngleY);
                Vector2 vector2 = m_componentCreature.ComponentLocomotion.LookAngles;
                vector2.Y += m_headAngleY;
                vector2.X  = MathUtils.Clamp(vector2.X, 0f - MathUtils.DegToRad(65f), MathUtils.DegToRad(65f));
                vector2.Y  = MathUtils.Clamp(vector2.Y, 0f - MathUtils.DegToRad(55f), MathUtils.DegToRad(55f));
                Vector2 vector3 = Vector2.Zero;
                if (m_neckBone != null)
                {
                    vector3 = 0.6f * vector2;
                    vector2 = 0.4f * vector2;
                }
                if (m_feedFactor > 0f)
                {
                    float y = 0f - MathUtils.DegToRad(25f + 45f * SimplexNoise.OctavedNoise((float)m_subsystemTime.GameTime, 3f, 2, 2f, 0.75f));
                    vector2 = Vector2.Lerp(v2: new Vector2(0f, y), v1: vector2, f: m_feedFactor);
                    if (m_moveLegWhenFeeding)
                    {
                        float x = MathUtils.DegToRad(20f) + MathUtils.PowSign(SimplexNoise.OctavedNoise((float)m_subsystemTime.GameTime, 1f, 1, 1f, 1f) - 0.5f, 0.33f) / 0.5f * MathUtils.DegToRad(25f) * (float)MathUtils.Sin(17.0 * m_subsystemTime.GameTime);
                        num2 = MathUtils.Lerp(num2, x, m_feedFactor);
                    }
                }
                if (m_buttFactor != 0f)
                {
                    float y2 = (0f - MathUtils.DegToRad(40f)) * MathUtils.Sin((float)Math.PI * 2f * MathUtils.Sigmoid(m_buttPhase, 4f));
                    vector2 = Vector2.Lerp(v2: new Vector2(0f, y2), v1: vector2, f: m_buttFactor);
                }
                SetBoneTransform(m_bodyBone.Index, Matrix.CreateRotationY(vector.X) * Matrix.CreateTranslation(position.X, position.Y + base.Bob, position.Z));
                SetBoneTransform(m_headBone.Index, Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationZ(0f - vector2.X));
                if (m_neckBone != null)
                {
                    SetBoneTransform(m_neckBone.Index, Matrix.CreateRotationX(vector3.Y) * Matrix.CreateRotationZ(0f - vector3.X));
                }
                SetBoneTransform(m_leg1Bone.Index, Matrix.CreateRotationX(m_legAngle1));
                SetBoneTransform(m_leg2Bone.Index, Matrix.CreateRotationX(m_legAngle2));
                SetBoneTransform(m_leg3Bone.Index, Matrix.CreateRotationX(m_legAngle3));
                SetBoneTransform(m_leg4Bone.Index, Matrix.CreateRotationX(m_legAngle4));
            }
            else
            {
                float num19 = 1f - base.DeathPhase;
                float num20 = (Vector3.Dot(m_componentFrame.Matrix.Right, base.DeathCauseOffset) > 0f) ? 1 : (-1);
                float num21 = m_componentCreature.ComponentBody.BoundingBox.Max.Y - m_componentCreature.ComponentBody.BoundingBox.Min.Y;
                SetBoneTransform(m_bodyBone.Index, Matrix.CreateTranslation(-0.5f * num21 * Vector3.UnitY * base.DeathPhase) * Matrix.CreateFromYawPitchRoll(vector.X, 0f, (float)Math.PI / 2f * base.DeathPhase * num20) * Matrix.CreateTranslation(0.2f * num21 * Vector3.UnitY * base.DeathPhase) * Matrix.CreateTranslation(position));
                SetBoneTransform(m_headBone.Index, Matrix.CreateRotationX(MathUtils.DegToRad(50f) * base.DeathPhase));
                if (m_neckBone != null)
                {
                    SetBoneTransform(m_neckBone.Index, Matrix.Identity);
                }
                SetBoneTransform(m_leg1Bone.Index, Matrix.CreateRotationX(m_legAngle1 * num19));
                SetBoneTransform(m_leg2Bone.Index, Matrix.CreateRotationX(m_legAngle2 * num19));
                SetBoneTransform(m_leg3Bone.Index, Matrix.CreateRotationX(m_legAngle3 * num19));
                SetBoneTransform(m_leg4Bone.Index, Matrix.CreateRotationX(m_legAngle4 * num19));
            }
            base.Animate();
        }
Example #11
0
        public override void OnChunkInitialized(TerrainChunk chunk)
        {
            if (!(Utils.SubsystemTerrain.TerrainContentsGenerator is TerrainContentsGenerator generator) || chunk.IsLoaded)
            {
                return;
            }
            int x = chunk.Coords.X - 1;
            int y = chunk.Coords.Y - 1;
            const int
                f1 = 0x63721054,
                f2 = 0x04317562,
                f3 = 0x52473601,
                f4 = 0x61234057,
                f5 = 0x07142563,
                f6 = 0x53721604,
                f7 = 0x64317052,
                f8 = 0x02473561,
                f9 = 0x51234607,
                fa = 0x67142053,
                fb = 0x03721564,
                fc = 0x54317602,
                fd = 0x62473051,
                fe = 0x01234567,
                ff = 0x57142603;
            Random random;

            for (int i = x; i < x + 2; i++)
            {
                int k, ix16 = i << 4;
                for (int j = y; j < y + 2; j++)
                {
                    random = new Random(generator.m_seed + i + (f1 ^ f4 ^ f5 ^ f7 ^ fa ^ fc ^ fd) * j);
                    int       jx16 = j << 4;
                    float     num2 = generator.CalculateMountainRangeFactor(ix16, jx16);
                    const int index = BasaltBlock.Index, index2 = BasaltBlock.Index;
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i ^ fe, j ^ ff, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 30), jx16 | (random.Int() & 15), index2 | (int)BrushType.Au << 15);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + 713, j + f3, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 30), jx16 | (random.Int() & 15), index2 | (int)BrushType.Ag << 15);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f2, j + 396, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(PtBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 15), jx16 | (random.Int() & 15), index2 | (int)BrushType.Pt << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f6, j + 131, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Pb << 15);
                    }
                    for (k = (int)(0.5f + 2f * num2 * SimplexNoise.OctavedNoise(i + 432, j + f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 15), jx16 | (random.Int() & 15), index | (int)BrushType.Hg << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + 711, j + fb, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 40), jx16 | (random.Int() & 15), index | (int)BrushType.Sn << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f8, j + 272, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Ti << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + fa, j + fc, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Cr << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f3, j + f6, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Ni << 15);
                    }
                    for (k = 20 + (int)(8f * num2 * SimplexNoise.OctavedNoise(i + fa ^ f5 + f1, j + fc - f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintMaskSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | 65536 << 14);
                    }
                    for (k = 9 + (int)(8f * num2 * SimplexNoise.OctavedNoise(i + f5 ^ f8 + f1, j + f9 - fc, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintMaskSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | 32768 << 14);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + fc, j + f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 20), jx16 | (random.Int() & 15), index2 | (int)BrushType.U << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f3, j + f1, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(45, 70), jx16 | (random.Int() & 15), 3 | (int)BrushType.P << 15);
                    }
                    if (generator.CalculateOceanShoreDistance(ix16, y << 4) < -90f)
                    {
                        int n = TerrainChunk.CalculateCellIndex(random.Int() & 15, 35, random.Int() & 15);
                        for (k = 0; k < 45; k++)
                        {
                            if (Terrain.ExtractContents(chunk.GetCellValueFast(n + k)) == WaterBlock.Index && BlocksManager.Blocks[Terrain.ExtractContents(chunk.GetCellValueFast(n + k - 1))].IsCollidable)
                            {
                                chunk.SetCellValueFast(n + k, IceBlock.Index | 32 << 14);
                                break;
                            }
                        }
                    }
                }
                random = new Random(generator.m_seed ^ (x << 16 | y));
                if ((random.Int() & 1) != 0)
                {
                    chunk.PaintSelective(OilPocketCells[random.Int() & 15], x << 16 | (random.Int() & 15), random.UniformInt(40, 70), y << 16 | (random.Int() & 15), 3);
                }
            }
        }
Example #12
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    int num2      = slotValue;
                    int num3      = 0;
                    if (num == 212 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num4 = (float)(m_subsystemTime.GameTime - value);
                        float   num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.2f * MathUtils.Saturate((num4 - 2.5f) / 6f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num4 >= 10f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            if (num4 > 0.5f && !MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: true));
                                m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.21f, 0.15f, 0.08f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.4f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.08f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            bool    flag   = false;
                            int     value2 = 0;
                            int     num6   = 0;
                            float   s      = 0f;
                            Vector3 vector = Vector3.Zero;
                            MusketBlock.LoadState  loadState  = MusketBlock.GetLoadState(data);
                            BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data);
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                switch (loadState)
                                {
                                case MusketBlock.LoadState.Empty:
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load gunpowder first", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Gunpowder:
                                case MusketBlock.LoadState.Wad:
                                    flag = true;
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No bullet, blind shot fired", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Loaded:
                                    flag = true;
                                    if (bulletType == BulletBlock.BulletType.Buckshot)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 8;
                                        vector = new Vector3(0.04f, 0.04f, 0.25f);
                                        s      = 80f;
                                    }
                                    else if (bulletType == BulletBlock.BulletType.BuckshotBall)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 1;
                                        vector = new Vector3(0.06f, 0.06f, 0f);
                                        s      = 60f;
                                    }
                                    else if (bulletType.HasValue)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, bulletType.Value));
                                        num6   = 1;
                                        s      = 120f;
                                    }
                                    break;
                                }
                            }
                            if (flag)
                            {
                                if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f)
                                {
                                    m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, autoDelay: true);
                                }
                                else
                                {
                                    Vector3 vector2 = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                    Vector3 vector3 = Vector3.Normalize(vector2 + aim.Direction * 10f - vector2);
                                    Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
                                    Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector3, vector4));
                                    for (int i = 0; i < num6; i++)
                                    {
                                        Vector3    v3         = m_random.Float(0f - vector.X, vector.X) * vector4 + m_random.Float(0f - vector.Y, vector.Y) * v2 + m_random.Float(0f - vector.Z, vector.Z) * vector3;
                                        Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v3), Vector3.Zero, componentMiner.ComponentCreature);
                                        if (projectile != null)
                                        {
                                            projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
                                        }
                                    }
                                    m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, autoDelay: true);
                                    m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(m_subsystemTerrain, vector2 + 0.3f * vector3, vector3));
                                    m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
                                    componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-4f * vector3);
                                }
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetLoadState(Terrain.ExtractData(num2), MusketBlock.LoadState.Empty));
                                num3 = 1;
                            }
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                    if (num2 != slotValue)
                    {
                        inventory.RemoveSlotItems(activeSlotIndex, 1);
                        inventory.AddSlotItems(activeSlotIndex, num2, 1);
                    }
                    if (num3 > 0)
                    {
                        componentMiner.DamageActiveTool(num3);
                    }
                }
            }
            return(false);
        }
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    if (num == 200 && slotCount > 0)
                    {
                        int draw = CrossbowBlock.GetDraw(data);
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num2 = (float)(m_subsystemTime.GameTime - value);
                        float   num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.15f * MathUtils.Saturate((num2 - 2.5f) / 6f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num2 >= 10f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.22f, 0.15f, 0.1f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.3f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.1f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.55f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            ArrowBlock.ArrowType?arrowType = CrossbowBlock.GetArrowType(data);
                            if (draw != 15)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Draw the crossbow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else if (!arrowType.HasValue)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load a bolt first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else
                            {
                                Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 v2     = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                int     value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                float   s      = 38f;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, s * v2, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = CrossbowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0.05f);
                                }
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, CrossbowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            if (draw > 0)
                            {
                                componentMiner.DamageActiveTool(1);
                                m_subsystemAudio.PlaySound("Audio/CrossbowBoing", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }