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); }
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(); } }
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); }
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(); }
// 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; } } }