Exemplo n.º 1
0
		private static void validateStoreAssets(IStoreAssets storeAssets) {
			if (storeAssets == null) {
				throw new ArgumentException("The given store assets can't be null!");
			}

			if (storeAssets.GetCurrencies() == null ||
					storeAssets.GetCurrencyPacks() == null ||
					storeAssets.GetGoods() == null ||
					storeAssets.GetCategories() == null) {
				throw new ArgumentException("All IStoreAssets methods shouldn't return NULL-pointer references!");
			}

			if (!assetsArrayHasMarketIdDuplicates(storeAssets.GetGoods()) 
			    || !assetsArrayHasMarketIdDuplicates(storeAssets.GetCurrencyPacks())) {
				throw new ArgumentException("The given store assets has duplicates at marketItem productId!");
			}
		}
Exemplo n.º 2
0
        private static void validateStoreAssets(IStoreAssets storeAssets)
        {
            if (storeAssets == null)
            {
                throw new ArgumentException("The given store assets can't be null!");
            }

            if (storeAssets.GetCurrencies() == null ||
                storeAssets.GetCurrencyPacks() == null ||
                storeAssets.GetGoods() == null ||
                storeAssets.GetCategories() == null)
            {
                throw new ArgumentException("All IStoreAssets methods shouldn't return NULL-pointer references!");
            }

            if (!assetsArrayHasMarketIdDuplicates(storeAssets.GetGoods()) ||
                !assetsArrayHasMarketIdDuplicates(storeAssets.GetCurrencyPacks()))
            {
                throw new ArgumentException("The given store assets has duplicates at marketItem productId!");
            }
        }
Exemplo n.º 3
0
 private static void validateStoreAssets(IStoreAssets storeAssets)
 {
     if (storeAssets == null)
     {
         throw new ArgumentException("The given store assets can't be null!");
     }
     if (!assetsArrayHasMarketIdDuplicates(storeAssets.GetGoods()) ||
         !assetsArrayHasMarketIdDuplicates(storeAssets.GetCurrencyPacks()))
     {
         throw new ArgumentException("The given store assets has duplicates at marketItem productId!");
     }
 }
Exemplo n.º 4
0
        public static List <VirtualCurrencyPack> GetVirtualCurrencyPacks()
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch packs");
            List <VirtualCurrencyPack> vcps = new List <VirtualCurrencyPack>();

#if UNITY_EDITOR
            vcps.AddRange(storeAssets.GetCurrencyPacks());
