Backup before cleanup

This commit is contained in:
Joan
2026-02-05 15:00:49 +01:00
parent e6747b1d05
commit 1b7ffd614d
60 changed files with 3013 additions and 460 deletions

View File

@@ -136,6 +136,7 @@ export interface GameEngineActions {
removePlayerFromLocation: (playerId: number) => void
addNPCToLocation: (npc: any) => void
removeNPCFromLocation: (enemyId: string) => void
updateStatusEffect: (effectName: string | any, remainingTicks: number) => void
}
export function useGameEngine(
@@ -243,7 +244,7 @@ export function useGameEngine(
stamina: gameState.player.stamina,
max_stamina: gameState.player.max_stamina,
inventory: gameState.inventory || [],
status_effects: []
status_effects: gameState.player.status_effects || []
})
setEquipment(gameState.equipment || {})
@@ -275,7 +276,7 @@ export function useGameEngine(
stamina: gameState.player.stamina,
max_stamina: gameState.player.max_stamina,
inventory: gameState.inventory || [],
status_effects: []
status_effects: gameState.player.status_effects || []
})
setLocation(locationRes.data)
@@ -458,6 +459,42 @@ export function useGameEngine(
setLoadedTabs(new Set())
}
const updateStatusEffect = useCallback((effectName: string | any, remainingTicks: number) => {
setPlayerState((prev: PlayerState | null) => {
if (!prev) return null
if (!prev) return null
const target = typeof effectName === 'object'
? (effectName.en || Object.values(effectName)[0])
: effectName
if (remainingTicks <= 0) {
return {
...prev,
status_effects: prev.status_effects.filter(e => {
const current = typeof e.effect_name === 'object'
? (e.effect_name.en || Object.values(e.effect_name)[0])
: e.effect_name
return current !== target
})
}
}
return {
...prev,
status_effects: prev.status_effects.map(e => {
const current = typeof e.effect_name === 'object'
? (e.effect_name.en || Object.values(e.effect_name)[0])
: e.effect_name
if (current === target) {
return { ...e, ticks_remaining: remainingTicks }
}
return e
})
}
})
}, [])
// State object
const state: GameEngineState = {
playerState,
@@ -720,8 +757,13 @@ export function useGameEngine(
const handleCombatAction = async (action: string) => {
try {
// setEnemyTurnMessage('Processing...') // Handled by Combat.tsx now
const response = await api.post('/api/game/combat/action', { action })
let payload: any = { action }
if (action.includes(':')) {
const [act, itemId] = action.split(':')
payload = { action: act, item_id: itemId }
}
const response = await api.post('/api/game/combat/action', payload)
return response.data
} catch (error: any) {
setMessage(error.response?.data?.detail || 'Combat action failed')
@@ -754,11 +796,19 @@ export function useGameEngine(
const handlePvPAction = async (action: string, _targetId: number) => {
try {
const response = await api.post('/api/game/pvp/action', { action })
let payload: any = { action }
if (action.includes(':')) {
const [act, itemId] = action.split(':')
payload = { action: act, item_id: itemId }
}
const response = await api.post('/api/game/pvp/action', payload)
setMessage(response.data.message || 'Action performed!')
await fetchGameData()
return response.data // Return data so caller can use it
} catch (error: any) {
setMessage(error.response?.data?.detail || 'PvP action failed')
throw error // Re-throw so caller knows it failed
}
}
@@ -1086,7 +1136,8 @@ export function useGameEngine(
}
return newSet
})
}
},
updateStatusEffect
}
// Polling fallback for PvP Combat reliability