Example #1
0
        /// <summary>
        /// Unequips the virtual good with the given <c>goodItemId</c>. Unequipping means that the
        /// user decides to stop using the virtual good he/she is currently using.
        /// For more details and examples <see cref="com.soomla.store.domain.virtualGoods.EquippableVG"/>.
        /// </summary>
        /// <param name="goodItemId">Id of the good to be unequipped.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static void UnEquipVirtualGood(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "UnEquipping: " + goodItemId);

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

            good.Unequip();
        }
Example #2
0
        /// <summary>
        /// Equips the current <code>EquippableVG</code>.
        /// The equipping is done according to the equipping model ('GLOBAL', 'CATEGORY', or 'LOCAL').
        /// </summary>
        /// <exception cref="Soomla.Store.NotEnoughGoodsException">Throws NotEnoughGoodsException</exception>
        /// <param name="notify">if true, the relevant event will be posted when equipped.</param>
        public void Equip(bool notify)
        {
            // only if the user has bought this EquippableVG, the EquippableVG is equipped.
            if (VirtualGoodsStorage.GetBalance(this) > 0)
            {
                if (Equipping == EquippingModel.CATEGORY)
                {
                    VirtualCategory category = null;
                    try {
                        category = StoreInfo.GetCategoryForVirtualGood(this.ItemId);
                    } catch (VirtualItemNotFoundException) {
                        SoomlaUtils.LogError(TAG,
                                             "Tried to unequip all other category VirtualGoods but there was no " +
                                             "associated category. virtual good itemId: " + this.ItemId);
                        return;
                    }

                    foreach (string goodItemId in category.GoodItemIds)
                    {
                        EquippableVG equippableVG = null;
                        try {
                            equippableVG = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

                            if (equippableVG != null && equippableVG != this)
                            {
                                equippableVG.Unequip(notify);
                            }
                        } catch (VirtualItemNotFoundException) {
                            SoomlaUtils.LogError(TAG, "On equip, couldn't find one of the itemIds "
                                                 + "in the category. Continuing to the next one. itemId: "
                                                 + goodItemId);
                        } catch (System.InvalidCastException) {
                            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);
                        }
                    }
                }
                else if (Equipping == EquippingModel.GLOBAL)
                {
                    foreach (VirtualGood good in StoreInfo.Goods)
                    {
                        if (good != this &&
                            good is EquippableVG)
                        {
                            ((EquippableVG)good).Unequip(notify);
                        }
                    }
                }

                VirtualGoodsStorage.Equip(this, notify);
            }
            else
            {
                throw new NotEnoughGoodsException(ItemId);
            }
        }