Ejemplo n.º 1
0
        /**
         * Removes the non-consumable item with the given <code>nonConsItemId</code> from the
         * non-consumable items storage.
         *
         * @param nonConsItemId the non-consumable to be removed to the database
         * @throws VirtualItemNotFoundException
         * @throws ClassCastException
         */
        public static void removeNonConsumableItem(String nonConsItemId)
        {
            NonConsumableItem nonConsumableItem =
                (NonConsumableItem)StoreInfo.getVirtualItem(nonConsItemId);

            StorageManager.getNonConsumableItemsStorage().remove(nonConsumableItem);
        }
Ejemplo n.º 2
0
        /**
         * Buys the virtual item with other virtual items.
         *
         * @throws com.soomla.store.exceptions.InsufficientFundsException
         */
        public override void buy(String payload)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to buy a " + getAssociatedItem().getName() + " with "
                                 + mAmount + " pieces of " + mTargetItemId);

            VirtualItem item = null;

            try {
                item = StoreInfo.getVirtualItem(mTargetItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !" + " " + e.Message);
                return;
            }

            StoreEvents.GetInstance().PostItemPurchaseStartedEvent(getAssociatedItem());

            VirtualItemStorage storage = StorageManager.getVirtualItemStorage(item);

            Debug.Assert(storage != null);
            int balance = storage.getBalance(item);

            if (balance < mAmount)
            {
                throw new InsufficientFundsException(mTargetItemId);
            }

            storage.remove(item, mAmount);

            getAssociatedItem().give(1);
            //BusProvider.getInstance().post(new OnItemPurchasedEvent(getAssociatedItem(), payload));
            StoreEvents.GetInstance().PostItemPurchasedEvent(getAssociatedItem(), payload);
        }
Ejemplo n.º 3
0
        /** NON CONSUMABLES **/

        /**
         * Checks if the non-consumable with the given <code>nonConsItemId</code> exists.
         *
         * @param nonConsItemId the non-consumable to check if exists in the database
         * @return true if non-consumable item with nonConsItemId exists, false otherwise
         * @throws VirtualItemNotFoundException
         * @throws ClassCastException
         */
        public static bool nonConsumableItemExists(String nonConsItemId)
        {
            NonConsumableItem nonConsumableItem =
                (NonConsumableItem)StoreInfo.getVirtualItem(nonConsItemId);

            return(StorageManager.getNonConsumableItemsStorage().nonConsumableItemExists(
                       nonConsumableItem));
        }
Ejemplo n.º 4
0
        /**
         * Equips the current <code>EquippableVG</code>.
         * The equipping is done according to the equipping model ('GLOBAL', 'CATEGORY', or 'LOCAL').
         *
         * @param notify if true post event to bus
         * @throws NotEnoughGoodsException
         */
        public void equip(bool notify)
        {
            // only if the user has bought this EquippableVG, the EquippableVG is equipped.
            if (StorageManager.getVirtualGoodsStorage().getBalance(this) > 0)
            {
                if (mEquippingModel == EquippingModel.CATEGORY)
                {
                    VirtualCategory category = null;
                    try {
                        category = StoreInfo.getCategory(getItemId());
                    } catch (VirtualItemNotFoundException e) {
                        SoomlaUtils.LogError(TAG,
                                             "Tried to unequip all other category VirtualGoods but there was no " +
                                             "associated category. virtual good itemId: " + getItemId() + " " + e.Message);
                        return;
                    }

                    foreach (String goodItemId in category.getGoodsItemIds())
                    {
                        EquippableVG equippableVG = null;
                        try {
                            equippableVG = (EquippableVG)StoreInfo.getVirtualItem(goodItemId);

                            if (equippableVG != null && equippableVG != this)
                            {
                                equippableVG.unequip(notify);
                            }
                        } catch (VirtualItemNotFoundException e) {
                            SoomlaUtils.LogError(TAG, "On equip, couldn't find one of the itemIds "
                                                 + "in the category. Continuing to the next one. itemId: "
                                                 + goodItemId + " " + e.Message);
                        } catch (InvalidCastException ex) {
                            SoomlaUtils.LogDebug(TAG, "On equip, an error occurred. It's a debug "
                                                 + "message b/c the VirtualGood may just not be an EquippableVG. "
                                                 + "itemId: " + goodItemId + " " + ex.Message);
                        }
                    }
                }
                else if (mEquippingModel == EquippingModel.GLOBAL)
                {
                    foreach (VirtualGood good in StoreInfo.getGoods())
                    {
                        if (good != this &&
                            good is EquippableVG)
                        {
                            ((EquippableVG)good).unequip(notify);
                        }
                    }
                }

                StorageManager.getVirtualGoodsStorage().equip(this, notify);
            }
            else
            {
                throw new NotEnoughGoodsException(getItemId());
            }
        }
