UsualCaidanData.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /** 常规彩蛋数据类 */
  2. import Main from "../Main"
  3. import AdM from "../manager/AdM"
  4. import GameM from "../manager/GameM"
  5. import UiM, { PANEL_NAME } from "../manager/UiM"
  6. import CashPro from "../ui/CashPro"
  7. import EffectNode from "../ui/EffectNode"
  8. import UsualCaidanNode from "../ui/UsualCaidanNode"
  9. import LogUtil from "../utils/LogUtil"
  10. import { CFG_SERVER, HTTP_TYPE } from "./CommonData"
  11. export default class UsualCaidanData {
  12. /** 常规彩蛋配置数据 */
  13. UsualEggTaskCfg = null
  14. /** 常规彩蛋进行中任务配置 */
  15. curUsualEggTask = null
  16. /** 点击冷却 */
  17. cool = false
  18. /** 当前完成index */
  19. curCompleteIndex = 0
  20. /** 常规蛋数据 */
  21. userUsualEggInfo = {
  22. 'index': 1,
  23. 'progress': 0,
  24. 'isEnd': 0, //是否完结 0.未完结 1.已完结
  25. 'isOpen': 1, //是否开启 0.未开启 1.已开启
  26. 'videoTimes': 0, //视频次数
  27. 'isTodayFinished': 0 //今日完结 0.未完结 1.已完结
  28. }
  29. private static instance: UsualCaidanData = null
  30. static get Instance(): UsualCaidanData {
  31. if (!this.instance) {
  32. this.instance = new UsualCaidanData()
  33. }
  34. return this.instance
  35. }
  36. /** 获取彩蛋数据
  37. * @param showGuide 是否引导
  38. * @param request 是否请求
  39. */
  40. getUsualEggData(request) {
  41. LogUtil.logV('UsualCaidan ', "getUsualEggData")
  42. if (GameM.commonData.redSwitch) {
  43. if (request) {
  44. let data = {}
  45. LogUtil.logV('UsualCaidan ', "getUsualEggData 111")
  46. GameM.httpM.sendDatas(HTTP_TYPE.openUsualEggData, data, UsualCaidanData.Instance.onUsualGetEggData.bind(this))
  47. }
  48. else {
  49. if (this.userUsualEggInfo) {
  50. if (this.userUsualEggInfo.isEnd == 0 && this.userUsualEggInfo.isOpen == 1) {
  51. // this.checkHasUsualEggTaskCfg()
  52. UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
  53. }
  54. else {
  55. UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
  56. LogUtil.logV('UsualCaidan ', "彩蛋消失1 ")
  57. }
  58. }
  59. }
  60. }
  61. }
  62. /** 是否显示引导小手 */
  63. checkShowHand() {
  64. if (this.userUsualEggInfo && this.userUsualEggInfo.isEnd == 0 && this.userUsualEggInfo.isOpen == 1) {
  65. if (this.userUsualEggInfo.progress == this.userUsualEggInfo.videoTimes) {
  66. UiM.Instance.hallNode.getComponent(Main).caidanHand.active = true
  67. }
  68. }
  69. }
  70. /** 彩蛋数据返回 */
  71. onUsualGetEggData(data) {
  72. LogUtil.logV('UsualCaidan onUsualGetEggData ', data.userUsualEggInfo)
  73. if (data && data.userUsualEggInfo && data.userUsualEggInfo.isEnd == 0 && data.userUsualEggInfo.isOpen == 1) {
  74. this.userUsualEggInfo = data.userUsualEggInfo
  75. // this.checkHasUsualEggTaskCfg()
  76. UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
  77. }
  78. else {
  79. UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
  80. LogUtil.logV('UsualCaidan ', "彩蛋消失2 ")
  81. }
  82. }
  83. // /** 获取彩蛋配置返回 */
  84. // setUsualEggTaskCfg(data: string) {
  85. // let jsonObj = JSON.parse(data)
  86. // this.UsualEggTaskCfg = jsonObj
  87. // LogUtil.logV('UsualCaidan setUsualEggTaskCfg ', this.UsualEggTaskCfg)
  88. // this.setCurUsualEggTaskCfg(this.userUsualEggInfo.index)
  89. // UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
  90. // }
  91. // /** 是否有配置 */
  92. // checkHasUsualEggTaskCfg() {
  93. // if (this.UsualEggTaskCfg) {
  94. // this.setCurUsualEggTaskCfg(this.userUsualEggInfo.index)
  95. // UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
  96. // }
  97. // else {
  98. // //获取彩蛋配置
  99. // GameM.commonData.getSingleCfg(CFG_SERVER.UsualEggTaskCfg)
  100. // }
  101. // }
  102. // /** 设置当前彩蛋配置
  103. // * @param index 彩蛋类型
  104. // */
  105. // setCurUsualEggTaskCfg(index: number) {
  106. // this.curUsualEggTask = this.getUsualEggTaskByIndex(index)
  107. // }
  108. // /** 根据彩蛋类型获取配置
  109. // * @param index 彩蛋index
  110. // */
  111. // getUsualEggTaskByIndex(index: number) {
  112. // let cfg = null
  113. // for (const item of this.UsualEggTaskCfg) {
  114. // if (item.index == index) {
  115. // cfg = item
  116. // break
  117. // }
  118. // }
  119. // return cfg
  120. // }
  121. // /** 完成任务 */
  122. // completeUsualEggTask() {
  123. // this.curCompleteIndex = this.userUsualEggInfo.index
  124. // let data = {
  125. // "index": this.userUsualEggInfo.index
  126. // }
  127. // GameM.httpM.sendDatas(HTTP_TYPE.completeUsualEggTask, data)
  128. // }
  129. // onCompleteUsualEggTask(data) {
  130. // if (UiM.Instance.usualCaidanNode) {
  131. // UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).completeAward(this.curCompleteIndex)
  132. // }
  133. // this.freshUserUsualEggInfo(data.userUsualEggInfo)
  134. // }
  135. /** 提现 */
  136. usualeggCash() {
  137. if (this.cool) {
  138. return
  139. }
  140. this.cool = true
  141. let data = {
  142. "index": this.userUsualEggInfo.index,
  143. "appVersion": GameM.commonData.appVersion
  144. }
  145. GameM.httpM.sendDatas(HTTP_TYPE.usualEggsTaskCash, data, UsualCaidanData.Instance.tixianSuccess.bind(this), UsualCaidanData.Instance.tixianFail.bind(this))
  146. UiM.Instance.cashProNode.getComponent(CashPro).showLoad()
  147. }
  148. /** 提现成功 */
  149. tixianSuccess(data) {
  150. this.setDot('usualCaidanEnd')
  151. AdM.setTAEventUser(1, 'eggCashTime_total', 1)
  152. AdM.setTAEventUser(1, 'eggCashMoney_total', data.money)
  153. AdM.onSendEvent(`caidanCash_${this.userUsualEggInfo.index}`, `第${this.userUsualEggInfo.index}个常规彩蛋提现成功`, 'caidanCash')
  154. setTimeout(() => {
  155. this.cool = false
  156. UiM.Instance.cashProNode.getComponent(CashPro).tixianSuccess(true, data.money)
  157. this.freshUserUsualEggInfo(data.userUsualEggInfo)
  158. }, 1500)
  159. }
  160. /** 提现失败 */
  161. tixianFail(errmsg) {
  162. this.cool = false
  163. EffectNode.instance.PlayTip(errmsg)
  164. if (UiM.Instance.cashProNode) {
  165. UiM.Instance.cashProNode.getComponent(CashPro).tixianFail()
  166. }
  167. }
  168. /** 刷新彩蛋信息 */
  169. freshUserUsualEggInfo(data) {
  170. this.userUsualEggInfo = data
  171. LogUtil.logV('freshUserUsualEggInfo ', this.userUsualEggInfo)
  172. // if (this.userUsualEggInfo.isTodayFinished == 1) {
  173. // EffectNode.instance.PlayTip('今日已完成,明日再来')
  174. // }
  175. if (this.userUsualEggInfo) {
  176. if (UiM.Instance.usualCaidanNode) {
  177. UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
  178. }
  179. }
  180. else {
  181. UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
  182. LogUtil.logV('UsualCaidan ', "彩蛋消失3 ")
  183. }
  184. }
  185. /** 更新常规彩蛋进度
  186. * @param type 增加进度类型
  187. */
  188. addUsualProgress(type, add = true, value = 0) {
  189. if (!this.userUsualEggInfo || this.userUsualEggInfo.isEnd == 1 || this.userUsualEggInfo.isOpen == 0 || this.userUsualEggInfo.isTodayFinished == 1) {
  190. return
  191. }
  192. // let taskType = this.getUsualEggTaskByIndex(this.userUsualEggInfo.index).taskType
  193. // if (type == taskType) {
  194. if (add) {
  195. this.userUsualEggInfo.progress++
  196. }
  197. else {
  198. this.userUsualEggInfo.progress = value
  199. }
  200. let data = {
  201. "userUsualEggInfo": this.userUsualEggInfo
  202. }
  203. this.checkShowHand()
  204. GameM.httpM.sendDatas(HTTP_TYPE.updateUsualEggData, data)
  205. // }
  206. }
  207. getUsualEggCashMoney() {
  208. let data = {
  209. "index": this.userUsualEggInfo.index
  210. }
  211. LogUtil.logV('getUsualEggCashMoney ', this.userUsualEggInfo.index)
  212. GameM.httpM.sendDatas(HTTP_TYPE.getUsualEggCashMoney, data, UsualCaidanData.Instance.getUsualEggCashMoneyBack.bind(this))
  213. }
  214. getUsualEggCashMoneyBack(data) {
  215. LogUtil.logV('getUsualEggCashMoneyBack ', data.money)
  216. if (UiM.Instance.cashProNode) {
  217. UiM.Instance.cashProNode.getComponent(CashPro).labRedMoney.string = `¥${(data.money * 0.01).toFixed(2)}`
  218. }
  219. }
  220. /** 打点 每个打点只触发一次*/
  221. setDot(des: string) {
  222. let eventID = ''
  223. let eventDes = ''
  224. let event = ''
  225. let hasDot = ''
  226. if (des == 'usualCaidanStart') {
  227. eventID = `caidan_normal_open${this.userUsualEggInfo.index}`
  228. eventDes = `常规彩蛋第${this.userUsualEggInfo.index}个开启`
  229. event = GameM.commonData.uin + eventID
  230. hasDot = GameM.globalStorage.getStorage(event)
  231. if (hasDot == null) {
  232. GameM.globalStorage.setStorage(event, 1)
  233. AdM.onSendEvent(eventID, eventDes, 'caidan_normal_open')
  234. }
  235. }
  236. else if (des == 'usualCaidanEnd') {
  237. eventID = `caidan_normal_reward${this.userUsualEggInfo.index}`
  238. eventDes = `常规彩蛋第${this.userUsualEggInfo.index}个奖励领取`
  239. event = GameM.commonData.uin + eventID
  240. hasDot = GameM.globalStorage.getStorage(event)
  241. if (hasDot == null) {
  242. GameM.globalStorage.setStorage(event, 1)
  243. AdM.onSendEvent(eventID, eventDes, 'caidan_normal_reward')
  244. }
  245. }
  246. }
  247. }