需要修复 英雄目标错误
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
@@ -36,8 +36,8 @@ export class HeroViewComp extends CCComp {
|
||||
@property(Material)
|
||||
atkMaterial: Material;
|
||||
|
||||
@property(Node)
|
||||
BoxRang:Node =null!
|
||||
// @property(Node)
|
||||
// BoxRang:Node =null!
|
||||
|
||||
is_role:boolean = false;
|
||||
enemy_pos:Vec3=null!;
|
||||
@@ -106,8 +106,8 @@ export class HeroViewComp extends CCComp {
|
||||
// this.node.getChildByName("hp_max").setScale(this.scale,1);
|
||||
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
|
||||
// this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
|
||||
// this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
|
||||
// this.BoxRang.getComponent(BoxRangComp).offset_x = 300;
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
@@ -148,15 +148,24 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
|
||||
|
||||
if(selfCollider.node.position.y < otherCollider.node.position.y){
|
||||
if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
|
||||
|
||||
selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
|
||||
// console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
|
||||
}
|
||||
|
||||
if(otherCollider.node.name=="role") return
|
||||
let self_x = selfCollider.node.position.x;
|
||||
let other_x = otherCollider.node.position.x;
|
||||
if(otherCollider.node.getComponent(HeroViewComp).type == this.type && self_x < other_x && Math.abs(other_x-self_x) < 15 ){
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
// if(selfCollider.node.position.y < otherCollider.node.position.y){
|
||||
// if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
|
||||
|
||||
// selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
|
||||
// // console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
|
||||
this.stop_cd = 0.1;
|
||||
this.is_atking=true
|
||||
}
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
@@ -171,7 +180,10 @@ export class HeroViewComp extends CCComp {
|
||||
this.check_buff_atks(dt)
|
||||
this.in_shield(dt);
|
||||
this.in_stop(dt);
|
||||
this.atk_time += dt;
|
||||
this.check_enemy_alive()
|
||||
this.in_atk(dt);
|
||||
|
||||
this.hp_show()
|
||||
// this.in_speek(dt);
|
||||
this.move(dt);
|
||||
@@ -200,7 +212,7 @@ export class HeroViewComp extends CCComp {
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
}
|
||||
}
|
||||
move_to(){
|
||||
move_to(target:any){
|
||||
// if(this.stop_cd > 0){
|
||||
// return
|
||||
// }
|
||||
@@ -208,13 +220,13 @@ export class HeroViewComp extends CCComp {
|
||||
// return
|
||||
// }
|
||||
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
move.target = v3(smc.Role.RoleView.node.position.x+smc.role_heros[this.role_heros_index].x,smc.Role.RoleView.node.position.y+smc.role_heros[this.role_heros_index].y);
|
||||
move.target = v3(target.x,target.y);
|
||||
move.node = this.node;
|
||||
move.speed = this.ospeed;
|
||||
}
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max&&this.check_enemy_alive()){
|
||||
if(this.power >= this.power_max){
|
||||
this.as.atk()
|
||||
// this.to_speek(smc.skills[this.max_skill_uuid].name)
|
||||
this.scheduleOnce(()=>{
|
||||
@@ -230,25 +242,23 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
get_enemy_pos(){
|
||||
let pos =this.skill_pos()
|
||||
let t_pos:Vec3 = v3(720,BoxSet.GAME_LINE)
|
||||
let t_pos:Vec3 = v3(720,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+pos.y))
|
||||
}
|
||||
console.log("get_hero_pos",this.enemy,this.node.position,t_pos);
|
||||
return {pos,t_pos}
|
||||
}
|
||||
get_hero_pos(hero:any){
|
||||
let pos =this.skill_pos()
|
||||
let t_pos:Vec3 = v3(720,BoxSet.GAME_LINE)
|
||||
let t_pos:Vec3 = v3(720,0)
|
||||
if(!hero.HeroView.node.isValid){
|
||||
console.log("hero.heroView.node.isValid",hero.HeroView);
|
||||
return
|
||||
}else{
|
||||
t_pos = v3(hero.HeroView.node.position.x-this.node.position.x,hero.HeroView.node.position.y-(this.node.position.y+pos.y)+BoxSet.ATK_Y)
|
||||
t_pos = v3(hero.HeroView.node.position.x-this.node.position.x,hero.HeroView.node.position.y-(this.node.position.y+pos.y))
|
||||
}
|
||||
|
||||
return {pos,t_pos}
|
||||
}
|
||||
shoot_enemy(skill_uuid:number,y:number=0,x:number=0){
|
||||
@@ -256,6 +266,7 @@ export class HeroViewComp extends CCComp {
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk;
|
||||
let {pos,t_pos}=this.get_enemy_pos()
|
||||
|
||||
pos.y=pos.y + y
|
||||
pos.x=pos.x + x
|
||||
skill.load(pos,BoxSet.HERO,this.node,skill_uuid,atk,t_pos);
|
||||
@@ -348,19 +359,26 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
check_enemy_alive(){
|
||||
if(this.enemy){
|
||||
if(!this.enemy.isValid){
|
||||
return false
|
||||
let dir = 320
|
||||
for (let i = 0; i <= 2; i++) {
|
||||
let mon:any = smc.enemy_pos[i];
|
||||
let squaredDistance =mon.x*mon.x+mon.y*mon.y
|
||||
let distance = Math.sqrt(squaredDistance);
|
||||
if(distance < dir){
|
||||
dir = distance
|
||||
this.enemy = mon
|
||||
}
|
||||
if(Math.abs(this.enemy.position.x-this.node.position.x) < this.atk_dis) return true;
|
||||
return false
|
||||
|
||||
}
|
||||
if(dir < this.atk_dis){
|
||||
this.is_atking=true
|
||||
}else{
|
||||
return false
|
||||
this.is_atking=false
|
||||
}
|
||||
}
|
||||
in_atk(dt: number) {
|
||||
if(this.atk_time >= this.atk_cd){
|
||||
if(this.is_atking&&this.check_enemy_alive()){
|
||||
if(this.is_atking){
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
@@ -368,8 +386,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.handle_skill(this.skill_uuid)
|
||||
},0.4)
|
||||
}
|
||||
}else{
|
||||
this.atk_time += dt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +423,6 @@ export class HeroViewComp extends CCComp {
|
||||
if(this.hp <= 0){
|
||||
this.dead();
|
||||
this.is_dead = true;
|
||||
// smc.role_heros[this.role_heros_index].eid == 0
|
||||
setTimeout(() => {
|
||||
this.ent.destroy();
|
||||
}, 15);
|
||||
|
||||
Reference in New Issue
Block a user