#elif UNITY_ANDROID
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualCurrencyPacks = new AndroidJavaClass("com.soomla.unity.StoreInfo").CallStatic <AndroidJavaObject>("getCurrencyPacks")) {
                for (int i = 0; i < jniVirtualCurrencyPacks.Call <int>("size"); i++)
                {
                    using (AndroidJavaObject jnivcp = jniVirtualCurrencyPacks.Call <AndroidJavaObject>("get", i)) {
                        vcps.Add(new VirtualCurrencyPack(jnivcp));
                    }
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetVirtualCurrencyPacks(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string packsJson = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            StoreUtils.LogDebug(TAG, "Got json: " + packsJson);

            JSONObject packsArr = new JSONObject(packsJson);
            foreach (JSONObject obj in packsArr.list)
            {
                vcps.Add(new VirtualCurrencyPack(obj));
            }
#endif
            return(vcps);
        }
Exemplo n.º 5
0
    /**
     * Initializes from <code>IStoreAssets</code>.
     * This happens only once - when the game is loaded for the first time.
     *
     * @param storeAssets game economy
     */
    private static void initializeWithStoreAssets(IStoreAssets storeAssets) {
        // fall-back here if the json doesn't exist,
        // we load the store from the given {@link IStoreAssets}.
        mCurrencies = new List<VirtualCurrency>();
        mCurrencies.AddRange(storeAssets.GetCurrencies());
        mCurrencyPacks = new List<VirtualCurrencyPack>();
        mCurrencyPacks.AddRange(storeAssets.GetCurrencyPacks());
        mGoods = new List<VirtualGood>();
        mGoods.AddRange(storeAssets.GetGoods());
        mCategories = new List<VirtualCategory>();
        mCategories.AddRange(storeAssets.GetCategories());
        //mNonConsumables = new List<NonConsumableItem>();
        //mNonConsumables.AddRange(storeAssets.GetNonConsumableItems());

        mVirtualItems = new Dictionary<String, VirtualItem>();
        mPurchasableItems = new Dictionary<String, PurchasableVirtualItem>();
        mGoodsCategories = new Dictionary<String, VirtualCategory>();
        mGoodsUpgrades = new Dictionary<String, List<UpgradeVG>>();

        foreach(VirtualCurrency vi in mCurrencies) {
            mVirtualItems.Add(vi.getItemId(), vi);
        }

        foreach(VirtualCurrencyPack vi in mCurrencyPacks) {
            mVirtualItems.Add(vi.getItemId(), vi);

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

        foreach(VirtualGood vi in mGoods) {
            mVirtualItems.Add(vi.getItemId(), vi);

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

            PurchaseType purchaseType = vi.GetPurchaseType();
            if (purchaseType is PurchaseWithMarket) {
                mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
                        .getProductId(), vi);
            }
        }
        /*
        foreach(NonConsumableItem vi in mNonConsumables) {
            mVirtualItems.Add(vi.getItemId(), vi);

            PurchaseType purchaseType = vi.GetPurchaseType();
            if (purchaseType is PurchaseWithMarket) {
                mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
                        .getProductId(), vi);
            }
        }
        */
        foreach(VirtualCategory category in mCategories) {
            foreach(String goodItemId in category.getGoodsItemIds()) {
                mGoodsCategories.Add(goodItemId, category);
            }
        }

        save();
    }
Exemplo n.º 6
0
        public static void Initialize(IStoreAssets storeAssets)
        {
            //			StoreUtils.LogDebug(TAG, "Adding currency");
            JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCurrency vi in storeAssets.GetCurrencies()) {
                currencies.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding packs");
            JSONObject packs = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) {
                packs.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding goods");
            JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualGood g in storeAssets.GetGoods()){
                if (g is SingleUseVG) {
                    suGoods.Add(g.toJSONObject());
                } else if (g is EquippableVG) {
                    eqGoods.Add(g.toJSONObject());
                } else if (g is UpgradeVG) {
               		            upGoods.Add(g.toJSONObject());
               		        } else if (g is LifetimeVG) {
                    ltGoods.Add(g.toJSONObject());
                } else if (g is SingleUsePackVG) {
                    paGoods.Add(g.toJSONObject());
                }
            }
            JSONObject goods = new JSONObject(JSONObject.Type.OBJECT);
            goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods);
            goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods);
            goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods);
            goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods);
            goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods);

            //			StoreUtils.LogDebug(TAG, "Adding categories");
            JSONObject categories = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCategory vi in storeAssets.GetCategories()) {
                categories.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding nonConsumables");
            JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY);
            foreach(NonConsumableItem vi in storeAssets.GetNonConsumableItems()) {
                nonConsumables.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Preparing StoreAssets  JSONObject");
            JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT);
            storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs);
            storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods);
            storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables);

            string storeAssetsJSON = storeAssetsObj.print();

            #if UNITY_ANDROID && !UNITY_EDITOR
            StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on java side");
            using(AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {
                jniStoreAssets.CallStatic("prepare", storeAssets.GetVersion(), storeAssetsJSON);
            }
            StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)");
            #elif UNITY_IOS && !UNITY_EDITOR
            StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on ios side");
            storeAssets_Init(storeAssets.GetVersion(), storeAssetsJSON);
            StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on ios side)");
            #endif
        }
