// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import GameM, { AUDIO_TYPE } from "../manager/GameM"; import EffectNode from "../ui/EffectNode"; import UiM, { PANEL_NAME } from "../manager/UiM"; import Main from "../Main"; import { RecordTYPE } from "../datas/CommonData"; import { RichData } from "../datas/RichData"; import Task from "../ui/Task"; import AdM from "../manager/AdM"; const { ccclass, property } = cc._decorator; @ccclass export default class TaskItem extends cc.Component { @property(cc.Label) labDes: cc.Label = null; @property(cc.Sprite) pro: cc.Sprite = null; @property(cc.Label) proTxt: cc.Label = null; @property(cc.Label) labAward: cc.Label = null; @property(cc.Node) btnGet: cc.Node = null; @property(cc.Node) btnNo: cc.Node = null; @property(cc.Label) labGo: cc.Label = null; @property(cc.Node) btnGo: cc.Node = null; @property(cc.Node) activePart: cc.Node = null; @property(cc.Node) achievePart: cc.Node = null; @property(cc.Label) labAchieveAward: cc.Label = null; @property(cc.Node) iconGet: cc.Node = null; // LIFE-CYCLE CALLBACKS: // onLoad () {} /** 0 日常 1 成就 */ private tab = 0 public data = null /** 成就 * 1:合成车辆地次数 2:解锁XX等级地新车 3:成功观看广告地次数 4:玩家等级达到XX级别 5: 小秘书亲密度 6: 投资次数 7:转盘次数 日常 1:观看广告 2:转盘 3:飞艇 4:投资次数 5:工厂点击次数 6:现金夺宝 7:看视频得金币 */ private type = 0 isGeted: boolean = false; //是否已领取 start() { } onEnable() { this.updateSibling() } /** 初始化 * @param tab 0 日常 1 成就 * @param type 类型 * @param data 配合数据 * @param effect 效果 */ init(tab: number, type: number, data, effect = false) { //console.log("cfg init:"+tab+" type:"+type+" data:"+data) this.tab = tab this.type = type this.data = data let str = '' let fill = 0 let time = 0 if (effect) { cc.tween(this.node) .to(0.2, { x: -1000 }) .delay(0.1) .call(() => { this.node.x = 1000 }) .to(0.3, { x: 0 }) .start() } let showGo = false if (tab == 0) { time = GameM.commonData.getDailyFinishTimesDataByType(this.type) if (time > this.data.condition) { time = this.data.condition } switch (this.type) { case 1: str = `观看广告${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = false break; case 2: str = `转盘抽奖${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = true break; case 3: str = `点击空投礼包${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = false break; case 4: str = `探索${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = true break; case 5: str = `点击武将${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = false break; case 6: str = `现金夺宝${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = true break; case 7: str = `看视频得金币${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = false break; case 8: str = `参与财神降临${this.data.condition}次` fill = time / this.data.condition this.proTxt.string = time + "/" + this.data.condition showGo = false break; } this.activePart.active = true this.achievePart.active = false this.labAward.string = this.data.rewadr_num.toString() // this.labGo.string = des } else if (tab == 1) { switch (this.type) { case 1: str = `合成${this.data.condition}次武将` fill = GameM.commonData.composeCarTimes / this.data.condition this.proTxt.string = GameM.commonData.composeCarTimes + "/" + this.data.condition break; case 2: str = `解锁${this.data.condition}等级的新武将` fill = GameM.commonData.maxCarLevel / this.data.condition this.proTxt.string = GameM.commonData.maxCarLevel + "/" + this.data.condition break; case 3: str = `成功观看${this.data.condition}次广告` fill = GameM.commonData.videoTimes / this.data.condition this.proTxt.string = GameM.commonData.videoTimes + "/" + this.data.condition break; case 4: str = `玩家等级达到${this.data.condition}级` fill = GameM.commonData.roleData.lv / this.data.condition this.proTxt.string = GameM.commonData.roleData.lv + "/" + this.data.condition break; // case 5: // let num1 = GameM.commonData.SecretaryData.loveNum // let num2 = GameM.commonData.SecretaryDataSecond.loveNum // let num3 = GameM.commonData.SecretaryDataThird.loveNum // let num = Math.max(num1, num2, num3) // str = `小秘书亲密度达到${this.data.condition}点` // fill = num / this.data.condition // this.proTxt.string = num + "/" + this.data.condition // break; case 6: str = `投资达到${this.data.condition}次` fill = GameM.commonData.roleData.investTotal / this.data.condition this.proTxt.string = GameM.commonData.roleData.investTotal + "/" + this.data.condition break; case 7: str = `参加转盘抽奖${this.data.condition}次` fill = GameM.commonData.roleData.turntableTotal / this.data.condition this.proTxt.string = GameM.commonData.roleData.turntableTotal + "/" + this.data.condition break; } this.activePart.active = false this.achievePart.active = true this.labAchieveAward.string = this.data.rewadr_num.toString() } this.labDes.string = str this.pro.fillRange = fill if (fill >= 1) { if (tab == 0) { let times = GameM.commonData.getDailyGetData(this.type) let arr = GameM.commonData.taskCft[this.type.toString()] if (times < arr.length) { this.btnGet.active = true this.btnNo.active = false this.btnGo.active = false this.iconGet.active = false GameM.commonData.taskRedNum++ GameM.commonData.dailyTaskRedNum++ } else { this.btnGet.active = false this.btnNo.active = false this.btnGo.active = false this.isGeted = true this.iconGet.active = true } } else if (tab == 1) { GameM.commonData.taskRedNum++ GameM.commonData.achieveTaskRedNum++ this.btnGet.active = true this.btnNo.active = false this.btnGo.active = false this.iconGet.active = false } } else { this.btnGet.active = false if (showGo) { this.btnNo.active = false this.btnGo.active = true } else { this.btnNo.active = true this.btnGo.active = false } this.iconGet.active = false } } updateSibling() { if (this.isGeted) { this.node.setSiblingIndex(this.node.parent.childrenCount - 1); this.iconGet.active = true } } clickNo() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.tab == 0) { switch (this.type) { case 2: UiM.Instance.taskNode.active = false if (GameM.commonData.maxCarLevel >= GameM.commonData.turntableOpenLevel) { UiM.Instance.onPanel(PANEL_NAME.TurnTableNode) } else { EffectNode.instance.PlayTip(`首次合成${GameM.commonData.turntableOpenLevel}级武将解锁`) } break; case 4: UiM.Instance.taskNode.active = false if (GameM.commonData.maxCarLevel >= GameM.commonData.investOpenLevel) { UiM.Instance.onPanel(PANEL_NAME.InvestNode) } else { EffectNode.instance.PlayTip(`首次合成${GameM.commonData.investOpenLevel}级武将解锁`) } break; case 6: if (GameM.commonData.maxCarLevel >= GameM.commonData.trerasureOpenLevel) { if (GameM.commonData.isAuth) { UiM.Instance.taskNode.active = false UiM.Instance.onPanel(PANEL_NAME.TreasureNode) } else { AdM.WxLogin() } } else { EffectNode.instance.PlayTip(`首次合成${GameM.commonData.trerasureOpenLevel}级武将解锁`) } break; } } } clickGet() { if (this.tab == 0) { this.Get() } else if (this.tab == 1) { UiM.Instance.checkDelayShow(() => { UiM.Instance.rewardNode.EnterTaskPanel(this); }) } } // update (dt) {} AdGet() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.tab == 0) { GameM.commonData.roleData.activeNum += this.data.rewadr_num GameM.commonData.updateRoleData() EffectNode.instance.PlayCoinAnim(5, this.data.rewadr_num, cc.v2(0, 0)); // GameM.commonData.updateRedMoney(this.data.rewadr_num + 300, RecordTYPE.dailytask) } else { GameM.commonData.updateRedMoney(this.data.rewadr_num + 300, RecordTYPE.achievement) EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300)); } GameM.audioM.playEffect(AUDIO_TYPE.getGold, false) if (this.tab == 0) { GameM.commonData.updateDailyGetData(this.type); let times = GameM.commonData.getDailyGetData(this.type) let arr = GameM.commonData.taskCft[this.type.toString()] //下一个日常 if (times < arr.length) { this.init(0, this.type, arr[times], true) } else { //此类型日常都完成了 this.btnGet.active = false this.btnNo.active = false this.isGeted = true; } GameM.commonData.dailyTaskRedNum-- } else if (this.tab == 1) { GameM.commonData.updateAchieveGetData(this.type) let times = GameM.commonData.getAchieveGetData(this.type) let arr = GameM.commonData.achieveCft[this.type.toString()] //下一个成就 if (times < arr.length) { this.init(1, this.type, arr[times], true) } else { //此类型成就都完成了 this.btnGet.active = false this.btnNo.active = false this.isGeted = true; } GameM.commonData.achieveTaskRedNum-- } GameM.commonData.taskRedNum-- UiM.Instance.hallNode.getComponent(Main).checkTaskRed() // this.node.setSiblingIndex(this.node.parent.childrenCount - 1); this.updateSibling() } Get() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.tab == 0) { // GameM.commonData.roleData.activeNum += this.data.rewadr_num // GameM.commonData.updateRoleData() // EffectNode.instance.PlayCoinAnim(5, this.data.rewadr_num, cc.v2(0, 0)); RichData.Ins.UpdateItemCard(this.data.rewadr_num, 0, 0, 0, 0, 0, 0, () => { if (UiM.Instance.taskNode) { UiM.Instance.taskNode.getComponent(Task).PlayDiceEft(); } UiM.Instance.hallNode.getComponent(Main).UpdateRichManQipao(); }); // GameM.commonData.updateRedMoney(this.data.rewadr_num, RecordTYPE.dailytask) } else { GameM.commonData.updateRedMoney(this.data.rewadr_num, RecordTYPE.achievement) EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300)); } GameM.audioM.playEffect(AUDIO_TYPE.getGold, false) if (this.tab == 0) { GameM.commonData.updateDailyGetData(this.type); let times = GameM.commonData.getDailyGetData(this.type) let arr = GameM.commonData.taskCft[this.type.toString()] //下一个日常 if (times < arr.length) { this.init(0, this.type, arr[times], true) } else { //此类型日常都完成了 this.btnGet.active = false this.btnNo.active = false this.isGeted = true; } GameM.commonData.dailyTaskRedNum-- } else if (this.tab == 1) { GameM.commonData.updateAchieveGetData(this.type) let times = GameM.commonData.getAchieveGetData(this.type) let arr = GameM.commonData.achieveCft[this.type.toString()] //下一个成就 if (times < arr.length) { this.init(1, this.type, arr[times], true) } else { //此类型成就都完成了 this.btnGet.active = false this.btnNo.active = false this.isGeted = true; } GameM.commonData.achieveTaskRedNum-- } GameM.commonData.taskRedNum-- UiM.Instance.hallNode.getComponent(Main).checkTaskRed() this.updateSibling() } }