Esempio n. 1
0
    void AddToItemsNeeded(Item item, int quantity)
    {
        Item craftMat = DeepCopy.CopyItem(item);

        craftMat.CurStacks = quantity;
        itemsNeeded.Add(craftMat);
    }
Esempio n. 2
0
    public void ShowSplitStack()
    {
        Rect sssRect = new Rect(
            (_inventoryWindowRect.x + _inventoryWindowRect.width) / 2 - 50,
            (_inventoryWindowRect.y + _inventoryWindowRect.height) / 2 - 35,
            100,
            70);

        GUI.Box(sssRect, "");

        GUI.Label(new Rect(sssRect.x + 5, sssRect.y + 5, 90, 30), "Split by:");
        //MyGUI.amountToSplitBy = int.Parse (GUI.TextField(new Rect(sssRect.x+5,sssRect.y+35,60,30),MyGUI.amountToSplitBy.ToString()));
        MyGUI.amountToSplitBy = GUI.HorizontalSlider(new Rect(sssRect.x + 5, sssRect.y + 35, 60, 30), MyGUI.amountToSplitBy, 1, _pc.Inventory[MyGUI.inventoryArrayToSplit].CurStacks);
        GUI.Label(new Rect(sssRect.x + 5, sssRect.y + 50, 60, 30), MyGUI.amountToSplitBy.ToString());
        MyGUI.amountToSplitBy = Mathf.Clamp(MyGUI.amountToSplitBy, 1, _pc.Inventory[MyGUI.inventoryArrayToSplit].CurStacks);
        MyGUI.amountToSplitBy = (int)MyGUI.amountToSplitBy;

        if (MyGUI.amountToSplitBy == 0)
        {
            MyGUI.amountToSplitBy = 1;
        }
        if (GUI.Button(new Rect(sssRect.x + 70, sssRect.y + 35, 30, 30), "Ok"))
        {
            if (_pc.Inventory[MyGUI.inventoryArrayToSplit].CurStacks - (int)MyGUI.amountToSplitBy == 0)
            {
                showSplit = false;
                MyGUI.inventoryArrayToSplit = 1000;
            }
            else
            {
                if (_pc.Inventory.Count + 1 <= _pc.MaxInventorySpace)
                {
                    _pc.Inventory[MyGUI.inventoryArrayToSplit].CurStacks -= (int)MyGUI.amountToSplitBy;
                    Item newStack = DeepCopy.CopyItem(_pc.Inventory[MyGUI.inventoryArrayToSplit]);
                    newStack.CurStacks = (int)MyGUI.amountToSplitBy;
                    _pc.Inventory.Add(newStack);
                }
                else
                {
                    Debug.Log("No space to split stack");
                }
                showSplit = false;
                MyGUI.inventoryArrayToSplit = 1000;
            }
        }
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        //For testing /////////////////////////////////////
        ModifyAttribute(AttributeName.Strength, 10);
        ModifyAttribute(AttributeName.Dexterity, 10);
        ModifyAttribute(AttributeName.Vitality, 10);
        ModifyAttribute(AttributeName.Intelligence, 10);
        Name = "Player";
        RefreshVitals();
        ///////////////////////////////////////////////////

        Item item = ItemGenerator.CreateItem("consum", "random", 100);

        item.CurStacks = 10;
        Item itemcopy = DeepCopy.CopyItem(item);

        Inventory.Add(item);
        Inventory.Add(itemcopy);
    }
Esempio n. 4
0
    IEnumerator Harvest()
    {
        if (materialsRemaining == 0)
        {
            harvesting         = false;
            player.playerState = PlayerState.Normal;
            playerCamera.GetComponent <ActionRPGCamera>().target = player.transform;
            Destroy(gameObject, 3.0f);
            return(false);
        }
        yield return(new WaitForSeconds(0.5f));

        HarvestedItem = DeepCopy.CopyItem(HarvestedItem);
        ItemSpawner itemspawner = GameObject.FindGameObjectWithTag("ItemSpawner").GetComponent <ItemSpawner>();

        itemspawner.SpawnAnItem(this.transform.position, HarvestedItem);
        materialsRemaining -= 1;
        yield return(new WaitForSeconds(0.3f));

        StartCoroutine("Harvest");
    }
