Ejemplo n.º 1
0
    /*public void RestoreItems(int[] restoredSlotID, int[] restoredValue, int[] restoredName){
     *      slotID [indexID] = item.itemID;
     *      slotValue [indexID] = item.itemValue;
     *      slotName [indexID] = item.itemName;
     *      slotDesc [indexID] = item.itemDesc;
     *      slotSprite [indexID] = item.itemSprite;
     *      slotType [indexID] = item.itemType;
     *      slotIcon[indexID].sprite = item.itemSprite;
     *      slotStack [indexID]++;
     *      EnableItem(ID);
     * }*/

    public void PurchaseItem(int ID)      //This method allows the player to purchase an item based on value of given item ID
    {
        BarController coinScript = this.gameObject.GetComponent <BarController>();

        if (InventoryFull() == false)
        {
            Debug.Log(coinScript.GetCoins());
            Item item = ItemDatabase.GetItem(storeItems[ID]);
            Debug.Log(item.itemValue);
            if (coinScript.GetCoins() >= item.itemValue)
            {
                //Subtract the correct amount of coins
                coinScript.SetCoins(coinScript.GetCoins() - item.itemValue);
                ItemClicked(storeItems[ID]);
                coinScript.InvokeSound(coinScript.craftSound);
                StartCoroutine(coinScript.InvokeMessage("+ITEM!", 1f));
            }
            else
            {
                //YOU DONT HAVE ENOUGH COINS
                coinScript.InvokeSound(coinScript.errorSound);
                StartCoroutine(coinScript.InvokeMessage("NOT ENOUGH COINS!", 1f));
            }
        }
        else
        {
            coinScript.InvokeSound(coinScript.errorSound);
            StartCoroutine(coinScript.InvokeMessage("INVENTORY FULL!", 1f));
        }
    }
Ejemplo n.º 2
0
    public void SetData()
    {
        Debug.Log("Set player data");
        //Set player health
        BarController player = GameObject.Find("Captain").GetComponent <BarController>();

        player.SetHealth(playerHealth);

        //Set Coins
        player.SetCoins(playerCoins);

        //Set Resources
        player.SetResources(playerResources);

        //Set Score
        player.SetScore(playerScore);

        //Set Crafting Cost
        player.craftingCost = playerCraftingCost;

        //Set key
        player.foundKey = playerKey;

        //Set Player Revived State
        player.SetPlayerRevived(playerRevived);

        //Set Extra Stats
        player.upgradedDamage  = playerUpgradedAttack;
        player.upgradedDefence = playerUpgradedDefence;
        player.upgradedHealth  = playerUpgradedHealth;
        player.upgradedSpeed   = playerUpgradedSpeed;

        //Set challenge counter
        player.challengeCounters = playerChallengeCounter;

        //Set Inventory
        PlayerInventory inventoryScript = GameObject.Find("Captain").GetComponent <PlayerInventory>();

        inventoryScript.slotID     = this.slotID;
        inventoryScript.slotValue  = this.slotValue;
        inventoryScript.slotName   = this.slotName;
        inventoryScript.slotDesc   = this.slotDesc;
        inventoryScript.slotSprite = this.slotSprite;
        inventoryScript.slotType   = this.slotType;
        inventoryScript.slotStack  = this.slotStack;
        //inventoryScript.slotIcon = this.slotIcon;
        for (int i = 0; i < playerInventory.Length; i++)
        {
            inventoryScript.slotIcon[i].sprite = inventoryScript.slotSprite[i];
            if (inventoryScript.slotIcon[i].sprite == null)
            {
                inventoryScript.slotIcon[i].sprite = inventoryScript.emptySlotSprite;
            }
            inventoryScript.EnableItem(playerInventory[i]);
        }

        //Set Villagers
        GameObject.Find("PickUpRange").GetComponent <PlayerInteract>().UnlockedVillagers = villageState;

        //Set Key
    }