| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /** 常规彩蛋数据类 */
- import Main from "../Main"
- import AdM from "../manager/AdM"
- import GameM from "../manager/GameM"
- import UiM, { PANEL_NAME } from "../manager/UiM"
- import CashPro from "../ui/CashPro"
- import EffectNode from "../ui/EffectNode"
- import UsualCaidanNode from "../ui/UsualCaidanNode"
- import LogUtil from "../utils/LogUtil"
- import { CFG_SERVER, HTTP_TYPE } from "./CommonData"
- export default class UsualCaidanData {
- /** 常规彩蛋配置数据 */
- UsualEggTaskCfg = null
- /** 常规彩蛋进行中任务配置 */
- curUsualEggTask = null
- /** 点击冷却 */
- cool = false
- /** 当前完成index */
- curCompleteIndex = 0
- /** 常规蛋数据 */
- userUsualEggInfo = {
- 'index': 1,
- 'progress': 0,
- 'isEnd': 0, //是否完结 0.未完结 1.已完结
- 'isOpen': 1, //是否开启 0.未开启 1.已开启
- 'videoTimes': 0, //视频次数
- 'isTodayFinished': 0 //今日完结 0.未完结 1.已完结
- }
- private static instance: UsualCaidanData = null
- static get Instance(): UsualCaidanData {
- if (!this.instance) {
- this.instance = new UsualCaidanData()
- }
- return this.instance
- }
- /** 获取彩蛋数据
- * @param showGuide 是否引导
- * @param request 是否请求
- */
- getUsualEggData(request) {
- LogUtil.logV('UsualCaidan ', "getUsualEggData")
- if (GameM.commonData.redSwitch) {
- if (request) {
- let data = {}
- LogUtil.logV('UsualCaidan ', "getUsualEggData 111")
- GameM.httpM.sendDatas(HTTP_TYPE.openUsualEggData, data, UsualCaidanData.Instance.onUsualGetEggData.bind(this))
- }
- else {
- if (this.userUsualEggInfo) {
- if (this.userUsualEggInfo.isEnd == 0 && this.userUsualEggInfo.isOpen == 1) {
- // this.checkHasUsualEggTaskCfg()
- UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
- }
- else {
- UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
- LogUtil.logV('UsualCaidan ', "彩蛋消失1 ")
- }
- }
- }
- }
- }
- /** 是否显示引导小手 */
- checkShowHand() {
- if (this.userUsualEggInfo && this.userUsualEggInfo.isEnd == 0 && this.userUsualEggInfo.isOpen == 1) {
- if (this.userUsualEggInfo.progress == this.userUsualEggInfo.videoTimes) {
- UiM.Instance.hallNode.getComponent(Main).caidanHand.active = true
- }
- }
- }
- /** 彩蛋数据返回 */
- onUsualGetEggData(data) {
- LogUtil.logV('UsualCaidan onUsualGetEggData ', data.userUsualEggInfo)
- if (data && data.userUsualEggInfo && data.userUsualEggInfo.isEnd == 0 && data.userUsualEggInfo.isOpen == 1) {
- this.userUsualEggInfo = data.userUsualEggInfo
- // this.checkHasUsualEggTaskCfg()
- UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
- }
- else {
- UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
- LogUtil.logV('UsualCaidan ', "彩蛋消失2 ")
- }
- }
- // /** 获取彩蛋配置返回 */
- // setUsualEggTaskCfg(data: string) {
- // let jsonObj = JSON.parse(data)
- // this.UsualEggTaskCfg = jsonObj
- // LogUtil.logV('UsualCaidan setUsualEggTaskCfg ', this.UsualEggTaskCfg)
- // this.setCurUsualEggTaskCfg(this.userUsualEggInfo.index)
- // UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
- // }
- // /** 是否有配置 */
- // checkHasUsualEggTaskCfg() {
- // if (this.UsualEggTaskCfg) {
- // this.setCurUsualEggTaskCfg(this.userUsualEggInfo.index)
- // UiM.Instance.hallNode.getComponent(Main).showCaidan(2)
- // }
- // else {
- // //获取彩蛋配置
- // GameM.commonData.getSingleCfg(CFG_SERVER.UsualEggTaskCfg)
- // }
- // }
- // /** 设置当前彩蛋配置
- // * @param index 彩蛋类型
- // */
- // setCurUsualEggTaskCfg(index: number) {
- // this.curUsualEggTask = this.getUsualEggTaskByIndex(index)
- // }
- // /** 根据彩蛋类型获取配置
- // * @param index 彩蛋index
- // */
- // getUsualEggTaskByIndex(index: number) {
- // let cfg = null
- // for (const item of this.UsualEggTaskCfg) {
- // if (item.index == index) {
- // cfg = item
- // break
- // }
- // }
- // return cfg
- // }
- // /** 完成任务 */
- // completeUsualEggTask() {
- // this.curCompleteIndex = this.userUsualEggInfo.index
- // let data = {
- // "index": this.userUsualEggInfo.index
- // }
- // GameM.httpM.sendDatas(HTTP_TYPE.completeUsualEggTask, data)
- // }
- // onCompleteUsualEggTask(data) {
- // if (UiM.Instance.usualCaidanNode) {
- // UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).completeAward(this.curCompleteIndex)
- // }
- // this.freshUserUsualEggInfo(data.userUsualEggInfo)
- // }
- /** 提现 */
- usualeggCash() {
- if (this.cool) {
- return
- }
- this.cool = true
- let data = {
- "index": this.userUsualEggInfo.index,
- "appVersion": GameM.commonData.appVersion
- }
- GameM.httpM.sendDatas(HTTP_TYPE.usualEggsTaskCash, data, UsualCaidanData.Instance.tixianSuccess.bind(this), UsualCaidanData.Instance.tixianFail.bind(this))
- UiM.Instance.cashProNode.getComponent(CashPro).showLoad()
- }
- /** 提现成功 */
- tixianSuccess(data) {
- this.setDot('usualCaidanEnd')
- AdM.setTAEventUser(1, 'eggCashTime_total', 1)
- AdM.setTAEventUser(1, 'eggCashMoney_total', data.money)
- AdM.onSendEvent(`caidanCash_${this.userUsualEggInfo.index}`, `第${this.userUsualEggInfo.index}个常规彩蛋提现成功`, 'caidanCash')
- setTimeout(() => {
- this.cool = false
- UiM.Instance.cashProNode.getComponent(CashPro).tixianSuccess(true, data.money)
- this.freshUserUsualEggInfo(data.userUsualEggInfo)
- }, 1500)
- }
- /** 提现失败 */
- tixianFail(errmsg) {
- this.cool = false
- EffectNode.instance.PlayTip(errmsg)
- if (UiM.Instance.cashProNode) {
- UiM.Instance.cashProNode.getComponent(CashPro).tixianFail()
- }
- }
- /** 刷新彩蛋信息 */
- freshUserUsualEggInfo(data) {
- this.userUsualEggInfo = data
- LogUtil.logV('freshUserUsualEggInfo ', this.userUsualEggInfo)
- // if (this.userUsualEggInfo.isTodayFinished == 1) {
- // EffectNode.instance.PlayTip('今日已完成,明日再来')
- // }
- if (this.userUsualEggInfo) {
- if (UiM.Instance.usualCaidanNode) {
- UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
- }
- }
- else {
- UiM.Instance.hallNode.getComponent(Main).caidanBtn.node.active = false
- LogUtil.logV('UsualCaidan ', "彩蛋消失3 ")
- }
- }
- /** 更新常规彩蛋进度
- * @param type 增加进度类型
- */
- addUsualProgress(type, add = true, value = 0) {
- if (!this.userUsualEggInfo || this.userUsualEggInfo.isEnd == 1 || this.userUsualEggInfo.isOpen == 0 || this.userUsualEggInfo.isTodayFinished == 1) {
- return
- }
- // let taskType = this.getUsualEggTaskByIndex(this.userUsualEggInfo.index).taskType
- // if (type == taskType) {
- if (add) {
- this.userUsualEggInfo.progress++
- }
- else {
- this.userUsualEggInfo.progress = value
- }
- let data = {
- "userUsualEggInfo": this.userUsualEggInfo
- }
- this.checkShowHand()
- GameM.httpM.sendDatas(HTTP_TYPE.updateUsualEggData, data)
- // }
- }
- getUsualEggCashMoney() {
- let data = {
- "index": this.userUsualEggInfo.index
- }
- LogUtil.logV('getUsualEggCashMoney ', this.userUsualEggInfo.index)
- GameM.httpM.sendDatas(HTTP_TYPE.getUsualEggCashMoney, data, UsualCaidanData.Instance.getUsualEggCashMoneyBack.bind(this))
- }
- getUsualEggCashMoneyBack(data) {
- LogUtil.logV('getUsualEggCashMoneyBack ', data.money)
- if (UiM.Instance.cashProNode) {
- UiM.Instance.cashProNode.getComponent(CashPro).labRedMoney.string = `¥${(data.money * 0.01).toFixed(2)}`
- }
- }
- /** 打点 每个打点只触发一次*/
- setDot(des: string) {
- let eventID = ''
- let eventDes = ''
- let event = ''
- let hasDot = ''
- if (des == 'usualCaidanStart') {
- eventID = `caidan_normal_open${this.userUsualEggInfo.index}`
- eventDes = `常规彩蛋第${this.userUsualEggInfo.index}个开启`
- event = GameM.commonData.uin + eventID
- hasDot = GameM.globalStorage.getStorage(event)
- if (hasDot == null) {
- GameM.globalStorage.setStorage(event, 1)
- AdM.onSendEvent(eventID, eventDes, 'caidan_normal_open')
- }
- }
- else if (des == 'usualCaidanEnd') {
- eventID = `caidan_normal_reward${this.userUsualEggInfo.index}`
- eventDes = `常规彩蛋第${this.userUsualEggInfo.index}个奖励领取`
- event = GameM.commonData.uin + eventID
- hasDot = GameM.globalStorage.getStorage(event)
- if (hasDot == null) {
- GameM.globalStorage.setStorage(event, 1)
- AdM.onSendEvent(eventID, eventDes, 'caidan_normal_reward')
- }
- }
- }
- }
|