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);
        }
Example #2
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);
        }
        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 #4
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);
        }
Example #5
0
        public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner)
        {
            FurnitureDesign          design           = null;
            FurnitureDesign          furnitureDesign  = null;
            Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>();
            Point3 point      = start.Point;
            Point3 point2     = start.Point;
            int    startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z);
            int    num        = Terrain.ExtractContents(startValue);

            if (BlocksManager.Blocks[num] is FurnitureBlock)
            {
                int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue));
                furnitureDesign = GetDesign(designIndex);
                if (furnitureDesign == null)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = furnitureDesign.Clone();
                design.LinkedDesign    = null;
                design.InteractionMode = FurnitureInteractionMode.None;
                valuesDictionary.Add(start.Point, startValue);
            }
            else
            {
                Stack <Point3> val = new Stack <Point3>();
                val.Push(start.Point);
                while (val.Count > 0)
                {
                    Point3 key = val.Pop();
                    if (valuesDictionary.ContainsKey(key))
                    {
                        continue;
                    }
                    int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z);
                    if (IsValueDisallowed(cellValue))
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                        return;
                    }
                    if (IsValueAllowed(cellValue))
                    {
                        if (key.X < point.X)
                        {
                            point.X = key.X;
                        }
                        if (key.Y < point.Y)
                        {
                            point.Y = key.Y;
                        }
                        if (key.Z < point.Z)
                        {
                            point.Z = key.Z;
                        }
                        if (key.X > point2.X)
                        {
                            point2.X = key.X;
                        }
                        if (key.Y > point2.Y)
                        {
                            point2.Y = key.Y;
                        }
                        if (key.Z > point2.Z)
                        {
                            point2.Z = key.Z;
                        }
                        if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16)
                        {
                            componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false);
                            return;
                        }
                        valuesDictionary[key] = cellValue;
                        val.Push(new Point3(key.X - 1, key.Y, key.Z));
                        val.Push(new Point3(key.X + 1, key.Y, key.Z));
                        val.Push(new Point3(key.X, key.Y - 1, key.Z));
                        val.Push(new Point3(key.X, key.Y + 1, key.Z));
                        val.Push(new Point3(key.X, key.Y, key.Z - 1));
                        val.Push(new Point3(key.X, key.Y, key.Z + 1));
                    }
                }
                if (valuesDictionary.Count == 0)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = new FurnitureDesign(base.SubsystemTerrain);
                Point3 point3 = point2 - point;
                int    num2   = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2);
                int[]  array  = new int[num2 * num2 * num2];
                foreach (KeyValuePair <Point3, int> item in valuesDictionary)
                {
                    Point3 point4 = item.Key - point;
                    array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value;
                }
                design.SetValues(num2, array);
                int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face);
                design.Rotate(1, steps);
                Point3 location = design.Box.Location;
                Point3 point5   = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size);
                Point3 delta    = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2);
                design.Shift(delta);
            }
            BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result)
            {
                if (result)
                {
                    design = TryAddDesign(design);
                    if (design == null)
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false);
                    }
                    else
                    {
                        if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                        {
                            foreach (KeyValuePair <Point3, int> item2 in valuesDictionary)
                            {
                                base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true);
                            }
                        }
                        int value        = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter));
                        int num3         = MathUtils.Clamp(design.Resolution, 4, 8);
                        Matrix matrix    = componentMiner.ComponentCreature.ComponentBody.Matrix;
                        Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY;
                        m_subsystemPickables.AddPickable(value, num3, position, null, null);
                        componentMiner.DamageActiveTool(1);
                        componentMiner.Poke(forceRestart: false);
                        for (int i = 0; i < 3; i++)
                        {
                            Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f);
                            });
                        }
                        if (componentMiner.ComponentCreature.PlayerStats != null)
                        {
                            componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3;
                        }
                    }
                }
            });

            if (componentMiner.ComponentPlayer != null)
            {
                DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog);
            }
        }
        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 #7
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);
        }