import { useState } from 'react' import { useGameStore } from '../store' import { applyEventChoice, rankPower } from '../../game/engine/systems/events' import { eventCategoryName } from '../../game/data/events' import { describeRealm } from '../../game/data/realms' import { Character } from '../../game/types/domain' import { combatPowerOf } from '../../game/engine/systems/combat' export function EventModal() { const pendingEventId = useGameStore((s) => s.pendingEventId) const pendingEventDef = useGameStore((s) => s.pendingEventDef) const world = useGameStore((s) => s.world) const bump = useGameStore((s) => s.bump) const setSpeed = useGameStore((s) => s.setSpeed) const [squadPicking, setSquadPicking] = useState(false) const [squadSel, setSquadSel] = useState([]) if (!pendingEventId || !pendingEventDef || !world) return null const raidIdx = pendingEventDef.options.findIndex((o) => o.eff.raid) const squadPool: Character[] = raidIdx >= 0 ? world.aliveMembers() .filter((c) => world.ageOf(c) >= 16 && c.state !== 'expedition') .sort((a, b) => rankPower(world, b) - rankPower(world, a)) : [] const closeModal = () => { useGameStore.setState({ pendingEventId: undefined, pendingEventDef: undefined }) setSquadPicking(false) setSquadSel([]) bump() } const choose = (idx: number) => { const isRaid = raidIdx >= 0 && raidIdx === idx if (isRaid && !squadPicking) { setSquadPicking(true) setSquadSel(squadPool.slice(0, 4).map((c) => c.id)) return } applyEventChoice(world, pendingEventId, idx, isRaid ? squadSel : undefined) closeModal() const sp = useGameStore.getState().speed if (sp > 1) setSpeed(1) } const toggleSquad = (id: string) => { setSquadSel((old) => old.includes(id) ? old.filter((x) => x !== id) : old.length >= 4 ? [...old.slice(1), id] : [...old, id] ) } return (
{pendingEventDef.name}
{eventCategoryName(pendingEventDef.category)} {pendingEventDef.once && ' · 仅此一次'}
{pendingEventDef.text}
{squadPicking && (
迎战点将(默认四人,可改动)
{squadPool.map((c) => (
toggleSquad(c.id)} > {c.name}·{describeRealm(c.realm)}·战力{Math.round(combatPowerOf(world, c))}
))} {squadPool.length === 0 && 无可出战之人}
)}
{pendingEventDef.options.map((o, i) => { const isRaid = raidIdx === i return ( ) })}
) }