Esempio n. 1
0
    /// <summary>
    /// Called when the craft button is clicked.
    /// </summary>
    public void callback_craftButtonClick()
    {
        Recipe r = this.selectedRecipe.getRecipe();
        ContainerContents <IItemBase> inventory = this.getPlayer().inventory;

        // Remove the items from the players inventory.
        foreach (ItemData item in r.getIngredients())
        {
            int i;
            inventory.containsItem(item, out i);
            if (i != -1)
            {
                ItemManager.destroyItem(this.getPlayer(), i);
            }
        }

        // Add the new item to the players inventory.
        if (r.getResult() != null)
        {
            IItemBase item = ItemManager.create <IItemBase>(r.getResult());
            item.setInWorld(false, Vector3.zero, Quaternion.identity);
            inventory.addItem(item);
        }

        // Set the selected recipe to be null.
        this.selectedRecipe.setOutlined(false);
        this.setSelectedRecipe(null);
    }
Esempio n. 2
0
    public bool hasRequiredIngredients(ContainerContents <IItemBase> containerContents)
    {
        IItemBase[] items    = containerContents.getRawItemArray();
        List <int>  indicies = new List <int>();

        foreach (ItemData item in this.ingredients)
        {
            if (item != null)
            {
                for (int i = 0; i < items.Length; i++)
                {
                    if (items[i] != null && items[i].getData() == item)
                    {
                        if (indicies.Contains(i))
                        {
                            continue;
                        }
                        else
                        {
                            indicies.Add(i);
                            break; // Found the item, go to the next ingredient
                        }
                    }
                }
            }
        }

        return(indicies.Count == this.ingredients.Length);
    }
Esempio n. 3
0
    public static T create <T>(ItemData itemData, ContainerContents <IItemBase> container) where T : IItemBase
    {
        T item = ItemManager.create <T>(itemData);

        item.setInWorld(false, Vector3.zero, Quaternion.identity); // TODO where should they be stored?
        container.addItem(item);

        return(item);
    }
Esempio n. 4
0
    /// <summary>
    /// Called when the container is opened by a Player.
    /// </summary>
    public virtual Container onOpen(ContainerContents <IItemBase> data, Player player)
    {
        this.contents = data;
        this.player   = player;

        this.gameObject.SetActive(true);

        return(this);
    }
Esempio n. 5
0
    private void Start()
    {
        this.health.subscribeToDamageEvent(onDamageCallback);

        Vector2Int inventorySize = this.getContainerSize();

        this.inventory = new ContainerContents <IItemBase>(inventorySize.x, inventorySize.y);

        this.init();
    }
Esempio n. 6
0
 public void drawHotbarItems(ContainerContents <IItemBase> container)
 {
     for (int i = 0; i < 4; i++)
     {
         IItemBase item = container.getItem(i);
         if (item != null)
         {
             Transform t = this.hotbarSquares[i].transform;
             RenderHelper.renderItemMesh(item, t.position, t.rotation, t.localScale, this.orthoCamera);
         }
     }
 }
Esempio n. 7
0
    public void fillContainer(ContainerContents <IItemBase> container)
    {
        foreach (ItemData itemData in this.items)
        {
            if (container.isFull())
            {
                break;
            }

            if (itemData == null)
            {
                continue;
            }

            ItemManager.create <IItemBase>(itemData, container);
        }
    }
Esempio n. 8
0
    public void Init(ContainerContents containerCont)
    {
        items = new ItemDictionary();

        var contents = containerCont.GetContents();

        List <ContainerItem> itemCounts = new List <ContainerItem>();

        foreach (ItemBaseCount baseCount in contents)
        {
            Item item = Game.Instance.Factories.ItemFactory.CreateItem(baseCount.itemBase);
            itemCounts.Add(new ContainerItem()
            {
                item = item, count = baseCount.count
            });
        }

        Add(itemCounts);
    }