示例#1
0
        /// <summary>
        /// Takes a curtain amount of <c>VirtualCurrency</c> according to the given amount and the definition of this pack.
        /// </summary>
        /// <param name="amount">the amount of the specific item to be taken.</param>
        /// <param name="notify">notify of change in user's balance of current virtual item.</param>
        public override int Take(int amount, bool notify)
        {
            VirtualCurrency currency = null;

            try {
                currency = (VirtualCurrency)StoreInfo.GetItemByItemId(CurrencyItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualCurrency with itemId: " + CurrencyItemId +
                                     " doesn't exist! Can't take this pack.");
                return(0);
            }
            return(VirtualCurrencyStorage.Remove(currency, CurrencyAmount * amount, notify));
        }
示例#2
0
        /// <summary>
        /// Equips the virtual good with the given <c>goodItemId</c>.
        /// Equipping means that the user decides to currently use a specific virtual good.
        /// For more details and examples <see cref="com.soomla.store.domain.virtualGoods.EquippableVG"/>.
        /// </summary>
        /// <param name="goodItemId">Id of the good to be equipped.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        /// <exception cref="NotEnoughGoodsException"></exception>
        public static void EquipVirtualGood(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "Equipping: " + goodItemId);

            EquippableVG good = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

            try {
                good.Equip();
            } catch (NotEnoughGoodsException e) {
                SoomlaUtils.LogError(TAG, "UNEXPECTED! Couldn't equip something");
                throw e;
            }
        }
示例#3
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // in the editor we just give the item... no real market.
            item.Give(1);
#endif
        }
示例#4
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());
        }
示例#5
0
        protected override UpgradeVG _getCurrentUpgrade(VirtualGood good)
        {
            string upgradeVGItemId;
            int    err = vgStorage_GetCurrentUpgrade(good.ItemId, out upgradeVGItemId);

            IOS_ErrorCodes.CheckAndThrowException(err);

            if (!string.IsNullOrEmpty(upgradeVGItemId))
            {
                return((UpgradeVG)StoreInfo.GetItemByItemId(upgradeVGItemId));
            }

            return(null);
        }
示例#6
0
        public static void onMarketPurchase(MarketPurchaseEvent _Event)
        {
            SoomlaWpStore.domain.PurchasableVirtualItem purchasableVirtualItem = _Event.GetPurchasableVirtualItem();
            String payload = _Event.GetPayload();
            String token   = _Event.GetToken();

            Debug.Log("SOOMLA/UNITY onMarketPurchase:" + purchasableVirtualItem.getItemId() + " " + payload + " " + token);

            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(purchasableVirtualItem.getItemId());
            //TODO Implement extra on WP8 onMarketPurchase
            Dictionary <string, string> extra = new Dictionary <string, string>();

            StoreEvents.OnMarketPurchase(pvi, payload, extra);
        }
示例#7
0
        /// <summary>
        /// Removes all upgrades from the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">Id of the good whose upgrades are to be removed.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static void RemoveGoodUpgrades(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY Calling RemoveGoodUpgrades with: " + goodItemId);

            List <UpgradeVG> upgrades = StoreInfo.GetUpgradesForVirtualGood(goodItemId);

            foreach (UpgradeVG upgrade in upgrades)
            {
                VirtualGoodsStorage.Remove(upgrade, 1, true);
            }
            VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId);

            VirtualGoodsStorage.RemoveUpgrades(good);
        }
示例#8
0
        public static void onItemPurchaseStarted(ItemPurchaseStartedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.PurchasableVirtualItem purchasableVirtualItem = _Event.GetPurchasableVirtualItem();
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onItemPurchaseStarted:" + purchasableVirtualItem.getItemId());

            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(purchasableVirtualItem.getItemId());

            StoreEvents.OnItemPurchaseStarted(pvi);

            if (alsoPush)
            {
                sep.PushEventOnItemPurchaseStarted(_Event);
            }
        }
