Example #1
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);
            }
        }
 /// <summary>
 /// Gets the category that the virtual good with the given <c>goodItemId</c> belongs to.
 /// </summary>
 /// <param name="goodItemId">Item id.</param>
 /// <returns>Category that the item with given id belongs to.</returns>
 /// <exception cref="VirtualItemNotFoundException">Exception is thrown if category is not found.</exception>
 protected override VirtualCategory _getCategoryForVirtualGood(string goodItemId)
 {
     VirtualCategory vc = null;
     AndroidJNI.PushLocalFrame(100);
     using(AndroidJavaObject jniVirtualVategory = AndroidJNIHandler.CallStatic<AndroidJavaObject>(
         new AndroidJavaClass("com.soomla.store.data.StoreInfo"),"getCategory", goodItemId)) {
         vc = new VirtualCategory(jniVirtualVategory);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
     return vc;
 }
        /// <summary>
        /// Gets the category that the virtual good with the given <c>goodItemId</c> belongs to.
        /// </summary>
        /// <param name="goodItemId">Item id.</param>
        /// <returns>Category that the item with given id belongs to.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if category is not found.</exception>
        override protected VirtualCategory _getCategoryForVirtualGood(string goodItemId)
        {
            VirtualCategory vc = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualVategory = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getCategory", goodItemId)) {
                vc = new VirtualCategory(jniVirtualVategory);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vc);
        }
Example #4
0
        /// <summary>
        /// Checks currently equipped good in given <c>category</c>
        /// </summary>
        /// <param name="category">Category we want to check</param>
        /// <returns>EquippableVG otherwise null</returns>
        public static EquippableVG GetEquippedVirtualGood(VirtualCategory category)
        {
            SoomlaUtils.LogDebug(TAG, "Checking equipped goood in " + category.Name + " category");

            foreach (string goodItemId in category.GoodItemIds)
            {
                EquippableVG good = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

                if (good != null && good.Equipping == EquippableVG.EquippingModel.CATEGORY &&
                    VirtualGoodsStorage.IsEquipped(good) &&
                    StoreInfo.GetCategoryForVirtualGood(goodItemId) == category)
                {
                    return(good);
                }
            }
            SoomlaUtils.LogError(TAG, "There is no virtual good equipped in " + category.Name + " category");
            return(null);
        }
Example #5
0
        /// <summary>
        /// Checks currently equipped good in given <c>category</c>
        /// </summary>
        /// <param name="category">Category we want to check</param>
        /// <returns>EquippableVG otherwise null</returns>
        public static EquippableVG GetEquippedVirtualGood(VirtualCategory category)
        {
            SoomlaUtils.LogDebug(TAG, "Checking equipped goood in " + category.Name + " category");

            foreach (string goodItemId in category.GoodItemIds)
            {
                EquippableVG good = (EquippableVG) StoreInfo.GetItemByItemId(goodItemId);

                if (good != null && good.Equipping == EquippableVG.EquippingModel.CATEGORY &&
                    VirtualGoodsStorage.IsEquipped(good) &&
                    StoreInfo.GetCategoryForVirtualGood(goodItemId) == category)
                    return good;
            }
            SoomlaUtils.LogError(TAG, "There is no virtual good equipped in " + category.Name + " category");
            return null;
        }