cc.Class({ extends: cc.BaseClass, ctor: function () { this.m_LastIndex = 0; this.m_LastRotation = 0; this.m_BaseTurns = 5; this.m_BaseRate = 60; this.m_BaseItemCnt = 6; this.m_CurIndex = 0; this.m_TotalCnt = 0; this.m_UserCnt = 0; this.m_ResInfo = null; }, onLoad: function () { this.m_BasicSound = new Array(); this.m_BasicSound[0] = ['TURN','Audio/turn']; this.m_BasicSound[1] = ['AWARD','Audio/award']; cc.gSoundRes.LoadSoundArr(this.m_BasicSound,'TurnTable'); this.m_TurnNode = this.$('bg/wheel'); this.m_LabShareInfo = this.$('textContent/ShareInfo@Label'); this.m_LabSignInfo = this.$('textContent/SignInfo@Label'); this.m_LabGameCntInfo = this.$('textContent/GameCntInfo@Label'); this.m_LabCnt = this.$('turnNode/LeftCnt@Label'); this.m_pointer = this.$('turnNode/pointer@SpineAnimationCtrl'); this.m_BtTurn = this.$('turnNode/BtTurn@Button'); this.m_selectEffect = this.$('turnNode/selectEffect@SpineAnimationCtrl'); this.m_turnEffect = this.$('turnNode/turnEffect'); this.m_clickEffect = this.$('turnNode/BtTurn/clickEffect@SpineAnimationCtrl'); this.m_showLight = this.$('turnNode/showLight'); this.m_AwardRes = this.$('AwardNode'); }, ShowView: function () { this.m_TotalCnt = 0; var webUrl = window.PHP_HOME + '/Lottery.php?&GetMark=0'; var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); webUrl += '&dwUserID=' + pGlobalUserData.dwUserID; WebCenter.GetData(webUrl, 0, function (data) { var res = JSON.parse(data); console.log(res); this.m_TotalCnt += res.IsShare == 0 ? 0 : 1; this.m_TotalCnt += res.IsSign == 0 ? 0 : 1; this.m_TotalCnt += res.GameCnt == 0 ? 0 : Math.floor(res.GameCnt / 10); this.m_TotalCnt += res.FreeCnt ? res.FreeCnt : 0; this.m_UserCnt = res.UserCnt; this.initView(res); }.bind(this)); this.node.active = true; this.m_AwardRes.active = false; this.m_showLight.active = true; this.m_clickEffect.playAnimation("idle", true); this.m_pointer.playAnimation("idle", true); this.m_selectEffect.playAnimation("idle", true); this.m_turnEffect.active = false; this.m_selectEffect.node.active = false; this.isSet = true; this.m_turning = false; this.isFirst = true; }, initView: function (res) { /** * 1.每日分享一次游藏,可得一次轉盤抽獎。 * 2.每日登錄可獲得一次轉盤抽獎。 * 3.每日進行10局遊戲,可参與一次轉盤抽獎。(今日已进行1局,再去打9局即可抽獎) */ const PlayCount = 10; this.m_LabShareInfo.node.color = res.IsShare == 0 ? cc.color(97, 65, 16) : cc.color(0, 255, 0); this.m_LabSignInfo.node.color = res.IsSign == 0 ? cc.color(97, 65, 16) : cc.color(0, 255, 0); this.m_LabGameCntInfo.node.color = res.GameCnt < PlayCount ? cc.color(97, 65, 16) : cc.color(0, 255, 0); this.m_LabShareInfo.string = `1.每日分享一次游藏,可得一次轉盤抽獎。${res.IsShare != 0 ? "√" : ""}`; this.m_LabSignInfo.string = `2.每日登錄可獲得一次轉盤抽獎。${res.IsSign != 0 ? "√" : ""}`; this.m_LabGameCntInfo.string = `3.每日進行10局遊戲,可参與一次轉盤抽獎。(${res.GameCnt}/${PlayCount})${res.GameCnt >= PlayCount ? "√" : ""}` this._updateLeftDrawCount(); this._updateTurnStatus(); }, _setView() { if (this.isSet) { return; } this.isSet = true; this.m_pointer.playAnimation("idle", true); this.m_selectEffect.playAnimation("idle", true); this.m_turnEffect.active = false; this.m_selectEffect.node.active = false; }, onBtTurn: function () { // if (this.m_turning) { // return; // } // this._setView(); // this.m_turning = true; // this.m_clickEffect.playAnimation("touch", false, true, "idle", true); // this.m_showLight.active = false; // this.TurnAcion(); // return if (this.m_turning) { return; } this._setView(); if (this.m_TotalCnt - this.m_UserCnt == 0) { this.ShowAlert('次数已用完,不能抽奖'); return; } this.m_turning = true; this.m_clickEffect.playAnimation("touch", false, true, "idle", true); this.m_showLight.active = false; var webUrl = window.PHP_HOME + '/Lottery.php?&GetMark=1'; var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); webUrl += '&dwUserID=' + pGlobalUserData.dwUserID; WebCenter.GetData(webUrl, 0, function (data) { var res = JSON.parse(data); if (res.resCode == 1) { this.ShowAlert('抽奖失败,请联系管理员'); this.m_turning = false; return; } this.m_ResInfo = res.resLottery; console.log(res); this.m_CurIndex = res.resLottery[0]; this.TurnAcion(); this.m_UserCnt++; this.m_LastIndex = this.m_CurIndex; }.bind(this)); }, TurnAcion: function () { this.isSet = false; this.m_turnEffect.active = true; this.m_turnEffect.opacity = 0; cc.tween(this.m_turnEffect) .to(1/6, { opacity: 255 }) .start(); console.log('m_LastIndex:'+this.m_LastIndex); console.log('m_LastIndex:'+this.m_CurIndex); var totalRotation = -360 * this.m_BaseTurns - (this.isFirst ? 30 : 0); var offsetR = 0; if (this.m_CurIndex > this.m_LastIndex) { offsetR = this.m_BaseItemCnt + this.m_LastIndex - this.m_CurIndex ; } else { offsetR = this.m_LastIndex - this.m_CurIndex; } console.log('offsetR:'+offsetR); totalRotation -= offsetR * this.m_BaseRate; cc.gSoundRes.PlaySound('TURN'); let turnCallback = () => { console.log('finish!!!'); this.isFirst = false; this._showGotEffect(); this._updateTurnStatus(); this._updateLeftDrawCount(); var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); pGlobalUserData.llUserIngot = parseInt(pGlobalUserData.llUserIngot) + parseInt(this.m_ResInfo[2]); this.m_Hook.OnUpdateCard(); this.onShowAward(); this.m_turning = false; }; cc.tween(this.m_TurnNode) .by(5, { angle: totalRotation }, { easing: 'quadInOut' }) .call(turnCallback) .start(); }, _showGotEffect() { cc.tween(this.m_turnEffect) .to(1/6, { opacity: 0 }) .set({ opacity: 255, active: false }) .start(); this.m_selectEffect.playAnimation("touch", true); this.m_pointer.playAnimation("touch", true); }, _updateLeftDrawCount() { let leftCount = this.m_TotalCnt - this.m_UserCnt; if (leftCount < 0) { leftCount = 0; } this.m_LabCnt.string = `今日剩餘抽獎次數:${leftCount}次`; }, _updateTurnStatus() { this.m_BtTurn.interactable = (this.m_TotalCnt - this.m_UserCnt) > 0; }, onShowAward: function () { this.m_AwardRes.active = true; var ani = this.$('AwardNode/AniNode').getComponent(dragonBones.ArmatureDisplay); cc.gSoundRes.PlaySound('AWARD'); if (this.m_ResInfo[1] == 0) { ani.armatureName = 'xiexiecanyu'; this.$('AwardNode/AwardItem').active = false; this.$('AwardNode/AwardInfo').active = false; this.$('AwardNode/NoAwardInfo').active = true; } else { ani.armatureName = 'gognxihuode'; var Item = this.$('AwardNode/AwardItem@Sprite'); var LabInfo = this.$('AwardNode/AwardInfo@Label'); this.$('AwardNode/NoAwardInfo').active = false; cc.gPreLoader.LoadRes('Image_Item' +(this.m_ResInfo[0]+1) ,'TurnTable', function (sf) { Item.spriteFrame = sf; Item.node.active = true; }.bind(this)); LabInfo.node.active = true; LabInfo.string = `恭喜您获得"${this.m_ResInfo[2]}钻石"`; } ani.playAnimation('newAnimation', 1); }, OnBtAwardHide: function () { this.m_AwardRes.active = false; }, });