187 lines
6.2 KiB
TypeScript
187 lines
6.2 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 { FightSet, MissionData, Missions, MissionStatus, VmInfo} 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);
|
|
waveTimer:Timer = new Timer(10);
|
|
normal_max_wave:number = 10;
|
|
is_fight:boolean = false;
|
|
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)
|
|
this.on(GameEvent.WaveUpdate,this.on_mon_wave_update,this)
|
|
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause){
|
|
return
|
|
}
|
|
if(smc.vmdata.mission_data.in_fight){
|
|
smc.vmdata.mission_data.fight_time+=dt
|
|
if(this.GlodAddTimer.update(dt)){
|
|
smc.vmdata.mission_data.gold+=(smc.vmdata.mission_data.add_gold+smc.vmdata.mission_data.buff_add_gold)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private on_mon_wave_update(){
|
|
smc.vmdata.mission_data.current_wave++
|
|
let wave=smc.vmdata.mission_data.current_wave
|
|
if(wave==FightSet.FRIEND_WAVE_UP){
|
|
console.log("[任务系统] FRIEND_WAVE_UP 伙伴选择 :",wave,FightSet.FRIEND_WAVE_UP)
|
|
let node= this.node.getChildByName("new_hero")
|
|
tween(node).to(0.3, {position:v3(280,node.position.y,1)}).start()
|
|
}
|
|
|
|
}
|
|
|
|
async mission_start(){
|
|
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_ready()
|
|
this.to_fight()
|
|
loading.active=false
|
|
},0.5)
|
|
}
|
|
to_ready(){
|
|
console.log("英雄技能选择")
|
|
// oops.message.dispatchEvent(GameEvent.HeroSkillSelect)
|
|
}
|
|
|
|
to_call_friend(){
|
|
oops.message.dispatchEvent(GameEvent.HeroSelect)
|
|
}
|
|
|
|
to_fight(){
|
|
smc.vmdata.mission_data.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.active=false
|
|
}
|
|
|
|
data_init(){
|
|
//局内数据初始化 smc 数据初始化
|
|
console.log("局内数据初始化")
|
|
smc.mission.play = true;
|
|
smc.vmdata.mission_data = JSON.parse(JSON.stringify(MissionData));
|
|
smc.vmdata.hero = JSON.parse(JSON.stringify(VmInfo));
|
|
smc.vmdata.friend = JSON.parse(JSON.stringify(VmInfo));
|
|
smc.vmdata.boss = JSON.parse(JSON.stringify(VmInfo));
|
|
this.GlodAddTimer=new Timer(smc.vmdata.mission_data.refrsh_time)
|
|
this.hide_call_friend()
|
|
|
|
|
|
}
|
|
|
|
//角色初始化
|
|
hart_hero_load(){
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
hero.hart_load()
|
|
}
|
|
|
|
card_init(){
|
|
oops.message.dispatchEvent(GameEvent.CardRefresh)
|
|
}
|
|
|
|
card_refresh(){
|
|
let mission_data=smc.vmdata.mission_data
|
|
if(mission_data.gold < (mission_data.refresh_gold+mission_data.buff_refresh_gold)){
|
|
oops.gui.toast("金币不足", false);
|
|
return
|
|
}
|
|
oops.message.dispatchEvent(GameEvent.CardRefresh)
|
|
mission_data.gold-=(mission_data.refresh_gold+mission_data.buff_refresh_gold)
|
|
|
|
}
|
|
call_friend_card(){
|
|
oops.message.dispatchEvent(GameEvent.HeroSelect)
|
|
}
|
|
call_equip_card(){
|
|
let mission_data=smc.vmdata.mission_data
|
|
if(mission_data.gold < (mission_data.refresh_gold+mission_data.buff_refresh_gold)){
|
|
oops.gui.toast("金币不足", false);
|
|
return
|
|
}
|
|
oops.message.dispatchEvent(GameEvent.EquipSelect)
|
|
mission_data.gold-=(mission_data.refresh_gold+mission_data.buff_refresh_gold)
|
|
|
|
}
|
|
call_func_card(){
|
|
let mission_data=smc.vmdata.mission_data
|
|
if(mission_data.gold < (mission_data.refresh_gold+mission_data.buff_refresh_gold)){
|
|
oops.gui.toast("金币不足", false);
|
|
return
|
|
}
|
|
oops.message.dispatchEvent(GameEvent.FuncSelect)
|
|
mission_data.gold-=(mission_data.refresh_gold+mission_data.buff_refresh_gold)
|
|
|
|
}
|
|
call_skill_card(e:any,data:any){
|
|
console.log("call_skill_card",e)
|
|
oops.message.dispatchEvent(GameEvent.HeroSkillSelect,{slot:data})
|
|
}
|
|
private cleanComponents() {
|
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
|
|
}
|
|
hide_call_friend(){
|
|
let node =this.node.getChildByName("new_hero")
|
|
tween(node).to(0.3, {position:v3(480,node.position.y,1)}).start()
|
|
}
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |