MainScene.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /** @format */
  2. import {Data, GameControl, Mgr} from '../GameControl'
  3. import {BaseUI} from './BaseUI'
  4. import {ACTIVITY_TYPE, APP_TYPE, DIS_ID, EVENT, GOODS, GOODS_TYPE, LANGUAGE_TYPE, LOCAL} from '../enums/Enum'
  5. import {Log} from '../utils/LogUtils'
  6. import {ccUtils} from '../utils/ccUtils'
  7. import {UI} from '../enums/UI'
  8. import {msgCmd} from '../proto/msg_cmd'
  9. import {
  10. activityGetConfListRsp,
  11. activityTimeListNty,
  12. adventureDataRsp,
  13. boxGetAwardRsp,
  14. altarBattleRsp,
  15. altarDataRsp,
  16. cityDataSend,
  17. debrisGetDataRsp,
  18. embattleBattleRsp,
  19. embattleGetDataRsp,
  20. equipGetDataRsp,
  21. equipOnekeyUpgradeStarRsp,
  22. equipResetRsp,
  23. equipUpgradeRsp,
  24. equipUpgradeStarRsp,
  25. firstRechargeAwardRsp,
  26. firstRechargeDataRsp,
  27. firstRechargeNty,
  28. heroChangeNty,
  29. heroGetDataRsp,
  30. heroOnekeyUpgradeStarRsp,
  31. heroResetRsp,
  32. heroUpgradeRsp,
  33. heroUpgradeStarRsp,
  34. heroWearEquipRsp,
  35. login,
  36. loginRsp,
  37. manualGetDataRsp,
  38. payCurrency,
  39. payDebrisNty,
  40. rewardInfo,
  41. skillCardGetDataRsp,
  42. skillCardUpgradeRsp,
  43. skillCardUpgradeStarRsp,
  44. talentGetDataRsp,
  45. user,
  46. popGiftNty,
  47. popGiftChangeNty,
  48. popGiftDataRsp,
  49. relicDataNty,
  50. simpleMail,
  51. sendMail,
  52. createOrderNty,
  53. onlineAwardNty,
  54. cityDataRsp,
  55. } from '../proto/game'
  56. import {action} from 'mobx'
  57. import {activityTimeInfo, card, equip, hero, idNum} from '../proto/typedef'
  58. import {TalentConfig} from '../config/TalentConfig'
  59. import {GoodsConfig} from '../config/GoodsConfig'
  60. import {IRewardNty} from '../interface/UIInterface'
  61. import {ICard, IEquip, IRole, ICardDebris, ITimeGift} from '../interface/GlobalInterface'
  62. import {RanksLevelConfig} from '../config/RanksLevelConfig'
  63. import UserGuide from '../userguide/UserGuide'
  64. import value = cc.js.value
  65. import {LimitgiftConfig} from '../config/LimitgiftConfig'
  66. import KEY = cc.macro.KEY
  67. import {DataConfig} from '../config/DataConfig'
  68. import {CardSkillConfig} from '../config/CardSkillConfig'
  69. import {CastleSkillConfig} from '../config/CastleSkillConfig'
  70. import {HttpUrl} from '../data/HttpUrl'
  71. /** @format */
  72. const {ccclass, property} = cc._decorator
  73. @ccclass
  74. export default class MainScene extends BaseUI {
  75. async onLoad() {
  76. //屏蔽多点触摸 (屏蔽后setSwallowTouches无法吞噬)
  77. //cc.macro.ENABLE_MULTI_TOUCH = false
  78. //关闭FPS
  79. cc.debug.setDisplayStats(false)
  80. //开启动态合图
  81. cc.macro.CLEANUP_IMAGE_CACHE = false
  82. cc.dynamicAtlasManager.enabled = true
  83. cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE)
  84. await this.startGame()
  85. }
  86. async startGame() {
  87. HttpUrl.init()
  88. let isInit = await GameControl.init()
  89. if (!isInit) {
  90. Log.error('游戏初始化失败')
  91. return
  92. }
  93. Mgr.platform.hideSplash()
  94. let assets: cc.JsonAsset = await this.loadSync(cc.resources, 'version', cc.JsonAsset)
  95. let appType = assets?.json.appType
  96. Mgr.event.add(EVENT.webSocketOpen, this, () => {
  97. Data.main.webSocketCon = true
  98. Mgr.ui.hideLoading()
  99. //Mgr.ui.tip(LANGUAGE_TYPE.serverConnect)
  100. //游戏内断线重连
  101. if (Data.user.account && !Mgr.ui.getUI(UI.LoginUI)) {
  102. let loginReq = login.create()
  103. loginReq.sid = 1
  104. loginReq.account = Data.user.account
  105. Mgr.net.send(msgCmd.cmd_login, loginReq)
  106. }
  107. })
  108. Mgr.event.add(EVENT.webSocketClose, this, () => {
  109. Data.main.webSocketCon = false
  110. if (!Mgr.ui.getUI(UI.LoadingUI)) Mgr.ui.showLoading(LANGUAGE_TYPE.connectServer, false, false)
  111. //Mgr.ui.tip(LANGUAGE_TYPE.serverCut)
  112. })
  113. this.registerNetEvent()
  114. Data.main.texBundle = await ccUtils.getBundleAsync('texture')
  115. //加载所有角色spine
  116. Data.main.texBundle.loadDir('Public/role/spine', sp.SkeletonData, (error, assets: sp.SkeletonData[]) => {
  117. if (error) {
  118. Log.error(error)
  119. } else {
  120. let guideSp
  121. for (let i = 0; i < assets.length; i++) {
  122. Data.main.roleSpineMap.set(assets[i].name, assets[i])
  123. if (assets[i].name == 'yuelunche') guideSp = assets[i]
  124. assets[i]['_ref'] = Infinity
  125. }
  126. //初始新手引导
  127. let userGuideNode = cc.find('userguide', this.node)
  128. userGuideNode.zIndex = 9999
  129. Mgr.global.userGuideCom = userGuideNode.getComponent(UserGuide)
  130. Mgr.global.userGuideCom.init(guideSp, Data.main.texBundle)
  131. Mgr.ui.show(UI.LoginUI)
  132. }
  133. })
  134. }
  135. @action
  136. registerNetEvent() {
  137. Mgr.net.addTop(msgCmd.cmd_login_rsp, this, (data: loginRsp) => {
  138. if (Data.main.payData.length > 0) {
  139. for (let payObj of Data.main.payData) {
  140. Mgr.net.send(msgCmd.cmd_recharge_result, payObj)
  141. }
  142. Data.main.payData.length = 0
  143. }
  144. })
  145. Mgr.net.addTop(msgCmd.cmd_user, this, (data: user) => {
  146. Data.user.uid = data.uid
  147. Data.user.nickname = data.nickname
  148. Data.user.level = data.level
  149. Data.user.exp = data.exp
  150. Data.user.avatar = data.avatar
  151. Data.user.renameTime = data.renameTime
  152. Data.user.createTime = data.createtime
  153. for (let idNum of data.currency) {
  154. Mgr.goods.setGoodsNum(idNum.id, idNum.num)
  155. this.addReadyBox(idNum)
  156. }
  157. Data.main.loginTime = data.svrtime
  158. Data.main.serverTime = data.svrtime
  159. //开始全局时间计时器
  160. Data.main.globalTime = 0
  161. Data.main.secondTime = 0
  162. Data.main.minutesTime = 0
  163. Mgr.time.globalTimer()
  164. console.log(Date.Format('当前服务器时间:MM/dd/yyyy hh:mm:ss', data.svrtime))
  165. Mgr.storage.init(data.uid, '1')
  166. Mgr.time.initLoginDate(data.svrtime)
  167. })
  168. Mgr.net.addTop(msgCmd.cmd_pay_currency, this, (data: payCurrency) => {
  169. for (let idNum of data.now) {
  170. Mgr.event.trigger(EVENT.goodsChangeSync, idNum.id, idNum.num - Mgr.goods.getGoodsNum(idNum.id))
  171. Mgr.goods.setGoodsNum(idNum.id, idNum.num)
  172. }
  173. })
  174. Mgr.net.addTop(msgCmd.cmd_reward_info, this, (data: rewardInfo) => {
  175. let changeArr: idNum[] = []
  176. let syncArr: idNum[] = []
  177. let iRoles: IRole[] = []
  178. let iCards: ICard[] = []
  179. let iEquips: IEquip[] = []
  180. let debrisArr: idNum[] = []
  181. for (let idNum of data.added.currency) {
  182. let dur = idNum.num - Mgr.goods.getGoodsNum(idNum.id)
  183. if (dur > 0) {
  184. changeArr.push({id: idNum.id, num: dur})
  185. } else {
  186. syncArr.push({id: idNum.id, num: dur})
  187. }
  188. Mgr.goods.setGoodsNum(idNum.id, idNum.num)
  189. //处理队伍经验
  190. if (idNum.id == GOODS.exp) {
  191. Data.user.exp = idNum.num
  192. let cfg = RanksLevelConfig[Data.user.level]
  193. if (cfg && idNum.num >= cfg.exp) {
  194. Data.user.exp = cfg.exp
  195. }
  196. }
  197. this.addReadyBox(idNum, false)
  198. }
  199. for (let hero of data.added.heroes) {
  200. let role = Mgr.global.buildIRole(hero)
  201. Data.user.roles.push(role)
  202. iRoles.push(role)
  203. }
  204. if (data.added.heroes.length > 0) {
  205. Mgr.goods.sortRole()
  206. Mgr.goods.reactRolesChange()
  207. }
  208. for (let card of data.added.skillCard) {
  209. let iCard = Mgr.global.buildICard(card)
  210. Data.user.cards.push(iCard)
  211. iCards.push(iCard)
  212. }
  213. if (data.added.skillCard.length > 0) {
  214. Mgr.goods.sortCard()
  215. Mgr.goods.reactCardsChange()
  216. }
  217. for (let equip of data.added.equip) {
  218. let iEquip = Mgr.global.buildIEquip(equip)
  219. Data.user.equips.push(iEquip)
  220. iEquips.push(iEquip)
  221. }
  222. if (data.added.equip.length > 0) {
  223. Mgr.goods.sortEquip()
  224. Mgr.goods.reactEquipsChange()
  225. }
  226. for (let debris of data.added.debris) {
  227. let has = Data.user.cardDebris.find(item => item.id == debris.id)
  228. let changeDur = debris.num - (has ? has.num : 0)
  229. let cardDebris = Mgr.global.buildICardDebris(debris, has)
  230. if (!has) Data.user.cardDebris.push(cardDebris)
  231. debrisArr.push({id: debris.id, num: changeDur})
  232. }
  233. let rewardNty: IRewardNty = {
  234. changeArr,
  235. iRoles,
  236. iCards,
  237. iEquips,
  238. debrisArr,
  239. }
  240. syncArr.forEach(v => Mgr.event.trigger(EVENT.goodsChangeSync, v.id, v.num))
  241. //recharge_money 是需要花钱买的 shop_buy是用钻石买的或者是看广告获得的 服务端区分了用法
  242. if (data.flags == 'recharge_money' || data.flags == 'shop_buy') {
  243. Mgr.ui.showReward(rewardNty)
  244. } else {
  245. Data.main.rewardNtyMap.set('cmd_' + data.flags + '_rsp', rewardNty)
  246. }
  247. })
  248. //-------------------------------建筑数据-----------------------------------------
  249. Mgr.net.addTop(msgCmd.cmd_city_data_rsp, this, (data: cityDataRsp) => {
  250. Data.main.buildData = data.list
  251. //城堡技能
  252. Data.user.castleSkills = []
  253. Data.user.useCastleSkillID = data.skillid
  254. for (let i = 0; i < data.skillList.length; i++) {
  255. let iCastleSkill = Mgr.global.buildICastleSkill(data.skillList[i])
  256. Data.user.castleSkills.push(iCastleSkill)
  257. }
  258. })
  259. //-------------------------------装备数据-----------------------------------------
  260. //先获取装备背包,再获取英雄背包
  261. Mgr.net.addTop(msgCmd.cmd_equip_get_data_rsp, this, (data: equipGetDataRsp) => {
  262. Data.user.equips.length = 0
  263. data.list.forEach(equip => {
  264. Data.user.equips.push(Mgr.global.buildIEquip(equip))
  265. })
  266. Mgr.goods.sortEquip()
  267. Mgr.goods.reactEquipsChange()
  268. })
  269. let updateEquip = (equip: equip) => {
  270. Data.user.equips.forEach(v => {
  271. if (equip.sid == v.equip.sid) {
  272. Mgr.global.buildIEquip(equip, v)
  273. }
  274. })
  275. Mgr.goods.reactEquipsChange()
  276. }
  277. Mgr.net.addTop(msgCmd.cmd_equip_upgrade_rsp, this, (data: equipUpgradeRsp) => {
  278. updateEquip(data.data)
  279. })
  280. Mgr.net.addTop(msgCmd.cmd_equip_upgrade_star_rsp, this, (data: equipUpgradeStarRsp) => {
  281. for (let i = Data.user.equips.length - 1; i >= 0; i--) {
  282. let sid = Data.user.equips[i].equip.sid
  283. if (data.same.includes(sid) || data.other.includes(sid)) {
  284. Data.user.equips.splice(i, 1)
  285. }
  286. if (sid == data.data.sid) {
  287. Mgr.global.buildIEquip(data.data, Data.user.equips[i])
  288. }
  289. }
  290. Mgr.goods.reactEquipsChange()
  291. })
  292. Mgr.net.addTop(msgCmd.cmd_equip_onekey_upgrade_star_rsp, this, (data: equipOnekeyUpgradeStarRsp) => {
  293. for (let i = Data.user.equips.length - 1; i >= 0; i--) {
  294. if (data.delList.includes(Data.user.equips[i].equip.sid)) {
  295. Data.user.equips.splice(i, 1)
  296. }
  297. }
  298. for (let i = Data.user.equips.length - 1; i >= 0; i--) {
  299. let find = data.changeList.find(value => value.sid == Data.user.equips[i].equip.sid)
  300. if (find) {
  301. Mgr.global.buildIEquip(find, Data.user.equips[i])
  302. }
  303. }
  304. Mgr.goods.reactEquipsChange()
  305. })
  306. Mgr.net.addTop(msgCmd.cmd_equip_reset_rsp, this, (data: equipResetRsp) => {
  307. updateEquip(data.data)
  308. })
  309. Mgr.net.addTop(msgCmd.cmd_hero_wear_equip_rsp, this, (data: heroWearEquipRsp) => {
  310. let equips = new Array(Data.main.equipMaxNum).fill(null)
  311. Data.user.equips.find(value => {
  312. if (data.list.includes(value.equip.sid)) {
  313. value.equip.hero = data.data.sid
  314. equips[value.cfg.type - 1] = value
  315. } else if (value.equip.hero == data.data.sid) {
  316. value.equip.hero = ''
  317. }
  318. })
  319. Data.user.roles.find(value => {
  320. if (value.hero.sid == data.data.sid) {
  321. value.equips.length = 0
  322. value.equips.push(...equips)
  323. }
  324. })
  325. Mgr.goods.reactEquipsChange()
  326. })
  327. //-------------------------------英雄数据-----------------------------------------
  328. Mgr.net.addTop(msgCmd.cmd_hero_get_data_rsp, this, (data: heroGetDataRsp) => {
  329. Data.user.roles.length = 0
  330. data.list.forEach(hero => {
  331. Data.user.roles.push(Mgr.global.buildIRole(hero))
  332. })
  333. Mgr.goods.sortRole()
  334. Mgr.goods.reactRolesChange()
  335. })
  336. let updateRole = (data: hero) => {
  337. Data.user.roles.forEach(v => {
  338. if (data.sid == v.hero.sid) {
  339. Mgr.global.buildIRole(data, v)
  340. }
  341. })
  342. Mgr.goods.reactRolesChange()
  343. }
  344. Mgr.net.addTop(msgCmd.cmd_hero_upgrade_rsp, this, (data: heroUpgradeRsp) => {
  345. updateRole(data.data)
  346. })
  347. Mgr.net.addTop(msgCmd.cmd_hero_upgrade_star_rsp, this, (data: heroUpgradeStarRsp) => {
  348. for (let i = Data.user.roles.length - 1; i >= 0; i--) {
  349. let sid = Data.user.roles[i].hero.sid
  350. if (data.same.includes(sid) || data.other.includes(sid)) {
  351. Data.user.roles.splice(i, 1)
  352. }
  353. if (sid == data.data.sid) {
  354. Mgr.global.buildIRole(data.data, Data.user.roles[i])
  355. }
  356. }
  357. Mgr.goods.reactRolesChange()
  358. })
  359. Mgr.net.addTop(msgCmd.cmd_hero_onekey_upgrade_star_rsp, this, (data: heroOnekeyUpgradeStarRsp) => {
  360. for (let i = Data.user.roles.length - 1; i >= 0; i--) {
  361. if (data.delList.includes(Data.user.roles[i].hero.sid)) {
  362. Data.user.roles.splice(i, 1)
  363. }
  364. }
  365. for (let i = Data.user.roles.length - 1; i >= 0; i--) {
  366. let findHero = data.changeList.find(value => value.sid == Data.user.roles[i].hero.sid)
  367. if (findHero) {
  368. Mgr.global.buildIRole(findHero, Data.user.roles[i])
  369. }
  370. }
  371. Mgr.goods.reactRolesChange()
  372. })
  373. Mgr.net.addTop(msgCmd.cmd_hero_reset_rsp, this, (data: heroResetRsp) => {
  374. updateRole(data.data)
  375. })
  376. Mgr.net.addTop(msgCmd.cmd_hero_change_nty, this, (data: heroChangeNty) => {
  377. for (let i = 0; i < data.list.length; i++) {
  378. updateRole(data.list[i])
  379. }
  380. })
  381. //-------------------------------卡牌数据-----------------------------------------
  382. Mgr.net.addTop(msgCmd.cmd_skill_card_get_data_rsp, this, (data: skillCardGetDataRsp) => {
  383. Data.user.cards.length = 0
  384. data.list.forEach(card => {
  385. Data.user.cards.push(Mgr.global.buildICard(card))
  386. })
  387. Mgr.goods.sortCard()
  388. Mgr.goods.reactCardsChange()
  389. })
  390. let updateCard = (card: card) => {
  391. Data.user.cards.find(value => {
  392. if (value.card.sid == card.sid) {
  393. Mgr.global.buildICard(card, value)
  394. }
  395. })
  396. Mgr.goods.reactCardsChange()
  397. }
  398. Mgr.net.addTop(msgCmd.cmd_skill_card_upgrade_rsp, this, (data: skillCardUpgradeRsp) => {
  399. updateCard(data.data)
  400. })
  401. Mgr.net.addTop(msgCmd.cmd_skill_card_upgrade_star_rsp, this, (data: skillCardUpgradeStarRsp) => {
  402. updateCard(data.data)
  403. })
  404. //-------------------------------上阵数据-----------------------------------------
  405. let updateTeam = (data: embattleBattleRsp | embattleGetDataRsp) => {
  406. Data.user.teamRole.length = 0
  407. Data.user.teamCard.length = 0
  408. data.list.forEach(item => {
  409. if (item.sid) {
  410. Data.user.teamRole.push(Data.user.roles.find(hero => hero.hero.sid == item.sid))
  411. } else {
  412. Data.user.teamRole.push(null)
  413. }
  414. })
  415. data.cardList.forEach(item => {
  416. if (item.sid) {
  417. Data.user.teamCard.push(Data.user.cards.find(card => card.card.sid == item.sid))
  418. } else {
  419. Data.user.teamCard.push(null)
  420. }
  421. })
  422. Mgr.goods.reactRolesChange()
  423. Mgr.goods.reactCardsChange()
  424. }
  425. Mgr.net.addTop(msgCmd.cmd_embattle_get_data_rsp, this, (data: embattleBattleRsp) => {
  426. updateTeam(data)
  427. })
  428. Mgr.net.addTop(msgCmd.cmd_embattle_battle_rsp, this, (data: embattleBattleRsp) => {
  429. updateTeam(data)
  430. })
  431. //-------------------------------碎片数据-----------------------------------------
  432. Mgr.net.addTop(msgCmd.cmd_debris_get_data_rsp, this, (data: debrisGetDataRsp) => {
  433. Data.user.cardDebris.length = 0
  434. data.list.forEach(cardDebris => {
  435. Data.user.cardDebris.push(Mgr.global.buildICardDebris(cardDebris))
  436. })
  437. })
  438. Mgr.net.addTop(msgCmd.cmd_pay_debris_nty, this, (data: payDebrisNty) => {
  439. for (let i = Data.user.cardDebris.length - 1; i >= 0; i--) {
  440. let find = data.list.find(idNum => idNum.id == Data.user.cardDebris[i].id)
  441. if (find) {
  442. if (find.num == 0) {
  443. Data.user.cardDebris.splice(i, 1)
  444. } else {
  445. Data.user.cardDebris[i].num = find.num
  446. }
  447. }
  448. }
  449. })
  450. //-------------------------------天赋-----------------------------------------
  451. Mgr.net.addTop(msgCmd.cmd_talent_get_data_rsp, this, (data: talentGetDataRsp) => {
  452. Data.user.talents.length = 0
  453. let keys = Object.keys(TalentConfig)
  454. for (let i = 0; i < keys.length; i++) {
  455. let ID = TalentConfig[keys[i]].ID
  456. let type = TalentConfig[keys[i]].talentType
  457. if (data.id1 > 0 && ID <= data.id1 && type == 1) {
  458. Data.user.talents.push(ID)
  459. }
  460. if (data.id2 > 0 && ID <= data.id2 && type == 2) {
  461. Data.user.talents.push(ID)
  462. }
  463. }
  464. Mgr.global.initTalentAdd()
  465. })
  466. //-------------------------------冒险关卡-----------------------------------------
  467. Mgr.net.addTop(msgCmd.cmd_adventure_data_rsp, this, (data: adventureDataRsp) => {
  468. Data.user.adventureId = data.id1
  469. Data.user.eliteId = data.id2
  470. })
  471. //-------------------------------活动列表-----------------------------------------
  472. Mgr.net.addTop(msgCmd.cmd_activity_time_list_nty, this, (data: activityTimeListNty) => {
  473. data.list.forEach(activity => {
  474. Data.main.activityList.set(activity.type, activity)
  475. })
  476. })
  477. //-------------------------------祭坛-----------------------------------------
  478. Mgr.net.addTop(msgCmd.cmd_altar_data_rsp, this, (data: altarDataRsp) => {
  479. Data.user.altarInfoList = data.list
  480. Data.user.altarTopFive = data.baseList
  481. Data.user.roles.forEach(v => {
  482. updateRole(v.hero)
  483. })
  484. })
  485. Mgr.net.addTop(msgCmd.cmd_altar_battle_rsp, this, (data: altarBattleRsp) => {
  486. //祭坛上下阵刷新
  487. Data.user.altarInfoList[data.pos - 1] = data.data
  488. Data.user.roles.forEach(v => {
  489. updateRole(v.hero)
  490. })
  491. })
  492. //-------------------------------限时礼包/弹窗礼包-----------------------------------------
  493. Mgr.net.addTop(msgCmd.cmd_pop_gift_data_rsp, this, (data: popGiftDataRsp) => {
  494. let giftData: ITimeGift[] = data.list.sort((a, b) => a.time - b.time)
  495. for (let i = 0; i < Data.main.timeGifts.length; i++) {
  496. giftData[i].isPop = Data.main.timeGifts[i].isPop
  497. }
  498. Data.main.timeGifts = giftData
  499. })
  500. Mgr.net.addTop(msgCmd.cmd_pop_gift_nty, this, (data: popGiftNty) => {
  501. //弹窗礼包推送
  502. Data.main.timeGifts.push(data.data)
  503. Data.main.timeGifts.sort((a, b) => a.time - b.time)
  504. })
  505. Mgr.net.addTop(msgCmd.cmd_pop_gift_change_nty, this, (data: popGiftChangeNty) => {
  506. //刷新礼包数据
  507. let index = Data.main.timeGifts.findIndex(value => value.id == data.data.id)
  508. if (index >= 0) {
  509. let gift = Data.main.timeGifts[index]
  510. if (data.data.num >= LimitgiftConfig[gift.id].limit) {
  511. Data.main.timeGifts.splice(index, 1)
  512. } else {
  513. gift.num = data.data.num
  514. }
  515. }
  516. })
  517. //-------------------------------开宝箱-----------------------------------------
  518. Mgr.net.add(msgCmd.cmd_box_get_award_rsp, this, (data: boxGetAwardRsp, rewardNty: IRewardNty) => {
  519. //判断宝箱类型,防止OpenBoxUI也会执行showReward
  520. if (data.type == GOODS_TYPE.randomBox) Mgr.ui.showReward(rewardNty)
  521. })
  522. //-------------------------------遗迹-----------------------------------------
  523. Mgr.net.addTop(msgCmd.cmd_relic_data_nty, this, (data: relicDataNty) => {
  524. Data.main.relicData = data
  525. })
  526. //-------------------------------邮箱-----------------------------------------
  527. Mgr.net.addTop(msgCmd.cmd_simple_mail, this, (data: simpleMail) => {
  528. Data.main.emailRed = data.needread + data.noread > 0
  529. })
  530. Mgr.net.addTop(msgCmd.cmd_send_mail, this, (data: sendMail) => {
  531. Data.main.emailRed = true
  532. })
  533. //-------------------------------创建订单-----------------------------------------
  534. Mgr.net.addTop(msgCmd.cmd_create_order_nty, this, (data: createOrderNty) => {
  535. Mgr.ui.showLoading('', false)
  536. Mgr.platform.buyItem(data.cfid.toString(), data.id.toString())
  537. })
  538. //-------------------------------在线时长-----------------------------------------
  539. Mgr.net.addTop(msgCmd.cmd_online_award_nty, this, (data: onlineAwardNty) => {
  540. Data.main.onlineRewards = data
  541. })
  542. }
  543. addReadyBox(idNum: idNum, isOnlySelect: boolean = true) {
  544. let isBox =
  545. GoodsConfig[idNum.id].type == GOODS_TYPE.selectBox || GoodsConfig[idNum.id].type == GOODS_TYPE.randomBox
  546. if (isBox) {
  547. for (let i = 0; i < idNum.num; i++) {
  548. Data.user.readyOpenBox.push({id: idNum.id, num: 1})
  549. }
  550. }
  551. }
  552. }