Exemple #1
0
    /* Checks to see if the player is holding the gun, and if there are
     * any bullets, the player will shoot. Player loses stamina and a bullet from
     * their inventory.
     */
    private void ShootingCheck()
    {
        if (heldItem == null)
        {
            return;
        }

        if (heldItem != inv.FindItemById(6))
        {
            return;
        }

        if (inv.FindItemById(1) != null && inv.FindItemById(1).Value > 0)
        {
            if (currStamina > 0)
            {
                shootScript.Shoot(transform);
                if (shootScript.isShooting)
                {
                    LoseStamina(5f);
                    inv.RemoveQuantity(1, 1);
                    shootScript.isShooting = false;
                }
            }
        }
    }
Exemple #2
0
 public bool Withdraw(Player p, int id, int amount)
 {
     if (inv.RemoveQuantity(id, amount))
     {
         p.inv.AddQuantity(id, amount);
         return(true);
     }
     else
     {
         Debug.Log("Let player know that they can't withdraw the items.");
         return(false);
     }
 }
Exemple #3
0
    // buy an item - needs player to access their properties, the id of the item being bought, and amount of the item being bought
    public bool BuyItem(Player player, int id, int amount)
    {
        // Get the total value of the item being bought (price * amount).
        int total = inv.FindItemById(id).Price *amount;

        // Make sure the total money isnt greater than the player's current money
        if (total > player.currMoney)
        {
            //Debug.Log(string.Format("Couldn't buy {0} amount of item id: {1}. Player doesn't have enough money!",amount,id));
            // Since the player isn't able to buy, return false since buying failed.
            return(false);
        }

        if (inv.RemoveQuantity(id, amount))
        {
            ItemContainer item = inv.FindItemById(id);
            player.inv.AddQuantityByContainer(item, amount);
            player.currMoney -= total;
            return(true);
        }

        //Debug.Log(string.Format("Couldn't buy {0} amount of item id: {1}. Shop doesn't have enough in stock!", amount, id));
        return(false);
    }