コード例 #1
0
        /// <summary>
        /// Upgrades the virtual good with the given <c>goodItemId</c> by doing the following:
        /// 1. Checks if the good is currently upgraded or if this is the first time being upgraded.
        /// 2. If the good is currently upgraded, upgrades to the next upgrade in the series.
        /// In case there are no more upgrades available(meaning the current upgrade is the last available),
        /// the function returns.
        /// 3. If the good has never been upgraded before, the function upgrades it to the first
        /// available upgrade with the first upgrade of the series.
        /// </summary>
        /// <param name="goodItemId">Good item identifier.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static void UpgradeGood(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY Calling UpgradeGood with: " + goodItemId);
            VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId);

            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            if (upgradeVG != null)
            {
                String nextItemId = upgradeVG.NextItemId;
                if (string.IsNullOrEmpty(nextItemId))
                {
                    return;
                }
                UpgradeVG vgu = (UpgradeVG)StoreInfo.GetItemByItemId(nextItemId);
                vgu.Buy("");
            }
            else
            {
                UpgradeVG first = StoreInfo.GetFirstUpgradeForVirtualGood(goodItemId);
                if (first != null)
                {
                    first.Buy("");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the upgrade level of the virtual good with the given <c>goodItemId</c>.
        /// For Example:
        /// Let's say there's a strength attribute to one of the characters in your game and you provide
        /// your users with the ability to upgrade that strength on a scale of 1-3.
        /// This is what you've created:
        /// 1. <c>SingleUseVG</c> for "strength".
        /// 2. <c>UpgradeVG</c> for strength 'level 1'.
        /// 3. <c>UpgradeVG</c> for strength 'level 2'.
        /// 4. <c>UpgradeVG</c> for strength 'level 3'.
        /// In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
        /// </summary>
        /// <param name="goodItemId">Good item identifier.</param>
        /// <returns>The good upgrade level.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static int GetGoodUpgradeLevel(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "Checking " + goodItemId + " upgrade level");

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

            if (good == null)
            {
                SoomlaUtils.LogError(TAG, "You tried to get the level of a non-existant virtual good.");
                return(0);
            }
            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            if (upgradeVG == null)
            {
                return(0);                //no upgrade
            }

            UpgradeVG first = StoreInfo.GetFirstUpgradeForVirtualGood(goodItemId);
            int       level = 1;

            while (first.ItemId != upgradeVG.ItemId)
            {
                first = (UpgradeVG)StoreInfo.GetItemByItemId(first.NextItemId);
                level++;
            }

            return(level);
        }