示例#9
0
        /// <summary>
        /// Initializes the SOOMLA SDK.
        /// </summary>
        /// <param name="storeAssets">Your game's economy.</param>
        /// <exception cref="ExitGUIException">Thrown if soomlaSecret is missing or has not been changed.</exception>
        public static bool Initialize(IStoreAssets storeAssets)
        {
            StoreEvents.Initialize();
            if (string.IsNullOrEmpty(CoreSettings.SoomlaSecret))
            {
                SoomlaUtils.LogError(TAG, "MISSING SoomlaSecret !!! Stopping here !!");
                throw new ExitGUIException();
            }

            if (CoreSettings.SoomlaSecret == CoreSettings.ONLY_ONCE_DEFAULT)
            {
                SoomlaUtils.LogError(TAG, "You have to change SoomlaSecret !!! Stopping here !!");
                throw new ExitGUIException();
            }

            var storeEvents = GameObject.FindObjectOfType <StoreEvents> ();

            if (storeEvents == null)
            {
                SoomlaUtils.LogDebug(TAG, "StoreEvents Component not found in scene. We're continuing from here but you won't get many events.");
            }

            if (Initialized)
            {
                StoreEvents.Instance.onUnexpectedStoreError("{\"errorCode\": 0}", true);
                SoomlaUtils.LogError(TAG, "SoomlaStore is already initialized. You can't initialize it twice!");
                return(false);
            }

            SoomlaUtils.LogDebug(TAG, "SoomlaStore Initializing ...");

            StoreInfo.SetStoreAssets(storeAssets);

            instance._loadBillingService();

                        #if UNITY_IOS
            // On iOS we only refresh market items
            instance._refreshMarketItemsDetails();
#elif UNITY_ANDROID
            // On Android we refresh market items and restore transactions
            instance._refreshInventory();
#elif UNITY_WP8
            instance._refreshInventory();
#endif

            Initialized = true;
            StoreEvents.Instance.onSoomlaStoreInitialized("", true);

            return(true);
        }
示例#10
0
        /// <summary>
        /// Retrieves the current upgrade of the good with the given id.
        /// </summary>
        /// <param name="goodItemId">Id of the good whose upgrade we want to fetch. </param>
        /// <returns>The good's current upgrade.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        public static string GetGoodCurrentUpgrade(string goodItemId)
        {
            SoomlaUtils.LogDebug(TAG, "Checking " + goodItemId + " current upgrade");

            VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId);

            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            if (upgradeVG == null)
            {
                return("");
            }
            return(upgradeVG.ItemId);
        }
示例#11
0
文件: UpgradeVG.cs 项目: umardev0/Six
        /// <summary>
        /// Takes upgrade from the user, or in other words DOWNGRADES the associated
        /// <code>VirtualGood</code> (mGood).
        /// Checks if the current Upgrade is really associated with the <code>VirtualGood</code> and:
        /// </summary>
        /// <param name="amount">NOT USED HERE!.</param>
        /// <param name="notify">see parent.</param>
        public override int Take(int amount, bool notify)
        {
            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId
                                     + " doesn't exist! Can't downgrade.");
                return(0);
            }

            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            // Case: Upgrade is not assigned to this Virtual Good
            if (upgradeVG != this)
            {
                SoomlaUtils.LogError(TAG, "You can't take an upgrade that's not currently assigned."
                                     + "The UpgradeVG " + Name + " is not assigned to " + "the VirtualGood: "
                                     + good.Name);
                return(0);
            }

            if (!string.IsNullOrEmpty(PrevItemId))
            {
                UpgradeVG prevUpgradeVG = null;
                // Case: downgrade is not possible because previous upgrade does not exist
                try {
                    prevUpgradeVG = (UpgradeVG)StoreInfo.GetItemByItemId(PrevItemId);
                } catch (VirtualItemNotFoundException) {
                    SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + PrevItemId
                                         + " doesn't exist! Can't downgrade.");
                    return(0);
                }
                // Case: downgrade is successful!
                SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to: "
                                     + prevUpgradeVG.Name);
                VirtualGoodsStorage.AssignCurrentUpgrade(good, prevUpgradeVG, notify);
            }

            // Case: first Upgrade in the series - so we downgrade to NO upgrade.
            else
            {
                SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to NO-UPGRADE");
                VirtualGoodsStorage.RemoveUpgrades(good, notify);
            }

            return(base.Take(amount, notify));
        }
