/*Creates the item content gameobject, makes it a child of Item Information panel
  * , and shows the item informations (information of the items stored using Item class)*/
 void goToMap(string sceneString)     //int contentID
 {
     clickSound.PlaySound();
     sceneManagement.changeScene(sceneString);
 }
예제 #2
0
    public void buyItem(GameObject panel, Item item, int playerItemIndex, string itemType, string buttonText, Button contentBuyButton, Button newButtonComponent)
    {
        clickSound.PlaySound();

        if (item.itemCost > playerDataScript.currencyAmount)
        {
            //print ("have a panel here saying you dont have enough gold to buy this item");
            openPopUp(noGoldPopUpPanel);
        }
        else            //else if you have enough gold then allow player to buy item, while deducting the gold
        {
            if (itemType == CHIP)
            {
                if (playerDataScript.chipsList [playerItemIndex] <= 0)
                {
                    playerDataScript.chipsList [playerItemIndex]++;

                    //item sold out code
                    itemSoldOut(contentBuyButton);
                    inventoryGeneratorScript.addInventory(inventoryChipGridPanel, item, playerItemIndex, itemType, buttonText);

                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (owned)";
                    newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);

                    playerDataScript.currencyAmount -= item.itemCost;                    //deduct item cost
                }
            }
            else if (itemType == SKILL)
            {
                if (playerDataScript.skillsList[playerItemIndex] <= 0)
                {
                    playerDataScript.skillsList[playerItemIndex]++;

                    //item sold out code
                    itemSoldOut(contentBuyButton);
                    inventoryGeneratorScript.addInventory(inventorySkillGridPanel, item, playerItemIndex, itemType, buttonText);

                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (owned)";
                    newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);

                    playerDataScript.currencyAmount -= item.itemCost;                    //deduct item cost
                }
                //playerDataScript.skillsList[playerItemIndex] ++;
            }
            else if (itemType == SKIN)
            {
                if (playerDataScript.skinsList[playerItemIndex] <= 0)
                {
                    playerDataScript.skinsList[playerItemIndex]++;

                    //item sold out code
                    itemSoldOut(contentBuyButton);
                    inventoryGeneratorScript.addInventory(inventorySkinGridPanel, item, playerItemIndex, itemType, buttonText);

                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (owned)";
                    newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);

                    playerDataScript.currencyAmount -= item.itemCost;                    //deduct item cost
                }
                //playerDataScript.skinsList[playerItemIndex] ++;
                //print("Skins have not been implemented yet :(");
            }
        }



        //print ("quantity bought: " + );



        //playerDataScript.chip1++;
        //print ("Item bought: " + playerDataScript.chip1);
    }
    //equips the item when you press equip and unequips if u press unequip. button text also changes. also calculates chip capacity
    public void equipItem(int playerItemIndex, string itemType, Button contentBuyButton, Item item, Button newButtonComponent, string buttonText)
    {
        clickSound.PlaySound();

        if (itemType == CHIP)
        {
            if (playerDataScript.chipsList[playerItemIndex] > 0)
            {
                if (playerDataScript.hasEquipchips [playerItemIndex] == true)                  //want to UNequip

                {
                    currentPlayerCapacity -= item.itemCapacity;                    //decrease item capacity

                    playerDataScript.hasEquipchips [playerItemIndex]       = false;
                    contentBuyButton.GetComponentInChildren <Text> ().text = "Equip";

                    newButtonComponent.image.color = Color.white;
                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText;
                }
                else                     // want to equip

                //cannot equip if adding on the item capcity to current capcity exceeds player capacity
                {
                    if (item.itemCapacity + currentPlayerCapacity > playerDataScript.itemCapacity)
                    {
                        //show a message to the user saying that cannot equip since capcity exceeds player capacity
                        openPopUp(noCapacityPopUpPanel);
                    }
                    else
                    {
                        currentPlayerCapacity += item.itemCapacity;
                        playerDataScript.hasEquipchips [playerItemIndex]       = true;
                        contentBuyButton.GetComponentInChildren <Text> ().text = "Unequip";

                        newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);
                        newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (Equipped)";
                    }
                }
            }
        }
        else if (itemType == SKILL)
        {
            if (playerDataScript.skillsList[playerItemIndex] > 0)
            {
                if (playerDataScript.hasEquipskills[playerItemIndex] == true)
                {
                    currentPlayerCapacity -= item.itemCapacity;                    //decrease item capacity

                    playerDataScript.hasEquipskills [playerItemIndex]      = false;
                    contentBuyButton.GetComponentInChildren <Text> ().text = "Equip";

                    newButtonComponent.image.color = Color.white;
                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText;
                }
                else
                {
                    //cannot equip if adding on the item capcity to current capcity exceeds player capacity
                    if (item.itemCapacity + currentPlayerCapacity > playerDataScript.itemCapacity)
                    {
                        //print ("capacity exceeds...");
                        //show a message to the user saying that cannot equip since capcity exceeds player capacity
                        openPopUp(noCapacityPopUpPanel);
                    }
                    else
                    {
                        currentPlayerCapacity += item.itemCapacity;
                        playerDataScript.hasEquipskills [playerItemIndex]      = true;
                        contentBuyButton.GetComponentInChildren <Text> ().text = "Unequip";

                        newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);
                        newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (Equipped)";
                    }
                }
            }
        }
        else if (itemType == SKIN)
        {
            if (playerDataScript.skinsList[playerItemIndex] > 0)
            {
                int equipCount = 0;

                foreach (bool equipped in playerDataScript.hasEquipSkins)
                {
                    if (equipped == true)
                    {
                        equipCount++;
                    }
                }


                if (playerDataScript.hasEquipSkins[playerItemIndex] == true)                //unequiping

                {
                    currentPlayerCapacity -= item.itemCapacity;                    //decrease item capacity

                    playerDataScript.hasEquipSkins [playerItemIndex]       = false;
                    contentBuyButton.GetComponentInChildren <Text> ().text = "Equip";

                    newButtonComponent.image.color = Color.white;
                    newButtonComponent.GetComponentInChildren <Text> ().text = buttonText;
                }
                else
                {
                    //cannot equip if adding on the item capcity to current capcity exceeds player capacity
                    if (item.itemCapacity + currentPlayerCapacity > playerDataScript.itemCapacity)
                    {
                        //show a message to the user saying that cannot equip since capcity exceeds player capacity
                        openPopUp(noCapacityPopUpPanel);
                    }
                    else if (equipCount == 1)                      //if you currently have an equiiped skin then cant equip another
                    {
                        openPopUp(onlyOneSkinPanel);
                    }
                    else
                    {
                        currentPlayerCapacity += item.itemCapacity;
                        playerDataScript.hasEquipSkins [playerItemIndex]       = true;
                        contentBuyButton.GetComponentInChildren <Text> ().text = "Unequip";

                        newButtonComponent.image.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);
                        newButtonComponent.GetComponentInChildren <Text> ().text = buttonText + " (Equipped)";
                    }
                }
            }
        }
    }