var touch,__extends=this&&this.__extends||function(){var e=function(i,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[t]=i[t])})(i,t)};return function(i,t){function n(){this.constructor=i}if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(i,t),i.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}}();!function(e){var i=function(i){function t(t){var n=i.call(this)||this;n._main=null,n._deadNum=0,n._revivingCountdown=0,n._score=0,n._distance=0,n._exceed=0,n._pkscore=0,n._BeyondFriendMaxIndex=0,n._beyondList=[],n._isPlayBeyondF=!1,n._count=0,n.nearFriends=[],n.isVictory=!1,n._sprintAnimation=0,n._uiSprintAnimationLeft=0,n._uiSprintAnimationRight=0,n._reviveDialog=null,n._resultView=null,n.tempBeyondList=[],n.tempBeyondWorldCount=0,n.tempReadyBeyondRank=null,n.tempISReadyBeyondRank=!0,n.tempBeyondScore=n.getBeyondTagerScore(),n._newSkins=[],n._main=t,n.onExceedNumberChange(0),n.onInitLife(),n._main.event(e.GameEvent.RESET),n.showScore(!1),n.boxBallState.visible=!1,n.onLootDiamondChange(0),n.boxReviving.visible=!1,n.boxLife.visible=!1,n.boxDiamond.visible=e.GameData.instance.config.diamondGroup.enabled,n.BeyondFriend.visible=!1,n.BeyondFriend.alpha=0,n.boxGuide.visible=!0,n.aniGuide.play(0,!0),n.stopSprintAnimation(),n._main.on(e.GameEvent.LIFE_CHANGE,n,n.onLifeChange),n._main.on(e.GameEvent.EXCEED_NUM_CHANGE,n,n.onExceedNumberChange),n._main.on(e.GameEvent.DISTANCE_CHANGE,n,n.onDistanceChange),n._main.on(e.GameEvent.LOOT_DIAMOND_CHANGE,n,n.onLootDiamondChange),n._main.on(e.GameEvent.DEAD,n,n.onDead),n._main.on(e.GameEvent.SPRINT_CHANGE,n,n.onSprintStateChange),n._main.on(e.GameEvent.TASK_FINISHED,n,n.onTaskFinished),n._main.on(e.GameEvent.SKIN_UNLOCkED,n,n.onSkinUnlocked),Laya.stage.once(Laya.Event.MOUSE_DOWN,n,n.onDidStartGame),n._BeyondFriendMaxIndex=0,n._isPlayBeyondF=!1,n._count=0,n.pbProgress.value=0,n.unlockLab.text=e.Lang.getLangText(e.Lang.unlock),n.tipLab.text=e.Lang.getLangText(e.Lang.control_ball);var a=e.Lang.getLangText(e.Lang.surpass);return a=a.replace("${value}","0"),n.tfExceed.text=a,n}return __extends(t,i),t.prototype.destroy=function(){this.stopSprintAnimation(),Laya.timer.clear(this,this.onRevivingCountDown),this._main.off(e.GameEvent.DEAD,this,this.onDead),this._main.off(e.GameEvent.EXCEED_NUM_CHANGE,this,this.onExceedNumberChange),this._main.off(e.GameEvent.DISTANCE_CHANGE,this,this.onDistanceChange),this._main.off(e.GameEvent.LOOT_DIAMOND_CHANGE,this,this.onLootDiamondChange),this._main.off(e.GameEvent.LIFE_CHANGE,this,this.onLifeChange),this._main.off(e.GameEvent.SPRINT_CHANGE,this,this.onSprintStateChange),this._main.off(e.GameEvent.TASK_FINISHED,this,this.onTaskFinished),this._main.off(e.GameEvent.SKIN_UNLOCkED,this,this.onSkinUnlocked),this._resultView&&(console.info("===> Remove Result View"),this._resultView.removeSelf(),this._resultView.destroy(),this._resultView=null),this._main=null,i.prototype.destroy.call(this)},t.prototype.onDidStartGame=function(){this.initBeyondFriend(),this.showScore(!0),this.boxGuide.visible=!1,this.boxLife.visible=GameBaseData.isSinglePlayerMode,this.aniGuide.stop(),this._main.event(e.GameEvent.DID_START_GAME)},t.prototype.onExceedNumberChange=function(i){var t=i-this._exceed;if(this._exceed=i,GameBaseData.isMultiplePlayerMode){this._score=i;var n=e.Lang.getLangText(e.Lang.surpass);n=n.replace("${value}",i+""),this.tfExceed.text=n,this._score>0&&(t>0&&(e.TaskManager.instance.addSurpass(t),50!==this._score&&100!==this._score&&200!==this._score&&300!==this._score&&400!==this._score&&500!==this._score||SdkHelper.EventLogger.logMultiScore(this._score)),this.updataBeyondFriend2())}},t.prototype.onDistanceChange=function(i){var t=Math.floor(i-this._distance);t<1||(this._distance=i,this.tfDistance.text=i+e.Lang.getLangText(e.Lang.metre),GameBaseData.isSinglePlayerMode&&(this._score=i,this._score>0&&e.TaskManager.instance.addDistance(t)),this.updataBeyondFriend2())},t.prototype.onLootDiamondChange=function(e){this.txtDiamond.text=e.toString()},t.prototype.onLifeChange=function(e,i){this.pbProgress.value=e/100,1==i?this.onChangeLife(!0):2==i&&this.onChangeLife(!1)},t.prototype.onInitLife=function(){this.l1.visible=!1,this.l2.visible=!1,this.l3.visible=!1,this.l4.visible=!1,this.l5.visible=!1,this.l1Gray.visible=!0,this.l2Gray.visible=!0,this.l3Gray.visible=!0,this.l4Gray.visible=!0,this.l5Gray.visible=!0},t.prototype.onChangeLife=function(e){var i=this;if(console.info("++"),e){if(this._playLifeIncreaseAnimation(),!this.l1.visible)return this.l1.visible=!0,this.l1.scaleX=this.l1.scaleY=.1,this.l1.x=310,this.l1.y=77,void Laya.Tween.to(this.l1,{scaleX:1,scaleY:1,x:23,y:23},300,Laya.Ease.linearIn,Laya.Handler.create(this,function(){i.l1Gray.visible=!1}));if(!this.l2.visible)return this.l2.visible=!0,this.l2.scaleX=this.l2.scaleY=.1,this.l2.x=310,this.l2.y=77,void Laya.Tween.to(this.l2,{scaleX:1,scaleY:1,x:76,y:23},350,Laya.Ease.linearIn,Laya.Handler.create(this,function(){i.l2Gray.visible=!1}));if(!this.l3.visible)return this.l3.visible=!0,this.l3.scaleX=this.l3.scaleY=.1,this.l3.x=310,this.l3.y=77,void Laya.Tween.to(this.l3,{scaleX:1,scaleY:1,x:129,y:23},400,Laya.Ease.linearIn,Laya.Handler.create(this,function(){i.l3Gray.visible=!1}));if(!this.l4.visible)return this.l4.visible=!0,this.l4.scaleX=this.l4.scaleY=.1,this.l4.x=310,this.l4.y=77,void Laya.Tween.to(this.l4,{scaleX:1,scaleY:1,x:182,y:23},450,Laya.Ease.linearIn,Laya.Handler.create(this,function(){i.l4Gray.visible=!1}));if(!this.l5.visible)return this.l5.visible=!0,this.l5.scaleX=this.l5.scaleY=.1,this.l5.x=310,this.l5.y=77,void Laya.Tween.to(this.l5,{scaleX:1,scaleY:1,x:235,y:23},500,Laya.Ease.linearIn,Laya.Handler.create(this,function(){i.l5Gray.visible=!1}))}else{if(this._playLifeDecreaseAnimation(),this.l5.visible)return this.l5.visible=!1,void(this.l5Gray.visible=!0);if(this.l4.visible)return this.l4.visible=!1,void(this.l4Gray.visible=!0);if(this.l3.visible)return this.l3.visible=!1,void(this.l3Gray.visible=!0);if(this.l2.visible)return this.l2.visible=!1,void(this.l2Gray.visible=!0);if(this.l1.visible)return this.l1.visible=!1,void(this.l1Gray.visible=!0)}},t.prototype._playLifeDecreaseAnimation=function(){var e=this,i=this.boxLife.x+this.boxLife.width/2,t=this.boxLife.y+this.boxLife.height/2;this.boxLifeTip.visible=!0,this.boxLifeTip.scaleX=this.boxLifeTip.scaleY=1,this.boxLifeTip.x=i,this.boxLifeTip.y=t,this.txtLifeTip.text="-1",Laya.Tween.to(this.boxLifeTip,{scaleX:2.5,scaleY:2.5,x:300,y:600},1e3,Laya.Ease.bounceOut,Laya.Handler.create(this,function(){e.boxLifeTip.visible=!1}),0)},t.prototype._playLifeIncreaseAnimation=function(){var e=this,i=this.boxLife.x+this.boxLife.width/2,t=this.boxLife.y+this.boxLife.height/2;this.boxLifeTip.visible=!0,this.boxLifeTip.scaleX=this.boxLifeTip.scaleY=2.5,this.boxLifeTip.x=300,this.boxLifeTip.y=600,this.txtLifeTip.text="+1",Laya.Tween.to(this.boxLifeTip,{scaleX:1,scaleY:1,x:i,y:t},800,Laya.Ease.linearIn,Laya.Handler.create(this,function(){e.boxLifeTip.visible=!1}),0)},t.prototype.onDead=function(){this.isVictory=!1,Laya.timer.once(1e3,this,this.doDead)},t.prototype.stopSprintAnimation=function(){this.boxSprintEffect.visible=!1,this._uiSprintAnimationLeft>0&&(e.GameUtils.stopSkinAnimation(this.imgSprint1,this._uiSprintAnimationLeft),e.GameUtils.stopSkinAnimation(this.imgSprint2,this._uiSprintAnimationRight))},t.prototype.onSprintStateChange=function(i){this._sprintAnimation>0&&(e.GameUtils.stopSkinAnimation(this.imgSprintBall,this._sprintAnimation),this._sprintAnimation=0),this.boxSprintEffect.visible=i,i?(this._uiSprintAnimationLeft=e.GameUtils.enableSkinAnimation(this.imgSprint1,"skin","v1.1/animation/ui_flash_{index}.png",1,5,60),this._uiSprintAnimationRight=e.GameUtils.enableSkinAnimation(this.imgSprint2,"skin","v1.1/animation/ui_flash_{index}.png",1,5,60),this.pbProgress.skin="v1.1/ui/progress_2.png"):(this.pbProgress.skin="v1.1/ui/progress.png",this.stopSprintAnimation())},t.prototype.showReviveDialog=function(){var i=this;this._deadNum++,this.showScore(!1),this.boxLife.visible=!1,this.BeyondFriend.visible=!1,GameBaseData.reviveCount++,this._reviveDialog||(this._reviveDialog=new e.GameReviveDialog);var t=this._reviveDialog;Laya.stage.addChild(t),t._closeHandler=function(t){console.info("Revive Choice: ",t),t!==e.ReviveChoice.NO_REVIVE?GameBaseData.isNative?i.reliveCloseHandlerNative(t):i.reliveCloseHandlerH5(t):i.gameOver()},t.popup(null,!1),t.startCountDown()},t.prototype.reliveCloseHandlerNative=function(i){i==e.ReviveChoice.NO_REVIVE?this._showNativeAdsOnGameOver():this.onWathVideo()},t.prototype.reliveCloseHandlerH5=function(i){i===e.ReviveChoice.NO_REVIVE?this.gameOver():this.onWathVideo()},t.prototype.showDeadInterstitialAd=function(){GameBaseData.isNative||SdkHelper.MiniGameSDKHelper.isInterstitialReady()&&SdkHelper.MiniGameSDKHelper.showInterstitial()},t.prototype.doDead=function(){this.stopSprintAnimation();var e=!1;e=GameBaseData.isNative?SdkHelper.IronSourceHelper.isVideoReady():SdkHelper.MiniGameSDKHelper.isRewardVideoReady(),this._deadNum<=2&&e&&(GameBaseData.isMultiplePlayerMode&&this._score>30||GameBaseData.isSinglePlayerMode&&this._score>800)?(GameBaseData.isNative,this.showReviveDialog()):(this._deadNum=0,this.playCPGGAndShowResult())},t.prototype.playCPGGAndShowResult=function(){if(this.isVictory)return this.isVictory=!1,void this.gameOver();this._showNativeAdsOnGameOver()},t.prototype._showNativeAdsOnGameOver=function(){GameBaseData.isNative?this.showNativeAdsOnGameOver():this.gameOver()},t.prototype.showNativeAdsOnGameOver=function(){var i=this;SdkHelper.IronSourceHelper.isInterstitialReady()?SdkHelper.IronSourceHelper.showInterstitialAsync(function(){SdkHelper.EventLogger.logAdShowEvent("GameOver",e.GameData.instance.isNewUser),i.gameOver()}):this.gameOver()},t.prototype.showH5AdsOnGameOver=function(){var e=this;SdkHelper.MiniGameSDKHelper.isInterstitialReady()?SdkHelper.MiniGameSDKHelper.showInterstitial(function(i){e.gameOver()}):this.gameOver()},t.prototype.showResultView=function(){SdkHelper.EventLogger.logGameEnd(GameBaseData.currentGameMode,this._distance,this._exceed),this.showScore(!1),this.boxLife.visible=!1,this.BeyondFriend.visible=!1,this._main.event(e.GameEvent.GAME_OVER,Math.floor(this._score)),null==this._resultView&&(this._resultView=new e.GameResultView,this.parent.addChild(this._resultView)),this._resultView.updateDisplay(),this._resultView.visible=!0,GameBaseData.isMultiplePlayerMode?this._score>e.TaskManager.instance.getBestSurpass()&&e.TaskManager.instance.setBestSurpass(this._score):GameBaseData.isSinglePlayerMode&&this._score>e.TaskManager.instance.getBestDistance()&&e.TaskManager.instance.setBestDistance(this._score),e.TaskManager.instance.save(),this.onOnlineReward()},t.prototype._showNewSkinOnEnd=function(){e.SkinManager.hasNewSkin()?this._showUnlockedSkins(this.showResultView.bind(this)):this.showResultView()},t.prototype._showUnlockedSkins=function(i){var t=this,n=e.SkinManager.getNewSkins().shift();e.SkinManager.clearNewSkinMark(n),e.SkinManager.save(),e.NewAwardDialog.showSkinAwards(n,function(a){e.GameData.instance.skinIndex=n,t._main.event(e.GameEvent.CHANGE_SKIN),e.SkinManager.hasNewSkin()?t._showUnlockedSkins(i):i()})},t.prototype.gameOver=function(){var i=this;if(GameBaseData.currentMatch.diamond>0){var t=GameBaseData.currentMatch.diamond,n=!0;n=SdkHelper.SdkUtils.isNativeMobile?SdkHelper.IronSourceHelper.isVideoReady():SdkHelper.MiniGameSDKHelper.isRewardVideoReady(),e.NewAwardDialog.showDiamondAwards(t,n,function(n){n?GameBaseData.isNative&&SdkHelper.IronSourceHelper.isVideoReady()?SdkHelper.IronSourceHelper.showVideoAdsAsync(function(n){n?t*=2:e.Notice.show("Complete the ads to get rewards"),e.Notice.show("Diamond +"+t),e.GameData.instance.diamond+=t,i._showNewSkinOnEnd()}):!GameBaseData.isNative&&SdkHelper.MiniGameSDKHelper.isRewardVideoReady()?SdkHelper.MiniGameSDKHelper.showRewardedVideo(function(n){n?t*=2:e.Notice.show("Complete the ads to get rewards"),e.Notice.show("Diamond +"+t),e.GameData.instance.diamond+=t,i._showNewSkinOnEnd()}):(e.Notice.show("Diamond +"+t),e.GameData.instance.diamond+=t,i._showNewSkinOnEnd()):(e.Notice.show("Diamond +"+t),e.GameData.instance.diamond+=t,i._showNewSkinOnEnd())})}else this._showNewSkinOnEnd()},t.prototype.showNativeDoubleReward=function(){},t.prototype.showH5DoubleReward=function(){},t.prototype.showNextUnlockSkin=function(){var e=this;if(!(this.boxTip.visible||this._newSkins.length<=0)){var i=this._newSkins.shift();this.boxTip.visible=!1,i>0&&(this.imgTip.skin="index/skin"+i+".png",this.boxTip.visible=!0,this.boxTip.right=-200,Laya.Tween.to(this.boxTip,{right:0},300,Laya.Ease.linearIn,Laya.Handler.create(this,function(){Laya.Tween.to(e.boxTip,{right:0},2e3,Laya.Ease.linearIn,Laya.Handler.create(e,function(){e.boxTip.visible=!1,e.showNextUnlockSkin()}))})))}},t.prototype.onWathVideo=function(){GameBaseData.isDebug&&console.log("观看视频"),this.onNativeWatchVideoRevive()},t.prototype.onNativeWatchVideoRevive=function(){GameBaseData.isNative?this.showNativeReliveVideo():this.showH5ReliveVideo()},t.prototype.showNativeReliveVideo=function(){var i=this;SdkHelper.IronSourceHelper.isVideoReady()?SdkHelper.IronSourceHelper.showVideoAdsAsync(function(t){t?(SdkHelper.EventLogger.logAdShowEvent("Revive",e.GameData.instance.isNewUser),i._onWathVideo(),SdkHelper.EventLogger.logAwardReceiveAdRevive()):(e.Notice.show("Ads needs to be completed to Revive"),i.gameOver())}):this._onWathVideo()},t.prototype.showH5ReliveVideo=function(){var i=this;SdkHelper.MiniGameSDKHelper.isRewardVideoReady()?SdkHelper.MiniGameSDKHelper.showRewardedVideo(function(t){t?(i._onWathVideo(),SdkHelper.EventLogger.logAwardReceiveAdRevive()):(e.Notice.show("Ads needs to be completed to Revive"),i.gameOver())}):(e.Notice.show("Ads is not ready"),this.gameOver())},t.prototype.showScore=function(i){this.tfDistance.visible=!1,this.tfExceed.visible=!1,e.GameData.instance.config.diamondGroup.enabled&&(this.boxDiamond.visible=i),GameBaseData.isMultiplePlayerMode?this.tfExceed.visible=i:this.tfDistance.visible=i,this.boxBallState.visible=i},t.prototype._onWathVideo=function(){this._main.event(e.GameEvent.REVIVE),this.boxReviving.visible=!0,this.showScore(!0),this.boxLife.visible=GameBaseData.isSinglePlayerMode,this.doRevivingCountDown(),1==this.BeyondFriend.alpha&&(this.BeyondFriend.visible=!0)},t.prototype.updataBeyondFriend2=function(){this._count++,this._count<100&&GameBaseData.isSinglePlayerMode||(this._count=0,this.tempISReadyBeyondRank&&this._score>this.tempBeyondScore&&this.setPlayBeyondRank())},t.prototype.initBeyondFriend=function(){var e=this;GameBaseData.getInitBeyondFriend(GameBaseData.currentGameMode,function(i,t){e.tempBeyondList=i,e.getRankObj_second()})},t.prototype.getRankObj_second=function(){this.tempBeyondWorldCount++;var e=this.getBeyondTagerScore();this.tempBeyondScore=this.tempBeyondWorldCount*e-e/2+Math.floor(e*Math.random());var i=new RankObj;i.pic=this.getFakeAvatar(),i.score=""+this.tempBeyondScore,this.setReadyBeyondRank(i)},t.prototype.getFakeAvatar=function(){var i=e.GameDefine.TOTAL_FAKE_AVATARS;return"head/"+(Math.floor(Math.random()*i)+1)+".png"},t.prototype.setReadyBeyondRank=function(i){this.tempReadyBeyondRank=i,this.bfInfo.text=i.score+(GameBaseData.isSinglePlayerMode?e.Lang.getLangText(e.Lang.metre):""),this.tempBeyondScore=i.score,i.pic?(this.bfImage.skin=null,this.bfImage.on(Laya.Event.LOADED,this,this.onLoadBeyondImage),this.bfImage.skin=i.pic):this.onLoadBeyondImage(),GameBaseData.isDebug&&(console.log("超越角色=>"),console.log(i))},t.prototype.onLoadBeyondImage=function(){GameBaseData.isDebug&&console.log("超越头像载入完毕"),this.BeyondFriend.y=360,this.BeyondFriend.x=80,this.BeyondFriend.scaleX=this.BeyondFriend.scaleY=0,this.BeyondFriend.alpha=1;this.BeyondFriend.visible=!0,Laya.Tween.clearAll(this.BeyondFriend),Laya.Tween.to(this.BeyondFriend,{scaleX:1,scaleY:1},800,Laya.Ease.elasticOut,Laya.Handler.create(this,function(){}),0),this.tempISReadyBeyondRank=!0,this.bfImage.off(Laya.Event.LOADED,this,this.onLoadBeyondImage)},t.prototype.setPlayBeyondRank=function(){var e=this;if(!this.tempReadyBeyondRank)return console.log("没有头像 请求"),void this.getRankObj_second();this.tempISReadyBeyondRank=!1,Laya.Tween.clearAll(this.BeyondFriend),Laya.Tween.to(this.BeyondFriend,{y:120,alpha:.1},800,Laya.Ease.cubicOut,Laya.Handler.create(this,function(){e.tempReadyBeyondRank=null,e.tempISReadyBeyondRank=!0,e.BeyondFriend.visible=!1,console.log("头像超越完毕 请求"),e.getRankObj_second()}),0)},t.prototype.getBeyondTagerScore=function(){return GameBaseData.isMultiplePlayerMode?6:500},t.prototype.doRevivingCountDown=function(){this._revivingCountdown=t.REVIVING_COUNTDOWN,this.updateRevivingUI(),Laya.timer.loop(1e3,this,this.onRevivingCountDown)},t.prototype.onRevivingCountDown=function(){this._revivingCountdown--,this.updateRevivingUI(),this._revivingCountdown<=0&&(Laya.timer.clear(this,this.onRevivingCountDown),this.boxReviving.visible=!1,this.showScore(!0),this.boxLife.visible=GameBaseData.isSinglePlayerMode,this.BeyondFriend.visible=!0)},t.prototype.updateRevivingUI=function(){this.tfReviving.text=this._revivingCountdown.toString()},t.prototype.onOnlineReward=function(){e.TipDialog.can_subscribe&&0==e.TipDialog.pushState&&this._main.event(e.GameEvent.OPEN_TIP,1)},t.prototype.onTaskFinished=function(e){},t.prototype.onSkinUnlocked=function(e){this._newSkins.push(e),this.showNextUnlockSkin()},t.PAGE="Game",t.REVIVING_COUNTDOWN=3,t}(ui.GameViewUI);e.GameView=i}(touch||(touch={}));