示例#12
0
        /// <summary>
        /// Handles an <c>onGoodUpgrade</c> event, which is fired when a specific <c>UpgradeVG</c> has
        /// been upgraded/downgraded.
        /// </summary>
        /// <param name="message">Message that contains information about the good that has been
        /// upgraded/downgraded.</param>
        public void onGoodUpgrade(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + message);

            string[] vars = Regex.Split(message, "#SOOM#");

            VirtualGood vg  = (VirtualGood)StoreInfo.GetItemByItemId(vars[0]);
            UpgradeVG   vgu = null;

            if (vars.Length > 1)
            {
                vgu = (UpgradeVG)StoreInfo.GetItemByItemId(vars[1]);
            }
            StoreEvents.OnGoodUpgrade(vg, vgu);
        }
示例#13
0
        public static void onGoodUnequipped(GoodUnEquippedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.EquippableVG good = _Event.GetEquippableVG();
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onVirtualGoodUnEquipped:" + good.getItemId());

            EquippableVG vg = (EquippableVG)StoreInfo.GetItemByItemId(good.getItemId());

            StoreInventory.RefreshOnGoodUnEquipped(vg);
            StoreEvents.OnGoodUnEquipped(vg);

            if (alsoPush)
            {
                sep.PushEventOnGoodUnequipped(_Event);
            }
        }
示例#14
0
        /// <summary>
        /// Handles the <c>onMarketPurchaseDeferred</c> event, which is fired when a Market purchase was deferred
        /// until it can be finished by the family delegate.
        /// Note that this is an iOS only event for when users have set up "Ask to Buy" and the purchaser is
        /// selected as a family member that needs "family organizer" permission to buy.
        /// <see href="https://support.apple.com/en-us/HT201089">Apple's explanation of "Ask to Buy"</see>
        /// </summary>
        /// <param name="message">Message that contains information about the market purchase that is being
        /// deferred.</param>
        public void onMarketPurchaseDeferred(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketPurchaseDeferred: " + message);

            var eventJSON = new JSONObject(message);

            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);
            string payload             = "";

            if (eventJSON.HasField("payload"))
            {
                payload = eventJSON["payload"].str;
            }
            StoreEvents.OnMarketPurchaseDeferred(pvi, payload);
        }
示例#15
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // simulate onMarketPurchaseStarted event
            var eventJSON = new JSONObject();
            eventJSON.AddField("itemId", item.ItemId);
            eventJSON.AddField("payload", payload);
            StoreEvents.Instance.onMarketPurchaseStarted(eventJSON.print());

            // simulate events as they happen on the device
            // the order is :
            //    onMarketPurchase
            //    give item
            //    onItemPurchase
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", item.ItemId);
                eventJSON.AddField("payload", payload);
                var extraJSON = new JSONObject();
                        #if UNITY_IOS
                extraJSON.AddField("receipt", "fake_receipt_abcd1234");
                extraJSON.AddField("token", "fake_token_zyxw9876");
                        #elif UNITY_ANDROID
                extraJSON.AddField("orderId", "fake_orderId_abcd1234");
                extraJSON.AddField("purchaseToken", "fake_purchaseToken_zyxw9876");
                        #endif
                eventJSON.AddField("extra", extraJSON);
                StoreEvents.Instance.onMarketPurchase(eventJSON.print());

                // in the editor we just give the item... no real market.
                item.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", item.ItemId);
                    eventJSON.AddField("payload", payload);
                    StoreEvents.Instance.onItemPurchased(eventJSON.print());
                });
            });
#endif
        }
示例#16
0
        /// <summary>
        /// Handles an <c>onItemPurchased</c> event, which is fired when a specific
        /// <c>PurchasableVirtualItem</c> has been purchased.
        /// </summary>
        /// <param name="message">Message that contains information about the good that has been purchased.</param>
        public void onItemPurchased(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onItemPurchased:" + message);

            string[] vars = Regex.Split(message, "#SOOM#");

            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(vars[0]);
            string payload             = "";

            if (vars.Length > 1)
            {
                payload = vars[1];
            }

            StoreEvents.OnItemPurchased(pvi, payload);
        }
