예제 #1
0
    private static void UnlockInGameContent(string productId)
    {
        var gameData = GameDataController.GetGameData();

        // Check if a consumable (coins) has been purchased by this user.
        foreach (var coin in CoinList.List.Where(coin =>
                                                 string.Equals(productId, coin.ProductId, StringComparison.Ordinal)))
        {
            gameData.UpdateCoins(coin);
            return;
        }

        // Check if a non-consumable (car) has been purchased by this user.
        foreach (var car in CarList.List.Where(car => string.Equals(productId, car.ProductId,
                                                                    StringComparison.Ordinal)))
        {
            gameData.PurchaseCar(car);
            return;
        }

        // Check if a subscription has been purchased by this user.
        foreach (var subscription in SubscriptionList.List.Where(subscription => string.Equals(productId,
                                                                                               subscription.ProductId,
                                                                                               StringComparison.Ordinal)))
        {
            gameData.UpdateSubscription(subscription);
            return;
        }


        // Pop up window
        Debug.LogError("Product ID doesn't match any of exist products.");
    }
예제 #2
0
 // Check if player owns the background, and set the item activeness accordingly.
 private void ToggleBackgroundActivenessBasedOnOwnership()
 {
     foreach (var background in BackgroundList.List)
     {
         var isBackgroundOwned = GameDataController.GetGameData().CheckBackgroundOwnership(background);
         background.GarageItemGameObj.SetActive(isBackgroundOwned);
     }
 }
 // Check if player owns the car.
 private void ToggleCarActivenessBasedOnOwnership()
 {
     foreach (var car in CarList.List)
     {
         var isCarOwned = GameDataController.GetGameData().CheckCarOwnership(car);
         car.GarageItemGameObj.SetActive(isCarOwned);
     }
 }
 private void RefreshGasStorePage()
 {
     _currentCost       = Math.Ceiling((Gas.FullGasLevel - _gas.GasLevel) * GameDataController.GetGameData().Discount);
     gasPrice.text      = "* " + _currentCost;
     panelGasPrice.text = "Would you like to fill the gas tank with  " + _currentCost + "  coins";
     _gas.SetGasLevelHelper(_gasLevelImage, gasLevelImageObj);
     panelFillGas.SetActive(false);
     cannotAffordWarning.SetActive(false);
 }
예제 #5
0
 public void OnConfirmSubscriptionPanelButtonClicked(bool isConfirmed)
 {
     confirmPanel.SetActive(false);
     if (isConfirmed)
     {
         PurchaseController.PurchaseASubscription(GameDataController.GetGameData().CurSubscriptionObj,
                                                  _subscriptionToSubscribe);
     }
 }
예제 #6
0
    public static ServerResponseModel SaveGameDataOnline()
    {
        var values = new Dictionary <string, string>
        {
            ["gameData"] = JsonUtility.ToJson(GameDataController.GetGameData())
        };

        return(sendUnityWebRequest(values, SAVE_GAME_DATA_URL));
    }
    private void SetCarUsageStatus()
    {
        foreach (var carObj in CarList.List)
        {
            carObj.GarageItemGameObj.transform.Find("statusText").gameObject.SetActive(false);
        }

        GameDataController.GetGameData().CarInUseObj.GarageItemGameObj.transform.Find("statusText").gameObject
        .SetActive(true);
    }
예제 #8
0
    private void SetBackgroundUsageStatus()
    {
        foreach (var background in BackgroundList.List)
        {
            background.GarageItemGameObj.transform.Find("statusText").gameObject.SetActive(false);
        }

        GameDataController.GetGameData().BackgroundInUseObj.GarageItemGameObj.transform.Find("statusText").gameObject
        .SetActive(true);
    }
예제 #9
0
    // Apply discounts on coin text for each car sales in coin.
    private void ApplyCoinItemsDiscount()
    {
        var discount = GameDataController.GetGameData().Discount;

        foreach (var car in CarList.List.Where(car => !car.IsRealMoneyPurchase))
        {
            car.StoreItemCarGameObj.transform.Find("price/priceValue").gameObject.GetComponent <Text>().text =
                (car.Price * discount).ToString(CultureInfo.InvariantCulture);
        }
    }
    public void OnFillGasConfirmPanelButtonClicked(bool isConfirmed)
    {
        panelFillGas.SetActive(false);

        // Fill the gas if the user taps "YES".
        if (isConfirmed)
        {
            GameDataController.GetGameData().ReduceCoinsOwned((int)_currentCost);
            _gas.FilledGas();
            RefreshGasStorePage();
        }
    }
예제 #11
0
    private static void CheckSubscriptionsAvailabilityBasedOnReceipt(IStoreController controller)
    {
        var silverSubscriptionProduct = controller.products.WithID(SubscriptionList.SilverSubscription.ProductId);
        var goldenSubscriptionProduct = controller.products.WithID(SubscriptionList.GoldenSubscription.ProductId);

        if (!(silverSubscriptionProduct.hasReceipt && ClientSideReceiptValidation(silverSubscriptionProduct.receipt)) &&
            !(goldenSubscriptionProduct.hasReceipt && ClientSideReceiptValidation(goldenSubscriptionProduct.receipt)))
        {
            GameDataController.GetGameData().UpdateSubscription(SubscriptionList.NoSubscription);
            Debug.Log("No subscription receipt found. Unsubscribe all subscriptions");
        }
    }
