mon 和hero 统一
This commit is contained in:
@@ -20,6 +20,7 @@ import { HeroSet,MonSet } from "../common/config/heroSet";
|
||||
import { Role } from "../Role/Role";
|
||||
import { MoveToComp } from "../common/ecs/position/MoveTo";
|
||||
import { Talents } from "../common/config/TalentSet";
|
||||
import { MonModelComp } from "../mon/MonModelComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
export class Hero extends ecs.Entity {
|
||||
@@ -30,7 +31,7 @@ export class Hero extends ecs.Entity {
|
||||
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>( HeroModelComp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +42,19 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!,index:number=-1) {
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!,index:number=-1,is_hero:boolean=true) {
|
||||
let box_group= 0
|
||||
|
||||
if (is_hero) {
|
||||
scale = 1
|
||||
box_group=BoxSet.HERO
|
||||
this.addComponents<ecs.Comp>( HeroModelComp);
|
||||
}else{
|
||||
scale=-1
|
||||
box_group=BoxSet.MONSTER
|
||||
this.addComponents<ecs.Comp>( MonModelComp);
|
||||
}
|
||||
|
||||
var path = "game/hero/"+smc.heros[uuid].path;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
@@ -52,17 +65,18 @@ export class Hero extends ecs.Entity {
|
||||
// pos.x=smc.Role.RoleView.node.position.x+pos.x;
|
||||
// pos.y=smc.Role.RoleView.node.position.y+pos.y;
|
||||
node.setPosition(pos)
|
||||
this.hero_init(uuid,node,index)
|
||||
this.hero_init(uuid,node,index,scale,box_group)
|
||||
oops.message.dispatchEvent("hero_load",this)
|
||||
}
|
||||
|
||||
hero_init(uuid:number=1001,node:Node,index:number=-1){
|
||||
hero_init(uuid:number=1001,node:Node,index:number=-1,scale:number=1,box_group=BoxSet.HERO){
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
// console.log("hero_init",buff)
|
||||
let hero_set= smc.heros[uuid]
|
||||
let role_talent= smc.vm_data.talent
|
||||
let talents=Talents;
|
||||
hv.scale = 1;
|
||||
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;
|
||||
|
||||
@@ -105,6 +105,7 @@ export class HeroViewComp extends CCComp {
|
||||
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").getChildByName("shield").active = false;
|
||||
// this.node.getChildByName("top").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").setScale(this.scale,1);
|
||||
@@ -124,6 +125,7 @@ export class HeroViewComp extends CCComp {
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
console.log("hero collider ",this.scale,collider);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
@@ -154,22 +156,22 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
|
||||
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()){
|
||||
// if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
|
||||
// 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());
|
||||
// }
|
||||
// // 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
|
||||
@@ -230,7 +232,10 @@ export class HeroViewComp extends CCComp {
|
||||
if(this.stop_cd > 0){
|
||||
return
|
||||
}
|
||||
if (this.node.position.x >= 250-this.atk_dis/2) {
|
||||
if (this.node.position.x >= 360 && this.scale==1) {
|
||||
return;
|
||||
}
|
||||
if(this.scale===-1&&this.node.position.x <= -360){
|
||||
return;
|
||||
}
|
||||
// if(this.enemy){
|
||||
@@ -301,14 +306,14 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
pos.y=pos.y + y
|
||||
pos.x=pos.x + x
|
||||
skill.load(pos,BoxSet.HERO,this.node,skill_uuid,atk,t_pos);
|
||||
skill.load(pos,this.box_group,this.node,skill_uuid,atk,t_pos);
|
||||
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
|
||||
}
|
||||
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,BoxSet.HERO,this.node,this.max_skill_uuid,atk,t_pos);
|
||||
skill.load(pos,this.box_group,this.node,this.max_skill_uuid,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)
|
||||
|
||||
Reference in New Issue
Block a user