102 lines
4.0 KiB
TypeScript
102 lines
4.0 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 { CardSet } from "../common/config/CardSet";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
import { MonsterBuffComp } from "./MonsterBuffComp";
|
|
/** 角色实体 */
|
|
@ecs.register(`Monster`)
|
|
export class Monster extends ecs.Entity {
|
|
// 数据层
|
|
MonsterModel!: MonsterModelComp;
|
|
// 视图层
|
|
MonsterView!: MonsterViewComp;
|
|
MonsterBuff!: MonsterBuffComp; // 移动
|
|
|
|
protected init() {
|
|
this.addComponents<ecs.Comp>( MonsterModelComp);
|
|
|
|
}
|
|
|
|
destroy(): void {
|
|
this.remove(MonsterViewComp);
|
|
this.remove(MonsterBuffComp);
|
|
super.destroy();
|
|
}
|
|
|
|
/** 加载角色 */
|
|
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
|
|
// var path = "game/monster/"+prefab_path;
|
|
var path = "game/heros/hero";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
node.parent=layer
|
|
// var as = node.getComponent(MonsterSpine);
|
|
// let ratio=this.set_ratio(uuid);
|
|
node.setScale(node.scale.x*scale, node.scale.y, node.scale.z);
|
|
|
|
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, 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("monster_load",this)
|
|
}
|
|
// set_ratio(uuid:number){
|
|
// let ratio=1;
|
|
// switch (smc.heros[uuid].level) {
|
|
// case 2:
|
|
// ratio=1.1
|
|
// break;
|
|
// case 3:
|
|
// ratio=1.2
|
|
// break;
|
|
// case 4:
|
|
// ratio=1.3
|
|
// break;
|
|
// case 5:
|
|
// ratio=1.4
|
|
// break;
|
|
// default:
|
|
// ratio=1
|
|
// }
|
|
// return ratio;
|
|
// }
|
|
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
|
var mv = node.getComponent(MonsterViewComp)!;
|
|
var buff =node.getComponent(MonsterBuffComp)!;
|
|
mv.speed =mv.ospeed = smc.heros[uuid].speed;
|
|
mv.hero_name= smc.heros[uuid].name;
|
|
buff.group=mv.box_group= BoxSet.MONSTER;
|
|
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.skill_uuid = 9001;
|
|
mv.max_skill_uuid = smc.heros[uuid].max_skill_uuid;
|
|
mv.scale = -1;
|
|
mv.Tpos = v3(0,0,0);
|
|
this.add(mv);
|
|
this.add(buff);
|
|
}
|
|
} |