예제 #1
0
        /// <summary>
        /// Buys the purchasable virtual item.
        /// Implementation in subclasses will be according to specific type of purchase.
        /// </summary>
        /// <param name="payload">a string you want to be assigned to the purchase. This string
        /// is saved in a static variable and will be given bacl to you when the
        ///  purchase is completed.</param>
        /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception>
        public override void Buy(string payload)
        {
            SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with "
                                 + Amount + " pieces of " + TargetItemId);

            VirtualItem item = getTargetVirtualItem();

            if (item == null)
            {
                return;
            }


            JSONObject eventJSON = new JSONObject();

            eventJSON.AddField("itemId", AssociatedItem.ItemId);
            StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true);

            if (!checkTargetBalance(item))
            {
                throw new InsufficientFundsException(TargetItemId);
            }

            item.Take(Amount);

            AssociatedItem.Give(1);

            // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", AssociatedItem.ItemId);
                eventJSON.AddField("payload", payload);
                StoreEvents.Instance.onItemPurchased(eventJSON.print(), true);
            });
        }
예제 #2
0
        /** VIRTUAL ITEMS **/

        /// <summary>
        /// Gives your user the given amount of the virtual item with the given <c>itemId</c>.
        /// For example, when your user plays your game for the first time you GIVE him/her 1000 gems.
        ///
        /// NOTE: This action is different than buy -
        /// You use <c>give(int amount)</c> to give your user something for free.
        /// You use <c>buy()</c> to give your user something and you get something in return.
        /// </summary>
        /// <param name="itemId">Id of the item to be given.</param>
        /// <param name="amount">Amount of the item to be given.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static void GiveItem(string itemId, int amount)
        {
            SoomlaUtils.LogDebug(TAG, "Giving: " + amount + " pieces of: " + itemId);
            VirtualItem item = StoreInfo.GetItemByItemId(itemId);

            item.Give(amount);
        }
 protected override int _add(VirtualItem item, int amount, bool notify)
 {
     int retBalance;
     SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId);
     retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().add(vi, amount, notify);
     return retBalance;
 }
예제 #4
0
        protected override int _remove(VirtualItem item, int amount, bool notify)
        {
            int retBalance;

            retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().remove(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId), amount, notify);
            return(retBalance);
        }
예제 #5
0
        protected override int _getBalance(VirtualItem item)
        {
            int retBalance;

            retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().getBalance(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId));
            return(retBalance);
        }
예제 #6
0
        /// <summary>
        /// Retrieves the balance of the given virtual item.
        /// </summary>
        /// <returns>The balance of the required virtual item.</returns>
        /// <param name="item">The required virtual item.</param>
        public static int GetBalance(VirtualItem item)
        {
            SoomlaUtils.LogDebug(TAG, "fetching balance for virtual item with itemId: "
                                 + item.ItemId);

            return(instance._getBalance(item));
        }
예제 #7
0
        protected virtual int _add(VirtualItem item, int amount, bool notify)
        {
#if UNITY_EDITOR
            string itemId  = item.ItemId;
            int    balance = _getBalance(item);
            if (balance < 0)               /* in case the user "adds" a negative value */
            {
                balance = 0;
                amount  = 0;
            }
            string balanceStr = "" + (balance + amount);
            string key        = keyBalance(itemId);

            PlayerPrefs.SetString(key, balanceStr);

            if (notify)
            {
                postBalanceChangeEvent(item, balance + amount, amount);
            }

            return(balance + amount);
#else
            return(0);
#endif
        }
예제 #8
0
        protected virtual int _setBalance(VirtualItem item, int balance, bool notify)
        {
#if UNITY_EDITOR
            int oldBalance = _getBalance(item);
            if (oldBalance == balance)
            {
                return(balance);
            }

            string itemId = item.ItemId;

            string balanceStr = "" + balance;
            string key        = keyBalance(itemId);

            PlayerPrefs.SetString(key, balanceStr);

            if (notify)
            {
                postBalanceChangeEvent(item, balance, 0);
            }

            return(balance);
#else
            return(0);
#endif
        }
 protected override int _getBalance(VirtualItem item)
 {
     int retBalance;
     SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId);
     retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getBalance(vi);
     return retBalance;
 }