Ejemplo n.º 5
0
 /**
  * Upgrades the good with the given <code>upgradeItemId</code> for FREE (you are GIVING him/her
  * the upgrade). In case that the good is not an upgradeable item, an error message will be
  * produced. <code>forceUpgrade()</code> is different than <code>upgradeVirtualGood()<code>
  * because <code>forceUpgrade()</code> is a FREE upgrade.
  *
  * @param upgradeItemId id of the virtual good who we want to force an upgrade upon
  * @throws VirtualItemNotFoundException
  */
 public static void forceUpgrade(String upgradeItemId)
 {
     try {
         UpgradeVG upgradeVG = (UpgradeVG)StoreInfo.getVirtualItem(upgradeItemId);
         upgradeVG.give(1);
     } catch (InvalidCastException ex) {
         SoomlaUtils.LogError("SOOMLA StoreInventory",
                              "The given itemId was of a non UpgradeVG VirtualItem. Can't force it." + " " + ex.Message);
     }
 }
Ejemplo n.º 6
0
        /**
         * Retrieves the itemId of the current upgrade of the virtual good with the given
         * <code>goodItemId</code>.
         *
         * @param goodItemId id of the virtual good whose upgrade id we want to know
         * @return upgrade id if exists, or empty string otherwise
         * @throws VirtualItemNotFoundException
         */
        public static String getGoodCurrentUpgrade(String goodItemId)
        {
            VirtualGood good      = (VirtualGood)StoreInfo.getVirtualItem(goodItemId);
            UpgradeVG   upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good);

            if (upgradeVG == null)
            {
                return("");
            }
            return(upgradeVG.getItemId());
        }
Ejemplo n.º 7
0
        /** VIRTUAL GOODS **/

        /**
         * Equips the virtual good with the given <code>goodItemId</code>.
         * Equipping means that the user decides to currently use a specific virtual good.
         * For more details and examples see {@link com.soomla.store.domain.virtualGoods.EquippableVG}.
         *
         * @param goodItemId id of the virtual good to be equipped
         * @throws VirtualItemNotFoundException
         * @throws ClassCastException
         * @throws NotEnoughGoodsException
         */
        public static void equipVirtualGood(String goodItemId)
        {
            EquippableVG good = (EquippableVG)StoreInfo.getVirtualItem(goodItemId);

            try {
                good.equip();
            } catch (NotEnoughGoodsException e) {
                SoomlaUtils.LogError("StoreInventory", "UNEXPECTED! Couldn't equip something");
                throw e;
            }
        }
Ejemplo n.º 8
0
        /**
         * Removes all upgrades from the virtual good with the given <code>goodItemId</code>.
         *
         * @param goodItemId id of the virtual good we want to remove all upgrades from
         * @throws VirtualItemNotFoundException
         */
        public static void removeUpgrades(String goodItemId)
        {
            List <UpgradeVG> upgrades = StoreInfo.getGoodUpgrades(goodItemId);

            foreach (UpgradeVG upgrade in upgrades)
            {
                StorageManager.getVirtualGoodsStorage().remove(upgrade, 1, true);
            }
            VirtualGood good = (VirtualGood)StoreInfo.getVirtualItem(goodItemId);

            StorageManager.getVirtualGoodsStorage().removeUpgrades(good);
        }
