예제 #1
0
        /// <summary>
        /// Sets a product to purchased after successful verification (or without).
        /// This alters the database entry for non-consumable or products with usage as well.
        /// </summary>
        public void PurchaseVerified(string id)
        {
            if (!IAPObjects.ContainsKey(id))
            {
                id = GetIAPIdentifier(id);
            }
            if (!IAPObjects.ContainsKey(id))
            {
                return;
            }
            IAPObject obj = IAPObjects[id];

            switch (obj.editorType)
            {
            case IAPType.Currency:
                foreach (IAPCurrency cur in obj.virtualPrice)
                {
                    DBManager.IncreaseFunds(cur.name, cur.amount);
                }
                break;

            default:
                //for consumables, add the defined usage count to tracking in player data
                //on non-consumables, don't continue if the product is already purchased,
                //for example if we just want to verify an existing product again
                switch (obj.type)
                {
                case ProductType.Consumable:
                    if (obj.usageCount > 0)
                    {
                        DBManager.IncreasePlayerData(id, obj.usageCount);

                        //update server player data
                                #if PLAYFAB && !PLAYFAB_VALIDATION
                        PlayfabManager.SetPlayerData();
                                #endif
                    }
                    break;

                default:
                    if (DBManager.GetPurchase(id) > 0)
                    {
                        return;
                    }

                    DBManager.IncreasePurchase(id, 1);
                    break;
                }
                break;
            }

            purchaseSucceededEvent(id);
        }
예제 #2
0
        /// <summary>
        /// Increases player level by 1 which unlocks new shop items.
        /// <summary>
        public void LevelUp()
        {
            if (DBManager.GetInstance())
            {
                int level = DBManager.IncreasePlayerData("level", 1);

                if (ShopManager.GetInstance())
                {
                    ShopManager.RefreshAll();
                }

                Debug.Log("Leveled up to level: " + level +
                          "! Shop Manager tried to unlock new items.");
            }
        }
예제 #3
0
        /// <summary>
        /// Overload for purchasing virtual product based on its product identifier.
        /// </summary>
        public static void PurchaseProduct(IAPObject obj)
        {
            string productId = obj.id;

            //product is set to already owned, this should not happen
            if (obj.type != ProductType.Consumable && DBManager.GetPurchase(productId) > 0)
            {
                OnPurchaseFailed("Product already owned.");
                return;
            }

            #if PLAYFAB && !PLAYFAB_VALIDATION
            new PlayfabStore().Purchase(obj);
            return;
            #endif

            //check whether the player has enough funds
            bool didSucceed = DBManager.VerifyVirtualPurchase(obj);
            if (isDebug)
            {
                Debug.Log("Purchasing virtual product " + productId + ", result: " + didSucceed);
            }
            //on success, non-consumables are saved to the database. This automatically
            //saves the new substracted fund value, then and fire the succeeded event
            if (didSucceed)
            {
                if (obj.type == ProductType.Consumable)
                {
                    DBManager.IncreasePlayerData(productId, obj.usageCount);
                    purchaseSucceededEvent(productId);
                }
                else
                {
                    DBManager.SetPurchase(obj.id);
                }
                purchaseSucceededEvent(productId);
            }
            else
            {
                OnPurchaseFailed("Insufficient funds.");
            }
        }