mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
feat: 初始化项目结构与核心功能
引入项目基础目录结构,包含多语言支持、主要页面与组件、核心游戏逻辑、UI 组件库、加密与本地持久化、自动化 Docker 构建流程、GitHub issue 模板(中英文)、README(中英文)、LICENSE 及开发配置文件。实现 OGame 单机版主要功能模块,为后续开发和扩展奠定基础。
This commit is contained in:
81
src/logic/researchValidation.ts
Normal file
81
src/logic/researchValidation.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import type { Planet, Resources, BuildQueueItem, Officer } from '@/types/game'
|
||||
import { TechnologyType, OfficerType } from '@/types/game'
|
||||
import * as researchLogic from './researchLogic'
|
||||
import * as resourceLogic from './resourceLogic'
|
||||
import * as publicLogic from './publicLogic'
|
||||
import * as officerLogic from './officerLogic'
|
||||
|
||||
/**
|
||||
* 验证科技研究的所有条件
|
||||
*/
|
||||
export const validateTechnologyResearch = (
|
||||
planet: Planet,
|
||||
techType: TechnologyType,
|
||||
technologies: Partial<Record<TechnologyType, number>>,
|
||||
researchQueue: BuildQueueItem[]
|
||||
): {
|
||||
valid: boolean
|
||||
reason?: string
|
||||
} => {
|
||||
const currentLevel = technologies[techType] || 0
|
||||
const targetLevel = currentLevel + 1
|
||||
const cost = researchLogic.calculateTechnologyCost(techType, targetLevel)
|
||||
|
||||
// 检查研究队列是否已满
|
||||
const maxQueue = publicLogic.getMaxResearchQueue(technologies)
|
||||
if (researchQueue.length >= maxQueue) {
|
||||
return { valid: false, reason: 'errors.researchQueueFull' }
|
||||
}
|
||||
|
||||
// 检查前置条件
|
||||
if (!researchLogic.checkTechnologyRequirements(techType, planet.buildings, technologies)) {
|
||||
return { valid: false, reason: 'errors.requirementsNotMet' }
|
||||
}
|
||||
|
||||
// 检查资源
|
||||
if (!resourceLogic.checkResourcesAvailable(planet.resources, cost)) {
|
||||
return { valid: false, reason: 'errors.insufficientResources' }
|
||||
}
|
||||
|
||||
return { valid: true }
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行科技研究(扣除资源,创建队列项)
|
||||
*/
|
||||
export const executeTechnologyResearch = (
|
||||
planet: Planet,
|
||||
techType: TechnologyType,
|
||||
currentLevel: number,
|
||||
officers: Record<OfficerType, Officer>
|
||||
): { queueItem: BuildQueueItem } => {
|
||||
const targetLevel = currentLevel + 1
|
||||
const cost = researchLogic.calculateTechnologyCost(techType, targetLevel)
|
||||
|
||||
// 计算军官加成
|
||||
const bonuses = officerLogic.calculateActiveBonuses(officers, Date.now())
|
||||
const time = researchLogic.calculateTechnologyTime(techType, currentLevel, bonuses.researchSpeedBonus)
|
||||
|
||||
// 扣除资源
|
||||
resourceLogic.deductResources(planet.resources, cost)
|
||||
|
||||
// 创建队列项
|
||||
const queueItem = researchLogic.createResearchQueueItem(techType, targetLevel, time)
|
||||
|
||||
return { queueItem }
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消研究并计算返还资源
|
||||
*/
|
||||
export const cancelTechnologyResearch = (queueItem: BuildQueueItem): Resources => {
|
||||
const cost = researchLogic.calculateTechnologyCost(queueItem.itemType as TechnologyType, queueItem.targetLevel || 1)
|
||||
|
||||
return {
|
||||
metal: Math.floor(cost.metal * 0.5),
|
||||
crystal: Math.floor(cost.crystal * 0.5),
|
||||
deuterium: Math.floor(cost.deuterium * 0.5),
|
||||
darkMatter: Math.floor(cost.darkMatter * 0.5),
|
||||
energy: 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user