示例#17
0
        protected override UpgradeVG _getCurrentUpgrade(VirtualGood good)
        {
            SoomlaWpStore.domain.virtualGoods.UpgradeVG   uvg = null;
            SoomlaWpStore.domain.virtualGoods.VirtualGood vg  = (SoomlaWpStore.domain.virtualGoods.VirtualGood)SoomlaWpStore.data.StoreInfo.getVirtualItem(good.ItemId);
            if (vg is SoomlaWpStore.domain.virtualGoods.UpgradeVG)
            {
                uvg = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(vg);
            }

            if (uvg != null)
            {
                return((UpgradeVG)StoreInfo.GetItemByItemId(uvg.GetId()));
            }

            return(null);
        }
示例#18
0
        /// <summary>
        /// Initializes the SOOMLA SDK.
        /// </summary>
        /// <param name="storeAssets">Your game's economy.</param>
        /// <exception cref="ExitGUIException">Thrown if soomlaSecret is missing or has not been changed.
        /// </exception>
        protected override void _initialize(IStoreAssets storeAssets)
        {
            if (StoreSettings.GPlayBP &&
                (string.IsNullOrEmpty(StoreSettings.AndroidPublicKey) ||
                 StoreSettings.AndroidPublicKey == StoreSettings.AND_PUB_KEY_DEFAULT))
            {
                SoomlaUtils.LogError(TAG, "SOOMLA/UNITY You chose Google Play billing service but publicKey is not set!! Stopping here!!");
                throw new ExitGUIException();
            }

            if (StoreSettings.BazaarBP &&
                (string.IsNullOrEmpty(StoreSettings.BazaarPublicKey) ||
                 StoreSettings.BazaarPublicKey == StoreSettings.BAZAAR_PUB_KEY_DEFAULT))
            {
                SoomlaUtils.LogError(TAG, "SOOMLA/UNITY You chose Bazaar billing service but publicKey is not set!! Stopping here!!");
                throw new ExitGUIException();
            }
            StoreInfo.Initialize(storeAssets);

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniStoreAssetsInstance = new AndroidJavaObject("com.soomla.unity.StoreAssets")) {
                using (AndroidJavaClass jniSoomlaStoreClass = new AndroidJavaClass("com.soomla.store.SoomlaStore")) {
                    jniSoomlaStore = jniSoomlaStoreClass.CallStatic <AndroidJavaObject>("getInstance");
                    jniSoomlaStore.Call <bool>("initialize", jniStoreAssetsInstance);
                }
            }

            if (StoreSettings.GPlayBP)
            {
                using (AndroidJavaClass jniGooglePlayIabServiceClass = new AndroidJavaClass("com.soomla.store.billing.google.GooglePlayIabService")) {
                    AndroidJavaObject jniGooglePlayIabService = jniGooglePlayIabServiceClass.CallStatic <AndroidJavaObject>("getInstance");
                    jniGooglePlayIabService.Call("setPublicKey", StoreSettings.AndroidPublicKey);

                    jniGooglePlayIabServiceClass.SetStatic("AllowAndroidTestPurchases", StoreSettings.AndroidTestPurchases);
                }
            }
            if (StoreSettings.BazaarBP)
            {
                using (AndroidJavaClass jniBazaarIabServiceClass = new AndroidJavaClass("com.soomla.store.billing.bazaar.BazaarIabService")) {
                    AndroidJavaObject jniBazaarIabService = jniBazaarIabServiceClass.CallStatic <AndroidJavaObject>("getInstance");
                    jniBazaarIabService.Call("setPublicKey", StoreSettings.BazaarPublicKey);

                    jniBazaarIabServiceClass.SetStatic("AllowAndroidTestPurchases", StoreSettings.BazaarTestPurchases);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
示例#19
0
        public void onItemPurchaseStarted(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onItemPurchaseStarted:" + message);

            var eventJSON = new JSONObject(message);

            PurchasableVirtualItem pvi = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);

            StoreEvents.OnItemPurchaseStarted(pvi);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnItemPurchaseStarted(pvi);
#endif
            }
        }
        protected override UpgradeVG _getCurrentUpgrade(VirtualGood good)
        {
            string upgradeVGItemId = null;

            SoomlaWpStore.domain.virtualGoods.VirtualGood vg = (SoomlaWpStore.domain.virtualGoods.VirtualGood)SoomlaWpStore.data.StoreInfo.getVirtualItem(good.ItemId);
            if (vg is SoomlaWpStore.domain.virtualGoods.UpgradeVG)
            {
                upgradeVGItemId = SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(vg).getItemId();
            }

            if (!string.IsNullOrEmpty(upgradeVGItemId))
            {
                return((UpgradeVG)StoreInfo.GetItemByItemId(upgradeVGItemId));
            }

            return(null);
        }
