Example #1
0
        public void SetDraw(int draw)
        {
            int data  = Terrain.ExtractData(m_inventory.GetSlotValue(m_slotIndex));
            int value = Terrain.MakeBlockValue(200, 0, CrossbowBlock.SetDraw(data, draw));

            m_inventory.RemoveSlotItems(m_slotIndex, 1);
            m_inventory.AddSlotItems(m_slotIndex, value, 1);
        }
 public override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
 {
     if (processCount == 1)
     {
         ArrowBlock.ArrowType arrowType = ArrowBlock.GetArrowType(Terrain.ExtractData(value));
         int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
         processedValue = 0;
         processedCount = 0;
         inventory.RemoveSlotItems(slotIndex, 1);
         inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(200, 0, CrossbowBlock.SetArrowType(data, arrowType)), 1);
     }
     else
     {
         processedValue = value;
         processedCount = count;
     }
 }
        public override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value)
        {
            int num = Terrain.ExtractContents(value);

            ArrowBlock.ArrowType arrowType = ArrowBlock.GetArrowType(Terrain.ExtractData(value));
            if (num == 192 && m_supportedArrowTypes.Contains(arrowType))
            {
                int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
                ArrowBlock.ArrowType?arrowType2 = CrossbowBlock.GetArrowType(data);
                int draw = CrossbowBlock.GetDraw(data);
                if (!arrowType2.HasValue && draw == 15)
                {
                    return(1);
                }
                return(0);
            }
            return(0);
        }
Example #4
0
        public override void Update()
        {
            int slotValue = m_inventory.GetSlotValue(m_slotIndex);
            int slotCount = m_inventory.GetSlotCount(m_slotIndex);
            int num       = Terrain.ExtractContents(slotValue);
            int data      = Terrain.ExtractData(slotValue);
            int draw      = CrossbowBlock.GetDraw(data);

            ArrowBlock.ArrowType?arrowType = CrossbowBlock.GetArrowType(data);
            if (num == 200 && slotCount > 0)
            {
                if (draw < 15)
                {
                    m_instructionsLabel.Text = "Pull";
                }
                else if (!arrowType.HasValue)
                {
                    m_instructionsLabel.Text = "Load bolt";
                }
                else
                {
                    m_instructionsLabel.Text = "Ready to fire";
                }
                if ((draw < 15 || !arrowType.HasValue) && base.Input.Tap.HasValue && HitTestGlobal(base.Input.Tap.Value) == m_inventorySlotWidget)
                {
                    Vector2 vector = m_inventorySlotWidget.ScreenToWidget(base.Input.Press.Value);
                    float   num2   = vector.Y - DrawToPosition(draw);
                    if (MathUtils.Abs(vector.X - m_inventorySlotWidget.ActualSize.X / 2f) < 25f && MathUtils.Abs(num2) < 25f)
                    {
                        m_dragStartOffset = num2;
                    }
                }
                if (!m_dragStartOffset.HasValue)
                {
                    return;
                }
                if (base.Input.Press.HasValue)
                {
                    int num3 = PositionToDraw(m_inventorySlotWidget.ScreenToWidget(base.Input.Press.Value).Y - m_dragStartOffset.Value);
                    SetDraw(num3);
                    if (draw <= 9 && num3 > 9)
                    {
                        AudioManager.PlaySound("Audio/CrossbowDraw", 1f, m_random.Float(-0.2f, 0.2f), 0f);
                    }
                }
                else
                {
                    m_dragStartOffset = null;
                    if (draw == 15)
                    {
                        AudioManager.PlaySound("Audio/UI/ItemMoved", 1f, 0f, 0f);
                        return;
                    }
                    SetDraw(0);
                    AudioManager.PlaySound("Audio/CrossbowBoing", MathUtils.Saturate((float)(draw - 3) / 10f), m_random.Float(-0.1f, 0.1f), 0f);
                }
            }
            else
            {
                base.ParentWidget.Children.Remove(this);
            }
        }
        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);
        }