145 lines
4.7 KiB
TypeScript
145 lines
4.7 KiB
TypeScript
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI, instantiate, Prefab, screen } 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 { FightSet} 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 { MonModelComp } from "../hero/MonModelComp";
|
|
import { SkillCom } from "../skills/SkillCom";
|
|
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;
|
|
|
|
|
|
onLoad(){
|
|
this.on(GameEvent.MissionStart,this.mission_start,this)
|
|
this.on(GameEvent.MonDead,this.do_mon_dead,this)
|
|
this.on(GameEvent.HeroDead,this.do_hero_dead,this)
|
|
this.on(GameEvent.FightEnd,this.fight_end,this)
|
|
this.on(GameEvent.MissionEnd,this.mission_end,this)
|
|
this.on(GameEvent.DO_AD_BACK,this.do_ad,this)
|
|
// this.on(GameEvent.CanUpdateLv,this.show_uplv_button,this)
|
|
}
|
|
protected update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause){
|
|
return
|
|
}
|
|
if(smc.mission.in_fight){
|
|
smc.vmdata.mission_data.fight_time+=dt
|
|
}
|
|
}
|
|
//奖励发放
|
|
do_reward(){
|
|
// 奖励发放
|
|
}
|
|
|
|
do_mon_dead(){
|
|
smc.addGold(1)
|
|
smc.vmdata.mission_data.mon_num--
|
|
console.log("[MissionComp] do_mon_dead",smc.vmdata.mission_data.mon_num)
|
|
if(smc.vmdata.mission_data.mon_num<=0) {
|
|
smc.addMission()
|
|
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:true})
|
|
}
|
|
}
|
|
do_hero_dead(){
|
|
smc.vmdata.mission_data.hero_num--
|
|
console.log("[MissionComp] do_hero_dead",smc.vmdata.mission_data.hero_num)
|
|
if(smc.vmdata.mission_data.hero_num<=0) {
|
|
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false})
|
|
}
|
|
}
|
|
do_ad(){
|
|
if(this.ad_back()){
|
|
oops.message.dispatchEvent(GameEvent.AD_BACK_TRUE)
|
|
smc.vmdata.mission_data.refresh_count+=FightSet.MORE_RC
|
|
}else{
|
|
oops.message.dispatchEvent(GameEvent.AD_BACK_FALSE)
|
|
}
|
|
}
|
|
|
|
ad_back(){
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
async mission_start(){
|
|
console.log("[MissionComp] ** 1 ** mission_start")
|
|
|
|
this.node.getChildByName("ending").getComponent(Animation).play("startFight")
|
|
oops.message.dispatchEvent(GameEvent.FightReady)
|
|
this.node.active=true
|
|
this.data_init()
|
|
let loading=this.node.parent.getChildByName("loading")
|
|
loading.active=true
|
|
this.scheduleOnce(()=>{
|
|
loading.active=false
|
|
},0.5)
|
|
this.scheduleOnce(()=>{
|
|
this.to_fight()
|
|
},0.1)
|
|
|
|
}
|
|
|
|
to_fight(){
|
|
smc.mission.in_fight=true
|
|
oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪
|
|
}
|
|
|
|
|
|
to_end_fight(){
|
|
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.getChildByName("ending").active=false
|
|
this.node.active=false
|
|
}
|
|
|
|
data_init(){
|
|
//局内数据初始化 smc 数据初始化
|
|
smc.mission.play = true;
|
|
smc.vmdata.mission_data.in_fight=false
|
|
smc.vmdata.mission_data.fight_time=0
|
|
smc.initReward()
|
|
console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data)
|
|
}
|
|
|
|
private cleanComponents() {
|
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
|
|
ecs.query(ecs.allOf(SkillCom)).forEach(entity => {entity.remove(SkillCom);entity.destroy()});
|
|
}
|
|
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |