TowerUI.ts 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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. Framework.layer.open(ViewID.HeroFate);
  1134. } else if (target.name == 'mail_btn') {
  1135. MailManager.sendGetMailMsg({ ids: [MailData.getMaxMailId(0), MailData.getMaxMailId(1)] }, () => {
  1136. Framework.layer.open(ViewID.MailMain);
  1137. })
  1138. }else if (target.name == 'title_bg'){
  1139. this.rewardChapterNode.getComponent(RewardChapter) .show();
  1140. }
  1141. }
  1142. //{typeID:number,value:number}
  1143. private bossUpdate(data:EnemyActionType){
  1144. switch(data){
  1145. case EnemyActionType.Born:
  1146. break;
  1147. case EnemyActionType.Die:
  1148. break;
  1149. case EnemyActionType.Hurt:
  1150. break;
  1151. case EnemyActionType.Move:
  1152. break;
  1153. }
  1154. }
  1155. private loadHeroModel(){
  1156. let fightRole = RoleData.fightRole
  1157. this.fightRole = fightRole
  1158. this.loadHeroModelNum = 0
  1159. this.loadHeroModelNumMax = 0
  1160. fightRole.forEach(element => {
  1161. if(element > 0 ){
  1162. this.loadHeroModelNumMax ++
  1163. if(!this.heroModelMap.has(element)){
  1164. let url = "prefab/ui/tower/hero/role"+element
  1165. this.load("package",url,Prefab,(prefab:Prefab)=>{
  1166. this.heroModelMap.set(element,prefab)
  1167. this.loadHeroModelNum++
  1168. if(this.loadHeroModelNum == this.loadHeroModelNumMax){
  1169. this.resetBattleLayout()
  1170. }
  1171. })
  1172. }
  1173. else{
  1174. this.loadHeroModelNum++
  1175. }
  1176. }
  1177. });
  1178. }
  1179. private resetBattleLayout(){
  1180. //添加初始英雄
  1181. for (let i = 0; i < BattleData.layout.length; i++) {
  1182. let value = BattleData.layout[i];
  1183. if(value > 0){
  1184. let battleLayoutData = BattleManager.getDataWithLayoutValue(value)
  1185. this.addHeroWithData(battleLayoutData.typeID,battleLayoutData.level,i)
  1186. }
  1187. }
  1188. }
  1189. //重新开始第x关
  1190. private restartBattle(battlesID){
  1191. this.enemyMap.forEach((enemy, enemyID) => {
  1192. enemy.getComponent(Enemy).clearData();
  1193. this.enemyMap.delete(enemyID);
  1194. let typeID = enemy.getComponent(Enemy).typeID
  1195. if(this.enemyPool.has(typeID)){
  1196. this.enemyPool.get(typeID).push(enemy);
  1197. }
  1198. else {
  1199. this.enemyPool.set(typeID,[enemy]);
  1200. }
  1201. })
  1202. this.battlesID = battlesID;
  1203. this.battleControl.reset(this.battlesID)
  1204. this.reset()
  1205. for(let index = 0; index < this.attackPosList.length; index++){
  1206. let hero = this.attackPosList[index].hero;
  1207. if(hero){
  1208. hero.position = this.attackPosList[index].pos;
  1209. let heroObj = hero.getComponent(Hero)
  1210. this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
  1211. }
  1212. }
  1213. this.bStart = true;
  1214. }
  1215. }