import { useGameStore } from '../store'
import { ITEMS } from '../../game/data/items'
import { TECHNIQUES } from '../../game/data/techniques'
import { techniqueGradeName } from '../../game/data/realms'
import { marketPrice, buyItem, sellItem, buyTechnique, techniquePrice } from '../../game/engine/sim/Market'
import { PILL_RECIPES, FORGE_RECIPES } from '../../game/data/items'
import { bonusOf } from '../../game/data/buildings'
import { useMemo, useState } from 'react'
export default function MarketPanel() {
const world = useGameStore((s) => s.world)
const bump = useGameStore((s) => s.bump)
const revision = useGameStore((s) => s.revision)
void revision
const [tab, setTab] = useState<'goods' | 'tech' | 'craft'>('goods')
if (!world) return null
const w = world
const fam = w.state.family
const inv = fam.inventory
const goods = useMemo(
() => Object.values(ITEMS).filter((i) => ['resource', 'material', 'pill', 'talisman', 'brew', 'artifact'].includes(i.kind)),
[]
)
const artifacts = useMemo(() => Object.values(ITEMS).filter((i) => i.kind === 'artifact'), [])
const marketTech = TECHNIQUES.filter((t) => t.grade <= 3)
const cangshuLv = fam.buildings['cangshu'] ?? 0
const price = (id: string) => marketPrice(w, id)
return (
setTab('goods')}>货栈
setTab('tech')}>法帖
setTab('craft')}>定制
{tab === 'goods' && (
<>
集市物价随季节波动(当前行情 {Math.round(((fam.flag['priceMult'] as number) ?? 1) * 100)}%)。
仓库寄存的灵草、灵矿、兽核均可在此出手。
| 品名 |
说明 |
行价 |
库存/持有 |
买卖 |
{[...goods, ...artifacts].map((item) => {
const have = ['resource', 'material', 'pill', 'talisman', 'brew', 'artifact'].includes(item.kind)
? inv[item.id] ?? 0
: 0
const stock = item.kind === 'artifact' ? 3 : ['pill', 'talisman', 'brew'].includes(item.kind) ? 5 : 9999
const count = item.kind === 'artifact' ? 1 : 5
return (
|
{item.icon} {item.name}
|
{item.desc} |
{price(item.id)} 灵石 |
{have} |
{' '}
{(['resource', 'material', 'pill'].includes(item.kind) && have >= count) && (
)}
{item.kind === 'artifact' && have > 0 && (
已购藏
)}
|
)
})}
>
)}
{tab === 'tech' && (
<>
藏书阁录存法帖,族人可修习。藏书阁等级决定可在坊市搜购的品阶(当前 {cangshuLv} 级,可购至{techniqueGradeName(Math.min(4, Math.max(0, cangshuLv + 1)))})。
若藏书阁未建或等级不足,只可见基础法帖。
| 法帖 |
品阶/路子 |
妙用 |
修为加成 |
战力加成 |
|
{marketTech
.filter((t) => t.grade <= 1 + cangshuLv)
.filter((t) => t.grade <= 3)
.map((t) => {
const owned = fam.techniques.includes(t.id)
const p = t.grade <= 1 + cangshuLv
const priceT = techniquePrice(t.id)
return (
| 《{t.name}》 |
{techniqueGradeName(t.grade)} · {t.path} |
{t.desc} |
+{Math.round((t.expBonus) * 100)}% |
+{Math.round((t.powerBonus) * 100)}% |
{owned ? (
已录
) : (
)}
|
)
})}
>
)}
{tab === 'craft' && (
<>
丹房依「灵草+兽核+灵石」配比丹药,成数随丹房等级;破境丹需丹房三级。炼器以灵矿兽核+灵石相合,无建筑门槛,只看家底。
丹房炼制(当前 {fam.buildings['danfang'] ?? 0} 级 · 成率 {Math.round(bonusOf('danfang', 'craftChance', fam.buildings['danfang'] ?? 0) * 100)}%)
| 丹方 | 药性 | 配方 | 门槛 | |
{PILL_RECIPES.map((r) => {
const lvl = fam.buildings['danfang'] ?? 0
const enough = (inv['lingcao'] ?? 0) >= r.lingcao && (inv['beastcore'] ?? 0) >= r.beastcore && fam.stones >= r.stones
return (
| 丹 {r.name} |
{r.desc} |
草{r.lingcao}·核{r.beastcore}·灵石{r.stones} |
{r.danfangLevel}级丹房 |
|
)
})}
铸器坊(灵矿+兽核+灵石 → 兵刃)
| 兵刃 | 妙用 | 配方 | |
{FORGE_RECIPES.map((r) => {
const enough = (inv['lingkuang'] ?? 0) >= r.lingkuang && (inv['beastcore'] ?? 0) >= r.beastcore && fam.stones >= r.stones
return (
| 器 {r.name} |
{r.desc} |
矿{r.lingkuang}·核{r.beastcore}·灵石{r.stones} |
|
)
})}
{(fam.buildings['danfang'] ?? 0) > 0 && (
破境丹亦可等拍卖会落槌(需要时留神百年拍卖)。
)}
>
)}
灵矿不足时可上坊市民间收购;妖丹于探秘与灵兽园中可得。
)
}