Initial commit: Text Adventure Game
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>
This commit is contained in:
177
config/shop.js
Normal file
177
config/shop.js
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* 商店配置
|
||||
* 定义不同位置商店的出售物品
|
||||
*/
|
||||
|
||||
import { ITEM_CONFIG } from './items.js'
|
||||
|
||||
// 商店配置
|
||||
export const SHOP_CONFIG = {
|
||||
// 营地商店 - 基础物品
|
||||
camp: {
|
||||
name: '营地杂货铺',
|
||||
owner: '老杰克',
|
||||
icon: '🏪',
|
||||
// 出售的物品列表
|
||||
items: [
|
||||
{
|
||||
itemId: 'bread',
|
||||
stock: 99, // 库存,-1表示无限
|
||||
baseStock: 99
|
||||
},
|
||||
{
|
||||
itemId: 'healing_herb',
|
||||
stock: 20,
|
||||
baseStock: 20
|
||||
},
|
||||
{
|
||||
itemId: 'old_book',
|
||||
stock: 5,
|
||||
baseStock: 5
|
||||
}
|
||||
],
|
||||
// 收购的物品类型
|
||||
buyItems: ['material', 'consumable'],
|
||||
// 收购价格倍率
|
||||
buyRate: 0.3
|
||||
},
|
||||
|
||||
// 测试市场 - 商人老张
|
||||
market: {
|
||||
name: '商人老张的摊位',
|
||||
owner: '商人老张',
|
||||
icon: '🛒',
|
||||
items: [
|
||||
{
|
||||
itemId: 'bread',
|
||||
stock: -1,
|
||||
baseStock: -1
|
||||
},
|
||||
{
|
||||
itemId: 'healing_herb',
|
||||
stock: 50,
|
||||
baseStock: 50
|
||||
},
|
||||
{
|
||||
itemId: 'old_book',
|
||||
stock: 10,
|
||||
baseStock: 10
|
||||
}
|
||||
],
|
||||
buyItems: ['material', 'consumable', 'weapon', 'armor'],
|
||||
buyRate: 0.4
|
||||
},
|
||||
|
||||
// 测试黑市 - 神秘人
|
||||
blackmarket: {
|
||||
name: '神秘人的黑市',
|
||||
owner: '神秘人',
|
||||
icon: '🌑',
|
||||
items: [
|
||||
{
|
||||
itemId: 'healing_herb',
|
||||
stock: 10,
|
||||
baseStock: 10
|
||||
}
|
||||
],
|
||||
buyItems: ['material', 'weapon'],
|
||||
buyRate: 0.2
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定位置的商店配置
|
||||
* @param {string} locationId - 位置ID
|
||||
* @returns {Object|null} 商店配置
|
||||
*/
|
||||
export function getShopConfig(locationId) {
|
||||
return SHOP_CONFIG[locationId] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商店的可售物品列表
|
||||
* @param {string} locationId - 位置ID
|
||||
* @returns {Array} 可售物品列表
|
||||
*/
|
||||
export function getShopItems(locationId) {
|
||||
const shop = getShopConfig(locationId)
|
||||
if (!shop) return []
|
||||
|
||||
return shop.items
|
||||
.filter(item => item.stock === -1 || item.stock > 0)
|
||||
.map(shopItem => {
|
||||
const itemConfig = ITEM_CONFIG[shopItem.itemId]
|
||||
if (!itemConfig) return null
|
||||
|
||||
return {
|
||||
...itemConfig,
|
||||
stock: shopItem.stock,
|
||||
baseStock: shopItem.baseStock,
|
||||
shopItemId: shopItem.itemId
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查物品是否可以被商店收购
|
||||
* @param {string} locationId - 位置ID
|
||||
* @param {Object} item - 物品对象
|
||||
* @returns {boolean} 是否可以收购
|
||||
*/
|
||||
export function canShopBuyItem(locationId, item) {
|
||||
const shop = getShopConfig(locationId)
|
||||
if (!shop || !shop.buyItems) return false
|
||||
|
||||
// 关键道具不能出售
|
||||
if (item.type === 'key') return false
|
||||
|
||||
return shop.buyItems.includes(item.type)
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算物品的购买价格(玩家买)
|
||||
* @param {Object} gameStore - 游戏Store
|
||||
* @param {string} itemId - 物品ID
|
||||
* @returns {number} 购买价格(铜币)
|
||||
*/
|
||||
export function getBuyPrice(gameStore, itemId) {
|
||||
const item = ITEM_CONFIG[itemId]
|
||||
if (!item || !item.baseValue) return 0
|
||||
|
||||
const marketData = gameStore.marketPrices?.prices?.[itemId]
|
||||
const basePrice = item.baseValue
|
||||
|
||||
if (marketData) {
|
||||
return Math.floor(basePrice * marketData.buyRate)
|
||||
}
|
||||
|
||||
return Math.floor(basePrice * 2)
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算物品的出售价格(玩家卖)
|
||||
* @param {Object} gameStore - 游戏Store
|
||||
* @param {string} itemId - 物品ID
|
||||
* @param {number} quality - 物品品质
|
||||
* @returns {number} 出售价格(铜币)
|
||||
*/
|
||||
export function getSellPrice(gameStore, itemId, quality = 100) {
|
||||
const item = ITEM_CONFIG[itemId]
|
||||
if (!item || !item.baseValue) return 0
|
||||
|
||||
const marketData = gameStore.marketPrices?.prices?.[itemId]
|
||||
const basePrice = item.baseValue
|
||||
|
||||
// 品质影响价格
|
||||
const qualityMultiplier = quality / 100
|
||||
let price = Math.floor(basePrice * qualityMultiplier)
|
||||
|
||||
if (marketData) {
|
||||
price = Math.floor(price * marketData.sellRate)
|
||||
} else {
|
||||
price = Math.floor(price * 0.3)
|
||||
}
|
||||
|
||||
return Math.max(1, price)
|
||||
}
|
||||
Reference in New Issue
Block a user