Treasure.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 { MONEY_TYPE } from "../datas/CommonData";
  8. import TreasureData from "../datas/TreasureData";
  9. import AdM from "../manager/AdM";
  10. import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM";
  11. import GuideMng from "../manager/GuideMng";
  12. import UiM, { PANEL_NAME } from "../manager/UiM";
  13. import TreaRecordItem from "../prefabs/TreaRecordItem";
  14. import TreasureItem from "../prefabs/TreasureItem";
  15. import { PlayerPrefs } from "../tools/MyExtends";
  16. import LogUtil from "../utils/LogUtil";
  17. import Sciencen_M from "../utils/Sciencen_M";
  18. import { Utils } from "../utils/Utils";
  19. import EffectNode from "./EffectNode";
  20. import Gift from "./Gift";
  21. import Guide from "./Guide";
  22. import RedCodeNode from "./RedCodeNode";
  23. const { ccclass, property } = cc._decorator;
  24. @ccclass
  25. export default class Treasure extends cc.Component {
  26. @property(cc.Label)
  27. labGetGold: cc.Label = null;
  28. @property(cc.Label)
  29. labTicket: cc.Label = null;
  30. @property(cc.Label)
  31. labLeftTimes: cc.Label = null;
  32. @property(cc.Node)
  33. scNode: cc.Node = null;
  34. @property(cc.Node)
  35. viewNode: cc.Node = null;
  36. @property(cc.Node)
  37. content: cc.Node = null;
  38. //--弹窗
  39. @property(cc.Node)
  40. resultPart: cc.Node = null;
  41. @property(cc.Label)
  42. labIssue: cc.Label = null;
  43. @property(cc.Label)
  44. labAwardMoney: cc.Label = null;
  45. @property(cc.Label)
  46. labNickName: cc.Label = null;
  47. @property(cc.Node)
  48. btnState: cc.Node = null;
  49. @property(cc.Label)
  50. labState: cc.Label = null;
  51. @property(cc.Sprite)
  52. spHead: cc.Sprite = null;
  53. @property(cc.Node)
  54. spFail: cc.Node = null;
  55. @property(cc.Node)
  56. spSuccess: cc.Node = null;
  57. //提现成功
  58. @property(cc.Node)
  59. loadPart: cc.Node = null;
  60. @property(cc.Animation)
  61. loadAni: cc.Animation = null;
  62. @property(cc.Node)
  63. cashPro: cc.Node = null;
  64. @property(cc.Label)
  65. labMoney1: cc.Label = null;
  66. //--记录
  67. @property(cc.Label)
  68. labRTitle: cc.Label = null;
  69. @property(cc.Node)
  70. recordPart: cc.Node = null;
  71. @property(cc.Node)
  72. recordContent: cc.Node = null;
  73. //--帮助
  74. @property(cc.Node)
  75. helpPart: cc.Node = null;
  76. @property(cc.Label)
  77. labTimes: cc.Label = null;
  78. @property(cc.RichText)
  79. LabScroll: cc.RichText = null
  80. @property(cc.Node)
  81. qipaoOne: cc.Node = null
  82. @property(cc.Node)
  83. qipaoSec: cc.Node = null
  84. @property(cc.Node)
  85. rewardBgNode: cc.Node = null
  86. @property(cc.Node)
  87. guideRect1: cc.Node = null;
  88. //当前弹窗状态 0 参加下一期 1 提现 2 过期
  89. curResultState = 0
  90. roledata = null
  91. cfg = null
  92. //分帧加载
  93. addNum = 0
  94. addTotal = 0
  95. //刷新现金夺宝间隔
  96. treasureDis = 0
  97. _n = 0
  98. _dis = 5
  99. itemP = null
  100. //看视频获得金币数量
  101. private getGoldNum: string = ''
  102. //开奖记录
  103. recordList = []
  104. private reAddNum = 0
  105. private reAddTotal = 0
  106. _ren = 0
  107. _redis = 5
  108. reItemP = null
  109. curLotteryResult = null
  110. private addY = 0
  111. private lastTicket = 0
  112. //获奖信息滚动播出,每次进夺宝,随机取一个档位的获奖记录显示
  113. private recordScroll: Array<any> = null
  114. //滚动信息下标
  115. count = 0
  116. //滚动信息的获奖金额
  117. scrollAmount = 0
  118. // LIFE-CYCLE CALLBACKS:
  119. async onLoad() {
  120. this.node.height = cc.winSize.height
  121. this.addY = cc.winSize.height - 1334
  122. this.itemP = await Utils.loadResPromise('prefabs/TreasureItem')
  123. this.reItemP = await Utils.loadResPromise('prefabs/TreaRecordItem')
  124. this.roledata = GameM.commonData.roleData
  125. this.schedule(this.updateOpenTime, 3)
  126. if (!TreasureData.Instance.treasureData) {
  127. TreasureData.Instance.getTreasureData()
  128. }
  129. else {
  130. this.onGetTreasureData()
  131. }
  132. this.getPopResult()
  133. this.scNode.height += this.addY
  134. this.viewNode.height += this.addY
  135. LogUtil.logV("TreasureData.Instance.treasureDailyTimes zero", TreasureData.Instance.treasureDailyTimes)
  136. this.freshLimitLab()
  137. TreasureData.Instance.getDailyLimit()
  138. this.rewardBgNode.y += this.addY / 2
  139. }
  140. onDisable() {
  141. this.unschedule(this.updateOpenTime)
  142. }
  143. /** */
  144. onEnable() {
  145. // let guide = UiM.Instance.guideNode.getComponent(Guide);
  146. // if (guide.treasureStep1.active) {
  147. // guide.hideTreasureStep1();
  148. // }
  149. //西游 夺宝引导 第一次进入夺宝界面
  150. this.scheduleOnce(() => {
  151. GuideMng.Ins.CheckTreasureGuide13();
  152. this.guideRect1.active = GuideMng.Ins.CurGuideId == 13;
  153. }, 0.1);
  154. }
  155. updateOpenTime() {
  156. TreasureData.Instance.treasureOpenTime += 3
  157. }
  158. /** 获取服务器数据返回
  159. * 数据 name 开奖名字
  160. * phase 开奖期数
  161. * joinManInfoQueue 参加者队列
  162. * limitMan 个人参加次数
  163. * joinTimes 个人参加次数
  164. * joinTotal 参加总人数
  165. */
  166. onGetTreasureData() {
  167. this.cfg = TreasureData.Instance.treasureCfg
  168. this.addTotal = TreasureData.Instance.treasureData.length
  169. this.addNum = 0
  170. this.lastTicket = GameM.commonData.roleData.ticket
  171. this.refreshLabs()
  172. // this.checkTreasureTimer()
  173. this.getShowScrollReward()
  174. }
  175. /** 单条数据 */
  176. freshTreasureDataOne(hasOpen, data) {
  177. let item = this.content.getChildByName(data.drawid)
  178. item.getComponent(TreasureItem).onFreshServerData(hasOpen, data)
  179. }
  180. start() {
  181. LogUtil.logV("Treasure", " start ")
  182. }
  183. update() {
  184. if (this.addNum < this.addTotal) {
  185. if (this._n <= this._dis) {
  186. this._n++
  187. }
  188. else {
  189. this._n = 0
  190. let item: cc.Node = cc.instantiate(this.itemP)
  191. let curCfg = this.cfg[this.addNum]
  192. item.name = (curCfg.drawid).toString()
  193. let s = item.getComponent(TreasureItem)
  194. s.init(curCfg)
  195. this.content.addChild(item)
  196. // this.content.height = this.addTotal * (item.height + 10)
  197. this.addNum++
  198. }
  199. }
  200. if (this.recordPart.active) {
  201. if (this.reAddNum < this.reAddTotal) {
  202. if (this._ren <= this._redis) {
  203. this._ren++
  204. }
  205. else {
  206. this._ren = 0
  207. let item: cc.Node = cc.instantiate(this.reItemP)
  208. let s = item.getComponent(TreaRecordItem)
  209. s.init(this.recordList[this.reAddNum])
  210. this.recordContent.addChild(item)
  211. // this.content.height = this.addTotal * (item.height + 10)
  212. this.reAddNum++
  213. }
  214. }
  215. }
  216. }
  217. refreshLabs() {
  218. this.labTimes.string = `5、每人每天最多只能参加${GameM.commonData.globalCfg.treasureDailylimit}次现金夺宝`
  219. this.labTicket.string = this.roledata.ticket.toString()
  220. let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
  221. let percent = 0.1
  222. this.getGoldNum = Sciencen_M.instance.accMul(videoPrice, percent.toString())
  223. let str = Sciencen_M.instance.format(this.getGoldNum)
  224. this.labGetGold.string = str //`<color=#ffffff>观看视频必得</c><color=#F2FF1C>${str}</color><color=#ffffff>金币奖励,并额外赠送夺宝券</c>`
  225. }
  226. // /** 刷新为index的item */
  227. // refreshItem(index) {
  228. // let item = this.content.getChildByName(index.toString())
  229. // if (item) {
  230. // let s = item.getComponent(TreasureItem)
  231. // s.refresh()
  232. // }
  233. // }
  234. // /** 检查是否更新现金夺宝消息 */
  235. // checkTreasureTimer() {
  236. // if (GameM.commonData.roleData.treasureDayNum != [] || UiM.Instance.treasureNode) {
  237. // this.treasureDis = 0
  238. // this.startTreasureTimer()
  239. // }
  240. // else {
  241. // this.unschedule(this.freshTreasure)
  242. // }
  243. // }
  244. // /** 刷新夺宝时间 */
  245. // startTreasureTimer() {
  246. // this.schedule(this.freshTreasure, 10)
  247. // }
  248. // freshTreasure() {
  249. // this.treasureDis++
  250. // if (GameM.commonData.roleData.treasureDayNum != []) {
  251. // }
  252. // if (UiM.Instance.treasureNode) {
  253. // //刷新界面
  254. // }
  255. // }
  256. clickGetTicket() {
  257. GameM.audioM.playEffect(AUDIO_TYPE.button)
  258. this.showVideoTip()
  259. // this.showVideoTip()
  260. // if (GameM.commonData.isVideoTest) {
  261. // this.onGetTicketAdEnd()
  262. // }
  263. // else {
  264. // GameM.adM.watchVideo(VIDEO_TYPE.getTicket)
  265. // }
  266. }
  267. showVideoTip() {
  268. // this.videoTip.active= true
  269. // if (GameM.commonData.isVideoTest) {
  270. // this.onGetTicketAdEnd()
  271. // }
  272. // else {
  273. // GameM.adM.watchVideo(VIDEO_TYPE.getTicket)
  274. UiM.Instance.giftNode.active = true
  275. let gift = UiM.Instance.giftNode.getComponent(Gift)
  276. gift.init(MONEY_TYPE.treasureTicket, this.getGoldNum)
  277. // }
  278. }
  279. watchVideo() {
  280. if (GameM.commonData.isVideoTest) {
  281. this.onGetTicketAdEnd()
  282. }
  283. else {
  284. GameM.adM.watchVideo(VIDEO_TYPE.getTicket)
  285. }
  286. }
  287. freshVideo() {
  288. this.content.children.forEach(element => {
  289. let s = element.getComponent(TreasureItem)
  290. s.freshVideo()
  291. });
  292. }
  293. onGetTicketAdEnd() {
  294. LogUtil.logV(" onGetTicketAdEndt", "start")
  295. // this.roledata.ticket++
  296. GameM.commonData.updateRoleData()
  297. if (this.lastTicket == 0) {
  298. this.freshVideo()
  299. }
  300. this.lastTicket = this.roledata.ticket
  301. // GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  302. // EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300))
  303. let str = Sciencen_M.instance.format(this.getGoldNum)
  304. this.refreshLabs()
  305. }
  306. clickClose() {
  307. GameM.audioM.playEffect(AUDIO_TYPE.button)
  308. this.content.destroyAllChildren()
  309. UiM.Instance.offPanel(PANEL_NAME.TreasureNode, false, () => {
  310. AdM.createInter(17)
  311. })
  312. }
  313. freshLimitLab() {
  314. let leftTimes = GameM.commonData.globalCfg.treasureDailylimit - TreasureData.Instance.treasureDailyTimes
  315. if (leftTimes < 0) {
  316. leftTimes = 0
  317. }
  318. this.labLeftTimes.string = `今日剩余夺宝次数:${leftTimes}`
  319. }
  320. //-----resultPart
  321. /** 界面打开获取弹出数组 */
  322. getPopResult() {
  323. TreasureData.Instance.getLotteryresults()
  324. }
  325. /** 显示开奖结果界面
  326. */
  327. showResult() {
  328. this.curLotteryResult = TreasureData.Instance.getCurLotteryresult()
  329. if (this.curLotteryResult) {
  330. this.resultPart.active = true
  331. cc.loader.load(this.curLotteryResult.headimgurl + "?aaa=aa.jpg", (err, res) => {
  332. if (err) {
  333. console.log('err:', err);
  334. return;
  335. }
  336. let tex: cc.Texture2D = res as cc.Texture2D;
  337. this.spHead.spriteFrame = new cc.SpriteFrame(tex);
  338. })
  339. this.labIssue.string = `现金夺宝第${this.curLotteryResult.phase}期`
  340. let money = this.curLotteryResult.amount / 100
  341. this.labAwardMoney.string = `¥${money.toFixed(2)}`
  342. this.labNickName.string = `${this.curLotteryResult.nikeName}`
  343. if (!this.curLotteryResult.isWin) {
  344. this.labState.string = '参加下一期'
  345. this.btnState.active = true
  346. this.curResultState = 0
  347. this.spFail.active = false
  348. this.spSuccess.active = false
  349. //发送消息弹过窗了
  350. this.curLotteryResult.isNotice = true
  351. TreasureData.Instance.updateLottery(this.curLotteryResult.recordId)
  352. }
  353. else {
  354. if (GameM.commonData.gameTime * 0.001 < this.curLotteryResult.outTime) {
  355. this.labState.string = '提现'
  356. this.btnState.active = true
  357. this.curResultState = 1
  358. this.spFail.active = false
  359. this.spSuccess.active = true
  360. }
  361. else {
  362. this.spFail.active = true
  363. this.spSuccess.active = false
  364. this.btnState.active = false
  365. this.curResultState = 2
  366. //发送消息弹过窗了
  367. this.curLotteryResult.isNotice = true
  368. TreasureData.Instance.updateLottery(this.curLotteryResult.recordId)
  369. }
  370. }
  371. }
  372. }
  373. /** 下一个开奖结果 */
  374. nextResult() {
  375. this.resultPart.active = false
  376. this.scheduleOnce(() => {
  377. //检查是否有下一个数据
  378. this.showResult()
  379. }, 1)
  380. }
  381. clickCloseResult() {
  382. GameM.audioM.playEffect(AUDIO_TYPE.button)
  383. this.resultPart.active = false
  384. this.nextResult()
  385. }
  386. clickBtnState() {
  387. GameM.audioM.playEffect(AUDIO_TYPE.button)
  388. if (this.curResultState == 0) {
  389. this.nextResult()
  390. }
  391. else if (this.curResultState == 1) {
  392. //调用提现接口
  393. let money = this.curLotteryResult.amount / 100
  394. TreasureData.Instance.luckycash(this.curLotteryResult.recordId, money)
  395. this.loadPart.active = true
  396. this.loadAni.play('load', 0)
  397. }
  398. }
  399. resultLuckycash(showPro) {
  400. //发送消息弹过窗了
  401. this.curLotteryResult.isNotice = true
  402. TreasureData.Instance.updateLottery(this.curLotteryResult.recordId)
  403. this.scheduleOnce(() => {
  404. this.loadPart.active = false
  405. this.showCashPro(showPro)
  406. }, 1.5)
  407. }
  408. tixianFail() {
  409. this.scheduleOnce(() => {
  410. this.loadPart.active = false
  411. this.nextResult()
  412. }, 1.5)
  413. }
  414. showCashPro(showPro) {
  415. if (showPro) {
  416. UiM.Instance.openPanel(this.cashPro)
  417. }
  418. let money = this.curLotteryResult.amount / 100
  419. this.labMoney1.string = `¥${money.toFixed(2)}`
  420. }
  421. clickClosePro() {
  422. GameM.audioM.playEffect(AUDIO_TYPE.button)
  423. UiM.Instance.closePanelM()
  424. this.nextResult()
  425. }
  426. //------recordPart
  427. showRecord(id, amount) {
  428. TreasureData.Instance.getLuckyLottery(id)
  429. this.labRTitle.string = `${(amount / 100).toFixed(2)}元开奖记录`
  430. }
  431. onShowRecord(data) {
  432. this.recordPart.active = true
  433. this.recordList = data
  434. this.reAddTotal = this.recordList.length
  435. this.reAddNum = 0
  436. }
  437. getShowScrollReward() {
  438. LogUtil.logV("getShowScrollReward", "start")
  439. // let tempArr = new Array<any>()
  440. // for (let i = 0; i < this.cfg.length; i++) {
  441. // if (this.cfg[i].amount >= 50) {
  442. // tempArr.push(this.cfg[i])
  443. // }
  444. // }
  445. // LogUtil.logV("getShowScrollReward", "one")
  446. // tempArr = tempArr.sort((a, b) => {
  447. // return Math.random() - 0.5
  448. // })
  449. // LogUtil.logV("getShowScrollReward", "two")
  450. // let tempInfo = tempArr[0]
  451. // this.scrollAmount = tempInfo.amount
  452. // LogUtil.logV("getShowScrollReward", tempInfo.drawid)
  453. TreasureData.Instance.getRandomLottery()
  454. }
  455. showScrollInfo(data) {
  456. LogUtil.logV("showScrollInfo", "one")
  457. this.recordScroll = data
  458. this.startScrollInfo()
  459. }
  460. startScrollInfo() {
  461. LogUtil.logV("startScrollInfo", "one")
  462. if (this.recordScroll == null || this.recordScroll == undefined || this.recordScroll.length == 0) {
  463. LogUtil.logV("startScrollInfo", "null")
  464. return
  465. }
  466. LogUtil.logV("startScrollInfo", this.recordScroll.length + "two")
  467. if (this.count == this.recordScroll.length - 1) {
  468. this.count = 0
  469. } else {
  470. this.count++
  471. }
  472. let info = this.recordScroll[this.count]
  473. let name = info.nickname
  474. let money = info.amount / 100
  475. let str = `恭喜 “<color=#D0AEFF><u>${name}</u></c>” 获得 “<color=#F05512><u>${money.toFixed(2)}</u></color>” 元`
  476. this.LabScroll.string = str
  477. this.LabScroll.node.position = cc.v3(0, -55)
  478. this.LabScroll.node.runAction(cc.sequence(cc.moveTo(0.3, cc.v2(0, 0)), cc.delayTime(2), cc.moveTo(0.3, cc.v2(0, 55)), cc.callFunc(() => {
  479. this.startScrollInfo()
  480. })))
  481. }
  482. clickCloseRecord() {
  483. GameM.audioM.playEffect(AUDIO_TYPE.button)
  484. this.recordPart.active = false
  485. this.recordContent.removeAllChildren()
  486. }
  487. //------helpPart
  488. clickOpenHelp() {
  489. GameM.audioM.playEffect(AUDIO_TYPE.button)
  490. this.helpPart.active = true
  491. }
  492. clickCloseHelp() {
  493. GameM.audioM.playEffect(AUDIO_TYPE.button)
  494. this.helpPart.active = false
  495. }
  496. clickIconShowTipOne() {
  497. this.qipaoOne.active = true
  498. this.scheduleOnce(() => {
  499. if (cc.isValid(this.qipaoOne)) {
  500. this.qipaoOne.active = false
  501. }
  502. }, 2)
  503. }
  504. clickIconShowTipSec() {
  505. this.qipaoSec.active = true
  506. this.scheduleOnce(() => {
  507. if (cc.isValid(this.qipaoSec)) {
  508. this.qipaoSec.active = false
  509. }
  510. }, 2)
  511. }
  512. clickRedCode() {
  513. GameM.audioM.playEffect(AUDIO_TYPE.button)
  514. UiM.Instance.onPanel(PANEL_NAME.RedCodeNode, false, () => {
  515. UiM.Instance.redCodeNode.getComponent(RedCodeNode).init(3)
  516. })
  517. }
  518. //西游 隐藏guideRect按钮
  519. Click_GuideRectBtn() {
  520. this.guideRect1.active = false;
  521. }
  522. }