Пример #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);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Checks if the virtual good with the given <c>goodItemId</c> is currently equipped.
        /// </summary>
        /// <param name="goodItemId">Id of the virtual good who we want to know if is equipped.</param>
        /// <returns>True if the virtual good is equipped, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static bool IsVirtualGoodEquipped(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "Checking if " + goodItemId + " is equipped");

            EquippableVG good = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

            return(VirtualGoodsStorage.IsEquipped(good));;
        }
Пример #3
0
        /// <summary>
        /// Checks currently equipped good in given <c>category</c>
        /// </summary>
        /// <param name="category">Category we want to check</param>
        /// <returns>EquippableVG otherwise null</returns>
        public static EquippableVG GetEquippedVirtualGood(VirtualCategory category)
        {
            SoomlaUtils.LogDebug(TAG, "Checking equipped goood in " + category.Name + " category");

            foreach (string goodItemId in category.GoodItemIds)
            {
                EquippableVG good = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

                if (good != null && good.Equipping == EquippableVG.EquippingModel.CATEGORY &&
                    VirtualGoodsStorage.IsEquipped(good) &&
                    StoreInfo.GetCategoryForVirtualGood(goodItemId) == category)
                {
                    return(good);
                }
            }
            SoomlaUtils.LogError(TAG, "There is no virtual good equipped in " + category.Name + " category");
            return(null);
        }