Exemplo n.º 7
0
		/** Protected Functions **/

		protected static string IStoreAssetsToJSON(IStoreAssets storeAssets) {

			// Utils.LogDebug(TAG, "Adding currency");
			JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY);
			foreach(VirtualCurrency vi in storeAssets.GetCurrencies()) {
				currencies.Add(vi.toJSONObject());
			}

			// Utils.LogDebug(TAG, "Adding packs");
			JSONObject packs = new JSONObject(JSONObject.Type.ARRAY);
			foreach(VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) {
				packs.Add(vi.toJSONObject());
			}

			// Utils.LogDebug(TAG, "Adding goods");
			JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY);
			JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY);
			JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY);
			JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY);
			JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY);
			foreach(VirtualGood g in storeAssets.GetGoods()){
				if (g is SingleUseVG) {
					suGoods.Add(g.toJSONObject());
				} else if (g is EquippableVG) {
					eqGoods.Add(g.toJSONObject());
				} else if (g is UpgradeVG) {
					upGoods.Add(g.toJSONObject());
				} else if (g is LifetimeVG) {
					ltGoods.Add(g.toJSONObject());
				} else if (g is SingleUsePackVG) {
					paGoods.Add(g.toJSONObject());
				}
			}
			JSONObject goods = new JSONObject(JSONObject.Type.OBJECT);
			goods.AddField(StoreJSONConsts.STORE_GOODS_SU, suGoods);
			goods.AddField(StoreJSONConsts.STORE_GOODS_LT, ltGoods);
			goods.AddField(StoreJSONConsts.STORE_GOODS_EQ, eqGoods);
			goods.AddField(StoreJSONConsts.STORE_GOODS_UP, upGoods);
			goods.AddField(StoreJSONConsts.STORE_GOODS_PA, paGoods);

			// Utils.LogDebug(TAG, "Adding categories");
			JSONObject categories = new JSONObject(JSONObject.Type.ARRAY);
			foreach(VirtualCategory vi in storeAssets.GetCategories()) {
				categories.Add(vi.toJSONObject());
			}

			// Utils.LogDebug(TAG, "Preparing StoreAssets  JSONObject");
			JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT);
			storeAssetsObj.AddField(StoreJSONConsts.STORE_CATEGORIES, categories);
			storeAssetsObj.AddField(StoreJSONConsts.STORE_CURRENCIES, currencies);
			storeAssetsObj.AddField(StoreJSONConsts.STORE_CURRENCYPACKS, packs);
			storeAssetsObj.AddField(StoreJSONConsts.STORE_GOODS, goods);

			return storeAssetsObj.print();
		}
Exemplo n.º 8
0
//		private static AndroidJavaClass jniStoreInfo = new AndroidJavaClass("com.soomla.unity.StoreInfo");
#endif

        public static void Initialize(IStoreAssets storeAssets)
        {
#if UNITY_EDITOR
            StoreInfo.storeAssets = storeAssets;
#endif

//			StoreUtils.LogDebug(TAG, "Adding currency");
            JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY);
            foreach (VirtualCurrency vi in storeAssets.GetCurrencies())
            {
                currencies.Add(vi.toJSONObject());
            }

//			StoreUtils.LogDebug(TAG, "Adding packs");
            JSONObject packs = new JSONObject(JSONObject.Type.ARRAY);
            foreach (VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks())
            {
                packs.Add(vi.toJSONObject());
            }

//			StoreUtils.LogDebug(TAG, "Adding goods");
            JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY);
            foreach (VirtualGood g in storeAssets.GetGoods())
            {
                if (g is SingleUseVG)
                {
                    suGoods.Add(g.toJSONObject());
                }
                else if (g is EquippableVG)
                {
                    eqGoods.Add(g.toJSONObject());
                }
                else if (g is LifetimeVG)
                {
                    ltGoods.Add(g.toJSONObject());
                }
                else if (g is SingleUsePackVG)
                {
                    paGoods.Add(g.toJSONObject());
                }
                else if (g is UpgradeVG)
                {
                    upGoods.Add(g.toJSONObject());
                }
            }
            JSONObject goods = new JSONObject(JSONObject.Type.OBJECT);
            goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods);
            goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods);
            goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods);
            goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods);
            goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods);

//			StoreUtils.LogDebug(TAG, "Adding categories");
            JSONObject categories = new JSONObject(JSONObject.Type.ARRAY);
            foreach (VirtualCategory vi in storeAssets.GetCategories())
            {
                categories.Add(vi.toJSONObject());
            }

