fix: 优化NPC冷却与成长平衡及多语言提示

为NPC初始化和数据迁移时增加侦查/攻击冷却的随机延迟,避免所有NPC同时行动。调整NPC成长难度参数,降低前期NPC威胁,提升平滑度。修正多语言包中侦查被发现提示内容。优化舰队警报弹窗滚动体验。
This commit is contained in:
谦君
2025-12-18 04:41:52 +08:00
parent 2ed15c4782
commit 53d5216e88
11 changed files with 64 additions and 53 deletions

View File

@@ -1136,6 +1136,11 @@
// 这是NPC的星球 // 这是NPC的星球
if (!npcMap.has(planet.ownerId)) { if (!npcMap.has(planet.ownerId)) {
// 为每个NPC设置随机的初始冷却时间避免所有NPC同时行动
const now = Date.now()
const randomSpyOffset = Math.random() * 240 * 1000 // 0-4分钟的随机延迟
const randomAttackOffset = Math.random() * 480 * 1000 // 0-8分钟的随机延迟
npcMap.set(planet.ownerId, { npcMap.set(planet.ownerId, {
id: planet.ownerId, id: planet.ownerId,
name: `NPC-${planet.ownerId.substring(0, 8)}`, name: `NPC-${planet.ownerId.substring(0, 8)}`,
@@ -1145,8 +1150,8 @@
relations: {}, // 外交关系 relations: {}, // 外交关系
allies: [], // 盟友列表 allies: [], // 盟友列表
enemies: [], // 敌人列表 enemies: [], // 敌人列表
lastSpyTime: 0, // 上次侦查时间 lastSpyTime: now - randomSpyOffset, // 设置随机的上次侦查时间
lastAttackTime: 0, // 上次攻击时间 lastAttackTime: now - randomAttackOffset, // 设置随机的上次攻击时间
fleetMissions: [], // 舰队任务 fleetMissions: [], // 舰队任务
playerSpyReports: {} // 对玩家的侦查报告 playerSpyReports: {} // 对玩家的侦查报告
}) })
@@ -1224,7 +1229,8 @@
} }
const now = Date.now() const now = Date.now()
const allPlanets = Object.values(universeStore.planets) // 合并玩家星球和NPC星球到allPlanetsNPC需要能够侦查和攻击玩家星球
const allPlanets = [...gameStore.player.planets, ...Object.values(universeStore.planets)]
// 更新每个NPC的行为 // 更新每个NPC的行为
npcStore.npcs.forEach(npc => { npcStore.npcs.forEach(npc => {

View File

@@ -1,6 +1,6 @@
<template> <template>
<div v-if="alerts.length > 0" class="bg-destructive/10 border-b border-destructive/20"> <div v-if="alerts.length > 0" class="bg-destructive/10 border-b border-destructive/20">
<div class="px-4 sm:px-6 py-2 space-y-2"> <div class="px-4 sm:px-6 py-2 space-y-2 max-h-[230px] overflow-y-auto">
<div <div
v-for="alert in alerts" v-for="alert in alerts"
:key="alert.id" :key="alert.id"

View File

@@ -866,7 +866,7 @@ export default {
ships: 'Schiffe', ships: 'Schiffe',
spiedBy: 'Ausspioniert von', spiedBy: 'Ausspioniert von',
attackedBy: 'Angegriffen von', attackedBy: 'Angegriffen von',
detectionSuccess: 'Spionage entdeckt', detectionSuccess: 'Du hast feindliche Spionage entdeckt!',
detectionFailed: 'Spionage nicht entdeckt', detectionFailed: 'Spionage nicht entdeckt',
npcSpiedYourPlanet: 'NPC hat deinen Planeten ausspioniert', npcSpiedYourPlanet: 'NPC hat deinen Planeten ausspioniert',
npcAttackedYourPlanet: 'NPC hat deinen Planeten angegriffen' npcAttackedYourPlanet: 'NPC hat deinen Planeten angegriffen'

View File

@@ -655,7 +655,7 @@ export default {
spiedNotificationDetails: 'Spied Notification Details', spiedNotificationDetails: 'Spied Notification Details',
spyDetected: 'Spy Detected', spyDetected: 'Spy Detected',
detectionResult: 'Detection Result', detectionResult: 'Detection Result',
detectionSuccess: 'Your spy probe was detected!', detectionSuccess: 'You detected the enemy spy!',
spiedNotificationMessage: '{npc} attempted to spy on your planet {planet}', spiedNotificationMessage: '{npc} attempted to spy on your planet {planet}',
spiedNotificationTip: 'Consider increasing your defense or counter-attacking if this NPC is hostile', spiedNotificationTip: 'Consider increasing your defense or counter-attacking if this NPC is hostile',
viewInGalaxy: 'View in Galaxy', viewInGalaxy: 'View in Galaxy',

View File

@@ -856,7 +856,7 @@ export default {
ships: '隻', ships: '隻',
spiedBy: '偵察された', spiedBy: '偵察された',
attackedBy: '攻撃された', attackedBy: '攻撃された',
detectionSuccess: '偵察発見された', detectionSuccess: '敵の偵察発見した!',
detectionFailed: '偵察が発見されなかった', detectionFailed: '偵察が発見されなかった',
npcSpiedYourPlanet: 'NPCがあなたの惑星を偵察しました', npcSpiedYourPlanet: 'NPCがあなたの惑星を偵察しました',
npcAttackedYourPlanet: 'NPCがあなたの惑星を攻撃しました' npcAttackedYourPlanet: 'NPCがあなたの惑星を攻撃しました'

View File

@@ -857,7 +857,7 @@ export default {
ships: '척', ships: '척',
spiedBy: '정찰당함', spiedBy: '정찰당함',
attackedBy: '공격당함', attackedBy: '공격당함',
detectionSuccess: '정찰 발견', detectionSuccess: '적의 정찰 발견했습니다!',
detectionFailed: '정찰 미발견', detectionFailed: '정찰 미발견',
npcSpiedYourPlanet: 'NPC가 당신의 행성을 정찰했습니다', npcSpiedYourPlanet: 'NPC가 당신의 행성을 정찰했습니다',
npcAttackedYourPlanet: 'NPC가 당신의 행성을 공격했습니다' npcAttackedYourPlanet: 'NPC가 당신의 행성을 공격했습니다'

View File

@@ -864,7 +864,7 @@ export default {
ships: 'кораблей', ships: 'кораблей',
spiedBy: 'Разведан', spiedBy: 'Разведан',
attackedBy: 'Атакован', attackedBy: 'Атакован',
detectionSuccess: 'Разведка обнаружена', detectionSuccess: 'Вы обнаружили вражескую разведку!',
detectionFailed: 'Разведка не обнаружена', detectionFailed: 'Разведка не обнаружена',
npcSpiedYourPlanet: 'NPC разведал вашу планету', npcSpiedYourPlanet: 'NPC разведал вашу планету',
npcAttackedYourPlanet: 'NPC атаковал вашу планету' npcAttackedYourPlanet: 'NPC атаковал вашу планету'

View File

@@ -650,7 +650,7 @@ export default {
spiedNotificationDetails: '被侦查通知详情', spiedNotificationDetails: '被侦查通知详情',
spyDetected: '侦查被发现', spyDetected: '侦查被发现',
detectionResult: '检测结果', detectionResult: '检测结果',
detectionSuccess: '你的侦查探测被发现了!', detectionSuccess: '你发现了敌方侦查',
spiedNotificationMessage: '{npc}试图侦查你的星球{planet}', spiedNotificationMessage: '{npc}试图侦查你的星球{planet}',
spiedNotificationTip: '考虑增强防御或反击如果这个NPC对你有敌意', spiedNotificationTip: '考虑增强防御或反击如果这个NPC对你有敌意',
viewInGalaxy: '在星系中查看', viewInGalaxy: '在星系中查看',

View File

@@ -857,7 +857,7 @@ export default {
ships: '艘艦船', ships: '艘艦船',
spiedBy: '被偵查', spiedBy: '被偵查',
attackedBy: '被攻擊', attackedBy: '被攻擊',
detectionSuccess: '偵查被發現', detectionSuccess: '你發現了敵方偵查!',
detectionFailed: '偵查未被發現', detectionFailed: '偵查未被發現',
npcSpiedYourPlanet: 'NPC偵查了你的星球', npcSpiedYourPlanet: 'NPC偵查了你的星球',
npcAttackedYourPlanet: 'NPC攻擊了你的星球' npcAttackedYourPlanet: 'NPC攻擊了你的星球'

View File

@@ -23,25 +23,25 @@ export interface NPCGrowthGameState {
// NPC成长配置旧版保留用于兼容 // NPC成长配置旧版保留用于兼容
export const NPC_GROWTH_CONFIG = { export const NPC_GROWTH_CONFIG = {
easy: { easy: {
powerRatio: 1.0, // 实力比例(相对玩家) - 提升到1.0,与玩家势均力敌 powerRatio: 0.6, // 实力比例(相对玩家)
checkInterval: 300, // 检查间隔(秒) - 5分钟 checkInterval: 300, // 检查间隔(秒) - 5分钟
resourceGrowthRate: 1.3, // 资源增长速率系数 - 大幅提升 resourceGrowthRate: 0.5, // 资源增长速率系数
buildingGrowthSpeed: 1.0, // 建筑升级速度系数 buildingGrowthSpeed: 0.5, // 建筑升级速度系数
techGrowthSpeed: 1.0 // 科技研究速度系数 techGrowthSpeed: 0.5 // 科技研究速度系数
}, },
medium: { medium: {
powerRatio: 1.5, // 提升到1.5,超越玩家 powerRatio: 0.8,
checkInterval: 180, // 3分钟 checkInterval: 180, // 3分钟
resourceGrowthRate: 1.8, // 大幅提升资源增长 resourceGrowthRate: 0.8,
buildingGrowthSpeed: 1.5, buildingGrowthSpeed: 0.8,
techGrowthSpeed: 1.5 techGrowthSpeed: 0.8
}, },
hard: { hard: {
powerRatio: 2.0, // 提升到2.0,远超玩家 powerRatio: 1.1,
checkInterval: 120, // 2分钟 checkInterval: 120, // 2分钟
resourceGrowthRate: 2.5, // 极高资源增长 resourceGrowthRate: 1.2,
buildingGrowthSpeed: 2.0, buildingGrowthSpeed: 1.0,
techGrowthSpeed: 2.0 techGrowthSpeed: 1.0
} }
} as const } as const
@@ -61,58 +61,58 @@ export const calculateDynamicDifficulty = (playerPoints: number): DynamicDifficu
// 积分区间和对应的难度参数 // 积分区间和对应的难度参数
if (playerPoints < 1000) { if (playerPoints < 1000) {
// 新手期0-1,000分 // 新手期0-1,000分
// NPC保持50-70%实力,给予发展空间但保持挑战 // NPC保持30-50%实力,给予充分发展空间,但资源增长速度加快
const ratio = 0.5 + (playerPoints / 1000) * 0.2 const ratio = 0.3 + (playerPoints / 1000) * 0.2
return { return {
powerRatio: ratio, powerRatio: ratio,
checkInterval: 300, // 5分钟 checkInterval: 300, // 5分钟
resourceGrowthRate: 1.2, // 提升资源增长,确保NPC快速发育 resourceGrowthRate: 0.8, // 从0.4提升到0.8确保NPC有足够资源发育
buildingGrowthSpeed: 0.8, buildingGrowthSpeed: 0.6, // 从0.4提升到0.6
techGrowthSpeed: 0.8 techGrowthSpeed: 0.6 // 从0.4提升到0.6
} }
} else if (playerPoints < 5000) { } else if (playerPoints < 5000) {
// 初级期1,000-5,000分 // 初级期1,000-5,000分
// NPC保持70-110%实力,快速追赶玩家 // NPC保持50-70%实力,逐渐增加挑战
const ratio = 0.7 + ((playerPoints - 1000) / 4000) * 0.4 const ratio = 0.5 + ((playerPoints - 1000) / 4000) * 0.2
return { return {
powerRatio: ratio, powerRatio: ratio,
checkInterval: 240, // 4分钟 checkInterval: 240, // 4分钟
resourceGrowthRate: 1.5, // 大幅提升资源增长速度 resourceGrowthRate: 1.0, // 从0.6提升到1.0,与玩家资源产出相当
buildingGrowthSpeed: 1.2, buildingGrowthSpeed: 0.8, // 从0.6提升到0.8
techGrowthSpeed: 1.2 techGrowthSpeed: 0.8 // 从0.6提升到0.8
} }
} else if (playerPoints < 20000) { } else if (playerPoints < 20000) {
// 中级期5,000-20,000分 // 中级期5,000-20,000分
// NPC保持110-150%实力,形成强大威胁 // NPC保持70-90%实力,持续挑战
const ratio = 1.1 + ((playerPoints - 5000) / 15000) * 0.4 const ratio = 0.7 + ((playerPoints - 5000) / 15000) * 0.2
return { return {
powerRatio: ratio, powerRatio: ratio,
checkInterval: 180, // 3分钟 checkInterval: 180, // 3分钟
resourceGrowthRate: 1.8, // 极大幅提升资源增长 resourceGrowthRate: 0.8,
buildingGrowthSpeed: 1.5, buildingGrowthSpeed: 0.8,
techGrowthSpeed: 1.5 techGrowthSpeed: 0.8
} }
} else if (playerPoints < 50000) { } else if (playerPoints < 50000) {
// 高级期20,000-50,000分 // 高级期20,000-50,000分
// NPC保持150-200%实力,远超玩家 // NPC保持90-110%实力,与玩家势均力敌
const ratio = 1.5 + ((playerPoints - 20000) / 30000) * 0.5 const ratio = 0.9 + ((playerPoints - 20000) / 30000) * 0.2
return { return {
powerRatio: ratio, powerRatio: ratio,
checkInterval: 150, // 2.5分钟 checkInterval: 150, // 2.5分钟
resourceGrowthRate: 2.2, // 极高资源增长 resourceGrowthRate: 1.0,
buildingGrowthSpeed: 1.8, buildingGrowthSpeed: 1.0,
techGrowthSpeed: 1.8 techGrowthSpeed: 1.0
} }
} else { } else {
// 专家期50,000+分 // 专家期50,000+分
// NPC保持200-250%实力,成为超强对手 // NPC保持110-130%实力,超越玩家
const ratio = Math.min(2.5, 2.0 + ((playerPoints - 50000) / 50000) * 0.5) const ratio = Math.min(1.3, 1.1 + ((playerPoints - 50000) / 50000) * 0.2)
return { return {
powerRatio: ratio, powerRatio: ratio,
checkInterval: 120, // 2分钟 checkInterval: 120, // 2分钟
resourceGrowthRate: 2.5, // 极高的资源增长速度 resourceGrowthRate: 1.2,
buildingGrowthSpeed: 2.0, buildingGrowthSpeed: 1.2,
techGrowthSpeed: 2.0 techGrowthSpeed: 1.2
} }
} }
} }

View File

@@ -68,13 +68,18 @@ export const migrateGameData = (): void => {
// 修复NPC数据确保所有必需字段都存在 // 修复NPC数据确保所有必需字段都存在
if (oldData.npcs && Array.isArray(oldData.npcs)) { if (oldData.npcs && Array.isArray(oldData.npcs)) {
const now = Date.now()
oldData.npcs.forEach((npc: NPC) => { oldData.npcs.forEach((npc: NPC) => {
// 确保NPC有必需的时间字段 // 确保NPC有必需的时间字段,并设置随机冷却避免同时行动
if (npc.lastSpyTime === undefined) { if (npc.lastSpyTime === undefined || npc.lastSpyTime === 0) {
npc.lastSpyTime = 0 // 0-4分钟的随机延迟
const randomSpyOffset = Math.random() * 240 * 1000
npc.lastSpyTime = now - randomSpyOffset
} }
if (npc.lastAttackTime === undefined) { if (npc.lastAttackTime === undefined || npc.lastAttackTime === 0) {
npc.lastAttackTime = 0 // 0-8分钟的随机延迟
const randomAttackOffset = Math.random() * 480 * 1000
npc.lastAttackTime = now - randomAttackOffset
} }
// 确保NPC有必需的数组字段 // 确保NPC有必需的数组字段
if (!npc.fleetMissions) { if (!npc.fleetMissions) {