83 lines
3.1 KiB
TypeScript
83 lines
3.1 KiB
TypeScript
|
|
/*
|
|
* @Author: dgflash
|
|
* @Date: 2021-11-18 17:47:56
|
|
* @LastEditors: dgflash
|
|
* @LastEditTime: 2022-08-04 15:43:04
|
|
*/
|
|
import { instantiate, Node, Prefab, Vec3,v3,resources,SpriteFrame,Sprite,SpriteAtlas} from "cc";
|
|
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { MonsterModelComp } from "./MonsterModelComp";
|
|
import { MonsterSpine } from "./MonsterSpine";
|
|
import { MonsterViewComp } from "./MonsterViewComp";
|
|
import {HeroModelComp} from "./HeroModelComp";
|
|
import { CardSet } from "../common/config/CardSet";
|
|
/** 角色实体 */
|
|
@ecs.register(`Hero`)
|
|
export class Hero extends ecs.Entity {
|
|
// 数据层
|
|
HeroModel!: HeroModelComp;
|
|
// 视图层
|
|
MonsterView!: MonsterViewComp;
|
|
|
|
protected init() {
|
|
this.addComponents<ecs.Comp>(HeroModelComp);
|
|
}
|
|
|
|
destroy(): void {
|
|
this.remove(MonsterViewComp);
|
|
this.remove(MonsterModelComp);
|
|
super.destroy();
|
|
}
|
|
|
|
/** 加载角色 */
|
|
load(pos: Vec3 = Vec3.ZERO,camp:number = 1,uuid:number=1001) {
|
|
// var path = "game/monster/"+prefab_path;
|
|
var path = "game/heros/hero";
|
|
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
var scene = smc.map.MapView.scene;
|
|
node.parent = scene.entityLayer!.node!;
|
|
// var as = node.getComponent(MonsterSpine);
|
|
|
|
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
|
node.setPosition(pos)
|
|
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
|
const url = 'game/heros/heros';
|
|
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
|
|
|
sprite.spriteFrame = atlas.getSpriteFrame(smc.heros[uuid].path);
|
|
});
|
|
this.hero_init(uuid,node)
|
|
oops.message.dispatchEvent("hero_load",this)
|
|
}
|
|
|
|
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
|
var mv = node.getComponent(MonsterViewComp)!;
|
|
mv.hero_uuid=uuid;
|
|
mv.speed =mv.ospeed = smc.heros[uuid].speed;
|
|
mv.hero_name= smc.heros[uuid].name;
|
|
mv.hp= mv.hp_max = smc.heros[uuid].hp;
|
|
mv.level = smc.heros[uuid].level;
|
|
mv.atk = smc.heros[uuid].atk;
|
|
mv.atk_cd = smc.heros[uuid].atk_cd;
|
|
mv.power = smc.heros[uuid].power;
|
|
mv.type = smc.heros[uuid].type;
|
|
mv.Tpos = v3(0,0,0);
|
|
mv.camp = 1;
|
|
mv.change_name(smc.heros[uuid].name,1)
|
|
this.add(mv);
|
|
this.push_monsters_in(uuid,mv.ent.eid)
|
|
}
|
|
push_monsters_in(uuid:number=1001,eid:number=0){
|
|
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})
|
|
}
|
|
|
|
|
|
} |