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
        /** 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));
        }
        /// <summary>   Removes the given nonConsumableItem. </summary>
        ///
        /// <param name="nonConsumableItem">    The non consumable item. </param>
        ///
        /// <returns>   true if it succeeds, false if it fails. </returns>
        public bool remove(NonConsumableItem nonConsumableItem)
        {
            SoomlaUtils.LogDebug(TAG, "Removing " + nonConsumableItem.getName());

            String itemId = nonConsumableItem.getItemId();
            String key    = keyNonConsExists(itemId);

            KeyValueStorage.DeleteKeyValue(key);

            return(false);
        }
        /// <summary>   Adds the given non-consumable item to the storage. </summary>
        ///
        /// <param name="nonConsumableItem">    The non consumable item. </param>
        ///
        /// <returns>   true if it succeeds, false if it fails. </returns>
        public bool add(NonConsumableItem nonConsumableItem)
        {
            SoomlaUtils.LogDebug(TAG, "Adding " + nonConsumableItem.getItemId());

            String itemId = nonConsumableItem.getItemId();
            String key    = keyNonConsExists(itemId);

            KeyValueStorage.SetValue(key, "");

            return(true);
        }
        /// <summary>   Checks if the given <c>NonConsumableItem</c> exists. </summary>
        ///
        /// <param name="nonConsumableItem">    The non consumable item. </param>
        ///
        /// <returns>   true if it succeeds, false if it fails. </returns>
        public bool nonConsumableItemExists(NonConsumableItem nonConsumableItem)
        {
            SoomlaUtils.LogDebug(TAG, "Checking if the given MANAGED item exists.");

            String itemId = nonConsumableItem.getItemId();
            String key    = keyNonConsExists(itemId);

            String val = KeyValueStorage.GetValue(key);

            return(val != null);
        }
Ejemplo n.º 6
0
        public void Prepare(int version, String JsonStoreAssets)
        {
            try
            {
                mVersion = version;

                JObject JObject = JObject.Parse(JsonStoreAssets);

                JArray virtualCurrencies = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCIES);
                mVirtualCurrency = new VirtualCurrency[virtualCurrencies.Count];
                for (int i = 0; i < virtualCurrencies.Count; i++)
                {
                    JObject         o = virtualCurrencies.Value <JObject>(i);
                    VirtualCurrency c = new VirtualCurrency(o);
                    mVirtualCurrency[i] = c;
                }

                JArray currencyPacks = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCYPACKS);
                mVirtualCurrencyPack = new VirtualCurrencyPack[currencyPacks.Count];
                for (int i = 0; i < currencyPacks.Count; i++)
                {
                    JObject             o    = currencyPacks.Value <JObject>(i);
                    VirtualCurrencyPack pack = new VirtualCurrencyPack(o);
                    mVirtualCurrencyPack[i] = pack;
                }

                // The order in which VirtualGoods are created matters!
                // For example: VGU and VGP depend on other VGs
                JObject            virtualGoods = JObject.Value <JObject>(StoreJSONConsts.STORE_GOODS);
                JArray             suGoods      = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_SU);
                JArray             ltGoods      = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_LT);
                JArray             eqGoods      = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_EQ);
                JArray             upGoods      = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_UP);
                JArray             paGoods      = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_PA);
                List <VirtualGood> goods        = new List <VirtualGood>();
                for (int i = 0; i < suGoods.Count; i++)
                {
                    JObject     o = suGoods.Value <JObject>(i);
                    SingleUseVG g = new SingleUseVG(o);
                    goods.Add(g);
                }
                for (int i = 0; i < ltGoods.Count; i++)
                {
                    JObject    o = ltGoods.Value <JObject>(i);
                    LifetimeVG g = new LifetimeVG(o);
                    goods.Add(g);
                }
                for (int i = 0; i < eqGoods.Count; i++)
                {
                    JObject      o = eqGoods.Value <JObject>(i);
                    EquippableVG g = new EquippableVG(o);
                    goods.Add(g);
                }
                for (int i = 0; i < paGoods.Count; i++)
                {
                    JObject         o = paGoods.Value <JObject>(i);
                    SingleUsePackVG g = new SingleUsePackVG(o);
                    goods.Add(g);
                }
                for (int i = 0; i < upGoods.Count; i++)
                {
                    JObject   o = upGoods.Value <JObject>(i);
                    UpgradeVG g = new UpgradeVG(o);
                    goods.Add(g);
                }

                mVirtualGood = new VirtualGood[goods.Count];
                for (int i = 0; i < goods.Count; i++)
                {
                    mVirtualGood[i] = goods[i];
                }

                // categories depend on virtual goods. That's why the have to be initialized after!
                JArray virtualCategories = JObject.Value <JArray>(StoreJSONConsts.STORE_CATEGORIES);
                mVirtualCategory = new VirtualCategory[virtualCategories.Count];
                for (int i = 0; i < virtualCategories.Count; i++)
                {
                    JObject         o        = virtualCategories.Value <JObject>(i);
                    VirtualCategory category = new VirtualCategory(o);
                    mVirtualCategory[i] = category;
                }

                JArray nonConsumables = JObject.Value <JArray>(StoreJSONConsts.STORE_NONCONSUMABLES);
                mNonConsumableItem = new NonConsumableItem[nonConsumables.Count];
                for (int i = 0; i < nonConsumables.Count; i++)
                {
                    JObject           o   = nonConsumables.Value <JObject>(i);
                    NonConsumableItem non = new NonConsumableItem(o);
                    mNonConsumableItem[i] = non;
                }
            }
            catch (Exception ex)
            {
                SoomlaUtils.LogError(TAG, "An error occurred while trying to prepare storeAssets" + ex.Message);
            }
        }
Ejemplo n.º 7
0
        /**
         * Replaces an old virtual item with a new one by doing the following:
         * 1. Determines the type of the given virtual item.
         * 2. Looks for the given virtual item in the relevant list, according to its type.
         * 3. If found, removes it.
         * 4. Adds the given virtual item.
         *
         * @param virtualItem the virtual item that replaces the old one if exists.
         */
        public static void replaceVirtualItem(VirtualItem virtualItem)
        {
            mVirtualItems.Add(virtualItem.getItemId(), virtualItem);

            if (virtualItem is VirtualCurrency)
            {
                for (int i = 0; i < mCurrencies.Count; i++)
                {
                    if (mCurrencies[i].getItemId() == virtualItem.getItemId())
                    {
                        mCurrencies.RemoveAt(i);
                        break;
                    }
                }
                mCurrencies.Add((VirtualCurrency)virtualItem);
            }

            if (virtualItem is VirtualCurrencyPack)
            {
                VirtualCurrencyPack vcp          = (VirtualCurrencyPack)virtualItem;
                PurchaseType        purchaseType = vcp.GetPurchaseType();
                if (purchaseType is PurchaseWithMarket)
                {
                    mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem()
                                          .getProductId(), vcp);
                }

                for (int i = 0; i < mCurrencyPacks.Count; i++)
                {
                    if (mCurrencyPacks[i].getItemId() == vcp.getItemId())
                    {
                        mCurrencyPacks.RemoveAt(i);
                        break;
                    }
                }
                mCurrencyPacks.Add(vcp);
            }

            if (virtualItem is VirtualGood)
            {
                VirtualGood vg = (VirtualGood)virtualItem;

                if (vg is UpgradeVG)
                {
                    List <UpgradeVG> upgrades = mGoodsUpgrades[((UpgradeVG)vg).getGoodItemId()];
                    if (upgrades == null)
                    {
                        upgrades = new List <UpgradeVG>();
                        mGoodsUpgrades.Add(((UpgradeVG)vg).getGoodItemId(), upgrades);
                    }
                    upgrades.Add((UpgradeVG)vg);
                }

                PurchaseType purchaseType = vg.GetPurchaseType();
                if (purchaseType is PurchaseWithMarket)
                {
                    mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem()
                                          .getProductId(), vg);
                }

                for (int i = 0; i < mGoods.Count; i++)
                {
                    if (mGoods[i].getItemId() == vg.getItemId())
                    {
                        mGoods.RemoveAt(i);
                        break;
                    }
                }
                mGoods.Add(vg);
            }

            if (virtualItem is NonConsumableItem)
            {
                NonConsumableItem non = (NonConsumableItem)virtualItem;

                PurchaseType purchaseType = non.GetPurchaseType();
                if (purchaseType is PurchaseWithMarket)
                {
                    mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem()
                                          .getProductId(), non);
                }

                for (int i = 0; i < mNonConsumables.Count; i++)
                {
                    if (mNonConsumables[i].getItemId() == non.getItemId())
                    {
                        mNonConsumables.RemoveAt(i);
                        break;
                    }
                }
                mNonConsumables.Add(non);
            }
        }
