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:
193
src/logic/planetLogic.ts
Normal file
193
src/logic/planetLogic.ts
Normal file
@@ -0,0 +1,193 @@
|
||||
import type { Planet, Resources } from '@/types/game'
|
||||
import { ShipType, DefenseType, BuildingType } from '@/types/game'
|
||||
import { MOON_CONFIG } from '@/config/gameConfig'
|
||||
|
||||
/**
|
||||
* 创建初始星球
|
||||
*/
|
||||
export const createInitialPlanet = (playerId: string, planetName: string = 'Home Planet'): Planet => {
|
||||
const initialPlanet: Planet = {
|
||||
id: 'planet1',
|
||||
name: planetName,
|
||||
ownerId: playerId,
|
||||
position: { galaxy: 1, system: 1, position: 1 },
|
||||
resources: {
|
||||
metal: 500,
|
||||
crystal: 500,
|
||||
deuterium: 0,
|
||||
darkMatter: 0,
|
||||
energy: 0
|
||||
},
|
||||
buildings: {} as Record<BuildingType, number>,
|
||||
fleet: {
|
||||
[ShipType.LightFighter]: 0,
|
||||
[ShipType.HeavyFighter]: 0,
|
||||
[ShipType.Cruiser]: 0,
|
||||
[ShipType.Battleship]: 0,
|
||||
[ShipType.SmallCargo]: 0,
|
||||
[ShipType.LargeCargo]: 0,
|
||||
[ShipType.ColonyShip]: 0,
|
||||
[ShipType.Recycler]: 0,
|
||||
[ShipType.EspionageProbe]: 0,
|
||||
[ShipType.DarkMatterHarvester]: 0
|
||||
},
|
||||
defense: {
|
||||
[DefenseType.RocketLauncher]: 0,
|
||||
[DefenseType.LightLaser]: 0,
|
||||
[DefenseType.HeavyLaser]: 0,
|
||||
[DefenseType.GaussCannon]: 0,
|
||||
[DefenseType.IonCannon]: 0,
|
||||
[DefenseType.PlasmaTurret]: 0,
|
||||
[DefenseType.SmallShieldDome]: 0,
|
||||
[DefenseType.LargeShieldDome]: 0
|
||||
},
|
||||
buildQueue: [],
|
||||
lastUpdate: Date.now(),
|
||||
maxSpace: 200,
|
||||
isMoon: false
|
||||
}
|
||||
|
||||
// 初始化建筑等级
|
||||
Object.values(BuildingType).forEach(building => {
|
||||
initialPlanet.buildings[building] = 0
|
||||
})
|
||||
|
||||
return initialPlanet
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建NPC星球
|
||||
*/
|
||||
export const createNPCPlanet = (
|
||||
npcId: number,
|
||||
position: { galaxy: number; system: number; position: number },
|
||||
planetPrefix: string = 'Planet'
|
||||
): Planet => {
|
||||
const npcPlanet: Planet = {
|
||||
id: `npc_planet_${npcId}`,
|
||||
name: `${planetPrefix} ${position.galaxy}:${position.system}:${position.position}`,
|
||||
ownerId: `npc_${npcId}`,
|
||||
position,
|
||||
resources: {
|
||||
metal: Math.floor(Math.random() * 10000) + 5000,
|
||||
crystal: Math.floor(Math.random() * 5000) + 2000,
|
||||
deuterium: Math.floor(Math.random() * 2000) + 500,
|
||||
darkMatter: Math.floor(Math.random() * 100),
|
||||
energy: 0
|
||||
},
|
||||
buildings: {} as Record<BuildingType, number>,
|
||||
fleet: {
|
||||
[ShipType.LightFighter]: Math.floor(Math.random() * 50),
|
||||
[ShipType.HeavyFighter]: Math.floor(Math.random() * 20),
|
||||
[ShipType.Cruiser]: Math.floor(Math.random() * 10),
|
||||
[ShipType.Battleship]: Math.floor(Math.random() * 5),
|
||||
[ShipType.SmallCargo]: Math.floor(Math.random() * 10),
|
||||
[ShipType.LargeCargo]: Math.floor(Math.random() * 5),
|
||||
[ShipType.ColonyShip]: 0,
|
||||
[ShipType.Recycler]: 0,
|
||||
[ShipType.EspionageProbe]: 0,
|
||||
[ShipType.DarkMatterHarvester]: 0
|
||||
},
|
||||
defense: {
|
||||
[DefenseType.RocketLauncher]: Math.floor(Math.random() * 100),
|
||||
[DefenseType.LightLaser]: Math.floor(Math.random() * 50),
|
||||
[DefenseType.HeavyLaser]: Math.floor(Math.random() * 20),
|
||||
[DefenseType.GaussCannon]: Math.floor(Math.random() * 10),
|
||||
[DefenseType.IonCannon]: Math.floor(Math.random() * 10),
|
||||
[DefenseType.PlasmaTurret]: Math.floor(Math.random() * 5),
|
||||
[DefenseType.SmallShieldDome]: Math.random() > 0.5 ? 1 : 0,
|
||||
[DefenseType.LargeShieldDome]: Math.random() > 0.8 ? 1 : 0
|
||||
},
|
||||
buildQueue: [],
|
||||
lastUpdate: Date.now(),
|
||||
maxSpace: 200,
|
||||
isMoon: false
|
||||
}
|
||||
|
||||
// 随机初始化建筑等级
|
||||
Object.values(BuildingType).forEach(building => {
|
||||
npcPlanet.buildings[building] = Math.floor(Math.random() * 10)
|
||||
})
|
||||
|
||||
return npcPlanet
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算月球生成概率
|
||||
*/
|
||||
export const calculateMoonChance = (debrisField: Resources): number => {
|
||||
const totalDebris = debrisField.metal + debrisField.crystal
|
||||
if (totalDebris < MOON_CONFIG.minDebrisField) return 0
|
||||
|
||||
const chance = MOON_CONFIG.baseChance + Math.floor(totalDebris / MOON_CONFIG.chancePerDebris)
|
||||
return Math.min(chance, MOON_CONFIG.maxChance)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建月球
|
||||
*/
|
||||
export const createMoon = (
|
||||
parentPlanet: Planet,
|
||||
position: { galaxy: number; system: number; position: number },
|
||||
playerId: string,
|
||||
moonSuffix: string = "'s Moon"
|
||||
): Planet => {
|
||||
const moonId = `moon_${Date.now()}`
|
||||
const moon: Planet = {
|
||||
id: moonId,
|
||||
name: `${parentPlanet.name}${moonSuffix}`,
|
||||
ownerId: playerId,
|
||||
position: { ...position },
|
||||
resources: {
|
||||
metal: 0,
|
||||
crystal: 0,
|
||||
deuterium: 0,
|
||||
darkMatter: 0,
|
||||
energy: 0
|
||||
},
|
||||
buildings: {} as Record<BuildingType, number>,
|
||||
fleet: {
|
||||
[ShipType.LightFighter]: 0,
|
||||
[ShipType.HeavyFighter]: 0,
|
||||
[ShipType.Cruiser]: 0,
|
||||
[ShipType.Battleship]: 0,
|
||||
[ShipType.SmallCargo]: 0,
|
||||
[ShipType.LargeCargo]: 0,
|
||||
[ShipType.ColonyShip]: 0,
|
||||
[ShipType.Recycler]: 0,
|
||||
[ShipType.EspionageProbe]: 0,
|
||||
[ShipType.DarkMatterHarvester]: 0
|
||||
},
|
||||
defense: {
|
||||
[DefenseType.RocketLauncher]: 0,
|
||||
[DefenseType.LightLaser]: 0,
|
||||
[DefenseType.HeavyLaser]: 0,
|
||||
[DefenseType.GaussCannon]: 0,
|
||||
[DefenseType.IonCannon]: 0,
|
||||
[DefenseType.PlasmaTurret]: 0,
|
||||
[DefenseType.SmallShieldDome]: 0,
|
||||
[DefenseType.LargeShieldDome]: 0
|
||||
},
|
||||
buildQueue: [],
|
||||
lastUpdate: Date.now(),
|
||||
maxSpace: MOON_CONFIG.baseSize,
|
||||
isMoon: true,
|
||||
parentPlanetId: parentPlanet.id
|
||||
}
|
||||
|
||||
// 初始化建筑等级
|
||||
Object.values(BuildingType).forEach(building => {
|
||||
moon.buildings[building] = 0
|
||||
})
|
||||
|
||||
return moon
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算月球空间上限
|
||||
*/
|
||||
export const calculateMoonMaxSpace = (moon: Planet): number => {
|
||||
if (!moon.isMoon) return 0
|
||||
const lunarBaseLevel = moon.buildings[BuildingType.LunarBase] || 0
|
||||
return MOON_CONFIG.baseSize + lunarBaseLevel * MOON_CONFIG.lunarBaseSpaceBonus
|
||||
}
|
||||
Reference in New Issue
Block a user