예제 #10
0
        protected override int _getBalance(VirtualItem item)
        {
            int retBalance;

            SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId);
            retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getBalance(vi);
            return(retBalance);
        }
예제 #11
0
        protected override int _getBalance(VirtualItem item)
        {
            int outBalance = 0;
            int err        = vgStorage_GetBalance(item.ItemId, out outBalance);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(outBalance);
        }
예제 #12
0
        protected override int _setBalance(VirtualItem item, int balance, bool notify)
        {
            int outBalance = 0;
            int err        = vcStorage_SetBalance(item.ItemId, balance, notify, out outBalance);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(outBalance);
        }
예제 #13
0
        protected override int _remove(VirtualItem item, int amount, bool notify)
        {
            int outBalance = 0;
            int err        = vgStorage_Remove(item.ItemId, amount, notify, out outBalance);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(outBalance);
        }
예제 #14
0
        protected override int _add(VirtualItem item, int amount, bool notify)
        {
            int retBalance;

            SoomlaWpStore.domain.VirtualItem vi = SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId);
            retBalance = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().add(vi, amount, notify);
            return(retBalance);
        }
예제 #15
0
        /// <summary>
        /// Checks if there is enough funds to afford the <code>PurchasableVirtualItem</code>.
        /// Implementation in subclasses will be according to specific type of purchase.
        /// </summary>
        /// <returns>True if there are enough funds to afford the virtual item with the given item id </returns>
        public override bool CanAfford()
        {
            SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Checking affordability of " + AssociatedItem.Name + " with "
                                 + Amount + " pieces of " + TargetItemId);

            VirtualItem targetItem = getTargetVirtualItem();

            return(checkTargetBalance(targetItem));
        }
예제 #16
0
파일: StoreInfo.cs 프로젝트: umardev0/Six
        /// <summary>
        /// Replaces the given virtual item, and then saves the store's metadata
        /// (if requested).
        /// </summary>
        /// <param name="virtualItem">the virtual item to replace.</param>
        /// <param name="saveToDB">should the virtual item be persisted to local DB</param>
        public static void Save(VirtualItem virtualItem, bool saveToDB = true)
        {
            replaceVirtualItem(virtualItem);

            if (saveToDB)
            {
                Save();
            }
        }
예제 #17
0
        protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded)
        {
            JSONObject eventJSON = new JSONObject();

            eventJSON.AddField("itemId", item.ItemId);
            eventJSON.AddField("balance", balance);
            eventJSON.AddField("amountAdded", amountAdded);
            StoreEvents.Instance.onCurrencyBalanceChanged(eventJSON.print());
        }
		protected override int _remove(VirtualItem item, int amount, bool notify){
			int retBalance;
			AndroidJNI.PushLocalFrame(100);
			using(AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) {
				using(AndroidJavaObject jniVCStorage = jniStorageManager.CallStatic<AndroidJavaObject>("getVirtualCurrencyStorage")) {
					retBalance = jniVCStorage.Call<int>("remove", item.ItemId, amount, notify);
				}
			}
			AndroidJNI.PopLocalFrame(IntPtr.Zero);
			return retBalance;
		}
예제 #19
0
        private VirtualItem getTargetVirtualItem()
        {
            VirtualItem item = null;

            try {
                item = StoreInfo.GetItemByItemId(TargetItemId);
            }
            catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !");
            }
            return(item);
        }
예제 #20
0
        /// <summary>
        /// Gets the purchasable item with the given <c>productId</c>.
        /// </summary>
        /// <param name="productId">Product id.</param>
        /// <returns>Purchasable virtual item with the given id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception>
        override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId)
        {
            VirtualItem vi = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
        }
