Esempio n. 1
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // Return the product sale relative to the base product.
    // return number < 0 if getting product sale fails
    public static int GetProductSaleInPercent(string productId,
                                              string baseProductId,
                                              InAppInventory productsInventory,
                                              FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const int failed = -1;

        InAppProduct product     = productsInventory.Product(productId);
        InAppProduct baseProduct = productsInventory.Product(baseProductId);

        if (baseProduct == null)
        {
            Debug.LogWarning("ProductsSalesProvider -> GetProductSaleInPercent: BaseProduct with id " + baseProductId +
                             " is not contained in the inventory. Product sale cannot be computed.");
            return(failed);
        }

        if (product == null)
        {
            return(failed);
        }

        float baseProductCoinPrice = GetOneGoldCoinPrice(baseProduct, fundSettingsManager);
        float productCoinPrice     = GetOneGoldCoinPrice(product, fundSettingsManager);

        float productSale          = (baseProductCoinPrice / productCoinPrice) - 1;
        int   productSaleInPercent = (int)Math.Round(productSale * 100);

        return(productSaleInPercent);
    }
Esempio n. 2
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    public static List <ShopItemId> GetFunds()
    {
        // products that can be purchased by user
        List <ShopItemId> shopItems = new List <ShopItemId>();

        if (ShopDataBridge.Instance == null)
        {
            Debug.Log("GuiShopPageFunds -> List: ShopDataBridge is not initialized.");
            return(shopItems);
        }

        // products obtained from local storage or cloud
        List <ShopItemId> localShopItems = ShopDataBridge.Instance.GetFunds();

        // products available in the current shop (e.g. AppStore, ...)
        InAppInventory availableProducts = InAppPurchaseMgr.Instance.Inventory;

        foreach (ShopItemId localShopItem in localShopItems)
        {
            string productId = GetProductId(localShopItem);

            // return only products available in the shop
            if (availableProducts.IsProductAvailable(productId))
            {
                shopItems.Add(localShopItem);
            }
        }

        // should not return empty list
        // GUI can not handle empty list of the products
        if (shopItems.Count == 0)
        {
            shopItems = localShopItems;
        }

        /*
         * string log = "funds:\n";
         * foreach (ShopItemId localShopItem in localShopItems)
         * {
         *      log += GetProductId( localShopItem ) + "\n";
         * }
         * log += "\n";
         *
         * log += "inventory:\n";
         * if (availableProducts != null)
         * {
         *      log += availableProducts.DebugProductsIdsString();
         * }
         * else
         * {
         *      log += "null";
         * }
         *
         * Debug.Log( log );
         * //*/

        return(shopItems);
    }
Esempio n. 3
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------
    // Public methods
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // Return the product sale relative to the cheapest product in the inventory.
    // return number < 0 if getting product sale fails
    public static int GetProductSaleInPercent(string productId, InAppInventory productsInventory, FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const int failed = -1;

        string cheapestProductId = GetCheapestProduct(productsInventory).ProductId;

        if (cheapestProductId != null)
        {
            return(GetProductSaleInPercent(productId, cheapestProductId, productsInventory, fundSettingsManager));
        }
        else
        {
            return(failed);
        }
    }
Esempio n. 4
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return null if fails
    static InAppProduct GetCheapestProduct(InAppInventory productsInventory)
    {
        InAppProduct cheapestProduct      = null;
        float        cheapestProductPrice = float.MaxValue;

        foreach (InAppProduct product in productsInventory)
        {
            float productPrice = GetProductPrice(product);

            if (productPrice >= 0 && productPrice < cheapestProductPrice)
            {
                cheapestProduct      = product;
                cheapestProductPrice = productPrice;
            }
        }

        return(cheapestProduct);
    }
Esempio n. 5
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return null if fails
    static string GetCheapestProductId(List <ShopItemId> shopFunds, InAppInventory productsInventory, FundSettingsManager fundSettingsManager)
    {
        string cheapestProductId    = null;
        float  cheapestProductPrice = float.MaxValue;

        foreach (ShopItemId shopFund in shopFunds)
        {
            float productPrice = GetProductPriceForFund(shopFund, productsInventory, fundSettingsManager);

            if (productPrice >= 0 && productPrice < cheapestProductPrice)
            {
                cheapestProductId    = GetProductId(shopFund, fundSettingsManager);
                cheapestProductPrice = productPrice;
            }
        }

        return(cheapestProductId);
    }
Esempio n. 6
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return number < 0 if fails
    static float GetProductPriceForFund(ShopItemId shopFund, InAppInventory productsInventory, FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const float failed = -1;

        string productId = GetProductId(shopFund, fundSettingsManager);

        if (productId == null)
        {
            return(failed);
        }

        InAppProduct product = productsInventory.Product(productId);

        if (product == null)
        {
            return(failed);
        }

        return(GetProductPrice(product));
    }
Esempio n. 7
0
    protected override void OnViewShow()
    {
        base.OnViewShow();

        Debug.Log("Not Funds Show");
        //Show fund info
        if (!ShopDataBridge.Instance.IsIAPFund(AddFundsID))
        {
            Debug.LogError("Selected funds is not IAP: " + AddFundsID);
        }

        ShopItemInfo inf    = ShopDataBridge.Instance.GetItemInfo(AddFundsID);
        string       strBuy = TextDatabase.instance[02030093];

        strBuy = strBuy.Replace("%d1", inf.AddGold.ToString());

        string productId = FundSettingsManager.Instance.Get((E_FundID)(AddFundsID.Id)).GUID.ToString();

        InAppInventory inventory = InAppPurchaseMgr.Instance.Inventory;
        InAppProduct   product   = null;

        if (inventory != null)
        {
            product = inventory.Product(productId);
        }

        if (product != null)
        {
            // add price to the buy label string
            strBuy += " (" + product.Price + " " + product.CurrencyCode + ")";
        }

        GUIBase_Label buyLabel = GuiBaseUtils.PrepareLabel(m_ScreenLayout, "Buy_Label");

        buyLabel.SetNewText(strBuy);
    }