Exemple #1
0
        /// <summary>
        /// Removes all upgrades from the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">Id of the good whose upgrades are to be removed.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static void RemoveGoodUpgrades(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY Calling RemoveGoodUpgrades with: " + goodItemId);

            List <UpgradeVG> upgrades = StoreInfo.GetUpgradesForVirtualGood(goodItemId);

            foreach (UpgradeVG upgrade in upgrades)
            {
                VirtualGoodsStorage.Remove(upgrade, 1, true);
            }
            VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId);

            VirtualGoodsStorage.RemoveUpgrades(good);
        }
Exemple #2
0
        /// <summary>
        /// Takes upgrade from the user, or in other words DOWNGRADES the associated
        /// <code>VirtualGood</code> (mGood).
        /// Checks if the current Upgrade is really associated with the <code>VirtualGood</code> and:
        /// </summary>
        /// <param name="amount">NOT USED HERE!.</param>
        /// <param name="notify">see parent.</param>
        public override int Take(int amount, bool notify)
        {
            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId
                                     + " doesn't exist! Can't downgrade.");
                return(0);
            }

            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            // Case: Upgrade is not assigned to this Virtual Good
            if (upgradeVG != this)
            {
                SoomlaUtils.LogError(TAG, "You can't take an upgrade that's not currently assigned."
                                     + "The UpgradeVG " + Name + " is not assigned to " + "the VirtualGood: "
                                     + good.Name);
                return(0);
            }

            if (!string.IsNullOrEmpty(PrevItemId))
            {
                UpgradeVG prevUpgradeVG = null;
                // Case: downgrade is not possible because previous upgrade does not exist
                try {
                    prevUpgradeVG = (UpgradeVG)StoreInfo.GetItemByItemId(PrevItemId);
                } catch (VirtualItemNotFoundException) {
                    SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + PrevItemId
                                         + " doesn't exist! Can't downgrade.");
                    return(0);
                }
                // Case: downgrade is successful!
                SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to: "
                                     + prevUpgradeVG.Name);
                VirtualGoodsStorage.AssignCurrentUpgrade(good, prevUpgradeVG, notify);
            }

            // Case: first Upgrade in the series - so we downgrade to NO upgrade.
            else
            {
                SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to NO-UPGRADE");
                VirtualGoodsStorage.RemoveUpgrades(good, notify);
            }

            return(base.Take(amount, notify));
        }