예제 #21
0
        protected override int _getBalance(VirtualItem item)
        {
            int retBalance;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) {
                using (AndroidJavaObject jniVCStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualCurrencyStorage")) {
                    retBalance = jniVCStorage.Call <int>("getBalance", item.ItemId);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(retBalance);
        }
예제 #22
0
        /// <summary>
        /// Retrieves the balance of the virtual item with the given <c>itemId</c>.
        /// </summary>
        /// <param name="itemId">Id of the virtual item to be fetched.</param>
        /// <returns>Balance of the virtual item with the given item id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static int GetItemBalance(string itemId)
        {
            int amount;

            if (localItemBalances.TryGetValue(itemId, out amount))
            {
                return(amount);
            }

            VirtualItem item = StoreInfo.GetItemByItemId(itemId);

            return(item.GetBalance());
        }
예제 #23
0
        protected override int _remove(VirtualItem item, int amount, bool notify)
        {
            int retBalance;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) {
                using (AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualGoodsStorage")) {
                    retBalance = jniVGStorage.Call <int>("remove", item.ItemId, amount, notify);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(retBalance);
        }
예제 #24
0
        /// <summary>
        /// Gets the purchasable item with the given <c>productId</c>.
        /// </summary>
        /// <param name="productId">Product id.</param>
        /// <returns>Purchasable virtual item with the given id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception>
        override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId)
        {
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetPurchasableItemWithProductId(productId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string nonConsJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

            JSONObject obj = new JSONObject(nonConsJson);

            return((PurchasableVirtualItem)VirtualItem.factoryItemFromJSONObject(obj));
        }
예제 #25
0
        /// <summary>
        /// Gets the item with the given <c>itemId</c>.
        /// </summary>
        /// <param name="itemId">Item id.</param>
        /// <returns>Item with the given id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception>
        override protected VirtualItem _getItemByItemId(string itemId)
        {
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetItemByItemId(itemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string json = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);
            SoomlaUtils.LogDebug(TAG, "Got json: " + json);

            JSONObject obj = new JSONObject(json);

            return(VirtualItem.factoryItemFromJSONObject(obj));
        }
예제 #26
0
		/** Unity-Editor Functions **/

		protected virtual int _getBalance(VirtualItem item) {
#if UNITY_EDITOR
			string itemId = item.ItemId;
			string key = keyBalance(itemId);
			string val = PlayerPrefs.GetString(key);
			
			int balance = 0;
			if (!string.IsNullOrEmpty(val)) {
				balance = int.Parse(val);
			}
			
			SoomlaUtils.LogDebug(TAG, "the balance for " + item.ItemId + " is " + balance);
			
			return balance;
#else
			return 0;
#endif
		}
예제 #27
0
        /// <summary>
        /// Fetches the virtual goods of your game.
        /// </summary>
        /// <returns>All virtual goods.</returns>
        override protected List <VirtualGood> _getVirtualGoods()
        {
            List <VirtualGood> virtualGoods = new List <VirtualGood>();

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualGoods = new AndroidJavaClass("com.soomla.store.data.StoreInfo").CallStatic <AndroidJavaObject>("getGoods")) {
                for (int i = 0; i < jniVirtualGoods.Call <int>("size"); i++)
                {
                    AndroidJNI.PushLocalFrame(100);
                    using (AndroidJavaObject jniGood = jniVirtualGoods.Call <AndroidJavaObject>("get", i)) {
                        virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJNI(jniGood));
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(virtualGoods);
        }
예제 #28
0
        /// <summary>
        /// Buys the purchasable virtual item.
        /// Implementation in subclasses will be according to specific type of purchase.
        /// </summary>
        /// <param name="payload">a string you want to be assigned to the purchase. This string
        /// is saved in a static variable and will be given bacl to you when the
        ///  purchase is completed.</param>
        /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception>
        public override void Buy(string payload)
        {
            SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with "
                                 + Amount + " pieces of " + TargetItemId);

            VirtualItem item = null;

            try {
                item = StoreInfo.GetItemByItemId(TargetItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !");
                return;
            }

            JSONObject eventJSON = new JSONObject();

            eventJSON.AddField("itemId", AssociatedItem.ItemId);
            StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print());

            int balance = item.GetBalance();

            if (item is VirtualCurrency)
            {
                balance = VirtualCurrencyStorage.GetBalance(item);
            }
            else
            {
                balance = VirtualGoodsStorage.GetBalance(item);
            }

            if (balance < Amount)
            {
                throw new InsufficientFundsException(TargetItemId);
            }

            item.Take(Amount);

            AssociatedItem.Give(1);

            eventJSON = new JSONObject();
            eventJSON.AddField("itemId", AssociatedItem.ItemId);
            eventJSON.AddField("payload", payload);
            StoreEvents.Instance.onItemPurchased(eventJSON.print());
        }
예제 #29
0
        /** Unity-Editor Functions **/

        protected virtual int _getBalance(VirtualItem item)
        {
#if UNITY_EDITOR
            string itemId = item.ItemId;
            string key    = keyBalance(itemId);
            string val    = PlayerPrefs.GetString(key);

            int balance = 0;
            if (!string.IsNullOrEmpty(val))
            {
                balance = int.Parse(val);
            }

            SoomlaUtils.LogDebug(TAG, "the balance for " + item.ItemId + " is " + balance);

            return(balance);
#else
            return(0);
#endif
        }
예제 #30
0
		protected virtual int _add(VirtualItem item, int amount, bool notify){
#if UNITY_EDITOR
			string itemId = item.ItemId;
			int balance = _getBalance(item);
			if (balance < 0) { /* in case the user "adds" a negative value */
				balance = 0;
				amount = 0;
			}
			string balanceStr = "" + (balance + amount);
			string key = keyBalance(itemId);

			PlayerPrefs.SetString(key, balanceStr);
			
			if (notify) {
				postBalanceChangeEvent(item, balance+amount, amount);
			}
			
			return balance + amount;
#else
			return 0;
#endif
		}
예제 #31
0
        /// <summary>
        /// Fetches the virtual goods of your game.
        /// </summary>
        /// <returns>All virtual goods.</returns>
        override protected List <VirtualGood> _getVirtualGoods()
        {
            List <VirtualGood> virtualGoods = new List <VirtualGood>();
            IntPtr             p            = IntPtr.Zero;
            int err = storeInfo_GetVirtualGoods(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string goodsJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

            SoomlaUtils.LogDebug(TAG, "Got json: " + goodsJson);

            JSONObject goodsArr = new JSONObject(goodsJson);

            foreach (JSONObject obj in goodsArr.list)
            {
                virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJSONObject(obj));
            }
            return(virtualGoods);
        }
        /// <summary>
        /// Buys the purchasable virtual item.
        /// Implementation in subclasses will be according to specific type of purchase.
        /// </summary>
        /// <param name="payload">a string you want to be assigned to the purchase. This string
        /// is saved in a static variable and will be given bacl to you when the
        ///  purchase is completed.</param>
        /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception>
        public override void Buy(string payload)
        {
            SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with "
                                 + Amount + " pieces of " + TargetItemId);

            VirtualItem item = null;

            try {
                item = StoreInfo.GetItemByItemId(TargetItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !");
                return;
            }

            JSONObject eventJSON = new JSONObject();

            eventJSON.AddField("itemId", AssociatedItem.ItemId);
            StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true);

            int balance = item.GetBalance();

            if (balance < Amount)
            {
                throw new InsufficientFundsException(TargetItemId);
            }

            item.Take(Amount);

            AssociatedItem.Give(1);

            // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", AssociatedItem.ItemId);
                eventJSON.AddField("payload", payload);
                StoreEvents.Instance.onItemPurchased(eventJSON.print(), true);
            });
        }