//			StoreUtils.LogDebug(TAG, "Adding nonConsumables");
            JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY);
            foreach (NonConsumableItem vi in storeAssets.GetNonConsumableItems())
            {
                nonConsumables.Add(vi.toJSONObject());
            }

//			StoreUtils.LogDebug(TAG, "Preparing StoreAssets  JSONObject");
            JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT);
            storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs);
            storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods);
            storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables);

            string storeAssetsJSON = storeAssetsObj.print();

#if UNITY_ANDROID
            StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on java side");
            using (AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {
                jniStoreAssets.CallStatic("prepare", storeAssets.GetVersion(), storeAssetsJSON);
            }
            StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)");
#elif UNITY_IOS
            StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on ios side");
            storeAssets_Init(storeAssets.GetVersion(), storeAssetsJSON);
            StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on ios side)");
#endif
        }
Exemplo n.º 9
0
        public static void Initialize(IStoreAssets storeAssets)
        {
            //			StoreUtils.LogDebug(TAG, "Adding currency");
            JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCurrency vi in storeAssets.GetCurrencies()) {
                currencies.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding packs");
            JSONObject packs = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) {
                packs.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding goods");
            JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualGood g in storeAssets.GetGoods()){
                if (g is SingleUseVG) {
                    suGoods.Add(g.toJSONObject());
                } else if (g is EquippableVG) {
                    eqGoods.Add(g.toJSONObject());
                } else if (g is UpgradeVG) {
               		            upGoods.Add(g.toJSONObject());
               		        } else if (g is LifetimeVG) {
                    ltGoods.Add(g.toJSONObject());
                } else if (g is SingleUsePackVG) {
                    paGoods.Add(g.toJSONObject());
                }
            }
            JSONObject goods = new JSONObject(JSONObject.Type.OBJECT);
            goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods);
            goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods);
            goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods);
            goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods);
            goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods);

            //			StoreUtils.LogDebug(TAG, "Adding categories");
            JSONObject categories = new JSONObject(JSONObject.Type.ARRAY);
            foreach(VirtualCategory vi in storeAssets.GetCategories()) {
                categories.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Adding nonConsumables");
            JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY);
            foreach(NonConsumableItem vi in storeAssets.GetNonConsumableItems()) {
                nonConsumables.Add(vi.toJSONObject());
            }

            //			StoreUtils.LogDebug(TAG, "Preparing StoreAssets  JSONObject");
            JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT);
            storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs);
            storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods);
            storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables);

            string storeAssetsJSON = storeAssetsObj.print();
            instance._initialize(storeAssets.GetVersion(), storeAssetsJSON);
        }
