Files
heros/assets/script/game/map/MissionComp.ts
2025-06-12 23:35:25 +08:00

143 lines
4.6 KiB
TypeScript

import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI } 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 { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { MissionData, Missions, MissionStatus} from "../common/config/Mission";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "../hero/HeroViewComp";
import { Hero } from "../hero/Hero";
const { ccclass, property } = _decorator;
//@todo this is a test
/** 视图层对象 */
@ccclass('MissionComp')
@ecs.register('MissionComp', false)
export class MissionComp extends CCComp {
VictoryComp:any = null;
reward:number = 0;
reward_num:number = 0;
GlodAddTimer:Timer = new Timer(1);
onLoad(){
this.on(GameEvent.MissionStart,this.mission_start,this)
this.on(GameEvent.FightEnd,this.fight_end,this)
this.on(GameEvent.MissionEnd,this.mission_end,this)
this.on(GameEvent.CardsClose,this.after_used_skill_card,this)
}
protected update(dt: number): void {
if(!smc.mission.play||smc.mission.pause){
return
}
if(this.GlodAddTimer.update(dt)){
smc.vmdata.mission_data.gold+=smc.vmdata.mission_data.add_gold
}
}
async mission_start(){
smc.mission.status=MissionStatus.ready
oops.message.dispatchEvent(GameEvent.FightReady)
this.node.active=true
this.data_init()
this.hart_hero_load()
let loading=this.node.parent.getChildByName("loading")
loading.active=true
this.scheduleOnce(()=>{
this.to_hero_skill_select()
loading.active=false
},0.5)
}
to_hero_skill_select(){
console.log("英雄技能选择")
oops.message.dispatchEvent(GameEvent.HeroSkillSelect)
smc.mission.status=MissionStatus.ready_skill_select
}
after_used_skill_card(){
switch(smc.mission.status){
case MissionStatus.ready_skill_select:
console.log("next to_hero_select")
this.scheduleOnce(()=>{
this.to_hero_select()
},0.3)
break
case MissionStatus.ready_hero_select:
console.log("netx to_fight")
this.to_fight()
break
case MissionStatus.playing:
break
}
}
to_hero_select(){
smc.mission.status=MissionStatus.ready_hero_select
oops.message.dispatchEvent(GameEvent.HeroSelect)
}
to_fight(){
smc.mission.status=MissionStatus.playing
oops.message.dispatchEvent(GameEvent.FightStart)
}
to_end_fight(){
smc.mission.status=MissionStatus.end
oops.message.dispatchEvent(GameEvent.FightEnd)
}
fight_end(){
console.log("任务结束")
// 延迟0.5秒后执行任务结束逻辑
this.scheduleOnce(() => {
smc.mission.play=false
smc.mission.pause=false
this.cleanComponents()
}, 0.5)
}
mission_end(){
this.node.active=false
}
data_init(){
//局内数据初始化
console.log("局内数据初始化")
smc.mission.play = true;
smc.vmdata.mission_data = JSON.parse(JSON.stringify(MissionData));
this.GlodAddTimer=new Timer(smc.vmdata.mission_data.refrsh_time)
}
//角色初始化
hart_hero_load(){
let hero = ecs.getEntity<Hero>(Hero);
hero.hart_load()
}
card_init(){
oops.message.dispatchEvent(GameEvent.CardRefresh)
}
card_refresh(){
if(smc.vmdata.mission_data.gold< smc.vmdata.mission_data.refresh_gold){
oops.gui.toast("金币不足", false);
return
}
oops.message.dispatchEvent(GameEvent.CardRefresh)
smc.vmdata.mission_data.gold-=smc.vmdata.mission_data.refresh_gold
}
private cleanComponents() {
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
}
/** 视图层逻辑代码分离演示 */
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}