83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
import { _decorator, Label, ProgressBar, resources, Sprite, SpriteAtlas } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MSkillComp')
|
|
@ecs.register('MSkillComp', false)
|
|
export class MSkillComp extends CCComp {
|
|
s_uuid: number = 0;
|
|
group: number = 0;
|
|
lv:number = 0;
|
|
skill_on:boolean = false;
|
|
cd:number = 0;
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
}
|
|
init(){
|
|
this.lv=0
|
|
console.log("MSkillComp init s_uuid:",this.s_uuid,this.group);
|
|
this.node.getChildByName("lv").getComponent(Label).string=this.lv.toString()
|
|
if(SkillSet[this.s_uuid]==undefined){this.skill_on=false; return}
|
|
this.cd=SkillSet[this.s_uuid].cd;
|
|
this.s_uuid=smc.mission.mskill
|
|
smc.vmdata.mission.exp_max=SkillSet[this.s_uuid].exp
|
|
|
|
if(this.group == BoxSet.MONSTER){
|
|
this.s_uuid=smc.mission.mmskill
|
|
smc.vmdata.mission.mexp_max=SkillSet[this.s_uuid].exp
|
|
}
|
|
|
|
var icon_path = "game/skills/skill_icon"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[this.s_uuid].path);
|
|
});
|
|
this.skill_on=true
|
|
|
|
}
|
|
protected update(dt: number): void {
|
|
if(!this.skill_on) return
|
|
this.check_exp()
|
|
this.doing_cd(dt)
|
|
}
|
|
doing_cd(dt: number){
|
|
this.cd-=dt
|
|
this.node.getChildByName("cd").getComponent(ProgressBar).progress=this.cd/SkillSet[this.s_uuid].cd
|
|
if(this.cd<=0){
|
|
console.log("cd<=0")
|
|
this.cd=SkillSet[this.s_uuid].cd
|
|
}
|
|
}
|
|
|
|
check_exp(){
|
|
switch(this.group){
|
|
case BoxSet.HERO:
|
|
if(smc.vmdata.mission.exp >= SkillSet[this.s_uuid].exp){
|
|
console.log("hero MSkillComp check_exp s_uuid:",this.s_uuid,this.group);
|
|
smc.vmdata.mission.exp-=SkillSet[this.s_uuid].exp
|
|
this.lvup()
|
|
}
|
|
break;
|
|
case BoxSet.MONSTER:
|
|
if(smc.vmdata.mission.mexp >= SkillSet[this.s_uuid].exp){
|
|
console.log("monster MSkillComp check_exp s_uuid:",this.s_uuid,this.group);
|
|
smc.vmdata.mission.mexp-=SkillSet[this.s_uuid].exp
|
|
this.lvup()
|
|
}
|
|
}
|
|
}
|
|
lvup(){
|
|
this.lv++
|
|
this.node.getChildByName("lv").getComponent(Label).string=this.lv.toString()
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |