/// <summary>
    /// Resets game data.
    /// </summary>
    public void ResetGameData()
    {
        // Take the first launch reward (so it can be given again)
        m_firstLaunchReward.Take();
        // Reset coin balance to 0
        SetCoinBalance(0);
        // Unequip equipped character
        EquippableVG vg = StoreInventory.GetEquippedVirtualGood(CRCAssets.GetCharactersCategory());

        if (vg != null)
        {
            StoreInventory.UnEquipVirtualGood(vg.ItemId);
        }
        // Remove all characters from inventory
        for (int index = 0; index < CRCAssets.CharactersLTVGArray.Length; ++index)
        {
            VirtualGood charVG = CRCAssets.CharactersLTVGArray[index];
            if (charVG != null)
            {
                charVG.ResetBalance(0);
            }
        }
        // Reset other data
        SoomlaDataSystem dataSystem = (SoomlaDataSystem)Locator.GetDataSystem();

        dataSystem.ResetGameData();
        // Reset all characters to unused
        for (int index = 0; index < CRCAssets.CharactersLTVGArray.Length; ++index)
        {
            dataSystem.SetCharacterUsed((CharacterType)index, false);
        }
    }
    /// <summary>
    /// Gets the currently equipped character.
    /// </summary>
    /// <returns>The equipped character</returns>
    public CharacterType GetEquippedCharacter()
    {
        EquippableVG evg = StoreInventory.GetEquippedVirtualGood(CRCAssets.GetCharactersCategory());

        if (evg != null)
        {
            return(m_charItemIDDictionary[evg.ItemId]);
        }
        // Give first character and equip
        CharacterType firstCharacter = CharacterType.Chicken;

        if (!IsOwned(firstCharacter))
        {
            GiveCharacter(firstCharacter);
        }
        EquipCharacter(firstCharacter);
        return(firstCharacter);
    }
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    public void Initialize(CharacterResource charResource,
                           Action <string> charPurchaseSucceededDelegate,
                           Action <string> charPurchaseCancelledDelegate,
                           Action restoreTransactionsCompletedDelegate,
                           Action restoreTransactionsFailedDelegate,
                           Action <int> coinBalanceChangedDelegate,
                           Action <int> gachaBalanceChangedDelegate)
    {
        // Initialize only once
        if (m_isInitialized)
        {
            return;
        }

        // Set up character data in Soomla's StoreAssets
        CRCAssets.CharactersLTVGArray = new EquippableVG[charResource.CharacterCount];
        m_charItemIDDictionary.Clear();
        // For testing: Index used for assigning test product IDs
        //int testIDIndex = 0;
        for (int index = 0; index < charResource.CharacterCount; ++index)
        {
            CharacterType character = (CharacterType)index;
            CharacterResource.CharacterStruct charData = charResource.GetCharacterStruct(character);

            // Check if character is buyable
            PurchaseType purchaseType = new PurchaseWithMarket(charData.ItemID, charData.Price);

            /*
             * // For testing: Use test product IDs for the first four purchasable characters
             * PurchaseType purchaseType = null;
             * string productID = charData.ItemID;
             * if (charData.IsBuyable)
             * {
             *  if (testIDIndex == 0)       productID = CRCAssets.PURCHASED_TEST_ID;
             *  else if (testIDIndex == 1)  productID = CRCAssets.CANCELED_TEST_ID;
             *  else if (testIDIndex == 2)  productID = CRCAssets.REFUNDED_TEST_ID;
             *  else if (testIDIndex == 3)  productID = CRCAssets.UNAVAILABLE_TEST_ID;
             *  testIDIndex++;
             * }
             * purchaseType = new PurchaseWithMarket(productID, charData.Price);
             * //purchaseType = new PurchaseWithMarket(CRCAssets.PURCHASED_TEST_ID, charData.Price);
             */

            // Create equippable virtual good instance for each character
            CRCAssets.CharactersLTVGArray[index] = new EquippableVG(
                EquippableVG.EquippingModel.CATEGORY,
                charData.Name,
                "",
                charData.ItemID,
                purchaseType);

            // Add the item ID and character type to a dictionary
            if (!m_charItemIDDictionary.ContainsKey(charData.ItemID))
            {
                m_charItemIDDictionary.Add(charData.ItemID, character);
            }
        }

        // Create an instance of the in-game implementation of IStoreAssets
        CRCAssets crcAssets = new CRCAssets();

        // Update the list of character goods
        for (int index = 0; index < charResource.CharacterCount; ++index)
        {
            crcAssets.AddToCharacterGoodsList(CRCAssets.CharactersLTVGArray[index]);
        }
        // Finalize character goods collections before initializing Soomla Store
        crcAssets.FinalizeCharacterGoods();

        // Save delegates
        m_charPurchaseSucceededDelegate        = charPurchaseSucceededDelegate;
        m_charPurchaseCancelledDelegate        = charPurchaseCancelledDelegate;
        m_restoreTransactionsCompletedDelegate = restoreTransactionsCompletedDelegate;
        m_restoreTransactionsFailedDelegate    = restoreTransactionsFailedDelegate;
        m_coinBalanceChangedDelegate           = coinBalanceChangedDelegate;
        m_gachaBalanceChangedDelegate          = gachaBalanceChangedDelegate;

        // Subscribe to Store events
        StoreEvents.OnSoomlaStoreInitialized      += OnSoomlaStoreInitialized;
        StoreEvents.OnCurrencyBalanceChanged      += OnCurrencyBalanceChanged;
        StoreEvents.OnMarketPurchaseStarted       += OnMarketPurchaseStarted;
        StoreEvents.OnMarketPurchase              += OnMarketPurchase;
        StoreEvents.OnMarketPurchaseCancelled     += OnMarketPurchaseCancelled;
        StoreEvents.OnMarketRefund                += OnMarketRefund;
        StoreEvents.OnRestoreTransactionsStarted  += OnRestoreTransactionsStarted;
        StoreEvents.OnRestoreTransactionsFinished += OnRestoreTransactionsFinished;
        StoreEvents.OnUnexpectedStoreError        += OnUnexpectedStoreError;

        // Initialize rewards
        m_firstLaunchReward = new VirtualItemReward(
            "first-launch",
            "Give coins at first launch",
            CRCAssets.COIN_CURRENCY_ITEM_ID,
            FIRST_LAUNCH_REWARD_AMOUNT);

        // Initialize the store with the in-game implementation of IStoreAssets
        // Note: This must be done after setting up values in the store assets class
        SoomlaStore.Initialize(crcAssets);
    }