//---- 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);
    }
    public void OnClickCraft()
    {
        PlayerCharacter player = PlayerCharacter.Get();

        if (player.CanCraft(data))
        {
            ItemData         item      = data.GetItem();
            ConstructionData construct = data.GetConstruction();
            PlantData        plant     = data.GetPlant();

            if (item != null)
            {
                player.CraftItem(item);
            }
            if (construct != null)
            {
                player.SelectCraftConstruction(construct);
            }
            if (plant != null)
            {
                player.CraftPlant(plant);
            }

            craft_btn.interactable = false;
            Hide();
        }
    }
Beispiel #3
0
 public ItemData GetItem()
 {
     if (item != null)
     {
         return(item.GetItem());
     }
     return(null);
 }
Beispiel #4
0
    private void OnClickSlotRight(int slot, CraftData item)
    {
        selected_slot       = -1;
        selected_right_slot = -1;
        ActionSelectorUI.Get().Hide();

        if (item != null && item.GetItem() != null && item.GetItem().actions.Length > 0)
        {
            selected_right_slot = slot;
            ActionSelectorUI.Get().Show(PlayerCharacter.Get(), slots[slot]);
        }

        ItemSlot cslot = GetSlot(slot);

        if (onRightClickSlot != null && cslot != null)
        {
            onRightClickSlot.Invoke(cslot);
        }
    }