import GameM, { VIDEO_TYPE, AUDIO_TYPE } from "../manager/GameM"; import TurntableItem from "../prefabs/TurntableItem"; import UiM, { PANEL_NAME } from "../manager/UiM"; import Gift from "./Gift"; import CommonData, { HTTP_TYPE, MONEY_TYPE } from "../datas/CommonData"; import EffectNode from "./EffectNode"; import AdM from "../manager/AdM"; import Sciencen_M from "../utils/Sciencen_M"; import RoleManageData from "../datas/RoleManageData"; import TurntableData from "../datas/TurntableData"; import GuideMng from "../manager/GuideMng"; import { PlayerPrefs } from "../tools/MyExtends"; import { MateData } from "../datas/MateData"; import { Utils } from "../utils/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class Turntable extends cc.Component { @property(cc.Label) labDes: cc.Label = null; @property(cc.Label) labLeftTimes: cc.Label = null; @property(cc.Label) labLeftCardCount: cc.Label = null; @property(cc.Node) adIcon: cc.Node = null; @property(cc.Node) labCardTip: cc.Node = null; @property(cc.Node) turnIn: cc.Node = null; @property(cc.Node) ruleNode: cc.Node = null; @property(cc.Label) labRule: cc.Label = null; @property(cc.ParticleSystem) starAni: cc.ParticleSystem = null; @property(sp.Skeleton) runAni: sp.Skeleton = null; @property([cc.Node]) extraNode: cc.Node[] = [] @property(cc.Sprite) extraProgress: cc.Sprite = null private lock = false // LIFE-CYCLE CALLBACKS: // onLoad () {} private data = null private endAngle = 0 private startDraw = false private slowDis = 720 private slowAngle = 0 private perAdd = 10 private perMinus = 0 private itemList: Array = null //需要视频次数 private needVideoTimes = 8 onEnable() { this.labLeftTimes.string = TurntableData.Instance.turntableTimes.toString() this.labLeftCardCount.string = GameM.commonData.roleData.turntableCard.toString() this.adIcon.active = (TurntableData.Instance.turntableTimes <= this.needVideoTimes && GameM.commonData.roleData.turntableCard <= 0); this.labCardTip.active = GameM.commonData.roleData.turntableCard > 0 if (GuideMng.Ins.CurGuideId == 15) { if (PlayerPrefs.GetInt("GGuide15", 0) != 1) { //转盘引导 GuideMng.Ins.ResumeGuide(); } } AdM.showBanner() this.updateExtraInfo() } onDisable() { AdM.destroyBanner() } start() { if (!TurntableData.Instance.turntableCft) { this.lock = true TurntableData.Instance.getTurntableCfg() } else { this.init() } } // upRewardInfo:1,100;2,200 async init() { this.runAni.node.active = false let turntableCft = TurntableData.Instance.turntableCft let datas = new Array() // let turntableUseCard = GameM.commonData.roleData.turntableUseCard for (let entry of turntableCft) { if (entry.reward == 2) { let upRewardInfo: string = entry.upRewardInfo let a = upRewardInfo.split(";") let currentArr = this.checkCurrentNum(a) if (currentArr.length > 0) { entry.num = new Number(currentArr[1]).valueOf() } } datas.push(entry) } let typeTemp = new Array() for (let entry of datas) { if (entry.reward == 2) { typeTemp.push(entry) } } typeTemp = typeTemp.sort((a, b) => { return a.num > b.num ? 1 : -1 }) for (let i = 0; i < typeTemp.length; i++) { if (i < 4) { typeTemp[i].moneyLevel = i + 1 } else { typeTemp[i].moneyLevel = 4 } } this.itemList = new Array() let pre = await Utils.loadResPromise('prefabs/TurnTableItem') let item; let s for (var i = 0; i < datas.length; i++) { item = cc.instantiate(pre) s = item.getComponent(TurntableItem) for (let entry of typeTemp) { if (entry.index == datas[i].index) { datas[i] = entry break } } s.init(datas[i]) this.itemList.push(item) this.turnIn.addChild(item) } this.labRule.string = GameM.commonData.TxtCft[0].turn_table; this.lock = false // this.dengNode.runAction(cc.repeatForever(cc.sequence(cc.fadeIn(0.3), cc.fadeOut(0.3)))) } checkCurrentNum(arr: Array): Array { let turntableUseCard = GameM.commonData.roleData.turntableUseCard let turntableTimes = TurntableData.Instance.turntableTimes let nowCount = turntableUseCard + (10 - turntableTimes) let resultArray = new Array() for (let entry of arr) { let a = entry.split(",") if (new Number(a[0]).valueOf() <= nowCount) { resultArray = a } } return resultArray } updateCurrentNum() { let turntableCft = TurntableData.Instance.turntableCft for (let entry of turntableCft) { if (entry.reward != 2) { continue } else { let upRewardInfo: string = entry.upRewardInfo let a = upRewardInfo.split(";") let currentArr = this.checkCurrentNum(a) if (currentArr.length > 0) { entry.num = new Number(currentArr[1]).valueOf() let childList = this.turnIn.children for (let child of childList) { let turntableItem = child.getComponent(TurntableItem) if (turntableItem) { if (turntableItem.data.index == entry.index) { turntableItem.updateNum(entry.num) } } } } } } } clickRule() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.lock) { return } this.ruleNode.active = true } clickCloseRule() { this.ruleNode.active = false } /** 开始抽奖 */ clickDraw() { if (this.lock) { return } if (GameM.commonData.roleData.turntableCard > 0) { this.lock = true GameM.audioM.playEffect(AUDIO_TYPE.turntableDraw) this.data = TurntableData.Instance.getTurnTable(0) let index = this.data.index - 1 this.perAdd = 10 this.turnIn.angle += 360 * 5 this.endAngle = index * -60 this.slowAngle = this.endAngle + this.slowDis this.perMinus = this.perAdd / (this.slowDis / (this.perAdd * 0.5)) this.startDraw = true this.starAni.resetSystem() this.starAni.node.active = true GameM.commonData.roleData.turntableTotal++ GameM.commonData.updateRoleData() this.updateCurrentNum() } else if (TurntableData.Instance.turntableTimes > 0) { this.lock = true if (TurntableData.Instance.turntableTimes > this.needVideoTimes) { GameM.audioM.playEffect(AUDIO_TYPE.turntableDraw) this.data = TurntableData.Instance.getTurnTable(0) let index = this.data.index - 1 this.perAdd = 10 this.turnIn.angle += 360 * 5 this.endAngle = index * -60 this.slowAngle = this.endAngle + this.slowDis this.perMinus = this.perAdd / (this.slowDis / (this.perAdd * 0.5)) this.startDraw = true this.starAni.resetSystem() this.starAni.node.active = true GameM.commonData.roleData.turntableTotal++ GameM.commonData.updateRoleData() this.updateCurrentNum() } else { if (GameM.commonData.isVideoTest) { this.onTurnTableVideoEnd() } else { let state = GameM.adM.watchVideo(VIDEO_TYPE.turnTable) if (!state) { this.lock = false } } } } else { EffectNode.instance.PlayTip('次数不足,请等待重置') } } onTurnTableVideoEnd() { GameM.audioM.playEffect(AUDIO_TYPE.turntableDraw) this.data = TurntableData.Instance.getTurnTable(1) let index = this.data.index - 1 this.perAdd = 10 this.turnIn.angle += 360 * 5 this.endAngle = index * -60 this.slowAngle = this.endAngle + this.slowDis this.perMinus = this.perAdd / (this.slowDis / (this.perAdd * 0.5)) this.startDraw = true this.starAni.resetSystem() this.starAni.node.active = true EffectNode.instance.PlayTip("感谢您的观看,额外奖励已发放"); GameM.commonData.roleData.turntableTotal++ GameM.commonData.updateRoleData() } onTurnTableVideoFail() { this.startDraw = false this.lock = false } update(dt) { if (this.startDraw) { this.turnIn.angle -= this.perAdd //开始减速 if (this.turnIn.angle <= this.slowAngle) { if (this.perAdd <= this.perMinus * 4) { this.perAdd -= this.perMinus * 0.01 } else { this.perAdd -= this.perMinus } } if (this.turnIn.angle <= this.endAngle) { this.startDraw = false this.starAni.node.active = false this.runAni.node.active = true this.runAni.setAnimation(0, 'animation', false) GameM.audioM.playEffect(AUDIO_TYPE.turntableDrawEnd) if (GameM.commonData.roleData.turntableCard > 0) { RoleManageData.Instance.updateTurntableCardCount() this.labLeftCardCount.string = GameM.commonData.roleData.turntableCard.toString() this.adIcon.active = (TurntableData.Instance.turntableTimes <= this.needVideoTimes && GameM.commonData.roleData.turntableCard <= 0); this.labCardTip.active = GameM.commonData.roleData.turntableCard > 0 AdM.onSendEvent(`item_${MONEY_TYPE.turnTableCard}`, `使用道具${MONEY_TYPE.turnTableCard}`, 'item') } else { TurntableData.Instance.updateTurntableTimes() this.labLeftTimes.string = TurntableData.Instance.turntableTimes.toString() this.adIcon.active = TurntableData.Instance.turntableTimes <= this.needVideoTimes; this.labCardTip.active = GameM.commonData.roleData.turntableCard > 0 } this.updateExtraInfo() this.scheduleOnce(() => { this.lock = false UiM.Instance.checkDelayShow(() => { if (this.data.reward == 1) { //GameM.commonData.updateGiftCacheNum(this.data.num) UiM.Instance.giftNode.active = true let gift = UiM.Instance.giftNode.getComponent(Gift) gift.init(MONEY_TYPE.box, String(this.data.num), null, false, 0, null, -1, true); } else if (this.data.reward == 2) { UiM.Instance.giftNode.active = true let gift = UiM.Instance.giftNode.getComponent(Gift) let num = Sciencen_M.instance.accMul(GameM.commonData.goldSecond.toString(), (this.data.num * 60).toString()) gift.init(MONEY_TYPE.gold, num, null, false, 0, null, -1, true) } else if (this.data.reward == 3) { UiM.Instance.giftNode.active = true let gift = UiM.Instance.giftNode.getComponent(Gift) gift.init(MONEY_TYPE.redMoney, String(this.data.num), null, false, 0, null, -1, true) } else if (this.data.reward == 4) { UiM.Instance.giftNode.active = true let gift = UiM.Instance.giftNode.getComponent(Gift) gift.init(MONEY_TYPE.talentCoin, String(this.data.num), null, false, 0, null, -1, true) } }) }, 0.7) } } } clickClose() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.lock) { return } // this.node.active = false UiM.Instance.offPanel(PANEL_NAME.TurnTableNode, false, () => { AdM.createInter(6); }) } clickIconShowTip() { // let qipao = this.node.getChildByName('qipao') // qipao.active = true // this.scheduleOnce(() => { // if (cc.isValid(qipao)) { // qipao.active = false // } // }, 2) } updateExtraInfo() { let getTimes = GameM.commonData.roleData.turntableExtrasReward let totalTimes = GameM.commonData.getDailyFinishTimesDataByType(2) // this.extraProgress.fillRange = 0 let range = 0 for (let i = 0; i < this.extraNode.length; i++) { let cfgInfo = TurntableData.Instance.turntableExtrasCfg[i] let getType = 0 let propType = cfgInfo[1] let num = cfgInfo[2] if (cfgInfo[0] <= totalTimes) { range = i / (this.extraNode.length - 1) if (getTimes.indexOf(i) >= 0) { getType = 2 } else { getType = 1 } } else { getType = 0 } this.showReward(getType, propType, num, this.extraNode[i], totalTimes, cfgInfo[0]) } this.extraProgress.fillRange = range } /** * * @param getType 领取状态 0 未完成,1,未领取,2.已领取 * @param propType 物品id * @param num 物品数量 * @param node 物品节点 */ showReward(getType: number, propType: number, num: number, node: cc.Node, curTime: number, needTimes: number) { // if(propType == MONEY_TYPE.carLvUp) node.stopAllActions() node.scale = 1 if (propType == MONEY_TYPE.talentCoin) { cc.loader.loadRes('xiyou/icon/1003', cc.SpriteFrame, (err, assets) => { if (err) { cc.error(err); return; } if (cc.isValid(node)) { node.getChildByName("prop").getComponent(cc.Sprite).spriteFrame = assets; node.getChildByName("prop").scale = 0.6 } }) } node.getChildByName("num").getComponent(cc.Label).string = num + "" if (getType == 0) { node.getChildByName("getBg").active = false node.getChildByName("getIcon").active = false node.getChildByName("progress").getComponent(cc.Label).string = curTime + "/" + needTimes + "次" } else if (getType == 1) { node.getChildByName("getBg").active = true node.getChildByName("getIcon").active = false node.getChildByName("progress").getComponent(cc.Label).string = needTimes + "/" + needTimes + "次" node.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1, 1.3), cc.scaleTo(1, 1)))) } else if (getType == 2) { node.getChildByName("getBg").active = true node.getChildByName("getIcon").active = true node.getChildByName("progress").getComponent(cc.Label).string = needTimes + "/" + needTimes + "次" } } clickGetReward(event, type) { let index = Number(type) let getTimes = GameM.commonData.roleData.turntableExtrasReward let totalTimes = GameM.commonData.getDailyFinishTimesDataByType(2) let cfgInfo = TurntableData.Instance.turntableExtrasCfg[index] if (cfgInfo[0] <= totalTimes) { if (getTimes.indexOf(index) >= 0) { EffectNode.instance.PlayTip("已领取"); } else { let name = "" if (MONEY_TYPE.talentCoin == cfgInfo[1]) { MateData.Ins.talentCoin += cfgInfo[2] GameM.httpM.SendData(HTTP_TYPE.updateBattleStoneCount, { "count": MateData.Ins.talentCoin }) GameM.commonData.roleData.turntableExtrasReward.push(index) GameM.commonData.updateRoleData() name = "天赋石 *" + cfgInfo[2] + " " } EffectNode.instance.PlayTip(name + "领取成功"); this.updateExtraInfo() } } else { let desc = "" if (MONEY_TYPE.talentCoin == cfgInfo[1]) { // MateData.Ins.talentCoin += cfgInfo[2] // GameM.httpM.SendData(HTTP_TYPE.updateBattleStoneCount, { "count": MateData.Ins.talentCoin }) // GameM.commonData.roleData.turntableExtrasReward.push(index) // GameM.commonData.updateRoleData() desc = "即可获得 天赋石 *" + cfgInfo[2] } EffectNode.instance.PlayTip("完成" + (cfgInfo[0]) + "次转盘" + desc); } } }