示例#21
0
        public static void onGoodBalanceChanged(GoodBalanceChangedEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.VirtualGood good = _Event.GetGood();
            int balance     = _Event.GetBalance();
            int amountAdded = _Event.GetAmountAdded();

            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodBalanceChanged:" + good.getItemId() + " " + balance.ToString() + " " + amountAdded.ToString());

            VirtualGood vg = (VirtualGood)StoreInfo.GetItemByItemId(good.getItemId());

            StoreInventory.RefreshOnGoodBalanceChanged(vg, balance, amountAdded);
            StoreEvents.OnGoodBalanceChanged(vg, balance, amountAdded);

            if (alsoPush)
            {
                sep.PushEventOnGoodBalanceChanged(_Event);
            }
        }
示例#22
0
文件: UpgradeVG.cs 项目: umardev0/Six
        /// <summary>
        /// Assigns the current upgrade to the associated <code>VirtualGood</code> (mGood).
        /// </summary>
        /// <param name="amount">NOT USED HERE!</param>
        /// <param name="notify">notify of change in user's balance of current virtual item.</param>
        public override int Give(int amount, bool notify)
        {
            SoomlaUtils.LogDebug(TAG, "Assigning " + Name + " to: " + GoodItemId);

            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId +
                                     " doesn't exist! Can't upgrade.");
                return(0);
            }

            VirtualGoodsStorage.AssignCurrentUpgrade(good, this, notify);

            return(base.Give(amount, notify));
        }
示例#23
0
        /// <summary>
        /// Checks currently equipped good in given <c>category</c>
        /// </summary>
        /// <param name="category">Category we want to check</param>
        /// <returns>EquippableVG otherwise null</returns>
        public static EquippableVG GetEquippedVirtualGood(VirtualCategory category)
        {
            SoomlaUtils.LogDebug(TAG, "Checking equipped goood in " + category.Name + " category");

            foreach (string goodItemId in category.GoodItemIds)
            {
                EquippableVG good = (EquippableVG)StoreInfo.GetItemByItemId(goodItemId);

                if (good != null && good.Equipping == EquippableVG.EquippingModel.CATEGORY &&
                    VirtualGoodsStorage.IsEquipped(good) &&
                    StoreInfo.GetCategoryForVirtualGood(goodItemId) == category)
                {
                    return(good);
                }
            }
            SoomlaUtils.LogError(TAG, "There is no virtual good equipped in " + category.Name + " category");
            return(null);
        }
示例#24
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());
        }
示例#25
0
文件: UpgradeVG.cs 项目: umardev0/Six
        /// <summary>
        /// Determines if the user is in a state that allows him/her to buy an <code>UpgradeVG</code>
        ///	This method enforces allowing/rejecting of upgrades here so users won't buy them when
        /// they are not supposed to.
        /// If you want to give your users free upgrades, use the <code>give</code> function.
        /// </summary>
        /// <returns><c>true</c>, if can buy, <c>false</c> otherwise.</returns>
        protected override bool canBuy()
        {
            VirtualGood good = null;

            try {
                good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId);
            } catch (VirtualItemNotFoundException) {
                SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId +
                                     " doesn't exist! Returning NO (can't buy).");
                return(false);
            }

            UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);

            return(((upgradeVG == null && string.IsNullOrEmpty(PrevItemId)) ||
                    (upgradeVG != null && ((upgradeVG.NextItemId == this.ItemId) ||
                                           (upgradeVG.PrevItemId == this.ItemId)))) &&
                   base.canBuy());
        }