예제 #12
0
    // Update the car in use in the play page when player switch the car.
    public void UpdateCarInUse()
    {
        // Set all cars to be inactive.
        foreach (var car in CarList.List)
        {
            car.PlayCarGameObj.SetActive(false);
        }

        // Set the car in use game object to be active.
        var carInUseGameObj = GameDataController.GetGameData().CarInUseObj.PlayCarGameObj;

        SetCarInUseState(carInUseGameObj);
    }
    public void OnFillGasButtonClicked()
    {
        var currentCoins = GameDataController.GetGameData().CoinsOwned;

        if (currentCoins >= _currentCost)
        {
            panelFillGas.SetActive(true);
        }
        else
        {
            cannotAffordWarning.SetActive(true);
        }
    }
예제 #14
0
 private void BuyCar()
 {
     confirmPanel.SetActive(true);
     if (_carToPurchaseObj.IsRealMoneyPurchase)
     {
         confirmText.text = "Would you like to purchase " + _carToPurchaseObj.Name + " with $" +
                            _carToPurchaseObj.Price + "?";
     }
     else
     {
         confirmText.text = "Would you like to purchase " + _carToPurchaseObj.Name + " with " +
                            _carToPurchaseObj.Price * GameDataController.GetGameData().Discount + " coins?";
     }
 }
예제 #15
0
    public void OnConfirmPurchasePanelButtonClicked(bool isConfirmed)
    {
        confirmPanel.SetActive(false);

        if (isConfirmed)
        {
            // If the item sales in coins, buy the product through the client side.
            if (_carToPurchaseObj.IsRealMoneyPurchase)
            {
                PurchaseController.BuyProductId(_carToPurchaseObj.ProductId);
            }
            else
            {
                GameDataController.GetGameData().PurchaseCar(_carToPurchaseObj);
            }
        }
    }
예제 #16
0
 // Check if the player own the car;
 // If the player own the car, disable the interaction of the car item.
 private void SetCarStoreItemStatusBasedOnOwnership()
 {
     foreach (var car in CarList.List)
     {
         var storeItemCarGameObj = car.StoreItemCarGameObj;
         if (GameDataController.GetGameData().CheckCarOwnership(car))
         {
             storeItemCarGameObj.GetComponent <Image>().color         = _lightGreyColor;
             storeItemCarGameObj.GetComponent <Button>().interactable = false;
             storeItemCarGameObj.transform.Find("price").gameObject.GetComponent <Text>().text = "owned";
             SetDeferredPurchaseReminderActiveness(car, false);
             if (!car.IsRealMoneyPurchase)
             {
                 storeItemCarGameObj.transform.Find("coinImage").gameObject.SetActive(false);
                 storeItemCarGameObj.transform.Find("price/priceValue").gameObject.SetActive(false);
             }
         }
     }
 }
예제 #17
0
    // Listener for car item purchase.
    public void OnCarStoreItemClicked(int carIndex)
    {
        _carToPurchaseObj = CarList.GetCarByCarIndex(carIndex);

        if (_carToPurchaseObj.IsRealMoneyPurchase)
        {
            BuyCar();
        }
        else // if the item sells in coins.
        {
            var gameData = GameDataController.GetGameData();
            // Players can purchase the coin item only it they have enough coin.
            if (gameData.coinsOwned >= _carToPurchaseObj.Price * gameData.Discount)
            {
                BuyCar();
            }
            else
            {
                coinsNotEnoughReminder.SetActive(true);
                Invoke(nameof(HideCoinsNotEnoughReminder), HideCoinsNotEnoughReminderTimeOutSec);
            }
        }
    }
예제 #18
0
    // Check if the player already subscribed to a plan and change the subscribe button correspondingly.
    private static void SetSubscriptionStatusBasedOnOwnership()
    {
        var currentSubscription = GameDataController.GetGameData().CurSubscriptionObj;

        // If the player doesn't subscribe to any of subscription, set all subscription item to initial status.
        if (currentSubscription.Type == SubscriptionType.NoSubscription)
        {
            foreach (var subscription in SubscriptionList.List)
            {
                SetSubscribeButton(subscription, subscription.SubscribeButton.SubscribeButtonTextWhenNoSubscription,
                                   true);
            }
        }
        else
        {
            foreach (var subscription in SubscriptionList.List)
            {
                if (subscription == currentSubscription)
                {
                    SetSubscribeButton(
                        subscription,
                        subscription.SubscribeButton.SubscribeButtonTextWhenSubscribeToThisSubscription,
                        false
                        );
                }
                else
                {
                    SetSubscribeButton(
                        subscription,
                        subscription.SubscribeButton.SubscribeButtonTextWhenSubscribeToOthers,
                        true
                        );
                }
            }
        }
    }
예제 #19
0
 // Update coin text in the garage page.
 private void SetCoinsBasedOnGameData()
 {
     coinsCount.text = GameDataController.GetGameData().CoinsOwned.ToString();
 }
 private void SwitchCarInUse(CarList.Car targetCar)
 {
     GameDataController.GetGameData().UpdateCarInUse(targetCar);
     SetCarUsageStatus();
 }
예제 #21
0
 private void SwitchToTargetBackground(BackgroundList.Background targetBackground)
 {
     GameDataController.GetGameData().UpdateBackgroundInUse(targetBackground);
     SetBackgroundUsageStatus();
 }
예제 #22
0
 private static void SetBackgroundBasedOnGameData()
 {
     GameDataController.GetGameData().SetBackgroundBasedOnGameData();
 }