private void AddPurchasedItem(Product product) { if (PurchasedItems.ContainsKey(product.definition.id)) { PurchasedItems[product.definition.id]++; } else { PurchasedItems.Add(product.definition.id, 1); } }
public static void GetInventoryInternal(PlayfabSave saveInstance) { if (isRefreshing) { return; } isRefreshing = true; if (saveInstance != null) { saveInstance.onRefreshing.Invoke(); } PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), (result) => { isRefreshing = false; currencies = result.VirtualCurrency; items.Clear(); foreach (var item in result.Inventory) { items.Add(item.ItemId); } if (saveInstance != null) { saveInstance.onRefresh.Invoke(); } if (!isRefreshFirstTime) { isRefreshFirstTime = true; if (saveInstance != null) { saveInstance.onRefreshFirstTime.Invoke(); } } }, (error) => { isRefreshing = false; Debug.LogError("[Playfab Save] " + error.ErrorMessage); if (saveInstance != null) { saveInstance.onError.Invoke(error.ErrorMessage); } }); }
public void PurchaseItems(List <PurchasedItem> itemsToPurchase, bool removeFromCrate) { // Check all the prices before starting the transaction // to make sure the modifiers stay the same for the whole transaction Dictionary <ItemPrefab, int> buyValues = GetBuyValuesAtCurrentLocation(itemsToPurchase.Select(i => i.ItemPrefab)); foreach (PurchasedItem item in itemsToPurchase) { // Add to the purchased items var purchasedItem = PurchasedItems.Find(pi => pi.ItemPrefab == item.ItemPrefab); if (purchasedItem != null) { purchasedItem.Quantity += item.Quantity; } else { purchasedItem = new PurchasedItem(item.ItemPrefab, item.Quantity); PurchasedItems.Add(purchasedItem); } // Exchange money var itemValue = item.Quantity * buyValues[item.ItemPrefab]; campaign.Money -= itemValue; Location.StoreCurrentBalance += itemValue; if (removeFromCrate) { // Remove from the shopping crate var crateItem = ItemsInBuyCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab); if (crateItem != null) { crateItem.Quantity -= item.Quantity; if (crateItem.Quantity < 1) { ItemsInBuyCrate.Remove(crateItem); } } } } OnPurchasedItemsChanged?.Invoke(); }
public void PurchaseItems(List <PurchasedItem> itemsToPurchase, bool removeFromCrate) { foreach (PurchasedItem item in itemsToPurchase) { // Add to the purchased items var purchasedItem = PurchasedItems.Find(pi => pi.ItemPrefab == item.ItemPrefab); if (purchasedItem != null) { purchasedItem.Quantity += item.Quantity; } else { purchasedItem = new PurchasedItem(item.ItemPrefab, item.Quantity); PurchasedItems.Add(purchasedItem); } // Exchange money var itemValue = GetBuyValueAtCurrentLocation(item); campaign.Money -= itemValue; Location.StoreCurrentBalance += itemValue; if (removeFromCrate) { // Remove from the shopping crate var crateItem = ItemsInBuyCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab); if (crateItem != null) { crateItem.Quantity -= item.Quantity; if (crateItem.Quantity < 1) { ItemsInBuyCrate.Remove(crateItem); } } } } OnPurchasedItemsChanged?.Invoke(); }
private void AddPurchasedItem(PurchasedItem purchasedItem) { PurchasedItems.Add(purchasedItem); CartLines.Refresh(); UpdateView(); }
public override void AddPurchasedItem(string itemName) { Items.Add(itemName); SetPurchasedItems(Items); }