GameDevUI.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /** @format */
  2. import {BaseUI} from './BaseUI'
  3. import {Data, Mgr} from '../GameControl'
  4. import {ccUtils} from '../utils/ccUtils'
  5. import {list, node, observer} from '../mobx/observer'
  6. import {GAME_WIN_TYPE, Language, LOCAL, MONSTER_TYPE} from '../enums/Enum'
  7. import List from '../uiutils/List'
  8. import {IRoleConfig, RoleConfig} from '../config/RoleConfig'
  9. import GameUI, {RoundOutType} from '../zuma/FightCore'
  10. import {CardSkillConfig} from '../config/CardSkillConfig'
  11. import {IMonsterConfig, MonsterConfig} from '../config/MonsterConfig'
  12. import {BT} from '../behaviorTree/BehaviorTree'
  13. import {IStageConfig, StageConfig} from '../config/StageConfig'
  14. import {IStageInfoConfig, StageInfoConfig} from '../config/StageInfoConfig'
  15. import {EliteInfoConfig} from '../config/EliteInfoConfig'
  16. import {EliteStageConfig} from '../config/EliteStageConfig'
  17. const {ccclass, property} = cc._decorator
  18. @ccclass
  19. @observer
  20. export class GameDevUI extends BaseUI {
  21. @list('chooseNode/scrollView')
  22. private chooseList: List
  23. @node('chooseNode')
  24. private chooseViewNode: cc.Node
  25. private allRoleIDs: string[]
  26. private allCardIDs: string[]
  27. private isChooseCard: boolean = false
  28. private gameUI: GameUI
  29. private curLang: Language
  30. onShow(args, fromUI: number) {
  31. this.curLang = Mgr.i18n.getLanguage()
  32. Mgr.i18n.setLanguage(Language.zh)
  33. this.gameUI = args
  34. this.allRoleIDs = Object.keys(RoleConfig).sort((a, b) => parseInt(a) - parseInt(b))
  35. this.allCardIDs = Object.keys(CardSkillConfig).sort((a, b) => parseInt(a) - parseInt(b))
  36. //白绿蓝紫橙
  37. let testID = [1, 4, 7, 11]
  38. this.allRoleIDs = this.allRoleIDs.filter(value => testID.includes(+value % 100))
  39. //加上有技能的怪物
  40. let monsterIDs = Object.keys(MonsterConfig).filter(value => MonsterConfig[value].skills[0] >= 0)
  41. this.allRoleIDs = this.allRoleIDs.concat(monsterIDs)
  42. cc.debug.setDisplayStats(false)
  43. this.initItem(true)
  44. this.initItem(false)
  45. //检查关卡配置
  46. this.checkStageConfig(Object.values(StageInfoConfig), StageConfig, '普通')
  47. this.checkStageConfig(Object.values(EliteInfoConfig), EliteStageConfig, '精英')
  48. }
  49. onDisable(): any {
  50. Mgr.i18n.setLanguage(this.curLang)
  51. Mgr.event.removeAll(this)
  52. }
  53. update(dt: number) {
  54. if (this.gameUI) {
  55. let {roleNum, enemyNum, castCost} = this.gameUI.getGameInfo()
  56. ccUtils.setLabel(roleNum.toString(), this.node, 'roleNum')
  57. ccUtils.setLabel(enemyNum.toString(), this.node, 'enemyNum')
  58. ccUtils.setLabel(castCost.toString(), this.node, 'costNum')
  59. }
  60. }
  61. initItem(isChooseCard: boolean) {
  62. this.isChooseCard = isChooseCard
  63. let arr = Mgr.storage.getObject(isChooseCard ? LOCAL.chooseMultCard : LOCAL.chooseMultRole, [])
  64. if (arr) {
  65. this.chooseList.setMultSelected(arr, null)
  66. this.onChooseSureClick()
  67. }
  68. }
  69. initChooseRole(node, itemIndex) {
  70. let curAllIDs = this.isChooseCard ? this.allCardIDs : this.allRoleIDs
  71. let curCfg = this.isChooseCard
  72. ? CardSkillConfig[curAllIDs[itemIndex]]
  73. : this.getRoleCfgByID(+curAllIDs[itemIndex])
  74. if (curCfg) ccUtils.setLabel(Mgr.i18n.getLabel(curCfg.name) + curCfg.quality + '阶', node, 'lb')
  75. }
  76. getRoleCfgByID(ID: number): IRoleConfig {
  77. let cfg = RoleConfig[ID]
  78. if (!cfg) cfg = (MonsterConfig[ID] as unknown) as IRoleConfig
  79. return cfg
  80. }
  81. checkStageConfig(stageInfos, stageConfig, stageName: string) {
  82. let errStage = []
  83. let errRoleStage = []
  84. for (let i = 0; i < stageInfos.length; i++) {
  85. let roleNum = 0
  86. let stageInfo = stageInfos[i]
  87. let allRoles = []
  88. for (let j = 1; j < 100; j++) {
  89. let stageCfg = stageConfig[stageInfo.ID * 100 + j]
  90. if (stageCfg) {
  91. if (stageCfg.summonType == RoundOutType.time || stageCfg.summonType == RoundOutType.dieOut) {
  92. roleNum += stageCfg.roles[0].length
  93. } else if (stageCfg.summonType == RoundOutType.average) {
  94. roleNum += stageCfg.rolesTime.flat().reduce((acc, val) => acc + val, 0)
  95. }
  96. let checkLength = (array1, array2) => {
  97. let isSame = array1.flat().length == array2.flat().length
  98. if (!isSame)
  99. console.log(
  100. '配置长度不一致:',
  101. stageInfo.ID * 100 + j,
  102. 'roles长度:',
  103. stageCfg.roles.flat().length,
  104. 'rolesPos长度',
  105. stageCfg.rolesPos.flat().length,
  106. 'rolesTime长度',
  107. stageCfg.rolesTime.flat().length,
  108. )
  109. return isSame
  110. }
  111. //检测配置长度是否一致
  112. checkLength(stageCfg.roles, stageCfg.rolesPos)
  113. checkLength(stageCfg.rolesPos, stageCfg.rolesTime)
  114. allRoles.push(...stageCfg.roles.flat())
  115. } else {
  116. if (stageInfo.parameter > 0 && roleNum != stageInfo.parameter) {
  117. errStage.push(`${stageName}关卡${stageInfo.ID}`)
  118. }
  119. break
  120. }
  121. }
  122. //检测类型是杀敌数量的时候,不能有召唤类型的怪物
  123. if (stageInfo.type == GAME_WIN_TYPE.killNum) {
  124. let summonArr = allRoles.filter(v => MonsterConfig[v].type == MONSTER_TYPE.baby)
  125. if (summonArr.length > 0) {
  126. errRoleStage.push(`${stageName}关卡${stageInfo.ID}:有召唤类型怪物ID:${summonArr}`)
  127. }
  128. } else if (stageInfo.type == GAME_WIN_TYPE.boss) {
  129. //检测boss类型,有且只能有一个boss
  130. let boosArr = allRoles.filter(v => MonsterConfig[v].type == MONSTER_TYPE.boss)
  131. if (boosArr.length != 1) {
  132. errRoleStage.push(`${stageName}关卡${stageInfo.ID}boos数量不等于1:boosID:${boosArr}`)
  133. }
  134. }
  135. }
  136. if (errStage.length > 0) {
  137. console.log('关卡配置错误,配置怪物数量不等于通过条件:', errStage.join(','))
  138. Mgr.ui.tip('关卡配置错误,配置怪物数量不等于通过条件:' + errStage.join(','))
  139. }
  140. if (errRoleStage.length > 0) {
  141. console.log('关卡配置错误,配置的怪物类型错误:', errRoleStage.join(','))
  142. Mgr.ui.tip('关卡配置错误,配置的怪物类型错误:' + errRoleStage.join(','))
  143. }
  144. }
  145. //网络事件=======================================
  146. //触发事件=======================================
  147. // 点击事件=======================================
  148. onClickCreateRoleEntity(e) {
  149. if (e.target['cfgID']) this.gameUI.createDevEntity(parseInt(e.target['cfgID']))
  150. }
  151. onClickCreateEnemyRoleEntity(e) {
  152. if (e.target['cfgID']) this.gameUI.createDevEntity(parseInt(e.target['cfgID']), true)
  153. }
  154. onClickCreateSkillCardEntity(e) {
  155. if (e.target['cfgID']) this.gameUI.showSkillPop(Mgr.global.buildICard({id: e.target['cfgID'], lv: 1, sid: ''}))
  156. }
  157. onClickDebug() {
  158. cc.debug.setDisplayStats(!cc.debug.isDisplayStats())
  159. }
  160. onClickShowLayout() {
  161. let layouts = cc.find('layouts', this.node)
  162. layouts.active = !layouts.active
  163. }
  164. onStageChange(editBox: cc.EditBox) {
  165. this.gameUI.changeStageChange(parseInt(editBox.string))
  166. }
  167. onRoleLogChange(editBox: cc.EditBox) {
  168. BT.debugEntity = parseInt(editBox.string)
  169. }
  170. onGameSpeedChange(editBox: cc.EditBox) {
  171. Data.game.gameSpeed = parseInt(editBox.string)
  172. }
  173. onChooseSureOpenClick(e, detail) {
  174. this.isChooseCard = detail != undefined
  175. this.chooseViewNode.active = true
  176. let curAllIDs = this.isChooseCard ? this.allCardIDs : this.allRoleIDs
  177. this.chooseList.numItems = curAllIDs.length
  178. this.scheduleOnce(() => {
  179. let arr = Mgr.storage.getObject(this.isChooseCard ? LOCAL.chooseMultCard : LOCAL.chooseMultRole)
  180. this.chooseList.setMultSelected(arr, null)
  181. })
  182. }
  183. onChooseSureClick() {
  184. this.chooseViewNode.active = false
  185. let multArr = this.chooseList.getMultSelected()
  186. multArr.sort((a, b) => a - b)
  187. let key = !this.isChooseCard ? 'layout' : 'layout_card'
  188. let curAllIDs = this.isChooseCard ? this.allCardIDs : this.allRoleIDs
  189. for (let i = multArr.length - 1; i >= 0; i--) {
  190. if (multArr[i] >= curAllIDs.length) {
  191. multArr.splice(i, 1)
  192. }
  193. }
  194. let nodes = ccUtils.instantChildren(cc.find(`layouts/${key}/btn`, this.node), multArr.length)
  195. let nodeEs
  196. if (!this.isChooseCard) {
  197. nodeEs = ccUtils.instantChildren(cc.find(`layouts/${key}E/btn`, this.node), multArr.length)
  198. }
  199. for (let i = 0; i < multArr.length; i++) {
  200. nodes[i]['cfgID'] = curAllIDs[multArr[i]]
  201. let cfg = this.isChooseCard ? CardSkillConfig[nodes[i]['cfgID']] : this.getRoleCfgByID(+nodes[i]['cfgID'])
  202. let name = Mgr.i18n.getLabel(cfg.name)
  203. ccUtils.setLabel(name + cfg.quality + '阶', nodes[i], 'Label')
  204. if (nodeEs) {
  205. nodeEs[i]['cfgID'] = curAllIDs[multArr[i]]
  206. ccUtils.setLabel(name + cfg.quality + '阶', nodeEs[i], 'Label')
  207. }
  208. }
  209. Mgr.storage.set(this.isChooseCard ? LOCAL.chooseMultCard : LOCAL.chooseMultRole, multArr)
  210. }
  211. }