Exemplo n.º 1
0
    //---- Crafting ----

    public bool CanCraft(CraftData item)
    {
        CraftCostData cost      = item.GetCraftCost();
        bool          can_craft = true;

        foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
        {
            if (!PlayerData.Get().HasItem(pair.Key.id, pair.Value))
            {
                can_craft = false; //Dont have required items
            }
        }

        if (cost.craft_near != null && !IsNearGroup(cost.craft_near) && !HasItemInGroup(cost.craft_near))
        {
            can_craft = false; //Not near required construction
        }
        ItemData idata = item.GetItem();

        if (idata != null && !PlayerData.Get().CanTakeItem(idata.id, 1))
        {
            can_craft = false; //Inventory is full
        }
        return(can_craft);
    }
Exemplo n.º 2
0
    private void RefreshPanel()
    {
        slot.SetSlot(data, 1, true);
        slot.AnimateGain();
        title.text = data.title;
        desc.text  = data.desc;

        foreach (ItemSlot slot in craft_slots)
        {
            slot.Hide();
        }

        CraftCostData cost  = data.GetCraftCost();
        int           index = 0;

        foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
        {
            if (index < craft_slots.Length)
            {
                ItemSlot slot = craft_slots[index];
                slot.SetSlot(pair.Key, pair.Value, false);
                slot.ShowTitle();
            }
            index++;
        }

        if (index < craft_slots.Length)
        {
            ItemSlot slot = craft_slots[index];
            if (cost.craft_near != null)
            {
                slot.SetSlotCustom(cost.craft_near.icon, cost.craft_near.title, false);
                slot.ShowTitle();
            }
        }

        PlayerCharacter player = PlayerCharacter.Get();

        craft_btn.interactable = player.CanCraft(data);
    }