This commit is contained in:
2024-09-18 13:59:54 +08:00
parent cd0dc9fe7c
commit 839ccba3de
4 changed files with 111 additions and 277 deletions

View File

@@ -21,6 +21,7 @@ import { MoveToComp } from "../common/ecs/position/MoveTo";
import { RoleRangComp } from "./RoleRangComp";
import { Tooltip } from "../skills/Tooltip";
import { MonViewComp } from "../mon/MonViewComp";
import { MonModelComp } from "../mon/MonModelComp";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@@ -41,6 +42,8 @@ export class RoleViewComp extends CCComp {
is_role:boolean = false;
enemy_pos:Vec3=null!;
enemy:any=null!;
atk_enemy:any=null!;
neraster_enemy:any=null!;
/** 角色动画 */
hero_uuid:number = 1001;
hero_name : string = "role";
@@ -180,10 +183,28 @@ export class RoleViewComp extends CCComp {
this.in_shield(dt);
this.in_stop(dt);
this.in_atk(dt);
this.move();
// this.move();
this.check_enemys()
}
check_enemys(){
let enemys=ecs.query(ecs.allOf(MonViewComp));
if(enemys.length > 0){
let x= 720
for (let i = 0; i < enemys.length; i++) {
let enemy:any = enemys[i];
if(!enemy.MonView) continue
let node=enemy.MonView.node
if(node.isValid){
if(node.position.x < x){
x=node.position.x
this.enemy = node.position;
}
}
}
}else{
this.enemy = v3(720,this.node.position.y);
}
}
move(){
if(this.stop_cd > 0){
return
@@ -222,13 +243,9 @@ export class RoleViewComp extends CCComp {
let pos = v3(0,50)
let t_pos:Vec3 = v3(0,0)
if(this.enemy){
if(!this.enemy.isValid){
console.log("move_to",this.enemy.isValid);
return
}
t_pos = v3(this.enemy.position.x-(this.node.position.x),this.enemy.position.y-(this.node.position.y+pos.y)+BoxSet.ATK_Y)
t_pos = v3(this.enemy.x-this.node.position.x,this.enemy.y-this.node.position.y)
}else{
t_pos=v3(720,BoxSet.GAME_LINE)
t_pos=v3(720,0)
}
return {pos,t_pos}
}
@@ -244,14 +261,19 @@ export class RoleViewComp extends CCComp {
}
in_atk(dt: number) {
if(this.atk_time >= this.atk_cd){
if(this.is_atking&&this.check_enemy_alive()){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
this.scheduleOnce(()=>{
this.shoot(this.skill,-30);
},0.4)
}
// if(this.is_atking&&this.check_enemy_alive()){
// this.atk_time = 0;
// // console.log("atk_cd:"+this.atk_cd);
// this.as.atk();
// this.scheduleOnce(()=>{
// this.shoot(this.skill,-30);
// },0.4)
// }
this.atk_time = 0;
this.as.atk();
this.scheduleOnce(()=>{
this.shoot(this.skill,-30);
},0.4)
}else{
this.atk_time += dt;
}