Ejemplo n.º 1
0
        public static List <NonConsumableItem> GetNonConsumableItems()
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch noncons");
            List <NonConsumableItem> nonConsumableItems = new List <NonConsumableItem>();

#if UNITY_EDITOR
            nonConsumableItems.AddRange(storeAssets.GetNonConsumableItems());
#elif UNITY_ANDROID
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniNonConsumableItems = new AndroidJavaClass("com.soomla.unity.StoreInfo").CallStatic <AndroidJavaObject>("getNonConsumableItems")) {
                for (int i = 0; i < jniNonConsumableItems.Call <int>("size"); i++)
                {
                    using (AndroidJavaObject jniNon = jniNonConsumableItems.Call <AndroidJavaObject>("get", i)) {
                        nonConsumableItems.Add(new NonConsumableItem(jniNon));
                    }
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetNonConsumableItems(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

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

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

            JSONObject nonConsArr = new JSONObject(nonConsumableJson);
            foreach (JSONObject obj in nonConsArr.list)
            {
                nonConsumableItems.Add(new NonConsumableItem(obj));
            }
#endif
            return(nonConsumableItems);
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static void Initialize(IStoreAssets storeAssets)
        {
            #if UNITY_ANDROID
            Debug.Log("pushing data to StoreAssets on java side");

            AndroidJNI.PushLocalFrame(100);

            using(AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {

                //storeAssets version
                jniStoreAssets.CallStatic("setVersion", storeAssets.GetVersion());

                Dictionary<int, AndroidJavaObject> jniCategories = new Dictionary<int, AndroidJavaObject>();
                //virtual categories
                using(AndroidJavaObject jniVirtualCategories = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCategories")) {
                    jniVirtualCategories.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCategory vc in storeAssets.GetVirtualCategories()){
                        jniCategories[vc.Id] = vc.toAndroidJavaObject(jniStoreAssets);
                        jniVirtualCategories.Call<bool>("add", jniCategories[vc.Id]);
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //non consumable items
                using(AndroidJavaObject jniNonConsumableItems = jniStoreAssets.GetStatic<AndroidJavaObject>("nonConsumableItems")) {
                    jniNonConsumableItems.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(NonConsumableItem non in storeAssets.GetNonConsumableItems()){
                        using(AndroidJavaObject obj = non.toAndroidJavaObject()) {
                            jniNonConsumableItems.Call<bool>("add", obj);
                        }
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                Dictionary<string, AndroidJavaObject> jniCurrencies = new Dictionary<string, AndroidJavaObject>();
                //Virtual currencies
                using(AndroidJavaObject jniVirtualCurrencies = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCurrencies")) {
                    jniVirtualCurrencies.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCurrency vc in storeAssets.GetVirtualCurrencies()){
                        jniCurrencies[vc.ItemId] = vc.toAndroidJavaObject();
                        jniVirtualCurrencies.Call<bool>("add", jniCurrencies[vc.ItemId]);
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //Virtual currency packs
                using(AndroidJavaObject jniVirtualCurrencyPacks = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCurrencyPacks")) {
                    jniVirtualCurrencyPacks.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCurrencyPack vcp in storeAssets.GetVirtualCurrencyPacks()){
                        using(AndroidJavaObject obj = vcp.toAndroidJavaObject(jniCurrencies[vcp.Currency.ItemId])) {
                            jniVirtualCurrencyPacks.Call<bool>("add", obj);
                        }
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //Virtual goods
                using(AndroidJavaObject jniVirtualGoods = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualGoods")) {
                    jniVirtualGoods.Call("clear");
                    foreach(VirtualGood vg in storeAssets.GetVirtualGoods()){
                        AndroidJNI.PushLocalFrame(100);
                        using(AndroidJavaObject obj = vg.toAndroidJavaObject(jniStoreAssets, jniCategories[vg.Category.Id])) {
                            jniVirtualGoods.Call<bool>("add", obj);
                        }
                        AndroidJNI.PopLocalFrame(IntPtr.Zero);
                    }
                }

                foreach(KeyValuePair<int, AndroidJavaObject> kvp in jniCategories) {
                    kvp.Value.Dispose();
                }

                foreach(KeyValuePair<string, AndroidJavaObject> kvp in jniCurrencies) {
                    kvp.Value.Dispose();
                }
            }

            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            Debug.Log("done! (pushing data to StoreAssets on java side)");
            #elif UNITY_IOS
            Debug.Log("pushing data to StoreAssets on ios side");

            storeAssets_Init();

            // storeAssets version
            storeAssets_SetVersion(storeAssets.GetVersion());
            //virtual categories
            foreach(VirtualCategory vc in storeAssets.GetVirtualCategories()){
                storeAssets_AddCategory(vc.Name, vc.Id, vc.Equipping.ToString());
            }
            //ios market items
            foreach(NonConsumableItem non in storeAssets.GetNonConsumableItems()){
                storeAssets_AddNonConsumable(non.Name, non.Description, non.ItemId, non.MarketItem.Price, non.MarketItem.ProductId);
            }
            //Virtual currencies
            foreach(VirtualCurrency vc in storeAssets.GetVirtualCurrencies()){
                storeAssets_AddCurrency(vc.Name, vc.Description, vc.ItemId);
            }
            //Virtual currency packs
            foreach(VirtualCurrencyPack vcp in storeAssets.GetVirtualCurrencyPacks()){
                storeAssets_AddCurrencyPack(vcp.Name, vcp.Description, vcp.ItemId, vcp.MarketItem.Price, vcp.MarketItem.ProductId, vcp.CurrencyAmount, vcp.Currency.ItemId);
            }
            //Virtual goods
            foreach(VirtualGood vg in storeAssets.GetVirtualGoods()){
                string json = vg.PriceModel.toJSONObject().print();
                storeAssets_AddVirtualGood(vg.Name, vg.Description, vg.ItemId, vg.Category.Id, json);
            }

            Debug.Log("done! (pushing data to StoreAssets on ios side)");
            #endif
        }
Ejemplo n.º 6
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();
    }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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);
        }