feat(奖励系统): 实现等级奖励分发和收集品显示功能

- 新增GameEvent.UpdateCollection事件用于更新收集品显示
- 将CardType枚举移至GameSet并添加getLevelRewardType函数
- 修改MissionComp根据等级分发不同类型奖励事件
- 实现MissionGetsComp收集品数量显示功能
- 在SingletonModuleComp中添加收集品更新事件触发
This commit is contained in:
walkpan
2026-01-05 20:06:23 +08:00
parent 93e0ab083b
commit 9bf8ad2625
7 changed files with 121 additions and 154 deletions

View File

@@ -8,16 +8,10 @@ import { CanSelectHeros, HeroInfo } from "../common/config/heroSet";
import { CanSelectSkills, SkillSet } from "../common/config/SkillSet";
import { ItemSet } from "../common/config/ItemSet";
import { smc } from "../common/SingletonModuleComp";
import { CardType } from "../common/config/GameSet";
const { ccclass, property } = _decorator;
export enum CardType {
Talent = 1,
Skill = 2,
Potion = 3,
Partner = 4
}
/** 视图层对象 */
@ccclass('MissionCardComp')
@ecs.register('MissionCard', false)

View File

@@ -9,7 +9,7 @@ import { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "../hero/HeroViewComp";
import { UIID } from "../common/config/GameUIConfig";
import { SkillView } from "../skill/SkillView";
import { FightSet } from "../common/config/GameSet";
import { FightSet, getLevelRewardType, CardType } from "../common/config/GameSet";
const { ccclass, property } = _decorator;
@@ -54,7 +54,31 @@ export class MissionComp extends CCComp {
// 升级奖励触发
onLevelUp(event: string, args: any) {
console.log(`[MissionComp] 英雄升级到 ${args.lv} 级!`);
oops.message.dispatchEvent(GameEvent.TalentSelect)
// 获取当前等级对应的奖励类型
const rewardType = getLevelRewardType(args.lv);
console.log(`[MissionComp] 触发奖励选择, 类型: ${rewardType}`);
// 根据类型发送对应的事件
switch (rewardType) {
case CardType.Talent:
oops.message.dispatchEvent(GameEvent.TalentSelect);
break;
case CardType.Skill:
oops.message.dispatchEvent(GameEvent.HeroSkillSelect);
break;
case CardType.Partner:
oops.message.dispatchEvent(GameEvent.ToCallFriend);
break;
case CardType.Potion:
oops.message.dispatchEvent(GameEvent.ShopOpen);
break;
default:
console.warn(`[MissionComp] 未知的奖励类型: ${rewardType}`);
oops.message.dispatchEvent(GameEvent.TalentSelect); // 默认回退到天赋选择
break;
}
// 触发奖励选择界面 (暂时留空)
// this.showLevelUpReward();
}

View File

@@ -1,6 +1,9 @@
import { _decorator, Node } from "cc";
import { _decorator, Node, Label } 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
@@ -8,34 +11,73 @@ const { ccclass, property } = _decorator;
@ccclass('MissionGetsCompComp')
@ecs.register('MissionGetsComp', false)
export class MissionGetsCompComp extends CCComp {
@property(Node)
get0:Node = null!
@property(Node)
get1:Node = null!
@property(Node)
get2:Node = null!
@property(Node)
get3:Node = null!
@property(Node)
get4:Node = null!
@property(Node)
get5:Node = null!
/** 视图层逻辑代码分离演示 */
@property(Node)
get0:Node = null!
@property(Node)
get1:Node = null!
@property(Node)
get2:Node = null!
@property(Node)
get3:Node = null!
@property(Node)
get4:Node = null!
@property(Node)
get5:Node = null!
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
this.updateView();
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
onDestroy() {
oops.message.off(GameEvent.UpdateCollection, this.updateView, this);
}
private updateView() {
if (!smc.vmdata || !smc.vmdata.collection) return;
const data = smc.vmdata.collection;
// Talents (get0 - get3)
const talentIds = Object.keys(data.talents);
const talentNodes = [this.get0, this.get1, this.get2, this.get3];
for (let i = 0; i < talentNodes.length; i++) {
const node = talentNodes[i];
if (i < talentIds.length) {
const id = Number(talentIds[i]); // Object.keys returns strings
const count = data.talents[id];
this.updateNodeNum(node, count);
} else {
this.updateNodeNum(node, 0);
}
}
// Skill (get4)
this.updateNodeNum(this.get4, data.skill.count);
// Friend (get5)
this.updateNodeNum(this.get5, data.friend.count);
}
private updateNodeNum(node: Node, num: number) {
if (!node) return;
// Try to find Label on the node itself
let label = node.getComponent(Label);
// If not found, try to find a child named "num" with Label
if (!label) {
const numNode = node.getChildByName("num");
if (numNode) {
label = numNode.getComponent(Label);
}
}
if (label) {
label.string = num > 0 ? num.toString() : "";
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}
}