Example #1
0
    private void ConfirmRescueCallback(bool result)
    {
        if (result)
        {
            if (GameSystem.GetInstance().CheckIsActivated(ConfirmActiveGame, ActivateGameSucceed))
            {
                if (GameSystem.GetInstance().Coin >= rescuePrice)
                {
                    GameSystem.GetInstance().Coin -= rescuePrice;
                    GameSystem.GetInstance().CurrentModeLogic.Rescue();
                    GameSystem.GetInstance().ChangeState(GameSystem.States.GamePreview);
                    PlayerProfile.SaveCoin(GameSystem.GetInstance().Coin);

                    UMengManager.Buy(UMengManager.Item_IAP[(int)IAPManager.IAPProduct.Rescue], 1, rescuePrice);
                }
                else
                {
                    IAPManager.GetInstance().Pay(IAPManager.IAPProduct.Rescue);
                }
            }
        }
        else
        {
            entity.gameCore.StarWaveFailAnim();
        }
    }
Example #2
0
    public void UnlockMode(Mode mode)
    {
        if (GameSystem.GetInstance().Coin >= Constant.MODE_UNLOCK_COIN[(int)mode])
        {
            PlayerProfile.SaveModeUnlock(mode, true);
            GameSystem.GetInstance().Coin -= Constant.MODE_UNLOCK_COIN[(int)mode];
            PlayerProfile.SaveCoin(GameSystem.GetInstance().Coin);

            UMengManager.Buy(UMengManager.Item_Unlock_Mode[(int)mode], 1, Constant.MODE_UNLOCK_COIN[(int)mode]);
        }
    }
Example #3
0
    public void GameEnd()
    {
        if (this.CurrentModeType == ModeType.PassLevel)
        {
            if (brokenRecord)
            {
                GameSoundSystem.GetInstance().PlayCheerSound();
            }
            LeaderboardManager.ReportScore(this.CurrentMode, this.CurrentModeType, this.DisplayWaveNumber);
        }
        else
        {
            int bestRecord = PlayerProfile.LoadBestRecord(this.CurrentMode, this.CurrentModeType);
            if (this.Score > bestRecord)
            {
                brokenRecord = true;
                GameSoundSystem.GetInstance().PlayCheerSound();
                PlayerProfile.SaveBestRecord(this.CurrentMode, this.CurrentModeType, this.Score);
                if (OnBestRecordChanged != null)
                {
                    OnBestRecordChanged();
                }
            }

            if (isActivated)
            {
                int gainedCoin = this.Score / Constant.SCORE_TO_COIN;
                if (isVIP)
                {
                    gainedCoin *= 2;
                }
                this.Coin += gainedCoin;
                PlayerProfile.SaveCoin(this.Coin);

                UMengManager.Bonus(gainedCoin, (Umeng.GA.BonusSource)UMengManager.Bonus_Source_Pass_Level);
            }
            else
            {
                //Trick Code : 使界面刷新用
                this.Coin += 0;
            }
            LeaderboardManager.ReportScore(this.CurrentMode, this.CurrentModeType, this.Score);
        }

        //友盟统计游戏结束后的数据
        Dictionary <string, string> dict = new Dictionary <string, string>();
        string keyString   = "mode|modeType|wave|score";
        string valueString = string.Format("{0}|{1}|{2}|{3}", this.CurrentMode, this.CurrentModeType, this.DisplayWaveNumber, this.Score);

        dict.Add(keyString, valueString);
        UMengManager.Event(UMengManager.Event_GameEnd, dict);
    }
