Ejemplo n.º 1
0
        /**
         * Retrieves the upgrade level of the virtual good with the given <code>goodItemId</code>.
         *
         * 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. <code>SingleUseVG</code> for "strength"
         *  2. <code>UpgradeVG</code> for strength 'level 1'.
         *  3. <code>UpgradeVG</code> for strength 'level 2'.
         *  4. <code>UpgradeVG</code> for strength 'level 3'.
         * In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
         *
         * @param goodItemId id of the virtual good whose upgrade level we want to know
         * @return upgrade level of the good with the given id
         * @throws VirtualItemNotFoundException
         */
        public static int getGoodUpgradeLevel(String goodItemId)
        {
            VirtualGood good      = (VirtualGood)StoreInfo.getVirtualItem(goodItemId);
            UpgradeVG   upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good);

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

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

            while (!first.Equal(upgradeVG))
            {
                first = (UpgradeVG)StoreInfo.getVirtualItem(first.getNextItemId());
                level++;
            }

            return(level);
        }
Ejemplo n.º 2
0
        /**
         * Upgrades the virtual good with the given <code>goodItemId</code> 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, or in
         *    other words, <code>buy()</code>s the next upgrade. 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, or in other words, <code>buy()</code>s the first upgrade in the series.
         *
         * @param goodItemId the id of the virtual good to be upgraded
         * @throws VirtualItemNotFoundException
         * @throws InsufficientFundsException
         */
        public static void upgradeVirtualGood(String goodItemId)
        {
            VirtualGood good      = (VirtualGood)StoreInfo.getVirtualItem(goodItemId);
            UpgradeVG   upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good);

            if (upgradeVG != null)
            {
                String nextItemId = upgradeVG.getNextItemId();
                if (String.IsNullOrEmpty(nextItemId))
                {
                    return;
                }
                UpgradeVG vgu = (UpgradeVG)StoreInfo.getVirtualItem(nextItemId);
                vgu.buy("");
            }
            else
            {
                UpgradeVG first = StoreInfo.getGoodFirstUpgrade(goodItemId);
                if (first != null)
                {
                    first.buy("");
                }
            }
        }