public void AddItemToInventory(BlockType BlockType, GameModel gameModel)
        {
            bool found     = false;
            int  firstZero = -1;

            for (int i = 0; i < gameModel.Player.Inventory.MainInventory.GetLength(1); i++)
            {
                if (gameModel.Player.Inventory.MainInventory[3, i].ItemCount > 0)
                {
                    if (gameModel.Player.Inventory.MainInventory[3, i].Item.ItemType == ItemType.Blocks)
                    {
                        BlockItemModel block = (BlockItemModel)gameModel.Player.Inventory.MainInventory[3, i].Item;
                        if (block.BlockType == BlockType)
                        {
                            gameModel.Player.Inventory.MainInventory[3, i].ItemCount++;
                            found = true;
                            break;
                        }
                    }
                }
                else if (firstZero == -1)
                {
                    firstZero = i;
                }
            }

            if (!found && firstZero != -1)
            {
                BlockItemModel block = new BlockItemModel(BlockType);
                gameModel.Player.Inventory.MainInventory[3, firstZero].Item      = block;
                gameModel.Player.Inventory.MainInventory[3, firstZero].ItemCount = 1;
            }
        }
示例#2
0
    private void SetRawImage(RawImage image, ItemModel item)
    {
        BlockItemModel block = (BlockItemModel)item;

        Vector2 material = MaterialsSides[(int)block.BlockType, 5];

        image.uvRect = new Rect(material * 0.0625f, new Vector2(0.0625f, 0.0625f));
    }
示例#3
0
 public void PlaceBlockFromSlectedSlot(int x, int y, int z, GameModel gameModel)
 {
     if (gameModel.Blocks.GetLength(0) > x && x >= 0 && gameModel.Blocks.GetLength(1) > y && y >= 0 && gameModel.Blocks.GetLength(2) > z && z >= 0)
     {
         InventorySlotModel slot = inventoryService.GetBlockFromSelectedSlot(gameModel);
         if (slot.ItemCount > 0)
         {
             if (slot.Item.ItemType == ItemType.Blocks)
             {
                 BlockItemModel block = (BlockItemModel)slot.Item;
                 gameModel.Blocks[x, y, z] = BlockFactory.CreateBlock(new Point(x, y, z), block.BlockType);
                 if (gameModel.Player.Gamemode == GamemodeType.Survival)
                 {
                     gameModel.Player.Inventory.MainInventory[3, gameModel.Player.Inventory.SelectedBlock].ItemCount--;
                 }
             }
         }
     }
 }