Example #1
0
        /// <summary>
        /// This function refreshes a local set of objects that will hold your user's balances in memory for quick
        /// and more efficient fetching for your game UI.
        /// This way, we save many JNI or static calls to native platforms.
        ///
        /// NOTE: You don't need to call this function as it's automatically called when the game initializes.
        /// NOTE: This is less useful when you work in editor.
        /// </summary>
        public static void RefreshLocalInventory()
        {
            SoomlaUtils.LogDebug(TAG, "Refreshing local inventory");

            localItemBalances  = new Dictionary <string, int> ();
            localUpgrades      = new Dictionary <string, LocalUpgrade>();
            localEquippedGoods = new HashSet <string>();

            foreach (VirtualCurrency item in StoreInfo.Currencies)
            {
                localItemBalances[item.ItemId] = VirtualCurrencyStorage.GetBalance(item);
            }

            foreach (VirtualGood item in StoreInfo.Goods)
            {
                localItemBalances[item.ItemId] = VirtualGoodsStorage.GetBalance(item);

                UpgradeVG upgrade = VirtualGoodsStorage.GetCurrentUpgrade(item);
                if (upgrade != null)
                {
                    int upgradeLevel = GetGoodUpgradeLevel(item.ItemId);
                    localUpgrades.AddOrUpdate(item.ItemId, new LocalUpgrade {
                        itemId = upgrade.ItemId, level = upgradeLevel
                    });
                }

                if (item is EquippableVG)
                {
                    if (VirtualGoodsStorage.IsEquipped((EquippableVG)item))
                    {
                        localEquippedGoods.Add(item.ItemId);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Takes a curtain amount of <c>VirtualCurrency</c> according to the given amount and the definition of this pack.
        /// </summary>
        /// <param name="amount">the amount of the specific item to be taken.</param>
        /// <param name="notify">notify of change in user's balance of current virtual item.</param>
        public override int Take(int amount, bool notify)
        {
            VirtualCurrency currency = null;

            try {
                currency = (VirtualCurrency)StoreInfo.GetItemByItemId(CurrencyItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualCurrency with itemId: " + CurrencyItemId +
                                     " doesn't exist! Can't take this pack.");
                return(0);
            }
            return(VirtualCurrencyStorage.Remove(currency, CurrencyAmount * amount, notify));
        }
        /// <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());
        }
Example #4
0
 /// <summary>
 /// Will fetch the balance for the current currency according to its type.
 /// </summary>
 /// <returns>The balance.</returns>
 public override int GetBalance()
 {
     return(VirtualCurrencyStorage.GetBalance(this));
 }
Example #5
0
 /// <summary>
 /// Resets the currency balance to a given balance.
 /// </summary>
 /// <returns>The balance after the reset process.</returns>
 /// <param name="balance">The balance of the current virtual item.</param>
 /// <param name="notify">Notify of change in user's balance of current virtual item.</param>
 public override int ResetBalance(int balance, bool notify)
 {
     return(VirtualCurrencyStorage.SetBalance(this, balance, notify));
 }
Example #6
0
 /// <summary>
 /// Takes a curtain amount of this currency.
 /// </summary>
 /// <param name="amount">the amount of the specific item to be taken.</param>
 /// <param name="notify">notify of change in user's balance of current virtual item.</param>
 public override int Take(int amount, bool notify)
 {
     return(VirtualCurrencyStorage.Remove(this, amount, notify));
 }
Example #7
0
 /// <summary>
 /// Gives a curtain amount of this currency.
 /// </summary>
 /// <param name="amount">amount the amount of the specific item to be given.</param>
 /// <param name="notify">notify of change in user's balance of current virtual item.</param>
 public override int Give(int amount, bool notify)
 {
     return(VirtualCurrencyStorage.Add(this, amount, notify));
 }