Example #4
0
    public void CheckUnlock()
    {
        isUnlocked          = PlayerProfile.LoadModeUnlock(mode);
        isEntered           = PlayerProfile.LoadModeEntered(mode);
        background1.color   = isUnlocked ? Constant.COLOR_WHITE : Constant.COLOR_GRAY;
        modeNameLabel.color = isUnlocked ? Constant.COLOR_DARK_BLACK : Constant.COLOR_LIGHT_WHITE;
        background2.color   = background1.color;
        this.GetComponent <BoxCollider>().enabled = isUnlocked;

        if (mode == GameSystem.Mode.Inverse)
        {
            unlockWithCoinContents.gameObject.SetActive(false);
            unlockWithScoreContents.gameObject.SetActive(!isUnlocked);
            if (isUnlocked == false)
            {
                canUnlock = PlayerProfile.LoadBestRecord(GameSystem.Mode.Classic, GameSystem.ModeType.Challenge) >= Constant.MODE_UNLOCK_COIN[(int)mode];
                unlockWithScoreContents.SetActive(!canUnlock);
                newText.SetActive(canUnlock);

                if (canUnlock)
                {
                    PlayerProfile.SaveModeUnlock(mode, true);
                    CheckUnlock();

                    //友盟统计解锁模式
                    UMengManager.Event(UMengManager.Event_UnlockMode, mode.ToString());
                }
            }
            else
            {
                newText.SetActive(!isEntered);
            }
        }
        else
        {
            unlockWithScoreContents.gameObject.SetActive(false);
            unlockWithCoinContents.gameObject.SetActive(!isUnlocked);
            if (isUnlocked == false)
            {
                canUnlock = GameSystem.GetInstance().Coin >= Constant.MODE_UNLOCK_COIN[(int)mode];
                unlockWithCoinContents.enabled = canUnlock;
                newText.SetActive(false);
            }
            else
            {
                newText.SetActive(!isEntered);
            }
        }
    }
Example #5
0
    void ConfirmUnlockModeWithCoinCallback(bool result)
    {
        if (result)
        {
            GameSystem.GetInstance().UnlockMode(mode);
            newText.SetActive(true);

            //友盟统计解锁模式
            UMengManager.Event(UMengManager.Event_UnlockMode, mode.ToString());
        }
        else
        {
            TrialPlay();
        }
    }
Example #6
0
    public void EnterGame()
    {
        GameSystem.GetInstance().CurrentMode = mode;
        GameSystem.GetInstance().ChangeState(GameSystem.States.GameReady);
        if (isEntered == false)
        {
            isEntered = true;
            newText.SetActive(false);
            PlayerProfile.SaveModeEntered(mode, true);

            //友盟统计进入模式的次数
            UMengManager.Event(UMengManager.Event_EnterMode, string.Format("{0}|{1}", mode, GameSystem.GetInstance().CurrentModeType));
        }
        HideModeDetailImmediately();
    }
Example #7
0
    // Use this for initialization
    void Start()
    {
        MergeScenes();

        fsm = new FiniteStateMachine <GameSystem, GameSystem.States>(this);
        fsm.RegisterState(stateGameInit);
        fsm.RegisterState(stateGameMenu);
        fsm.RegisterState(stateGameReady);
        fsm.RegisterState(stateGamePreview);
        fsm.RegisterState(stateGamePlay);
        fsm.RegisterState(stateWaveComplete);
        fsm.RegisterState(stateGameResult);

        ChangeState(States.GameInit);

        UMengManager.Init();
    }
Example #8
0
 // Use this for initialization
 void Awake()
 {
             #if UNITY_IPHONE
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         GA.StartWithAppKeyAndChannelId("53f0bdc9fd98c586a9004d4d", "App Store");
         GA.CheckUpdate();
     }
             #endif
             #if UNITY_ANDROID
     if (Application.platform == RuntimePlatform.Android)
     {
         GA.StartWithAppKeyAndChannelId("547aacd0fd98c56e270006fd", "Google Play");
     }
             #endif
     NetworkManager.GetInstance();
     instance = this;
 }
Example #9
0
    public void ActivateGame()
    {
        isActivated = true;
        PlayerProfile.SaveIsActivated(true);

        this.Coin += Constant.ACTIVATE_GAME_BONUS;
        PlayerProfile.SaveCoin(this.Coin);

        UMengManager.Bonus(Constant.ACTIVATE_GAME_BONUS, (Umeng.GA.BonusSource)UMengManager.Bonus_Source_Activate_Game);

        if (activeGameSucceedCallback != null)
        {
            activeGameSucceedCallback();
        }

        if (CurrentState == States.WaveComplete)
        {
            StartNextWave();
        }
    }
