// 测试星露谷风格经验曲线 const LEVEL_EXP_TABLE = [ 0, // Lv.1 起始(占位) 100, // Lv.1→2 所需 200, // Lv.2→3 所需 400, // Lv.3→4 所需 800, // Lv.4→5 所需 1200, // Lv.5→6 所需 1800, // Lv.6→7 所需 2500, // Lv.7→8 所需 3500, // Lv.8→9 所需 5000, // Lv.9→10 所需 ]; function getLevelStartExp(level: number): number { let total = 0; for (let i = 1; i < level && i < LEVEL_EXP_TABLE.length; i++) { total += LEVEL_EXP_TABLE[i]; } return total; } function getLevelExpRequirement(level: number): number { if (level >= LEVEL_EXP_TABLE.length) { return LEVEL_EXP_TABLE[LEVEL_EXP_TABLE.length - 1]; } return LEVEL_EXP_TABLE[level] || 0; } function calculateLevel(experience: number): number { let level = 1; let totalExp = 0; for (let i = 1; i < LEVEL_EXP_TABLE.length; i++) { const requirement = LEVEL_EXP_TABLE[i]; if (totalExp + requirement > experience) { break; } totalExp += requirement; level++; } if (level >= LEVEL_EXP_TABLE.length) { const lastRequirement = LEVEL_EXP_TABLE[LEVEL_EXP_TABLE.length - 1]; const remainingExp = experience - totalExp; level += Math.floor(remainingExp / lastRequirement); } return level; } console.log('🧪 测试星露谷风格经验曲线\n'); console.log('经验值 | 等级 | 等级起始 | 升级所需 | 下一级经验'); console.log('------|------|---------|---------|-----------'); const testCases = [0, 50, 100, 200, 300, 500, 700, 1000, 1500, 2000, 3000, 5000, 10000, 15500]; testCases.forEach(exp => { const lv = calculateLevel(exp); const startExp = getLevelStartExp(lv); const requirement = getLevelExpRequirement(lv); const nextLevelExp = startExp + requirement; const remaining = nextLevelExp - exp; console.log(`${exp.toString().padStart(6)} | Lv.${lv.toString().padStart(2)} | ${startExp.toString().padStart(7)} | ${requirement.toString().padStart(7)} | ${nextLevelExp.toString().padStart(9)} (还差 ${remaining})`); }); console.log('\n✅ 测试完成!');