Exemplo n.º 1
0
        public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
        {
            if (worldItem.ToRemove)
            {
                return;
            }
            var blockEntity = Utils.GetBlockEntity(cellFace.Point);

            if (blockEntity == null)
            {
                return;
            }
            var inventory = blockEntity.Entity.FindComponent <ICraftingMachine>(true);
            var pickable = worldItem as Pickable;
            int value = worldItem.Value;
            int count = (pickable == null) ? 1 : pickable.Count, count2 = MathUtils.Min(count, inventory.GetSlotCapacity(inventory.SlotIndex, value) - inventory.GetSlotCount(inventory.SlotIndex));

            if (inventory.GetSlotCount(inventory.SlotIndex) != 0 && inventory.GetSlotValue(inventory.SlotIndex) != value)
            {
                return;
            }
            inventory.AddSlotItems(inventory.SlotIndex, value, count2);
            if (count2 < count)
            {
                Utils.SubsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, true);
            }
            if (count - count2 <= 0)
            {
                worldItem.ToRemove = true;
            }
            else if (pickable != null)
            {
                pickable.Count = count - count2;
            }
        }
Exemplo n.º 2
0
        public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            var blockEntity = Utils.GetBlockEntity(raycastResult.CellFace.Point);

            if (blockEntity == null || componentMiner.ComponentPlayer == null)
            {
                return(false);
            }
            switch (Terrain.ExtractContents(raycastResult.Value))
            {
            case BlastFurnaceBlock.Index:
                componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new BlastFurnaceWidget(componentMiner.Inventory, blockEntity.Entity.FindComponent <ComponentBlastFurnace>(true));
                break;

            case CovenBlock.Index:
                componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new CovenWidget(componentMiner.Inventory, blockEntity.Entity.FindComponent <ComponentCoven>(true));
                break;

            case HearthFurnaceBlock.Index:
                componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new CovenWidget(componentMiner.Inventory, blockEntity.Entity.FindComponent <ComponentHearthFurnace>(true), "Widgets/HearthFurnaceWidget");
                break;

            case TankBlock.Index:
                if (TankBlock.GetType(raycastResult.Value) == TankBlock.Type.FractionatingTower)
                {
                    componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new FractionalTowerWidget(componentMiner.Inventory, blockEntity.Entity.FindComponent <ComponentFractionalTower>(true));
                    break;
                }
                return(false);

            default: return(false);
            }
            AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
            return(true);
        }
Exemplo n.º 3
0
        public override Device Create(Point3 p)
        {
            var device = (EntityDevice <T>)base.Create(p);

            device.Component = Utils.GetBlockEntity(p)?.Entity.FindComponent <T>(true);
            device.Name      = Name;
            return(device);
        }
Exemplo n.º 4
0
        public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            var entity = Utils.GetBlockEntity(raycastResult.CellFace.Point);

            if (entity == null || componentMiner.ComponentPlayer == null)
            {
                return(false);
            }
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = GetWidget(componentMiner.Inventory, entity.Entity.FindComponent <T>(true));
            AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
            return(true);
        }
Exemplo n.º 5
0
        public virtual void OnBlockRemoved(SubsystemTerrain subsystemTerrain, int value, int newValue)
        {
            var blockEntity = Utils.GetBlockEntity(Point);

            if (blockEntity == null)
            {
                return;
            }
            var position = new Vector3(Point) + new Vector3(.5f);

            for (var i = blockEntity.Entity.FindComponents <IInventory>().GetEnumerator(); i.MoveNext();)
            {
                i.Current.DropAllItems(position);
            }
            subsystemTerrain.Project.RemoveEntity(blockEntity.Entity, true);
        }
Exemplo n.º 6
0
 public override bool Simulate()
 {
     for (int i = 0; i < Connections.Count; i++)
     {
         var connection = Connections[i];
         if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
         {
             ICraftingMachine inventory = Inventory;
             if (inventory == null)
             {
                 Inventory = inventory = Utils.GetBlockEntity(Point)?.Entity.FindComponent <ICraftingMachine>();
                 if (inventory == null)
                 {
                     return(false);
                 }
             }
             int n = (int)MathUtils.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f);
             if (connection.CellFace.Face == 4)
             {
                 inventory.SlotIndex = n;
             }
             else if (n > 0 && (SubsystemElectricity.SubsystemTime.GameTime - m_lastDispenseTime > 0.1) && connection.CellFace.Face == 5)
             {
                 m_lastDispenseTime = SubsystemElectricity.SubsystemTime.GameTime;
                 var matchedRecipe = inventory.GetRecipe() ?? new CraftingRecipe
                 {
                     ResultCount  = 1,
                     RemainsCount = 1
                 };
                 var position = new Vector3(Point) + new Vector3(0.5f, 1f, 0.5f);
                 Utils.SubsystemPickables.AddPickable(inventory.GetSlotValue(inventory.ResultSlotIndex), inventory.RemoveSlotItems(inventory.ResultSlotIndex, matchedRecipe.ResultCount * MathUtils.Min(inventory.GetSlotCount(inventory.ResultSlotIndex) / matchedRecipe.ResultCount, n)), position, null, null);
                 if (matchedRecipe.RemainsCount > 0)
                 {
                     Utils.SubsystemPickables.AddPickable(inventory.GetSlotValue(inventory.RemainsSlotIndex), inventory.RemoveSlotItems(inventory.RemainsSlotIndex, matchedRecipe.RemainsCount * MathUtils.Min(inventory.GetSlotCount(inventory.RemainsSlotIndex) / matchedRecipe.RemainsCount, n)), position, null, null);
                 }
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public override bool Simulate()
        {
            int n = 0;

            for (int i = 0; i < Connections.Count; i++)
            {
                var connection = Connections[i];
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
                {
                    n = MathUtils.Max(n, (int)MathUtils.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f));
                    if (n > 7)
                    {
                        break;
                    }
                }
            }
            if (n > 7 && SubsystemElectricity.SubsystemTime.GameTime - m_lastDispenseTime > 0.1)
            {
                var inventory = Inventory;
                if (inventory == null)
                {
                    inventory = Utils.GetBlockEntity(Point)?.Entity.FindComponent <ICraftingMachine>();
                }
                if (inventory == null)
                {
                    return(false);
                }
                var position = new Vector3(Point) + new Vector3(0.5f, 1f, 0.5f);
                Utils.SubsystemPickables.AddPickable(inventory.GetSlotValue(inventory.ResultSlotIndex), inventory.RemoveSlotItems(inventory.ResultSlotIndex, MathUtils.Min(inventory.GetSlotCount(inventory.ResultSlotIndex), n)), position, null, null);
                if (inventory.GetSlotCount(inventory.RemainsSlotIndex) > 0)
                {
                    Utils.SubsystemPickables.AddPickable(inventory.GetSlotValue(inventory.RemainsSlotIndex), inventory.RemoveSlotItems(inventory.RemainsSlotIndex, MathUtils.Min(inventory.GetSlotCount(inventory.RemainsSlotIndex), n)), position, null, null);
                }
            }
            return(false);
        }