Example #10
0
    public int ReceiveGift()
    {
        isGiftAvailableNow = false;
        Dictionary <int, float> giftNumberProbability = NetworkManager.GetInstance().giftNumberProbability;
        int coin = RandomTool.Chances(giftNumberProbability);

        if (isVIP)
        {
            coin *= 2;
        }
        this.Coin += coin;
        PlayerProfile.SaveCoin(GameSystem.GetInstance().Coin);

        giftReceivedCount++;
        PlayerProfile.SaveGiftReceivedCount(giftReceivedCount);

        PlayerProfile.SaveLastGiftTime(DateTime.Now);

        ReloadGiftTimeInfo();

        UMengManager.Bonus(coin, (Umeng.GA.BonusSource)UMengManager.Bonus_Source_Gift);

        return(coin);
    }
Example #11
0
 public void ShareButtonOnClick()
 {
     StartCoroutine(UMengManager.ShareGame());
     GameSoundSystem.GetInstance().PlayRandomSound();
 }
Example #12
0
    public void StartNextWave()
    {
        int[] trialLevelNumberList = NetworkManager.GetInstance().trialLevels;
        int   trialLevelNumber     = 20;

        if (trialLevelNumberList.Length > (int)currentMode)
        {
            trialLevelNumber = trialLevelNumberList[(int)currentMode];
        }
        if ((isActivated == false) &&
            this.DisplayWaveNumber >= trialLevelNumber)
        {
            gameUI.confirmMenu.SetConfirmCallback(ConfirmActivateGameInTrialEndCallback);
            gameUI.confirmMenu.SetCloseCallback(JumpToGameEnd);
            gameUI.confirmMenu.SetContent(TextManager.GetText("confirm_activate_game_title"), string.Format(TextManager.GetText("confirm_activate_game_content"), Constant.ACTIVATE_GAME_BONUS), ConfirmStyle.YesClose);
            gameUI.confirmMenu.Show(true);
            return;
        }
        else if ((isTrial) &&
                 this.DisplayWaveNumber >= trialLevelNumber)
        {
            if (currentMode == Mode.Inverse)
            {
                string title   = TextManager.GetText("trial_end_when_activated_title");
                string content = string.Format(TextManager.GetText("trial_end_of_inverse_content"), Constant.MODE_UNLOCK_COIN[(int)currentMode]);
                gameUI.confirmMenu.SetConfirmCallback((result) => {
                    JumpToGameEnd();
                });
                gameUI.confirmMenu.SetContent(title, content, ConfirmStyle.OnlyYes);
                gameUI.confirmMenu.Show(true);
                return;
            }
            else
            {
                int price = Constant.MODE_UNLOCK_COIN[(int)currentMode];
#if UNITY_IOS
                if (GameSystem.GetInstance().Coin < price)
                {
                    string title   = TextManager.GetText("trial_end_when_activated_title");
                    string content = string.Format(TextManager.GetText("trial_end_when_coin_not_enough_unlock"), price);
                    gameUI.confirmMenu.SetConfirmCallback(ConfirmTrialEndCallback);
                    gameUI.confirmMenu.SetCloseCallback(() => {
                        gameUI.confirmMenu.SetCloseMenuAfterClickYesEnable(true);
                        JumpToGameEnd();
                    });
                    gameUI.confirmMenu.SetContent(title, content, ConfirmStyle.YesClose);
                    gameUI.confirmMenu.SetYesButtonText(TextManager.GetText("go_to_shop"));
                    gameUI.confirmMenu.SetCloseMenuAfterClickYesEnable(false);
                    gameUI.confirmMenu.Show(true);
                    return;
                }
                else
#endif
                {
                    string title   = TextManager.GetText("trial_end_when_activated_title");
                    string content = string.Format(TextManager.GetText("trial_end_when_activated_msg"), price);
                    gameUI.confirmMenu.SetConfirmCallback(ConfirmTrialEndCallback);
                    gameUI.confirmMenu.SetCloseCallback(JumpToGameEnd);
                    gameUI.confirmMenu.SetContent(title, content, ConfirmStyle.YesClose);
                    gameUI.confirmMenu.Show(true);
                    return;
                }
            }
        }

        if (this.realWaveIndex < LevelData.NormalLevelMaxIndex(currentMode))
        {
            this.realWaveIndex++;
        }
        this.DisplayWaveNumber++;

        if (this.CurrentModeType == ModeType.PassLevel)
        {
            brokenRecord = true;
            //冲关状态时,每过一关就要存储一次,避免意外结束游戏导致进度未保存
            PlayerProfile.SaveBestRecord(this.CurrentMode, this.CurrentModeType, this.DisplayWaveNumber);
            if (OnBestRecordChanged != null)
            {
                OnBestRecordChanged();
            }
            int scoreDiff = this.Score - this.preWaveScore;
            if (scoreDiff >= Constant.SCORE_TO_COIN)
            {
                int coinGained = scoreDiff / Constant.SCORE_TO_COIN;
                if (isVIP)
                {
                    coinGained *= 2;
                }
                this.Coin        += coinGained;
                this.preWaveScore = this.Score;
                PlayerProfile.SaveCoin(this.Coin);

                UMengManager.Bonus(coinGained, (Umeng.GA.BonusSource)UMengManager.Bonus_Source_Pass_Level);
            }
            LeaderboardManager.ReportScore(this.CurrentMode, this.CurrentModeType, this.DisplayWaveNumber);
        }

        StartTheWave();
    }
