Files
heros/assets/script/game/map/MSkillComp.ts
2025-08-04 23:58:11 +08:00

143 lines
4.8 KiB
TypeScript

import { _decorator, resources, Sprite, SpriteAtlas ,Node, ProgressBar, tween, v3, Label, Animation, CCString, CCInteger} 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 { GameEvent } from "../common/config/GameEvent";
import { CdType, SkillSet } from "../common/config/SkillSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "db://oops-framework/core/Oops";
import { MissionEvent } from "../common/config/MissionEvent";
import { HeroInfo } from "../common/config/heroSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('MSkillComp')
@ecs.register('MSkill', false)
export class MSkillComp extends CCComp {
@property(CCString)
skill_slot:string="skill1"
@property(CCInteger)
skill_slot_index:number=1
skill:any=null
skill_cd_bar_progress:any=null
max_show:boolean=false
/** 视图层逻辑代码分离演示 */
onLoad() {
this.on(GameEvent.UseSkillCard, this.get_skill, this);
this.on(GameEvent.FightReady,this.fight_ready,this)
this.on(GameEvent.MasterCalled,this.master_called,this)
// this.node.getChildByName("icon").getChildByName("cd").active=false
}
start(){
this.fight_ready()
}
private master_called(e:any,data:any){
console.log("[EquipSkillComp]: master_called",data)
let hero=HeroInfo[data.uuid]
if(hero.skills.length>0){
this.get_skill(null,{slot:this.skill_slot,uuid:hero.skills[this.skill_slot_index]})
}
}
fight_ready(){
console.log("[MSkillComp]: fight_ready",this.node)
this.node.getChildByName("icon").active=false
this.hide_skill_get(null,"skill1")
this.skill={
uuid:0,
name:"skill1",
type:0, //1 被动 0 主动
level:0,
quality:0,
cd:0,
cd_time:0,
active:false,
}
}
update(dt: number): void {
if(!smc.mission.play||smc.mission.pause) return
if(this.skill.uuid!=0){
let cd=this.skill.cd/((smc.vmdata.hero.skill_cd_buff)/100+1)
if(this.skill.cd_time < cd){
this.skill.cd_time+=dt
}else{
if(this.skill.type==1){
this.spell_skill()
}
}
let progress=(1-this.skill.cd_time/cd)
this.node.getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=progress
}
}
show_max(){
this.node.getChildByName("light").active=true
this.node.getComponent(Animation).play()
}
hide_max(){
this.max_show=false
this.node.getChildByName("light").active=false
this.node.setScale(1,1,1)
this.node.getComponent(Animation).stop()
}
spell_skill(){
console.log("spell_skill")
this.skill.cd_time=0
tween(this.node).to(0.1, {scale:v3(1.2,1.2,1)},{onComplete:()=>{
tween(this.node).to(0.2, {scale:v3(1,1,1)}).start()
}}).start()
this.do_skill(this.skill.uuid)
this.hide_max()
}
do_skill(uuid:number){
oops.message.dispatchEvent(GameEvent.CastHeroSkill,uuid)
}
get_skill(e:GameEvent,data:any){
console.log("[MSkillComp]: get_skill",data)
if(data.slot==this.skill_slot||this.skill_slot_index==data.slot){
this.skill.uuid=data.uuid
this.skill.skill_name=SkillSet[data.uuid].name
this.skill.type=1
this.skill.cd=SkillSet[data.uuid].cd
this.skill.cd_time=SkillSet[data.uuid].cd
let icon1 = this.node.getChildByName("icon")
icon1.active=true
// if(SkillSet[data.uuid].CdType!=CdType.cd){
// icon1.getChildByName("cd").active=false
// }
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = icon1.getChildByName("skill").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
});
}
}
call_skill_card(e:any,data:any){
oops.message.dispatchEvent(GameEvent.HeroSkillSelect,{slot:data})
}
show_info(e:any,data:any){
console.log("[MSkillComp]: show_info",this.skill)
}
private hide_skill_get(e:any,data:string){
this.node.getChildByName("get").active =false
this.node.getChildByName("tip").active =false
this.node.getChildByName("light").active=false
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}