예제 #33
0
		protected virtual int _setBalance(VirtualItem item, int balance, bool notify) {
#if UNITY_EDITOR
			int oldBalance = _getBalance(item);
			if (oldBalance == balance) {
				return balance;
			}
			
			string itemId = item.ItemId;
			
			string balanceStr = "" + balance;
			string key = keyBalance(itemId);

			PlayerPrefs.SetString(key, balanceStr);

			if (notify) {
				postBalanceChangeEvent(item, balance, 0);
			}
			
			return balance;
#else
			return 0;
#endif
		}
예제 #34
0
        protected virtual int _remove(VirtualItem item, int amount, bool notify)
        {
#if UNITY_EDITOR
            string itemId  = item.ItemId;
            int    balance = _getBalance(item) - amount;
            if (balance < 0)
            {
                balance = 0;
                amount  = 0;
            }
            string balanceStr = "" + balance;
            string key        = keyBalance(itemId);
            PlayerPrefs.SetString(key, balanceStr);

            if (notify)
            {
                postBalanceChangeEvent(item, balance, -1 * amount);
            }

            return(balance);
#else
            return(0);
#endif
        }
예제 #35
0
		/// <summary>
		/// Adds the given amount of items to the storage, and if notify is true
		/// posts the change in the balance to the event bus.
		/// </summary>
		/// <param name="item">the required virtual item.</param>
		/// <param name="amount">the amount of items to add.</param>
		/// <param name="notify">notify if true posts balance change event.</param>
		public static int Add(VirtualItem item, int amount, bool notify){
			SoomlaUtils.LogDebug(TAG, "adding " + amount + " " + item.ItemId);

			return instance._add(item, amount, notify);
		}
