Example #1
0
        protected override int _getBalance(VirtualItem item)
        {
            int outBalance = 0;
            int err        = vgStorage_GetBalance(item.ItemId, out outBalance);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(outBalance);
        }
Example #2
0
        protected override bool _isEquipped(EquippableVG good)
        {
            bool res = false;
            int  err = vgStorage_IsEquipped(good.ItemId, out res);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(res);
        }
Example #3
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);
        }
Example #4
0
        /** VIRTUAL ITEMS **/

        /// <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>
        override protected int _getItemBalance(string itemId)
        {
            int balance = 0;
            int err     = storeInventory_GetItemBalance(itemId, out balance);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(balance);
        }
Example #5
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);
        }
Example #6
0
        /// <summary>
        /// Retrieves the upgrade level of the virtual good with the given <c>goodItemId</c>.
        /// For Example:
        /// Let's say there's a strength attribute to one of the characters in your game and you provide
        /// your users with the ability to upgrade that strength on a scale of 1-3.
        /// This is what you've created:
        /// 1. <c>SingleUseVG</c> for "strength".
        /// 2. <c>UpgradeVG</c> for strength 'level 1'.
        /// 3. <c>UpgradeVG</c> for strength 'level 2'.
        /// 4. <c>UpgradeVG</c> for strength 'level 3'.
        /// In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
        /// </summary>
        /// <param name="goodItemId">Good item identifier.</param>
        /// <returns>The good upgrade level.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected int _getGoodUpgradeLevel(string goodItemId)
        {
            int level = 0;
            int err   = storeInventory_GetGoodUpgradeLevel(goodItemId, out level);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(level);
        }
Example #7
0
        /** NON-CONSUMABLES **/

        /// <summary>
        /// Checks if the non-consumable with the given <c>nonConsItemId</c> exists.
        /// </summary>
        /// <param name="nonConsItemId">Id of the item to check if exists.</param>
        /// <returns>True if non-consumable item with nonConsItemId exists, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _nonConsumableItemExists(string nonConsItemId)
        {
            bool result = false;
            int  err    = storeInventory_NonConsumableItemExists(nonConsItemId, out result);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(result);
        }
Example #8
0
        /// <summary>
        /// Checks if the virtual good with the given <c>goodItemId</c> is currently equipped.
        /// </summary>
        /// <param name="goodItemId">Id of the virtual good who we want to know if is equipped.</param>
        /// <returns>True if the virtual good is equipped, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _isVertualGoodEquipped(string goodItemId)
        {
            bool result = false;
            int  err    = storeInventory_IsVirtualGoodEquipped(goodItemId, out result);

            IOS_ErrorCodes.CheckAndThrowException(err);
            return(result);
        }
Example #9
0
        /// <summary>
        /// Initializes <c>StoreInfo</c>.
        /// On first initialization, when the database doesn't have any previous version of the store
        /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>.
        /// After the first initialization, <c>StoreInfo</c> will be initialized from the database.
        ///
        /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump
        /// the version of your implementation of <c>IStoreAssets</c> in order to remove the
        /// metadata when the application loads. Bumping the version is done by returning a higher
        /// number in <c>IStoreAssets</c>'s <c>getVersion</c>.
        /// </summary>
        /// <param name="storeAssets">your game's economy</param>
        override protected void _setStoreAssets(IStoreAssets storeAssets)
        {
            SoomlaUtils.LogDebug(TAG, "pushing IStoreAssets to StoreInfo on iOS side");
            string storeAssetsJSON = IStoreAssetsToJSON(storeAssets);
            int    version         = storeAssets.GetVersion();
            int    err             = storeInfo_SetStoreAssets(storeAssetsJSON, version);

            IOS_ErrorCodes.CheckAndThrowException(err);
            SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on iOS side)");
        }
Example #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>
        override protected string _getGoodCurrentUpgrade(string goodItemId)
        {
            IntPtr p   = IntPtr.Zero;
            int    err = storeInventory_GetGoodCurrentUpgrade(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);
            string result = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);
            return(result);
        }
Example #11
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);
        }
Example #12
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));
        }
Example #13
0
        /// <summary>
        /// Gets the last upgrade for the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">item id</param>
        /// <returns>last upgrade for virtual good with the given id</returns>
        override protected UpgradeVG _getLastUpgradeForVirtualGood(string goodItemId)
        {
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetLastUpgradeForVirtualGood(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string json = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

            JSONObject obj = new JSONObject(json);

            return(new UpgradeVG(obj));
        }
Example #14
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));
        }
