技能 目标确认 优化完成 最近,最远,血最少,血最多

This commit is contained in:
2025-01-09 10:05:17 +08:00
parent 52cc268368
commit 4c68d9484b
3 changed files with 172 additions and 166 deletions

View File

@@ -260,6 +260,7 @@ export class BuffComp extends Component {
heathed(){
this.node.getChildByName("heathed").active=true
}
}

View File

@@ -315,35 +315,6 @@ export class HeroViewComp extends CCComp {
}
}
skill_pos(){
return v3((this.node.position.x,this.node.position.y + 35))
}
get_enemy_pos(){
let t_pos:Vec3 = v3(720,0)
if(this.enemy){
t_pos = v3(this.enemy.x,this.enemy.y)
}
console.log(this.hero_name+":"+this.uuid+"enemy ="+this.enemy.x+" x"+this.node.position.x+" t_pos"+t_pos);
return t_pos
}
get_back_enemy_pos(hero:any){
let t_pos:Vec3 = v3(720,0)
if(this.enemy){
t_pos = v3(this.enemy.x,this.enemy.y)
}
console.log(this.hero_name+":"+this.uuid+"enemy ="+this.enemy.x+" x"+this.node.position.x+" t_pos"+t_pos);
return {t_pos}
}
get_hero_pos(hero:any){
let t_pos:Vec3 = v3(-720,0)
if(!hero.node.isValid){
return
}else{
t_pos = v3(hero.node.position.x,hero.node.position.y)
}
return t_pos
}
//受伤判断
check_uatk(skill:any){
if(this.shield > 0){
@@ -373,7 +344,6 @@ export class HeroViewComp extends CCComp {
}
check_debuff(skill:any,l_hp:number=0){
console.log(this.hero_name+":"+this.uuid+"check_debuff "+skill.debuff);
if(skill.debuff == 0) return
let num=RandomManager.instance.getRandomInt(0,100)
switch (skill.debuff){
@@ -410,25 +380,14 @@ export class HeroViewComp extends CCComp {
if(num > skill.depb) return
tween(this.node).to( 0.1,
{ position: new Vec3(this.node.position.x-this.scale*50,this.node.position.y) },
{
}
{ }
).start();
break;
}
}
//能量判断
check_power(){
if(this.pw >= this.pwm){
this.pw = 0
this.BUFFCOMP.max_show()
this.do_skill(this.sk2)
return true
}else{
return false
}
}
//暴击判断
/**
* 检查是否触发暴击,并执行相应的暴击效果。
@@ -536,18 +495,30 @@ export class HeroViewComp extends CCComp {
},0.3)
}
}
}
//能量判断
check_power(){
if(this.pw >= this.pwm){
this.pw = 0
this.BUFFCOMP.max_show()
this.do_skill(this.sk2)
return true
}else{
return false
}
}
//使用max_skill
do_skill(skill:number){
this.as.max()
this.at = 0;
this.at = 0; //共享普攻攻击cd
this.BUFFCOMP.tooltip(3,SkillSet[skill].name,skill);
switch (SkillSet[skill].tg) {
case SkTG.self: //自己
this.do_add_buff(this.node.getComponent(HeroViewComp),skill)
break;
case SkTG.friend: //伙伴
this.check_other_buff(skill)
if(this.box_group == BoxSet.HERO) this.check_other_hero_buff(skill)
if(this.box_group == BoxSet.MONSTER) this.check_other_mon_buff(skill)
break;
case SkTG.team: //自己和伙伴
this.do_all_buff(skill)
@@ -561,129 +532,21 @@ export class HeroViewComp extends CCComp {
break;
}
}
check_other_buff(skill:number){
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
let least_hp:number=0
let hight_hp:number=9999999999
let right_x:number=360
let left_x:number=-360
if(this.box_group==BoxSet.MONSTER){
heros=ecs.query(ecs.allOf(MonModelComp))
}
let t_hero:any= null
if (heros.length > 0) {
if(SkillSet[skill].type==SkType.random){ //随机添加buff
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
while(!heros[i].HeroView){
i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
if(heros[i].HeroView){
break
}
}
this.do_add_buff(heros[i].HeroView,skill)
}else{
for (let i = 0; i < heros.length; i++) {
if(!heros[i].HeroView) continue
let hero = heros[i].HeroView;
switch(SkillSet[skill].type){
case SkType.leastHealth: //血量最少单体
if((hero.rhp_max-hero.hp) > least_hp){
least_hp = (hero.rhp_max-hero.hp)
t_hero = hero
}
break;
case SkType.highestHealth: //血量最多单体
if((hero.rhp_max-hero.hp) < hight_hp){
hight_hp = (hero.rhp_max-hero.hp)
t_hero = hero
}
break;
case SkType.frontRow: //最前排
if(hero.node.position.x > left_x){
left_x = hero.node.position.x
t_hero = hero
}
if(this.box_group==BoxSet.MONSTER){
if(hero.node.position.x < right_x){
right_x = hero.node.position.x
t_hero = hero
}
}
break;
case SkType.backRow: //最后排
if(hero.node.position.x < right_x){
right_x = hero.node.position.x
t_hero = hero
}
if(this.box_group==BoxSet.MONSTER){
if(hero.node.position.x > left_x){
left_x = hero.node.position.x
t_hero = hero
}
}
break;
}
// if(SkillSet[skill].type==SkType.leastHealth){ //血量最少单体
// if((hero.rhp_max-hero.hp) > least_hp){
// least_hp = (hero.rhp_max-hero.hp)
// t_hero = hero
// }
// }
// if(SkillSet[skill].type==SkType.highestHealth){ //血量最多单体
// if((hero.rhp_max-hero.hp) < hight_hp){
// hight_hp = (hero.rhp_max-hero.hp)
// t_hero = hero
// }
// }
// if(SkillSet[skill].type==SkType.frontRow){ //最前排
// if(hero.node.position.x > left_x){
// left_x = hero.node.position.x
// t_hero = hero
// }
// }
// if(SkillSet[skill].type==SkType.backRow){ //最后排
// if(hero.node.position.x < right_x){
// right_x = hero.node.position.x
// t_hero = hero
// }
// }
//todo 最前排 最后排 远程 近战 辅助
}
if(t_hero){ //存在目标
this.do_add_buff(t_hero,skill)
}
}
}
}
do_all_buff(sk:number){
let skill = ecs.getEntity<Skill>(Skill);
let t_pos=v3(-320,0)
if(this.box_group==BoxSet.MONSTER){
t_pos=v3(320,0)
}
let pos = t_pos
this.to_console("to_all_buff:"+sk)
let is_crit=this.check_crit()
skill.load(pos,this.box_group,this.node,sk,this.ap_max,t_pos,is_crit,this.crit_add);
this.to_console("使用buff:"+sk+" t_pos:"+t_pos+" box:"+this.box_group);
}
shoot_enemy(sk:number,y:number=0,x:number=0){
// console.log("mon shoot_enemy");
let skill = ecs.getEntity<Skill>(Skill);
let t_pos=v3(smc.mon_front_x,BoxSet.GAME_LINE)
let t_pos=v3(smc.mon_front_x,BoxSet.GAME_LINE) //最前排目标
if(this.box_group==BoxSet.MONSTER){
t_pos=v3(smc.hero_front_x,BoxSet.GAME_LINE)
}
switch(SkillSet[sk].type){
case SkType.leastHealth: //血量最少单体
t_pos=this.check_heros().l_hero.node.position
if(this.box_group==BoxSet.MONSTER) t_pos=this.check_mons().l_hero.node.position
break;
case SkType.highestHealth: //血量最多单体
t_pos=this.check_heros().m_hero.node.position
if(this.box_group==BoxSet.MONSTER) t_pos=this.check_mons().m_hero.node.position
break;
case SkType.backRow: //最后排
t_pos=v3(smc.mon_back_x,BoxSet.GAME_LINE)
@@ -692,17 +555,159 @@ export class HeroViewComp extends CCComp {
}
break;
}
let pos =this.skill_pos()
pos.y=this.node.position.y + y
pos.x=this.node.position.x + x
let pos =this.node.position
let is_crit=this.check_crit()
this.to_console(this.scale+this.hero_name+"使用技能:"+sk+SkillSet[sk].name+" pos:"+pos+" t_pos:"+t_pos+" box:"+this.box_group,);
skill.load(pos,this.box_group,this.node,sk,this.ap_max,t_pos,is_crit,this.crit_add);
}
check_heros(){
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
let l_hp:number=0
let h_hp:number=9999999999
let right_x:number=360
let left_x:number=-360
let f_hero:any= null
let b_hero:any= null
let l_hero:any= null
let m_hero:any= null
let r_hero:any= null
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
while(!heros[i].HeroView){
i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
if(!heros[i].HeroView.in_grave){
r_hero= heros[i].HeroView
break
}
}
for (let i = 0; i < heros.length; i++) {
let hero:any = heros[i].HeroView;
if (hero.in_grave) continue
if((hero.rhp_max-hero.hp) > l_hp){
l_hp = (hero.rhp_max-hero.hp)
l_hero = hero
}
if((hero.rhp_max-hero.hp) < h_hp){
h_hp = (hero.rhp_max-hero.hp)
m_hero = hero
}
if(hero.node.position.x > left_x){
left_x = hero.node.position.x
f_hero = hero
}
if(this.box_group==BoxSet.MONSTER){
if(hero.node.position.x < right_x){
right_x = hero.node.position.x
f_hero = hero
}
}
if(hero.node.position.x < right_x){
right_x = hero.node.position.x
b_hero = hero
}
if(this.box_group==BoxSet.MONSTER){
if(hero.node.position.x > left_x){
left_x = hero.node.position.x
b_hero = hero
}
}
}
return {l_hero,m_hero,f_hero,b_hero,r_hero}
}
check_mons(){
let heros:any=ecs.query(ecs.allOf(MonModelComp))
let l_hp:number=0
let h_hp:number=9999999999
let right_x:number=360
let left_x:number=-360
let f_hero:any= null
let b_hero:any= null
let l_hero:any= null
let m_hero:any= null
let r_hero:any= null
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
while(!heros[i].HeroView){
i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
if(!heros[i].HeroView.in_grave){
r_hero= heros[i].HeroView
break
}
}
for (let i = 0; i < heros.length; i++) {
let hero:any = heros[i].HeroView;
if (hero.in_grave) continue
if((hero.rhp_max-hero.hp) > l_hp){
l_hp = (hero.rhp_max-hero.hp)
l_hero = hero
}
if((hero.rhp_max-hero.hp) < h_hp){
h_hp = (hero.rhp_max-hero.hp)
m_hero = hero
}
if(hero.node.position.x < right_x){
right_x = hero.node.position.x
f_hero = hero
}
if(hero.node.position.x > left_x){
left_x = hero.node.position.x
b_hero = hero
}
}
return {l_hero,m_hero,f_hero,b_hero,r_hero}
}
check_other_hero_buff(skill:number){
switch(SkillSet[skill].type){
case SkType.random:
this.do_add_buff(this.check_heros().r_hero,skill)
break;
case SkType.leastHealth: //血量最少单体
this.do_add_buff(this.check_heros().l_hero,skill)
break;
case SkType.highestHealth: //血量最多单体
this.do_add_buff(this.check_heros().m_hero,skill)
break;
case SkType.frontRow: //最前排
this.do_add_buff(this.check_heros().f_hero,skill)
break;
case SkType.backRow: //最后排
this.do_add_buff(this.check_heros().b_hero,skill)
break;
}
}
check_other_mon_buff(skill:number){
switch(SkillSet[skill].type){
case SkType.random:
this.do_add_buff(this.check_mons().r_hero,skill)
break;
case SkType.leastHealth: //血量最少单体
this.do_add_buff(this.check_mons().l_hero,skill)
break;
case SkType.highestHealth: //血量最多单体
this.do_add_buff(this.check_mons().m_hero,skill)
break;
case SkType.frontRow: //最前排
this.do_add_buff(this.check_mons().f_hero,skill)
break;
case SkType.backRow: //最后排
this.do_add_buff(this.check_mons().b_hero,skill)
break;
}
}
do_all_buff(sk:number){
let skill = ecs.getEntity<Skill>(Skill);
let t_pos=v3(-320,0)
if(this.box_group==BoxSet.MONSTER) t_pos=v3(320,0)
let pos = t_pos
this.to_console("to_all_buff:"+sk)
let is_crit=this.check_crit()
skill.load(pos,this.box_group,this.node,sk,this.ap_max,t_pos,is_crit,this.crit_add);
this.to_console(this.scale+this.hero_name+"使用技能:"+sk+SkillSet[sk].name+" t_pos:"+t_pos+" box:"+this.box_group,);
this.to_console("使用buff:"+sk+" t_pos:"+t_pos+" box:"+this.box_group);
}
do_add_buff(hero:any,sk:number){
let skill = ecs.getEntity<Skill>(Skill);
let t_pos=this.get_hero_pos(hero)
let pos = this.skill_pos()
let t_pos=hero.node.position
let pos = this.node.position
this.to_console("do_add_buff:"+hero.hero_name+" "+sk);
let is_crit=this.check_crit()
skill.load(pos,this.box_group,this.node,sk,this.ap_max,t_pos,is_crit,this.crit_add);

View File

@@ -26,7 +26,7 @@ export class Skill extends ecs.Entity {
{
var path = "game/skills/"+SkillSet[uuid].sp_name;
var prefab: Prefab = oops.res.get(path, Prefab)!;
// console.log("load skill :",path,prefab)
console.log("load skill pos:",pos)
var node = instantiate(prefab);
pos=v3(pos.x,pos.y)
node.parent = parent.parent;