コード例 #1
0
ファイル: EquippableVG.cs プロジェクト: lickey10/BeerMe
        /// <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);
            }
        }
コード例 #2
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);
        }