清理掉 missioncomp的 抽卡相关的 游戏逻辑

This commit is contained in:
2025-08-11 22:02:20 +08:00
parent 89daacba36
commit 5bcf5e737b
13 changed files with 2344 additions and 1061 deletions

View File

@@ -1,6 +1,8 @@
import { _decorator, Animation, AnimationClip, CCInteger, Component, Node, resources } from 'cc';
import { _decorator, Animation, AnimationClip, CCInteger, Component, Label, Node, resources } from 'cc';
import { smc } from '../common/SingletonModuleComp';
import { HeroInfo } from '../common/config/heroSet';
import { GameEvent } from '../common/config/GameEvent';
import { oops } from 'db://oops-framework/core/Oops';
const { ccclass, property } = _decorator;
@ccclass('HeroReadyCom')
@@ -10,6 +12,7 @@ export class HeroReadyCom extends Component {
start() {
this.update_hero()
oops.message.on(GameEvent.UpdateHero,this.update_hero,this)
}
update(deltaTime: number) {
@@ -18,8 +21,10 @@ export class HeroReadyCom extends Component {
update_hero(){
let hero = smc.fight_heros[this.slot]
if(hero==0){
this.no_hero()
return
}
this.node.getChildByName("add").active=false
let hero_data = HeroInfo[hero]
console.log("[HeroReadyCom]hero_data",smc.fight_heros,hero,smc.fight_heros[this.slot],this.slot,hero_data)
let anm_path=hero_data.path
@@ -27,9 +32,14 @@ export class HeroReadyCom extends Component {
this.node.getChildByName("icon").getComponent(Animation).addClip(clip);
this.node.getChildByName("icon").getComponent(Animation).play("idle");
});
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=smc.heros[hero].lv.toString()
// console.log("[HeroReadyCom]clip",this.node.getChildByName("icon").getComponent(Animation))
}
no_hero(){
this.node.getChildByName("lv").active=false
this.node.getChildByName("add").active=true
}
}

View File

@@ -0,0 +1,413 @@
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();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d8d095e8-6cd9-4fe1-a9cc-bffcf04e0346",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -7,13 +7,6 @@ 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;
@@ -26,134 +19,31 @@ 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--
@@ -164,7 +54,6 @@ export class MissionComp extends CCComp {
// this.tals[this.count_tal()]=true
// }
this.show_time(this.do_next_wave.bind(this))
}
}
@@ -172,13 +61,6 @@ export class MissionComp extends CCComp {
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)
@@ -194,51 +76,7 @@ export class MissionComp extends CCComp {
}
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")
@@ -252,41 +90,14 @@ export class MissionComp extends CCComp {
loading.active=false
this.node.getChildByName("ending").active=false
},1)
this.to_ready()
this.to_fight()
}
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")
console.log("[MissionComp] ** 3 ** to_fight")
smc.vmdata.mission_data.in_fight=true
oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪
this.do_next_wave()
}
@@ -316,86 +127,9 @@ export class MissionComp extends CCComp {
//局内数据初始化 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())
console.log("局内数据初始化")
}
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))

View File