예제 #36
0
		/// <summary>
		/// Same as the other SetBalance but with "notify".
		/// </summary>
		/// <param name="item">the required virtual item.</param>
		/// <param name="balance">the new balance to be set.</param>
		/// <param name="notify">if notify is true post balance change event.</param>
		/// <returns>the balance of the required virtual item</returns>
		public static int SetBalance(VirtualItem item, int balance, bool notify){
			SoomlaUtils.LogDebug(TAG, "setting balance " + balance + " to " + item.ItemId + ".");
			
			return instance._setBalance(item, balance, notify);
		}
예제 #37
0
		/// <summary>
		/// Adds the given amount of items to the storage.
		/// </summary>
		/// <param name="item">the required virtual item.</param>
		/// <param name="amount">the amount of items to add.</param>
		public static int Add(VirtualItem item, int amount){
			return Add(item, amount, true);
		}
예제 #38
0
		/// <summary>
		/// Retrieves the balance of the given virtual item.
		/// </summary>
		/// <returns>The balance of the required virtual item.</returns>
		/// <param name="item">The required virtual item.</param>
		public static int GetBalance(VirtualItem item){
			SoomlaUtils.LogDebug(TAG, "fetching balance for virtual item with itemId: "
			                     + item.ItemId);
			
			return instance._getBalance(item);
		}
예제 #39
0
		/// <summary>
		/// Sets the balance of the given virtual item to be the given balance, and if notify is true
		/// posts the change in the balance to the event bus.
		/// </summary>
		/// <param name="item">the required virtual item.</param>
		/// <param name="balance">the new balance to be set.</param>
		/// <returns>the balance of the required virtual item</returns>
		public static int SetBalance(VirtualItem item, int balance){
			return SetBalance(item, balance, true);
		}
예제 #40
0
		protected virtual int _remove(VirtualItem item, int amount, bool notify){
#if UNITY_EDITOR
			string itemId = item.ItemId;
			int balance = _getBalance(item) - amount;
			if (balance < 0) {
				balance = 0;
				amount = 0;
			}
			string balanceStr = "" + balance;
			string key = keyBalance(itemId);
			PlayerPrefs.SetString(key, balanceStr);
			
			if (notify) {
				postBalanceChangeEvent(item, balance, -1*amount);
			}
			
			return balance;
#else
			return 0;
#endif
		}
예제 #41
0
		protected override int _setBalance(VirtualItem item, int balance, bool notify) {
			int outBalance = 0;
			int err = vgStorage_SetBalance(item.ItemId, balance, notify, out outBalance);
			IOS_ErrorCodes.CheckAndThrowException(err);
			return outBalance;
		}
		protected override int _getBalance(VirtualItem item) {
			int retBalance;
			AndroidJNI.PushLocalFrame(100);
			using(AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) {
				using(AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic<AndroidJavaObject>("getVirtualGoodsStorage")) {
					retBalance = jniVGStorage.Call<int>("getBalance", item.ItemId);
				}
			}
			AndroidJNI.PopLocalFrame(IntPtr.Zero);
			return retBalance;
		}
예제 #43
0
		protected override int _add(VirtualItem item, int amount, bool notify){
			int outBalance = 0;
			int err = vgStorage_Add(item.ItemId, amount, notify, out outBalance);
			IOS_ErrorCodes.CheckAndThrowException(err);
			return outBalance;
		}
