@@ -37,20 +37,28 @@ export class HeroViewComp extends CCComp {
@property ( Material )
atkMaterial : Material ;
// @property(Node)
// BoxRang:Node =null!
is_role :boolean = false ;
enemy_pos :Vec3 = null ! ;
enemy :any = null ! ;
/** 角色动画 */
as : HeroSpine = null ! ;
anm_timer :Timer = new Timer ( 2 ) ;
anm_name = "idle"
status :String = "idle"
hero_uuid :number = 1001 ;
hero_name : string = "hero" ;
level :number = 1 ;
scale : number = 1 ; /** 角色阵营 1: hero -1 :mon */
type : number = 1 ; /**角色类型 1: 前排 2 后排 */
state : number = 1 ; /** 状态 1: move ,2: act 3: stop */
box_group :number = BoxSet . HERO ;
atk_range :number = 150 ;
private timer :Timer = new Timer ( 1 ) ; //计时器
is_dead :boolean = false ; //是否摧毁
is_stop :boolean = false ;
is_atking :boolean = false ;
hp : number = 100 ; /** 血量 */
hp_max : number = 100 ; /** 最大血量 */
@@ -60,20 +68,29 @@ export class HeroViewComp extends CCComp {
power_max : number = 1200 ; /** 能量最大值 */
power_speed : number = 1 ; //能量回复速度每0.1秒回复量
skill_uuid :number = 9001 ;
max_skill_uuid :number = 1001 ;
sk1 :number = 9001 ;
sk2 :number = 1001 ;
sk3 :number = 1001 ;
sk4 :number = 1001 ;
sk5 :number = 1001 ;
atk : number = 10 ; /**攻击力 */
buff_atk : number = 0 ;
atk_ buff : number = 0 ;
atk_buffs :any = [ ] ;
// atk_speed: number = 1;
atk_cd : number = 1.3 ; /**攻击速度 攻击间隔 */
atk_dis : number = 80 ;
atk_time : number = 0 ; /** 冷却时间 */
st_boncus : number = 1 ; //技能持续时间加成
s_boncus : number = 1 ; //技能效果加成
speed : number = 100 ; /** 角色移动速度 */
ospeed : number = 100 ; /** 角色初始速度 */
Tpos : Vec3 = v3 ( 0 , - 60 , 0 ) ;
stop_cd : number = 0.5 ; /*停止倒计时*/
//暴击
crit : number = 1.5 ;
crit_rate : number = 0 ;
@@ -84,22 +101,13 @@ export class HeroViewComp extends CCComp {
shield_max :number = 200 ;
shield_time :number = 0 ; //护盾持续时间
box_group :number = BoxSet . HERO ;
atk_range :number = 150 ;
private timer :Timer = new Timer ( 1 ) ; //计时器
private m_timer :Timer = new Timer ( 0.1 ) ;
is_dead :boolean = false ; //是否摧毁
is_stop :boolean = false ;
is_atking :boolean = false ;
buff_shields :any = [ ] ;
buff_atks :any = [ ] ;
dir_y :number = 0 ;
speek_time :number = 0 ;
role_heros_index :number = - 1 ;
anm_timer :Timer = new Timer ( 2 ) ;
anm_name = "idle"
status :String = "idle"
onLoad() {
this . as = this . getComponent ( HeroSpine ) ;
// this.BoxRang = this.node.getChildByName("range_box");
@@ -109,16 +117,21 @@ 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 . setScale ( this . scale , 1 ) ;
this . node . getChildByName ( "top" ) . setScale ( this . scale , 1 ) ;
/** 显示角色血量 */
this . node . getChildByName ( "top" ) . getChildByName ( "hp" ) . active = true ;
/** 闪光特效 */
this . sprite = this . node . getChildByName ( "anm" ) . getComponent ( Sprite ) ;
this . orginalFlashMaterial = this . sprite . getRenderMaterial ( 0 ) ;
// this.node.getChildByName("top").getChildByName("shield").active = false;
// this.node.getChildByName("top").setScale(this.scale,1);
// this.node.getChildByName("atk").setScale(this.scale,1);
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
// 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).offset_x = 300;
@@ -126,6 +139,7 @@ export class HeroViewComp extends CCComp {
// console.log("monseter ",this.BoxRang);
// 注册单个碰撞体的回调函数
let collider = this . getComponent ( Collider2D ) ;
collider . group = this . box_group ;
console . log ( "hero collider " , this . scale , collider ) ;
@@ -135,7 +149,6 @@ export class HeroViewComp extends CCComp {
collider . on ( Contact2DType . PRE_SOLVE , this . onPreSolve , this ) ;
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
}
@@ -203,13 +216,13 @@ export class HeroViewComp extends CCComp {
// this.change_anm()
// }
this . in_destroy ( ) ;
this . check_buff_atk s ( dt )
this . check_atk_ buffs ( 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.hp_show()
this . move ( dt ) ;
@@ -315,9 +328,9 @@ export class HeroViewComp extends CCComp {
this . power += power ;
if ( this . power >= this . power_max ) {
this . as . atk ( )
// this.to_speek(smc.skills[this.max_skill_uuid ].name)
// this.to_speek(smc.skills[this.sk2 ].name)
this . scheduleOnce ( ( ) = > {
this . handle_skill ( this . max_skill_uuid ) ;
this . handle_skill ( this . sk2 ) ;
} , 0.5 )
this . power = 0
}
@@ -346,24 +359,24 @@ export class HeroViewComp extends CCComp {
return { pos , t_pos }
}
shoot_enemy ( skill_uuid :number , y :number = 0 , x :number = 0 ) {
shoot_enemy ( sk1 :number , y :number = 0 , x :number = 0 ) {
// console.log("mon shoot_enemy");
let skill = ecs . getEntity < Skill > ( Skill ) ;
let increase_atk = Math . floor ( this . atk * smc . vm_data . mission . hero . atk )
let atk = smc . skills [ skill_uuid ] . atk + this . buff_atk + increase_atk ;
let atk = smc . skills [ sk1 ] . atk + this . atk_ buff+ increase_atk ;
let { pos , t_pos } = this . get_enemy_pos ( )
pos . y = pos . y + y
pos . x = pos . x + x
skill . load ( pos , this . box_group , this . node , skill_uuid , atk , t_pos ) ;
console . log ( this . scale + this . hero_name + "使用技能:" + skill_uuid ) ;
// this.tooltip(3,smc.skills[skill_uuid ].name,this.skill_uuid );
skill . load ( pos , this . box_group , this . node , sk1 , atk , t_pos ) ;
console . log ( this . scale + this . hero_name + "使用技能:" + sk1 ) ;
// this.tooltip(3,smc.skills[sk1 ].name,this.sk1 );
}
to_add_buff ( hero :any , s_uuid :number ) {
let skill = ecs . getEntity < Skill > ( Skill ) ;
let atk = smc . skills [ s_uuid ] . atk + this . atk ;
let { pos , t_pos } = this . get_hero_pos ( hero )
skill . load ( pos , this . box_group , this . node , this . max_skill_uuid , atk , t_pos ) ;
skill . load ( pos , this . box_group , this . node , this . sk2 , atk , t_pos ) ;
if ( smc . skills [ s_uuid ] . hp > 0 ) { //buff加血
let increase_hp = Math . floor ( smc . skills [ s_uuid ] . hp * this . atk * this . s_boncus * smc . vm_data . mission . hero . atk )
hero . add_hp ( increase_hp )
@@ -464,7 +477,7 @@ export class HeroViewComp extends CCComp {
console . log ( "atk_cd:" + this . atk_cd ) ;
this . as . atk ( ) ;
this . scheduleOnce ( ( ) = > {
this . handle_skill ( this . skill_uuid )
this . handle_skill ( this . sk1 )
} , 0.4 )
}
}
@@ -524,29 +537,29 @@ export class HeroViewComp extends CCComp {
}
add_atk ( atk : number , time :number = 0 ) {
if ( time > 0 ) {
this . buff_atk = 0
this . atk_ buff= 0
let buff = { atk :atk , time :time }
this . buff_atk s . push ( buff ) ;
this . buff_atk s . forEach ( ( element : { atk : number ; } ) = > {
this . buff_atk += element . atk
this . atk_ buffs. push ( buff ) ;
this . atk_ buffs. forEach ( ( element : { atk : number ; } ) = > {
this . atk_ buff += element . atk
} ) ;
} else {
this . atk += atk ;
}
// console.log(this.buff_atk s)
// console.log(this.atk_ buffs)
}
check_buff_atk s ( dt : number ) {
for ( let i = 0 ; i < this.buff_atk s.length ; i + + ) {
let buff = this.buff_atk s [ i ] ;
check_atk_ buffs ( dt : number ) {
for ( let i = 0 ; i < this.atk_ buffs.length ; i + + ) {
let buff = this.atk_ buffs [ i ] ;
buff.time - = dt ;
if ( buff.time < = 0 ) {
this.buff_atk - = buff.atk
this.buff_atk s.splice ( i , 1 ) ;
this.atk_ buff - = buff.atk
this.atk_ buffs.splice ( i , 1 ) ;
}
}
if ( this.buff_atk s.length < = 0 ) {
this.buff_atk = 0
if ( this.atk_ buffs.length < = 0 ) {
this.atk_ buff = 0
// this.buff_icon_change("atk",false)
this.sprite.setSharedMaterial ( this.orginalFlashMaterial , 0 ) ;
} else {