123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- /** @format */
- import {BaseUI} from './BaseUI'
- import {Data, Mgr} from '../GameControl'
- import {ccUtils} from '../utils/ccUtils'
- import {list, observer, render} from '../mobx/observer'
- import {msgCmd} from '../proto/msg_cmd'
- import {IRoleQualityConfig, RoleQualityConfig} from '../config/RoleQualityConfig'
- import {ATTR_NAME, GOODS, LANGUAGE_TYPE, PROFESSION, QUALITY_COLOR, QUALITY_TYPE, ROLE_TYPE} from '../enums/Enum'
- import {idNum} from '../proto/typedef'
- import List, {SelectedType} from '../uiutils/List'
- import UserButton from '../uiutils/UserButton'
- import {heroOnekeyUpgradeStarRsp, heroUpgrade, heroUpgradeStar, heroUpgradeStarRsp} from '../proto/game'
- import {i18nLabel} from '../uiutils/i18nLabel'
- import {UI} from '../enums/UI'
- import {GoodsConfig} from '../config/GoodsConfig'
- import {RoleLevelConfig} from '../config/RoleLevelConfig'
- import {IRewardNty} from '../interface/UIInterface'
- import {IRole} from '../interface/GlobalInterface'
- const {ccclass, property} = cc._decorator
- export interface qualityGoods {
- id: number
- num: number
- quality: number
- }
- type roleGoods = IRole | qualityGoods
- @ccclass
- @observer
- export class RoleBreakUI extends BaseUI {
- chooseRole: IRole = null
- roleAndGoodArr: roleGoods[]
- needArr: roleGoods[]
- @list('roleList')
- roleList: List
- lastPower: number
- onShow(args, fromUI: number) {
- Mgr.net.add(msgCmd.cmd_hero_upgrade_star_rsp, this, this.onHeroStarRsp)
- Mgr.net.add(msgCmd.cmd_hero_onekey_upgrade_star_rsp, this, this.onHeroOneKeyStarRsp)
- Mgr.ui.showTop(this, [GOODS.coin, GOODS.diamond])
- this.clearRole()
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- clearRole() {
- this.chooseRole = null
- this.resetData()
- this.initNeedSlot()
- this.initUI()
- this.initOneKey()
- }
- resetData() {
- this.chooseRole = null
- this.roleList.selectedMode = SelectedType.SINGLE
- this.roleList.selectedId = -1
- this.roleAndGoodArr = [...Data.user.roles.filter(value => value.cfg.quality < Data.main.maxRoleQuality)]
- let goodsIDArr: number[] = []
- let cfgArr: IRoleQualityConfig[] = []
- for (let ID in RoleQualityConfig) {
- let goodsID = RoleQualityConfig[ID].resetGoods
- if (!goodsIDArr.includes(goodsID)) {
- goodsIDArr.push(goodsID)
- cfgArr.push(RoleQualityConfig[ID])
- }
- }
- for (let i = 0; i < goodsIDArr.length; i++) {
- let goodsID = goodsIDArr[i]
- if (goodsID > 0 && Mgr.goods.getGoodsNum(goodsID) > 0) {
- for (let j = 0; j < Mgr.goods.getGoodsNum(goodsID); j++) {
- this.roleAndGoodArr.push({
- id: goodsID,
- num: 1,
- quality: cfgArr[i].ID - 1,
- })
- }
- }
- }
- this.needArr = []
- }
- initUI() {
- cc.find('btn_auto', this.node).active = this.chooseRole == null
- cc.find('btn_break', this.node).active = this.chooseRole != null
- cc.find('joinTip', this.node).active = this.chooseRole == null
- let breakTip = cc.find('breakTip', this.node)
- let curSlotRoleNode = cc.find('cur_slot/role', this.node)
- curSlotRoleNode.active = false
- let nextSlotRoleNode = cc.find('next_slot/role', this.node)
- nextSlotRoleNode.active = false
- let hasChoose = this.chooseRole != null
- breakTip.active = hasChoose
- cc.find('add_need', this.node).active = hasChoose
- cc.find('need', this.node).active = hasChoose
- let rtTip = cc.find('tip_rt', this.node)
- ccUtils.setLabel(LANGUAGE_TYPE.autoBreakTip, rtTip)
- if (this.chooseRole) {
- let iRole = this.chooseRole
- this.lastPower = iRole.power
- curSlotRoleNode.active = true
- let hero = ccUtils.deepCopy(iRole.hero)
- hero.id += 1
- Mgr.global.initRoleItem(iRole, curSlotRoleNode, this)
- let nextQualityIRole = Mgr.global.buildIRole(hero)
- nextSlotRoleNode.active = true
- Mgr.global.initRoleItem(nextQualityIRole, nextSlotRoleNode, this)
- this.loadTexImg(`Public/role/streamer_${iRole.cfg.qualityType + 1}`, breakTip, 'streamer')
- ccUtils.setLabel(iRole.cfg.name, breakTip, 'roleName')
- let attrOrigin = cc.find('scrollView/view/content/attrs/attr', breakTip)
- let attrs = [ATTR_NAME.HP, ATTR_NAME.defense, ATTR_NAME.spellDefense]
- attrs.unshift(iRole.cfg.profession == PROFESSION.mage ? ATTR_NAME.spellAttack : ATTR_NAME.attack)
- let allAttrs = ccUtils.instantChildren(attrOrigin, attrs.length + 1)
- //显示等级
- let lvNode = allAttrs[0]
- ccUtils.setLabel(LANGUAGE_TYPE.lvMax, lvNode, 'attrName')
- ccUtils.setLabel(RoleQualityConfig[iRole.cfg.quality].maxLv.toString(), lvNode, 'attrNum')
- ccUtils.setLabel(RoleQualityConfig[nextQualityIRole.cfg.quality].maxLv.toString(), lvNode, 'nextNum')
- for (let i = 0; i < attrs.length; i++) {
- let attr = attrs[i]
- let attrNode = allAttrs[i + 1]
- ccUtils.setLabel(LANGUAGE_TYPE[attr.toString()], attrNode, 'attrName')
- ccUtils.setLabel(iRole[attr.toString()], attrNode, 'attrNum')
- ccUtils.setLabel(nextQualityIRole[attr.toString()], attrNode, 'nextNum')
- }
- ccUtils.setLabel(nextQualityIRole.cfg.tips, breakTip, 'scrollView/view/content/rtL/rt')
- ccUtils.setLabel(LANGUAGE_TYPE.needBreakTip, rtTip)
- let rtTipI18n = rtTip.getComponent(i18nLabel)
- let qCfg = RoleQualityConfig[iRole.cfg.quality + 1]
- if (qCfg.anyQualityNum > 0) {
- this.roleList.maxMutSelected = qCfg.anyQualityNum
- rtTipI18n.setParamByIndex(qCfg.anyQualityNum.toString(), 0)
- rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.anyQuality]], 1)
- rtTipI18n.setParamByIndex(LANGUAGE_TYPE[QUALITY_TYPE[Data.user.qualityTypeArr[qCfg.anyQuality]]], 2)
- } else {
- this.roleList.maxMutSelected = qCfg.sameQualityNum
- rtTipI18n.setParamByIndex(qCfg.sameQualityNum.toString(), 0)
- rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.sameQuality]], 1)
- rtTipI18n.setParamByIndex(
- Mgr.i18n.getLabel(iRole.cfg.name) +
- (iRole.grade > 0 ? `(${iRole.grade}${Mgr.i18n.getLabel(LANGUAGE_TYPE.star)})` : ''),
- 2,
- )
- }
- cc.find('need', this.node).children.forEach((value, index) => {
- value.active = index < this.roleList.maxMutSelected
- })
- }
- this.roleAndGoodArr.sort((a, b) => {
- if (this.chooseRole) {
- let aNeed = 'cfg' in a ? this.roleCanBeNeed(a) : this.goodsCanBeNeed(a)
- let bNeed = 'cfg' in b ? this.roleCanBeNeed(b) : this.goodsCanBeNeed(b)
- return Number(bNeed) - Number(aNeed)
- }
- let aAlter
- let bAlter
- if ('isAlter' in a) {
- aAlter = a.isAlter
- }
- if ('isAlter' in b) {
- bAlter = b.isAlter
- }
- if (aAlter != bAlter) {
- return aAlter - bAlter
- }
- let aIndex = 'cfg' in a ? Data.user.teamRole.indexOf(a) : -1
- let bIndex = 'cfg' in b ? Data.user.teamRole.indexOf(b) : -1
- if (aIndex != bIndex) {
- if (aIndex >= 0 && bIndex >= 0) {
- return aIndex - bIndex
- } else {
- return bIndex - aIndex
- }
- }
- let aQuality
- let aNum = 0
- let bNum = 0
- let bQuality
- if ('quality' in a) {
- aQuality = a.quality
- aNum = a.num
- } else {
- aQuality = a.cfg.quality
- }
- if ('quality' in b) {
- bQuality = b.quality
- bNum = b.num
- } else {
- bQuality = b.cfg.quality
- }
- let curQuality = this.chooseRole ? this.chooseRole.cfg.quality : -1
- // 先按照aQuality bQuality是否等于 iRole.cfg.quality 进行排序
- if (aQuality == curQuality && bQuality != curQuality) {
- return -1
- } else if (aQuality != curQuality && bQuality == curQuality) {
- return 1
- } else {
- if (aQuality != bQuality) {
- return bQuality - aQuality
- }
- if (aNum != bNum) {
- return aNum - bNum
- }
- if ('cfg' in a && 'cfg' in b) {
- return b.power - a.power
- }
- }
- })
- this.roleList.numItems = this.roleAndGoodArr.length
- }
- roleCanBeNeed(iRole: IRole) {
- if (!this.chooseRole) return false
- //选择了某个目标,可以吃的材料卡可以点击
- let qCfg = RoleQualityConfig[this.chooseRole.cfg.quality + 1]
- //同名卡可以点击
- let can1 = qCfg.sameQualityNum > 0 && this.chooseRole.hero.id == iRole.hero.id
- //同品质卡可以点击
- let can2 = qCfg.anyQualityNum > 0 && this.chooseRole.cfg.quality - this.chooseRole.grade == iRole.cfg.quality
- return (can1 || can2) && !Mgr.goods.roleIsUp(iRole) && iRole != this.chooseRole
- }
- goodsCanBeNeed(goods: qualityGoods) {
- if (!this.chooseRole) return false
- let qCfg = RoleQualityConfig[this.chooseRole.cfg.quality + 1]
- return qCfg.anyQualityNum > 0 && qCfg.resetGoods == goods.id
- }
- initNeedSlot() {
- let children = cc.find('need', this.node).children
- for (let i = 0; i < children.length; i++) {
- let node = children[i]
- let itemParent = cc.find('itemParent', node)
- if (this.needArr[i]) {
- itemParent.active = true
- this.initByRoleAndGoods(node, this.needArr[i])
- } else {
- itemParent.active = false
- }
- }
- }
- initRoleItem(node: cc.Node, index: number) {
- let roleAndGoods = this.roleAndGoodArr[index]
- let iRole: IRole = 'cfg' in roleAndGoods ? roleAndGoods : null
- let goods: qualityGoods = 'quality' in roleAndGoods ? roleAndGoods : null
- this.initByRoleAndGoods(node, roleAndGoods)
- let isIRole = iRole != null
- let icon_battle = cc.find('icon_battle', node)
- icon_battle.active = isIRole && Mgr.goods.roleIsUp(iRole)
- //升级需要资源
- cc.find('red_dot', node).active = isIRole && Mgr.goods.checkRoleBreakNeed(iRole).canUp
- let canClick = false
- if (this.chooseRole) {
- if (iRole) canClick = this.roleCanBeNeed(iRole) && !iRole.isAlter
- if (goods) canClick = this.goodsCanBeNeed(goods)
- } else if (iRole) {
- //没有选择,可以突破的角色可以点击
- canClick = RoleQualityConfig[iRole.cfg.quality + 1] != undefined && !iRole.isAlter
- }
- node.getComponent(UserButton).interactable = canClick
- cc.find('gray', node).active = !canClick
- }
- initByRoleAndGoods(node: cc.Node, roleAndGoods: roleGoods) {
- let iRole: IRole = 'cfg' in roleAndGoods ? roleAndGoods : null
- let goods: qualityGoods = 'quality' in roleAndGoods ? roleAndGoods : null
- let itemParent = cc.find('itemParent', node)
- if (!iRole) {
- Mgr.goods.initOneGoods({id: goods.id, num: goods.num}, itemParent, this, {showDetails: false})
- } else {
- Mgr.global.initRoleItem(iRole, itemParent, this)
- }
- }
- initOneKey() {
- let canUp = false
- for (let iRole of Data.user.roles) {
- if (iRole.cfg.qualityType < QUALITY_TYPE.elite && !Mgr.goods.roleIsUp(iRole) && iRole.hero.lv == 1) {
- canUp ||= Mgr.goods.checkRoleBreakNeed(iRole, true).canUp
- if (canUp) break
- }
- }
- cc.find('btn_auto/red_dot', this.node).active = canUp
- }
- //网络事件=======================================
- onHeroStarRsp(data: heroUpgradeStarRsp, rewardNty: IRewardNty) {
- Mgr.ui.show(UI.PowerUpUI, `+${this.chooseRole.power - this.lastPower}`)
- this.clearRole()
- Mgr.ui.showUIs([
- Mgr.ui.getGroupUIInfo(UI.RoleBreakSuccessUI, Mgr.global.buildIRole(data.data)),
- Mgr.ui.getRewardGroupUIInfo(rewardNty),
- ])
- }
- onHeroOneKeyStarRsp(data: heroOnekeyUpgradeStarRsp, rewardNty: IRewardNty) {
- this.clearRole()
- let changeIRole: IRole[] = []
- for (let i = Data.user.roles.length - 1; i >= 0; i--) {
- let findHero = data.changeList.find(value => value.sid == Data.user.roles[i].hero.sid)
- if (findHero) {
- changeIRole.push(Data.user.roles[i])
- }
- }
- }
- //触发事件=======================================
- // 点击事件=======================================
- onRoleClick(node, index, lastSelected, isSelected, isMax) {
- if (this.roleList.scrollView.isScrolling()) return
- if (!node) return
- if (cc.find('gray', node).active) return
- if (isMax) Mgr.ui.tip(LANGUAGE_TYPE.materialsLimit)
- if (this.chooseRole) {
- this.needArr = []
- this.roleList.getMultSelected().forEach(i => {
- this.needArr.push(this.roleAndGoodArr[i])
- })
- this.initNeedSlot()
- } else {
- this.chooseRole = this.roleAndGoodArr[index] as IRole
- this.roleList.selectedMode = SelectedType.MULT
- this.roleList.setMultSelected([], null)
- this.initUI()
- this.roleList.scrollTo(0)
- }
- }
- onChooseRoleClick() {
- this.clearRole()
- }
- onBreakClick() {
- if (!this.chooseRole) return
- if (this.needArr?.length < this.roleList.maxMutSelected) {
- Mgr.ui.tip(LANGUAGE_TYPE.materialsNeed)
- return
- }
- let currency: idNum = {id: 0, num: 0}
- let sidArr: string[] = []
- let hasLvUp = false
- this.needArr.forEach(value => {
- if ('hero' in value) {
- sidArr.push(value.hero.sid)
- if (!hasLvUp && value.hero.lv > 1) hasLvUp = true
- }
- if ('quality' in value) {
- currency.id = value.id
- currency.num += 1
- }
- })
- let isSame = RoleQualityConfig[this.chooseRole.cfg.quality + 1].sameQualityNum > 0
- let data: heroUpgradeStar = {
- currency,
- other: isSame ? [] : sidArr,
- same: isSame ? sidArr : [],
- sid: this.chooseRole.hero.sid,
- }
- if (hasLvUp) {
- Mgr.ui.message(LANGUAGE_TYPE.materialsLvUp, () => {
- Mgr.net.send(msgCmd.cmd_hero_upgrade_star, data)
- })
- } else {
- Mgr.net.send(msgCmd.cmd_hero_upgrade_star, data)
- }
- }
- onOneKeyBreakClick() {
- Mgr.net.send(msgCmd.cmd_hero_onekey_upgrade_star)
- }
- }
|