Example #15
0
        /// <summary>
        /// Fetches the virtual categories of your game.
        /// </summary>
        /// <returns>All virtual categories.</returns>
        override protected List <VirtualCategory> _getVirtualCategories()
        {
            List <VirtualCategory> virtualCategories = new List <VirtualCategory>();
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetVirtualCategories(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string categoriesJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

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

            JSONObject categoriesArr = new JSONObject(categoriesJson);

            foreach (JSONObject obj in categoriesArr.list)
            {
                virtualCategories.Add(new VirtualCategory(obj));
            }
            return(virtualCategories);
        }
Example #16
0
        /// <summary>
        /// Fetches the non consumable items of your game.
        /// </summary>
        /// <returns>All non consumable items.</returns>
        override protected List <NonConsumableItem> _getNonConsumableItems()
        {
            List <NonConsumableItem> nonConsumableItems = new List <NonConsumableItem>();
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetNonConsumableItems(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string nonConsumableJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

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

            JSONObject nonConsArr = new JSONObject(nonConsumableJson);

            foreach (JSONObject obj in nonConsArr.list)
            {
                nonConsumableItems.Add(new NonConsumableItem(obj));
            }
            return(nonConsumableItems);
        }
Example #17
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);
        }
Example #18
0
        /// <summary>
        /// Fetches the virtual currency packs of your game.
        /// </summary>
        /// <returns>All virtual currency packs.</returns>
        override protected List <VirtualCurrencyPack> _getVirtualCurrencyPacks()
        {
            List <VirtualCurrencyPack> vcps = new List <VirtualCurrencyPack>();
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetVirtualCurrencyPacks(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string packsJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

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

            JSONObject packsArr = new JSONObject(packsJson);

            foreach (JSONObject obj in packsArr.list)
            {
                vcps.Add(new VirtualCurrencyPack(obj));
            }
            return(vcps);
        }
Example #19
0
        /// <summary>
        /// Gets all the upgrades for the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">Item id.</param>
        /// <returns>All upgrades for virtual good with the given id.</returns>
        override protected List <UpgradeVG> _getUpgradesForVirtualGood(string goodItemId)
        {
            List <UpgradeVG> vgus = new List <UpgradeVG>();
            IntPtr           p    = IntPtr.Zero;
            int err = storeInfo_GetUpgradesForVirtualGood(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string upgradesJson = Marshal.PtrToStringAnsi(p);

            Marshal.FreeHGlobal(p);

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

            JSONObject upgradesArr = new JSONObject(upgradesJson);

            foreach (JSONObject obj in upgradesArr.list)
            {
                vgus.Add(new UpgradeVG(obj));
            }
            return(vgus);
        }
Example #20
0
        protected override void _removeUpgrades(VirtualGood good, bool notify)
        {
            int err = vgStorage_RemoveUpgrades(good.ItemId, notify);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #21
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>
        override protected void _removeGoodUpgrades(string goodItemId)
        {
            int err = storeInventory_RemoveGoodUpgrades(goodItemId);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #22
0
        /// <summary>
        /// Removes the non-consumable item with the given <c>nonConsItemId</c> from the non-consumable
        /// items storage.
        /// </summary>
        /// <param name="nonConsItemId">Id of the item to be removed.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected void _removeNonConsumableItem(string nonConsItemId)
        {
            int err = storeInventory_RemoveNonConsumableItem(nonConsItemId);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #23
0
        protected override void loadNativeFromDB()
        {
            int err = storeInfo_LoadFromDB();

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #24
0
        /// <summary>
        /// Buys the item with the given <c>itemId</c>.
        /// </summary>
        /// <param name="itemId">id of item to be bought</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item to be bought is not found.</exception>
        /// <exception cref="InsufficientFundsException">Thrown if the user does not have enough funds.</exception>
        override protected void _buyItem(string itemId, string payload)
        {
            int err = storeInventory_BuyItem(itemId, payload);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #25
0
        protected override void _equip(EquippableVG good, bool notify)
        {
            int err = vgStorage_Equip(good.ItemId, notify);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #26
0
        /// <summary>
        /// Unequips the virtual good with the given <c>goodItemId</c>. Unequipping means that the
        /// user decides to stop using the virtual good he/she is currently using.
        /// For more details and examples <see cref="com.soomla.store.domain.virtualGoods.EquippableVG"/>.
        /// </summary>
        /// <param name="goodItemId">Id of the good to be unequipped.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected void _unEquipVirtualGood(string goodItemId)
        {
            int err = storeInventory_UnEquipVirtualGood(goodItemId);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #27
0
        protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify)
        {
            int err = vgStorage_AssignCurrentUpgrade(good.ItemId, upgradeVG.ItemId, notify);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }
Example #28
0
        /// <summary>
        /// Takes from your user the given amount of the virtual item with the given <c>itemId</c>.
        /// For example, when your user requests a refund, you need to TAKE the item he/she is returning from him/her.
        /// </summary>
        /// <param name="itemId">Item identifier.</param>
        /// <param name="amount">Amount.</param>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected void _takeItem(string itemId, int amount)
        {
            int err = storeInventory_TakeItem(itemId, amount);

            IOS_ErrorCodes.CheckAndThrowException(err);
        }