156 lines
4.8 KiB
JavaScript
156 lines
4.8 KiB
JavaScript
const fs = require('fs')
|
|
const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/'
|
|
function patch(file, pairs) {
|
|
const p = base + file
|
|
let c = fs.readFileSync(p, 'utf8')
|
|
for (const [from, to] of pairs) {
|
|
if (!c.includes(from)) {
|
|
console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n'))
|
|
continue
|
|
}
|
|
c = c.replace(from, to)
|
|
}
|
|
fs.writeFileSync(p, c, 'utf8')
|
|
}
|
|
|
|
// ---- 翻车免罚:存档字段 + store 方法 + main 判定
|
|
patch('shared/petState.ts', [
|
|
[
|
|
` dailyGiftDay: string
|
|
inventory: Record<string, number>`,
|
|
` dailyGiftDay: string
|
|
accidentForgiven: boolean
|
|
inventory: Record<string, number>`
|
|
],
|
|
[
|
|
` dailyGiftDay: '',
|
|
inventory: { riceball: 2, oil: 2 },`,
|
|
` dailyGiftDay: '',
|
|
accidentForgiven: false,
|
|
inventory: { riceball: 2, oil: 2 },`
|
|
]
|
|
])
|
|
patch('main/stateStore.ts', [
|
|
[
|
|
" if (typeof save.sleeping !== 'boolean') save.sleeping = false",
|
|
" if (typeof save.sleeping !== 'boolean') save.sleeping = false\n if (typeof save.accidentForgiven !== 'boolean') save.accidentForgiven = false"
|
|
],
|
|
[
|
|
` buySpecial(itemId: string, price: number): ActionResult {`,
|
|
` forgiveAccident(): boolean {
|
|
if (this.save.accidentForgiven) return false
|
|
this.save.accidentForgiven = true
|
|
this.emit()
|
|
this.saveNow()
|
|
return true
|
|
}
|
|
|
|
buySpecial(itemId: string, price: number): ActionResult {`
|
|
]
|
|
])
|
|
patch('main/index.ts', [
|
|
[
|
|
` const acc = rollAccident()
|
|
if (acc) {
|
|
store.applyJobPenalty({`,
|
|
` const acc = rollAccident()
|
|
if (acc) {
|
|
if (store.forgiveAccident()) {
|
|
say(
|
|
'(身后传来老师的声音)「第一次翻车就不罚你了,回去把操作规范抄一遍。」……我记住了 (´-ω-)',
|
|
7000
|
|
)
|
|
return
|
|
}
|
|
store.applyJobPenalty({`
|
|
]
|
|
])
|
|
|
|
// ---- 自动购买 + 作息:配置字段
|
|
patch('shared/petState.ts', [
|
|
[
|
|
` /** Live2D 视线跟随鼠标 */
|
|
eyeFollow: boolean`,
|
|
` /** Live2D 视线跟随鼠标 */
|
|
eyeFollow: boolean
|
|
/** 饱食过低时自动买饭团 */
|
|
autoBuy: boolean
|
|
/** 作息:自动睡觉/起床 HH:MM */
|
|
sleepAt: string
|
|
wakeAt: string`
|
|
],
|
|
[
|
|
` eyeFollow: false,`,
|
|
` eyeFollow: false,
|
|
autoBuy: false,
|
|
sleepAt: '23:30',
|
|
wakeAt: '07:30',`
|
|
]
|
|
])
|
|
|
|
// ---- main:自动购买与作息检查(挂在 scheduleEvents 的 30 秒循环里)
|
|
patch('main/index.ts', [
|
|
[
|
|
` if (Date.now() < nextEventAt) return
|
|
const snap = store.snapshot()`,
|
|
` // 自动购买:饿了自己买饭团
|
|
const cfgNow = store.getConfig()
|
|
if (cfgNow.autoBuy && snapNow.stats.satiety < 25 && snapNow.money >= 12) {
|
|
const r = store.autoBuy('riceball')
|
|
if (r.ok) say('(自己翻出钱包)肚子好饿……我先买个饭团垫一下 (๑´ڡ\`๑)', 6000)
|
|
}
|
|
// 作息:到点自动睡觉 / 起床
|
|
const hhmm = new Date().toTimeString().slice(0, 5)
|
|
if (hhmm === cfgNow.sleepAt && !snapNow.sleeping && !snapNow.job) {
|
|
store.action('sleep')
|
|
say('(看了眼时间)到点了,我去睡啦,晚安~ (。-ω-)zzz', 6000)
|
|
} else if (hhmm === cfgNow.wakeAt && snapNow.sleeping) {
|
|
store.action('sleep')
|
|
say('(伸了个懒腰)早上好呀,我醒啦 ( ̄▽ ̄)', 6000)
|
|
}
|
|
if (Date.now() < nextEventAt) return
|
|
const snap = store.snapshot()`
|
|
],
|
|
[
|
|
` buySpecial(itemId: string, price: number): ActionResult {`,
|
|
` buySpecial(itemId: string, price: number): ActionResult {`
|
|
]
|
|
])
|
|
|
|
// store.autoBuy
|
|
patch('main/stateStore.ts', [
|
|
[
|
|
` claimDaily(): ActionResult {`,
|
|
` autoBuy(itemId: string): ActionResult {
|
|
const r = buy(this.save, itemId, 1)
|
|
if (r.ok) {
|
|
this.emit()
|
|
this.saveNow()
|
|
}
|
|
return r
|
|
}
|
|
|
|
claimDaily(): ActionResult {`
|
|
]
|
|
])
|
|
|
|
// ---- preload/api:工作区
|
|
patch('preload/index.ts', [
|
|
[
|
|
" buyDailySpecial: () => Promise<ActionResult>",
|
|
" buyDailySpecial: () => Promise<ActionResult>\n getWs: () => Promise<Array<{ name: string; size: number }>>\n delWs: (name: string) => Promise<Array<{ name: string; size: number }>>\n openWs: () => Promise<void>"
|
|
],
|
|
[
|
|
" buyDailySpecial: () => ipcRenderer.invoke('pet:daily:buy'),",
|
|
" buyDailySpecial: () => ipcRenderer.invoke('pet:daily:buy'),\n getWs: () => ipcRenderer.invoke('pet:ws:list'),\n delWs: (name: string) => ipcRenderer.invoke('pet:ws:del', name),\n openWs: () => ipcRenderer.invoke('pet:ws:open'),"
|
|
]
|
|
])
|
|
patch('renderer/src/api.ts', [
|
|
[
|
|
" buyDailySpecial: () => Promise<ActionResult>",
|
|
" buyDailySpecial: () => Promise<ActionResult>\n getWs: () => Promise<Array<{ name: string; size: number }>>\n delWs: (name: string) => Promise<Array<{ name: string; size: number }>>\n openWs: () => Promise<void>"
|
|
]
|
|
])
|
|
|
|
console.log('forgive/autobuy/ws patched')
|