Esempio n. 1
0
    public bool AddItem(int id, int amt)
    {
        Debug.Log("Adding id "+ id);
        Vector2 temp = FindItem(id);
        int arr = (int) (temp.x);
        int ind = (int) (temp.y);
        if (arr != 0) {
            if (devArray.gInv[id].GetComponent<Item>().stackable) {
                if (arr == 1) {
                    Debug.Log("Plus one " + toolbar[ind].title);
                    toolbar[ind].quantity += amt;
                    return true;
                }
                if (arr == 2) {
                    Debug.Log("Plus one " + mainInv[ind].title);
                    mainInv[ind].quantity += amt;
                    return true;
                }
            }
        } else {
            for (int i = 0; i < toolbar.Length; i++) {
                if(toolbar[i] == null) {
                    Debug.Log("First item of " + toolbar[i].title);
                    toolbar[i] = new InvCard(devArray.gInv[id]);
                    toolbar[1].quantity = amt;
                    return true;
                }
            }

            for (int i = 0; i < mainInv.Length; i++) {
                if(mainInv[i] == null) {
                    Debug.Log("First item of " + mainInv[i].title);
                    mainInv[i] = new InvCard(devArray.gInv[id]);
                    mainInv[i].quantity = amt;
                    return true;
                }
            }
        }

        string name = devArray.gInv[id].GetComponent<Item>().title;
        Debug.Log("!!!Could NOT put " + name + " into inventory");
        return false;
    }
Esempio n. 2
0
    void CraftThis(int index, int recipeIndex)
    {
        Debug.Log("Ize bee crafftun, massa");
        Cneeds[] itemRecipes = craftList[index].GetComponents<Cneeds>();

        int numCraft = 1;

        // Get the chosen recipe and remove the used ingredients
        Cneeds rec = itemRecipes[recipeIndex];
        for (int i = 0; i < itemRecipes[recipeIndex].input.Length; i++) {
            InvCard[] icard = playerInv.toolbar;
            for (int j = 0; j < icard.Length; j++) {
                if (icard[j].id == rec.input[i].GetComponent<Item>().id) {
                    int useAmt = 0;
                    if (rec.amount[i] < 1) {
                        float Amt = 1 / rec.amount[i];
                        numCraft = Mathf.FloorToInt(Amt);
                        useAmt = 1;
                    } else {
                        useAmt = Mathf.FloorToInt(rec.amount[i]);
                    }

                    if ((icard[j].quantity - useAmt) <= 0) {
                        icard[j] = new InvCard();
                    } else {
                        icard[j].quantity -= useAmt;
                    }
                }
            }
        }

        for (int i = 0; i < numCraft; i++) {
            playerInv.GiveDev(craftList[index]);
        }
        CheckInv();
    }
Esempio n. 3
0
    void GiveRes(GameObject devitem)
    {
        for (int ii = 0; ii < devitem.GetComponent<Resource>().matsID.Length; ii++) {
            bool found = false;
            int amt = Random.Range(devitem.GetComponent<Resource>().matsMin[ii], devitem.GetComponent<Resource>().matsMax[ii]);

            foreach(InvCard obj in toolbar) {
                Debug.Log("Searching...");
                if(obj.id != 0 && obj.id == devitem.GetComponent<Resource>().matsID[ii]) {
                    obj.quantity += amt;
                    Debug.Log("Increased a stack of " + obj.title + " by " + amt);
                    found = true;
                    break;
                }
            }

            if (!found) {
                foreach(InvCard obj in mainInv) {
                    Debug.Log("Still searching...");
                    if(obj.id != 0 && obj.id == devitem.GetComponent<Resource>().matsID[ii]) {
                        obj.quantity += amt;
                        Debug.Log("Increased a stack of " + obj.title + " by " + amt);
                        found = true;
                        break;
                    }
                }
            }

            if (!found) {
                for (int i = 0; i < toolbar.Length; i++) {
                    if(toolbar[i].id == 0) {
                        toolbar[i] = new InvCard(devArray.gInv[devitem.GetComponent<Resource>().matsID[ii]]);
                        Debug.Log("Added " + toolbar[i].title);
                        if (i == toolbarSel) {
                            PlaceItem();
                        }
                        found = true;
                        break;
                    }
                }
            }

            if (!found) {
                for (int i = 0; i < mainInv.Length; i++) {
                    if(mainInv[i].id == 0) {
                        mainInv[i] = new InvCard(devArray.gInv[devitem.GetComponent<Resource>().matsID[ii]]);
                        Debug.Log("Added " + mainInv[i].title);
                        found = true;
                        break;
                    }
                }
            }

            if (!found) {
                Debug.Log(devitem.GetComponent<Item>().title + " failed to fit in inventory");
                audio.PlayOneShot(clickFailFX);
            }
        }
    }
Esempio n. 4
0
    public void GiveDev(GameObject devitem)
    {
        if(devitem.GetComponent<Item>().stackable) {
            foreach(InvCard obj in toolbar) {
                if (obj.id != 0) {
                    if(obj.model == devitem) {
                        obj.quantity += devitem.GetComponent<Item>().quantity;
                        Debug.Log("Increased a stack of " + obj.title);
                        //audio.PlayOneShot(clickFX);
                        return;
                    }
                }
            }

            foreach(InvCard obj in mainInv) {
                if (obj.id != 0) {
                    if(obj.model == devitem) {
                        //obj.GetComponent<Item>().quantity += devitem.GetComponent<Item>().quantity;
                        obj.quantity += devitem.GetComponent<Item>().quantity;
                        Debug.Log("Increased a stack of " + obj.title);
                        //audio.PlayOneShot(clickFX);
                        return;
                    }
                }
            }
        }

        for (int i = 0; i < toolbar.Length; i++) {
            if(toolbar[i].id == 0) {
                toolbar[i] = new InvCard(devitem);
                //toolbar[i] = devitem.GetComponent<Item>();
                Debug.Log("Added " + toolbar[i].title);
                if (i == toolbarSel) {
                    PlaceItem();
                }
                //audio.PlayOneShot(clickFX);
                return;
            }
        }

        for (int i = 0; i < mainInv.Length; i++) {
            if(mainInv[i].id == 0) {
                mainInv[i] = new InvCard(devitem);
                //mainInv[i] = devitem.GetComponent<Item>();
                Debug.Log("Added " + mainInv[i].title);
                //audio.PlayOneShot(clickFX);
                return;
            }
        }
        Debug.Log(devitem.GetComponent<Item>().title + " failed to fit in inventory");
        audio.PlayOneShot(clickFailFX);
    }