Example #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.");
    }
Example #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);
 }
Example #5
0
 public void OnConfirmSubscriptionPanelButtonClicked(bool isConfirmed)
 {
     confirmPanel.SetActive(false);
     if (isConfirmed)
     {
         PurchaseController.PurchaseASubscription(GameDataController.GetGameData().CurSubscriptionObj,
                                                  _subscriptionToSubscribe);
     }
 }
Example #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);
    }
Example #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);
    }
Example #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();
        }
    }
Example #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");
        }
    }
Example #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);
        }
    }
Example #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?";
     }
 }
Example #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);
            }
        }
    }
Example #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);
             }
         }
     }
 }
Example #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);
            }
        }
    }
Example #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
                        );
                }
            }
        }
    }
Example #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();
 }
Example #21
0
 private void SwitchToTargetBackground(BackgroundList.Background targetBackground)
 {
     GameDataController.GetGameData().UpdateBackgroundInUse(targetBackground);
     SetBackgroundUsageStatus();
 }
Example #22
0
 private static void SetBackgroundBasedOnGameData()
 {
     GameDataController.GetGameData().SetBackgroundBasedOnGameData();
 }