假期修改
This commit is contained in:
@@ -33,7 +33,9 @@ export class HeroViewComp extends CCComp {
|
||||
hitFlashMaterial: Material;
|
||||
orginalFlashMaterial: Material;
|
||||
sprite: Sprite;
|
||||
|
||||
@property(Material)
|
||||
atkMaterial: Material;
|
||||
|
||||
@property(Node)
|
||||
BoxRang:Node =null!
|
||||
|
||||
@@ -57,8 +59,6 @@ export class HeroViewComp extends CCComp {
|
||||
power_max: number = 1200; /** 能量最大值 */
|
||||
power_speed: number = 1; //能量回复速度每0.1秒回复量
|
||||
|
||||
skill_name: string = "base"; //技能名称
|
||||
max_skill_name: string = "base"; //大技能名称
|
||||
skill_uuid:number = 9001;
|
||||
max_skill_uuid:number = 1001;
|
||||
atk: number = 10; /**攻击力 */
|
||||
@@ -89,6 +89,7 @@ export class HeroViewComp extends CCComp {
|
||||
buff_atks:any = [];
|
||||
dir_y:number = 0;
|
||||
speek_time:number = 0;
|
||||
role_heros_index:number = -1;
|
||||
onLoad() {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
// this.BoxRang = this.node.getChildByName("range_box");
|
||||
@@ -96,6 +97,7 @@ export class HeroViewComp extends CCComp {
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
this.as.move()
|
||||
this.node.getChildByName("top").getChildByName("hp").active = false;
|
||||
this.sprite = this.node.getChildByName("anm").getComponent(Sprite);
|
||||
// this.node.getChildByName("top").getChildByName("shield").active = false;
|
||||
// this.node.getChildByName("top").setScale(this.scale,1);
|
||||
@@ -118,9 +120,9 @@ export class HeroViewComp extends CCComp {
|
||||
collider.group = this.box_group;
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
|
||||
|
||||
@@ -146,6 +148,7 @@ 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()){
|
||||
|
||||
@@ -164,13 +167,15 @@ export class HeroViewComp extends CCComp {
|
||||
if (this.timer.update(dt)) {
|
||||
this.power_change(this.power_speed)
|
||||
}
|
||||
this.check_buff_atks(dt)
|
||||
this.in_destroy();
|
||||
this.check_buff_atks(dt)
|
||||
this.in_shield(dt);
|
||||
this.in_stop(dt);
|
||||
this.in_atk(dt);
|
||||
this.in_speek(dt);
|
||||
this.move(dt);
|
||||
this.hp_show()
|
||||
// this.in_speek(dt);
|
||||
// this.move(dt);
|
||||
this.move_to()
|
||||
// if(this.m_timer.update(dt)){
|
||||
// this.move_to()
|
||||
// }
|
||||
@@ -186,15 +191,24 @@ export class HeroViewComp extends CCComp {
|
||||
if(this.enemy){
|
||||
return
|
||||
}
|
||||
// this.set_diry()
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y+dt*this.dir_y, this.node.position.z);
|
||||
}
|
||||
set_diry(){
|
||||
this.dir_y=-(this.node.position.y-BoxSet.GAME_LINE)/20
|
||||
hp_show(){
|
||||
if(this.hp == this.hp_max){
|
||||
this.node.getChildByName("top").getChildByName("hp").active = false;
|
||||
} else{
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
}
|
||||
}
|
||||
move_to(){
|
||||
// if(this.stop_cd > 0){
|
||||
// return
|
||||
// }
|
||||
// if(this.enemy){
|
||||
// return
|
||||
// }
|
||||
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
move.target = v3(smc.Role.RoleView.node.position.x+10,smc.Role.RoleView.node.position.y);
|
||||
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.node = this.node;
|
||||
move.speed = this.ospeed;
|
||||
}
|
||||
@@ -202,7 +216,7 @@ export class HeroViewComp extends CCComp {
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max&&this.check_enemy_alive()){
|
||||
this.as.atk()
|
||||
this.to_speek(smc.skills[this.max_skill_uuid].name)
|
||||
// this.to_speek(smc.skills[this.max_skill_uuid].name)
|
||||
this.scheduleOnce(()=>{
|
||||
this.handle_skill(this.max_skill_uuid);
|
||||
},0.5)
|
||||
@@ -237,10 +251,10 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
return {pos,t_pos}
|
||||
}
|
||||
shoot(skill_uuid:number,y:number=0,x:number=0){
|
||||
// console.log("mon shoot");
|
||||
shoot_enemy(skill_uuid:number,y:number=0,x:number=0){
|
||||
// console.log("mon shoot_enemy");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk;
|
||||
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
|
||||
@@ -252,21 +266,32 @@ export class HeroViewComp extends CCComp {
|
||||
let atk = smc.skills[s_uuid].atk+this.atk;
|
||||
let {pos,t_pos}=this.get_hero_pos(hero)
|
||||
skill.load(pos,BoxSet.HERO,this.node,this.max_skill_uuid,atk,t_pos);
|
||||
hero.HeroView.add_hp(smc.skills[s_uuid].atk)
|
||||
if(smc.skills[s_uuid].hp > 0){ //buff加血
|
||||
hero.HeroView.add_hp(smc.skills[s_uuid].hp)
|
||||
}
|
||||
if(smc.skills[s_uuid].atk > 0){ //buff加攻击
|
||||
hero.HeroView.add_atk(smc.skills[s_uuid].atk,smc.skills[s_uuid].bsd)
|
||||
}
|
||||
if(smc.skills[s_uuid].shield > 0){ //buff护盾
|
||||
hero.HeroView.add_shield(smc.skills[s_uuid].shield,smc.skills[s_uuid].bsd)
|
||||
}
|
||||
|
||||
}
|
||||
push_least_buff(skill:number){
|
||||
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
|
||||
let least_hp:number=999999
|
||||
let least_hp:number=0
|
||||
let t_hero:any= null
|
||||
if (heros.length > 0) {
|
||||
if(smc.skills[skill].type==92){ //随机添加buff
|
||||
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
|
||||
this.to_add_buff(heros[i],skill)
|
||||
}else{
|
||||
for (let i = 0; i < heros.length; i++) {
|
||||
let hero = heros[i];
|
||||
if(!hero.HeroView) continue
|
||||
if(smc.skills[skill].type==91){ //血量最少单体
|
||||
if(hero.HeroView.hp < least_hp){
|
||||
least_hp = hero.HeroView.hp
|
||||
if((hero.HeroView.hp_max-hero.HeroView.hp) > least_hp){
|
||||
least_hp = (hero.HeroView.hp_max-hero.HeroView.hp)
|
||||
t_hero = hero
|
||||
}
|
||||
}else{ //群体
|
||||
@@ -287,19 +312,21 @@ export class HeroViewComp extends CCComp {
|
||||
handle_skill(skill:number){
|
||||
switch (smc.skills[skill].tg) {
|
||||
case 0: //自己
|
||||
|
||||
this.to_add_buff(this.ent,skill)
|
||||
break;
|
||||
case 1: //伙伴
|
||||
this.push_least_buff(skill)
|
||||
break;
|
||||
case 2: //自己和伙伴
|
||||
|
||||
this.to_add_buff(this.ent,skill)
|
||||
this.push_least_buff(skill)
|
||||
break;
|
||||
case 3: //敌人
|
||||
this.shoot(skill)
|
||||
this.shoot_enemy(skill)
|
||||
break;
|
||||
case 4: //敌人和自己
|
||||
this.shoot(skill)
|
||||
this.to_add_buff(this.ent,skill)
|
||||
this.shoot_enemy(skill)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -346,6 +373,22 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
heathed(){
|
||||
this.node.getChildByName("heathed").active=true
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
this.heathed();
|
||||
this.hp+=hp;
|
||||
if(this.hp > this.hp_max){
|
||||
this.hp = this.hp_max;
|
||||
}
|
||||
this.tooltip(2,hp.toString());
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
}
|
||||
|
||||
hp_change(hp: number){
|
||||
if(this.is_dead){
|
||||
return;
|
||||
@@ -364,26 +407,15 @@ 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);
|
||||
}
|
||||
}
|
||||
heathed(){
|
||||
this.node.getChildByName("heathed").active=true
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
this.heathed();
|
||||
this.hp+=hp;
|
||||
if(this.hp > this.hp_max){
|
||||
this.hp = this.hp_max;
|
||||
}
|
||||
this.tooltip(2,hp.toString());
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
}
|
||||
add_atk(atk: number,time:number=0){
|
||||
if(time > 0){
|
||||
this.buff_atk=0
|
||||
let buff={atk:atk,time:time}
|
||||
this.buff_atks.push(buff);
|
||||
this.buff_atks.forEach((element: { atk: number; }) => {
|
||||
@@ -392,15 +424,20 @@ export class HeroViewComp extends CCComp {
|
||||
}else{
|
||||
this.atk += atk;
|
||||
}
|
||||
this.sprite.setSharedMaterial(this.atkMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
}, 0.3);
|
||||
console.log(this.buff_atks)
|
||||
}
|
||||
|
||||
check_buff_atks(dt: number){
|
||||
for(let i=0;i<this.buff_atks.length;i++){
|
||||
let buff=this.buff_atks[i];
|
||||
buff.time -= dt;
|
||||
if(buff.time <= 0){
|
||||
this.buff_atk -= buff.atk
|
||||
this.buff_atks.splice(i,1);
|
||||
}else{
|
||||
this.buff_atk += buff.atk
|
||||
}
|
||||
}
|
||||
if(this.buff_atks.length <= 0){
|
||||
@@ -410,9 +447,14 @@ export class HeroViewComp extends CCComp {
|
||||
this.buff_icon_change("atk",true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buff_icon_change(icon:string,value:boolean){
|
||||
this.node.getChildByName("top").getChildByName("buff").getChildByName(icon).active=value
|
||||
}
|
||||
|
||||
|
||||
|
||||
add_shield(shield: number,time:number=0){
|
||||
this.shield =this.shield_max=shield
|
||||
this.shield_time = time;
|
||||
@@ -428,7 +470,15 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
in_shield(dt: number){
|
||||
if(this.shield <= 0){
|
||||
this.shield_time=0
|
||||
this.node.getChildByName("shielded").active=false
|
||||
}else{
|
||||
this.node.getChildByName("shielded").active=true
|
||||
}
|
||||
if(this.shield_time <= 0){
|
||||
this.shield = this.shield_max=0;
|
||||
this.node.getChildByName("shielded").active=false
|
||||
return
|
||||
}
|
||||
if(this.shield_time > 0){
|
||||
@@ -441,12 +491,6 @@ export class HeroViewComp extends CCComp {
|
||||
// let shield_progress= this.shield/this.shield_max;
|
||||
// this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
|
||||
}
|
||||
if(this.shield <= 0){
|
||||
this.shield_time=0
|
||||
// this.node.getChildByName("top").getChildByName("shield").active=false
|
||||
}else{
|
||||
// this.node.getChildByName("top").getChildByName("shield").active=true
|
||||
}
|
||||
}
|
||||
tooltip(type:number=1,value:string="",s_uuid:number=1001,y:number=60){
|
||||
// console.log("tooltip",type);
|
||||
|
||||
Reference in New Issue
Block a user