public bool processPurchase(PurchasableItem item_purchased, AwardedPurchaseCallback purchase_callback, AwardedPurchaseCallback awarded_callback)
    {
        //this handles all backend aspects of the purchase, including the awarding of bonuses, application of global discounts
        //returns true if purchase is successful, otherwise false
        if (!canAffordPurchase(item_purchased))
        {
            Debug.LogError("Not enough currency to buy this");
            return(false);
        }

        //charge the user for the purchase
        m_currency_owned -= Mathf.RoundToInt(item_purchased.currency_cost * GlobalDiscountManager.GetDiscountFactor());
        pushCurrencyToBackend();

        //invoke the callback for this purchase, if any
        if (purchase_callback != null)
        {
            purchase_callback(item_purchased);
        }

        //call any on_purchase methods specified
        if (item_purchased.on_purchase_methods != null)
        {
            MethodCallUtility.CallOnPurchaseMethods(item_purchased.on_purchase_methods);
        }

        return(true);
    }
Esempio n. 2
0
    public static void ChanceToAwardFreeItem(string item_key, float chance_to_award)
    {
        Debug.Log("Chance to award free");
        float randy = UnityEngine.Random.Range(0.0f, 1.0f);

        if (randy < chance_to_award)
        {
            PurchasableItem free_item = PurchaseSystemManager.GetInstance().getPurchasableItemByKey(item_key);
            Debug.Log("Awarding " + free_item.visible_name);

            string free_item_notification = string.Format(FREE_ITEM_AWARDED, free_item.visible_name);
            ModalSystemManager.GetInstance().showSingleButtonModal(free_item_notification);

            //call any on_purchase methods specified
            if (free_item.on_purchase_methods != null)
            {
                MethodCallUtility.CallOnPurchaseMethods(free_item.on_purchase_methods);
            }
        }
    }