324 lines
10 KiB
TypeScript
324 lines
10 KiB
TypeScript
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI, instantiate, Prefab } 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, 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";
|
|
import { defaultEnhancements, EnhancementOptions } from "../common/config/LevelUp";
|
|
import { MonModelComp } from "../hero/MonModelComp";
|
|
import { TalentSlot } from "../common/config/TalentSet";
|
|
import { RogueTalWave } from "./RogueConfig";
|
|
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);
|
|
normal_max_wave:number = 10;
|
|
is_fight:boolean = false;
|
|
enhancements:any=[0,0,0,0,0]
|
|
update_count:number = 0;
|
|
is_show_time:boolean = false;
|
|
time_num:number = 0;
|
|
time_cd:Timer=new Timer(1);
|
|
|
|
next_func?:Function;
|
|
wave_time_num:number = 0;
|
|
wave_time_cd:Timer=new Timer(1);
|
|
is_in_wave:boolean = false;
|
|
tals:{
|
|
0:false,
|
|
1:false,
|
|
2:false,
|
|
3:false,
|
|
4:false,
|
|
5:false,
|
|
}
|
|
|
|
onLoad(){
|
|
this.on(GameEvent.MissionStart,this.mission_start,this)
|
|
this.on(GameEvent.MasterCalled,this.ready_to_fight,this)
|
|
// this.on(GameEvent.CardsClose,this.after_used_skill_card,this)
|
|
this.on(GameEvent.MonDead,this.do_mon_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)
|
|
// this.on(GameEvent.UseEnhancement,this.hide_uplv_button,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)
|
|
}
|
|
}
|
|
if(this.is_show_time){
|
|
if(this.time_cd.update(dt)){
|
|
this.run_time()
|
|
}
|
|
}
|
|
|
|
// if(this.is_in_wave){
|
|
// if(this.wave_time_cd.update(dt)){
|
|
// smc.vmdata.mission_data.wave_time_num--
|
|
// if(smc.vmdata.mission_data.wave_time_num<=0){
|
|
// this.hide_wave_time()
|
|
// this.show_time(this.do_next_wave.bind(this))
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
//奖励发放
|
|
do_reward(){
|
|
// 奖励发放
|
|
}
|
|
|
|
count_tal(){
|
|
let count=0
|
|
for(let i=0;i<5;i++){
|
|
if(this.tals[i]){
|
|
count++
|
|
}
|
|
}
|
|
return count
|
|
}
|
|
|
|
do_mon_dead(){
|
|
this.do_mon_dead_thing()
|
|
smc.vmdata.mission_data.mon_num--
|
|
if(smc.vmdata.mission_data.mon_num<=0 && this.count_tal() < 6) {
|
|
if(smc.vmdata.mission_data.current_wave == RogueTalWave[this.count_tal()].wave){
|
|
console.log("[MissionComp] current_wave:"+smc.vmdata.mission_data.current_wave+" tal wave:"+RogueTalWave[this.count_tal()].wave)
|
|
oops.message.dispatchEvent(GameEvent.TalentSelect,{slot:TalentSlot[this.count_tal()]})
|
|
this.tals[this.count_tal()]=true
|
|
|
|
}
|
|
this.show_time(this.do_next_wave.bind(this))
|
|
}
|
|
}
|
|
|
|
do_mon_dead_thing(){
|
|
smc.vmdata.mission_data.gold+=smc.vmdata.mission_data.add_gold+smc.vmdata.mission_data.buff_add_gold
|
|
}
|
|
|
|
do_next_wave(){ //怪物死亡后,重置时间
|
|
smc.vmdata.mission_data.current_wave++
|
|
smc.vmdata.mission_data.refresh_count++
|
|
oops.message.dispatchEvent(GameEvent.NewWave)
|
|
this.show_wave_time()
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
show_wave_time(){
|
|
smc.vmdata.mission_data.wave_time_num=FightSet.ONE_WAVE_TIME
|
|
this.is_in_wave=true
|
|
}
|
|
|
|
hide_wave_time(){
|
|
this.is_in_wave=false
|
|
}
|
|
|
|
show_time(onHide?:Function){
|
|
this.time_num=FightSet.DOWN_TIME
|
|
this.node.getChildByName("time").active=true
|
|
this.is_show_time=true
|
|
this.next_func=onHide
|
|
}
|
|
|
|
hide_time(){
|
|
if(this.next_func){
|
|
this.next_func()
|
|
}
|
|
this.node.getChildByName("time").active=false
|
|
this.is_show_time=false
|
|
this.next_func=undefined
|
|
}
|
|
|
|
run_time(){
|
|
this.node.getChildByName("time").setScale(0,0,0)
|
|
tween(this.node.getChildByName("time"))
|
|
.to(0.2, {scale:v3(1,1,1)}, {easing:"backOut"})
|
|
.to(0.2, {scale:v3(0,0,0)}, {easing:"backIn"})
|
|
.start()
|
|
this.time_num--
|
|
this.node.getChildByName("time").getChildByName("time").getComponent(Label).string=this.time_num.toString()
|
|
if(this.time_num<=0){
|
|
this.hide_time()
|
|
}
|
|
}
|
|
|
|
|
|
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(()=>{
|
|
loading.active=false
|
|
},0.5)
|
|
this.to_ready()
|
|
|
|
|
|
}
|
|
to_ready(){
|
|
oops.message.dispatchEvent(GameEvent.HeroSelect,{is_master:true})
|
|
}
|
|
ready_to_fight(){
|
|
this.time_num=5
|
|
this.show_time(this.to_fight.bind(this))
|
|
}
|
|
// show_uplv_button(){
|
|
// this.update_count++
|
|
// this.node.getChildByName("uplv").active=true
|
|
// }
|
|
// hide_uplv_button(){
|
|
// this.update_count--
|
|
// if(this.update_count > 0) return
|
|
// this.node.getChildByName("uplv").active=false
|
|
// }
|
|
// to_uplv(){
|
|
// oops.message.dispatchEvent(GameEvent.EnhancementSelect)
|
|
// }
|
|
to_call_friend(){
|
|
oops.message.dispatchEvent(GameEvent.HeroSelect,{is_master:false})
|
|
}
|
|
|
|
to_fight(){
|
|
console.log("[MissionComp] to_fight")
|
|
smc.vmdata.mission_data.in_fight=true
|
|
oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪
|
|
this.do_next_wave()
|
|
}
|
|
|
|
|
|
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 数据初始化
|
|
smc.mission.play = true;
|
|
smc.vmdata.mission_data = JSON.parse(JSON.stringify(MissionData));
|
|
smc.vmdata.hero = JSON.parse(JSON.stringify(VmInfo));
|
|
smc.vmdata.boss = JSON.parse(JSON.stringify(VmInfo));
|
|
this.update_count=0
|
|
this.GlodAddTimer=new Timer(smc.vmdata.mission_data.refrsh_time)
|
|
smc.enhancements=defaultEnhancements()
|
|
this.hide_time()
|
|
this.hide_wave_time()
|
|
this.tals={
|
|
0:false,
|
|
1:false,
|
|
2:false,
|
|
3:false,
|
|
4:false,
|
|
5:false,
|
|
}
|
|
smc.vmdata.mission_data.wave_time_num=FightSet.ONE_WAVE_TIME
|
|
console.log("局内数据初始化",smc.enhancements,defaultEnhancements())
|
|
|
|
}
|
|
|
|
//角色初始化
|
|
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,{is_master:false})
|
|
}
|
|
|
|
call_func_card(){
|
|
this.show_lucky_gold()
|
|
|
|
}
|
|
show_lucky_gold(){
|
|
var path = "game/gui/lcard";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
node.setScale(0,0,0)
|
|
node.parent = this.node
|
|
node.setPosition(v3(this.node.getChildByName("luckybox").position.x,this.node.getChildByName("luckybox").position.y));
|
|
|
|
tween(node) .to(0.5, {
|
|
scale: v3(1,1,1),
|
|
position: v3(0,this.node.getChildByName("luckybox").position.y+200),
|
|
}, {easing:"backOut"})
|
|
.start();
|
|
}
|
|
private cleanComponents() {
|
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
|
|
}
|
|
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |