fix(game): 修复输了能进下一关的Bug、换关后塔残留、召唤按钮太小、战斗前不能发激励
This commit is contained in:
@@ -48,7 +48,7 @@ function calcPuaCost(hc: number): number {
|
||||
}
|
||||
|
||||
// ── PUA 输入面板 ─────────────────────────────────────────────────────────────
|
||||
function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
function PuaPanel({ gameReady, hc, waveStarted }: { gameReady: boolean; hc: number; waveStarted: boolean }) {
|
||||
const [text, setText] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [result, setResult] = useState<PuaResult | null>(null)
|
||||
@@ -61,7 +61,7 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
const canAfford = hc >= cost
|
||||
|
||||
const handleSubmit = useCallback(async () => {
|
||||
if (!text.trim() || loading || !gameReady) return
|
||||
if (!text.trim() || loading || !gameReady || !waveStarted) return
|
||||
|
||||
// 先从游戏扣除 HC(扣不到则拒绝)
|
||||
const spendHC: ((n: number) => boolean) | undefined =
|
||||
@@ -102,7 +102,7 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [text, loading, gameReady, hc])
|
||||
}, [text, loading, gameReady, hc, waveStarted])
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
@@ -143,7 +143,7 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
color: '#475569',
|
||||
marginTop: '2px',
|
||||
}}>
|
||||
输入打鸡血的话,AI判断鸡血值
|
||||
{!waveStarted ? '⚠ 召唤第一波后才能激励' : '输入打鸡血的话,AI判断鸡血值'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -210,12 +210,12 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
onChange={e => setText(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder={placeholder}
|
||||
disabled={loading || !gameReady}
|
||||
disabled={loading || !gameReady || !waveStarted}
|
||||
rows={4}
|
||||
style={{
|
||||
width: '100%',
|
||||
backgroundColor: '#0F1B2D',
|
||||
border: `1px solid ${canAfford ? '#1e3a5f' : '#7F1D1D'}`,
|
||||
border: `1px solid ${!waveStarted ? '#1e3a5f' : canAfford ? '#1e3a5f' : '#7F1D1D'}`,
|
||||
borderRadius: '6px',
|
||||
color: '#E2E8F0',
|
||||
fontFamily: 'VT323, monospace',
|
||||
@@ -224,7 +224,7 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
resize: 'none',
|
||||
outline: 'none',
|
||||
lineHeight: 1.4,
|
||||
opacity: gameReady ? 1 : 0.5,
|
||||
opacity: gameReady && waveStarted ? 1 : 0.4,
|
||||
transition: 'border-color 0.2s',
|
||||
}}
|
||||
/>
|
||||
@@ -232,23 +232,23 @@ function PuaPanel({ gameReady, hc }: { gameReady: boolean; hc: number }) {
|
||||
{/* 提交按钮 */}
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
disabled={loading || !text.trim() || !gameReady || !canAfford}
|
||||
disabled={loading || !text.trim() || !gameReady || !canAfford || !waveStarted}
|
||||
style={{
|
||||
width: '100%',
|
||||
padding: '8px',
|
||||
backgroundColor: loading ? '#1e3a5f' : canAfford ? '#7C3AED' : '#4C1D95',
|
||||
backgroundColor: loading ? '#1e3a5f' : !waveStarted ? '#1e3a5f' : canAfford ? '#7C3AED' : '#4C1D95',
|
||||
border: 'none',
|
||||
borderRadius: '6px',
|
||||
color: '#E2E8F0',
|
||||
fontFamily: "'Press Start 2P', monospace",
|
||||
fontSize: '8px',
|
||||
cursor: loading || !text.trim() || !gameReady || !canAfford ? 'not-allowed' : 'pointer',
|
||||
opacity: !text.trim() || !gameReady || !canAfford ? 0.45 : 1,
|
||||
cursor: loading || !text.trim() || !gameReady || !canAfford || !waveStarted ? 'not-allowed' : 'pointer',
|
||||
opacity: !text.trim() || !gameReady || !canAfford || !waveStarted ? 0.45 : 1,
|
||||
transition: 'all 0.15s',
|
||||
letterSpacing: '0.5px',
|
||||
}}
|
||||
>
|
||||
{loading ? '分析中...' : !canAfford ? 'HC不足' : `发起激励 -${cost}HC`}
|
||||
{loading ? '分析中...' : !waveStarted ? '战斗开始后可用' : !canAfford ? 'HC不足' : `发起激励 -${cost}HC`}
|
||||
</button>
|
||||
|
||||
{/* 当前结果 */}
|
||||
@@ -397,6 +397,7 @@ export default function GamePage() {
|
||||
const [hc, setHc] = useState(200)
|
||||
const [selectedTower, setSelectedTower] = useState<TowerType | null>(null)
|
||||
const [gameReady, setGameReady] = useState(false)
|
||||
const [waveStarted, setWaveStarted] = useState(false) // 第一波开始后才允许激励
|
||||
const selectedTowerRef = useRef<TowerType | null>(null)
|
||||
|
||||
const handleSelectTower = useCallback((type: TowerType) => {
|
||||
@@ -438,6 +439,13 @@ export default function GamePage() {
|
||||
if (mounted) { selectedTowerRef.current = null; setSelectedTower(null) }
|
||||
}
|
||||
;(window as any).__gameReady = () => { if (mounted) setGameReady(true) }
|
||||
// 轮询 __gameWaveStarted(Phaser 设置后通知 React)
|
||||
const checkWaveStarted = setInterval(() => {
|
||||
if ((window as any).__gameWaveStarted) {
|
||||
if (mounted) setWaveStarted(true)
|
||||
clearInterval(checkWaveStarted)
|
||||
}
|
||||
}, 200)
|
||||
}
|
||||
|
||||
gameRef.current = new Phaser.Game(config)
|
||||
@@ -450,7 +458,7 @@ export default function GamePage() {
|
||||
if (typeof window !== 'undefined') {
|
||||
;['__gameOnHCChange','__gameOnTowerDeselect','__gameSelectTower',
|
||||
'__gameReady','__gameDifficulty','__gamePuaBuff',
|
||||
'__gameGetHC','__gameSpendHC'].forEach(k => {
|
||||
'__gameGetHC','__gameSpendHC','__gameWaveStarted'].forEach(k => {
|
||||
delete (window as any)[k]
|
||||
})
|
||||
}
|
||||
@@ -470,7 +478,7 @@ export default function GamePage() {
|
||||
style={{ backgroundColor: '#0A1628' }}
|
||||
/>
|
||||
{/* PUA 激励台(右侧) */}
|
||||
<PuaPanel gameReady={gameReady} hc={hc} />
|
||||
<PuaPanel gameReady={gameReady} hc={hc} waveStarted={waveStarted} />
|
||||
</div>
|
||||
|
||||
{/* 底部塔选择面板 */}
|
||||
|
||||
Reference in New Issue
Block a user