Exemplo n.º 10
0
        /**
         * Initializes from <code>IStoreAssets</code>.
         * This happens only once - when the game is loaded for the first time.
         *
         * @param storeAssets game economy
         */
        private static void initializeWithStoreAssets(IStoreAssets storeAssets)
        {
            // fall-back here if the json doesn't exist,
            // we load the store from the given {@link IStoreAssets}.
            mCurrencies = new List <VirtualCurrency>();
            mCurrencies.AddRange(storeAssets.GetCurrencies());
            mCurrencyPacks = new List <VirtualCurrencyPack>();
            mCurrencyPacks.AddRange(storeAssets.GetCurrencyPacks());
            mGoods = new List <VirtualGood>();
            mGoods.AddRange(storeAssets.GetGoods());
            mCategories = new List <VirtualCategory>();
            mCategories.AddRange(storeAssets.GetCategories());
            //mNonConsumables = new List<NonConsumableItem>();
            //mNonConsumables.AddRange(storeAssets.GetNonConsumableItems());

            mVirtualItems     = new Dictionary <String, VirtualItem>();
            mPurchasableItems = new Dictionary <String, PurchasableVirtualItem>();
            mGoodsCategories  = new Dictionary <String, VirtualCategory>();
            mGoodsUpgrades    = new Dictionary <String, List <UpgradeVG> >();

            foreach (VirtualCurrency vi in mCurrencies)
            {
                mVirtualItems.Add(vi.getItemId(), vi);
            }

            foreach (VirtualCurrencyPack vi in mCurrencyPacks)
            {
                mVirtualItems.Add(vi.getItemId(), vi);

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

            foreach (VirtualGood vi in mGoods)
            {
                mVirtualItems.Add(vi.getItemId(), vi);

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

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

            /*
             * foreach(NonConsumableItem vi in mNonConsumables) {
             *  mVirtualItems.Add(vi.getItemId(), vi);
             *
             *  PurchaseType purchaseType = vi.GetPurchaseType();
             *  if (purchaseType is PurchaseWithMarket) {
             *      mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
             *              .getProductId(), vi);
             *  }
             * }*/

            foreach (VirtualCategory category in mCategories)
            {
                foreach (String goodItemId in category.getGoodsItemIds())
                {
                    mGoodsCategories.Add(goodItemId, category);
                }
            }

            save();
        }
Exemplo n.º 11
0
 private static void validateStoreAssets(IStoreAssets storeAssets)
 {
     if (storeAssets == null) {
         throw new ArgumentException("The given store assets can't be null!");
     }
     if (!assetsArrayHasMarketIdDuplicates(storeAssets.GetGoods())
         || !assetsArrayHasMarketIdDuplicates(storeAssets.GetCurrencyPacks())) {
         throw new ArgumentException("The given store assets has duplicates at marketItem productId!");
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes <c>StoreInfo</c>.
        /// On first initialization, when the database doesn't have any previous version of the store
        /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>.
        /// After the first initialization, <c>StoreInfo</c> will be initialized from the database.
        ///
        /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump
        /// the version of your implementation of <c>IStoreAssets</c> in order to remove the
        /// metadata when the application loads. Bumping the version is done by returning a higher
        /// number in <c>IStoreAssets</c>'s <c>getVersion</c>.
        /// </summary>
        /// <param name="storeAssets">your game's economy</param>
        public static void Initialize(IStoreAssets storeAssets)
        {
//			Utils.LogDebug(TAG, "Adding currency");
            JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY);

            foreach (VirtualCurrency vi in storeAssets.GetCurrencies())
            {
                currencies.Add(vi.toJSONObject());
            }

//			Utils.LogDebug(TAG, "Adding packs");
            JSONObject packs = new JSONObject(JSONObject.Type.ARRAY);

            foreach (VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks())
            {
                packs.Add(vi.toJSONObject());
            }

//			Utils.LogDebug(TAG, "Adding goods");
            JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY);

            foreach (VirtualGood g in storeAssets.GetGoods())
            {
                if (g is SingleUseVG)
                {
                    suGoods.Add(g.toJSONObject());
                }
                else if (g is EquippableVG)
                {
                    eqGoods.Add(g.toJSONObject());
                }
                else if (g is UpgradeVG)
                {
                    upGoods.Add(g.toJSONObject());
                }
                else if (g is LifetimeVG)
                {
                    ltGoods.Add(g.toJSONObject());
                }
                else if (g is SingleUsePackVG)
                {
                    paGoods.Add(g.toJSONObject());
                }
            }
            JSONObject goods = new JSONObject(JSONObject.Type.OBJECT);

            goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods);
            goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods);
            goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods);
            goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods);
            goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods);

//			Utils.LogDebug(TAG, "Adding categories");
            JSONObject categories = new JSONObject(JSONObject.Type.ARRAY);

            foreach (VirtualCategory vi in storeAssets.GetCategories())
            {
                categories.Add(vi.toJSONObject());
            }

//			Utils.LogDebug(TAG, "Adding nonConsumables");
            JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY);

            foreach (NonConsumableItem vi in storeAssets.GetNonConsumableItems())
            {
                nonConsumables.Add(vi.toJSONObject());
            }

//			Utils.LogDebug(TAG, "Preparing StoreAssets  JSONObject");
            JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT);

            storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies);
            storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs);
            storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods);
            storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables);

            string storeAssetsJSON = storeAssetsObj.print();

            instance._initialize(storeAssets.GetVersion(), storeAssetsJSON);
        }