123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- import { BattleBase } from "../base/BattleBase";
- import { BattleEventManager } from "../base/BattleEventManager";
- import { BattleEventData_Over, BattleEventTarget, BattleEventType } from "../base/BattleEventUtil";
- import { ObjectValueType } from "../data/BattleEnum";
- import { BattleUtil } from "../data/BattleUtil";
- import { MapData } from "../data/MapData";
- import { BuffControl } from "./BuffControl";
- import { EnemyControl } from "./EnemyControl";
- import { HeroControl } from "./HeroControl";
- import { SkillControl } from "./SkillControl";
- //战斗控制类
- export class BattleControl extends BattleBase{
- map:MapData = null
- //英雄控制类
- heroControl:HeroControl = null
- //敌人控制类
- enemyControl:EnemyControl = null
- //buff控制类
- buffControl:BuffControl = null
- battleEventManager:BattleEventManager = null
- private static instance:BattleControl;
- static GetInstance():BattleControl{
- if(!BattleControl.instance){
- BattleControl.instance = new BattleControl();
- }
- return BattleControl.instance;
- }
- //初始化
- init(battleID:number){
- this.battleEventManager = BattleEventManager.instance
- this.map = MapData.GetInstance()
- this.heroControl = new HeroControl()
- this.enemyControl = new EnemyControl()
- this.buffControl = new BuffControl()
- this.map.init(battleID)
- this.buffControl.init()
- this.heroControl.init()
- this.enemyControl.init()
- SkillControl.GetInstance().init()
-
- // for(let i = 0; i < BattleUtil.TurnMax; i++){
- // this.update()
- // if(this.map.battleEnd){
- // break;
- // }
- // }
- // this.map.battleEnd = true
- }
- reset(battleID:number){
- this.clear()
- this.map.reset(battleID)
- this.buffControl.init()
- this.heroControl.init()
- this.enemyControl.init()
- SkillControl.GetInstance().init()
- }
- clear(){
- this.map.clear()
- }
- //每次加一帧
- update(){
- this.map.curTurn++
- if(this.map.battleEnd){
- return
- }
- //更新操作结果
- this.updateAction()
- //更新子弹
- // this.updateBullet()
- this.updateBuff()
- //更新敌人(基础参数,技能,buff)
- this.updateEnemy()
-
- //更新英雄(基础参数,技能,buff)
- this.updateHero()
- this.buffControl.updateNewBuff()
- //判断是否结束
- if((this.map.enemyDataList.length == 0) && (this.map.bornNeedTime < this.map.curTurn)){
- this.map.battleEnd = true
- this.map.bWin = true
- let eventData:BattleEventData_Over = {
- eventType: BattleEventType.Over,
- bWin: true
- }
- this.battleEventManager.fireEvent(BattleEventTarget.Update,eventData)
- }
- }
- get mapID():number{
- return this.map.typeID
- }
- //敌人总血量
- get allEnemyHP():number{
- return this.map.allEnemyHP
- }
- //初始化操作列表,服务器才用的
- // initAction(actionJson:string){
- // let actionList = JSON.parse(actionJson)
- // if(actionList){
- // this.map.actionMap = actionList
- // }
- // }
- //更新操作结果
- private updateAction(){
- let actionList = this.map.actionMap.get(this.map.curTurn)
- if(actionList == null){
- return
- }
- for(let i = 0; i < actionList.length; i++){
- let heroDataChange:BattleUtil.HeroDataChange = actionList[i]
- switch(heroDataChange.changeType){
- case ObjectValueType.InBattle:{
- let startPosID = heroDataChange.changeValueLlist[2]
- let startPos = this.map.attackPosDataMap.get(startPosID)
- if(startPos){
- let heroData = this.map.addHero(heroDataChange.changeValueLlist[0],heroDataChange.changeValueLlist[1],heroDataChange.changeValueLlist[2])
- startPos.hero = heroData
- }
- break
- }
- case ObjectValueType.OutBattle:{
- let startPosID = heroDataChange.changeValueLlist[0]
- this.map.removeHero(startPosID)
- break
- }
- case ObjectValueType.PosID:{
- let startPosID = heroDataChange.changeValueLlist[0]
- let endPosID = heroDataChange.changeValueLlist[1]
- let startPos = this.map.attackPosDataMap.get(startPosID)
- let endPos = this.map.attackPosDataMap.get(endPosID)
- let startHero = startPos?.hero
- let endHero = endPos?.hero
- if(startPos){
- startPos.hero = endHero
- endHero.position = startPos.pos
- }
- if(endPos){
- endPos.hero = startHero
- endHero.position = endPos.pos
- }
- break;
- }
- case ObjectValueType.Level:{
- let startPosID = heroDataChange.changeValueLlist[0]
- let startPos = this.map.attackPosDataMap.get(startPosID)
- if(startPos && startPos.hero){
- startPos.hero.levelUp()
- }
- break;
- }
- // case ObjectValueType.Attack:{
- // // let startPosID = heroDataChange.changeValueLlist[0]
- // // let startPos = this.map.attackPosDataMap1.get(startPosID)
- // // if(startPos && startPos.hero){
- // // startPos.hero.attackDamage = heroDataChange.changeValueLlist[1]
- // // }
- // break;
- // }
- // case ObjectValueType.AttackRadius:{
- // let startPosID = heroDataChange.changeValueLlist[0]
- // let startPos = this.map.attackPosDataMap1[startPosID]
- // if(startPos && startPos.hero){
- // startPos.hero.attackRadius = heroDataChange.changeValueLlist[1]
- // }
- // break;
- // }
- // case ObjectValueType.Speed:{
- // let startPosID = heroDataChange.changeValueLlist[0]
- // let startPos = this.map.attackPosDataMap1[startPosID]
- // if(startPos && startPos.hero){
- // startPos.hero.speed = heroDataChange.changeValueLlist[1]
- // }
- // break;
- // }
- // case ObjectValueType.Critical:{
- // let startPosID = heroDataChange.changeValueLlist[0]
- // let startPos = this.map.attackPosDataMap1[startPosID]
- // if(startPos && startPos.hero){
- // startPos.hero.critical = heroDataChange.changeValueLlist[1]
- // }
- // break;
- // }
- // case ObjectValueType.CriticalDamage:{
- // let startPosID = heroDataChange.changeValueLlist[0]
- // let startPos = this.map.attackPosDataMap1[startPosID]
- // if(startPos && startPos.hero){
- // startPos.hero.criticalDamage = heroDataChange.changeValueLlist[1]
- // }
- // break;
- // }
- }
-
- }
- }
- //更新子弹
- // private updateBullet(){
- // }
- //更新buff计时
- private updateBuff(){
- this.buffControl.update()
- }
- //更新敌人(基础参数,技能,buff)
- private updateEnemy(){
- this.enemyControl.update()
- }
- //更新英雄(基础参数,技能,buff)
- private updateHero(){
- this.heroControl.update()
- }
- //添加操作步骤
- addAction(action:BattleUtil.HeroDataChange){
- if(!this.map.actionMap.get(this.map.curTurn+1)){
- this.map.actionMap.set(this.map.curTurn+1,[])
- }
- this.map.actionMap.get(this.map.curTurn+1).push(action)
- console.log("添加操作步骤",this.map.curTurn,action)
- }
- //上阵
- addHeroInPos(heroID:number,level:number,index:number){
- let posID = this.getPosIDByIndex(index)
- if(posID == BattleUtil.PosID_Init){
- return
- }
- let action:BattleUtil.HeroDataChange = {
- changeType: ObjectValueType.InBattle,
- changeValueLlist: [heroID,level,posID]
- }
- this.addAction(action)
- }
- //下阵
- removeHeroInPos(index:number){
- let posID = this.getPosIDByIndex(index)
- let action:BattleUtil.HeroDataChange = {
- changeType: ObjectValueType.OutBattle,
- changeValueLlist: [posID]
- }
- this.addAction(action)
- }
- //升级
- levelUp(index:number){
- let posID = this.getPosIDByIndex(index)
- let action:BattleUtil.HeroDataChange = {
- changeType: ObjectValueType.Level,
- changeValueLlist: [posID]
- }
- this.addAction(action)
- }
- //判断是否结束
- get isBattleEnd():boolean{
- return this.map.battleEnd
- }
- getPosIDByIndex(index:number){
- return this.map.attackPosition[index] || BattleUtil.PosID_Init
- }
- //根据id获取坐标 取值范围[0,this.length-1]
- getPosition(id:number):BattleUtil.Vector2{
-
- return this.map.getPosition(id);
- }
- }
|