feat(奖励系统): 实现等级奖励分发和收集品显示功能
- 新增GameEvent.UpdateCollection事件用于更新收集品显示 - 将CardType枚举移至GameSet并添加getLevelRewardType函数 - 修改MissionComp根据等级分发不同类型奖励事件 - 实现MissionGetsComp收集品数量显示功能 - 在SingletonModuleComp中添加收集品更新事件触发
This commit is contained in:
@@ -179,6 +179,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
}
|
||||
this.vmdata.collection.talents[id]++;
|
||||
console.log(`[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,6 +192,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
}
|
||||
this.vmdata.collection.skill.count++;
|
||||
console.log(`[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
/**
|
||||
* 记录好友获取
|
||||
@@ -202,6 +204,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
}
|
||||
this.vmdata.collection.friend.count++;
|
||||
console.log(`[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
vmAdd() {
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/**
|
||||
* 英雄升级经验配置表
|
||||
* ExpConf[lv] 返回从当前等级到下一级所需的经验值
|
||||
* 1-30级:初始值20,每级提升约20%
|
||||
* 31-100级:每级在前一级基础上+1000
|
||||
*/
|
||||
export const ExpConf: number[] = [
|
||||
// Lv1-10
|
||||
0,20, 24, 29, 35, 42, 50, 60, 72, 86, 103,
|
||||
// Lv11-20
|
||||
124, 149, 179, 215, 258, 310, 372, 446, 535, 642,
|
||||
// Lv21-30
|
||||
770, 924, 1109, 1331, 1597, 1916, 2299, 2759, 3311, 4000,
|
||||
// Lv31-40
|
||||
5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000,
|
||||
// Lv41-50
|
||||
15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000,
|
||||
// Lv51-60
|
||||
25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000,
|
||||
// Lv61-70
|
||||
35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000,
|
||||
// Lv71-80
|
||||
45000, 46000, 47000, 48000, 49000, 50000, 51000, 52000, 53000, 54000,
|
||||
// Lv81-90
|
||||
55000, 56000, 57000, 58000, 59000, 60000, 61000, 62000, 63000, 64000,
|
||||
// Lv91-100
|
||||
65000, 66000, 67000, 68000, 69000, 70000, 71000, 72000, 73000, 74000
|
||||
];
|
||||
|
||||
/**
|
||||
* 怪物击杀经验配置表
|
||||
* MonExp[lv] 返回该等级怪物提供的经验值
|
||||
*
|
||||
* 设计规则:
|
||||
* - 1-10级: 5个怪物 = ExpConf[lv-1],即 MonExp[lv] = ExpConf[lv-1] / 5
|
||||
* - 11-20级: 10个怪物 = ExpConf[lv-1],即 MonExp[lv] = ExpConf[lv-1] / 10
|
||||
* - 21-30级: 15个怪物 = ExpConf[lv-1],即 MonExp[lv] = ExpConf[lv-1] / 15
|
||||
* - 31级及以上: 固定为30级的经验值,即 MonExp[lv] = MonExp[30]
|
||||
*
|
||||
* 索引说明:MonExp[1] 表示1级怪物的经验值
|
||||
*/
|
||||
export const MonExp: number[] = [
|
||||
// Lv0-10
|
||||
0, 4, 5, 6, 7, 8, 10, 12, 14, 17, 21,
|
||||
// Lv11-20
|
||||
12, 15, 18, 22, 26, 31, 37, 45, 54, 64,
|
||||
// Lv21-30
|
||||
51, 62, 74, 89, 106, 128, 153, 184, 221, 267,
|
||||
// Lv31-40
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv41-50
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv51-60
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv61-70
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv71-80
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv81-90
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267,
|
||||
// Lv91-100
|
||||
267, 267, 267, 267, 267, 267, 267, 267, 267, 267
|
||||
];
|
||||
|
||||
/**
|
||||
* 等级属性成长系数配置
|
||||
* 用于计算角色/怪物升级时各属性的增长值
|
||||
*
|
||||
* 计算公式:
|
||||
* - 当前等级属性 = 基础属性 × (1 + 等级 × 成长系数)
|
||||
* 例如:10级角色HP = 基础HP × (1 + 10 × 0.08) = 基础HP × 1.8
|
||||
*/
|
||||
export const LevelAttrGrowthConfig = {
|
||||
/** 生命值成长系数(每级增长8%) */
|
||||
hp: 0.08,
|
||||
|
||||
/** 魔法值成长系数(每级增长6%) */
|
||||
mp: 0.06,
|
||||
|
||||
/** 攻击力成长系数(每级增长5%) */
|
||||
ap: 0.05,
|
||||
|
||||
/** 防御力成长系数(每级增长4%) */
|
||||
def: 0.04
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据等级计算属性值
|
||||
* @param baseValue 基础属性值
|
||||
* @param level 当前等级
|
||||
* @param growthRate 成长系数
|
||||
* @returns 计算后的属性值(向下取整)
|
||||
*/
|
||||
export function calculateAttrByLevel(baseValue: number, level: number, growthRate: number): number {
|
||||
return Math.floor(baseValue * (1 + level * growthRate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据等级计算所有属性
|
||||
* @param baseHP 基础生命值
|
||||
* @param baseMP 基础魔法值
|
||||
* @param baseAP 基础攻击力
|
||||
* @param baseDEF 基础防御力
|
||||
* @param level 当前等级
|
||||
* @returns 包含所有计算后属性的对象
|
||||
*/
|
||||
export function calculateAllAttrsByLevel(
|
||||
baseHP: number,
|
||||
baseMP: number,
|
||||
baseAP: number,
|
||||
baseDEF: number,
|
||||
level: number
|
||||
): { hp: number; mp: number; ap: number; def: number } {
|
||||
return {
|
||||
hp: calculateAttrByLevel(baseHP, level, LevelAttrGrowthConfig.hp),
|
||||
mp: calculateAttrByLevel(baseMP, level, LevelAttrGrowthConfig.mp),
|
||||
ap: calculateAttrByLevel(baseAP, level, LevelAttrGrowthConfig.ap),
|
||||
def: calculateAttrByLevel(baseDEF, level, LevelAttrGrowthConfig.def)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,4 +67,5 @@ export enum GameEvent {
|
||||
ReviveSuccess = "ReviveSuccess",
|
||||
ToCallFriend = "ToCallFriend",
|
||||
CallFriend = "CallFriend",
|
||||
UpdateCollection = "UpdateCollection",
|
||||
}
|
||||
@@ -22,6 +22,30 @@ export enum BoxSet {
|
||||
//攻击距离
|
||||
}
|
||||
|
||||
export enum CardType {
|
||||
Talent = 1,
|
||||
Skill = 2,
|
||||
Potion = 3,
|
||||
Partner = 4
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取等级对应的奖励类型
|
||||
* @param level 当前等级
|
||||
* @returns 奖励类型 CardType
|
||||
*/
|
||||
export function getLevelRewardType(level: number): CardType {
|
||||
if (level === 1) {
|
||||
return CardType.Skill;
|
||||
} else if (level >= 2 && level <= 5) {
|
||||
return CardType.Talent;
|
||||
} else if (level === 6) {
|
||||
return CardType.Partner;
|
||||
} else {
|
||||
return CardType.Potion; // 以后暂时都是物品
|
||||
}
|
||||
}
|
||||
|
||||
export enum FacSet {
|
||||
HERO=0,
|
||||
MON=1,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user