Example #1
0
    // player selling an item - takes an reference of the player to access their variables
    public bool SellItem(Player p, int id, int amount)
    {
        ItemContainer playerItem = p.inv.FindItemById(id);
        ItemContainer shopItem   = inv.FindItemById(id);

        // if the item the player is trying to sell doesn't exist. then return an error.
        if (playerItem == null)
        {
            //Debug.Log("ERROR: Item doesn't exist.");
            return(false);
        }

        // if the player is trying to sell a key item, dont let them.
        if (playerItem.Price == 0)
        {
            //Debug.Log(string.Format("{0} Cannot be sold!",playerItem.Name));
            return(false);
        }

        // selling the item
        if (p.inv.RemoveQuantity(playerItem.Id, amount))
        {
            p.AddMoney((playerItem.Price / 2) * amount);
            if (shopItem != null)
            {
                inv.AddQuantity(shopItem.Id, amount);
                //Debug.Log(string.Format("{0} added to shop stock!",playerItem.Name));
            }
            //Debug.Log(string.Format("Player successfully sold {0}!", playerItem.Name));
            return(true);
        }
        //Debug.Log(string.Format("Player couldn't sell {0}.", playerItem.Name));
        return(false);
    }
Example #2
0
 public bool Deposit(Player p, int id, int amount)
 {
     if (p.inv.RemoveQuantity(id, amount))
     {
         inv.AddQuantity(id, amount);
         return(true);
     }
     else
     {
         return(false);
     }
 }