コード例 #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);
        }
コード例 #3
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;
 }
コード例 #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
        }
コード例 #9
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;
 }
コード例 #10
0
ファイル: VirtualGoodsStorageWP.cs プロジェクト: umardev0/Six
        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
ファイル: VirtualGoodsStorageWP.cs プロジェクト: umardev0/Six
        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());
        }
コード例 #18
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 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
ファイル: StoreInventory.cs プロジェクト: helghast/OMFv3
        /// <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);
        }
コード例 #32
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(), 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;
		}
コード例 #42
0
		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;
		}