refactor(talent): 重构天赋升级消耗计算逻辑
1. 将天赋升级消耗从按等级索引改为按阶位统一配置 2. 调整getTalentUpgradeCost入参和计算逻辑 3. 更新天赋已投入点数的统计方式,优化计算效率 4. 修正天赋升级消耗判断的参数传递错误
This commit is contained in:
@@ -509,7 +509,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
if (curLv >= cfg.max_lv) return false;
|
if (curLv >= cfg.max_lv) return false;
|
||||||
// 阶位解锁:二/三阶天赋要求前一阶累计投入点数达标(一阶恒解锁)
|
// 阶位解锁:二/三阶天赋要求前一阶累计投入点数达标(一阶恒解锁)
|
||||||
if (!isTalentTierUnlocked(this.data.talents, cfg.tier)) return false;
|
if (!isTalentTierUnlocked(this.data.talents, cfg.tier)) return false;
|
||||||
const cost = getTalentUpgradeCost(curLv);
|
const cost = getTalentUpgradeCost(cfg.tier);
|
||||||
if (cost < 0 || this.getTalentPoints() < cost) return false;
|
if (cost < 0 || this.getTalentPoints() < cost) return false;
|
||||||
this.data.talent_points -= cost;
|
this.data.talent_points -= cost;
|
||||||
this.data.talents[uuid] = curLv + 1;
|
this.data.talents[uuid] = curLv + 1;
|
||||||
|
|||||||
@@ -272,17 +272,20 @@ export const TalentSet: Record<number, TalentConfig> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 天赋升级消耗:索引为当前等级(0 表示升到 1 级),返回所需天赋点数 */
|
/** 天赋升级消耗:按阶位统一消耗,同一阶内每级消耗相同 */
|
||||||
export const TALENT_UPGRADE_COST: number[] = [1, 1, 2, 2, 3];
|
export const TALENT_UPGRADE_COST: Record<number, number> = {
|
||||||
|
[TalentTier.Basic]: 1, // 基础天赋:1 点升 1 级
|
||||||
|
[TalentTier.Specialized]: 2, // 专精天赋:2 点升 1 级
|
||||||
|
[TalentTier.Super]: 2, // 传说天赋:2 点升 1 级
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询升级所需天赋点数
|
* 查询升级所需天赋点数
|
||||||
* @param curLv 当前等级
|
* @param tier 天赋所属阶位
|
||||||
* @returns 升到下一级所需点数;已满级返回 -1
|
* @returns 升 1 级所需点数;非法阶位返回 -1
|
||||||
*/
|
*/
|
||||||
export function getTalentUpgradeCost(curLv: number): number {
|
export function getTalentUpgradeCost(tier: TalentTier): number {
|
||||||
if (curLv < 0 || curLv >= TALENT_UPGRADE_COST.length) return -1;
|
return TALENT_UPGRADE_COST[tier] ?? -1;
|
||||||
return TALENT_UPGRADE_COST[curLv];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 天赋等级上限(不含):等级从 0 起步,区间 0~29,共 30 级;每升 1 级产出 1 点天赋点 */
|
/** 天赋等级上限(不含):等级从 0 起步,区间 0~29,共 30 级;每升 1 级产出 1 点天赋点 */
|
||||||
@@ -309,7 +312,7 @@ export function getTalentLevelExp(curLv: number): number {
|
|||||||
export const TALENT_TIER_UNLOCK_THRESHOLD = 10;
|
export const TALENT_TIER_UNLOCK_THRESHOLD = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算指定阶位已投入的天赋点数(按升级消耗表逐级累加)。
|
* 计算指定阶位已投入的天赋点数(按该阶统一消耗 × 等级累加)。
|
||||||
* Why: 阶位解锁按"实际消耗点数"而非"等级总和"口径——与玩家直觉(投入了多少点)
|
* Why: 阶位解锁按"实际消耗点数"而非"等级总和"口径——与玩家直觉(投入了多少点)
|
||||||
* 及重置退款口径(resetTalents 同表对账)保持一致。
|
* 及重置退款口径(resetTalents 同表对账)保持一致。
|
||||||
* @param levels 天赋等级表(key 为天赋 uuid,value 为当前等级)
|
* @param levels 天赋等级表(key 为天赋 uuid,value 为当前等级)
|
||||||
@@ -318,14 +321,13 @@ export const TALENT_TIER_UNLOCK_THRESHOLD = 10;
|
|||||||
*/
|
*/
|
||||||
export function getTalentTierInvestedPoints(levels: Record<number, number>, tier: TalentTier): number {
|
export function getTalentTierInvestedPoints(levels: Record<number, number>, tier: TalentTier): number {
|
||||||
if (!levels) return 0;
|
if (!levels) return 0;
|
||||||
|
const cost = getTalentUpgradeCost(tier);
|
||||||
|
if (cost <= 0) return 0;
|
||||||
let invested = 0;
|
let invested = 0;
|
||||||
for (const key in levels) {
|
for (const key in levels) {
|
||||||
const cfg = TalentSet[key];
|
const cfg = TalentSet[key];
|
||||||
if (!cfg || cfg.tier !== tier) continue;
|
if (!cfg || cfg.tier !== tier) continue;
|
||||||
for (let i = 0; i < levels[key]; i++) {
|
invested += levels[key] * cost;
|
||||||
const c = getTalentUpgradeCost(i);
|
|
||||||
if (c > 0) invested += c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return invested;
|
return invested;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ export class TalentsComp extends CCComp {
|
|||||||
this.showSmallTip(tab?.node ?? null, "该天赋已满级");
|
this.showSmallTip(tab?.node ?? null, "该天赋已满级");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cost = getTalentUpgradeCost(lv);
|
const cost = getTalentUpgradeCost(cfg.tier);
|
||||||
if (cost <= 0) return;
|
if (cost <= 0) return;
|
||||||
if (smc.getTalentPoints() < cost) {
|
if (smc.getTalentPoints() < cost) {
|
||||||
this.showSmallTip(tab?.node ?? null, "天赋点不足");
|
this.showSmallTip(tab?.node ?? null, "天赋点不足");
|
||||||
|
|||||||
Reference in New Issue
Block a user