Beispiel #1
0
    public void CraftItem(string itemId)
    {
        if (!Instance.recipeRequirements.ContainsKey(itemId))
        {
            Debug.LogError("No crafting info found for: " + itemId);
            return;
        }

        for (int i = 0; i < Instance.recipeRequirements[itemId].Length; i++)
        {
            if (TryRemoveFromInventory(Instance.recipeRequirements[itemId].ElementAt(i).id, Instance.recipeRequirements[itemId].ElementAt(i).amount))
            {
                continue;
            }
            else
            {
                Debug.LogError("Error happened removing item from inventory, able to craft when you should not be able to.");
                return;
            }
        }
        LittleHeightsItem item = junk.AddComponent <LittleHeightsItem>();

        item.id         = itemId;
        item.currAmount = GetCraftingItemAmount();
        foreach (var comp in junk.GetComponents <Component>())
        {
            if (!(comp is Transform))
            {
                Destroy(comp);
            }
        }
        this.transform.parent.GetComponentInChildren <PlayerInventory>().TryToAddItemToInventoryNonDroppedItem(item);
    }
Beispiel #2
0
 private bool TryToAddItemToExistingItem(LittleHeightsItem item)
 {
     for (int i = 0; i < this.itemHolders.Length; i++)
     {
         if (itemHolders[i].GetComponent <InventorySlot>().itemId == "")
         {
             continue;
         }
         else if (itemHolders[i].GetComponent <InventorySlot>().itemId == item.id)
         {
             if (itemHolders[i].GetComponent <InventorySlot>().currAmount + item.currAmount <= ItemProperties.quantityForItem[item.id])
             {
                 itemHolders[i].GetComponent <InventorySlot>().GetComponentInChildren <LittleHeightsItem>().currAmount += item.currAmount;
                 itemHolders[i].GetComponent <InventorySlot>().generateInventory();
                 return(true);
             }
             Debug.Log("Found matching, but max quantity has been reached");
             continue;
         }
         else
         {
             continue;
         }
     }
     return(false);
 }
Beispiel #3
0
 void Start()
 {
     item                  = this.GetComponent <LittleHeightsItem>();
     boxCollider           = this.GetComponent <BoxCollider2D>();
     spriteRenderer        = this.GetComponent <SpriteRenderer>();
     spriteRenderer.sprite = item.sprite;
     spriteRenderer.sprite = item.sprite;
 }
Beispiel #4
0
 void Start()
 {
     activeTileSelector = GameObject.FindGameObjectWithTag("TileManager");
     playerInventory    = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>();
     grid              = GameObject.FindObjectOfType <Grid>();
     currentItem       = playerInventory.currentItem;
     hotBarItem        = GameObject.Find("CurrentItemSelector").GetComponentInChildren <CurrentItem>();
     placeableItemMask = LayerMask.GetMask("PlaceableItem");
 }
Beispiel #5
0
    public void AddItemToIndex(int i, LittleHeightsItem item)
    {
        //itemHolders[i].gameObject.GetComponent<InventorySlot>().GetComponentInChildren<Item>().currAmount = item.currAmount;
        GameObject        temp     = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, itemHolders[i].transform);
        LittleHeightsItem tempItem = temp.GetComponent <LittleHeightsItem>();

        tempItem.id         = item.id;
        tempItem.currAmount = item.currAmount;
        //need to set inventoryslot stuff
        itemHolders[i].GetComponent <InventorySlot>().itemId     = item.id;
        itemHolders[i].GetComponent <InventorySlot>().currAmount = item.currAmount;
        //Debug.Log("Inventory is full");
    }
Beispiel #6
0
 void LoadInventory()
 {
     for (int i = 0; i < PersistentData.Instance.CurrentSave.characterInventory.InventoryDict.Count; i++)
     {
         if (PersistentData.Instance.CurrentSave.characterInventory.InventoryDict[i].count > 0)
         {
             LittleHeightsItem temp = new LittleHeightsItem();
             temp.id         = PersistentData.Instance.CurrentSave.characterInventory.InventoryDict[i].name;
             temp.currAmount = PersistentData.Instance.CurrentSave.characterInventory.InventoryDict[i].count;
             AddItemToIndex(i, temp);
         }
     }
 }
