/**
         * Buys the virtual item with other virtual items.
         *
         * @throws com.soomla.store.exceptions.InsufficientFundsException
         */
        public override void buy(String payload)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to buy a " + getAssociatedItem().getName() + " with "
                                 + mAmount + " pieces of " + mTargetItemId);

            VirtualItem item = null;

            try {
                item = StoreInfo.getVirtualItem(mTargetItemId);
            } catch (VirtualItemNotFoundException e) {
                SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !" + " " + e.Message);
                return;
            }

            StoreEvents.GetInstance().PostItemPurchaseStartedEvent(getAssociatedItem());

            VirtualItemStorage storage = StorageManager.getVirtualItemStorage(item);

            Debug.Assert(storage != null);
            int balance = storage.getBalance(item);

            if (balance < mAmount)
            {
                throw new InsufficientFundsException(mTargetItemId);
            }

            storage.remove(item, mAmount);

            getAssociatedItem().give(1);
            //BusProvider.getInstance().post(new OnItemPurchasedEvent(getAssociatedItem(), payload));
            StoreEvents.GetInstance().PostItemPurchasedEvent(getAssociatedItem(), payload);
        }
Exemplo n.º 2
0
        /**
         * Buys the virtual item with real money (from the Market).
         *
         * @throws com.soomla.store.exceptions.InsufficientFundsException
         */
        public override void buy(String payload)
        {
            SoomlaUtils.LogDebug(TAG, "Starting in-app purchase for productId: "
                                 + mMarketItem.getProductId());


            StoreEvents.GetInstance().PostItemPurchaseStartedEvent(getAssociatedItem());

            try {
                SoomlaStore.GetInstance().buyWithMarket(mMarketItem, payload);
            } catch (Exception e) {
                SoomlaUtils.LogError(TAG, "Error when purchasing item " + e.Message);
            }
        }
Exemplo n.º 3
0
        /**
         * Removes any upgrade associated with the given VirtualGood.
         *
         * @param good the virtual good to remove the upgrade from
         * @param notify if true post event to bus
         */
        public void removeUpgrades(VirtualGood good, bool notify)
        {
            SoomlaUtils.LogDebug(mTag, "Removing upgrade information from virtual good: " +
                                 good.getName());

            String itemId = good.getItemId();
            String key    = keyGoodUpgrade(itemId);

            KeyValueStorage.DeleteKeyValue(key);

            if (notify)
            {
                StoreEvents.GetInstance().PostGoodUpgradeEvent(good, null);
            }
        }
Exemplo n.º 4
0
        // Constructeur
        public MainPage()
        {
            InitializeComponent();
            StoreEvents.GetInstance().OnCurrencyBalanceChangedEvent += new CurrencyBalanceChangedEventHandler(UpdateCurrencyBalance);
            StoreEvents.GetInstance().OnGoodBalanceChangedEvent     += new GoodBalanceChangedEventHandler(UpdateGoodBalance);
            StoreEvents.GetInstance().OnGoodEquippedEvent           += new GoodEquippedEventHandler(UpdateGoodEquip);
            StoreEvents.GetInstance().OnGoodUnEquippedEvent         += new GoodUnEquippedEventHandler(UpdateGoodUnequip);

            SoomlaConfig.logDebug = true;
            Soomla.initialize("this_is_my_secret");
            SoomlaStore.GetInstance().initialize(new StoreAssets(), true);

            /// Update the currencies balance on the GUI
            UpdateCurrencyBalance(null, 0, 0);
            buildShop();
        }
Exemplo n.º 5
0
        /**
         * Assigns a specific upgrade to the given virtual good.
         *
         * @param good the VirtualGood to upgrade
         * @param upgradeVG the upgrade to assign
         * @param notify if true post event to bus
         */
        public void assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify)
        {
            if (getCurrentUpgrade(good) != null && getCurrentUpgrade(good).getItemId() == upgradeVG.getItemId())
            {
                return;
            }

            SoomlaUtils.LogDebug(mTag, "Assigning upgrade " + upgradeVG.getName() + " to virtual good: "
                                 + good.getName());

            String itemId   = good.getItemId();
            String key      = keyGoodUpgrade(itemId);
            String upItemId = upgradeVG.getItemId();

            KeyValueStorage.SetValue(key, upItemId);

            if (notify)
            {
                StoreEvents.GetInstance().PostGoodUpgradeEvent(good, upgradeVG);
            }
        }
Exemplo n.º 6
0
        /**
         * Helper function for <code>equip</code> and <code>unequip</code> functions.
         */
        private void equipPriv(EquippableVG good, bool equip, bool notify)
        {
            SoomlaUtils.LogDebug(mTag, (!equip ? "unequipping " : "equipping ") + good.getName() + ".");

            String itemId = good.getItemId();
            String key    = keyGoodEquipped(itemId);

            if (equip)
            {
                KeyValueStorage.SetValue(key, "");
                if (notify)
                {
                    StoreEvents.GetInstance().PostGoodEquippedEvent(good);
                }
            }
            else
            {
                KeyValueStorage.DeleteKeyValue(key);
                if (notify)
                {
                    StoreEvents.GetInstance().PostGoodUnEquippedEvent(good);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>   Loads Windows Store IAP informations. </summary>
        public async void LoadListingInfo()
        {
            StoreEvents.GetInstance().PostMarketItemsRefreshStartedEvent();
            try
            {
                if (StoreConfig.STORE_TEST_MODE)
                {
                    listingInfosMock = await MockStore.CurrentApp.LoadListingInformationAsync();

                    marketProductInfos.Clear();
                    if (listingInfosMock.ProductListings.Count > 0)
                    {
                        foreach (KeyValuePair <string, MockStore.ProductListing> pair in listingInfosMock.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name           = pair.Value.Name;
                            marketProduct.Description    = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri       = pair.Value.ImageUri;
                            marketProduct.Keywords       = pair.Value.Keywords;
                            marketProduct.ProductId      = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                            case Windows.ApplicationModel.Store.ProductType.Consumable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Durable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Unknown:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }
                else
                {
                    listingInfos = await Store.CurrentApp.LoadListingInformationAsync();

                    IReadOnlyDictionary <string, Store.ProductListing> productListing;
                    productListing = listingInfos.ProductListings;

                    marketProductInfos.Clear();
                    if (productListing.Count > 0)
                    {
                        foreach (KeyValuePair <string, Store.ProductListing> pair in listingInfos.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name           = pair.Value.Name;
                            marketProduct.Description    = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri       = pair.Value.ImageUri;
                            marketProduct.Keywords       = pair.Value.Keywords;
                            marketProduct.ProductId      = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                            case Windows.ApplicationModel.Store.ProductType.Consumable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Durable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Unknown:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SoomlaUtils.LogDebug(TAG, e.Message);
            }

            OnListingLoadedCB(marketProductInfos);
        }
Exemplo n.º 8
0
 /**
  * @{inheritDoc}
  */
 protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded)
 {
     StoreEvents.GetInstance().PostGoodBalanceChangedEvent((VirtualGood)item, balance, amountAdded);
 }