Ejemplo n.º 8
0
        /** Private functions **/

        /**
         * Transforms given JObject to StoreInfo
         *
         * @param JObject
         * @throws JSONException
         */
        private static void fromJObject(JObject JObject)
        {
            mVirtualItems     = new Dictionary <String, VirtualItem>();
            mPurchasableItems = new Dictionary <String, PurchasableVirtualItem>();
            mGoodsCategories  = new Dictionary <String, VirtualCategory>();
            mGoodsUpgrades    = new Dictionary <String, List <UpgradeVG> >();
            mCurrencyPacks    = new List <VirtualCurrencyPack>();
            mGoods            = new List <VirtualGood>();
            mCategories       = new List <VirtualCategory>();
            mCurrencies       = new List <VirtualCurrency>();
            mNonConsumables   = new List <NonConsumableItem>();

            JToken value;

            if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCIES, out value))
            {
                JArray virtualCurrencies = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCIES);
                for (int i = 0; i < virtualCurrencies.Count; i++)
                {
                    JObject         o = virtualCurrencies.Value <JObject>(i);
                    VirtualCurrency c = new VirtualCurrency(o);
                    mCurrencies.Add(c);

                    mVirtualItems.Add(c.getItemId(), c);
                }
            }

            if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCYPACKS, out value))
            {
                JArray currencyPacks = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCYPACKS);
                for (int i = 0; i < currencyPacks.Count; i++)
                {
                    JObject             o    = currencyPacks.Value <JObject>(i);
                    VirtualCurrencyPack pack = new VirtualCurrencyPack(o);
                    mCurrencyPacks.Add(pack);

                    mVirtualItems.Add(pack.getItemId(), pack);

                    PurchaseType purchaseType = pack.GetPurchaseType();
                    if (purchaseType is PurchaseWithMarket)
                    {
                        mPurchasableItems.Add(((PurchaseWithMarket)purchaseType)
                                              .getMarketItem().getProductId(), pack);
                    }
                }
            }

            // The order in which VirtualGoods are created matters!
            // For example: VGU and VGP depend on other VGs
            if (JObject.TryGetValue(StoreJSONConsts.STORE_GOODS, out value))
            {
                JObject virtualGoods = JObject.Value <JObject>(StoreJSONConsts.STORE_GOODS);

                JToken valueVg;
                if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_SU, out valueVg))
                {
                    JArray suGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_SU);
                    for (int i = 0; i < suGoods.Count; i++)
                    {
                        JObject     o = suGoods.Value <JObject>(i);
                        SingleUseVG g = new SingleUseVG(o);
                        addVG(g);
                    }
                }


                if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_LT, out valueVg))
                {
                    JArray ltGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_LT);
                    for (int i = 0; i < ltGoods.Count; i++)
                    {
                        JObject    o = ltGoods.Value <JObject>(i);
                        LifetimeVG g = new LifetimeVG(o);
                        addVG(g);
                    }
                }


                if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_EQ, out valueVg))
                {
                    JArray eqGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_EQ);
                    for (int i = 0; i < eqGoods.Count; i++)
                    {
                        JObject      o = eqGoods.Value <JObject>(i);
                        EquippableVG g = new EquippableVG(o);
                        addVG(g);
                    }
                }

                if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_PA, out valueVg))
                {
                    JArray paGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_PA);
                    for (int i = 0; i < paGoods.Count; i++)
                    {
                        JObject         o = paGoods.Value <JObject>(i);
                        SingleUsePackVG g = new SingleUsePackVG(o);
                        addVG(g);
                    }
                }


                if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_UP, out valueVg))
                {
                    JArray upGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_UP);
                    for (int i = 0; i < upGoods.Count; i++)
                    {
                        JObject   o = upGoods.Value <JObject>(i);
                        UpgradeVG g = new UpgradeVG(o);
                        addVG(g);

                        List <UpgradeVG> upgrades = mGoodsUpgrades[g.getGoodItemId()];
                        if (upgrades == null)
                        {
                            upgrades = new List <UpgradeVG>();
                            mGoodsUpgrades.Add(g.getGoodItemId(), upgrades);
                        }
                        upgrades.Add(g);
                    }
                }
            }

            // Categories depend on virtual goods. That's why the have to be initialized after!
            if (JObject.TryGetValue(StoreJSONConsts.STORE_CATEGORIES, out value))
            {
                JArray virtualCategories = JObject.Value <JArray>(StoreJSONConsts.STORE_CATEGORIES);
                for (int i = 0; i < virtualCategories.Count; i++)
                {
                    JObject         o        = virtualCategories.Value <JObject>(i);
                    VirtualCategory category = new VirtualCategory(o);
                    mCategories.Add(category);
                    foreach (String goodItemId in category.getGoodsItemIds())
                    {
                        mGoodsCategories.Add(goodItemId, category);
                    }
                }
            }

            if (JObject.TryGetValue(StoreJSONConsts.STORE_NONCONSUMABLES, out value))
            {
                JArray nonConsumables = JObject.Value <JArray>(StoreJSONConsts.STORE_NONCONSUMABLES);
                for (int i = 0; i < nonConsumables.Count; i++)
                {
                    JObject           o   = nonConsumables.Value <JObject>(i);
                    NonConsumableItem non = new NonConsumableItem(o);
                    mNonConsumables.Add(non);

                    mVirtualItems.Add(non.getItemId(), non);

                    PurchaseType purchaseType = non.GetPurchaseType();
                    if (purchaseType is PurchaseWithMarket)
                    {
                        mPurchasableItems.Add(((PurchaseWithMarket)purchaseType)
                                              .getMarketItem().getProductId(), non);
                    }
                }
            }
        }