Pre-combat-rewrite: Backup current state before comprehensive combat frontend rewrite
This commit is contained in:
@@ -217,7 +217,7 @@ export function useGameEngine(
|
||||
}, [])
|
||||
|
||||
const addCombatLogEntry = useCallback((entry: CombatLogEntry) => {
|
||||
setCombatLog((prev: CombatLogEntry[]) => [entry, ...prev])
|
||||
setCombatLog((prev: CombatLogEntry[]) => [{ ...entry, id: entry.id || Date.now() + Math.random() }, ...prev])
|
||||
}, [])
|
||||
|
||||
// Fetch functions
|
||||
@@ -337,6 +337,7 @@ export function useGameEngine(
|
||||
pvpRes.data.pvp_combat.defender :
|
||||
pvpRes.data.pvp_combat.attacker
|
||||
setCombatLog([{
|
||||
id: 'pvp-combat-init',
|
||||
time: timeStr,
|
||||
message: `PvP combat with ${opponent.username} (Lv. ${opponent.level})!`,
|
||||
isPlayer: true
|
||||
@@ -351,6 +352,7 @@ export function useGameEngine(
|
||||
const now = new Date()
|
||||
const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
||||
setCombatLog([{
|
||||
id: 'combat-in-progress',
|
||||
time: timeStr,
|
||||
message: 'Combat in progress...',
|
||||
isPlayer: true
|
||||
@@ -402,8 +404,9 @@ export function useGameEngine(
|
||||
const now = new Date()
|
||||
const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
||||
setCombatLog([{
|
||||
id: Date.now() + Math.random(),
|
||||
time: timeStr,
|
||||
message: `⚠️ ${encounter.combat.npc_name} ambushes you!`,
|
||||
message: { type: 'combat_start', data: { npc_name: encounter.combat.npc_name } },
|
||||
isPlayer: false
|
||||
}])
|
||||
|
||||
@@ -503,10 +506,23 @@ export function useGameEngine(
|
||||
const now = new Date()
|
||||
const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
||||
const messages = data.message.split('\n').filter((m: string) => m.trim())
|
||||
const newEntries = messages.map((msg: string) => ({
|
||||
const parsedMessages = messages.map((msg: string) => {
|
||||
try {
|
||||
if (msg.trim().startsWith('{')) {
|
||||
const parsed = JSON.parse(msg)
|
||||
if (parsed.type && parsed.data) return parsed
|
||||
}
|
||||
} catch (e) { }
|
||||
return msg
|
||||
})
|
||||
|
||||
const newEntries = parsedMessages.map((msg: any) => ({
|
||||
id: `item-use-${Date.now()}-${Math.random()}`,
|
||||
time: timeStr,
|
||||
message: msg,
|
||||
isPlayer: !msg.includes('attacks')
|
||||
isPlayer: typeof msg === 'object'
|
||||
? msg.type !== 'enemy_attack' && msg.type !== 'flee_fail'
|
||||
: !msg.includes('attacks') && !msg.includes('hits')
|
||||
}))
|
||||
setCombatLog((prev: any) => [...newEntries, ...prev])
|
||||
|
||||
@@ -688,8 +704,9 @@ export function useGameEngine(
|
||||
const now = new Date()
|
||||
const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
||||
setCombatLog([{
|
||||
id: Date.now() + Math.random(),
|
||||
time: timeStr,
|
||||
message: `Combat started with ${response.data.combat.npc_name}!`,
|
||||
message: { type: 'combat_start', data: { npc_name: response.data.combat.npc_name } },
|
||||
isPlayer: true
|
||||
}])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user