Beispiel #7
0
 public void TryToAddItemToInventoryNonDroppedItem(LittleHeightsItem item)
 {
     if (TryToAddItemToExistingItem(item))
     {
         //Debug.Log("Picked up existing item and added to count");
         return;
     }
     if (TryToAddItemToEmptySlot(item))
     {
         //Debug.Log("Added new item to inventory");
         return;
     }
     Debug.Log("Inventory is full");
 }
Beispiel #8
0
 // Update is called once per frame
 void Update()
 {
     currentItemHolder = GameObject.Find("CurrentItemSelector").GetComponent <CurrentItem>().currentSlot;
     if (currentItemHolder.transform.childCount > 0)
     {
         currentItem = currentItemHolder.GetComponentInChildren <LittleHeightsItem>();
     }
     else
     {
         currentItem = null;
     }
     if (Input.GetKeyDown(KeyCode.P))
     {
         SaveInventory();
     }
 }
Beispiel #9
0
 public void generateHotbarItem()
 {
     if (itemHolderOnInventory.GetComponent <InventorySlot>().itemId != "")
     {
         if (this.transform.childCount == 0)
         {
             itemPrefab = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, transform);
             item       = itemPrefab.GetComponent <LittleHeightsItem>();
         }
         item.id         = itemHolderOnInventory.GetComponent <InventorySlot>().itemId;
         item.currAmount = itemHolderOnInventory.GetComponent <InventorySlot>().currAmount;
     }
     else
     {
         foreach (Transform child in transform)
         {
             Destroy(child.gameObject);
         }
     }
 }
Beispiel #10
0
 public void TryToAddItemToInventory(LittleHeightsItem item)
 {
     if (TryToAddItemToExistingItem(item))
     {
         //Debug.Log("Picked up existing item and added to count");
         Destroy(item.transform.gameObject);
         audioSource.pitch = Random.Range(0.9f, 1.5f);
         audioSource.PlayOneShot(audioSource.clip);
         return;
     }
     if (TryToAddItemToEmptySlot(item))
     {
         //Debug.Log("Added new item to inventory");
         Destroy(item.transform.gameObject);
         audioSource.pitch = Random.Range(0.9f, 1.5f);
         audioSource.PlayOneShot(audioSource.clip);
         return;
     }
     Debug.Log("Inventory is full");
 }
Beispiel #11
0
 private bool TryToAddItemToEmptySlot(LittleHeightsItem item)
 {
     for (int i = 0; i < this.itemHolders.Length; i++)
     {
         if (itemHolders[i].GetComponent <InventorySlot>().itemId == "")
         {
             ////instantiate!!!!
             //itemHolders[i].gameObject.GetComponentInChildren<Item>().id = item.id;
             //itemHolders[i].gameObject.GetComponent<InventorySlot>().GetComponentInChildren<Item>().currAmount = item.currAmount;
             GameObject        temp     = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, itemHolders[i].transform);
             LittleHeightsItem tempItem = temp.GetComponent <LittleHeightsItem>();
             tempItem.id         = item.id;
             tempItem.currAmount = item.currAmount;
             //need to set inventoryslot stuff
             itemHolders[i].GetComponent <InventorySlot>().itemId     = item.id;
             itemHolders[i].GetComponent <InventorySlot>().currAmount = item.currAmount;
             return(true);
         }
     }
     return(false);
 }
Beispiel #12
0
 // Update is called once per frame
 void Update()
 {
     isActive      = activeTileSelector.GetComponent <MouseHoverScript>().isActiveArea;
     currentItem   = playerInventory.currentItem;
     mousePosition = placeableItemTileMap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));
     if (currentItem && isActive && ItemProperties.itemIsPlaceable[currentItem.id])
     {
         tryToHoverTile(currentItem.id);
         if (Input.GetMouseButtonDown(1))
         {
             Debug.Log("tried to place " + currentItem.id);
             // Debug.Log("tried to place on " + ItemProperties.itemsTilemap[currentItem.id]);
             Debug.Log("tried to make prefab " + ItemProperties.itemPlaced[currentItem.id]);
             try
             {
                 if (!checkIfItemThere())
                 {
                     placedItem = Instantiate(Resources.Load("PlaceableItem/" + currentItem.id), grid.GetCellCenterWorld(mousePosition), Quaternion.identity) as GameObject;
                     HotbarItemHolder hotbarItemHolder = hotBarItem.currentSlot;
                     Debug.Log("Position: " + grid.GetCellCenterWorld(mousePosition));
                     hotbarItemHolder.itemHolderOnInventory.GetComponentInChildren <LittleHeightsItem>().subtractQuantity(1);
                 }
                 else
                 {
                     Debug.Log("Item already there");
                 }
             }
             catch
             {
                 Debug.Log("error placing item");
             }
         }
     }
     else
     {
         placeableItemTileMap.SetTile(prevPos, null);
         placeableItemTileMap.SetTile(currPos, null);
     }
 }
