const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' // ---- stateStore:applyChatEffect 支持氧化度 { const p = base + 'main/stateStore.ts' let c = fs.readFileSync(p, 'utf8') c = c.replace( " applyChatEffect(e: { mood?: number; bond?: number; electron?: number; satiety?: number }): void {", " applyChatEffect(e: {\n mood?: number\n bond?: number\n electron?: number\n satiety?: number\n oxidation?: number\n }): void {" ) c = c.replace( " if (e.satiety) s.satiety = Math.max(0, Math.min(100, s.satiety + e.satiety))", " if (e.satiety) s.satiety = Math.max(0, Math.min(100, s.satiety + e.satiety))\n if (e.oxidation) s.oxidation = Math.max(0, Math.min(100, s.oxidation + e.oxidation))" ) fs.writeFileSync(p, c, 'utf8') } // ---- main:事件系统 { const p = base + 'main/index.ts' let c = fs.readFileSync(p, 'utf8') const marker = `let nextSuggestAt = Date.now() + 180_000` const insert = `let activeEvent: { id: string; until: number } | null = null let nextEventAt = Date.now() + 120_000 let lastChargeBark = 0 function startWaterEvent(): void { if (activeEvent) return const id = String(Date.now()) activeEvent = { id, until: Date.now() + 10_000 } mainWindow?.webContents.send('pet:event', { id, type: 'water', until: activeEvent.until }) mainWindow?.webContents.send('pet:motion', 'shake') say('(惊慌)桌上怎么有水?!呜哇,快帮我擦干!(>﹏<)', 6000) setTimeout(() => { if (activeEvent?.id === id) { activeEvent = null store.applyChatEffect({ mood: -10, oxidation: 15 }) mainWindow?.webContents.send('pet:event', null) say('(低头看了看手臂)呜……还是沾到了,表面有点发灰 (´・ω・) ', 7000) } }, 10_000) } function scheduleEvents(): void { setInterval(() => { if (Date.now() < nextEventAt) return const snap = store.snapshot() // 遇水危机:醒着、没在打工时随机出现 if (!snap.sleeping && !snap.job && Math.random() < 0.35) { startWaterEvent() } // 正电荷过载:电子过低时提醒(10 分钟冷却) if (snap.stats.electron < 18 && Date.now() > lastChargeBark) { lastChargeBark = Date.now() + 10 * 60_000 mainWindow?.webContents.send('pet:motion', 'shake') say('(晃了晃)不行了……正电荷太多了,我要接地一下 (´-ω-)', 6000) } nextEventAt = Date.now() + 150_000 + Math.random() * 150_000 }, 30_000) } let nextSuggestAt = Date.now() + 180_000` if (!c.includes(marker)) { console.log('MISS main event anchor') } else { c = c.replace(marker, insert) } c = c.replace( ` ipcMain.on('pet:bark', (_e, kind: string) => {`, ` ipcMain.on('pet:event:resolve', (_e, id: string) => { if (activeEvent?.id === String(id)) { activeEvent = null store.applyChatEffect({ mood: 3 }) mainWindow?.webContents.send('pet:event', null) say('(拍拍胸口)呼……差一点,谢谢你~ ( ̄▽ ̄)', 5000) } }) ipcMain.on('pet:bark', (_e, kind: string) => {` ) c = c.replace( ` scheduleBarks() scheduleSuggestions()`, ` scheduleBarks() scheduleSuggestions() scheduleEvents()` ) fs.writeFileSync(p, c, 'utf8') } // ---- preload / api:事件与动作通道 for (const file of ['preload/index.ts', 'renderer/src/api.ts']) { const p = base + file let c = fs.readFileSync(p, 'utf8') c = c.replace( " onToast: (cb: (text: string) => void) => () => void", " onToast: (cb: (text: string) => void) => () => void\n onEvent: (cb: (e: { id: string; type: string; until: number } | null) => void) => () => void\n onMotion: (cb: (name: string) => void) => () => void\n eventResolve: (id: string) => void" ) if (file.startsWith('preload')) { c = c.replace( " onToast: (cb: (text: string) => void) => {", " onEvent: (cb: (e: { id: string; type: string; until: number } | null) => void) => {\n const l = (_ev: unknown, e: { id: string; type: string; until: number } | null): void => cb(e)\n ipcRenderer.on('pet:event', l)\n return () => ipcRenderer.removeListener('pet:event', l)\n },\n onMotion: (cb: (name: string) => void) => {\n const l = (_ev: unknown, name: string): void => cb(name)\n ipcRenderer.on('pet:motion', l)\n return () => ipcRenderer.removeListener('pet:motion', l)\n },\n eventResolve: (id: string) => ipcRenderer.send('pet:event:resolve', id),\n onToast: (cb: (text: string) => void) => {" ) } fs.writeFileSync(p, c, 'utf8') } console.log('events patched')