Esempio n. 1
0
        public override void Update()
        {
            int value = m_subsystemTerrain.Terrain.GetCellValue(m_componentBlockEntity.Coordinates.X, m_componentBlockEntity.Coordinates.Y, m_componentBlockEntity.Coordinates.Z);
            int data  = Terrain.ExtractData(value);

            if (m_dispenseButton.IsClicked)
            {
                data  = DispenserBlock.SetMode(data, DispenserBlock.Mode.Dispense);
                value = Terrain.ReplaceData(value, data);
                m_subsystemTerrain.ChangeCell(m_componentBlockEntity.Coordinates.X, m_componentBlockEntity.Coordinates.Y, m_componentBlockEntity.Coordinates.Z, value);
            }
            if (m_shootButton.IsClicked)
            {
                data  = DispenserBlock.SetMode(data, DispenserBlock.Mode.Shoot);
                value = Terrain.ReplaceData(value, data);
                m_subsystemTerrain.ChangeCell(m_componentBlockEntity.Coordinates.X, m_componentBlockEntity.Coordinates.Y, m_componentBlockEntity.Coordinates.Z, value);
            }
            if (m_acceptsDropsBox.IsClicked)
            {
                data  = DispenserBlock.SetAcceptsDrops(data, !DispenserBlock.GetAcceptsDrops(data));
                value = Terrain.ReplaceData(value, data);
                m_subsystemTerrain.ChangeCell(m_componentBlockEntity.Coordinates.X, m_componentBlockEntity.Coordinates.Y, m_componentBlockEntity.Coordinates.Z, value);
            }
            DispenserBlock.Mode mode = DispenserBlock.GetMode(data);
            m_dispenseButton.IsChecked  = (mode == DispenserBlock.Mode.Dispense);
            m_shootButton.IsChecked     = (mode == DispenserBlock.Mode.Shoot);
            m_acceptsDropsBox.IsChecked = DispenserBlock.GetAcceptsDrops(data);
            if (!m_componentDispenser.IsAddedToProject)
            {
                base.ParentWidget.Children.Remove(this);
            }
        }
        public void Dispense()
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;
            int    data        = Terrain.ExtractData(m_subsystemTerrain.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z));
            int    direction   = DispenserBlock.GetDirection(data);

            DispenserBlock.Mode mode = DispenserBlock.GetMode(data);
            int num = 0;
            int slotValue;

            while (true)
            {
                if (num < SlotsCount)
                {
                    slotValue = GetSlotValue(num);
                    int slotCount = GetSlotCount(num);
                    if (slotValue != 0 && slotCount > 0)
                    {
                        break;
                    }
                    num++;
                    continue;
                }
                return;
            }
            int num2 = RemoveSlotItems(num, 1);

            for (int i = 0; i < num2; i++)
            {
                DispenseItem(coordinates, direction, slotValue, mode);
            }
        }
Esempio n. 3
0
        public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
        {
            if (worldItem.ToRemove)
            {
                return;
            }
            ComponentBlockEntity blockEntity = m_subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z);

            if (blockEntity != null && DispenserBlock.GetAcceptsDrops(Terrain.ExtractData(m_subsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z))))
            {
                ComponentDispenser inventory = blockEntity.Entity.FindComponent <ComponentDispenser>(throwOnError: true);
                Pickable           pickable  = worldItem as Pickable;
                int num  = pickable?.Count ?? 1;
                int num2 = ComponentInventoryBase.AcquireItems(inventory, worldItem.Value, num);
                if (num2 < num)
                {
                    m_subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true);
                }
                if (num2 <= 0)
                {
                    worldItem.ToRemove = true;
                }
                else if (pickable != null)
                {
                    pickable.Count = num2;
                }
            }
        }