TowerUI.ts 36 KB

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