Esempio n. 5
0
    public void CraftItem(Item item)
    {
        //FOREACH LOOP THROUGH EACH ITEM, TEMP INT TO CHECK EACH STACK, BOOL TO CHECK IF TEMP = NUMNEEDED(== ITEM.CURSTACKS)
        //WE SET ITEMSNEED.CURSTACKS AS THE NUMBER NEEDED

        //Check level if(player.CraftingLevel >= item.Level) {

        GetMatsInfo(item);         //sets itemsNeeded

        bool haveAllItems = true;

        for (int i = 0; i < itemsNeeded.Count; i++)
        {
            int tempMatCount = 0;
            int matCountNeed = itemsNeeded[i].CurStacks;
            foreach (Item x  in player.Inventory)
            {
                if (x.Name == itemsNeeded[i].Name)
                {
                    tempMatCount += x.CurStacks;
                }
            }
            if (tempMatCount < matCountNeed)
            {
                haveAllItems = false;
            }
            //Debug.Log (itemsNeeded[i].Name + " " + itemsNeeded[i].CurStacks + );
        }

        if (haveAllItems)
        {
            if (player.Inventory.Count < player.MaxInventorySpace)
            {
                for (int i = 0; i < itemsNeeded.Count; i++)
                {
                    int itemsLeftToTake = itemsNeeded[i].CurStacks;

                    for (int u = 0; u < player.Inventory.Count; u++)
                    {
                        if (player.Inventory[u].Name == itemsNeeded[i].Name)
                        {
                            int numTaken = 0;
                            if (player.Inventory[u].CurStacks - itemsLeftToTake <= 0)
                            {
                                numTaken += player.Inventory[u].CurStacks;
                                player.Inventory.RemoveAt(u);
                                u--;
                            }
                            else
                            {
                                player.Inventory[u].CurStacks -= itemsLeftToTake;
                                if (player.Inventory[u].CurStacks == 0)
                                {
                                    player.Inventory.RemoveAt(u);
                                    u--;
                                }
                                numTaken += itemsLeftToTake;
                            }

                            itemsLeftToTake -= numTaken;
                        }
                    }
                }

                player.Inventory.Add(DeepCopy.CopyItem(item));
            }
            else
            {
                Debug.Log("Inventory is full");
            }
        }
        else
        {
            Debug.Log("Don't have all items");
        }
        //else { Debug.Log("Not high enough crafting level");
    }
Esempio n. 6
0
    public void PlayerSellItem(int inventoryArrayNum)
    {
        Item soldItem = player.Inventory[inventoryArrayNum];

        if (soldItem.MaxStacks == 1)
        {
            //Debug.Log(buyBackItems.Count + " " + maxBuyBackItemCount);
            if (buyBackItems.Count == maxBuyBackItemCount)
            {
                buyBackItems.RemoveAt(0);                  //Remove oldest item
            }

            buyBackItems.Add(soldItem);
            player.Inventory.RemoveAt(inventoryArrayNum);
            int sellPrice = (int)(soldItem.Value * 0.65f);              //65% of value earned in gold for selling
            player.ModifyGold(sellPrice);
        }
        else if (soldItem.CurStacks == 1)
        {
            bool itemAdded = false;
            foreach (Item i in buyBackItems)
            {
                //Is the item already there
                if (i.Name == soldItem.Name)
                {
                    //Is there space in that stack to add the current item
                    if (i.CurStacks + 1 <= i.MaxStacks)
                    {
                        i.CurStacks += 1;
                        player.Inventory.RemoveAt(inventoryArrayNum);
                        itemAdded = true;
                    }
                }
            }

            if (!itemAdded)
            {
                buyBackItems.Add(soldItem);
                player.Inventory.RemoveAt(inventoryArrayNum);
                int sellPrice = (int)(soldItem.Value * 0.65f);                  //65% of value earned in gold for selling
                player.ModifyGold(sellPrice);
            }
        }
        else if (soldItem.CurStacks > 0)
        {
            bool itemAdded = false;
            foreach (Item i in buyBackItems)
            {
                //Is the item already there
                if (i.Name == soldItem.Name)
                {
                    //Is there space in that stack to add the current item
                    if (i.CurStacks + 1 <= i.MaxStacks)
                    {
                        i.CurStacks        += 1;
                        soldItem.CurStacks -= 1;

                        int sellPrice = (int)(soldItem.Value * 0.65f);                          //65% of value earned in gold for selling
                        player.ModifyGold(sellPrice);

                        if (soldItem.CurStacks == 0)
                        {
                            Debug.Log("No stacks");
                            player.Inventory.RemoveAt(inventoryArrayNum);
                        }

                        itemAdded = true;
                    }
                }
            }
            if (!itemAdded)
            {
                if (buyBackItems.Count == maxBuyBackItemCount)
                {
                    buyBackItems.RemoveAt(0);                      //Remove oldest item
                }

                Item onestack = DeepCopy.CopyItem(player.Inventory[inventoryArrayNum]);
                onestack.CurStacks = 1;
                buyBackItems.Add(onestack);
                player.Inventory[inventoryArrayNum].CurStacks -= 1;
                int sellPrice = (int)(soldItem.Value * 0.65f);                  //65% of value earned in gold for selling
                player.ModifyGold(sellPrice);
            }
        }
    }