123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { BattleBase } from "../base/BattleBase";
- import { BattleEventManager } from "../base/BattleEventManager";
- import { BattleEventData_EnemyHurt, BattleEventData_HeroAttack, BattleEventData_HeroAttackBullet, BattleEventTarget, BattleEventType, HurtEventState } from "../base/BattleEventUtil";
- import { BulletType } from "../data/BattleEnum";
- import { BattleUtil } from "../data/BattleUtil";
- import { BuffData } from "../data/BuffData";
- import { BulletData } from "../data/BulletData";
- import { EnemyData } from "../data/EnemyData";
- import { HeroData } from "../data/HeroData";
- import { MapData, PosData } from "../data/MapData";
- import { SkillControl } from "./SkillControl";
- //英雄控制类
- export class HeroControl extends BattleBase{
- map:MapData = null
- attackPosDataMap:Map<number,PosData> = null;
- enemyDataList:Array<EnemyData> = null;
- skillControl:SkillControl = null;
- battleEventManager: BattleEventManager;
- init(){
- this.battleEventManager = BattleEventManager.instance
- this.map = MapData.GetInstance()
- this.attackPosDataMap = this.map.attackPosDataMap
- this.enemyDataList = this.map.enemyDataList
- this.skillControl = SkillControl.GetInstance()
- }
- //每次加一帧
- update(){
- this.attackPosDataMap.forEach((posData:PosData)=>{
- let hero = posData.hero
- if(hero){
- hero.coolDown -= 1
- if(hero.coolDown <= 0){
-
- if(this.checkAttack(hero)){
- hero.coolDown = hero.speed
- }
- else{
- let eventData:BattleEventData_HeroAttack = {
- eventType: BattleEventType.HeroAttack,
- posID: hero.posID,
- hurt: 0,
- status: HurtEventState.Normal,
- targetID: BattleUtil.IndexID_Init
- }
- this.battleEventManager.fireEvent(BattleEventTarget.Update,eventData)
- }
- }
- }
-
- })
- }
- checkAttack(hero:HeroData){
- let bAttack = false
- if(hero.attackType == BulletType.Single ){
- for(let i = 0;i<this.enemyDataList.length;i++){
- let enemy = this.enemyDataList[i]
- if(this.isInRadius(hero.position,enemy.position,hero.attackRadius)){
- this.attack(hero,enemy)
- bAttack = true
- break;
- }
- }
- }
- else if(hero.attackType == BulletType.Group){
- // let attackList:Array<EnemyData> = []
- for(let i = 0;i<this.enemyDataList.length;i++){
- let enemy = this.enemyDataList[i]
- if(this.isInRadius(hero.position,enemy.position,hero.attackRadius)){
- this.attack(hero,enemy)
- bAttack = true
- }
- }
- }
- else if(hero.attackType == BulletType.SingleBullet){
- //创建一颗子弹
- for(let i = 0;i<this.enemyDataList.length;i++){
- let enemy = this.enemyDataList[i]
- if(this.isInRadius(hero.position,enemy.position,hero.attackRadius)){
- let bulletData:BulletData = this.map.addBullet(1,hero,enemy)
- this.attackBullet(hero,enemy,bulletData)
- bAttack = true
- break;
- }
- }
-
- }
- else if(hero.attackType == BulletType.GroupBullet){
-
- }
- return bAttack
- }
- //攻击直接伤害
- attack(hero: HeroData, enemy: EnemyData) {
- //先普通攻击
- enemy.life -= hero.attackDamage
- let eventData:BattleEventData_HeroAttack = {
- eventType: BattleEventType.HeroAttack,
- posID: hero.posID,
- hurt: hero.attackDamage,
- status: HurtEventState.Normal,
- targetID: enemy.ID
- }
- this.battleEventManager.fireEvent(BattleEventTarget.Update,eventData)
- let addBuffData:BuffData[] = null
- //在加技能攻击
- hero.skillList.forEach(skillID => {
- addBuffData = this.skillControl.useSkill(hero, enemy, skillID)
- })
- }
- //攻击打出子弹
- attackBullet(hero: HeroData, enemy: EnemyData,bulletData:BulletData) {
- let eventData:BattleEventData_HeroAttackBullet = {
- eventType: BattleEventType.HeroAttackBullet,
- posID: hero.posID,
- targetID: enemy.ID,
- bulletID: bulletData.ID
- }
- this.battleEventManager.fireEvent(BattleEventTarget.Update,eventData)
- let addBuffData:BuffData[] = null
- //在加技能攻击
- hero.skillList.forEach(skillID => {
- addBuffData = this.skillControl.useSkill(hero, enemy, skillID)
- })
- bulletData.buffDataList = addBuffData
- }
- isInRadius(position: BattleUtil.Vector2, position1: BattleUtil.Vector2, attackRadius: number) {
- return BattleUtil.Vector2.Sub(position, position1).length() <= attackRadius
- // return true
- }
-
- }
|