예제 #44
0
		protected override int _getBalance(VirtualItem item) {
			int retBalance;
            retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().getBalance(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId));			
			return retBalance;
		}
예제 #45
0
		protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded) {
			JSONObject eventJSON = new JSONObject();
			eventJSON.AddField("itemId", item.ItemId);
			eventJSON.AddField("balance", balance);
			eventJSON.AddField("amountAdded", amountAdded);
			StoreEvents.Instance.onGoodBalanceChanged(eventJSON.print());
		}
예제 #46
0
		protected abstract void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded);
예제 #47
0
 private bool checkTargetBalance(VirtualItem item)
 {
     int balance = item.GetBalance ();
     return balance >= Amount;
 }
예제 #48
0
 // When insufficient funds, page opens shop
 void onNotEnoughTargetItem(VirtualItem item)
 {
     if (item.ItemId == "seed")
         UIServer.main.ShowPage ("Store");
     StoreInventory.GetItemBalance (item.ID);
 }
예제 #49
0
		/// <summary>
		/// Removes the given amount from the given virtual item's balance.
		/// </summary>
		/// <param name="item">the virtual item to remove the given amount from.</param>
		/// <param name="amount">the amount to remove.</param>
		public static int Remove(VirtualItem item, int amount){
			return Remove(item, amount, true);
		}
예제 #50
0
		protected override int _getBalance(VirtualItem item) {
			int outBalance = 0;
			int err = vgStorage_GetBalance(item.ItemId, out outBalance);
			IOS_ErrorCodes.CheckAndThrowException(err);
			return outBalance;
		}
예제 #51
0
		/// <summary>
		/// Removes the given amount from the given virtual item's balance.
		/// </summary>
		/// <param name="item">the virtual item to remove the given amount from.</param>
		/// <param name="amount">the amount to remove.</param>
		/// <param name="notify">notify is true post balance change event</para>
		public static int Remove(VirtualItem item, int amount, bool notify){
			SoomlaUtils.LogDebug(TAG, "Removing " + amount + " " + item.ItemId + ".");
			
			return instance._remove(item, amount, true);
		}
예제 #52
0
        private bool checkTargetBalance(VirtualItem item)
        {
            int balance = item.GetBalance();

            return(balance > Amount);
        }
예제 #53
0
		protected override int _remove(VirtualItem item, int amount, bool notify){
			int retBalance;
            retBalance = SoomlaWpStore.data.StorageManager.getVirtualCurrencyStorage().remove(SoomlaWpStore.data.StoreInfo.getVirtualItem(item.ItemId), amount, notify);
			return retBalance;
		}
예제 #54
0
 /// <summary>
 /// Replaces the given virtual item, and then saves the store's metadata.
 /// </summary>
 /// <param name="virtualItem">the virtual item to replace.</param>
 public static void Save(VirtualItem virtualItem)
 {
     replaceVirtualItem(virtualItem);
     Save();
 }
예제 #55
0
        true);                          // Last 
    #endregion
    #endregion

    #region Private Functions
    private static VirtualGood CreateUpgrade(VirtualItem upgradedGood, string upgradeItemId, string upgradeName, string upgradeDescription, int level, int price, bool isLast = false)
    {
        var prevItemId = level > 1 ? upgradeItemId + (level - 1) : null;
        var nextItemId = isLast ? null : upgradeItemId + (level + 1);

        return new UpgradeVG(
        upgradedGood.ItemId,            // Good Item ID
        nextItemId,                     // Next Upgrade Item ID
        prevItemId,                     // Previous Upgrade Item ID
        upgradeName,                    // Name
        upgradeDescription + level,     // Description
        upgradeItemId + level,          // Item ID
        new PurchaseWithVirtualItem(    // Purchase type
            Coin.ItemId,                // Virtual item to pay with
            price)                      // Payment amount
        );
    }
예제 #56
0
		private bool checkTargetBalance (VirtualItem item)
		{
			int balance = StoreInventory.GetItemBalance(item.ItemId);
			return balance >= Amount;
		}