refactor: 清理废弃资源并优化卡牌相关逻辑

1.  删除废弃的notify.prefab和TalentSet.ts.meta文件
2.  新增MSkillBox预制体资源
3.  优化MissionCardComp抽卡按钮显示逻辑
4.  格式化CardComp.ts代码格式与变量声明
5.  优化MissionComp.ts代码格式与事件绑定
6.  更新mission.prefab布局添加技能槽位
This commit is contained in:
pan
2026-06-03 14:39:31 +08:00
parent 15c771c58c
commit 55c277016d
10 changed files with 6228 additions and 1565 deletions

View File

@@ -27,7 +27,7 @@
* - CardInitCoins —— 初始金币数
* - UIID.Victory —— 结算弹窗
*/
import { _decorator, Vec3,Animation, instantiate, Prefab, Node, NodeEventType, ProgressBar, Label, CCInteger, tween, v3, Tween, Widget, UIOpacity } from "cc";
import { _decorator, Vec3, Animation, instantiate, Prefab, Node, NodeEventType, ProgressBar, Label, CCInteger, tween, v3, Tween, Widget, UIOpacity } 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";
@@ -97,17 +97,17 @@ export class MissionComp extends CCComp {
/** 卡池升级波次配置:达到对应波次时,推送卡池升级事件 */
@property({ type: [CCInteger], tooltip: "卡池升级波次配置,例如 [10, 20] 表示第10波升到2级第20波升到3级" })
cardPoolUpgradeWaves: number[] = [5, 10];
// ======================== 编辑器绑定节点 ========================
/** 开始战斗按钮 */
@property(Node)
start_btn:Node = null!
start_btn: Node = null!
/** 时间/波数显示节点 */
@property(Node)
time_node:Node = null!
time_node: Node = null!
@property(Node)
tooltip:Node = null!
tooltip: Node = null!
/** 阶段名称映射表(用于 UI 显示) */
private static readonly PhaseNameMap: Record<MissionPhase, string> = {
@@ -124,19 +124,19 @@ export class MissionComp extends CCComp {
// ======================== 运行时状态 ========================
/** 战斗已耗时(秒),正向计时 */
clearTime:number = 0
clearTime: number = 0
/** 剩余复活次数 */
revive_times: number = 1;
/** 掉落奖励列表 */
rewards:any[]=[]
rewards: any[] = []
/** 累计游戏数据 */
game_data:any={
exp:0,
gold:0,
diamond:0
game_data: any = {
exp: 0,
gold: 0,
diamond: 0
}
/**秒计时 */
PhaseTime:Timer= new Timer(1)
PhaseTime: Timer = new Timer(1)
/** 上一次显示的时间字符串(避免重复设置) */
private lastTimeStr: string = "";
/** 上一次显示的秒数(避免重复计算) */
@@ -180,18 +180,18 @@ export class MissionComp extends CCComp {
private skillViewMatcher: any = null;
/** 匹配拥有 HeroAttrsComp 的实体(英雄/怪物属性) */
private heroAttrsMatcher: any = null;
// ======================== 生命周期 ========================
onLoad(){
onLoad() {
this.heroViewMatcher = ecs.allOf(HeroViewComp);
this.skillViewMatcher = ecs.allOf(SkillView);
this.heroAttrsMatcher = ecs.allOf(HeroAttrsComp);
this.showMemoryPanel = false
// 注册生命周期事件
this.on(GameEvent.MissionEnd,this.mission_end,this)
this.on(GameEvent.NewWave,this.onNewWave,this)
this.on(GameEvent.DO_AD_BACK,this.do_ad,this)
this.on(GameEvent.MissionEnd, this.mission_end, this)
this.on(GameEvent.NewWave, this.onNewWave, this)
this.on(GameEvent.DO_AD_BACK, this.do_ad, this)
this.start_btn?.on(NodeEventType.TOUCH_END, this.onStartFightBtnClick, this)
this.removeMemoryPanel()
}
@@ -206,7 +206,7 @@ export class MissionComp extends CCComp {
smc.map.MapView.scene.mapLayer.stopAnimations();
}
onDestroy(){
onDestroy() {
smc.map.MapView.scene.mapLayer.playAnimations()
super.onDestroy();
if (this.start_btn && this.start_btn.isValid) {
@@ -220,10 +220,10 @@ export class MissionComp extends CCComp {
* - 战斗中 → 同步怪物状态、更新计时器
*/
protected update(dt: number): void {
if(!smc.mission.play) return
if (!smc.mission.play) return
// 如果是暂停状态,且不在 BattleEnd 阶段(全灭时需要播放完 fend 技能动画并自动流转),才真正停止 update 逻辑
if(smc.mission.pause && this.currentPhase !== MissionPhase.BattleEnd) return
if (smc.mission.pause && this.currentPhase !== MissionPhase.BattleEnd) return
// 处理过渡阶段的计时
if (this.currentPhase === MissionPhase.PrepareStart ||
@@ -235,10 +235,10 @@ export class MissionComp extends CCComp {
}
}
if(this.currentPhase === MissionPhase.Battle){
if (this.currentPhase === MissionPhase.Battle) {
this.syncMonsterSpawnState(dt)
if(smc.mission.stop_mon_action) return
smc.vmdata.mission_data.fight_time+=dt
if (smc.mission.stop_mon_action) return
smc.vmdata.mission_data.fight_time += dt
this.clearTime += dt
this.update_time();
}
@@ -247,14 +247,14 @@ export class MissionComp extends CCComp {
// ======================== 时间显示 ========================
/** 更新时间/波数显示(仅在秒数变化时更新以减少 Label 操作) */
update_time(){
update_time() {
const remainSecond = Math.floor(this.clearTime);
if (remainSecond === this.lastTimeSecond) return;
this.lastTimeSecond = remainSecond;
let m = Math.floor(remainSecond / 60);
let s = remainSecond % 60;
let str = `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
if(str != this.lastTimeStr){
if (str != this.lastTimeStr) {
if (this.time_node && this.time_node.isValid) {
const timeChild = this.time_node.getChildByName("time");
if (timeChild) {
@@ -269,24 +269,24 @@ export class MissionComp extends CCComp {
// ======================== 奖励与广告 ========================
/** 奖励发放(预留) */
do_reward(){
do_reward() {
}
/**
* 广告回调处理:
* 成功 → 增加刷新次数;失败 → 分发失败事件。
*/
do_ad(){
if(this.ad_back()){
do_ad() {
if (this.ad_back()) {
oops.message.dispatchEvent(GameEvent.AD_BACK_TRUE)
smc.vmdata.mission_data.refresh_count+=FightSet.MORE_RC
}else{
smc.vmdata.mission_data.refresh_count += FightSet.MORE_RC
} else {
oops.message.dispatchEvent(GameEvent.AD_BACK_FALSE)
}
}
/** 广告观看结果(预留,默认返回 true */
ad_back(){
ad_back() {
return true
}
@@ -300,18 +300,18 @@ export class MissionComp extends CCComp {
* 4. 分发 FightReady 事件。
* 5. 进入准备阶段并显示 loading。
*/
async mission_start(){
async mission_start() {
this.unscheduleAllCallbacks();
this.cleanComponents();
this.data_init()
oops.message.dispatchEvent(GameEvent.FightReady)
this.changePhase(MissionPhase.Prepare)
let loading=this.node.getChildByName("loading")
let loading = this.node.getChildByName("loading")
if (loading) {
loading.active=true
this.scheduleOnce(()=>{
loading.active=false
},0.5)
loading.active = true
this.scheduleOnce(() => {
loading.active = false
}, 0.5)
}
}
@@ -389,8 +389,8 @@ export class MissionComp extends CCComp {
const phaseName = MissionComp.PhaseNameMap[targetPhase] || "未知";
// 播放状态切换提示栏动效(过滤掉 None、Prepare 准备阶段、Battle 战斗中阶段)
if (targetPhase !== MissionPhase.None &&
targetPhase !== MissionPhase.Prepare &&
if (targetPhase !== MissionPhase.None &&
targetPhase !== MissionPhase.Prepare &&
targetPhase !== MissionPhase.Battle) {
this.playTooltipAnim(phaseName);
}
@@ -404,7 +404,7 @@ export class MissionComp extends CCComp {
const wave = Math.max(1, this.currentWave || (smc.vmdata && smc.vmdata.mission_data ? smc.vmdata.mission_data.level : 1) || 1);
label.string = `${wave}/15 波`;
}
// 阶段切换动感表现:只在进入战斗阶段跳动一下,让流程充满心流体验
if (targetPhase === MissionPhase.BattleStart) {
Tween.stopAllByTarget(this.time_node);
@@ -449,6 +449,10 @@ export class MissionComp extends CCComp {
smc.mission.stop_spawn_mon = false;
smc.mission.in_fight = true;
smc.vmdata.mission_data.in_fight = true;
// 战斗阶段:隐藏开始按钮
if (this.start_btn && this.start_btn.isValid) {
this.start_btn.active = false;
}
oops.message.dispatchEvent(GameEvent.FightStart);
break;
@@ -462,7 +466,7 @@ export class MissionComp extends CCComp {
smc.vmdata.scores.wave_win_count++;
// 【评分系统 - 战绩分】记录每回合结束时场上留存的敌人数量(扣分项)
smc.vmdata.scores.wave_remain_monsters += smc.vmdata.mission_data.mon_num;
let allAlive = true;
let hasHero = false;
ecs.query(this.heroAttrsMatcher).forEach(entity => {
@@ -485,7 +489,7 @@ export class MissionComp extends CCComp {
// 触发战斗结束技能fend
this.triggerHeroBattleSkills(false);
// 战斗结束阶段给予所有英雄恢复70%血量的技能效果
this.healAllHeroes();
break;
@@ -496,7 +500,7 @@ export class MissionComp extends CCComp {
smc.mission.stop_spawn_mon = true;
// 不隐藏开始按钮
break;
case MissionPhase.None:
smc.mission.in_fight = false;
smc.vmdata.mission_data.in_fight = false;
@@ -529,7 +533,7 @@ export class MissionComp extends CCComp {
this.changePhase(MissionPhase.PrepareStart);
} else {
this.changePhase(MissionPhase.Settle);
// 此时已经经过了 2s可以真正执行结算弹窗或清理逻辑
if (smc.mission.play) {
// 如果游戏还在运行中,说明是通过 open_Victory 进来的
@@ -559,7 +563,7 @@ export class MissionComp extends CCComp {
* - 分发 FightStart 事件
* - 触发英雄战斗开始技能
*/
to_fight(){
to_fight() {
this.changePhase(MissionPhase.PrepareEnd);
}
@@ -609,14 +613,14 @@ export class MissionComp extends CCComp {
const attrs = entity.get(HeroAttrsComp);
const view = entity.get(HeroViewComp);
if (!attrs || !view || attrs.fac !== FacSet.HERO) return;
// 计算恢复量:基于配置的百分比(如 70%)的最大生命值
const healAmount = Math.floor(attrs.hp_max * finalHealRate);
// 应用恢复量,不超过最大生命值
attrs.hp = Math.min(attrs.hp_max, attrs.hp + healAmount);
attrs.dirty_hp = true;
// 重置复活次数,使得下回合可以继续复活
attrs.revived_count = 0;
@@ -642,7 +646,7 @@ export class MissionComp extends CCComp {
* @param e 事件对象(未使用)
* @param is_hero_dead 是否因英雄全灭触发
*/
open_Victory(e:any,is_hero_dead: boolean = false){
open_Victory(e: any, is_hero_dead: boolean = false) {
// 战斗失败或胜利,标记暂停状态以切断波次流转逻辑
smc.mission.pause = true;
// 直接切入 BattleEnd触发 fend 表现
@@ -652,9 +656,9 @@ export class MissionComp extends CCComp {
/** 战斗结束:延迟清理组件和对象池 */
fight_end(){
fight_end() {
// 这里只是强制清理关卡,为了防止重复弹窗,标记 play = false
smc.mission.play=false
smc.mission.play = false
this.changePhase(MissionPhase.BattleEnd);
}
@@ -665,9 +669,9 @@ export class MissionComp extends CCComp {
* - 清理组件和对象池
* - 隐藏节点
*/
mission_end(){
mission_end() {
this.unscheduleAllCallbacks();
smc.mission.play=false
smc.mission.play = false
smc.mission.pause = false;
this.changePhase(MissionPhase.None);
this.cleanComponents()
@@ -682,7 +686,7 @@ export class MissionComp extends CCComp {
* - 奖励列表 / 复活次数
* - 性能监控基准值
*/
data_init(){
data_init() {
if (!this.PhaseTime) {
this.PhaseTime = new Timer(1);
}
@@ -690,16 +694,16 @@ export class MissionComp extends CCComp {
smc.mission.pause = false;
smc.mission.stop_mon_action = false;
smc.mission.stop_spawn_mon = false;
smc.vmdata.mission_data.in_fight=false
smc.vmdata.mission_data.fight_time=0
smc.vmdata.mission_data.in_fight = false
smc.vmdata.mission_data.fight_time = 0
this.clearTime = 0
smc.vmdata.mission_data.mon_num=0
smc.vmdata.mission_data.mon_num = 0
smc.vmdata.mission_data.level = 1
smc.vmdata.mission_data.mon_max = Math.max(1, Math.floor(this.maxMonsterCount))
this.currentPhase = MissionPhase.None;
this.currentWave = 1;
this.isBossWave = false;
this.rewards=[]
this.rewards = []
this.revive_times = 1;
this.lastTimeStr = "";
this.lastTimeSecond = -1;
@@ -714,9 +718,9 @@ export class MissionComp extends CCComp {
this.heapTrendBaseMB = -1;
this.monsterCountSyncTimer = 0;
this.lastPrepareCoinWave = 0;
spawningEngine.reset();
// 重置所有的战局得分数据,防止上一局的数据污染
smc.resetScores();
@@ -740,9 +744,9 @@ export class MissionComp extends CCComp {
private onNewWave(event: string, data: any) {
const wave = Number(data?.wave ?? 0);
if (wave <= 0) return;
this.isBossWave = !!data?.bossWave;
if (wave > 1) {
// 在新一波到来时,先进入 BattleEnd触发上一波的战斗结束技能 (fend)2秒后自动进入下一波的准备阶段
this.changePhase(MissionPhase.BattleEnd);
@@ -773,7 +777,7 @@ export class MissionComp extends CCComp {
if (upgradeIndex !== -1) {
// 根据配置的索引,计算目标等级(初始等级 + index + 1
// 例如 index=0对应等级为2index=1对应等级为3
const targetLv = upgradeIndex + 2;
const targetLv = upgradeIndex + 2;
oops.message.dispatchEvent(GameEvent.CardPoolUpgrade, { wave, targetLv });
mLogger.log(this.debugMode, 'MissionComp', "card pool upgrade event pushed", { wave, targetLv });
}
@@ -836,7 +840,7 @@ export class MissionComp extends CCComp {
}
});
this.handleHeroWipe(heroCount);
// 怪物全灭检测:如果战斗阶段场上没有任何活着的怪物,且待刷新的怪物队列也为空,直接结束战斗进入下一波的准备阶段
const pendingCount = smc.vmdata.mission_data.pending_mon_num || 0;
if (monsterCount === 0 && pendingCount === 0 && smc.mission.play && !smc.mission.pause && this.currentPhase === MissionPhase.Battle) {
@@ -844,7 +848,7 @@ export class MissionComp extends CCComp {
// 如果能获取当前已部署英雄数最好,这里简化处理,大于 4 个就算高存活
heroesAliveRatio = Math.min(1.0, heroCount / 4.0);
spawningEngine.updateAdaptive(heroesAliveRatio, this.clearTime);
if (this.currentWave >= 15) {
// 15 波通关
this.open_Victory(null, false);
@@ -853,7 +857,7 @@ export class MissionComp extends CCComp {
}
return;
}
smc.vmdata.mission_data.mon_num = monsterCount;
const { max, resume } = this.getMonsterThresholds();
smc.vmdata.mission_data.mon_max = max;
@@ -938,7 +942,7 @@ export class MissionComp extends CCComp {
skillNodes: skillRoot?.children.length || 0
};
}
// ======================== 性能监控面板 ========================
/** 性能监控相关代码 */