Ejemplo n.º 9
0
        /**
         * @{inheritDoc}
         */
        public override int take(int amount, bool notify)
        {
            SingleUseVG good = null;

            try {
                good = (SingleUseVG)StoreInfo.getVirtualItem(mGoodItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "SingleUseVG with itemId: " + mGoodItemId + " doesn't exist! Can't take this pack. " + e.Message);
                return(0);
            }
            return(StorageManager.getVirtualGoodsStorage().remove(good, mGoodAmount * amount, notify));
        }
Ejemplo n.º 10
0
        /**
         * @{inheritDoc}
         */
        public override int give(int amount, bool notify)
        {
            VirtualCurrency currency = null;

            try {
                currency = (VirtualCurrency)StoreInfo.getVirtualItem(mCurrencyItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "VirtualCurrency with itemId: " + mCurrencyItemId
                                     + " doesn't exist! Can't give this pack." + " " + e.Message);
                return(0);
            }
            return(StorageManager.getVirtualCurrencyStorage().add(
                       currency, mCurrencyAmount * amount, notify));
        }
Ejemplo n.º 11
0
        /**
         * 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:
         *
         *   if YES - downgrades to the previous upgrade (or remove upgrades in case of null).
         *   if NO  - returns 0 (does nothing).
         *
         * @param amount is NOT USED HERE!
         * @param notify see parent
         * @return see parent
         */
        public override int take(int amount, bool notify)
        {
            VirtualGood good = null;

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

            UpgradeVG upgradeVG = StorageManager.getVirtualGoodsStorage().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 " + getName() + " is not assigned to " + "the VirtualGood: "
                                     + good.getName());
                return(0);
            }

            if (!String.IsNullOrEmpty(mPrevItemId))
            {
                UpgradeVG prevUpgradeVG = null;
                // Case: downgrade is not possible because previous upgrade does not exist
                try {
                    prevUpgradeVG = (UpgradeVG)StoreInfo.getVirtualItem(mPrevItemId);
                } catch (VirtualItemNotFoundException e) {
                    SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + mPrevItemId
                                         + " doesn't exist! Can't downgrade." + " " + e.Message);
                    return(0);
                }
                // Case: downgrade is successful!
                SoomlaUtils.LogDebug(TAG, "Downgrading " + good.getName() + " to: "
                                     + prevUpgradeVG.getName());
                StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(good,
                                                                             prevUpgradeVG, notify);
            }

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

            return(base.take(amount, notify));
        }
Ejemplo n.º 12
0
        /**
         * Assigns the current upgrade to the associated <code>VirtualGood</code> (mGood).
         *
         * NOTE: This action doesn't check anything! It just assigns the current UpgradeVG to the
         * associated mGood.
         *
         * @param amount is NOT USED HERE!
         * @return 1 if the user was given the good, 0 otherwise
         */
        public override int give(int amount, bool notify)
        {
            SoomlaUtils.LogDebug(TAG, "Assigning " + getName() + " to: " + mGoodItemId);

            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.getVirtualItem(mGoodItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + mGoodItemId +
                                     " doesn't exist! Can't upgrade. " + e.Message);
                return(0);
            }

            StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(good, this, notify);

            return(base.give(amount, notify));
        }
