This commit is contained in:
2024-11-13 10:26:06 +08:00
parent 208e8364a8
commit 4e08ad13d1
5 changed files with 475 additions and 69 deletions

View File

@@ -1,8 +1,9 @@
export const HeroSet = {
9001: {
uuid: 9001, path: "k1", type: 1, level: 1,cost:2, name: "白骑士", atk: 10, hp: 100, atk_dis: 100, atk_cd: 1, power: 0, power_max: 15, speed: 40,
skill_uuid: 9001, max_skill_uuid: 2002, atktype: 1,
uuid: 9001, path: "k1", type: 1, level: 1,cost:2, name: "白骑士",
atk: 10, hp: 100, atk_dis: 100, atk_cd: 1, power: 0, power_max: 15, speed: 40,
sk1: 9001, sk2: 2002, sk3: 9001, sk4: 2002, sk5: 9001, sk6: 2002, atktype: 1,
},

View File

@@ -73,15 +73,19 @@ export class Hero extends ecs.Entity {
let talents=Talents;
hv.scale = scale;
hv.box_group = box_group;
hv.speed =hv.ospeed = hero_set.speed;
hv.hero_uuid= uuid;
hv.hero_name= hero_set.name;
hv.speed =hv.ospeed = hero_set.speed;
hv.atk_dis = hero_set.atk_dis;
hv.power = hero_set.power;
hv.level = hero_set.level;
hv.type = hero_set.type;
hv.skill_uuid = hero_set.skill_uuid;
hv.max_skill_uuid = hero_set.max_skill_uuid;
hv.sk1 = hero_set.sk1;
hv.sk2 = hero_set.sk2;
hv.sk3 = hero_set.sk3;
hv.sk4 = hero_set.sk4;
hv.sk5 = hero_set.sk5;
hv.role_heros_index = index;
hv.type = hero_set.type;
hv.hp= hv.hp_max =hero_set.hp;

View File

@@ -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; /** 角色阵营 1hero -1 :mon */
type: number = 1; /**角色类型 1前排 2 后排 */
state: number = 1; /** 状态 1move ,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_atks(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_atks.push(buff);
this.buff_atks.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_atks)
// console.log(this.atk_buffs)
}
check_buff_atks(dt: number){
for(let i=0;i<this.buff_atks.length;i++){
let buff=this.buff_atks[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_atks.splice(i,1);
this.atk_buff -= buff.atk
this.atk_buffs.splice(i,1);
}
}
if(this.buff_atks.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{

View File

@@ -193,7 +193,6 @@ export class MapMonsterComp extends CCComp {
let mon:any = monsters[i].HeroView.node.position
smc.enemy_pos[i].x= mon.x
}
console.log("count_mon_pos",smc.enemy_pos);
}
count_hero_pos(){
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
@@ -202,7 +201,6 @@ export class MapMonsterComp extends CCComp {
let ho:any = heros[i].HeroView.node.position
smc.hero_pos[i].x= ho.x
}
console.log("count_hero_pos",smc.hero_pos);
}
private on_do_add_hero(event: string, args: any) {