Beispiel #13
0
 public void generateInventory()
 {
     if (this.transform.childCount == 0)
     {
         itemId = "";
     }
     else
     {
         itemId = this.GetComponentInChildren <LittleHeightsItem>().id;
     }
     if (itemId != "")
     {
         if (this.transform.childCount == 0)
         {
             itemPrefab = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, rectTransform);
             item       = itemPrefab.GetComponent <LittleHeightsItem>();
             itemId     = item.id;
             currAmount = item.currAmount;
         }
         else
         {
             path = "Items/" + this.itemId;
             transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>(path);
             item       = GetComponentInChildren <LittleHeightsItem>();
             itemId     = item.id;
             currAmount = item.currAmount;
         }
     }
     else
     {
         if (this.transform.childCount >= 0)
         {
             foreach (Transform child in transform)
             {
                 Destroy(child.gameObject);
             }
         }
     }
 }
Beispiel #14
0
 void InventoryButtonClicked()
 {
     generateInventory();
     if (MouseInventorySlot.Instance.itemOnMouse)//clicked when item is on mouse
     {
         if (itemId == "")
         {
             itemId          = MouseInventorySlot.Instance.itemIdOnMouse;
             currAmount      = MouseInventorySlot.Instance.currAmount;
             itemPrefab      = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, rectTransform);
             item            = itemPrefab.GetComponent <LittleHeightsItem>();
             item.id         = itemId;
             item.currAmount = currAmount;
             DestroyMousePrefab();
         }
         else
         {
             if (itemId == MouseInventorySlot.Instance.itemIdOnMouse && currAmount + MouseInventorySlot.Instance.currAmount <= ItemProperties.quantityForItem[itemId])
             {
                 currAmount = currAmount + MouseInventorySlot.Instance.currAmount;
                 DestroyMousePrefab();
                 item.currAmount = currAmount;
             }
             else
             {
                 item = this.GetComponentInChildren <LittleHeightsItem>();
                 string tempItemId   = item.id;
                 int    tempQuantity = item.currAmount;
                 item.id         = MouseInventorySlot.Instance.itemIdOnMouse;
                 item.currAmount = MouseInventorySlot.Instance.currAmount;
                 LittleHeightsItem tempItem = MouseInventorySlot.Instance.GetComponentInChildren <LittleHeightsItem>();
                 tempItem.id         = tempItemId;
                 tempItem.currAmount = tempQuantity;
                 MouseInventorySlot.Instance.itemIdOnMouse = tempItemId;
                 MouseInventorySlot.Instance.currAmount    = tempQuantity;
             }
         }
     }
     else //first click
     {
         if (itemId == "")
         {
             return;
         }
         else //first click with something in there
         {
             //make this another function
             MouseInventorySlot.Instance.itemIdOnMouse = itemId;
             MouseInventorySlot.Instance.currAmount    = currAmount;
             MouseInventorySlot.Instance.itemOnMouse   = true;
             itemId  = "";
             item.id = "";   //something weird here
             MouseInventorySlot.Instance.itemPrefabOnMouse = Instantiate(Resources.Load("Prefabs/ItemPrefab") as GameObject, MouseInventorySlot.Instance.transform);
             LittleHeightsItem tempItem = MouseInventorySlot.Instance.GetComponentInChildren <LittleHeightsItem>();
             tempItem.GetComponent <Image>().raycastTarget = false;
             tempItem.transform.localScale = new Vector3(0.8f, 0.8f);
             tempItem.id         = itemId;
             tempItem.currAmount = currAmount;
             foreach (Transform child in transform)
             {
                 Destroy(child.gameObject);
             }
         }
     }
     generateInventory();
 }