// 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); }
/* 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; } } } }