Features: - Combat system with AP/EP hit calculation and three-layer defense - Auto-combat/farming mode - Item system with stacking support - Skill system with levels, milestones, and parent skill sync - Shop system with dynamic pricing - Inventory management with bulk selling - Event system - Game loop with offline earnings - Save/Load system Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.2 KiB
JavaScript
95 lines
2.2 KiB
JavaScript
/**
|
|
* Store 测试辅助函数
|
|
*/
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
import { createMockPlayer } from '../fixtures/player.js'
|
|
import { createMockGame } from '../fixtures/game.js'
|
|
|
|
/**
|
|
* 设置测试用 Pinia Store
|
|
* @returns {Object} { playerStore, gameStore, pinia }
|
|
*/
|
|
export function setupTestStore() {
|
|
const pinia = createPinia()
|
|
setActivePinia(pinia)
|
|
|
|
// 动态导入 stores
|
|
const { usePlayerStore } = require('@/store/player.js')
|
|
const { useGameStore } = require('@/store/game.js')
|
|
|
|
const playerStore = usePlayerStore()
|
|
const gameStore = useGameStore()
|
|
|
|
// 初始化 mock 数据
|
|
Object.assign(playerStore, createMockPlayer())
|
|
Object.assign(gameStore, createMockGame())
|
|
|
|
return { playerStore, gameStore, pinia }
|
|
}
|
|
|
|
/**
|
|
* 创建带有特定技能的 Store
|
|
* @param {string} skillId - 技能ID
|
|
* @param {number} level - 技能等级
|
|
* @returns {Object} { playerStore, gameStore }
|
|
*/
|
|
export function setupStoreWithSkill(skillId, level = 1) {
|
|
const { playerStore, gameStore, pinia } = setupTestStore()
|
|
|
|
playerStore.skills = {
|
|
[skillId]: {
|
|
level,
|
|
exp: 0,
|
|
unlocked: true,
|
|
maxExp: (level + 1) * 100
|
|
}
|
|
}
|
|
|
|
return { playerStore, gameStore, pinia }
|
|
}
|
|
|
|
/**
|
|
* 创建战斗中的 Store
|
|
* @param {Object} enemy - 敌人对象
|
|
* @returns {Object} { playerStore, gameStore }
|
|
*/
|
|
export function setupStoreInCombat(enemy) {
|
|
const { playerStore, gameStore, pinia } = setupTestStore()
|
|
|
|
gameStore.inCombat = true
|
|
gameStore.combatState = {
|
|
enemyId: enemy.id,
|
|
enemy,
|
|
stance: 'balance',
|
|
environment: 'normal',
|
|
startTime: Date.now(),
|
|
ticks: 0
|
|
}
|
|
|
|
return { playerStore, gameStore, pinia }
|
|
}
|
|
|
|
/**
|
|
* 创建带有物品的 Store
|
|
* @param {Array} items - 物品数组
|
|
* @returns {Object} { playerStore, gameStore }
|
|
*/
|
|
export function setupStoreWithItems(items) {
|
|
const { playerStore, gameStore, pinia } = setupTestStore()
|
|
|
|
playerStore.inventory = [...items]
|
|
|
|
return { playerStore, gameStore, pinia }
|
|
}
|
|
|
|
/**
|
|
* 重置 Store 状态
|
|
* @param {Object} playerStore - 玩家Store
|
|
* @param {Object} gameStore - 游戏Store
|
|
*/
|
|
export function resetStore(playerStore, gameStore) {
|
|
Object.assign(playerStore, createMockPlayer())
|
|
Object.assign(gameStore, createMockGame())
|
|
}
|