Example #13
0
    // callback from platform purchse
    public void PayCallback(string param)
    {
        string[] returnParams = param.Split(","[0]);
        if (returnParams.Length != 2)
        {
            Debug.LogError("Invalid pay callback params!");
            return;
        }
        string     result    = returnParams[0];
        string     productID = returnParams[1];
        IAPProduct product   = IDProductMap [productID];

        if (result.Equals("succeed"))
        {
            ShopData shopData = ShopData.GetShopData(product);
            switch (product)
            {
            case IAPProduct.ActiveGame:
                GameSystem.GetInstance().ActivateGame();
                UMengManager.Pay(Constant.ACTIVATE_GAME_RMB_PRICE, Umeng.GA.PaySource.支付宝, UMengManager.Item_IAP[(int)shopData.product], 1, Constant.ACTIVATE_GAME_BONUS);
                break;

            case IAPProduct.VIP:
                GameSystem.GetInstance().Coin += shopData.number;
                PlayerProfile.SaveCoin(GameSystem.GetInstance().Coin);
                UMengManager.Bonus(shopData.number, (Umeng.GA.BonusSource)UMengManager.Bonus_Source_Buy_VIP);
                UMengManager.Pay(shopData.price, Umeng.GA.PaySource.支付宝, UMengManager.Item_IAP[(int)shopData.product], 1, shopData.number);

                GameSystem.GetInstance().BecomeVIP();
                break;

            case IAPProduct.WhiteBlock1:
            case IAPProduct.WhiteBlock2:
            case IAPProduct.WhiteBlock3:
            case IAPProduct.WhiteBlock4:
            case IAPProduct.WhiteBlock5:
                GameSystem.GetInstance().Coin += shopData.number;
                PlayerProfile.SaveCoin(GameSystem.GetInstance().Coin);
                UMengManager.Pay(shopData.price, Umeng.GA.PaySource.支付宝, shopData.number);
                UMengManager.Pay(shopData.price, Umeng.GA.PaySource.支付宝, UMengManager.Item_IAP[(int)shopData.product], 1, shopData.number);

#if UNITY_IOS
                if (GameSystem.GetInstance().UnlockRecommendMode)
                {
                    GameSystem.GetInstance().UnlockRecommendMode = false;
                    GameSystem.GetInstance().PayUnlockRecommendModeCallback(true);
                }
#else
                if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                {
                    GameSystem.GetInstance().PayUnlockModeCallback(true);
                }
#endif
                break;

            case IAPProduct.Rescue:
                GameSystem.GetInstance().CurrentModeLogic.Rescue();
                GameSystem.GetInstance().ChangeState(GameSystem.States.GamePreview);

                UMengManager.Pay(Constant.RESCUE_RMB_PRICE, Umeng.GA.PaySource.支付宝, UMengManager.Item_IAP[(int)shopData.product], 1, Constant.RESCUE_BASIC_PRICE);
                break;
            }
        }
        else if (result.Equals("failed"))
        {
#if !UNITY_IOS
            string rescueTitleText = TextManager.GetText("pay_failed");
            GameSystem.GetInstance().gameUI.confirmMenu.SetContent(rescueTitleText, null, ConfirmStyle.OnlyYes);
            GameSystem.GetInstance().gameUI.confirmMenu.Show(true);
#endif
            switch (product)
            {
            case IAPProduct.ActiveGame:
                GameSystem.GetInstance().gameUI.confirmMenu.SetConfirmCallback((confirmResult) => {
                    if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                    {
                        GameSystem.GetInstance().JumpToGameEnd();
                    }
                });
                break;

            case IAPProduct.VIP:
                break;

            case IAPProduct.WhiteBlock1:
            case IAPProduct.WhiteBlock2:
            case IAPProduct.WhiteBlock3:
            case IAPProduct.WhiteBlock4:
            case IAPProduct.WhiteBlock5:
#if UNITY_IOS
                if (GameSystem.GetInstance().UnlockRecommendMode)
                {
                    GameSystem.GetInstance().UnlockRecommendMode = false;
                    GameSystem.GetInstance().PayUnlockRecommendModeCallback(false);
                }
#else
                if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                {
                    GameSystem.GetInstance().PayUnlockModeCallback(false);
                }
#endif
                break;

            case IAPProduct.Rescue:
                GameSystem.GetInstance().gameUI.confirmMenu.SetConfirmCallback((confirmResult) => {
                    if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                    {
                        GameSystem.GetInstance().JumpToGameEnd();
                    }
                });
                break;
            }
        }
        else if (result.Equals("cancel"))
        {
#if !UNITY_IOS
            string rescueTitleText = TextManager.GetText("pay_cancel");
            GameSystem.GetInstance().gameUI.confirmMenu.SetContent(rescueTitleText, null, ConfirmStyle.OnlyYes);
            GameSystem.GetInstance().gameUI.confirmMenu.Show(true);
#endif
            switch (product)
            {
            case IAPProduct.ActiveGame:
                GameSystem.GetInstance().gameUI.confirmMenu.SetConfirmCallback((confirmResult) => {
                    if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                    {
                        GameSystem.GetInstance().JumpToGameEnd();
                    }
                });
                break;

            case IAPProduct.VIP:
                break;

            case IAPProduct.WhiteBlock1:
            case IAPProduct.WhiteBlock2:
            case IAPProduct.WhiteBlock3:
            case IAPProduct.WhiteBlock4:
            case IAPProduct.WhiteBlock5:
#if UNITY_IOS
                if (GameSystem.GetInstance().UnlockRecommendMode)
                {
                    GameSystem.GetInstance().UnlockRecommendMode = false;
                    GameSystem.GetInstance().PayUnlockRecommendModeCallback(false);
                }
#else
                if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                {
                    GameSystem.GetInstance().PayUnlockModeCallback(false);
                }
#endif
                break;

            case IAPProduct.Rescue:
                GameSystem.GetInstance().gameUI.confirmMenu.SetConfirmCallback((confirmResult) => {
                    if (GameSystem.GetInstance().CurrentState == GameSystem.States.WaveComplete)
                    {
                        GameSystem.GetInstance().JumpToGameEnd();
                    }
                });
                break;
            }
        }
    }