EquipBreakUI.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import List, {SelectedType} from '../uiutils/List'
  9. import {ATTR_NAME, EQUIPMENT, LANGUAGE_TYPE, PROFESSION, QUALITY_COLOR, QUALITY_TYPE} from '../enums/Enum'
  10. import {i18nLabel} from '../uiutils/i18nLabel'
  11. import UserButton from '../uiutils/UserButton'
  12. import {equipOnekeyUpgradeStarRsp, equipUpgradeStar, equipUpgradeStarRsp, heroUpgradeStar} from '../proto/game'
  13. import {idNum} from '../proto/typedef'
  14. import {qualityGoods} from './RoleBreakUI'
  15. import {EquipmentQualityConfig, IEquipmentQualityConfig} from '../config/EquipmentQualityConfig'
  16. import {EntryConfig} from '../config/EntryConfig'
  17. import {RoleQualityConfig} from '../config/RoleQualityConfig'
  18. import {IRewardNty} from '../interface/UIInterface'
  19. import {IEquip} from '../interface/GlobalInterface'
  20. const {ccclass, property} = cc._decorator
  21. type equipGoods = IEquip | qualityGoods
  22. @ccclass
  23. @observer
  24. export class EquipBreakUI extends BaseUI {
  25. chooseEquip: IEquip = null
  26. equipAndGoodArr: equipGoods[]
  27. needArr: equipGoods[]
  28. @list('equipList')
  29. equipList: List
  30. @node('chooseType')
  31. chooseTypeNode: cc.Node
  32. chooseType: EQUIPMENT = EQUIPMENT.none
  33. equips: IEquip[] = []
  34. lastPower: number
  35. onShow(args, fromUI: number) {
  36. Mgr.net.add(msgCmd.cmd_equip_upgrade_star_rsp, this, this.onEquipStarRsp)
  37. Mgr.net.add(msgCmd.cmd_equip_onekey_upgrade_star_rsp, this, this.onEquipOneKeyStarRsp)
  38. this.onChooseEquipItemClick(null, '0')
  39. }
  40. onHide(): any {
  41. Mgr.event.removeAll(this)
  42. }
  43. clearEquip() {
  44. this.chooseEquip = null
  45. this.resetData()
  46. this.initNeedSlot()
  47. this.initUI()
  48. this.initOneKey()
  49. }
  50. resetData() {
  51. this.equipList.selectedMode = SelectedType.SINGLE
  52. this.equipList.selectedId = -1
  53. this.equipAndGoodArr = [...this.equips]
  54. let goodsIDArr: number[] = []
  55. let cfgArr: IEquipmentQualityConfig[] = []
  56. for (let ID in EquipmentQualityConfig) {
  57. let goodsIDs = EquipmentQualityConfig[ID].resetGoods
  58. for (let i = 0; i < goodsIDs.length; i++) {
  59. let goodsID = goodsIDs[i]
  60. if (goodsID && !goodsIDArr.includes(goodsID) && (this.chooseType == 0 || i == this.chooseType - 1)) {
  61. goodsIDArr.push(goodsID)
  62. cfgArr.push(EquipmentQualityConfig[ID])
  63. }
  64. }
  65. }
  66. for (let i = 0; i < goodsIDArr.length; i++) {
  67. let goodsID = goodsIDArr[i]
  68. if (goodsID > 0 && Mgr.goods.getGoodsNum(goodsID) > 0) {
  69. for (let j = 0; j < Mgr.goods.getGoodsNum(goodsID); j++) {
  70. this.equipAndGoodArr.push({
  71. id: goodsID,
  72. num: 1,
  73. quality: cfgArr[i].ID - 1,
  74. })
  75. }
  76. }
  77. }
  78. this.needArr = []
  79. }
  80. initUI() {
  81. cc.find('btn_auto', this.node).active = this.chooseEquip == null
  82. cc.find('btn_break', this.node).active = this.chooseEquip != null
  83. cc.find('joinTip', this.node).active = this.chooseEquip == null
  84. let breakTip = cc.find('breakTip', this.node)
  85. let curSlotEquipNode = cc.find('cur_slot/equip', this.node)
  86. curSlotEquipNode.active = false
  87. let nextSlotEquipNode = cc.find('next_slot/equip', this.node)
  88. nextSlotEquipNode.active = false
  89. let hasChoose = this.chooseEquip != null
  90. breakTip.active = hasChoose
  91. let rtTip = cc.find('tip_rt', this.node)
  92. ccUtils.setLabel(LANGUAGE_TYPE.autoBreakEquipTip, rtTip)
  93. cc.find('add_need', this.node).active = hasChoose
  94. cc.find('need', this.node).active = hasChoose
  95. if (this.chooseEquip) {
  96. let iEquip = this.chooseEquip
  97. this.lastPower = iEquip.power
  98. curSlotEquipNode.active = true
  99. let equip = ccUtils.deepCopy(iEquip.equip)
  100. equip.id += 1
  101. Mgr.global.initEquipItem(iEquip, curSlotEquipNode, this)
  102. let nextQualityIEquip = Mgr.global.buildIEquip(equip)
  103. nextSlotEquipNode.active = true
  104. Mgr.global.initEquipItem(nextQualityIEquip, nextSlotEquipNode, this)
  105. this.loadTexImg(`Public/role/streamer_${iEquip.cfg.qualityType + 1}`, breakTip, 'streamer')
  106. ccUtils.setLabel(iEquip.cfg.name, breakTip, 'equipName')
  107. let attrOrigin = cc.find('scrollView/view/content/attrs/attr', breakTip)
  108. let attrs = [
  109. iEquip.HP > 0
  110. ? ATTR_NAME.HP
  111. : iEquip.spellAttack > iEquip.attack
  112. ? ATTR_NAME.spellAttack
  113. : ATTR_NAME.attack,
  114. ]
  115. let allAttrs = ccUtils.instantChildren(attrOrigin, attrs.length + 1)
  116. //显示等级
  117. let lvNode = allAttrs[0]
  118. ccUtils.setLabel(LANGUAGE_TYPE.lvMax, lvNode, 'attrName')
  119. ccUtils.setLabel(EquipmentQualityConfig[iEquip.cfg.quality].maxLv.toString(), lvNode, 'attrNum')
  120. ccUtils.setLabel(EquipmentQualityConfig[nextQualityIEquip.cfg.quality].maxLv.toString(), lvNode, 'nextNum')
  121. for (let i = 0; i < attrs.length; i++) {
  122. let attr = attrs[i]
  123. let attrNode = allAttrs[i + 1]
  124. ccUtils.setLabel(LANGUAGE_TYPE[attr.toString()], attrNode, 'attrName')
  125. ccUtils.setLabel(iEquip[attr.toString()], attrNode, 'attrNum')
  126. ccUtils.setLabel(nextQualityIEquip[attr.toString()], attrNode, 'nextNum')
  127. }
  128. ccUtils.setRichLabel(
  129. Mgr.i18n.getEntryLabel(nextQualityIEquip.cfg.entry),
  130. breakTip,
  131. 'scrollView/view/content/rtL/rt',
  132. )
  133. ccUtils.setLabel(LANGUAGE_TYPE.needBreakTip, rtTip)
  134. let rtTipI18n = rtTip.getComponent(i18nLabel)
  135. let qCfg = EquipmentQualityConfig[iEquip.cfg.quality + 1]
  136. if (qCfg.anyQualityNum > 0) {
  137. this.equipList.maxMutSelected = qCfg.anyQualityNum
  138. rtTipI18n.setParamByIndex(qCfg.anyQualityNum.toString(), 0)
  139. rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.anyQuality]], 1)
  140. rtTipI18n.setParamByIndex(LANGUAGE_TYPE[QUALITY_TYPE[Data.user.qualityTypeArr[qCfg.anyQuality]]], 2)
  141. } else {
  142. this.equipList.maxMutSelected = qCfg.sameQualityNum
  143. rtTipI18n.setParamByIndex(qCfg.sameQualityNum.toString(), 0)
  144. rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.sameQuality]], 1)
  145. rtTipI18n.setParamByIndex(
  146. Mgr.i18n.getLabel(iEquip.cfg.name) +
  147. (iEquip.grade > 0 ? `(${iEquip.grade}${Mgr.i18n.getLabel(LANGUAGE_TYPE.star)})` : ''),
  148. 2,
  149. )
  150. }
  151. cc.find('need', this.node).children.forEach((value, index) => {
  152. value.active = index < this.equipList.maxMutSelected
  153. })
  154. }
  155. this.equipAndGoodArr.sort((a, b) => {
  156. if (this.chooseEquip) {
  157. let aNeed = 'cfg' in a ? this.equipCanBeNeed(a) : this.goodsCanBeNeed(a)
  158. let bNeed = 'cfg' in b ? this.equipCanBeNeed(b) : this.goodsCanBeNeed(b)
  159. return Number(bNeed) - Number(aNeed)
  160. }
  161. let aIndex = 'cfg' in a ? Data.user.teamRole.findIndex(v => v && v.hero.sid == a.equip.hero) : -1
  162. let bIndex = 'cfg' in b ? Data.user.teamRole.findIndex(v => v && v.hero.sid == b.equip.hero) : -1
  163. if (aIndex != bIndex) {
  164. if (aIndex >= 0 && bIndex >= 0) {
  165. return aIndex - bIndex
  166. } else {
  167. return bIndex - aIndex
  168. }
  169. }
  170. let aQuality
  171. let aNum = 0
  172. let bNum = 0
  173. let bQuality
  174. if ('quality' in a) {
  175. aQuality = a.quality
  176. aNum = a.num
  177. } else {
  178. aQuality = a.cfg.quality
  179. }
  180. if ('quality' in b) {
  181. bQuality = b.quality
  182. bNum = b.num
  183. } else {
  184. bQuality = b.cfg.quality
  185. }
  186. let curQuality = this.chooseEquip ? this.chooseEquip.cfg.quality : -1
  187. // 先按照aQuality bQuality是否等于 cfg.quality 进行排序
  188. if (aQuality == curQuality && bQuality != curQuality) {
  189. return -1
  190. } else if (aQuality != curQuality && bQuality == curQuality) {
  191. return 1
  192. } else {
  193. if (aQuality != bQuality) {
  194. return bQuality - aQuality
  195. }
  196. if (aNum != bNum) {
  197. return aNum - bNum
  198. }
  199. if ('cfg' in a && 'cfg' in b) {
  200. return a.cfg.type - b.cfg.type
  201. }
  202. }
  203. })
  204. this.equipList.numItems = this.equipAndGoodArr.length
  205. }
  206. equipCanBeNeed(iEquip: IEquip) {
  207. if (!this.chooseEquip) return false
  208. //选择了某个目标,可以吃的材料卡可以点击
  209. let qCfg = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1]
  210. //同名卡可以点击
  211. let can1 = qCfg.sameQualityNum > 0 && this.chooseEquip.equip.id == iEquip.equip.id
  212. //当前颜色卡可以点击
  213. let can2 =
  214. qCfg.anyQualityNum > 0 &&
  215. this.chooseEquip.cfg.quality - this.chooseEquip.grade == iEquip.cfg.quality &&
  216. iEquip.cfg.type == this.chooseEquip.cfg.type
  217. return (can1 || can2) && !Mgr.goods.equipIsUp(iEquip) && iEquip != this.chooseEquip
  218. }
  219. goodsCanBeNeed(goods: qualityGoods) {
  220. if (!this.chooseEquip) return false
  221. let qCfg = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1]
  222. return qCfg.anyQualityNum > 0 && qCfg.resetGoods[this.chooseEquip.cfg.type - 1] == goods.id
  223. }
  224. initNeedSlot() {
  225. let children = cc.find('need', this.node).children
  226. for (let i = 0; i < children.length; i++) {
  227. let node = children[i]
  228. let itemParent = cc.find('itemParent', node)
  229. if (this.needArr[i]) {
  230. itemParent.active = true
  231. this.initByEquipAndGoods(node, this.needArr[i])
  232. } else {
  233. itemParent.active = false
  234. }
  235. }
  236. }
  237. initEquipListItem(node: cc.Node, index: number) {
  238. let equipAndGoods = this.equipAndGoodArr[index]
  239. let iEquip: IEquip = 'cfg' in equipAndGoods ? equipAndGoods : null
  240. let goods: qualityGoods = 'quality' in equipAndGoods ? equipAndGoods : null
  241. this.initByEquipAndGoods(node, equipAndGoods)
  242. let isIEquip = iEquip != null
  243. //升级需要资源
  244. cc.find('red_dots', node).active = isIEquip && Mgr.goods.checkEquipBreakNeed(iEquip).canUp
  245. let canClick = false
  246. if (this.chooseEquip) {
  247. if (iEquip) canClick = this.equipCanBeNeed(iEquip)
  248. if (goods) canClick = this.goodsCanBeNeed(goods)
  249. } else if (iEquip) {
  250. //没有选择,可以突破的角色可以点击
  251. canClick = EquipmentQualityConfig[iEquip.cfg.quality + 1] != undefined
  252. }
  253. node.getComponent(UserButton).interactable = canClick
  254. cc.find('gray', node).active = !canClick
  255. let hero = cc.find('hero', node)
  256. hero.active = isIEquip && !!iEquip.equip.hero
  257. if (hero.active) {
  258. let iRole = Data.user.roles.find(v => v.hero.sid == iEquip.equip.hero)
  259. this.loadTexImg(`Public/role/icon/${iRole.cfg.url}`, hero, 'icon')
  260. }
  261. }
  262. initByEquipAndGoods(node: cc.Node, equipAndGoods: equipGoods) {
  263. let iEquip: IEquip = 'cfg' in equipAndGoods ? equipAndGoods : null
  264. let goods: qualityGoods = 'quality' in equipAndGoods ? equipAndGoods : null
  265. let itemParent = cc.find('itemParent', node)
  266. if (goods) {
  267. Mgr.goods.initOneGoods({id: goods.id, num: goods.num}, itemParent, this, {showDetails: false})
  268. } else {
  269. Mgr.global.initEquipItem(iEquip, itemParent, this)
  270. }
  271. }
  272. initChooseTypeUI() {
  273. let icon = cc.find('btn_chooseType/type_icon', this.node)
  274. icon.active = this.chooseType > 0
  275. if (icon.active) {
  276. this.loadTexImg(`Public/equip/type_icon${this.chooseType}`, this.node, 'btn_chooseType/type_icon')
  277. }
  278. ccUtils.setLabel(
  279. this.chooseType == EQUIPMENT.none ? LANGUAGE_TYPE.all : LANGUAGE_TYPE[EQUIPMENT[this.chooseType]],
  280. this.node,
  281. 'btn_chooseType/label',
  282. )
  283. let items = cc.find('items', this.chooseTypeNode).children
  284. for (let i = 0; i < items.length; i++) {
  285. let item = items[i]
  286. cc.find('choose', item).active = this.chooseType == i
  287. }
  288. }
  289. initEquipByType() {
  290. this.equips.length = 0
  291. this.equips = Data.user.equips.filter(
  292. equip =>
  293. (!this.chooseType || this.chooseType == equip.cfg.type) &&
  294. equip.cfg.quality < Data.main.maxEquipQuality,
  295. )
  296. cc.find('equipList/lb', this.node).active = this.equips.length == 0
  297. }
  298. initOneKey() {
  299. let canUp = false
  300. for (let equip of Data.user.equips) {
  301. if (equip.cfg.qualityType < QUALITY_TYPE.elite && !Mgr.goods.equipIsUp(equip)) {
  302. canUp ||= Mgr.goods.checkEquipBreakNeed(equip, true).canUp
  303. if (canUp) break
  304. }
  305. }
  306. cc.find('btn_auto/red_dots', this.node).active = canUp
  307. }
  308. //网络事件=======================================
  309. onEquipStarRsp(data: equipUpgradeStarRsp, rewardNty: IRewardNty) {
  310. Mgr.ui.show(UI.PowerUpUI, `+${this.chooseEquip.power - this.lastPower}`)
  311. this.initEquipByType()
  312. this.clearEquip()
  313. Mgr.ui.showUIs([
  314. Mgr.ui.getGroupUIInfo(UI.EquipBreakSuccessUI, Mgr.global.buildIEquip(data.data)),
  315. Mgr.ui.getRewardGroupUIInfo(rewardNty),
  316. ])
  317. }
  318. onEquipOneKeyStarRsp(data: equipOnekeyUpgradeStarRsp, rewardNty: IRewardNty) {
  319. this.initEquipByType()
  320. this.clearEquip()
  321. let changeIEquip: IEquip[] = []
  322. for (let i = Data.user.equips.length - 1; i >= 0; i--) {
  323. let find = data.changeList.find(value => value.sid == Data.user.equips[i].equip.sid)
  324. if (find) {
  325. changeIEquip.push(Data.user.equips[i])
  326. }
  327. }
  328. }
  329. //触发事件=======================================
  330. // 点击事件=======================================
  331. onAllEquipClick() {
  332. this.chooseTypeNode.active = true
  333. }
  334. onChooseEquipItemClick(e, detail) {
  335. this.chooseType = parseInt(detail)
  336. this.chooseTypeNode.active = false
  337. this.initChooseTypeUI()
  338. this.initEquipByType()
  339. this.clearEquip()
  340. }
  341. onEquipClick(node, index, lastSelected, isSelected, isMax) {
  342. if (!node) return
  343. if (cc.find('gray', node).active) return
  344. if (isMax) Mgr.ui.tip(LANGUAGE_TYPE.materialsLimit)
  345. if (this.chooseEquip) {
  346. this.needArr = []
  347. this.equipList.getMultSelected().forEach(i => {
  348. this.needArr.push(this.equipAndGoodArr[i])
  349. })
  350. this.initNeedSlot()
  351. } else {
  352. this.chooseEquip = this.equipAndGoodArr[index] as IEquip
  353. this.equipList.selectedMode = SelectedType.MULT
  354. this.equipList.setMultSelected([], null)
  355. this.initUI()
  356. this.equipList.scrollTo(0)
  357. }
  358. }
  359. onChooseEquipClick() {
  360. this.clearEquip()
  361. }
  362. onBreakClick() {
  363. if (!this.chooseEquip) return
  364. if (this.needArr?.length < this.equipList.maxMutSelected) {
  365. Mgr.ui.tip(LANGUAGE_TYPE.materialsNeed)
  366. return
  367. }
  368. let currency: idNum = {id: 0, num: 0}
  369. let sidArr: string[] = []
  370. let hasLvUp = false
  371. this.needArr.forEach(value => {
  372. if ('equip' in value) {
  373. sidArr.push(value.equip.sid)
  374. if (!hasLvUp && value.equip.lv > 1) hasLvUp = true
  375. }
  376. if ('quality' in value) {
  377. currency.id = value.id
  378. currency.num += 1
  379. }
  380. })
  381. let isSame = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1].sameQualityNum > 0
  382. let data: equipUpgradeStar = {
  383. currency,
  384. other: isSame ? [] : sidArr,
  385. same: isSame ? sidArr : [],
  386. sid: this.chooseEquip.equip.sid,
  387. }
  388. if (hasLvUp) {
  389. Mgr.ui.message(LANGUAGE_TYPE.materialsLvUp, () => {
  390. Mgr.net.send(msgCmd.cmd_equip_upgrade_star, data)
  391. })
  392. } else {
  393. Mgr.net.send(msgCmd.cmd_equip_upgrade_star, data)
  394. }
  395. }
  396. onOneKeyBreakClick() {
  397. Mgr.net.send(msgCmd.cmd_equip_onekey_upgrade_star)
  398. }
  399. }