示例#26
0
        protected override UpgradeVG _getCurrentUpgrade(VirtualGood good)
        {
            string upgradeVGItemId;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) {
                using (AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualGoodsStorage")) {
                    upgradeVGItemId = jniVGStorage.Call <string>("getCurrentUpgrade", good.ItemId);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);

            if (!string.IsNullOrEmpty(upgradeVGItemId))
            {
                return((UpgradeVG)StoreInfo.GetItemByItemId(upgradeVGItemId));
            }

            return(null);
        }
示例#27
0
        public void onGoodUnequipped(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onVirtualGoodUnEquipped:" + message);

            var eventJSON = new JSONObject(message);

            EquippableVG vg = (EquippableVG)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);

            StoreInventory.RefreshOnGoodUnEquipped(vg);

            StoreEvents.OnGoodUnEquipped(vg);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnGoodUnequipped(vg);
#endif
            }
        }
示例#28
0
        /// <summary>
        /// Handles the <c>onMarketItemsRefreshFinished</c> event, which is fired when items associated with market are
        /// refreshed (prices, titles ...).
        /// </summary>
        /// <param name="message">Message that contains information about the process that is occurring.</param>
        public void onMarketItemsRefreshFinished(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketItemsRefreshFinished: " + message);

            var eventJSON = new JSONObject(message);

            List <VirtualItem> virtualItems = new List <VirtualItem>();
            List <MarketItem>  marketItems  = new List <MarketItem>();

            foreach (var micJSON in eventJSON.list)
            {
                string productId          = micJSON[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
                string marketPrice        = micJSON[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
                string marketTitle        = micJSON[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
                string marketDescription  = micJSON[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
                string marketCurrencyCode = micJSON[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
                long   marketPriceMicros  = System.Convert.ToInt64(micJSON[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n);
                try {
                    PurchasableVirtualItem pvi = StoreInfo.GetPurchasableItemWithProductId(productId);
                    MarketItem             mi  = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem;
                    mi.MarketPriceAndCurrency = marketPrice;
                    mi.MarketTitle            = marketTitle;
                    mi.MarketDescription      = marketDescription;
                    mi.MarketCurrencyCode     = marketCurrencyCode;
                    mi.MarketPriceMicros      = marketPriceMicros;

                    marketItems.Add(mi);
                    virtualItems.Add(pvi);
                } catch (VirtualItemNotFoundException ex) {
                    SoomlaUtils.LogDebug(TAG, ex.Message);
                }
            }

            if (virtualItems.Count > 0)
            {
                // no need to save to DB since it's already saved in native
                // before this event is received
                StoreInfo.Save(virtualItems, false);
            }

            StoreEvents.OnMarketItemsRefreshFinished(marketItems);
        }
示例#29
0
        public void onGoodBalanceChanged(string message, bool alsoPush)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodBalanceChanged:" + message);

            JSONObject eventJSON = new JSONObject(message);

            VirtualGood vg          = (VirtualGood)StoreInfo.GetItemByItemId(eventJSON["itemId"].str);
            int         balance     = (int)eventJSON["balance"].n;
            int         amountAdded = (int)eventJSON["amountAdded"].n;

            StoreInventory.RefreshOnGoodBalanceChanged(vg, balance, amountAdded);

            StoreEvents.OnGoodBalanceChanged(vg, balance, amountAdded);

            if (alsoPush)
            {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
                sep.PushEventOnGoodBalanceChanged(vg, balance, amountAdded);
#endif
            }
        }
示例#30
0
        public static void onGoodUpgrade(GoodUpgradeEvent _Event, bool alsoPush)
        {
            SoomlaWpStore.domain.virtualGoods.VirtualGood good      = _Event.GetGood();
            SoomlaWpStore.domain.virtualGoods.UpgradeVG   upgradeVG = _Event.GetUpgradeVG();
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + good.getItemId() + " " + upgradeVG.getItemId());

            VirtualGood vg  = (VirtualGood)StoreInfo.GetItemByItemId(good.getItemId());
            UpgradeVG   vgu = null;

            if (upgradeVG != null)
            {
                vgu = (UpgradeVG)StoreInfo.GetItemByItemId(upgradeVG.getItemId());
            }
            StoreInventory.RefreshOnGoodUpgrade(vg, vgu);
            StoreEvents.OnGoodUpgrade(vg, vgu);

            if (alsoPush)
            {
                sep.PushEventOnGoodUpgrade(_Event);
            }
        }