Ejemplo n.º 13
0
        /**
         * Determines if the user is in a state that allows him/her to buy an <code>UpgradeVG</code>
         * This method enforces allowing/rejecting of upgrades here so users won't buy them when
         * they are not supposed to.
         * If you want to give your users free upgrades, use the <code>give</code> function.
         *
         * @return true if can buy, false otherwise
         */
        protected override bool CanBuy()
        {
            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.getVirtualItem(mGoodItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + mGoodItemId +
                                     " doesn't exist! Returning NO (can't buy)." + " " + e.Message);
                return(false);
            }

            UpgradeVG upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good);

            return(((upgradeVG == null && String.IsNullOrEmpty(mPrevItemId)) ||
                    (upgradeVG != null && ((upgradeVG.getNextItemId() == getItemId()) ||
                                           (upgradeVG.getPrevItemId() == getItemId())))) &&
                   base.CanBuy());
        }
Ejemplo n.º 14
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.º 15
0
        private void buildShop()
        {
            foreach (VirtualCurrencyPack vc in StoreInfo.getCurrencyPacks())
            {
                buildShopLine(vc);
            }

            foreach (NonConsumableItem nci in StoreInfo.getNonConsumableItems())
            {
                buildShopLine(nci);
            }

            foreach (string id in StoreAssets.BOOTS_CATEGORY.getGoodsItemIds())
            {
                buildShopLine(StoreInfo.getVirtualItem(id));
            }

            foreach (string id in StoreAssets.GLOVE_CATEGORY.getGoodsItemIds())
            {
                buildShopLine(StoreInfo.getVirtualItem(id));
            }
        }
Ejemplo n.º 16
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("");
                }
            }
        }
Ejemplo n.º 17
0
        /**
         * Buys the item with the given <code>itemId</code>.
         *
         * @param itemId id of item to be purchased
         * @param 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.
         * @throws InsufficientFundsException
         * @throws VirtualItemNotFoundException
         */
        public static void buy(String itemId, String payload)
        {
            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.getVirtualItem(itemId);

            pvi.buy(payload);
        }
Ejemplo n.º 18
0
        /**
         * Checks if the virtual good with the given <code>goodItemId</code> is currently equipped.
         *
         * @param goodItemId id of the virtual good who we want to know if is equipped
         * @return true if the virtual good is equipped, false otherwise
         * @throws VirtualItemNotFoundException
         * @throws ClassCastException
         */
        public static bool isVirtualGoodEquipped(String goodItemId)
        {
            EquippableVG good = (EquippableVG)StoreInfo.getVirtualItem(goodItemId);

            return(StorageManager.getVirtualGoodsStorage().isEquipped(good));
        }
Ejemplo n.º 19
0
        /**
         * Unequips the virtual good with the given <code>goodItemId</code>. Unequipping means that the
         * user decides to stop using the virtual good he/she is currently using.
         * For more details and examples see {@link com.soomla.store.domain.virtualGoods.EquippableVG}.
         *
         * @param goodItemId id of the virtual good to be unequipped
         * @throws VirtualItemNotFoundException
         * @throws ClassCastException
         */
        public static void unEquipVirtualGood(String goodItemId)
        {
            EquippableVG good = (EquippableVG)StoreInfo.getVirtualItem(goodItemId);

            good.unequip();
        }
Ejemplo n.º 20
0
        /** VIRTUAL ITEMS **/

        /**
         * Retrieves the balance of the virtual item with the given <code>itemId</code>.
         *
         * @param itemId id of the virtual item to be fetched.
         * @return balance of the virtual item with the given <code>itemId</code>.
         * @throws VirtualItemNotFoundException
         */
        public static int getVirtualItemBalance(String itemId)
        {
            VirtualItem item = StoreInfo.getVirtualItem(itemId);

            return(StorageManager.getVirtualItemStorage(item).getBalance(item));
        }
Ejemplo n.º 21
0
        /**
         * Takes from your user the given amount of the virtual item with the given <code>itemId</code>.
         * For example, when your user requests a refund you need to TAKE the item he/she is returning.
         *
         * @param itemId id of the virtual item to be taken
         * @param amount amount of the item to be given
         * @throws VirtualItemNotFoundException
         */
        public static void takeVirtualItem(String itemId, int amount)
        {
            VirtualItem item = StoreInfo.getVirtualItem(itemId);

            item.take(amount);
        }