public void Buy(BuildableObject rideOrShop, Wallet fromWallet, ParkInventory toInventory) { if (fromWallet.Balance < rideOrShop.Cost) { throw new ArgumentException("Wallet does not have enough money! Check balance in the UI before calling this method."); } if (toInventory.Contains(rideOrShop)) { throw new ArgumentException("Inventory already contains this item! Check if player owns the item before calling this method."); } if (rideOrShop is Ride) { Ride ride = rideOrShop as Ride; toInventory.Rides.Add(ride); purchasedRides.Add(ride); } else if (rideOrShop is Shop) { Shop shop = rideOrShop as Shop; toInventory.Shops.Add(shop); purchasedShops.Add(shop); } // Always deduct the money fromWallet.SubtractFromBalance(rideOrShop.Cost, "Bought " + rideOrShop.Name); }
// Takes the current inventory, so already purchased rides can be hidden public List <Shop> GetBuyableShops(ParkInventory currentInventory) { List <Shop> buyableShops = new List <Shop>(); foreach (BuildableObject item in purchasableObjects) { if (!(item is Shop)) { continue; } // If the player already has the item if (currentInventory.Contains(item)) { continue; } // If the item has already been purchased if (purchasedObjects.Contains(item)) { continue; } buyableShops.Add(item as Shop); } return(buyableShops); }
// Takes the current inventory, so already purchased rides can be hidden public List <Ride> GetBuyableRides(ParkInventory currentInventory) { List <Ride> buyableRides = new List <Ride>(); foreach (Ride item in purchasableRides) { // If the player already has the item if (currentInventory.Contains(item)) { continue; } // If the item has already been purchased if (purchasedRides.Contains(item)) { continue; } buyableRides.Add(item); } return(buyableRides); }