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