/* * @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"; import { BoxSet } from "../common/config/BoxSet"; /** 角色实体 */ @ecs.register(`Hero`) export class Hero extends ecs.Entity { // 数据层 HeroModel!: HeroModelComp; // 视图层 MonsterView!: MonsterViewComp; protected init() { this.addComponents(HeroModelComp); } destroy(): void { this.remove(MonsterViewComp); this.remove(MonsterModelComp); super.destroy(); } /** 加载角色 */ load(pos: Vec3 = Vec3.ZERO,scale: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); let ratio=this.set_ratio(uuid); node.setScale(ratio*node.scale.x, ratio*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("hero_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)!; mv.hero_uuid=uuid; mv.speed =mv.ospeed = smc.heros[uuid].speed; mv.hero_name= smc.heros[uuid].name; mv.box_group= BoxSet.HERO; 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.Tpos = v3(0,0,0); mv.scale = 1; mv.change_name(smc.heros[uuid].name,1) this.add(mv); } }