TaskItem.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  8. import EffectNode from "../ui/EffectNode";
  9. import UiM, { PANEL_NAME } from "../manager/UiM";
  10. import Main from "../Main";
  11. import { RecordTYPE } from "../datas/CommonData";
  12. import { RichData } from "../datas/RichData";
  13. import Task from "../ui/Task";
  14. import AdM from "../manager/AdM";
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default class TaskItem extends cc.Component {
  18. @property(cc.Label)
  19. labDes: cc.Label = null;
  20. @property(cc.Sprite)
  21. pro: cc.Sprite = null;
  22. @property(cc.Label)
  23. proTxt: cc.Label = null;
  24. @property(cc.Label)
  25. labAward: cc.Label = null;
  26. @property(cc.Node)
  27. btnGet: cc.Node = null;
  28. @property(cc.Node)
  29. btnNo: cc.Node = null;
  30. @property(cc.Label)
  31. labGo: cc.Label = null;
  32. @property(cc.Node)
  33. btnGo: cc.Node = null;
  34. @property(cc.Node)
  35. activePart: cc.Node = null;
  36. @property(cc.Node)
  37. achievePart: cc.Node = null;
  38. @property(cc.Label)
  39. labAchieveAward: cc.Label = null;
  40. @property(cc.Node)
  41. iconGet: cc.Node = null;
  42. // LIFE-CYCLE CALLBACKS:
  43. // onLoad () {}
  44. /** 0 日常 1 成就 */
  45. private tab = 0
  46. public data = null
  47. /** 成就
  48. * 1:合成车辆地次数
  49. 2:解锁XX等级地新车
  50. 3:成功观看广告地次数
  51. 4:玩家等级达到XX级别
  52. 5: 小秘书亲密度
  53. 6: 投资次数
  54. 7:转盘次数
  55. 日常
  56. 1:观看广告
  57. 2:转盘
  58. 3:飞艇
  59. 4:投资次数
  60. 5:工厂点击次数
  61. 6:现金夺宝
  62. 7:看视频得金币
  63. */
  64. private type = 0
  65. isGeted: boolean = false; //是否已领取
  66. start() {
  67. }
  68. onEnable() {
  69. this.updateSibling()
  70. }
  71. /** 初始化
  72. * @param tab 0 日常 1 成就
  73. * @param type 类型
  74. * @param data 配合数据
  75. * @param effect 效果
  76. */
  77. init(tab: number, type: number, data, effect = false) {
  78. //console.log("cfg init:"+tab+" type:"+type+" data:"+data)
  79. this.tab = tab
  80. this.type = type
  81. this.data = data
  82. let str = ''
  83. let fill = 0
  84. let time = 0
  85. if (effect) {
  86. cc.tween(this.node)
  87. .to(0.2, { x: -1000 })
  88. .delay(0.1)
  89. .call(() => {
  90. this.node.x = 1000
  91. })
  92. .to(0.3, { x: 0 })
  93. .start()
  94. }
  95. let showGo = false
  96. if (tab == 0) {
  97. time = GameM.commonData.getDailyFinishTimesDataByType(this.type)
  98. if (time > this.data.condition) {
  99. time = this.data.condition
  100. }
  101. switch (this.type) {
  102. case 1:
  103. str = `观看广告${this.data.condition}次`
  104. fill = time / this.data.condition
  105. this.proTxt.string = time + "/" + this.data.condition
  106. showGo = false
  107. break;
  108. case 2:
  109. str = `转盘抽奖${this.data.condition}次`
  110. fill = time / this.data.condition
  111. this.proTxt.string = time + "/" + this.data.condition
  112. showGo = true
  113. break;
  114. case 3:
  115. str = `点击空投礼包${this.data.condition}次`
  116. fill = time / this.data.condition
  117. this.proTxt.string = time + "/" + this.data.condition
  118. showGo = false
  119. break;
  120. case 4:
  121. str = `探索${this.data.condition}次`
  122. fill = time / this.data.condition
  123. this.proTxt.string = time + "/" + this.data.condition
  124. showGo = true
  125. break;
  126. case 5:
  127. str = `点击武将${this.data.condition}次`
  128. fill = time / this.data.condition
  129. this.proTxt.string = time + "/" + this.data.condition
  130. showGo = false
  131. break;
  132. case 6:
  133. str = `现金夺宝${this.data.condition}次`
  134. fill = time / this.data.condition
  135. this.proTxt.string = time + "/" + this.data.condition
  136. showGo = true
  137. break;
  138. case 7:
  139. str = `看视频得金币${this.data.condition}次`
  140. fill = time / this.data.condition
  141. this.proTxt.string = time + "/" + this.data.condition
  142. showGo = false
  143. break;
  144. case 8:
  145. str = `参与财神降临${this.data.condition}次`
  146. fill = time / this.data.condition
  147. this.proTxt.string = time + "/" + this.data.condition
  148. showGo = false
  149. break;
  150. }
  151. this.activePart.active = true
  152. this.achievePart.active = false
  153. this.labAward.string = this.data.rewadr_num.toString()
  154. // this.labGo.string = des
  155. }
  156. else if (tab == 1) {
  157. switch (this.type) {
  158. case 1:
  159. str = `合成${this.data.condition}次武将`
  160. fill = GameM.commonData.composeCarTimes / this.data.condition
  161. this.proTxt.string = GameM.commonData.composeCarTimes + "/" + this.data.condition
  162. break;
  163. case 2:
  164. str = `解锁${this.data.condition}等级的新武将`
  165. fill = GameM.commonData.maxCarLevel / this.data.condition
  166. this.proTxt.string = GameM.commonData.maxCarLevel + "/" + this.data.condition
  167. break;
  168. case 3:
  169. str = `成功观看${this.data.condition}次广告`
  170. fill = GameM.commonData.videoTimes / this.data.condition
  171. this.proTxt.string = GameM.commonData.videoTimes + "/" + this.data.condition
  172. break;
  173. case 4:
  174. str = `玩家等级达到${this.data.condition}级`
  175. fill = GameM.commonData.roleData.lv / this.data.condition
  176. this.proTxt.string = GameM.commonData.roleData.lv + "/" + this.data.condition
  177. break;
  178. // case 5:
  179. // let num1 = GameM.commonData.SecretaryData.loveNum
  180. // let num2 = GameM.commonData.SecretaryDataSecond.loveNum
  181. // let num3 = GameM.commonData.SecretaryDataThird.loveNum
  182. // let num = Math.max(num1, num2, num3)
  183. // str = `小秘书亲密度达到${this.data.condition}点`
  184. // fill = num / this.data.condition
  185. // this.proTxt.string = num + "/" + this.data.condition
  186. // break;
  187. case 6:
  188. str = `投资达到${this.data.condition}次`
  189. fill = GameM.commonData.roleData.investTotal / this.data.condition
  190. this.proTxt.string = GameM.commonData.roleData.investTotal + "/" + this.data.condition
  191. break;
  192. case 7:
  193. str = `参加转盘抽奖${this.data.condition}次`
  194. fill = GameM.commonData.roleData.turntableTotal / this.data.condition
  195. this.proTxt.string = GameM.commonData.roleData.turntableTotal + "/" + this.data.condition
  196. break;
  197. }
  198. this.activePart.active = false
  199. this.achievePart.active = true
  200. this.labAchieveAward.string = this.data.rewadr_num.toString()
  201. }
  202. this.labDes.string = str
  203. this.pro.fillRange = fill
  204. if (fill >= 1) {
  205. if (tab == 0) {
  206. let times = GameM.commonData.getDailyGetData(this.type)
  207. let arr = GameM.commonData.taskCft[this.type.toString()]
  208. if (times < arr.length) {
  209. this.btnGet.active = true
  210. this.btnNo.active = false
  211. this.btnGo.active = false
  212. this.iconGet.active = false
  213. GameM.commonData.taskRedNum++
  214. GameM.commonData.dailyTaskRedNum++
  215. }
  216. else {
  217. this.btnGet.active = false
  218. this.btnNo.active = false
  219. this.btnGo.active = false
  220. this.isGeted = true
  221. this.iconGet.active = true
  222. }
  223. }
  224. else if (tab == 1) {
  225. GameM.commonData.taskRedNum++
  226. GameM.commonData.achieveTaskRedNum++
  227. this.btnGet.active = true
  228. this.btnNo.active = false
  229. this.btnGo.active = false
  230. this.iconGet.active = false
  231. }
  232. }
  233. else {
  234. this.btnGet.active = false
  235. if (showGo) {
  236. this.btnNo.active = false
  237. this.btnGo.active = true
  238. }
  239. else {
  240. this.btnNo.active = true
  241. this.btnGo.active = false
  242. }
  243. this.iconGet.active = false
  244. }
  245. }
  246. updateSibling() {
  247. if (this.isGeted) {
  248. this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
  249. this.iconGet.active = true
  250. }
  251. }
  252. clickNo() {
  253. GameM.audioM.playEffect(AUDIO_TYPE.button)
  254. if (this.tab == 0) {
  255. switch (this.type) {
  256. case 2:
  257. UiM.Instance.taskNode.active = false
  258. if (GameM.commonData.maxCarLevel >= GameM.commonData.turntableOpenLevel) {
  259. UiM.Instance.onPanel(PANEL_NAME.TurnTableNode)
  260. }
  261. else {
  262. EffectNode.instance.PlayTip(`首次合成${GameM.commonData.turntableOpenLevel}级武将解锁`)
  263. }
  264. break;
  265. case 4:
  266. UiM.Instance.taskNode.active = false
  267. if (GameM.commonData.maxCarLevel >= GameM.commonData.investOpenLevel) {
  268. UiM.Instance.onPanel(PANEL_NAME.InvestNode)
  269. }
  270. else {
  271. EffectNode.instance.PlayTip(`首次合成${GameM.commonData.investOpenLevel}级武将解锁`)
  272. }
  273. break;
  274. case 6:
  275. if (GameM.commonData.maxCarLevel >= GameM.commonData.trerasureOpenLevel) {
  276. if (GameM.commonData.isAuth) {
  277. UiM.Instance.taskNode.active = false
  278. UiM.Instance.onPanel(PANEL_NAME.TreasureNode)
  279. }
  280. else {
  281. AdM.WxLogin()
  282. }
  283. }
  284. else {
  285. EffectNode.instance.PlayTip(`首次合成${GameM.commonData.trerasureOpenLevel}级武将解锁`)
  286. }
  287. break;
  288. }
  289. }
  290. }
  291. clickGet() {
  292. if (this.tab == 0) {
  293. this.Get()
  294. }
  295. else if (this.tab == 1) {
  296. UiM.Instance.checkDelayShow(() => {
  297. UiM.Instance.rewardNode.EnterTaskPanel(this);
  298. })
  299. }
  300. }
  301. // update (dt) {}
  302. AdGet() {
  303. GameM.audioM.playEffect(AUDIO_TYPE.button)
  304. if (this.tab == 0) {
  305. GameM.commonData.roleData.activeNum += this.data.rewadr_num
  306. GameM.commonData.updateRoleData()
  307. EffectNode.instance.PlayCoinAnim(5, this.data.rewadr_num, cc.v2(0, 0));
  308. // GameM.commonData.updateRedMoney(this.data.rewadr_num + 300, RecordTYPE.dailytask)
  309. }
  310. else {
  311. GameM.commonData.updateRedMoney(this.data.rewadr_num + 300, RecordTYPE.achievement)
  312. EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
  313. }
  314. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  315. if (this.tab == 0) {
  316. GameM.commonData.updateDailyGetData(this.type);
  317. let times = GameM.commonData.getDailyGetData(this.type)
  318. let arr = GameM.commonData.taskCft[this.type.toString()]
  319. //下一个日常
  320. if (times < arr.length) {
  321. this.init(0, this.type, arr[times], true)
  322. }
  323. else {
  324. //此类型日常都完成了
  325. this.btnGet.active = false
  326. this.btnNo.active = false
  327. this.isGeted = true;
  328. }
  329. GameM.commonData.dailyTaskRedNum--
  330. }
  331. else if (this.tab == 1) {
  332. GameM.commonData.updateAchieveGetData(this.type)
  333. let times = GameM.commonData.getAchieveGetData(this.type)
  334. let arr = GameM.commonData.achieveCft[this.type.toString()]
  335. //下一个成就
  336. if (times < arr.length) {
  337. this.init(1, this.type, arr[times], true)
  338. }
  339. else {
  340. //此类型成就都完成了
  341. this.btnGet.active = false
  342. this.btnNo.active = false
  343. this.isGeted = true;
  344. }
  345. GameM.commonData.achieveTaskRedNum--
  346. }
  347. GameM.commonData.taskRedNum--
  348. UiM.Instance.hallNode.getComponent(Main).checkTaskRed()
  349. // this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
  350. this.updateSibling()
  351. }
  352. Get() {
  353. GameM.audioM.playEffect(AUDIO_TYPE.button)
  354. if (this.tab == 0) {
  355. // GameM.commonData.roleData.activeNum += this.data.rewadr_num
  356. // GameM.commonData.updateRoleData()
  357. // EffectNode.instance.PlayCoinAnim(5, this.data.rewadr_num, cc.v2(0, 0));
  358. RichData.Ins.UpdateItemCard(this.data.rewadr_num, 0, 0, 0, 0, 0, 0, () => {
  359. if (UiM.Instance.taskNode) {
  360. UiM.Instance.taskNode.getComponent(Task).PlayDiceEft();
  361. }
  362. UiM.Instance.hallNode.getComponent(Main).UpdateRichManQipao();
  363. });
  364. // GameM.commonData.updateRedMoney(this.data.rewadr_num, RecordTYPE.dailytask)
  365. }
  366. else {
  367. GameM.commonData.updateRedMoney(this.data.rewadr_num, RecordTYPE.achievement)
  368. EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
  369. }
  370. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  371. if (this.tab == 0) {
  372. GameM.commonData.updateDailyGetData(this.type);
  373. let times = GameM.commonData.getDailyGetData(this.type)
  374. let arr = GameM.commonData.taskCft[this.type.toString()]
  375. //下一个日常
  376. if (times < arr.length) {
  377. this.init(0, this.type, arr[times], true)
  378. }
  379. else {
  380. //此类型日常都完成了
  381. this.btnGet.active = false
  382. this.btnNo.active = false
  383. this.isGeted = true;
  384. }
  385. GameM.commonData.dailyTaskRedNum--
  386. }
  387. else if (this.tab == 1) {
  388. GameM.commonData.updateAchieveGetData(this.type)
  389. let times = GameM.commonData.getAchieveGetData(this.type)
  390. let arr = GameM.commonData.achieveCft[this.type.toString()]
  391. //下一个成就
  392. if (times < arr.length) {
  393. this.init(1, this.type, arr[times], true)
  394. }
  395. else {
  396. //此类型成就都完成了
  397. this.btnGet.active = false
  398. this.btnNo.active = false
  399. this.isGeted = true;
  400. }
  401. GameM.commonData.achieveTaskRedNum--
  402. }
  403. GameM.commonData.taskRedNum--
  404. UiM.Instance.hallNode.getComponent(Main).checkTaskRed()
  405. this.updateSibling()
  406. }
  407. }