技能cd 完善
This commit is contained in:
@@ -1,413 +0,0 @@
|
||||
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, HeroUI, 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";
|
||||
import { cardType, getRandomCardsByType, SuperCards, SuperCardsList, SuperCardsType } from "../common/config/CardSet";
|
||||
import { LuckCardComp } from "./LuckCardComp";
|
||||
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:any={
|
||||
0:false,
|
||||
1:false,
|
||||
2:false,
|
||||
3:false,
|
||||
4:false,
|
||||
5:false,
|
||||
}
|
||||
heros:any={
|
||||
0:{uuid:0,count:0},
|
||||
1:{uuid:0,count:0},
|
||||
2:{uuid:0,count:0},
|
||||
}
|
||||
func_queue:any=[]
|
||||
|
||||
|
||||
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.UseHeroCard,this.hero_called,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(){
|
||||
// 奖励发放
|
||||
}
|
||||
hero_called(event: any, data: any) {
|
||||
// 查找空位或已存在的英雄
|
||||
const heroIndex = this.findHeroSlot(data.uuid);
|
||||
|
||||
if (heroIndex !== -1) {
|
||||
// 找到英雄位置,增加数量
|
||||
this.heros[heroIndex].count += 1;
|
||||
} else {
|
||||
// 查找空位
|
||||
const emptySlot = this.findEmptySlot();
|
||||
if (emptySlot !== -1) {
|
||||
// 有空位,添加新英雄
|
||||
this.heros[emptySlot].uuid = data.uuid;
|
||||
this.heros[emptySlot].count = 1;
|
||||
} else {
|
||||
console.log("[MissionComp] 英雄已满");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找英雄位置
|
||||
* @param uuid 英雄UUID
|
||||
* @returns 英雄索引,未找到返回-1
|
||||
*/
|
||||
private findHeroSlot(uuid: number): number {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (this.heros[i].uuid === uuid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找空位
|
||||
* @returns 空位索引,无空位返回-1
|
||||
*/
|
||||
private findEmptySlot(): number {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (this.heros[i].uuid === 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
count_tal(){
|
||||
let count=0
|
||||
for(let i=0;i<FightSet.TAL_NUM;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) {
|
||||
// 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.run_time()
|
||||
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
|
||||
this.time_cd.reset()
|
||||
}
|
||||
clear_time(){
|
||||
this.node.getChildByName("time").active=false
|
||||
this.is_show_time=false
|
||||
this.next_func=undefined
|
||||
this.time_cd.reset()
|
||||
}
|
||||
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(){
|
||||
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
|
||||
this.node.getChildByName("ending").active=false
|
||||
},0.5)
|
||||
this.to_ready()
|
||||
|
||||
|
||||
}
|
||||
to_ready(){
|
||||
console.log("[MissionComp] ** 2 ** to_ready")
|
||||
oops.message.dispatchEvent(GameEvent.HeroSelect,{called:[]})
|
||||
}
|
||||
ready_to_fight(){
|
||||
console.log("[MissionComp] ** 3 ** 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(){
|
||||
let called = Object.values(this.heros).filter((item: any) => item.uuid != 0)
|
||||
oops.message.dispatchEvent(GameEvent.HeroSelect,{called:called})
|
||||
}
|
||||
|
||||
to_fight(){
|
||||
console.log("[MissionComp] ** 4 ** 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("任务结束")
|
||||
this.node.getChildByName("ending").active=true
|
||||
this.node.getChildByName("ending").getComponent(Animation).play("endFight")
|
||||
// 延迟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 = 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.heros={
|
||||
0:{uuid:0,count:0},
|
||||
1:{uuid:0,count:0},
|
||||
2:{uuid:0,count:0},
|
||||
}
|
||||
|
||||
this.clear_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())
|
||||
|
||||
}
|
||||
|
||||
|
||||
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_tal_card(){
|
||||
oops.message.dispatchEvent(GameEvent.TalentSelect)
|
||||
}
|
||||
call_func_card(){
|
||||
if(smc.vmdata.mission_data.gold < smc.vmdata.mission_data.lucky_gold){
|
||||
oops.gui.toast("金币不足", false);
|
||||
return
|
||||
}
|
||||
this.do_lucky_card()
|
||||
|
||||
}
|
||||
do_lucky_card(){
|
||||
smc.vmdata.mission_data.gold-=smc.vmdata.mission_data.lucky_gold
|
||||
let list=getRandomCardsByType(cardType.SPECIAL,1)
|
||||
let card=SuperCards[list[0].uuid]
|
||||
console.log("[MissionComp] do_lucky_card",card)
|
||||
this.show_lucky_gold(card)
|
||||
oops.message.dispatchEvent(GameEvent.LuckCardUsed,card)
|
||||
}
|
||||
show_lucky_gold(card:any){
|
||||
// this.node.getChildByName("luckybox").getComponent(Animation).play("luckyopen")
|
||||
var path = "game/gui/lcard";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.setScale(0,0,0)
|
||||
node.getComponent(LuckCardComp).show_card(card)
|
||||
node.parent = this.node
|
||||
node.setPosition(v3(this.node.getChildByName("luckybox").position.x,this.node.getChildByName("luckybox").position.y));
|
||||
let height=this.node.getComponent(UITransform).height
|
||||
tween(node) .to(1, {
|
||||
scale: v3(1,1,1),
|
||||
position: v3(0, height-300),
|
||||
}, {easing:"backOut"})
|
||||
.start();
|
||||
|
||||
}
|
||||
private cleanComponents() {
|
||||
smc.vmdata.hero1=JSON.parse(JSON.stringify(HeroUI))
|
||||
smc.vmdata.hero2=JSON.parse(JSON.stringify(HeroUI))
|
||||
smc.vmdata.hero3=JSON.parse(JSON.stringify(HeroUI))
|
||||
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
|
||||
}
|
||||
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user