|
@@ -15,7 +15,7 @@ import { BattleEventManager } from './base/BattleEventManager';
|
|
|
import { BattleEventData_EnemyBorn, BattleEventData_EnemyBuff, BattleEventData_EnemyDie, BattleEventData_EnemyHurt, BattleEventData_EnemyMove, BattleEventData_HeroAction, BattleEventData_HeroAttack, BattleEventData_Over, BattleEventTarget, BattleEventType, EnemyActionType, TowerUUID } from './base/BattleEventUtil';
|
|
|
import { MapConf } from './conf/MapConf';
|
|
|
import { isValid } from 'cc';
|
|
|
-import { HeroDataPool } from './data/HeroData';
|
|
|
+import { HeroDataPool, HeroRaceSacle } from './data/HeroData';
|
|
|
import { StringUtil } from '../../../framework/util/StringUtil';
|
|
|
import { MaterialUtil } from '../../../framework/util/MaterialUtil';
|
|
|
import { BattlesConf } from './conf/BattlesConf';
|
|
@@ -25,6 +25,10 @@ import { MailManager } from '../../manager/MailManager';
|
|
|
import { ViewID } from '../../../framework/config/LayerConf';
|
|
|
import { MailData } from '../../data/MailData';
|
|
|
import { RoleManager } from '../../manager/RoleManager';
|
|
|
+import { RoleData } from '../../data/RoleData';
|
|
|
+import { BattleData, BattleLayoutPos, BattleLayoutScale, BattleOptsBase, BattleOptsKill, BattleOptsMerge, BattleOptsMove, BattleOptsNew, BattleOptsRemove, BattleOptsType } from '../../data/BattleData';
|
|
|
+import { BattleManager } from '../../manager/BattleManager';
|
|
|
+import { UserData } from '../../data/UserData';
|
|
|
|
|
|
//地图比例尺 1:70
|
|
|
let mapScale = 72;
|
|
@@ -49,12 +53,18 @@ let MapDataSpeedToView = (x:number,y:number) => {
|
|
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
+//可操作格子:背包格子和战斗格子
|
|
|
export interface PosData {
|
|
|
+ //格子节点
|
|
|
node: Node,
|
|
|
+ //格子上的英雄
|
|
|
hero: Node,
|
|
|
+ //格子是否锁
|
|
|
bLock: boolean,
|
|
|
- posID: number,
|
|
|
+ //格子下标
|
|
|
+ posIndex: number,
|
|
|
pos: Vec3,
|
|
|
+ //地图编号
|
|
|
posNumber: number
|
|
|
}
|
|
|
|
|
@@ -81,9 +91,6 @@ export class TowerUI extends BaseView {
|
|
|
//背包位
|
|
|
bagPosList: PosData[] = [];
|
|
|
|
|
|
- @property({ type: [Prefab], tooltip: "英雄" })
|
|
|
- heroModelList: Prefab[] = [];
|
|
|
- heroPool: Map<number,Node[]> = new Map();
|
|
|
heroList: Node[] = [];
|
|
|
@property({type:[Node],tooltip:"升级效果"})
|
|
|
levelUpEffect:Node[] = []
|
|
@@ -123,6 +130,9 @@ export class TowerUI extends BaseView {
|
|
|
bStart = false;
|
|
|
waitTime = 5;
|
|
|
touchStart: Node = null;
|
|
|
+ //记录连击
|
|
|
+ touchEndIndex = -1;
|
|
|
+ touchEndTime = 0;
|
|
|
gameTime = 0;
|
|
|
|
|
|
//当前精力
|
|
@@ -141,6 +151,23 @@ export class TowerUI extends BaseView {
|
|
|
levelUpEffectIndex = 0;
|
|
|
//是否自动合成
|
|
|
isAutoMerge = false;
|
|
|
+ //英雄处理-------
|
|
|
+ //英雄模型加载数量
|
|
|
+ loadHeroModelNum: number = 0;
|
|
|
+ //英雄模型加载数量上限
|
|
|
+ loadHeroModelNumMax: number = -1;
|
|
|
+ heroModelMap:Map<number,Prefab> = new Map();
|
|
|
+ heroPool: Map<number,Node[]> = new Map();
|
|
|
+ //出战角色
|
|
|
+ fightRole = [0,0,0,0]
|
|
|
+ //锁定格子
|
|
|
+ lockBagPosNumber = 6;
|
|
|
+ lockAttackPosNumber = 8;
|
|
|
+
|
|
|
+ //操作指令集 记录下来发给服务器
|
|
|
+ operateList:Array<BattleOptsBase> = [];
|
|
|
+
|
|
|
+
|
|
|
|
|
|
protected onLoad() {
|
|
|
super.onLoad();
|
|
@@ -160,6 +187,7 @@ export class TowerUI extends BaseView {
|
|
|
|
|
|
Framework.event.addEvent(GameEvent.BossUpdate, this.bossUpdate.bind(this),this)
|
|
|
|
|
|
+
|
|
|
this.initPool()
|
|
|
}
|
|
|
protected start(): void {
|
|
@@ -218,6 +246,13 @@ export class TowerUI extends BaseView {
|
|
|
this.bStart = true;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if(this.touchEndTime > 0){
|
|
|
+ this.touchEndTime -= dt;
|
|
|
+ if(this.touchEndTime <= 0){
|
|
|
+ this.touchEndIndex = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -256,6 +291,7 @@ export class TowerUI extends BaseView {
|
|
|
case BattleEventType.EnemyDie:{
|
|
|
// console.log("死亡",event)
|
|
|
let enemyData = event as BattleEventData_EnemyDie;
|
|
|
+
|
|
|
if(this.enemyMap.has(enemyData.ID)){
|
|
|
let enemy = this.enemyMap.get(enemyData.ID);
|
|
|
enemy.getComponent(Enemy).die(()=>{
|
|
@@ -272,6 +308,13 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
+ //记录击杀敌人的操作
|
|
|
+ let otps:BattleOptsKill = {
|
|
|
+ count:1,
|
|
|
+ type:BattleOptsType.Kill,
|
|
|
+ typeID:enemyData.typeID
|
|
|
+ }
|
|
|
+ this.operateList.push(otps);
|
|
|
break;
|
|
|
}
|
|
|
case BattleEventType.EnemyBuff:{
|
|
@@ -338,32 +381,59 @@ export class TowerUI extends BaseView {
|
|
|
|
|
|
let winStr = attackData.bWin ? "胜利" : "失败";
|
|
|
console.log(winStr)
|
|
|
+ if(attackData.bWin){
|
|
|
+
|
|
|
+ let layout = {}
|
|
|
+ for(let index = 0; index < this.bagPosList.length; index++){
|
|
|
+ let posData = this.bagPosList[index]
|
|
|
+ let key = BattleLayoutPos[index]
|
|
|
+ layout[key] = 0
|
|
|
+ if(posData.hero){
|
|
|
+ let heroData = posData.hero.getComponent(Hero)
|
|
|
+ let value = heroData.level + heroData.raceID *BattleLayoutScale
|
|
|
+ if(key){
|
|
|
+ layout[key] = value
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- tween(this.node).delay(3).call(()=>{
|
|
|
- this.enemyMap.forEach((enemy, enemyID) => {
|
|
|
- enemy.getComponent(Enemy).clearData();
|
|
|
- this.enemyMap.delete(enemyID);
|
|
|
- let typeID = enemy.getComponent(Enemy).typeID
|
|
|
- if(this.enemyPool.has(typeID)){
|
|
|
- this.enemyPool.get(typeID).push(enemy);
|
|
|
+ //战场占位数量跟背包一样
|
|
|
+ for(let index = 0; index < BattleUtil.BagListSize; index++){
|
|
|
+ let posData = this.attackPosList[index]
|
|
|
+ let key = BattleLayoutPos[index+BattleUtil.BagListSize]
|
|
|
+ if(key){
|
|
|
+ if(posData && posData.hero){
|
|
|
+ let heroData = posData.hero.getComponent(Hero)
|
|
|
+ let value = heroData.level + heroData.raceID *BattleLayoutScale
|
|
|
+ layout[key] = value
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ layout[key] = 0
|
|
|
+ }
|
|
|
}
|
|
|
- else {
|
|
|
- this.enemyPool.set(typeID,[enemy]);
|
|
|
+ }
|
|
|
+
|
|
|
+ BattleManager.sendBattleDuplicateMsg(this.battlesID,attackData.bWin,layout,this.operateList,()=>{
|
|
|
+ if(this.battlesID == 20){
|
|
|
+ this.reStartBattle(this.battlesID)
|
|
|
}
|
|
|
- })
|
|
|
- this.battlesID = (this.battlesID+3) %20+1;
|
|
|
- this.battleControl.reset(this.battlesID)
|
|
|
- this.reset()
|
|
|
-
|
|
|
- for(let index = 0; index < this.attackPosList.length; index++){
|
|
|
- let hero = this.attackPosList[index].hero;
|
|
|
- if(hero){
|
|
|
- hero.position = this.attackPosList[index].pos;
|
|
|
- let heroObj = hero.getComponent(Hero)
|
|
|
- this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
|
|
|
+ else{
|
|
|
+ this.reStartBattle(this.battlesID+1)
|
|
|
}
|
|
|
+ },()=>{
|
|
|
+ this.reStartBattle(this.battlesID)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ if(this.battlesID%5 != 1){
|
|
|
+ this.reStartBattle(this.battlesID-1)
|
|
|
}
|
|
|
- }).start();
|
|
|
+ else{
|
|
|
+ this.reStartBattle(this.battlesID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -385,7 +455,7 @@ export class TowerUI extends BaseView {
|
|
|
this.touchStart = posData.hero;
|
|
|
hero.stand()
|
|
|
this.touchStart.setSiblingIndex(30);
|
|
|
- let index = posData.posID - BattleUtil.BagListSize
|
|
|
+ let index = posData.posIndex - BattleUtil.BagListSize
|
|
|
if(index >= 0){
|
|
|
this.battleControl.removeHeroInPos(index)
|
|
|
}
|
|
@@ -397,7 +467,7 @@ export class TowerUI extends BaseView {
|
|
|
if (this.touchStart ) {
|
|
|
this.touchStart .setPosition(this.roleNode.getComponent(UITransform).convertToNodeSpaceAR(new Vec3(event.getUILocation().x, event.getUILocation().y)))
|
|
|
let posData = this.getItemBaseByPosition(event.getLocation());
|
|
|
- if(posData&&(posData.posID >= BattleUtil.BagListSize)){
|
|
|
+ if(posData&&(posData.posIndex >= BattleUtil.BagListSize)){
|
|
|
this.radiusNode.position = v3(this.touchStart.position.x,this.touchStart.position.y);
|
|
|
this.radiusNode.active = true;
|
|
|
this.setRadius(this.touchStart.getComponent(Hero).radius)
|
|
@@ -416,22 +486,39 @@ export class TowerUI extends BaseView {
|
|
|
if (this.touchStart) {
|
|
|
let posData = this.getItemBaseByPosition(event.getLocation());
|
|
|
let touchEnd:Node = null
|
|
|
- if(posData && posData.hero != this.touchStart){
|
|
|
-
|
|
|
- if(posData.hero){
|
|
|
- let hero = posData.hero.getComponent(Hero);
|
|
|
- if(hero && hero.isLock){
|
|
|
- this.resetHeroPos(this.touchStart)
|
|
|
- this.touchStart = null;
|
|
|
- return;
|
|
|
+ if(posData){
|
|
|
+ if(posData.hero == this.touchStart){
|
|
|
+ if(this.touchEndIndex == posData.posIndex){
|
|
|
+ this.touchEndIndex = -1
|
|
|
+ if(posData.posIndex < BattleUtil.BagListSize){
|
|
|
+ this.removeHeroPos(this.touchStart,true)
|
|
|
+ this.touchStart = null;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.touchEndIndex = posData.posIndex
|
|
|
+ this.touchEndTime = 1
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- touchEnd = posData.hero;
|
|
|
+ else{
|
|
|
+ if(posData.hero){
|
|
|
+ let hero = posData.hero.getComponent(Hero);
|
|
|
+ if(hero && hero.isLock){
|
|
|
+ this.resetHeroPos(this.touchStart)
|
|
|
+ this.touchStart = null;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ touchEnd = posData.hero;
|
|
|
+ this.touchEndIndex = -1
|
|
|
+ }
|
|
|
}
|
|
|
else{
|
|
|
this.resetHeroPos(this.touchStart)
|
|
|
this.touchStart = null;
|
|
|
+ this.touchEndIndex = -1
|
|
|
return
|
|
|
}
|
|
|
if(touchEnd){
|
|
@@ -446,7 +533,7 @@ export class TowerUI extends BaseView {
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
- this.setHeroPos(this.touchStart, posData.posID)
|
|
|
+ this.setHeroPos(this.touchStart, posData.posIndex)
|
|
|
}
|
|
|
this.touchStart = null;
|
|
|
}
|
|
@@ -465,6 +552,7 @@ export class TowerUI extends BaseView {
|
|
|
let FindArr = this.bagPosList
|
|
|
|
|
|
let bag = FindArr.find(t => {
|
|
|
+ if(t.bLock) return false
|
|
|
if(t.hero && t.hero != this.touchStart){
|
|
|
return t.hero.getComponent(Hero).hitTest(pos)
|
|
|
}
|
|
@@ -523,7 +611,7 @@ export class TowerUI extends BaseView {
|
|
|
node: node,
|
|
|
hero: null,
|
|
|
bLock: false,
|
|
|
- posID: posID,
|
|
|
+ posIndex: posID,
|
|
|
pos: pos,
|
|
|
posNumber: -1
|
|
|
}
|
|
@@ -533,6 +621,8 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
|
|
|
this.reset()
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
reset(){
|
|
@@ -542,6 +632,8 @@ export class TowerUI extends BaseView {
|
|
|
console.log("战斗配置错误")
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ this.lockAttackPosNumber = BattleUtil.AttackListSize-battleConf.Unlock
|
|
|
|
|
|
let mapConf = MapConf.data[this.battleControl.mapID.toString()]
|
|
|
if(!mapConf){
|
|
@@ -558,35 +650,69 @@ export class TowerUI extends BaseView {
|
|
|
baseOffset.y = 0
|
|
|
}
|
|
|
let attackChildren = this.attackNode.children
|
|
|
- for (let i = 0; i < attackChildren.length; i++) {
|
|
|
+ let attackNode = this.attackNode.children[0]
|
|
|
+ // this.attackPosList = []
|
|
|
+ this.attackPosMap.clear()
|
|
|
+
|
|
|
+ for (let i = 0; i < BattleUtil.BagListSize; i++) {
|
|
|
+ let posData = this.bagPosList[i];
|
|
|
+ if(i < BattleUtil.BagListSize-this.lockBagPosNumber){
|
|
|
+ posData.node.getChildByName("lock").active = false
|
|
|
+ posData.bLock = false
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ posData.bLock = true
|
|
|
+ posData.node.getChildByName("lock").active = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (let i = 0; i < BattleUtil.AttackListSize; i++) {
|
|
|
let node = attackChildren[i];
|
|
|
+ if(!node){
|
|
|
+ node = instantiate(attackNode)
|
|
|
+ this.attackNode.addChild(node)
|
|
|
+ }
|
|
|
+
|
|
|
let posNumber = this.battleControl.getPosIDByIndex(i)
|
|
|
if(posNumber != -1){
|
|
|
node.active = true;
|
|
|
let mapDataPos = this.battleControl.getPosition(posNumber)
|
|
|
- let posXX = MapDataPosToView(mapDataPos.x,mapDataPos.y)
|
|
|
- node.position = posXX
|
|
|
+ let pos = MapDataPosToView(mapDataPos.x,mapDataPos.y)
|
|
|
+ node.position = pos
|
|
|
let posData: PosData = this.attackPosList[i]
|
|
|
- if(!posData){
|
|
|
- posData = {
|
|
|
- node: node,
|
|
|
- hero: null,
|
|
|
- bLock: false,
|
|
|
- posID: BattleUtil.BagListSize+i,
|
|
|
- pos: new Vec3(posXX.x, posXX.y, 0),
|
|
|
- posNumber: posNumber
|
|
|
+ if(i < BattleUtil.AttackListSize-this.lockAttackPosNumber){
|
|
|
+ node.getChildByName("lock").active = false
|
|
|
+ if(!posData){
|
|
|
+ posData = {
|
|
|
+ node: node,
|
|
|
+ hero: null,
|
|
|
+ bLock: false,
|
|
|
+ posIndex: BattleUtil.BagListSize+i,
|
|
|
+ pos: new Vec3(pos.x, pos.y, 0),
|
|
|
+ posNumber: posNumber
|
|
|
+ }
|
|
|
+ this.attackPosList.push(posData);
|
|
|
}
|
|
|
- this.attackPosList.push(posData);
|
|
|
+ else{
|
|
|
+ posData.posIndex = BattleUtil.BagListSize+i;
|
|
|
+ posData.pos = new Vec3(pos.x, pos.y, 0);
|
|
|
+ posData.posNumber = posNumber;
|
|
|
+ if(posData.hero){
|
|
|
+ posData.hero.position = posData.pos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.attackPosMap.set(posNumber, posData);
|
|
|
}
|
|
|
else{
|
|
|
- posData.posID = BattleUtil.BagListSize+i;
|
|
|
- posData.pos = new Vec3(posXX.x, posXX.y, 0);
|
|
|
- posData.posNumber = posNumber;
|
|
|
- if(posData.hero){
|
|
|
- posData.hero.position = posData.pos;
|
|
|
+ if(posData){
|
|
|
+ if(posData.hero){
|
|
|
+ posData.hero.removeFromParent();
|
|
|
+ }
|
|
|
+ this.attackPosList.splice(i);
|
|
|
}
|
|
|
+ node.getChildByName("lock").active = true
|
|
|
}
|
|
|
- this.attackPosMap.set(posNumber, posData);
|
|
|
}
|
|
|
else {
|
|
|
node.active = false;
|
|
@@ -614,6 +740,7 @@ export class TowerUI extends BaseView {
|
|
|
this.bStart = false;
|
|
|
this.waitTime = 5;
|
|
|
this.gameTime = 0;
|
|
|
+ this.powerCur = UserData.status.food
|
|
|
this.radiusNode.active = false;
|
|
|
this.damageCountData.clear()
|
|
|
this.updateDamageCount()
|
|
@@ -641,18 +768,27 @@ export class TowerUI extends BaseView {
|
|
|
queue.play();
|
|
|
|
|
|
//this._loginEx();
|
|
|
+ this.loadHeroModel()
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //添加一个新英雄
|
|
|
addHero() {
|
|
|
+
|
|
|
+ if(this.loadHeroModelNum < this.loadHeroModelNumMax){
|
|
|
+ console.log("英雄没加载完成");
|
|
|
+ return;
|
|
|
+ }
|
|
|
let posID = -1;
|
|
|
if(this.powerCur <= 0){
|
|
|
console.log("没有精力了");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
for (let i = 0; i < BattleUtil.BagListSize; i++) {
|
|
|
- if(this.bagPosList[i].hero == null){
|
|
|
- posID = this.bagPosList[i].posID;
|
|
|
+ let bagPos = this.bagPosList[i];
|
|
|
+ if(!bagPos.bLock && bagPos.hero == null){
|
|
|
+ posID = this.bagPosList[i].posIndex;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -662,9 +798,12 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
|
|
|
//添加英雄
|
|
|
- let heroID = Math.floor(Math.random() * this.heroModelList.length)%this.heroModelList.length + 1;
|
|
|
+
|
|
|
+
|
|
|
+ let heroIndex = Math.floor(Math.random() * this.loadHeroModelNum)%this.loadHeroModelNum;
|
|
|
+ let heroID = this.fightRole[heroIndex];
|
|
|
let heroData = HeroDataPool.getObject();
|
|
|
- heroData.init(heroID,1,posID)
|
|
|
+ heroData.init(heroID,1,1)
|
|
|
|
|
|
let node:Node = null;
|
|
|
if(this.heroPool[heroID] == null){
|
|
@@ -676,7 +815,7 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
}
|
|
|
if(node == null){
|
|
|
- node = instantiate(this.heroModelList[heroID-1]);
|
|
|
+ node = instantiate(this.heroModelMap.get(heroID));
|
|
|
node.parent = this.roleNode;
|
|
|
this.heroList.push(node);
|
|
|
}
|
|
@@ -685,7 +824,7 @@ export class TowerUI extends BaseView {
|
|
|
hero.resetData(heroData);
|
|
|
HeroDataPool.putObject(heroData);
|
|
|
|
|
|
- hero.posID = posID;
|
|
|
+ hero.posIndex = posID;
|
|
|
let posData = this.bagPosList[posID];
|
|
|
if(!posData){
|
|
|
return;
|
|
@@ -693,13 +832,79 @@ export class TowerUI extends BaseView {
|
|
|
posData.hero = node;
|
|
|
|
|
|
node.position = posData.pos;
|
|
|
+
|
|
|
+ //记录添加英雄操作
|
|
|
+ let otps:BattleOptsNew ={
|
|
|
+ type:BattleOptsType.New,
|
|
|
+ pos:BattleLayoutPos[posData.posIndex],
|
|
|
+ level:1,
|
|
|
+ raceID:Math.floor(heroData.typeID/HeroRaceSacle),
|
|
|
+
|
|
|
+ }
|
|
|
+ this.operateList.push(otps);
|
|
|
+
|
|
|
console.log("添加英雄", node.position);
|
|
|
this.powerLabel.string = `${this.powerCur}/${this.powerMax}`;
|
|
|
this.powerCur--;
|
|
|
|
|
|
this.checkMerge(node);
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加一个已有数据的英雄
|
|
|
+ * @param typeID 类型
|
|
|
+ * @param level 等级
|
|
|
+ * @param posIndex 所处位置下标
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ addHeroWithData( typeID:number,level:number, posIndex:number) {
|
|
|
+
|
|
|
+ //添加英雄
|
|
|
+ if(this.loadHeroModelNum < this.loadHeroModelNumMax){
|
|
|
+ console.log("英雄没加载完成");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // let heroIndex = Math.floor(Math.random() * this.loadHeroModelNum)%this.loadHeroModelNum;
|
|
|
+ let heroID = typeID;
|
|
|
+ let heroData = HeroDataPool.getObject();
|
|
|
+ heroData.init(heroID,1,1)
|
|
|
+
|
|
|
+ let node:Node = null;
|
|
|
+ if(this.heroPool[heroID] == null){
|
|
|
+ this.heroPool[heroID] = [];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(this.heroPool[heroID].length > 0){
|
|
|
+ node = this.heroPool[heroID].pop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(node == null){
|
|
|
+ node = instantiate(this.heroModelMap.get(heroID));
|
|
|
+ node.parent = this.roleNode;
|
|
|
+ this.heroList.push(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ let hero = node.getComponent(Hero);
|
|
|
+ hero.resetData(heroData);
|
|
|
+ HeroDataPool.putObject(heroData);
|
|
|
+
|
|
|
+ hero.posIndex = posIndex;
|
|
|
+ let posData = this.bagPosList[posIndex];
|
|
|
+ if(!posData){
|
|
|
+ posData = this.attackPosList[posIndex-BattleUtil.BagListSize];
|
|
|
+ this.battleControl.addHeroInPos(hero.typeID,hero.level,posIndex - BattleUtil.BagListSize)
|
|
|
+ }
|
|
|
+ if(!posData){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ posData.hero = node;
|
|
|
+
|
|
|
+ node.position = posData.pos;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
checkMerge(node:Node) {
|
|
|
let hero = node.getComponent(Hero);
|
|
@@ -707,7 +912,7 @@ export class TowerUI extends BaseView {
|
|
|
return;
|
|
|
}
|
|
|
let bFind = false;
|
|
|
- if(this.isAutoMerge && !hero.isLock && hero.posID < BattleUtil.BagListSize){
|
|
|
+ if(this.isAutoMerge && !hero.isLock && hero.posIndex < BattleUtil.BagListSize){
|
|
|
for (let i = 0; i < this.attackPosList.length; i++) {
|
|
|
let dstPosData = this.attackPosList[i];
|
|
|
if(dstPosData.hero != null && dstPosData.hero != node){
|
|
@@ -753,8 +958,8 @@ export class TowerUI extends BaseView {
|
|
|
if(isValid(dstHero)){
|
|
|
dstHero.isLock = false;
|
|
|
dstHero.levelUp()
|
|
|
- if(dstHero.posID >= BattleUtil.BagListSize){
|
|
|
- let index = dstHero.posID - BattleUtil.BagListSize;
|
|
|
+ if(dstHero.posIndex >= BattleUtil.BagListSize){
|
|
|
+ let index = dstHero.posIndex - BattleUtil.BagListSize;
|
|
|
this.battleControl.levelUp(index)
|
|
|
}
|
|
|
this.levelUpEffectIndex = this.levelUpEffectIndex++%this.levelUpEffect.length;
|
|
@@ -766,6 +971,15 @@ export class TowerUI extends BaseView {
|
|
|
this.checkMerge(dstNode)
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ //记录合并英雄操作
|
|
|
+ let opts:BattleOptsMerge = {
|
|
|
+ type:BattleOptsType.Merge,
|
|
|
+ srcPos:BattleLayoutPos[srcNode.getComponent(Hero).posIndex],
|
|
|
+ targetPos:BattleLayoutPos[dstHero.posIndex],
|
|
|
+ }
|
|
|
+ this.operateList.push(opts)
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -807,7 +1021,7 @@ export class TowerUI extends BaseView {
|
|
|
if(!hero) {
|
|
|
return;
|
|
|
}
|
|
|
- let posID = hero.posID;
|
|
|
+ let posID = hero.posIndex;
|
|
|
if(posID != -1){
|
|
|
if(posID < BattleUtil.BagListSize)
|
|
|
heroNode.position = this.bagPosList[posID].pos;
|
|
@@ -819,64 +1033,99 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
|
|
|
//设置新坐标
|
|
|
- setHeroPos(hero:Node,newPosID:number) {
|
|
|
- let posID = hero.getComponent(Hero).posID;
|
|
|
- if(posID != -1){
|
|
|
- if(posID < BattleUtil.BagListSize)
|
|
|
- this.bagPosList[posID].hero = null;
|
|
|
- else if(posID < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
- this.attackPosList[posID - BattleUtil.BagListSize].hero = null;
|
|
|
+ setHeroPos(hero:Node,newPosIndex:number) {
|
|
|
+ let posIndex = hero.getComponent(Hero).posIndex;
|
|
|
+ if(posIndex != -1){
|
|
|
+ if(posIndex < BattleUtil.BagListSize){
|
|
|
+ this.bagPosList[posIndex].hero = null;
|
|
|
+ // console.log("setHeroPos1",posID)
|
|
|
+ }else if(posIndex < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
+ this.attackPosList[posIndex - BattleUtil.BagListSize].hero = null;
|
|
|
+ // console.log("setHeroPos2",posID)
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ else{
|
|
|
+ console.error("setHeroPos error",posIndex)
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if(newPosID != -1){
|
|
|
- if(newPosID < BattleUtil.BagListSize){
|
|
|
- this.bagPosList[newPosID].hero = hero;
|
|
|
- hero.position = this.bagPosList[newPosID].pos;
|
|
|
+ if(newPosIndex != -1){
|
|
|
+ if(newPosIndex < BattleUtil.BagListSize){
|
|
|
+ this.bagPosList[newPosIndex].hero = hero;
|
|
|
+ hero.position = this.bagPosList[newPosIndex].pos;
|
|
|
}
|
|
|
- else if(newPosID < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
- let index = newPosID - BattleUtil.BagListSize;
|
|
|
+ else if(newPosIndex < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
+ let index = newPosIndex - BattleUtil.BagListSize;
|
|
|
this.attackPosList[index].hero = hero;
|
|
|
hero.position = this.attackPosList[index].pos;
|
|
|
let heroObj = hero.getComponent(Hero)
|
|
|
this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
|
|
|
}
|
|
|
- hero.getComponent(Hero).posID = newPosID
|
|
|
+ hero.getComponent(Hero).posIndex = newPosIndex
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ console.log("hero move error")
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ //记录交换操作
|
|
|
+ let opts:BattleOptsMove = {
|
|
|
+ type: BattleOptsType.Move,
|
|
|
+ targetPos: BattleLayoutPos[newPosIndex],
|
|
|
+ srcPos: BattleLayoutPos[posIndex],
|
|
|
+ }
|
|
|
+ this.operateList.push(opts)
|
|
|
|
|
|
}
|
|
|
|
|
|
- removeHeroPos(hero:Node) {
|
|
|
- let posID = hero.getComponent(Hero).posID;
|
|
|
- if(posID != -1){
|
|
|
+ /**
|
|
|
+ * 移除英雄
|
|
|
+ * @param hero 节点
|
|
|
+ * @param bOtps 是否记录此次移除操作
|
|
|
+ */
|
|
|
+ removeHeroPos(hero:Node,bOtps:boolean = false) {
|
|
|
+ let posIndex = hero.getComponent(Hero).posIndex;
|
|
|
+ if(posIndex != -1){
|
|
|
this.heroList.splice(this.heroList.indexOf(hero), 1)
|
|
|
this.heroPool[hero.getComponent(Hero).typeID].push(hero)
|
|
|
hero.getComponent(Hero).clearData();
|
|
|
- if(posID < BattleUtil.BagListSize)
|
|
|
- this.bagPosList[posID].hero = null;
|
|
|
- else if(posID < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
- this.attackPosList[posID - BattleUtil.BagListSize].hero = null;
|
|
|
- this.battleControl.removeHeroInPos(posID - BattleUtil.BagListSize)
|
|
|
+ if(posIndex < BattleUtil.BagListSize){
|
|
|
+ this.bagPosList[posIndex].hero = null;
|
|
|
+ // console.log("removeHeroPos1",posID)
|
|
|
+ }else if(posIndex < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
+ this.attackPosList[posIndex - BattleUtil.BagListSize].hero = null;
|
|
|
+ // console.log("removeHeroPos2",posID)
|
|
|
+ this.battleControl.removeHeroInPos(posIndex - BattleUtil.BagListSize)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bOtps){
|
|
|
+ let otps:BattleOptsRemove = {
|
|
|
+ pos:BattleLayoutPos[posIndex],
|
|
|
+ type:BattleOptsType.Remove
|
|
|
+ }
|
|
|
+ this.operateList.push(otps)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //交换位置
|
|
|
changeHeroPos(hero1:Node,hero2:Node) {
|
|
|
- let posID1 = hero1.getComponent(Hero).posID;
|
|
|
- let posID2 = hero2.getComponent(Hero).posID;
|
|
|
- hero1.getComponent(Hero).posID = posID2
|
|
|
- hero2.getComponent(Hero).posID = posID1
|
|
|
-
|
|
|
- if(posID1 != -1){
|
|
|
- if(posID1 < BattleUtil.BagListSize){
|
|
|
- hero2.position = this.bagPosList[posID1].pos;
|
|
|
- this.bagPosList[posID1].hero = hero2;
|
|
|
+ let posIndex1 = hero1.getComponent(Hero).posIndex;
|
|
|
+ let posIndex2 = hero2.getComponent(Hero).posIndex;
|
|
|
+ hero1.getComponent(Hero).posIndex = posIndex2
|
|
|
+ hero2.getComponent(Hero).posIndex = posIndex1
|
|
|
+
|
|
|
+
|
|
|
+ if(posIndex1 != -1){
|
|
|
+ if(posIndex1 < BattleUtil.BagListSize){
|
|
|
+ hero2.position = this.bagPosList[posIndex1].pos;
|
|
|
+ this.bagPosList[posIndex1].hero = hero2;
|
|
|
}
|
|
|
- else if(posID1 < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
- hero2.position = this.attackPosList[posID1 - BattleUtil.BagListSize].pos;
|
|
|
- let index = posID1 - BattleUtil.BagListSize;
|
|
|
+ else if(posIndex1 < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
+ hero2.position = this.attackPosList[posIndex1 - BattleUtil.BagListSize].pos;
|
|
|
+ let index = posIndex1 - BattleUtil.BagListSize;
|
|
|
this.attackPosList[index].hero = hero2;
|
|
|
let heroObj = hero2.getComponent(Hero)
|
|
|
this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
|
|
@@ -884,21 +1133,31 @@ export class TowerUI extends BaseView {
|
|
|
hero2.getComponent(Hero).stand()
|
|
|
}
|
|
|
|
|
|
- if(posID2 != -1){
|
|
|
- if(posID2 < BattleUtil.BagListSize){
|
|
|
- hero1.position = this.bagPosList[posID2].pos;
|
|
|
- this.bagPosList[posID2].hero = hero1;
|
|
|
+ if(posIndex2 != -1){
|
|
|
+ if(posIndex2 < BattleUtil.BagListSize){
|
|
|
+ hero1.position = this.bagPosList[posIndex2].pos;
|
|
|
+ this.bagPosList[posIndex2].hero = hero1;
|
|
|
}
|
|
|
- else if(posID2 < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
- hero1.position = this.attackPosList[posID2 - BattleUtil.BagListSize].pos;
|
|
|
- let index = posID2 - BattleUtil.BagListSize;
|
|
|
+ else if(posIndex2 < BattleUtil.BagListSize + this.attackPosList.length){
|
|
|
+ hero1.position = this.attackPosList[posIndex2 - BattleUtil.BagListSize].pos;
|
|
|
+ let index = posIndex2 - BattleUtil.BagListSize;
|
|
|
this.attackPosList[index].hero = hero1;
|
|
|
let heroObj = hero1.getComponent(Hero)
|
|
|
this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
|
|
|
}
|
|
|
hero1.getComponent(Hero).stand()
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //记录交换操作
|
|
|
+ let opts:BattleOptsMove = {
|
|
|
+ type: BattleOptsType.Move,
|
|
|
+ targetPos: BattleLayoutPos[posIndex2],
|
|
|
+ srcPos: BattleLayoutPos[posIndex1],
|
|
|
+ }
|
|
|
+ this.operateList.push(opts)
|
|
|
}
|
|
|
|
|
|
addHurt(pos:Vec3,value:number){
|
|
@@ -1043,4 +1302,73 @@ export class TowerUI extends BaseView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private loadHeroModel(){
|
|
|
+ let fightRole = RoleData.fightRole
|
|
|
+ this.fightRole = fightRole
|
|
|
+ this.loadHeroModelNum = 0
|
|
|
+ this.loadHeroModelNumMax = 0
|
|
|
+ fightRole.forEach(element => {
|
|
|
+
|
|
|
+ if(element > 0 ){
|
|
|
+ this.loadHeroModelNumMax ++
|
|
|
+ if(!this.heroModelMap.has(element)){
|
|
|
+ let url = "prefab/ui/tower/hero/role"+element
|
|
|
+ this.load("package",url,Prefab,(prefab:Prefab)=>{
|
|
|
+ this.heroModelMap.set(element,prefab)
|
|
|
+ this.loadHeroModelNum++
|
|
|
+ if(this.loadHeroModelNum == this.loadHeroModelNumMax){
|
|
|
+ this.resetBattleLayout()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.loadHeroModelNum++
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private resetBattleLayout(){
|
|
|
+
|
|
|
+ //添加初始英雄
|
|
|
+ for (let i = 0; i < BattleData.layout.length; i++) {
|
|
|
+ let value = BattleData.layout[i];
|
|
|
+ if(value > 0){
|
|
|
+ let battleLayoutData = BattleManager.getDataWithLayoutValue(value)
|
|
|
+ this.addHeroWithData(battleLayoutData.typeID,battleLayoutData.level,i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //重新开始第x关
|
|
|
+ private reStartBattle(battlesID){
|
|
|
+ this.enemyMap.forEach((enemy, enemyID) => {
|
|
|
+ enemy.getComponent(Enemy).clearData();
|
|
|
+ this.enemyMap.delete(enemyID);
|
|
|
+ let typeID = enemy.getComponent(Enemy).typeID
|
|
|
+ if(this.enemyPool.has(typeID)){
|
|
|
+ this.enemyPool.get(typeID).push(enemy);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.enemyPool.set(typeID,[enemy]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.battlesID = battlesID;
|
|
|
+ this.battleControl.reset(this.battlesID)
|
|
|
+ this.reset()
|
|
|
+
|
|
|
+ for(let index = 0; index < this.attackPosList.length; index++){
|
|
|
+ let hero = this.attackPosList[index].hero;
|
|
|
+ if(hero){
|
|
|
+ hero.position = this.attackPosList[index].pos;
|
|
|
+ let heroObj = hero.getComponent(Hero)
|
|
|
+ this.battleControl.addHeroInPos(heroObj.typeID,heroObj.level,index)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|