/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = getTargetVirtualItem(); if (item == null) { return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true); if (!checkTargetBalance(item)) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events. StoreEvents.Instance.RunLater(() => { eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print(), true); }); }
/** VIRTUAL ITEMS **/ /// <summary> /// Gives your user the given amount of the virtual item with the given <c>itemId</c>. /// For example, when your user plays your game for the first time you GIVE him/her 1000 gems. /// /// NOTE: This action is different than buy - /// You use <c>give(int amount)</c> to give your user something for free. /// You use <c>buy()</c> to give your user something and you get something in return. /// </summary> /// <param name="itemId">Id of the item to be given.</param> /// <param name="amount">Amount of the item to be given.</param> /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception> public static void GiveItem(string itemId, int amount) { SoomlaUtils.LogDebug(TAG, "Giving: " + amount + " pieces of: " + itemId); VirtualItem item = StoreInfo.GetItemByItemId(itemId); item.Give(amount); }
protected override int _add(VirtualItem item, int amount, bool notify) { int retBalance; SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId); retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().add(vi, amount, notify); return retBalance; }
protected override int _remove(VirtualItem item, int amount, bool notify) { int retBalance; retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().remove(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId), amount, notify); return(retBalance); }
protected override int _getBalance(VirtualItem item) { int retBalance; retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().getBalance(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId)); return(retBalance); }
/// <summary> /// Retrieves the balance of the given virtual item. /// </summary> /// <returns>The balance of the required virtual item.</returns> /// <param name="item">The required virtual item.</param> public static int GetBalance(VirtualItem item) { SoomlaUtils.LogDebug(TAG, "fetching balance for virtual item with itemId: " + item.ItemId); return(instance._getBalance(item)); }
protected virtual int _add(VirtualItem item, int amount, bool notify) { #if UNITY_EDITOR string itemId = item.ItemId; int balance = _getBalance(item); if (balance < 0) /* in case the user "adds" a negative value */ { balance = 0; amount = 0; } string balanceStr = "" + (balance + amount); string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance + amount, amount); } return(balance + amount); #else return(0); #endif }
protected virtual int _setBalance(VirtualItem item, int balance, bool notify) { #if UNITY_EDITOR int oldBalance = _getBalance(item); if (oldBalance == balance) { return(balance); } string itemId = item.ItemId; string balanceStr = "" + balance; string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance, 0); } return(balance); #else return(0); #endif }
protected override int _getBalance(VirtualItem item) { int retBalance; SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId); retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getBalance(vi); return retBalance; }
protected override int _getBalance(VirtualItem item) { int retBalance; SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId); retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getBalance(vi); return(retBalance); }
protected override int _getBalance(VirtualItem item) { int outBalance = 0; int err = vgStorage_GetBalance(item.ItemId, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return(outBalance); }
protected override int _setBalance(VirtualItem item, int balance, bool notify) { int outBalance = 0; int err = vcStorage_SetBalance(item.ItemId, balance, notify, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return(outBalance); }
protected override int _remove(VirtualItem item, int amount, bool notify) { int outBalance = 0; int err = vgStorage_Remove(item.ItemId, amount, notify, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return(outBalance); }
protected override int _add(VirtualItem item, int amount, bool notify) { int retBalance; SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId); retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().add(vi, amount, notify); return(retBalance); }
/// <summary> /// Checks if there is enough funds to afford the <code>PurchasableVirtualItem</code>. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <returns>True if there are enough funds to afford the virtual item with the given item id </returns> public override bool CanAfford() { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Checking affordability of " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem targetItem = getTargetVirtualItem(); return(checkTargetBalance(targetItem)); }
/// <summary> /// Replaces the given virtual item, and then saves the store's metadata /// (if requested). /// </summary> /// <param name="virtualItem">the virtual item to replace.</param> /// <param name="saveToDB">should the virtual item be persisted to local DB</param> public static void Save(VirtualItem virtualItem, bool saveToDB = true) { replaceVirtualItem(virtualItem); if (saveToDB) { Save(); } }
protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded) { JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", item.ItemId); eventJSON.AddField("balance", balance); eventJSON.AddField("amountAdded", amountAdded); StoreEvents.Instance.onCurrencyBalanceChanged(eventJSON.print()); }
protected override int _remove(VirtualItem item, int amount, bool notify){ int retBalance; AndroidJNI.PushLocalFrame(100); using(AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using(AndroidJavaObject jniVCStorage = jniStorageManager.CallStatic<AndroidJavaObject>("getVirtualCurrencyStorage")) { retBalance = jniVCStorage.Call<int>("remove", item.ItemId, amount, notify); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); return retBalance; }
private VirtualItem getTargetVirtualItem() { VirtualItem item = null; try { item = StoreInfo.GetItemByItemId(TargetItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !"); } return(item); }
/// <summary> /// Gets the purchasable item with the given <c>productId</c>. /// </summary> /// <param name="productId">Product id.</param> /// <returns>Purchasable virtual item with the given id.</returns> /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception> override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId) { VirtualItem vi = null; AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>( new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) { vi = VirtualItem.factoryItemFromJNI(jniVirtualItem); } AndroidJNI.PopLocalFrame(IntPtr.Zero); return((PurchasableVirtualItem)vi); }
protected override int _getBalance(VirtualItem item) { int retBalance; AndroidJNI.PushLocalFrame(100); using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using (AndroidJavaObject jniVCStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualCurrencyStorage")) { retBalance = jniVCStorage.Call <int>("getBalance", item.ItemId); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); return(retBalance); }
/// <summary> /// Retrieves the balance of the virtual item with the given <c>itemId</c>. /// </summary> /// <param name="itemId">Id of the virtual item to be fetched.</param> /// <returns>Balance of the virtual item with the given item id.</returns> /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception> public static int GetItemBalance(string itemId) { int amount; if (localItemBalances.TryGetValue(itemId, out amount)) { return(amount); } VirtualItem item = StoreInfo.GetItemByItemId(itemId); return(item.GetBalance()); }
protected override int _remove(VirtualItem item, int amount, bool notify) { int retBalance; AndroidJNI.PushLocalFrame(100); using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using (AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualGoodsStorage")) { retBalance = jniVGStorage.Call <int>("remove", item.ItemId, amount, notify); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); return(retBalance); }
/// <summary> /// Gets the purchasable item with the given <c>productId</c>. /// </summary> /// <param name="productId">Product id.</param> /// <returns>Purchasable virtual item with the given id.</returns> /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception> override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId) { IntPtr p = IntPtr.Zero; int err = storeInfo_GetPurchasableItemWithProductId(productId, out p); IOS_ErrorCodes.CheckAndThrowException(err); string nonConsJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); JSONObject obj = new JSONObject(nonConsJson); return((PurchasableVirtualItem)VirtualItem.factoryItemFromJSONObject(obj)); }
/// <summary> /// Gets the item with the given <c>itemId</c>. /// </summary> /// <param name="itemId">Item id.</param> /// <returns>Item with the given id.</returns> /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception> override protected VirtualItem _getItemByItemId(string itemId) { IntPtr p = IntPtr.Zero; int err = storeInfo_GetItemByItemId(itemId, out p); IOS_ErrorCodes.CheckAndThrowException(err); string json = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); SoomlaUtils.LogDebug(TAG, "Got json: " + json); JSONObject obj = new JSONObject(json); return(VirtualItem.factoryItemFromJSONObject(obj)); }
/** Unity-Editor Functions **/ protected virtual int _getBalance(VirtualItem item) { #if UNITY_EDITOR string itemId = item.ItemId; string key = keyBalance(itemId); string val = PlayerPrefs.GetString(key); int balance = 0; if (!string.IsNullOrEmpty(val)) { balance = int.Parse(val); } SoomlaUtils.LogDebug(TAG, "the balance for " + item.ItemId + " is " + balance); return balance; #else return 0; #endif }
/// <summary> /// Fetches the virtual goods of your game. /// </summary> /// <returns>All virtual goods.</returns> override protected List <VirtualGood> _getVirtualGoods() { List <VirtualGood> virtualGoods = new List <VirtualGood>(); AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniVirtualGoods = new AndroidJavaClass("com.soomla.store.data.StoreInfo").CallStatic <AndroidJavaObject>("getGoods")) { for (int i = 0; i < jniVirtualGoods.Call <int>("size"); i++) { AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniGood = jniVirtualGoods.Call <AndroidJavaObject>("get", i)) { virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJNI(jniGood)); } AndroidJNI.PopLocalFrame(IntPtr.Zero); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); return(virtualGoods); }
/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = null; try { item = StoreInfo.GetItemByItemId(TargetItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !"); return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print()); int balance = item.GetBalance(); if (item is VirtualCurrency) { balance = VirtualCurrencyStorage.GetBalance(item); } else { balance = VirtualGoodsStorage.GetBalance(item); } if (balance < Amount) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print()); }
/** Unity-Editor Functions **/ protected virtual int _getBalance(VirtualItem item) { #if UNITY_EDITOR string itemId = item.ItemId; string key = keyBalance(itemId); string val = PlayerPrefs.GetString(key); int balance = 0; if (!string.IsNullOrEmpty(val)) { balance = int.Parse(val); } SoomlaUtils.LogDebug(TAG, "the balance for " + item.ItemId + " is " + balance); return(balance); #else return(0); #endif }
protected virtual int _add(VirtualItem item, int amount, bool notify){ #if UNITY_EDITOR string itemId = item.ItemId; int balance = _getBalance(item); if (balance < 0) { /* in case the user "adds" a negative value */ balance = 0; amount = 0; } string balanceStr = "" + (balance + amount); string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance+amount, amount); } return balance + amount; #else return 0; #endif }
/// <summary> /// Fetches the virtual goods of your game. /// </summary> /// <returns>All virtual goods.</returns> override protected List <VirtualGood> _getVirtualGoods() { List <VirtualGood> virtualGoods = new List <VirtualGood>(); IntPtr p = IntPtr.Zero; int err = storeInfo_GetVirtualGoods(out p); IOS_ErrorCodes.CheckAndThrowException(err); string goodsJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); SoomlaUtils.LogDebug(TAG, "Got json: " + goodsJson); JSONObject goodsArr = new JSONObject(goodsJson); foreach (JSONObject obj in goodsArr.list) { virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJSONObject(obj)); } return(virtualGoods); }
/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = null; try { item = StoreInfo.GetItemByItemId(TargetItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !"); return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true); int balance = item.GetBalance(); if (balance < Amount) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events. StoreEvents.Instance.RunLater(() => { eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print(), true); }); }
protected virtual int _setBalance(VirtualItem item, int balance, bool notify) { #if UNITY_EDITOR int oldBalance = _getBalance(item); if (oldBalance == balance) { return balance; } string itemId = item.ItemId; string balanceStr = "" + balance; string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance, 0); } return balance; #else return 0; #endif }
protected virtual int _remove(VirtualItem item, int amount, bool notify) { #if UNITY_EDITOR string itemId = item.ItemId; int balance = _getBalance(item) - amount; if (balance < 0) { balance = 0; amount = 0; } string balanceStr = "" + balance; string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance, -1 * amount); } return(balance); #else return(0); #endif }
/// <summary> /// Adds the given amount of items to the storage, and if notify is true /// posts the change in the balance to the event bus. /// </summary> /// <param name="item">the required virtual item.</param> /// <param name="amount">the amount of items to add.</param> /// <param name="notify">notify if true posts balance change event.</param> public static int Add(VirtualItem item, int amount, bool notify){ SoomlaUtils.LogDebug(TAG, "adding " + amount + " " + item.ItemId); return instance._add(item, amount, notify); }
/// <summary> /// Same as the other SetBalance but with "notify". /// </summary> /// <param name="item">the required virtual item.</param> /// <param name="balance">the new balance to be set.</param> /// <param name="notify">if notify is true post balance change event.</param> /// <returns>the balance of the required virtual item</returns> public static int SetBalance(VirtualItem item, int balance, bool notify){ SoomlaUtils.LogDebug(TAG, "setting balance " + balance + " to " + item.ItemId + "."); return instance._setBalance(item, balance, notify); }
/// <summary> /// Adds the given amount of items to the storage. /// </summary> /// <param name="item">the required virtual item.</param> /// <param name="amount">the amount of items to add.</param> public static int Add(VirtualItem item, int amount){ return Add(item, amount, true); }
/// <summary> /// Retrieves the balance of the given virtual item. /// </summary> /// <returns>The balance of the required virtual item.</returns> /// <param name="item">The required virtual item.</param> public static int GetBalance(VirtualItem item){ SoomlaUtils.LogDebug(TAG, "fetching balance for virtual item with itemId: " + item.ItemId); return instance._getBalance(item); }
/// <summary> /// Sets the balance of the given virtual item to be the given balance, and if notify is true /// posts the change in the balance to the event bus. /// </summary> /// <param name="item">the required virtual item.</param> /// <param name="balance">the new balance to be set.</param> /// <returns>the balance of the required virtual item</returns> public static int SetBalance(VirtualItem item, int balance){ return SetBalance(item, balance, true); }
protected virtual int _remove(VirtualItem item, int amount, bool notify){ #if UNITY_EDITOR string itemId = item.ItemId; int balance = _getBalance(item) - amount; if (balance < 0) { balance = 0; amount = 0; } string balanceStr = "" + balance; string key = keyBalance(itemId); PlayerPrefs.SetString(key, balanceStr); if (notify) { postBalanceChangeEvent(item, balance, -1*amount); } return balance; #else return 0; #endif }
protected override int _setBalance(VirtualItem item, int balance, bool notify) { int outBalance = 0; int err = vgStorage_SetBalance(item.ItemId, balance, notify, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return outBalance; }
protected override int _getBalance(VirtualItem item) { int retBalance; AndroidJNI.PushLocalFrame(100); using(AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using(AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic<AndroidJavaObject>("getVirtualGoodsStorage")) { retBalance = jniVGStorage.Call<int>("getBalance", item.ItemId); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); return retBalance; }
protected override int _add(VirtualItem item, int amount, bool notify){ int outBalance = 0; int err = vgStorage_Add(item.ItemId, amount, notify, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return outBalance; }
protected override int _getBalance(VirtualItem item) { int retBalance; retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().getBalance(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId)); return retBalance; }
protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded) { JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", item.ItemId); eventJSON.AddField("balance", balance); eventJSON.AddField("amountAdded", amountAdded); StoreEvents.Instance.onGoodBalanceChanged(eventJSON.print()); }
protected abstract void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded);
private bool checkTargetBalance(VirtualItem item) { int balance = item.GetBalance (); return balance >= Amount; }
// When insufficient funds, page opens shop void onNotEnoughTargetItem(VirtualItem item) { if (item.ItemId == "seed") UIServer.main.ShowPage ("Store"); StoreInventory.GetItemBalance (item.ID); }
/// <summary> /// Removes the given amount from the given virtual item's balance. /// </summary> /// <param name="item">the virtual item to remove the given amount from.</param> /// <param name="amount">the amount to remove.</param> public static int Remove(VirtualItem item, int amount){ return Remove(item, amount, true); }
protected override int _getBalance(VirtualItem item) { int outBalance = 0; int err = vgStorage_GetBalance(item.ItemId, out outBalance); IOS_ErrorCodes.CheckAndThrowException(err); return outBalance; }
/// <summary> /// Removes the given amount from the given virtual item's balance. /// </summary> /// <param name="item">the virtual item to remove the given amount from.</param> /// <param name="amount">the amount to remove.</param> /// <param name="notify">notify is true post balance change event</para> public static int Remove(VirtualItem item, int amount, bool notify){ SoomlaUtils.LogDebug(TAG, "Removing " + amount + " " + item.ItemId + "."); return instance._remove(item, amount, true); }
private bool checkTargetBalance(VirtualItem item) { int balance = item.GetBalance(); return(balance > Amount); }
protected override int _remove(VirtualItem item, int amount, bool notify){ int retBalance; retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().remove(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId), amount, notify); return retBalance; }
/// <summary> /// Replaces the given virtual item, and then saves the store's metadata. /// </summary> /// <param name="virtualItem">the virtual item to replace.</param> public static void Save(VirtualItem virtualItem) { replaceVirtualItem(virtualItem); Save(); }
true); // Last #endregion #endregion #region Private Functions private static VirtualGood CreateUpgrade(VirtualItem upgradedGood, string upgradeItemId, string upgradeName, string upgradeDescription, int level, int price, bool isLast = false) { var prevItemId = level > 1 ? upgradeItemId + (level - 1) : null; var nextItemId = isLast ? null : upgradeItemId + (level + 1); return new UpgradeVG( upgradedGood.ItemId, // Good Item ID nextItemId, // Next Upgrade Item ID prevItemId, // Previous Upgrade Item ID upgradeName, // Name upgradeDescription + level, // Description upgradeItemId + level, // Item ID new PurchaseWithVirtualItem( // Purchase type Coin.ItemId, // Virtual item to pay with price) // Payment amount ); }
private bool checkTargetBalance (VirtualItem item) { int balance = StoreInventory.GetItemBalance(item.ItemId); return balance >= Amount; }