diff --git a/assets/script/game/hero/HeroInfoComp.ts b/assets/script/game/hero/HeroInfoComp.ts index 4641d67a..9020ea55 100644 --- a/assets/script/game/hero/HeroInfoComp.ts +++ b/assets/script/game/hero/HeroInfoComp.ts @@ -33,8 +33,14 @@ export class HeroInfoCompComp extends CCComp { this.update_info() } update_info(){ - let heros=ecs.query(ecs.allOf(HeroModelComp)) - for(let hero of heros){ + let heros=ecs.query(ecs.allOf(HeroModelComp)) + this.has_hero=false + this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string="" + this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string="" + this.node.getChildByName("name").getComponent(Label).string="无英雄" + const sprite = this.node.getChildByName("mask").getChildByName("icon").getComponent(Sprite); + // sprite.spriteFrame = //需要添加默认头像 + for(let hero of heros){ let info=hero.get(HeroViewComp) if(info.node.position.x==HeroPos[this.c_id].pos.x){ this.has_hero=true @@ -47,11 +53,11 @@ export class HeroInfoCompComp extends CCComp { sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[info.hero_uuid].path); }); } - } - if(this.is_Change){ - this.node.getChildByName("change").active=this.has_hero - this.node.getChildByName("select").active=!this.has_hero - } + } + // if(this.is_Change){ + // this.node.getChildByName("change").active=this.has_hero + // this.node.getChildByName("select").active=!this.has_hero + // } } /** 全局消息逻辑处理 */ // private onHandler(event: string, args: any) { diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index df9db183..2fc03e1b 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -16,6 +16,12 @@ const { ccclass, property } = _decorator; @ecs.register('MissionMonComp', false) export class MissionMonCompComp extends CCComp { timer:Timer=new Timer(3) + // 添加刷怪队列 + private monsterQueue: Array<{uuid: number, position: number, isBoss: boolean}> = []; + private isSpawning: boolean = false; + private spawnInterval: number = 0.5; // 每个怪物生成间隔时间 + private spawnTimer: number = 0; + /** 视图层逻辑代码分离演示 */ start() { // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 @@ -28,31 +34,45 @@ export class MissionMonCompComp extends CCComp { this.mon_refresh() } + // 处理刷怪队列 + if (this.monsterQueue.length > 0 && !this.isSpawning) { + this.spawnTimer += dt; + if (this.spawnTimer >= this.spawnInterval) { + this.spawnNextMonster(); + this.spawnTimer = 0; + } + } } test_call(){ - this.addMonster(5202,0,true) + this.addToSpawnQueue(5202, 0, true); } mon_refresh(){ - let num =3 - let t_num= Missions[0].length - let y_num= Missions[1].length - let b_num= Missions[2].length - let tc=1 - let yc=2 - let bc=1 - let x=RandomManager.instance.getRandomInt(0,y_num,1) - this.addMonster(Missions[0][x],0) - x=RandomManager.instance.getRandomInt(0,y_num,1) - this.addMonster(Missions[0][x],1) - x=RandomManager.instance.getRandomInt(0,y_num,1) - this.addMonster(Missions[0][x],2) - x=RandomManager.instance.getRandomInt(0,y_num,1) - this.addMonster(Missions[0][x],3) + let positions = [0, 1, 2, 3]; + positions.forEach(pos => { + let x = RandomManager.instance.getRandomInt(0, Missions[0].length, 1); + this.addToSpawnQueue(Missions[0][x], pos, false); + }); + } - console.log("Missions t:"+x,Missions[0][x]) + // 新增:添加到刷怪队列 + private addToSpawnQueue(uuid: number, position: number, isBoss: boolean = false) { + this.monsterQueue.push({ + uuid: uuid, + position: position, + isBoss: isBoss + }); + } + + // 新增:从队列中生成下一个怪物 + private spawnNextMonster() { + if (this.monsterQueue.length === 0) return; + const monsterData = this.monsterQueue.shift(); + if (monsterData) { + this.addMonster(monsterData.uuid, monsterData.position, monsterData.isBoss); + } } private addMonster(uuid:number=1001,i:number=0,is_boss:boolean=false) { diff --git a/assets/script/game/skill/HeroSkillSystem.ts b/assets/script/game/skill/HeroSkillSystem.ts index 854873bd..510950e0 100644 --- a/assets/script/game/skill/HeroSkillSystem.ts +++ b/assets/script/game/skill/HeroSkillSystem.ts @@ -54,7 +54,6 @@ export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUp view.node.parent, // 父节点 config.uuid, // 技能ID new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置 - targets[0]?.get(HeroViewComp), view ); caster.get(HeroViewComp).playSkillEffect(config.uuid); diff --git a/assets/script/game/skills/Skill.ts b/assets/script/game/skills/Skill.ts index 89844807..f9826392 100644 --- a/assets/script/game/skills/Skill.ts +++ b/assets/script/game/skills/Skill.ts @@ -27,7 +27,6 @@ export class Skill extends ecs.Entity { parent: Node, // 父节点 uuid: number, // 技能ID targetPos: Vec3, // 目标位置 - target:any=null, // 目标 caster:any=null // 施法者 ) { const config = SkillSet[uuid]; @@ -53,7 +52,6 @@ export class Skill extends ecs.Entity { skillComp.atk_count = 0; skillComp.startPos = startPos skillComp.targetPos =targetPos - skillComp.target = target; skillComp.caster = caster; skillComp.prefabName = config.sp_name; skillComp.group = group; diff --git a/assets/script/game/skills/SkillCom.ts b/assets/script/game/skills/SkillCom.ts index 252cf9b7..473c96ec 100644 --- a/assets/script/game/skills/SkillCom.ts +++ b/assets/script/game/skills/SkillCom.ts @@ -37,7 +37,6 @@ export class SkillCom extends CCComp { animName: string = ""; group:number = 0; //阵营 fac:number=0; //阵营 - target:any=null; caster:any=null; distance_x:number=0; distance_y:number=0; @@ -58,32 +57,31 @@ export class SkillCom extends CCComp { if (collider) { collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); } - let dir_x = this.target.node.position.x > this.node.position.x ? 1 : -1 + let dir_x = this.targetPos.x > this.node.position.x ? 1 : -1 this.node.scale = v3(dir_x,1,1) // 根据目标位置设置节点朝向 - if (this.target && this.target.node) { + if ( this.targetPos) { // 计算朝向 - let direction = this.target.node.position.x > this.node.position.x ? 1 : -1; + let direction = this.targetPos.x > this.node.position.x ? 1 : -1; // 设置节点缩放来改变朝向 this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1); } - let dir_y = (this.target.node.position.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1 - if(this.target.node.position.y+BoxSet.ATK_Y==this.node.position.y){ + let dir_y = ( this.targetPos.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1 + if( this.targetPos.y+BoxSet.ATK_Y==this.node.position.y){ dir_y=0 } // 计算这一帧的移动距离 this.distance_x = SkillSet[this.s_uuid].speed*dir_x; - this.distance_y = this.distance_x*Math.abs(this.target.node.position.y-this.node.position.y)/Math.abs(this.target.node.position.x-this.node.position.x)*dir_y; + this.distance_y = this.distance_x*Math.abs(this.targetPos.y-this.node.position.y)/Math.abs(this.targetPos.x-this.node.position.x)*dir_y; this.startMovement(); // 计算目标角度 - if (this.target && this.target.node) { - const targetPos = this.target.node.position; + if (this.targetPos) { const currentPos = this.node.position; // 计算角度(弧度) - const dx = targetPos.x - currentPos.x; - const dy = (targetPos.y + BoxSet.ATK_Y) - currentPos.y; + const dx = this.targetPos.x - currentPos.x; + const dy = (this.targetPos.y + BoxSet.ATK_Y) - currentPos.y; const angle = Math.atan2(dy, dx); // 将弧度转换为角度并设置节点旋转