@@ -26,21 +26,34 @@ export class MissionHeroCompComp extends CCComp {
this.on(GameEvent.UseHeroCard,this.call_hero,this)
this.on(GameEvent.FightReady,this.fight_ready,this)
this.on(GameEvent.Zhaohuan,this.zhao_huan,this)
this.on(GameEvent.FightEnd,this.clear_heros,this)
}
start() {
// this.test_call()
}
clear_heros(){
console.log("[MissionHeroComp]: FightEnd clear heros")
}
fight_ready(){
this.heros=[]
for(let i=0;i<FightSet.HERO_MAX_NUM;i++){
this.heros.push({
uuid:0,
count:0,
quality:0,
})
// this.heros=[]
// for(let i=0;i<FightSet.HERO_MAX_NUM;i++){
// this.heros.push({
// uuid:0,
// count:0,
// quality:0,
// })
// }
// this.current_hero_num=-1
// this.current_hero_uuid=0
console.log("[MissionHeroComp]:fight_ready",smc.fight_heros,Object.keys(smc.fight_heros).length)
let heros:any = smc.fight_heros
for(let i=0;i<Object.keys(heros).length;i++){
if(heros[i]!=0){
console.log("[MissionHeroComp]:fight_ready",heros[i])
this.addHero(heros[i],false)
}
}
this.current_hero_num=-1
this.current_hero_uuid=0
}
protected update(dt: number): void {
if(smc.mission.status != 1) return
@@ -105,6 +118,7 @@ export class MissionHeroCompComp extends CCComp {
/** 添加英雄 */
private addHero(uuid:number=1001,is_zhaohuan:boolean=false) {
console.log("[MissionHeroComp]:addHero",uuid,is_zhaohuan)
let hero_pos=0
let hero = ecs.getEntity<Hero>(Hero);
let scale = 1

View File

@@ -12,49 +12,27 @@ const { ccclass, property } = _decorator;
@ecs.register('MissionHome', false)
export class MissionHomeComp extends CCComp {
heros:any[]=[];
heros_pos:any=[
{uuid:0,px:-100},
{uuid:0,px:-200},
{uuid:0,px:-300},
]
protected onLoad(): void {
this.on(GameEvent.MissionEnd,this.mission_end,this)
}
/** 视图层逻辑代码分离演示 */
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
this.load_ui_heros()
this.home_active()
}
to_start(){
}
start_mission() {
for(let i=0;i<this.heros.length;i++){
this.heros[i].to_destroy()
}
this.heros=[]
this.heros_pos=[
{uuid:0,px:-100},
{uuid:0,px:-200},
{uuid:0,px:-300},
]
oops.message.dispatchEvent(GameEvent.MissionStart, {})
this.node.active=false;
}
mission_end(){
this.home_active()
}
home_active(){
this.node.active=true
oops.message.dispatchEvent(GameEvent.UpdateHero, {})
}
load_ui_heros(){
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */

View File

@@ -35,10 +35,12 @@ export class MissionMonCompComp extends CCComp { // 添加刷怪队列 - 扩
private spawnCount: number = 0; // 召唤计数器
private pauseInterval: number = 5.0; // 暂停间隔时间5秒
private isPausing: boolean = false; // 是否正在暂停
onLoad(){
this.on(GameEvent.NewWave,this.do_mon_wave,this)
// this.on(GameEvent.NewWave,this.do_mon_wave,this)
this.on(GameEvent.FightReady,this.fight_ready,this)
}
/** 视图层逻辑代码分离演示 */
start() {
@@ -46,6 +48,11 @@ export class MissionMonCompComp extends CCComp { // 添加刷怪队列 - 扩
// this.on(ModuleEvent.Cmd, this.onHandler, this);
}
fight_ready(){
console.log("[MissionMonComp]:fight_ready")
this.do_mon_wave()
}
protected update(dt: number): void {
if(!smc.mission.play||smc.mission.pause) return

View File

@@ -16,8 +16,8 @@ export class move extends Component {
@property({ type: CCInteger })
sc: number = 1; // 1: 从左到右, -1: 从右到左
@property({ type: CCBoolean })
isMove:boolean=false
@property({ type: CCInteger })
isMove:number=0
protected onLoad(): void {
oops.message.on(GameEvent.MAP_MOVE_END_LEFT, this.onMapMoveEndLeft, this);
oops.message.on(GameEvent.MAP_MOVE_END_RIGHT, this.onMapMoveEndRight, this);
@@ -27,13 +27,13 @@ export class move extends Component {
}
onMapMoveEndLeft() {
if(this.sc==-1){
this.isMove=true
this.isMove=1
this.setInitialPosition()
}
}
onMapMoveEndRight() {
if(this.sc==1){
this.isMove=true
this.isMove=1
this.setInitialPosition()
}
}
@@ -52,7 +52,7 @@ export class move extends Component {
update(dt: number) {
// 更新位置
if(this.isMove){
if(this.isMove==1){
const newX = this.node.position.x + dt * this.speed * this.sc;
this.node.setPosition(newX, this.node.position.y);
// 检查边界并重置位置
@@ -68,14 +68,14 @@ export class move extends Component {
// 从左到右移动,到达右边界后回到左边界
if (this.node.position.x >= this.maxX) {
this.node.setPosition(this.minX, this.node.position.y);
this.isMove=false
this.isMove=0
oops.message.dispatchEvent(GameEvent.MAP_MOVE_END_LEFT)
}
} else if (this.sc < 0) {
// 从右到左移动,到达左边界后回到右边界
if (this.node.position.x <= this.minX) {
this.node.setPosition(this.maxX, this.node.position.y);
this.isMove=false
this.isMove=0
oops.message.dispatchEvent(GameEvent.MAP_MOVE_END_RIGHT)
}
}