2026-01-21 17:13:51 +08:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
export const useGameStore = defineStore('game', () => {
|
|
|
|
|
// 当前标签页
|
|
|
|
|
const currentTab = ref('status')
|
|
|
|
|
|
|
|
|
|
// 抽屉状态
|
|
|
|
|
const drawerState = ref({
|
|
|
|
|
inventory: false,
|
|
|
|
|
event: false,
|
2026-01-23 16:20:10 +08:00
|
|
|
shop: false,
|
|
|
|
|
crafting: false
|
2026-01-21 17:13:51 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 日志
|
|
|
|
|
const logs = ref([])
|
|
|
|
|
|
|
|
|
|
// 游戏时间
|
|
|
|
|
const gameTime = ref({
|
|
|
|
|
day: 1,
|
|
|
|
|
hour: 8,
|
|
|
|
|
minute: 0,
|
|
|
|
|
totalMinutes: 480
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 战斗状态
|
|
|
|
|
const inCombat = ref(false)
|
|
|
|
|
const combatState = ref(null)
|
|
|
|
|
const autoCombat = ref(false) // 自动战斗模式
|
2026-01-23 19:40:55 +08:00
|
|
|
const isSearching = ref(false) // 正在寻找敌人中(自动战斗间隔期间)
|
2026-02-02 15:54:49 +08:00
|
|
|
const preferredStance = ref('balance') // 记住玩家偏好的战斗姿态
|
2026-01-21 17:13:51 +08:00
|
|
|
|
|
|
|
|
// 活动任务
|
|
|
|
|
const activeTasks = ref([])
|
|
|
|
|
|
|
|
|
|
// 负面状态
|
|
|
|
|
const negativeStatus = ref([])
|
|
|
|
|
|
|
|
|
|
// 市场价格
|
|
|
|
|
const marketPrices = ref({
|
|
|
|
|
lastRefreshDay: 1,
|
|
|
|
|
prices: {}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 当前事件
|
|
|
|
|
const currentEvent = ref(null)
|
|
|
|
|
|
2026-02-02 15:54:49 +08:00
|
|
|
// 成就系统
|
|
|
|
|
const achievements = ref({})
|
|
|
|
|
const achievementProgress = ref({
|
|
|
|
|
totalKills: 0,
|
|
|
|
|
bossKills: 0,
|
|
|
|
|
prostheticEquipped: 0,
|
|
|
|
|
visitedLocations: new Set(),
|
|
|
|
|
totalEarned: 0
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-21 17:13:51 +08:00
|
|
|
// 添加日志
|
|
|
|
|
function addLog(message, type = 'info') {
|
|
|
|
|
const time = `${String(gameTime.value.hour).padStart(2, '0')}:${String(gameTime.value.minute).padStart(2, '0')}`
|
|
|
|
|
logs.value.push({
|
|
|
|
|
id: Date.now(),
|
|
|
|
|
time,
|
|
|
|
|
message,
|
|
|
|
|
type
|
|
|
|
|
})
|
|
|
|
|
// 限制日志数量
|
|
|
|
|
if (logs.value.length > 200) {
|
|
|
|
|
logs.value.shift()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 15:54:49 +08:00
|
|
|
// 检查成就
|
|
|
|
|
function checkAchievements(triggerType, data = {}) {
|
|
|
|
|
const { ACHIEVEMENT_CONFIG } = require('@/config/achievements.js')
|
|
|
|
|
let newAchievements = []
|
|
|
|
|
|
|
|
|
|
for (const [id, achievement] of Object.entries(ACHIEVEMENT_CONFIG)) {
|
|
|
|
|
// 已完成的跳过
|
|
|
|
|
if (achievements.value[id]) continue
|
|
|
|
|
|
|
|
|
|
let unlocked = false
|
|
|
|
|
|
|
|
|
|
switch (achievement.condition.type) {
|
|
|
|
|
case 'kill':
|
|
|
|
|
unlocked = achievementProgress.value.totalKills >= achievement.condition.count
|
|
|
|
|
break
|
|
|
|
|
case 'boss_kill':
|
|
|
|
|
unlocked = achievementProgress.value.bossKills >= achievement.condition.count
|
|
|
|
|
break
|
|
|
|
|
case 'equip_prosthetic':
|
|
|
|
|
unlocked = data.prostheticCount >= achievement.condition.count
|
|
|
|
|
break
|
|
|
|
|
case 'skill_level':
|
|
|
|
|
unlocked = data.maxSkillLevel >= achievement.condition.level
|
|
|
|
|
break
|
|
|
|
|
case 'visit_locations':
|
|
|
|
|
unlocked = achievementProgress.value.visitedLocations.size >= achievement.condition.count
|
|
|
|
|
break
|
|
|
|
|
case 'total_earned':
|
|
|
|
|
unlocked = achievementProgress.value.totalEarned >= achievement.condition.amount
|
|
|
|
|
break
|
|
|
|
|
case 'survive_days':
|
|
|
|
|
unlocked = gameTime.value.day >= achievement.condition.days
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unlocked) {
|
|
|
|
|
achievements.value[id] = {
|
|
|
|
|
unlocked: true,
|
|
|
|
|
timestamp: Date.now()
|
|
|
|
|
}
|
|
|
|
|
newAchievements.push(achievement)
|
|
|
|
|
addLog(`🏆 解锁成就: ${achievement.icon} ${achievement.name}`, 'reward')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newAchievements
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 17:13:51 +08:00
|
|
|
// 重置游戏状态
|
|
|
|
|
function resetGame() {
|
|
|
|
|
currentTab.value = 'status'
|
|
|
|
|
drawerState.value = {
|
|
|
|
|
inventory: false,
|
|
|
|
|
event: false,
|
|
|
|
|
shop: false
|
|
|
|
|
}
|
|
|
|
|
logs.value = []
|
|
|
|
|
gameTime.value = {
|
|
|
|
|
day: 1,
|
|
|
|
|
hour: 8,
|
|
|
|
|
minute: 0,
|
|
|
|
|
totalMinutes: 480
|
|
|
|
|
}
|
|
|
|
|
inCombat.value = false
|
|
|
|
|
combatState.value = null
|
|
|
|
|
autoCombat.value = false
|
2026-01-23 19:40:55 +08:00
|
|
|
isSearching.value = false
|
2026-02-02 15:54:49 +08:00
|
|
|
preferredStance.value = 'balance'
|
2026-01-21 17:13:51 +08:00
|
|
|
activeTasks.value = []
|
|
|
|
|
negativeStatus.value = []
|
|
|
|
|
marketPrices.value = {
|
|
|
|
|
lastRefreshDay: 1,
|
|
|
|
|
prices: {}
|
|
|
|
|
}
|
|
|
|
|
currentEvent.value = null
|
2026-02-02 15:54:49 +08:00
|
|
|
achievements.value = {}
|
|
|
|
|
achievementProgress.value = {
|
|
|
|
|
totalKills: 0,
|
|
|
|
|
bossKills: 0,
|
|
|
|
|
prostheticEquipped: 0,
|
|
|
|
|
visitedLocations: new Set(),
|
|
|
|
|
totalEarned: 0
|
|
|
|
|
}
|
2026-01-21 17:13:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
currentTab,
|
|
|
|
|
drawerState,
|
|
|
|
|
logs,
|
|
|
|
|
gameTime,
|
|
|
|
|
inCombat,
|
|
|
|
|
combatState,
|
|
|
|
|
autoCombat,
|
2026-01-23 19:40:55 +08:00
|
|
|
isSearching,
|
2026-02-02 15:54:49 +08:00
|
|
|
preferredStance,
|
2026-01-21 17:13:51 +08:00
|
|
|
activeTasks,
|
|
|
|
|
negativeStatus,
|
|
|
|
|
marketPrices,
|
|
|
|
|
currentEvent,
|
2026-02-02 15:54:49 +08:00
|
|
|
achievements,
|
|
|
|
|
achievementProgress,
|
2026-01-21 17:13:51 +08:00
|
|
|
addLog,
|
2026-02-02 15:54:49 +08:00
|
|
|
resetGame,
|
|
|
|
|
checkAchievements
|
2026-01-21 17:13:51 +08:00
|
|
|
}
|
|
|
|
|
})
|