TowerUI.ts 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. import { _decorator, instantiate, Node, Prefab, Size, Tween, tween, UITransform, Vec2, Vec3 ,Animation, EventTouch, Button, sp, Enum, Label, Toggle, Sprite, SpriteFrame, v3, utils, ProgressBar} from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { Framework } from '../../../framework/Framework';
  4. import { FrameworkConf } from '../../../framework/config/FrameworkConf';
  5. import { AudioID } from '../../../framework/config/AudioConf';
  6. import { AsyncQueue, NextFunction } from '../../../framework/queue/AsyncQueue';
  7. import { Hero } from './node/Hero';
  8. import { Enemy } from './node/Enemy';
  9. import { Hurt } from './node/Hurt';
  10. import { BattleNodeBase } from './node/BattleNodeBase';
  11. import { BattleControl } from './control/BattleControl';
  12. import { BattleUtil } from './data/BattleUtil';
  13. import { BattleEventManager } from './base/BattleEventManager';
  14. import { BattleEventData_EnemyBorn, BattleEventData_EnemyBuff, BattleEventData_EnemyDie, BattleEventData_EnemyHurt, BattleEventData_EnemyMove, BattleEventData_HeroAction, BattleEventData_HeroAttack, BattleEventData_Over, BattleEventTarget, BattleEventType, EnemyActionType, TowerUUID } from './base/BattleEventUtil';
  15. import { MapConf } from './conf/MapConf';
  16. import { isValid } from 'cc';
  17. import { HeroDataPool, HeroRaceSacle } from './data/HeroData';
  18. import { StringUtil } from '../../../framework/util/StringUtil';
  19. import { MaterialUtil } from '../../../framework/util/MaterialUtil';
  20. import { BattlesConf } from './conf/BattlesConf';
  21. import { GameEvent } from '../../data/GameEvent';
  22. import { LoginManager, LoginMgr } from '../../common/LoginManager';
  23. import { MailManager } from '../../manager/MailManager';
  24. import { ViewID } from '../../../framework/config/LayerConf';
  25. import { MailData } from '../../data/MailData';
  26. import { RoleManager } from '../../manager/RoleManager';
  27. import { FightRole, RoleData } from '../../data/RoleData';
  28. import { BattleData, BattleLayoutPos, BattleLayoutScale, BattleOptsBase, BattleOptsKill, BattleOptsMerge, BattleOptsMove, BattleOptsNew, BattleOptsRemove, BattleOptsType } from '../../data/BattleData';
  29. import { BattleManager } from '../../manager/BattleManager';
  30. import { UserData } from '../../data/UserData';
  31. import { ResultUI } from './node/ResultUI';
  32. import { ChangeChapter } from './node/ChangeChapter';
  33. import { RewardChapter } from './node/RewardChapter';
  34. //地图比例尺 1:70
  35. let mapScale = 72;
  36. let basePoint = {x:-325,y:-70}
  37. let baseOffset = {x:0,y:0}
  38. //地图格子转坐标
  39. let MapDataPosToView = (x:number,y:number) => {
  40. let XX = (x+baseOffset.x) * mapScale + basePoint.x;
  41. let YY = (y+baseOffset.y) * mapScale + basePoint.y;
  42. return new Vec3(XX, YY, 0);
  43. //return new Vec3(x * mapScale + basePoint.x, y * mapScale + basePoint.y, 0);
  44. }
  45. //地图速度转换
  46. let MapDataSpeedToView = (x:number,y:number) => {
  47. let XX = x * mapScale * BattleUtil.FrameRate;
  48. let YY = y * mapScale * BattleUtil.FrameRate;
  49. return new Vec2(XX, YY,);
  50. //return new Vec3(x * mapScale + basePoint.x, y * mapScale + basePoint.y, 0);
  51. }
  52. const { ccclass, property } = _decorator;
  53. //可操作格子:背包格子和战斗格子
  54. export interface PosData {
  55. //格子节点
  56. node: Node,
  57. //格子上的英雄
  58. hero: Node,
  59. //格子是否锁
  60. bLock: boolean,
  61. //格子下标
  62. posIndex: number,
  63. pos: Vec3,
  64. //地图编号
  65. posNumber: number
  66. }
  67. @ccclass('TowerUI')
  68. export class TowerUI extends BaseView {
  69. @property({ type: Sprite, tooltip: "地图" })
  70. mapSprite: Sprite = null;
  71. @property({ type: Label, tooltip: "地图名字" })
  72. mapName: Label = null;
  73. @property({ type: Node, tooltip: "攻击位" })
  74. attackNode: Node = null;
  75. @property({ type: Node, tooltip: "背包位" })
  76. bagNode: Node = null;
  77. @property({ type: Node, tooltip: "减血数字根节点" })
  78. hurtNode: Node = null;
  79. // 攻击位
  80. attackPosList: PosData[] = [];
  81. //根据posID获取做的索引
  82. attackPosMap: Map<number,PosData> = new Map();
  83. //背包位
  84. bagPosList: PosData[] = [];
  85. heroList: Node[] = [];
  86. @property({type:[Node],tooltip:"升级效果"})
  87. levelUpEffect:Node[] = []
  88. @property({ type: [Prefab], tooltip: "敌人" })
  89. ememyModelList: Prefab[] = [];
  90. enemyPool: Map<number,Node[]> = new Map();
  91. enemyMap: Map<number,Node> = new Map();
  92. enemyWaitTime: number = 0;
  93. @property({ type: [Prefab], tooltip: "受伤数字" })
  94. hurtModelList: Prefab[] = [];
  95. hurtPool: Node[] = [];
  96. hurtList: Node[] = [];
  97. @property({ type:Node, tooltip: "所有角色根节点" })
  98. roleNode: Node = null;
  99. @property({ type:Node, tooltip: "攻击范围" })
  100. radiusNode: Node = null;
  101. @property({ type:[Node], tooltip: "统计节点" })
  102. countList: Node[] = [];
  103. @property({ type:[Node], tooltip: "boss节点" })
  104. bossList: Node[] = [];
  105. @property({ type: Label, tooltip: "精力统计" })
  106. powerLabel: Label = null;
  107. @property({ type: ProgressBar, tooltip: "关卡进度" })
  108. battlesProgressBar: ProgressBar = null;
  109. @property({ type: [Label], tooltip: "当前管卡展示" })
  110. levelValue: Label[] = []
  111. @property({ type: Node, tooltip: "结算" })
  112. resultNode: Node = null;
  113. @property({ type: Node, tooltip: "章节切换" })
  114. changeChapterNode: Node = null;
  115. @property({ type: Node, tooltip: "章节奖励" })
  116. rewardChapterNode: Node = null;
  117. //关卡id
  118. battlesID: number = 1;
  119. bStart = false;
  120. // waitTime = 5;
  121. touchStart: Node = null;
  122. //记录连击
  123. touchEndIndex = -1;
  124. touchEndTime = 0;
  125. gameTime = 0;
  126. //当前精力
  127. private powerCur = 180;
  128. //最大精力
  129. private powerMax = 180
  130. //伤害统计 key:typeID value:伤害值
  131. private damageCountData:Map<number,number> = new Map();
  132. private damageUpdateTime = 0;
  133. private bossIndexMap:Map<number,number> = new Map();
  134. battleControl: BattleControl = null;
  135. //当前动画下标
  136. levelUpEffectIndex = 0;
  137. //是否自动合成
  138. isAutoMerge = false;
  139. //英雄处理-------
  140. //英雄模型加载数量
  141. loadHeroModelNum: number = 0;
  142. //英雄模型加载数量上限
  143. loadHeroModelNumMax: number = -1;
  144. heroModelMap:Map<number,Prefab> = new Map();
  145. heroPool: Map<number,Node[]> = new Map();
  146. //出战角色
  147. fightRole:FightRole = [0,0,0,0]
  148. //锁定格子
  149. lockBagPosNumber = 6;
  150. lockAttackPosNumber = 8;
  151. //操作指令集 记录下来发给服务器
  152. operateList:Array<BattleOptsBase> = [];
  153. protected onLoad() {
  154. super.onLoad();
  155. this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this)
  156. this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  157. this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  158. this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
  159. for (let i = 0; i < this.levelUpEffect.length; i++) {
  160. this.levelUpEffect[i].getComponent(sp.Skeleton).setCompleteListener(()=>{
  161. this.levelUpEffect[i].active = false;
  162. })
  163. }
  164. this.battleControl = BattleControl.GetInstance()
  165. BattleEventManager.instance.addEvent(BattleEventTarget.Update, this.updateDataEvent.bind(this), TowerUUID);
  166. Framework.event.addEvent(GameEvent.BossUpdate, this.bossUpdate.bind(this),this)
  167. this.initPool()
  168. }
  169. protected onDestroy() {
  170. BattleEventManager.instance.removeEvent(TowerUUID)
  171. }
  172. protected update(dt: number): void {
  173. this.updateSiblingIndex()
  174. if(this.bStart){
  175. this.gameTime += dt;
  176. let nowFrame = Math.floor(this.gameTime/BattleUtil.FrameTime)
  177. if(nowFrame > this.battleControl.map.curTurn){
  178. //
  179. while(nowFrame > this.battleControl.map.curTurn+1){
  180. //需要移动的对象做瞬时计算 //目前只有敌人,以后会有子弹或者其他会移动的
  181. this.enemyMap.forEach(element => {
  182. element.getComponent(Enemy).battleUpdate(BattleUtil.FrameTime)
  183. });
  184. this.battleControl.update();
  185. if(this.battleControl.isBattleEnd){
  186. break;
  187. }
  188. }
  189. this.enemyMap.forEach(element => {
  190. element.getComponent(Enemy).battleUpdate(BattleUtil.FrameTime)
  191. });
  192. this.battleControl.update();
  193. }
  194. this.damageUpdateTime += dt;
  195. if(this.damageUpdateTime > 0.1){
  196. this.damageUpdateTime = 0;
  197. this.updateDamageCount()
  198. }
  199. }
  200. else{
  201. // if(this.waitTime > 0){
  202. // this.waitTime -= dt;
  203. // }
  204. // else{
  205. // this.bStart = true;
  206. // }
  207. }
  208. if(this.touchEndTime > 0){
  209. this.touchEndTime -= dt;
  210. if(this.touchEndTime <= 0){
  211. this.touchEndIndex = -1;
  212. }
  213. }
  214. }
  215. private updateDataEvent(event){
  216. if(this.battleControl.isBattleEnd && event.eventType!=BattleEventType.Over){
  217. console.log("结束")
  218. return
  219. }
  220. switch(event.eventType){
  221. case BattleEventType.EnemyBorn:{
  222. let enemyData = event as BattleEventData_EnemyBorn;
  223. this.addEnemy(enemyData);
  224. break;
  225. }
  226. case BattleEventType.EnemyMove:{
  227. let enemyData = event as BattleEventData_EnemyMove;
  228. // console.log("移动",enemyData.ID,enemyData.speedVector.x,enemyData.speedVector.y)
  229. if(this.enemyMap.has(enemyData.ID)){
  230. let enemy = this.enemyMap.get(enemyData.ID);
  231. enemy.getComponent(Enemy).speedVector = MapDataSpeedToView(enemyData.speedVector.x, enemyData.speedVector.y);
  232. }
  233. break;
  234. }
  235. case BattleEventType.EnemyHurt:{
  236. let enemyData = event as BattleEventData_EnemyHurt;
  237. //console.log("移动",enemyData.ID,enemyData.hurt,enemyData.status)
  238. if(this.enemyMap.has(enemyData.targetID)){
  239. let enemy = this.enemyMap.get(enemyData.targetID);
  240. enemy.getComponent(Enemy).hurt(enemyData.hurt);
  241. this.addHurt(enemy.position,enemyData.hurt)
  242. }
  243. this.setDamageCount(enemyData.typeID,enemyData.hurt)
  244. break;
  245. }
  246. case BattleEventType.EnemyDie:{
  247. // console.log("死亡",event)
  248. let enemyData = event as BattleEventData_EnemyDie;
  249. if(this.enemyMap.has(enemyData.ID)){
  250. let enemy = this.enemyMap.get(enemyData.ID);
  251. enemy.getComponent(Enemy).die(()=>{
  252. this.enemyMap.delete(enemyData.ID);
  253. let typeID = enemy.getComponent(Enemy).typeID
  254. if(this.enemyPool.has(typeID)){
  255. let pool = this.enemyPool.get(typeID);
  256. pool.push(enemy);
  257. }
  258. else {
  259. this.enemyPool.set(typeID,[enemy]);
  260. }
  261. }
  262. );
  263. }
  264. //记录击杀敌人的操作
  265. let otps:BattleOptsKill = {
  266. count:1,
  267. type:BattleOptsType.Kill,
  268. typeID:enemyData.typeID
  269. }
  270. this.operateList.push(otps);
  271. break;
  272. }
  273. case BattleEventType.EnemyBuff:{
  274. let enemyData = event as BattleEventData_EnemyBuff;
  275. if(this.enemyMap.has(enemyData.ID)){
  276. let enemy = this.enemyMap.get(enemyData.ID);
  277. //enemy.getComponent(Enemy).addbuff(enemyData.buff);
  278. }
  279. break;
  280. }
  281. case BattleEventType.HeroAction:{
  282. // console.log("攻击动作",event)
  283. let attackData = event as BattleEventData_HeroAction;
  284. if(this.attackPosMap.has(attackData.posID)){
  285. let posData = this.attackPosMap.get(attackData.posID);
  286. let enemy = this.enemyMap.get(attackData.targetID);
  287. if( posData && posData.hero){
  288. let hero = posData.hero.getComponent(Hero);
  289. if(enemy){
  290. hero.attack(enemy)
  291. // enemy.getComponent(Enemy).hurt(attackData.hurt);
  292. // this.addHurt(enemy.position,attackData.hurt)
  293. }
  294. else{
  295. hero.stand()
  296. }
  297. // this.setDamageCount(hero.typeID,attackData.hurt)
  298. }
  299. }
  300. break;
  301. }
  302. case BattleEventType.HeroAttack:{
  303. // console.log("攻击",event)
  304. let attackData = event as BattleEventData_HeroAttack;
  305. if(this.attackPosMap.has(attackData.posID)){
  306. let posData = this.attackPosMap.get(attackData.posID);
  307. let enemy = this.enemyMap.get(attackData.targetID);
  308. if( posData && posData.hero){
  309. let hero = posData.hero.getComponent(Hero);
  310. if(enemy){
  311. // hero.attack(enemy)
  312. enemy.getComponent(Enemy).hurt(attackData.hurt);
  313. this.addHurt(enemy.position,attackData.hurt)
  314. this.setDamageCount(hero.typeID,attackData.hurt)
  315. }
  316. // else{
  317. // hero.stand()
  318. // }
  319. }
  320. }
  321. break;
  322. }
  323. case BattleEventType.Over:{
  324. let attackData = event as BattleEventData_Over;
  325. this.attackPosMap.forEach((posData, posID) => {
  326. if(posData.hero){
  327. posData.hero.getComponent(Hero).stand()
  328. }
  329. })
  330. this.enemyMap.forEach((enemy, enemyID) => {
  331. enemy.getComponent(Enemy).stand()
  332. })
  333. let winStr = attackData.bWin ? "胜利" : "失败";
  334. console.log(winStr)
  335. let battlesConf = BattlesConf.data[this.battlesID];
  336. if(attackData.bWin &&(this.battlesID==battlesConf.BossProcess)){
  337. this.changeChapterNode.getComponent(ChangeChapter).show(()=>{
  338. this.restartBattle(this.battlesID)
  339. });
  340. }
  341. else{
  342. this.resultNode.getComponent(ResultUI).show(attackData.bWin,()=>{
  343. this.restartBattle(this.battlesID)
  344. })
  345. }
  346. if(attackData.bWin){
  347. let layout = {}
  348. for(let index = 0; index < this.bagPosList.length; index++){
  349. let posData = this.bagPosList[index]
  350. let key = BattleLayoutPos[index]
  351. layout[key] = 0
  352. if(posData.hero){
  353. let heroData = posData.hero.getComponent(Hero)
  354. let value = heroData.level + heroData.raceID *BattleLayoutScale
  355. if(key){
  356. layout[key] = value
  357. }
  358. }
  359. }
  360. //战场占位数量跟背包一样
  361. for(let index = 0; index < BattleUtil.BagListSize; index++){
  362. let posData = this.attackPosList[index]
  363. let key = BattleLayoutPos[index+BattleUtil.BagListSize]
  364. if(key){
  365. if(posData && posData.hero){
  366. let heroData = posData.hero.getComponent(Hero)
  367. let value = heroData.level + heroData.raceID *BattleLayoutScale
  368. layout[key] = value
  369. }
  370. else{
  371. layout[key] = 0
  372. }
  373. }
  374. }
  375. BattleManager.sendBattleDuplicateMsg(this.battlesID,attackData.bWin,layout,this.operateList,()=>{
  376. if(this.battlesID == 20){
  377. }
  378. else{
  379. this.battlesID++
  380. }
  381. },()=>{
  382. // this.reStartBattle(this.battlesID)
  383. })
  384. }
  385. else{
  386. if(this.battlesID%5 != 1){
  387. this.battlesID--
  388. }
  389. else{
  390. }
  391. }
  392. break;
  393. }
  394. }
  395. }
  396. onTouchStart(event: EventTouch) {
  397. if (this.touchStart) {
  398. this.resetHeroPos(this.touchStart)
  399. }
  400. // 获取触点对应节点
  401. let posData = this.getItemBaseByPosition(event.getLocation());
  402. if(posData && posData.hero){
  403. let hero = posData.hero.getComponent(Hero);
  404. if(hero.isLock){
  405. return;
  406. }
  407. Framework.audio.playEffect(AudioID.Click);
  408. this.touchStart = posData.hero;
  409. hero.stand()
  410. this.touchStart.setSiblingIndex(30);
  411. let index = posData.posIndex - BattleUtil.BagListSize
  412. if(index >= 0){
  413. this.battleControl.removeHeroInPos(index)
  414. }
  415. }
  416. }
  417. // 触摸移动
  418. onTouchMove(event: EventTouch) {
  419. if (this.touchStart ) {
  420. this.touchStart .setPosition(this.roleNode.getComponent(UITransform).convertToNodeSpaceAR(new Vec3(event.getUILocation().x, event.getUILocation().y)))
  421. let posData = this.getItemBaseByPosition(event.getLocation());
  422. if(posData&&(posData.posIndex >= BattleUtil.BagListSize)){
  423. this.radiusNode.position = v3(this.touchStart.position.x,this.touchStart.position.y);
  424. this.radiusNode.active = true;
  425. this.setRadius(this.touchStart.getComponent(Hero).radius)
  426. }
  427. else{
  428. this.radiusNode.active = false;
  429. }
  430. }
  431. else{
  432. this.radiusNode.active = false;
  433. }
  434. }
  435. onTouchEnd(event: EventTouch) {
  436. this.radiusNode.active = false;
  437. if (this.touchStart) {
  438. let posData = this.getItemBaseByPosition(event.getLocation());
  439. let touchEnd:Node = null
  440. if(posData){
  441. if(posData.hero == this.touchStart){
  442. if(this.touchEndIndex == posData.posIndex){
  443. this.touchEndIndex = -1
  444. if(posData.posIndex < BattleUtil.BagListSize){
  445. this.removeHeroPos(this.touchStart,true)
  446. this.touchStart = null;
  447. return;
  448. }
  449. }
  450. else{
  451. this.touchEndIndex = posData.posIndex
  452. this.touchEndTime = 1
  453. }
  454. }
  455. else{
  456. if(posData.hero){
  457. let hero = posData.hero.getComponent(Hero);
  458. if(hero && hero.isLock){
  459. this.resetHeroPos(this.touchStart)
  460. this.touchStart = null;
  461. return;
  462. }
  463. }
  464. touchEnd = posData.hero;
  465. this.touchEndIndex = -1
  466. }
  467. }
  468. else{
  469. this.resetHeroPos(this.touchStart)
  470. this.touchStart = null;
  471. this.touchEndIndex = -1
  472. return
  473. }
  474. if(touchEnd){
  475. let endHero = touchEnd.getComponent(Hero)
  476. let startHero = this.touchStart.getComponent(Hero)
  477. if(endHero.typeID == startHero.typeID && endHero.level == startHero.level){
  478. this.mergeHero(this.touchStart, touchEnd)
  479. }
  480. else{
  481. this.changeHeroPos(this.touchStart, touchEnd)
  482. }
  483. }
  484. else{
  485. this.setHeroPos(this.touchStart, posData.posIndex)
  486. }
  487. this.touchStart = null;
  488. }
  489. }
  490. onTouchCancel(event: EventTouch) {
  491. this.radiusNode.active = false;
  492. if (this.touchStart) {
  493. this.resetHeroPos(this.touchStart)
  494. this.touchStart = null;
  495. }
  496. }
  497. //根据世界坐标获取item 排除手上的
  498. private getItemBaseByPosition(pos: Vec2):PosData {
  499. let FindArr = this.bagPosList
  500. let bag = FindArr.find(t => {
  501. if(t.bLock) return false
  502. if(t.hero && t.hero != this.touchStart){
  503. return t.hero.getComponent(Hero).hitTest(pos)
  504. }
  505. return t.node.getComponent(UITransform).hitTest(pos)
  506. });
  507. if (bag ) return bag
  508. FindArr = this.attackPosList
  509. let attack = FindArr.find(t => {
  510. if(t.hero && t.hero != this.touchStart){
  511. return t.hero.getComponent(Hero).hitTest(pos)
  512. }
  513. return t.node.getComponent(UITransform).hitTest(pos)
  514. });
  515. return attack;
  516. }
  517. //炸弹效果播放结束
  518. bombSpineOver() {
  519. }
  520. //UI开打时会调用,如果有初始化代码应该放到此函数
  521. onOpen(args) {
  522. let battlesConf = BattlesConf.data[BattleData.duplicate.max_process]
  523. if(battlesConf){
  524. if(battlesConf.BossProcess > BattleData.duplicate.max_process){
  525. this.battlesID = BattleData.duplicate.max_process + 1
  526. this.bStart = true
  527. }
  528. else{
  529. this.changeChapterNode.getComponent(ChangeChapter).show(
  530. ()=>{
  531. this.restartBattle(this.battlesID+1)
  532. }
  533. );
  534. //只考虑换章节,暂不考虑数据错乱
  535. this.battlesID = BattleData.duplicate.max_process
  536. this.changeChapterNode.active = true
  537. this.bStart = false
  538. }
  539. }
  540. else{
  541. return
  542. }
  543. this.battleControl.init(this.battlesID)
  544. this.init();
  545. }
  546. //UI关闭时会调用,该函数在onDestroy前调用
  547. onClose() {
  548. }
  549. //框架管理UI层级时会调用,可根据UI情况修改
  550. onShow() {
  551. super.onShow();
  552. }
  553. //框架管理UI层级时会调用,可根据UI情况修改
  554. onHide() {
  555. super.onHide();
  556. }
  557. init() {
  558. let posID = 0;
  559. let roleTransform = this.roleNode.getComponent(UITransform)
  560. let bagChildren = this.bagNode.children
  561. for (let i = 0; i < BattleUtil.BagListSize; i++) {
  562. let node = bagChildren[i];
  563. let pos = roleTransform.convertToNodeSpaceAR(node.getWorldPosition())
  564. let posData: PosData = {
  565. node: node,
  566. hero: null,
  567. bLock: false,
  568. posIndex: posID,
  569. pos: pos,
  570. posNumber: -1
  571. }
  572. this.bagPosList.push(posData);
  573. posID++;
  574. }
  575. this.reset()
  576. }
  577. reset(){
  578. let battleConf = BattlesConf.data[this.battlesID.toString()]
  579. if(!battleConf){
  580. console.log("战斗配置错误")
  581. return
  582. }
  583. this.lockAttackPosNumber = BattleUtil.AttackListSize-battleConf.Unlock
  584. let mapConf = MapConf.data[this.battleControl.mapID.toString()]
  585. if(!mapConf){
  586. console.log("地图配置错误")
  587. return
  588. }
  589. let offset = mapConf.OffsetArray
  590. if(offset){
  591. baseOffset.x = offset[0]||0
  592. baseOffset.y = offset[1]||0
  593. }
  594. else{
  595. baseOffset.x = 0
  596. baseOffset.y = 0
  597. }
  598. let attackChildren = this.attackNode.children
  599. let attackNode = this.attackNode.children[0]
  600. // this.attackPosList = []
  601. this.attackPosMap.clear()
  602. for (let i = 0; i < BattleUtil.BagListSize; i++) {
  603. let posData = this.bagPosList[i];
  604. if(i < BattleUtil.BagListSize-this.lockBagPosNumber){
  605. posData.node.getChildByName("lock").active = false
  606. posData.bLock = false
  607. }
  608. else{
  609. posData.bLock = true
  610. posData.node.getChildByName("lock").active = true
  611. }
  612. }
  613. for (let i = 0; i < BattleUtil.AttackListSize; i++) {
  614. let node = attackChildren[i];
  615. if(!node){
  616. node = instantiate(attackNode)
  617. this.attackNode.addChild(node)
  618. }
  619. let posNumber = this.battleControl.getPosIDByIndex(i)
  620. if(posNumber != -1){
  621. node.active = true;
  622. let mapDataPos = this.battleControl.getPosition(posNumber)
  623. let pos = MapDataPosToView(mapDataPos.x,mapDataPos.y)
  624. node.position = pos
  625. let posData: PosData = this.attackPosList[i]
  626. if(i < BattleUtil.AttackListSize-this.lockAttackPosNumber){
  627. node.getChildByName("lock").active = false
  628. if(!posData){
  629. posData = {
  630. node: node,
  631. hero: null,
  632. bLock: false,
  633. posIndex: BattleUtil.BagListSize+i,
  634. pos: new Vec3(pos.x, pos.y, 0),
  635. posNumber: posNumber
  636. }
  637. this.attackPosList.push(posData);
  638. }
  639. else{
  640. posData.posIndex = BattleUtil.BagListSize+i;
  641. posData.pos = new Vec3(pos.x, pos.y, 0);
  642. posData.posNumber = posNumber;
  643. if(posData.hero){
  644. posData.hero.position = posData.pos;
  645. }
  646. }
  647. this.attackPosMap.set(posNumber, posData);
  648. }
  649. else{
  650. if(posData){
  651. if(posData.hero){
  652. posData.hero.removeFromParent();
  653. }
  654. this.attackPosList.splice(i);
  655. }
  656. node.getChildByName("lock").active = true
  657. }
  658. }
  659. else {
  660. node.active = false;
  661. }
  662. }
  663. let path = "texture/tower/"+mapConf.Background+"/spriteFrame"
  664. this.load("package",path, SpriteFrame, (res: SpriteFrame) => {
  665. this.mapSprite.spriteFrame = res
  666. })
  667. let processe = BattlesConf.data[this.battlesID].Process
  668. this.mapName.string = StringUtil.getLanguageData(mapConf.Name,[processe])
  669. tween(this.battlesProgressBar).to(0.5, { progress: ((processe-1)%5)/4 }).start()
  670. let curValue = processe-((processe-1)%5)
  671. for (let i = 0; i < 5; i++) {
  672. let node = this.levelValue[i];
  673. node.string = (curValue+i).toString()
  674. }
  675. this.bStart = false;
  676. // this.waitTime = 5;
  677. this.gameTime = 0;
  678. this.powerCur = UserData.status.food
  679. this.radiusNode.active = false;
  680. this.damageCountData.clear()
  681. this.resultNode.active = false
  682. this.updateDamageCount()
  683. }
  684. private initPool() {
  685. //初始化池
  686. let queue = new AsyncQueue();
  687. queue.pushMulti("InitPool", async (next: NextFunction, params: any, args: any) => {
  688. Framework.tips.setTipsNode("package", "prefab/ui/tips/tips_flash", "Label", () => {
  689. next && next();
  690. });
  691. });
  692. queue.complete = () => {
  693. //this._loginEx();
  694. };
  695. queue.play();
  696. //this._loginEx();
  697. this.loadHeroModel()
  698. }
  699. //添加一个新英雄
  700. addHero() {
  701. if(this.loadHeroModelNum < this.loadHeroModelNumMax){
  702. console.log("英雄没加载完成");
  703. return;
  704. }
  705. let posID = -1;
  706. if(this.powerCur <= 0){
  707. console.log("没有精力了");
  708. return;
  709. }
  710. for (let i = 0; i < BattleUtil.BagListSize; i++) {
  711. let bagPos = this.bagPosList[i];
  712. if(!bagPos.bLock && bagPos.hero == null){
  713. posID = this.bagPosList[i].posIndex;
  714. break;
  715. }
  716. }
  717. if(posID == -1) {
  718. console.log("没有空位了");
  719. return;
  720. }
  721. //添加英雄
  722. let heroIndex = Math.floor(Math.random() * this.loadHeroModelNum)%this.loadHeroModelNum;
  723. let heroID = this.fightRole[heroIndex];
  724. if(heroID == 0){
  725. for(let i = 0; i < this.fightRole.length; i++){
  726. heroID = this.fightRole[i];
  727. if(heroID != 0){
  728. break;
  729. }
  730. }
  731. }
  732. let heroData = HeroDataPool.getObject();
  733. heroData.init(heroID,1,1)
  734. let node:Node = null;
  735. if(this.heroPool[heroID] == null){
  736. this.heroPool[heroID] = [];
  737. }
  738. else {
  739. if(this.heroPool[heroID].length > 0){
  740. node = this.heroPool[heroID].pop();
  741. }
  742. }
  743. if(node == null){
  744. node = instantiate(this.heroModelMap.get(heroID));
  745. node.parent = this.roleNode;
  746. this.heroList.push(node);
  747. }
  748. let hero = node.getComponent(Hero);
  749. hero.resetData(heroData);
  750. HeroDataPool.putObject(heroData);
  751. hero.posIndex = posID;
  752. let posData = this.bagPosList[posID];
  753. if(!posData){
  754. return;
  755. }
  756. posData.hero = node;
  757. node.position = posData.pos;
  758. //记录添加英雄操作
  759. let otps:BattleOptsNew ={
  760. type:BattleOptsType.New,
  761. pos:BattleLayoutPos[posData.posIndex],
  762. level:1,
  763. raceID:Math.floor(heroData.typeID/HeroRaceSacle),
  764. }
  765. this.operateList.push(otps);
  766. console.log("添加英雄", node.position);
  767. this.powerLabel.string = `${this.powerCur}/${this.powerMax}`;
  768. this.powerCur--;
  769. this.checkMerge(node);
  770. }
  771. /**
  772. * 添加一个已有数据的英雄
  773. * @param typeID 类型
  774. * @param level 等级
  775. * @param posIndex 所处位置下标
  776. * @returns
  777. */
  778. addHeroWithData( typeID:number,level:number, posIndex:number) {
  779. //添加英雄
  780. if(this.loadHeroModelNum < this.loadHeroModelNumMax){
  781. console.log("英雄没加载完成");
  782. return;
  783. }
  784. // let heroIndex = Math.floor(Math.random() * this.loadHeroModelNum)%this.loadHeroModelNum;
  785. let heroID = typeID;
  786. let heroData = HeroDataPool.getObject();
  787. heroData.init(heroID,level,1)
  788. let node:Node = null;
  789. if(this.heroPool[heroID] == null){
  790. this.heroPool[heroID] = [];
  791. }
  792. else {
  793. if(this.heroPool[heroID].length > 0){
  794. node = this.heroPool[heroID].pop();
  795. }
  796. }
  797. if(node == null){
  798. node = instantiate(this.heroModelMap.get(heroID));
  799. node.parent = this.roleNode;
  800. this.heroList.push(node);
  801. }
  802. let hero = node.getComponent(Hero);
  803. hero.resetData(heroData);
  804. HeroDataPool.putObject(heroData);
  805. hero.posIndex = posIndex;
  806. let posData = this.bagPosList[posIndex];
  807. if(!posData){
  808. posData = this.attackPosList[posIndex-BattleUtil.BagListSize];
  809. this.battleControl.addHeroInPos(hero.typeID,hero.level,posIndex - BattleUtil.BagListSize)
  810. }
  811. if(!posData){
  812. return;
  813. }
  814. posData.hero = node;
  815. node.position = posData.pos;
  816. }
  817. checkMerge(node:Node) {
  818. let hero = node.getComponent(Hero);
  819. if(!hero) {
  820. return;
  821. }
  822. let bFind = false;
  823. if(this.isAutoMerge && !hero.isLock && hero.posIndex < BattleUtil.BagListSize){
  824. for (let i = 0; i < this.attackPosList.length; i++) {
  825. let dstPosData = this.attackPosList[i];
  826. if(dstPosData.hero != null && dstPosData.hero != node){
  827. let dstHero = dstPosData.hero.getComponent(Hero);
  828. if((!dstHero.isLock) && dstHero.typeID == hero.typeID && dstHero.level == hero.level){
  829. if(this.mergeHero(node, dstPosData.hero)){
  830. bFind = true;
  831. break;
  832. }
  833. }
  834. }
  835. }
  836. if(!bFind){
  837. for (let i = 0; i < BattleUtil.BagListSize; i++) {
  838. let dstPosData = this.bagPosList[i];
  839. if(dstPosData.hero != null && dstPosData.hero != node){
  840. let dstHero = dstPosData.hero.getComponent(Hero);
  841. if((!dstHero.isLock) && dstHero.typeID == hero.typeID && dstHero.level == hero.level){
  842. if(this.mergeHero(node, dstPosData.hero))
  843. break;
  844. }
  845. }
  846. }
  847. }
  848. }
  849. }
  850. //合并英雄
  851. mergeHero(srcNode:Node, dstNode:Node) {
  852. let dstHero = dstNode.getComponent(Hero);
  853. if(dstHero.isLock){
  854. return false;
  855. }
  856. dstHero.isLock = true;
  857. // srcNode.setSiblingIndex(BattleUtil.BagListSize+this.attackPosList.length)
  858. srcNode.getComponent(Hero).flyTo(dstNode.position,()=>{
  859. if(isValid(dstHero)){
  860. dstHero.isLock = false;
  861. dstHero.levelUp()
  862. if(dstHero.posIndex >= BattleUtil.BagListSize){
  863. let index = dstHero.posIndex - BattleUtil.BagListSize;
  864. this.battleControl.levelUp(index)
  865. }
  866. this.levelUpEffectIndex = this.levelUpEffectIndex++%this.levelUpEffect.length;
  867. this.levelUpEffect[this.levelUpEffectIndex].position = dstNode.position
  868. this.levelUpEffect[this.levelUpEffectIndex].active = true
  869. this.levelUpEffect[this.levelUpEffectIndex].getComponent(sp.Skeleton).setAnimation(0, "animation", false)
  870. this.removeHeroPos(srcNode)
  871. this.checkMerge(dstNode)
  872. }
  873. })
  874. //记录合并英雄操作
  875. let opts:BattleOptsMerge = {
  876. type:BattleOptsType.Merge,
  877. srcPos:BattleLayoutPos[srcNode.getComponent(Hero).posIndex],
  878. targetPos:BattleLayoutPos[dstHero.posIndex],
  879. }
  880. this.operateList.push(opts)
  881. return true;
  882. }
  883. addEnemy(eventData: BattleEventData_EnemyBorn) {
  884. //添加敌人
  885. let node:Node = null;
  886. if(this.enemyPool.has(eventData.typeID) && this.enemyPool.get(eventData.typeID).length > 0){
  887. node = this.enemyPool.get(eventData.typeID).pop();
  888. }
  889. else {
  890. node = instantiate(this.ememyModelList[eventData.typeID-1]);
  891. node.parent = this.roleNode;
  892. }
  893. node.setSiblingIndex(0)
  894. node.getComponent(Enemy).resetData(eventData.typeID,eventData.ID,MapDataPosToView(eventData.position.x,eventData.position.y),eventData.life,eventData.lifeMax)
  895. node.getComponent(Enemy).startMove("move1")
  896. this.enemyMap.set(eventData.ID,node);
  897. }
  898. onClickStart() {
  899. this.bStart = true;
  900. }
  901. onClickStop() {
  902. this.bStart = false;
  903. }
  904. onClickAddHero() {
  905. Framework.audio.playEffect(AudioID.Click);
  906. this.addHero();
  907. }
  908. //重置坐标
  909. resetHeroPos(heroNode:Node) {
  910. let hero = heroNode.getComponent(Hero)
  911. if(!hero) {
  912. return;
  913. }
  914. let posID = hero.posIndex;
  915. if(posID != -1){
  916. if(posID < BattleUtil.BagListSize)
  917. heroNode.position = this.bagPosList[posID].pos;
  918. else if(posID < BattleUtil.BagListSize + this.attackPosList.length){
  919. heroNode.position = this.attackPosList[posID - BattleUtil.BagListSize].pos;
  920. this.battleControl.addHeroInPos(hero.typeID,hero.level,posID - BattleUtil.BagListSize)
  921. }
  922. }
  923. }
  924. //设置新坐标
  925. setHeroPos(hero:Node,newPosIndex:number) {
  926. let posIndex = hero.getComponent(Hero).posIndex;
  927. if(posIndex != -1){
  928. if(posIndex < BattleUtil.BagListSize){
  929. this.bagPosList[posIndex].hero = null;
  930. // console.log("setHeroPos1",posID)
  931. }else if(posIndex < BattleUtil.BagListSize + this.attackPosList.length){
  932. this.attackPosList[posIndex - BattleUtil.BagListSize].hero = null;
  933. // console.log("setHeroPos2",posID)
  934. }
  935. }
  936. else{
  937. console.error("setHeroPos error",posIndex)
  938. return;
  939. }
  940. if(newPosIndex != -1){
  941. if(newPosIndex < BattleUtil.BagListSize){
  942. this.bagPosList[newPosIndex].hero = hero;
  943. hero.position = this.bagPosList[newPosIndex].pos;
  944. }
  945. else if(newPosIndex < BattleUtil.BagListSize + this.attackPosList.length){
  946. let index = newPosIndex - BattleUtil.BagListSize;
  947. this.attackPosList[index].hero = hero;
  948. hero.position = this.attackPosList[index].pos;
  949. let heroObj = hero.getComponent(Hero)
  950. this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
  951. }
  952. hero.getComponent(Hero).posIndex = newPosIndex
  953. }
  954. else{
  955. console.log("hero move error")
  956. return
  957. }
  958. //记录交换操作
  959. let opts:BattleOptsMove = {
  960. type: BattleOptsType.Move,
  961. targetPos: BattleLayoutPos[newPosIndex],
  962. srcPos: BattleLayoutPos[posIndex],
  963. }
  964. this.operateList.push(opts)
  965. }
  966. /**
  967. * 移除英雄
  968. * @param hero 节点
  969. * @param bOtps 是否记录此次移除操作
  970. */
  971. removeHeroPos(hero:Node,bOtps:boolean = false) {
  972. let posIndex = hero.getComponent(Hero).posIndex;
  973. if(posIndex != -1){
  974. this.heroList.splice(this.heroList.indexOf(hero), 1)
  975. this.heroPool[hero.getComponent(Hero).typeID].push(hero)
  976. hero.getComponent(Hero).clearData();
  977. if(posIndex < BattleUtil.BagListSize){
  978. this.bagPosList[posIndex].hero = null;
  979. // console.log("removeHeroPos1",posID)
  980. }else if(posIndex < BattleUtil.BagListSize + this.attackPosList.length){
  981. this.attackPosList[posIndex - BattleUtil.BagListSize].hero = null;
  982. // console.log("removeHeroPos2",posID)
  983. this.battleControl.removeHeroInPos(posIndex - BattleUtil.BagListSize)
  984. }
  985. if(bOtps){
  986. let otps:BattleOptsRemove = {
  987. pos:BattleLayoutPos[posIndex],
  988. type:BattleOptsType.Remove
  989. }
  990. this.operateList.push(otps)
  991. }
  992. }
  993. }
  994. //交换位置
  995. changeHeroPos(hero1:Node,hero2:Node) {
  996. let posIndex1 = hero1.getComponent(Hero).posIndex;
  997. let posIndex2 = hero2.getComponent(Hero).posIndex;
  998. hero1.getComponent(Hero).posIndex = posIndex2
  999. hero2.getComponent(Hero).posIndex = posIndex1
  1000. if(posIndex1 != -1){
  1001. if(posIndex1 < BattleUtil.BagListSize){
  1002. hero2.position = this.bagPosList[posIndex1].pos;
  1003. this.bagPosList[posIndex1].hero = hero2;
  1004. }
  1005. else if(posIndex1 < BattleUtil.BagListSize + this.attackPosList.length){
  1006. hero2.position = this.attackPosList[posIndex1 - BattleUtil.BagListSize].pos;
  1007. let index = posIndex1 - BattleUtil.BagListSize;
  1008. this.attackPosList[index].hero = hero2;
  1009. let heroObj = hero2.getComponent(Hero)
  1010. this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
  1011. }
  1012. hero2.getComponent(Hero).stand()
  1013. }
  1014. if(posIndex2 != -1){
  1015. if(posIndex2 < BattleUtil.BagListSize){
  1016. hero1.position = this.bagPosList[posIndex2].pos;
  1017. this.bagPosList[posIndex2].hero = hero1;
  1018. }
  1019. else if(posIndex2 < BattleUtil.BagListSize + this.attackPosList.length){
  1020. hero1.position = this.attackPosList[posIndex2 - BattleUtil.BagListSize].pos;
  1021. let index = posIndex2 - BattleUtil.BagListSize;
  1022. this.attackPosList[index].hero = hero1;
  1023. let heroObj = hero1.getComponent(Hero)
  1024. this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
  1025. }
  1026. hero1.getComponent(Hero).stand()
  1027. }
  1028. //记录交换操作
  1029. let opts:BattleOptsMove = {
  1030. type: BattleOptsType.Move,
  1031. targetPos: BattleLayoutPos[posIndex2],
  1032. srcPos: BattleLayoutPos[posIndex1],
  1033. }
  1034. this.operateList.push(opts)
  1035. }
  1036. addHurt(pos:Vec3,value:number){
  1037. // console.log("addHurt",value)
  1038. let node:Node = null;
  1039. if(this.hurtPool.length > 0){
  1040. node = this.hurtPool.pop();
  1041. }
  1042. else {
  1043. node = instantiate(this.hurtModelList[0]);
  1044. node.parent = this.roleNode;
  1045. }
  1046. node.position = pos;
  1047. this.hurtList.push(node);
  1048. node.getComponent(Hurt).hurt(value,()=>{
  1049. this.hurtList.splice(this.hurtList.indexOf(node), 1)
  1050. this.hurtPool.push(node)
  1051. })
  1052. }
  1053. updateSiblingIndex() {
  1054. let children = this.roleNode.children
  1055. children.sort((a, b) => {
  1056. let battleNodeA = a.getComponent(BattleNodeBase);
  1057. let battleNodeB = b.getComponent(BattleNodeBase);
  1058. if (!battleNodeA || !battleNodeB) {
  1059. return 0;
  1060. }
  1061. let priorityA = battleNodeA.priority
  1062. let priorityB = battleNodeB.priority
  1063. if (priorityA != priorityB) {
  1064. return priorityA - priorityB;
  1065. }
  1066. if(this.touchStart == b){
  1067. return -1;
  1068. }
  1069. if(this.touchStart == a){
  1070. return 1;
  1071. }
  1072. //特殊状态
  1073. if(battleNodeB.isLock){
  1074. return -1;
  1075. }
  1076. if(battleNodeA.isLock){
  1077. return 1;
  1078. }
  1079. if (a.position.y != b.position.y) {
  1080. return b.position.y - a.position.y;
  1081. }
  1082. else {
  1083. a.position.x - b.position.x
  1084. }
  1085. });
  1086. for (let i = 0; i < children.length; i++) {
  1087. children[i].setSiblingIndex(i);
  1088. }
  1089. }
  1090. setRadius(radius:number){
  1091. this.radiusNode.scale = v3(0.4*radius,0.4*radius,1)
  1092. }
  1093. updateDamageCount(){
  1094. let num = 0
  1095. let allEnemyHP = this.battleControl.allEnemyHP
  1096. this.damageCountData.forEach((value,typeID)=>{
  1097. let countNode = this.countList[num]
  1098. if(num < this.countList.length){
  1099. this.countList[num].active = true
  1100. }
  1101. if(countNode){
  1102. let headSprite = countNode.getChildByName("head").getComponent(Sprite)
  1103. let valueLabel = countNode.getChildByName("number")
  1104. let progress = countNode.getChildByName("progress").getComponent(UITransform)
  1105. MaterialUtil.getHeadByID(typeID,headSprite)
  1106. //headSprite.getComponent(Sprite).spriteFrame = this.headSprite[typeID]
  1107. valueLabel.getComponent(Label).string = StringUtil.bigNumberToStr(value)
  1108. let progressWidth = value/allEnemyHP*84
  1109. if(progressWidth > 84){
  1110. progressWidth = 84
  1111. }
  1112. progress.setContentSize(progressWidth,20)
  1113. }
  1114. num++
  1115. })
  1116. for(let i = num;i<this.countList.length;i++){
  1117. this.countList[i].active = false
  1118. }
  1119. }
  1120. setDamageCount(typeID:number,value:number){
  1121. let valueOld = this.damageCountData.get(typeID) || 0
  1122. this.damageCountData.set(typeID,value+valueOld)
  1123. }
  1124. private onTouchButton(event: Event, customStr) {
  1125. let target: any = event.target;
  1126. if (target.name == 'mask') {
  1127. Framework.layer.close(this);
  1128. } else if (target.name == 'hanghui_btn') {
  1129. RoleManager.getNewRole()
  1130. } else if (target.name == 'hero_btn') {
  1131. Framework.layer.open(ViewID.HeroList);
  1132. } else if (target.name == 'material_btn') {
  1133. LoginMgr.sendPost('tavern', 'get', (data) => {
  1134. console.log(data);
  1135. }, {})
  1136. } else if (target.name == 'mail_btn') {
  1137. MailManager.sendGetMailMsg({ ids: [MailData.getMaxMailId(0), MailData.getMaxMailId(1)] }, () => {
  1138. Framework.layer.open(ViewID.MailMain);
  1139. })
  1140. }else if (target.name == 'title_bg'){
  1141. this.rewardChapterNode.getComponent(RewardChapter) .show();
  1142. }
  1143. }
  1144. //{typeID:number,value:number}
  1145. private bossUpdate(data:EnemyActionType){
  1146. switch(data){
  1147. case EnemyActionType.Born:
  1148. break;
  1149. case EnemyActionType.Die:
  1150. break;
  1151. case EnemyActionType.Hurt:
  1152. break;
  1153. case EnemyActionType.Move:
  1154. break;
  1155. }
  1156. }
  1157. private loadHeroModel(){
  1158. let fightRole = RoleData.fightRole
  1159. this.fightRole = fightRole
  1160. this.loadHeroModelNum = 0
  1161. this.loadHeroModelNumMax = 0
  1162. fightRole.forEach(element => {
  1163. if(element > 0 ){
  1164. this.loadHeroModelNumMax ++
  1165. if(!this.heroModelMap.has(element)){
  1166. let url = "prefab/ui/tower/hero/role"+element
  1167. this.load("package",url,Prefab,(prefab:Prefab)=>{
  1168. this.heroModelMap.set(element,prefab)
  1169. this.loadHeroModelNum++
  1170. if(this.loadHeroModelNum == this.loadHeroModelNumMax){
  1171. this.resetBattleLayout()
  1172. }
  1173. })
  1174. }
  1175. else{
  1176. this.loadHeroModelNum++
  1177. }
  1178. }
  1179. });
  1180. }
  1181. private resetBattleLayout(){
  1182. //添加初始英雄
  1183. for (let i = 0; i < BattleData.layout.length; i++) {
  1184. let value = BattleData.layout[i];
  1185. if(value > 0){
  1186. let battleLayoutData = BattleManager.getDataWithLayoutValue(value)
  1187. this.addHeroWithData(battleLayoutData.typeID,battleLayoutData.level,i)
  1188. }
  1189. }
  1190. }
  1191. //重新开始第x关
  1192. private restartBattle(battlesID){
  1193. this.enemyMap.forEach((enemy, enemyID) => {
  1194. enemy.getComponent(Enemy).clearData();
  1195. this.enemyMap.delete(enemyID);
  1196. let typeID = enemy.getComponent(Enemy).typeID
  1197. if(this.enemyPool.has(typeID)){
  1198. this.enemyPool.get(typeID).push(enemy);
  1199. }
  1200. else {
  1201. this.enemyPool.set(typeID,[enemy]);
  1202. }
  1203. })
  1204. this.battlesID = battlesID;
  1205. this.battleControl.reset(this.battlesID)
  1206. this.reset()
  1207. for(let index = 0; index < this.attackPosList.length; index++){
  1208. let hero = this.attackPosList[index].hero;
  1209. if(hero){
  1210. hero.position = this.attackPosList[index].pos;
  1211. let heroObj = hero.getComponent(Hero)
  1212. this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
  1213. }
  1214. }
  1215. this.bStart = true;
  1216. }
  1217. }