dsh-fish-home 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +5 -4
- package/lib/draw-summary.js +49 -0
- package/lib/host.js +280 -111
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## 0.1.4 — 2026-11-22
|
|
2
|
+
|
|
3
|
+
- 抽卡工具和房间内的抽卡按钮支持百连、千连,千连按一百次十连的价格一次结算,保底连续计算。
|
|
4
|
+
- 网页玩家抽卡的 DSH 通知和抽卡工具回执统一压缩。新卡和升级按品种合并,珠光重复卡只报张数及分解获得的星尘、星辉。
|
|
5
|
+
- 房间内百连和千连增加费用确认;大批量结果只展示五星及以上,抽卡结果页合并同卡升级,满品质的重复卡只显示汇总。
|
|
6
|
+
- 电脑屏幕那一块改成可以打开「电脑记录」页面,不再只是切换亮灭。每条记录显示视频标题、BV 号、抓取时间和本地报告路径;标题和 BV 号都可以点击,直接跳到对应的 B 站页面。没有 B 站记录时恢复成普通屏幕,不会残留上一条视频的封面。
|
|
7
|
+
- 画册单张详情支持点击放大,`Esc` 或点背景关闭,同时显示本地图片路径。
|
|
8
|
+
- 修正旧交互层优先把电脑屏幕识别成「屏幕开关」的问题。
|
|
9
|
+
|
|
10
|
+
## 0.1.3 — 2026-11-21
|
|
11
|
+
|
|
12
|
+
- 收菜、出售及原地补种可一单完成;卖本批新收的菜或鱼不用先查数量。补种期间给这单留出原地和种子,代理继续照料其它地块。
|
|
13
|
+
- 修复普通聊天未统一计入本地心情和陪伴的问题;提示可区分插件心情与本地兜底,并说明六项数值的来源。
|
|
14
|
+
- 所有作物均支持巨型,菜田按 3×3 判定,花田每朵花成熟时单独判定。普通播种可一单种满并按实际缺口补买;巨型这一步失败不会撤回已完成的鱼塘或农活步骤。
|
|
15
|
+
- 巨型作物按同品种当日售价的 1.8 倍出售,菜田按九份普通菜计价,花田按一份普通花计价。DSH 可查单价,成熟提醒与收获回执按实际收成计数,出售显示到账与余量,不混扣普通收成。
|
|
16
|
+
- 农活查询直接显示总空位,收获失败区分空田、没种该作物和未成熟;同批唯一品种可自动接续放苗。超过本轮写入限制仍可查询,工具不会被卸载。
|
|
17
|
+
- `fish_home status` 一次查询实际位置、活动、身体感受和有效心情;留存未主动推送的近期场景体验。已送达的场景摘要不会在状态和可选的会话现场中再出现。
|
|
18
|
+
- 稍累时,等当前活动结束后会找地方休息;农活结束、手需要清洗时会去洗手。料理动作保持原样,整理厨房不会恢复个人清爽。
|
|
19
|
+
- 修复右上角退出图标的悬停提示空白。
|
|
20
|
+
- 重新生成可独立启动的纯净房间包;通过原更新脚本替换程序,保留已有存档和自定义配置。
|
|
21
|
+
|
|
1
22
|
## 0.1.2 — 2026-11-21
|
|
2
23
|
|
|
3
24
|
- 农活工具改成 `batch` / `list` 两个入口:同一轮可以一次提交多种作物的出售、买种和播种,重复请求复用原回执,每轮最多执行两批,避免模型逐格、逐品种循环调用。
|
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
### 抽卡(卡册)
|
|
45
45
|
|
|
46
46
|
- 三个卡池:**海边常驻**(顶 5★)、**鱼鱼表情**(顶 SP)、**万圣节**
|
|
47
|
-
-
|
|
47
|
+
- 支持单抽、十连和百连。新卡和品质升级进卡册,珠光重复卡合并结算为星尘或星辉。
|
|
48
48
|
|
|
49
49
|
### 菜谱
|
|
50
50
|
|
|
@@ -75,10 +75,11 @@
|
|
|
75
75
|
|
|
76
76
|
- **菜谱**。fish_home_recipe 默认查今天的菜名。可按菜名或 ID 查询一道菜,打开「学菜」后才能读食材和步骤。
|
|
77
77
|
- **天气**。fish_home 可查庭院当前天气(weather)或设置地区的三天预报(forecast)。在房间设置里开启当地天气同步后,庭院跟随该地区。手动点晴日、听雨或落雪会切回手动天气,仍能单独查当地预报。
|
|
78
|
-
- **卡册**。fish_home_card 按卡名或 ID
|
|
78
|
+
- **卡册**。fish_home_card 按卡名或 ID 一次看一张图,抽卡和兑换只返回文字。百连用 `count: 100`,千连用 `count: 1000`,需要 0.1.4 房间本体;十连、百连和千连的回执会合并珠光重复卡,只汇报张数与分解所得。fish_home_draw 加上 op=exchange 可换金币、星辉或指定卡。金币兑换数量填消耗的星尘,星辉兑换数量填要得到的星辉。
|
|
79
79
|
|
|
80
80
|
- **田地布局**。fish_home_farm 的 list 使用 scope=layout 查看菜畦按 3×3 分组的作物。加 bed=0、1 或 2 可看该菜畦每个格子。
|
|
81
|
-
-
|
|
81
|
+
- **批量收种**。用一次 `batch` 交整单:`actions` 只填 `replant` 会收获并原地补种(可用 `item` 指定品种);要顺手卖菜就按 `harvest` → `sell` → `replant` 排。`sell` 省略品种和数量时只卖本批刚入包的作物或成鱼。默认用背包里的种子,允许花金币买种子才填 `buyMissing: true`。回执会写明已完成的步骤和余额。
|
|
82
|
+
- **种满与巨型候选**。普通 `plant` 用 `fill: true` 自动算空位;菜田用 `layout: "giant"` 自动找 3×3,九格同种全熟时有一次 15% 的机会。花田用普通播种,每朵花成熟时独立有 15% 的机会变异。只有获准花金币才加 `buyMissing: true`,按实际可种和库存补买;允许碎地备用才加 `fallback: "normal"`。收、卖、播种可以仍在一批内完成。
|
|
82
83
|
- **集市**。商店里的「集市行情」和 fish_home 的 market、price 共用售价。每天北京时间零点更新,明日预告也可提前查询。price 可按 kind 或 item 筛选。
|
|
83
84
|
|
|
84
85
|
## 画架
|
|
@@ -138,7 +139,7 @@ Windows 就是 `C:\Users\<你>\.dsh\fish-home-room\`,打开里面要能直接
|
|
|
138
139
|
|
|
139
140
|
内置房间使用原版蓝色大肥鱼模型和配套动作。
|
|
140
141
|
|
|
141
|
-
回忆簿可在 DSH 设置里的「上下文与回忆」填写纯文本记忆路径、日记路径和相伴起始日;逐轮 runtime-context
|
|
142
|
+
回忆簿可在 DSH 设置里的「上下文与回忆」填写纯文本记忆路径、日记路径和相伴起始日;逐轮 runtime-context 默认关闭。`fish_home status` 可一次读到所在位置、活动、身体感受和心情;重要天气变化、成熟与生活里程碑、消费和场景事件仍分别控制是否通知绑定会话。模型制作:水原镜,MMD 转换与绑定:耶栗Yaki。模型的署名和原始使用规约随房间本体一起下发(房间目录 `dist/models/dayu-mmd/` 里的 `使用规约.txt` 和 `MODEL-CREDITS.md`),请一并保留。
|
|
142
143
|
|
|
143
144
|
卡包大部分立绘来源于 B站 UP 主 **ZipZipPipe**,版权归原作者,随游戏一起分发、未作修改。
|
|
144
145
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Fallback for rooms predating the draw summary in the response.
|
|
2
|
+
// One entry per changed card; cards already at pearl only contribute to totals.
|
|
3
|
+
const rarityRank = {'3★':0,'4★':1,'5★':2,SP:3,hidden:4};
|
|
4
|
+
const finishNames = ['普通','银箔','镀金','珠光'];
|
|
5
|
+
|
|
6
|
+
export function summarizeDraw(results = []) {
|
|
7
|
+
const changes = new Map();
|
|
8
|
+
const repeats = {count:0, converted:0, dust:0, starlight:0};
|
|
9
|
+
for (const row of results) {
|
|
10
|
+
if (!row.first) repeats.count++;
|
|
11
|
+
if (row.converted) {
|
|
12
|
+
repeats.converted++;
|
|
13
|
+
repeats.dust += row.dust || 0;
|
|
14
|
+
repeats.starlight += row.starlight || 0;
|
|
15
|
+
} else if (row.id && (row.first || row.upgrade)) {
|
|
16
|
+
const previous = changes.get(row.id);
|
|
17
|
+
changes.set(row.id,{...row,first:!!(previous?.first || row.first),upgraded:!!(previous?.upgraded || row.upgrade)});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {changes:[...changes.values()].sort((a,b)=>(rarityRank[b.rarity]??0)-(rarityRank[a.rarity]??0)||Number(b.first)-Number(a.first)),repeats};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function repeatDrawText({count,converted,dust,starlight}) {
|
|
24
|
+
if (!count) return '';
|
|
25
|
+
const intro = `重复 ${count} 张`;
|
|
26
|
+
if (!converted) return intro+'。';
|
|
27
|
+
const prefix = converted===count ? intro : `${intro},其中 ${converted} 张已分解`;
|
|
28
|
+
const rewards = [dust>0 && `${dust} 星尘`,starlight>0 && `${starlight} 星辉`].filter(Boolean);
|
|
29
|
+
return rewards.length ? `${prefix},${converted===count?'分解获得':'获得'} ${rewards.join('、')}。` :
|
|
30
|
+
`${prefix}${converted===count?',已全部分解':''}。`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function drawSummaryText(results, catalog = []) {
|
|
34
|
+
const {changes,repeats} = summarizeDraw(results);
|
|
35
|
+
const first = changes.filter(row=>row.first).length;
|
|
36
|
+
const upgraded = changes.length-first;
|
|
37
|
+
const cards = new Map(catalog.map(card=>[card.id,card]));
|
|
38
|
+
const names = changes.slice(0,4).map(row=>{
|
|
39
|
+
const card = row.card || cards.get(row.id);
|
|
40
|
+
const title = [card?.title || row.title || row.id,card?.subtitle].filter(Boolean).join('·').slice(0,28);
|
|
41
|
+
const finish = finishNames[row.finish];
|
|
42
|
+
const quality = (row.upgraded || !row.first) && finish ? '升至'+finish : '';
|
|
43
|
+
const hidden = row.rarity==='hidden' && row.starlight>0 ? `附赠 ${row.starlight} 星辉` : '';
|
|
44
|
+
return [title,quality,hidden].filter(Boolean).join('·');
|
|
45
|
+
});
|
|
46
|
+
const changesText = changes.length ?
|
|
47
|
+
`${[first&&`新卡 ${first} 张`,upgraded&&`升级 ${upgraded} 张`].filter(Boolean).join('、')}:${names.join('、')}${changes.length>names.length?'等':''}。` : '';
|
|
48
|
+
return repeatDrawText(repeats)+changesText;
|
|
49
|
+
}
|
package/lib/host.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {drawSummaryText} from './draw-summary.js';
|
|
1
2
|
// 鱼鱼窝 · 宿主半边
|
|
2
3
|
//
|
|
3
4
|
// 它干的事只有一件:让「大肥鱼的小日子」那个房间和 DSH 里的会话说上话。
|
|
@@ -835,7 +836,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
835
836
|
if (快 && 快.pond) 家当.push('池塘 ' + (Number(快.pond.条数) || 0) + '/' + (Number(快.pond.容量) || 8))
|
|
836
837
|
if (快 && 快.卡册) 家当.push('卡册 ' + (Number(快.卡册.已集) || 0) + '/' + (Number(快.卡册.总) || 0))
|
|
837
838
|
const 攒 = 家当.length ? (现场 ? '' : '上次同步:') + 家当.join(' · ') + '。' : ''
|
|
838
|
-
const 最近 = 生活事件.filter(e => e.sessionId === 目标会话() && Date.now() - e.at < 5 * 60000 && ['milestone','farm'].includes(e.kind)).slice(-2)
|
|
839
|
+
const 最近 = 生活事件.filter(e => e.sessionId === 目标会话() && Date.now() - e.at < 5 * 60000 && !e.notified && ['milestone','farm'].includes(e.kind)).slice(-2)
|
|
839
840
|
.map((x) => String((x && x.text) || '').trim())
|
|
840
841
|
.filter(Boolean)
|
|
841
842
|
.map((t) => (t.length > 24 ? t.slice(0, 24) + '…' : t))
|
|
@@ -850,10 +851,12 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
850
851
|
function 状态通知文本(previous, next, oldWeather = '') {
|
|
851
852
|
const lines = []
|
|
852
853
|
const after = next?.snapshot || {}
|
|
853
|
-
const newWeather = String(after.weather ||
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
854
|
+
const newWeather = String(after.weather || '')
|
|
855
|
+
const labels = { clear: '晴天', cloudy: '阴天', rain: '下雨', snow: '下雪', storm: '雷雨' }
|
|
856
|
+
const affectsOutdoors = value => ['rain','snow','storm'].includes(value);
|
|
857
|
+
if (Object.hasOwn(labels,oldWeather) && Object.hasOwn(labels,newWeather) && oldWeather !== newWeather &&
|
|
858
|
+
(affectsOutdoors(oldWeather)||affectsOutdoors(newWeather))) {
|
|
859
|
+
lines.push(affectsOutdoors(newWeather) ? '窗外天气变了:'+labels[newWeather]+'。' : '窗外的雨雪停了。');
|
|
857
860
|
}
|
|
858
861
|
return lines
|
|
859
862
|
}
|
|
@@ -896,6 +899,33 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
896
899
|
return '当前安排:'+[地点名字[activity?.room],label].filter(Boolean).join(' · ')+'。';
|
|
897
900
|
}
|
|
898
901
|
|
|
902
|
+
function 身体简报(live) {
|
|
903
|
+
const lines=[活动简报(live.activity,live.observation,live.presence)];
|
|
904
|
+
const observation=live.observation;
|
|
905
|
+
const fresh = value => Number.isFinite(value?.at)&&Date.now()-value.at<36000;
|
|
906
|
+
if (lines[0]==='活动:闲着。') lines[0]='当前安排:闲着。';
|
|
907
|
+
if (fresh(live.presence) && live.presence.visible && observation?.activityId===live.activity?.id &&
|
|
908
|
+
['moving','blocked'].includes(observation?.phase) && fresh(observation)) {
|
|
909
|
+
const dest=地点名字[live.activity?.room];
|
|
910
|
+
if (dest) lines.push((observation.phase==='moving'?'正在去':'暂时没走到')+dest+',安排是'+String(live.activity.label||'').slice(0,30)+'。');
|
|
911
|
+
}
|
|
912
|
+
const feelings=[];
|
|
913
|
+
const {energy,satiety,hygiene}=live.needs||{};
|
|
914
|
+
if (Number.isFinite(energy)&&energy<55) feelings.push(energy<35?'很累':'有点累');
|
|
915
|
+
if (Number.isFinite(satiety)&&satiety<54) feelings.push(satiety<40?'饿了':'有点饿');
|
|
916
|
+
if (Number.isFinite(hygiene)&&hygiene<65) feelings.push(hygiene<35?'想洗漱':'想洗洗手');
|
|
917
|
+
if (Number.isFinite(energy)&&Number.isFinite(satiety)&&Number.isFinite(hygiene)&&!feelings.length) feelings.push('状态还好');
|
|
918
|
+
if (Number.isFinite(live.mood)) {
|
|
919
|
+
const source=live.mood来源==='feiyu-mood'?'(鱼的心情)':live.mood来源==='local'?'(本地)':'';
|
|
920
|
+
feelings.push('心情 '+Math.round(live.mood)+'/100'+source);
|
|
921
|
+
}
|
|
922
|
+
if (feelings.length) lines.push('身体:'+feelings.join(',')+'。');
|
|
923
|
+
const scene=最近场景?.sid===目标会话() && Date.now()-最近场景.at<SCENE_TTL_MS ? 最近场景.text : '';
|
|
924
|
+
const recent=scene || live.recentBodyActivity;
|
|
925
|
+
if (recent) lines.push('刚才:'+String(recent).trim().slice(0,100).replace(/[。!?]+$/,'')+'。');
|
|
926
|
+
return lines.join('');
|
|
927
|
+
}
|
|
928
|
+
|
|
899
929
|
// 房间时间 + 画架工具,都挂在绑定的那间会话上(跟心情插件一样按 agent 实例记)
|
|
900
930
|
const 上下文挂着 = new Map() // scoped registrations and their disposers
|
|
901
931
|
function 画工具() {
|
|
@@ -986,12 +1016,12 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
986
1016
|
function 鱼鱼窝工具() {
|
|
987
1017
|
return {
|
|
988
1018
|
name: 'fish_home',
|
|
989
|
-
description: '鱼鱼窝的生活数据。what 的可选范围:status
|
|
1019
|
+
description: '鱼鱼窝的生活数据。what 的可选范围:status(实际地点、身体感受、心情和一条近期身体经历)、farm(田里种的、还有多久熟、剩什么种子和收成)、pond(池塘几条鱼、什么鱼、多久能捞)、cards(卡册集了多少、还差哪几张、哪几张还没到珠光)、pity(卡池保底和下一抽概率,不花金币)、price(完整价目,可按类别 kind 或品名 item 筛选)、market(今天和明天的行情摘要)、wallet(正式存档的当前金币、星尘和星辉)、today(今天做过什么)、weather(庭院当前天气)、forecast(设置地区的三天预报)、all(全看一遍)。',
|
|
990
1020
|
parameters: {
|
|
991
1021
|
type: 'object',
|
|
992
1022
|
properties: {
|
|
993
1023
|
what: { type: 'string', enum: ['status','farm','pond','cards','pity','wallet','price','market','today','weather','forecast','all'], description:'要看哪一块' },
|
|
994
|
-
kind: {type:'string',enum:['crop','flower','fish','all'],description:'
|
|
1024
|
+
kind: {type:'string',enum:['crop','flower','fish','giant','all'],description:'价目类别。giant 查巨型作物,省略时列出普通商品。'},
|
|
995
1025
|
item: {type:'string',description:'价目查询可填一个品名或 ID'},
|
|
996
1026
|
},
|
|
997
1027
|
required: ['what'],
|
|
@@ -1026,6 +1056,14 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1026
1056
|
}
|
|
1027
1057
|
if (要==='market'||要==='price') {
|
|
1028
1058
|
try {
|
|
1059
|
+
if(args.kind==='giant'){
|
|
1060
|
+
const {market,giantItems=[]}=await roomRequest('/api/farm',undefined,8000,exec?.signal);
|
|
1061
|
+
const query=String(args.item||'').trim().toLowerCase();
|
|
1062
|
+
const matches=giantItems.filter(item=>!query||item.id.includes(query)||item.name.toLowerCase().includes(query));
|
|
1063
|
+
if(!matches.length)return {ok:false,说:'没有匹配的巨型作物。'};
|
|
1064
|
+
const lines=matches.map(item=>`${item.name} · 今日售 ${item.sellPrice} / 明日售 ${item.tomorrowSellPrice} 金币`);
|
|
1065
|
+
return {ok:true,说:[`巨型作物单份售价(${market.today.date})`,...lines].join('\n')};
|
|
1066
|
+
}
|
|
1029
1067
|
const {market}=await roomRequest('/api/farm/market',undefined,8000,exec?.signal);
|
|
1030
1068
|
const lines=[market.today.date+' · '+market.today.note,market.tomorrow.date+' 预告 · '+market.tomorrow.note];
|
|
1031
1069
|
if (要==='market'&&!args.item&&!args.kind) return {ok:true,说:lines.join('\n')};
|
|
@@ -1069,36 +1107,33 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1069
1107
|
}
|
|
1070
1108
|
if (要 === 'status' || 要 === 'all') {
|
|
1071
1109
|
try {
|
|
1072
|
-
const live = await roomRequest('/api/life/activity', undefined, 5000, exec?.signal);
|
|
1073
|
-
const 说 =
|
|
1110
|
+
const live = await roomRequest('/api/life/activity?status=1', undefined, 5000, exec?.signal);
|
|
1111
|
+
const 说 = 身体简报(live);
|
|
1074
1112
|
if (要 === 'status') return {ok:true, 说};
|
|
1075
1113
|
段.push(说);
|
|
1076
1114
|
} catch (error) {
|
|
1077
1115
|
if (要 === 'status') return {ok:false, 说: '暂时读不到鱼鱼窝的当前状态。'};
|
|
1078
1116
|
}
|
|
1079
1117
|
}
|
|
1118
|
+
if (要 === 'farm' || 要 === 'all') {
|
|
1119
|
+
try {
|
|
1120
|
+
const data = await roomRequest('/api/farm', undefined, 8000, exec?.signal);
|
|
1121
|
+
const 说 = farmSummary(data, 'farm');
|
|
1122
|
+
if (要 === 'farm') return {ok:true,说};
|
|
1123
|
+
段.push(说);
|
|
1124
|
+
} catch (error) {
|
|
1125
|
+
const 说 = '暂时读不到当前田地:' + error.message;
|
|
1126
|
+
if (要 === 'farm') return {ok:false,说};
|
|
1127
|
+
段.push(说);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1080
1130
|
const 快 = 最近状态 && 最近状态.snapshot
|
|
1081
1131
|
if (!快 && 段.length) return {ok:true, 说:段.join('\n\n')};
|
|
1082
1132
|
if (!快) return { ok: false, 说: '房间那边还没报上来,等一下再问。' }
|
|
1083
|
-
const 田 = 快.farm || null
|
|
1084
1133
|
const 池 = 快.pond || null
|
|
1085
1134
|
const 册 = 快.卡册 || null
|
|
1086
1135
|
|
|
1087
1136
|
if (要 === 'all')段.push('行情可用 fish_home 的 market 或 price 单独查看。');
|
|
1088
|
-
if ((要 === 'farm' || 要 === 'all') && 田) {
|
|
1089
|
-
const 行 = []
|
|
1090
|
-
行.push(`田里 ${田.planted} 块种着,${田.空地} 块空着`)
|
|
1091
|
-
for (const 批 of 田.作物 || []) {
|
|
1092
|
-
const 名 = String(批.cropId || '')
|
|
1093
|
-
行.push(` ${名} ${批.块数} 块` + (批.熟 ? `,熟了 ${批.熟} 块` : `,最快还要 ${批.最快分钟} 分钟`))
|
|
1094
|
-
}
|
|
1095
|
-
const 种 = Object.entries(田.种子 || {}).map(([k, v]) => `${k}×${v}`).join('、')
|
|
1096
|
-
const 收 = Object.entries(田.收成 || {}).map(([k, v]) => `${k}×${v}`).join('、')
|
|
1097
|
-
行.push(`背包种子:${种 || '空'};收成:${收 || '空'}`)
|
|
1098
|
-
行.push(田.autoCare ? '开启了自动照料;启用自动播种时,空地会用背包种子补种。' : '自动照料关闭。')
|
|
1099
|
-
if (Number(田.ready)) 行.push('可用 fish_home_farm 一次收获。item 可指定品种。');
|
|
1100
|
-
段.push(行.join('\n'))
|
|
1101
|
-
}
|
|
1102
1137
|
if ((要 === 'pond' || 要 === 'all') && 池) {
|
|
1103
1138
|
const 行 = [`池塘 ${池.条数}/${池.容量} 条`]
|
|
1104
1139
|
for (const 鱼 of 池.鱼 || []) 行.push(` ${鱼.species}:` + (鱼.ready ? '能捞了' : `还要 ${鱼.剩余分钟} 分钟`))
|
|
@@ -1159,7 +1194,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1159
1194
|
properties: {
|
|
1160
1195
|
op: {type:'string', enum:['draw','exchange'], description:'操作,默认 draw'},
|
|
1161
1196
|
pool: {type:'string', enum:['standard','sp','encore'], description:'抽卡池:海边常驻、鱼鱼表情、万圣节'},
|
|
1162
|
-
count: {type:'
|
|
1197
|
+
count: {type:'integer', enum:[1,10,100,1000], description:'单抽、十连、百连或千连'},
|
|
1163
1198
|
kind: {type:'string', enum:['coins','starlight','card'], description:'星尘换金币、星尘换星辉、兑换指定卡'},
|
|
1164
1199
|
quantity: {type:'integer', minimum:1, description:'coins 填要花的星尘,starlight 填要换到的星辉,card 每次一张'},
|
|
1165
1200
|
item: {type:'string', description:'换卡时填卡名或卡 ID'},
|
|
@@ -1179,34 +1214,20 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1179
1214
|
if (op === 'exchange') return 换卡或货币(args, exec?.signal);
|
|
1180
1215
|
if (op !== 'draw') return {ok:false, 说:'可用操作是 draw(抽卡)和 exchange(兑换)。'};
|
|
1181
1216
|
if (!['standard','sp','encore'].includes(池)) return {ok:false, 说:'无效的卡池。请选择 standard(海边常驻)、sp(鱼鱼表情)或 encore(万圣节)。'};
|
|
1182
|
-
if (![1,10].includes(次)) return {ok:false, 说:'抽卡数量只能是 1 或
|
|
1217
|
+
if (![1,10,100,1000].includes(次)) return {ok:false, 说:'抽卡数量只能是 1、10、100 或 1000。'};
|
|
1183
1218
|
try {
|
|
1184
1219
|
const 结果 = await roomRequest('/api/cards/draw', {pool:池, count:次, requestId:randomUUID(), actor:'dayu'}, 15000, exec?.signal)
|
|
1185
|
-
const
|
|
1186
|
-
const
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
let detail;
|
|
1194
|
-
if(!r.id&&r.converted)detail='SP 已集齐 · 分解获得 '+reward;
|
|
1195
|
-
else if(r.first)detail='首次收藏'+(finish?' · '+finish:'');
|
|
1196
|
-
else if(r.converted)detail='已拥有 · '+(finish||'满品质')+'重复分解'+(reward?',获得 '+reward:'');
|
|
1197
|
-
else if(r.upgrade)detail='已拥有 · 升至'+finish;
|
|
1198
|
-
else detail='已拥有';
|
|
1199
|
-
return 名 + (星 ? '('+星+')' : '') + ' · '+detail
|
|
1200
|
-
}).filter(Boolean)
|
|
1201
|
-
const 余 = 结果 && Number.isFinite(Number(结果.coins)) ? `,余额 ${结果.coins}` : ''
|
|
1202
|
-
const 当前池 = 结果.cards?.pools?.find(p => p.id === 池)
|
|
1203
|
-
const odds = 当前池 ? cardOdds(当前池) : null
|
|
1204
|
-
const wallet = 结果.cards ? `,星尘 ${结果.cards.dust},星辉 ${结果.cards.starlight}` : ''
|
|
1205
|
-
const collection=结果.ok&&结果.cards?.owned&&结果.cards?.catalog
|
|
1206
|
-
? '卡册 '+Object.keys(结果.cards.owned).length+'/'+结果.cards.catalog.length+',本次新收藏 '+抽到.filter(r=>r.first).length+' 张。' : '';
|
|
1207
|
-
const 说 = [单 || 结果.error, (名单.length ? '抽到:' + 名单.join('、') : '') + 余 + wallet, collection, odds && formatOdds(odds)].filter(Boolean).join('\n')
|
|
1220
|
+
const cards = 结果.cards;
|
|
1221
|
+
const summary = 结果.summary ?? drawSummaryText(结果.results, cards?.catalog);
|
|
1222
|
+
const 当前池 = cards?.pools?.find(p => p.id === 池);
|
|
1223
|
+
const odds = 当前池 ? cardOdds(当前池) : null;
|
|
1224
|
+
const cost = Number.isFinite(结果.cost) ? `,花费 ${结果.cost} 金币` : '';
|
|
1225
|
+
const wallet = cards ? `余额 ${结果.coins} 金币、${cards.dust} 星尘、${cards.starlight} 星辉。` : '';
|
|
1226
|
+
const 说 = [`抽了 ${次} 张${cost}。${summary}`, wallet,
|
|
1227
|
+
odds && `距${当前池.top}保底 ${odds.pity.top} 抽,距四星及以上保底 ${odds.pity.fourOrAbove} 抽。`].filter(Boolean).join('\n');
|
|
1208
1228
|
return { ok: Boolean(结果.ok), 说: 说.trim() || '抽卡没成,房间那边没回话。', ...(odds ? {pity: odds.pity, rates: odds.rates} : {}) }
|
|
1209
1229
|
} catch (error) {
|
|
1230
|
+
if (次>=100 && error?.message==='无效的卡池或抽卡数量。') return {ok:false,说:`房间还不支持${次===1000?'千连':'百连'},请把鱼鱼窝房间更新到 0.1.4。`};
|
|
1210
1231
|
return { ok: false, 说: '抽卡没成:' + String((error && error.message) || error) }
|
|
1211
1232
|
}
|
|
1212
1233
|
},
|
|
@@ -1341,8 +1362,11 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1341
1362
|
redirect: 'error', signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
|
|
1342
1363
|
...(params === undefined ? {} : { method: 'POST', headers: {'content-type':'application/json'}, body: JSON.stringify(params) }),
|
|
1343
1364
|
});
|
|
1365
|
+
if (route==='/api/farm/plant-giant-batch' && response.status===404) {
|
|
1366
|
+
throw new Error('当前房间还没更新到支持整块 3×3 播种的版本;这一步没有买种或播种。');
|
|
1367
|
+
}
|
|
1344
1368
|
const result = await response.json();
|
|
1345
|
-
if (result.ok === false || !response.ok) throw Object.assign(new Error(result.say || result.说 || result.error || '鱼鱼窝没有完成这次操作。'),{code:result.code});
|
|
1369
|
+
if (result.ok === false || !response.ok) throw Object.assign(new Error(result.say || result.说 || result.error || '鱼鱼窝没有完成这次操作。'),{code:result.code,result});
|
|
1346
1370
|
return result;
|
|
1347
1371
|
}
|
|
1348
1372
|
|
|
@@ -1416,11 +1440,23 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1416
1440
|
return Object.entries(items).map(([id,n])=>id+'×'+n).join('、')||'空';
|
|
1417
1441
|
}
|
|
1418
1442
|
|
|
1443
|
+
function saleReceipt(result) {
|
|
1444
|
+
const {id,name,n,unitPrice} = result.卖出;
|
|
1445
|
+
const summary = `卖了 ${n} 份${name},入账 ${result.得了} 金币。`;
|
|
1446
|
+
if (!id.startsWith('giant_')) return summary;
|
|
1447
|
+
const remaining = result.wallet?.giants?.[id.slice('giant_'.length)] || 0;
|
|
1448
|
+
return `${summary} 每份 ${unitPrice} 金币,背包还剩 ${remaining} 份${name}。`;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1419
1451
|
function farmSummary(data,scope='all') {
|
|
1420
1452
|
const farm=data.farm;
|
|
1421
1453
|
const lines=[];
|
|
1422
1454
|
if(scope!=='pond') {
|
|
1423
1455
|
const groups=new Map();
|
|
1456
|
+
const giants=farm.giants || [];
|
|
1457
|
+
const giantNames=new Map((data.giantItems || []).map(item=>[item.cropId,item.name]));
|
|
1458
|
+
const giantName=cropId=>giantNames.get(cropId) || `巨型${cropId}`;
|
|
1459
|
+
const occupiedByGiants=new Set(giants.flatMap(item=>item.plotIds));
|
|
1424
1460
|
let emptyVegetables=0,emptyFlowers=0;
|
|
1425
1461
|
for(const plot of farm.plots){
|
|
1426
1462
|
if(!plot.cropId){
|
|
@@ -1428,14 +1464,22 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1428
1464
|
else emptyVegetables++;
|
|
1429
1465
|
continue;
|
|
1430
1466
|
}
|
|
1467
|
+
if (occupiedByGiants.has(plot.id)) continue;
|
|
1431
1468
|
const group=groups.get(plot.cropId)||{growing:0,ready:0};
|
|
1432
1469
|
if(plot.ready)group.ready++;
|
|
1433
1470
|
else group.growing++;
|
|
1434
1471
|
groups.set(plot.cropId,group);
|
|
1435
1472
|
}
|
|
1436
|
-
lines.push(
|
|
1473
|
+
lines.push(`总空位 ${emptyVegetables+emptyFlowers} 格:菜田 ${emptyVegetables}、花田 ${emptyFlowers}。`);
|
|
1437
1474
|
if(groups.size)lines.push([...groups].map(([id,g])=>id+' '+g.growing+' 格生长、'+g.ready+' 格成熟').join(';')+'。');
|
|
1438
|
-
|
|
1475
|
+
if (giants.length) {
|
|
1476
|
+
const counts=new Map();
|
|
1477
|
+
for (const giant of giants) counts.set(giant.cropId,(counts.get(giant.cropId)||0)+1);
|
|
1478
|
+
const mature=[...counts].map(([id,n])=>`${giantName(id)}×${n}`).join('、');
|
|
1479
|
+
lines.push(`田里已长成:${mature},共占 ${occupiedByGiants.size} 格。`);
|
|
1480
|
+
}
|
|
1481
|
+
const inventory=Object.entries(data.giants||{}).map(([id,n])=>`${giantName(id)}×${n}`).join('、');
|
|
1482
|
+
lines.push(`种子:${inventoryLine(data.seeds)}。普通收成:${inventoryLine(data.crops)}。巨型收成:${inventory||'空'}。`);
|
|
1439
1483
|
if(farm.autoCare&&data.自动播种开启)lines.push('自动补种已开,鱼鱼会使用背包种子种空地。');
|
|
1440
1484
|
}
|
|
1441
1485
|
if(scope!=='farm'){
|
|
@@ -1466,28 +1510,44 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1466
1510
|
const operations = ['plant','water','harvest','replant','buy','sell','stock','feed','catch'];
|
|
1467
1511
|
const actionFields = {
|
|
1468
1512
|
op: {type:'string',enum:operations},
|
|
1469
|
-
item: {type:'string',description:'品种 ID 或中文名。'},
|
|
1513
|
+
item: {type:'string',description:'品种 ID 或中文名。replant 省略时处理成熟作物;sell 省略时卖本批新收获,指定巨型收成用巨型品名或 kind=giant 加普通品名;stock 省略时接同一批中唯一买过的鱼种。'},
|
|
1470
1514
|
count: {type:'integer',minimum:1,maximum:999,description:'数量。收获、浇水、补种和捞鱼默认全部符合条件的。'},
|
|
1471
1515
|
kind: {type:'string',enum:['seed','fish','crop','giant'],description:'仅用于买卖。'},
|
|
1472
|
-
zone: {type:'string',enum:['vegetable','flower'],description:'
|
|
1473
|
-
bed: {type:'integer',minimum:0,maximum:2,description:'
|
|
1474
|
-
buyMissing: {type:'boolean',description:'
|
|
1516
|
+
zone: {type:'string',enum:['vegetable','flower'],description:'限制浇水和收获范围。播种自动选对应田地。'},
|
|
1517
|
+
bed: {type:'integer',minimum:0,maximum:2,description:'可指定 0 到 2 号菜畦播种、浇水或收获。'},
|
|
1518
|
+
buyMissing: {type:'boolean',description:'用于 plant 或 replant。允许花金币时填 true,只买实际种得下且缺的种子。'},
|
|
1519
|
+
fill: {type:'boolean',description:'仅用于普通 plant;种满用 true,按执行时的空格数播种,省略 count。'},
|
|
1520
|
+
layout: {type:'string',enum:['giant'],description:'只用于菜田的 plant,giant 会找完整 3×3。花田普通播种,每朵花成熟时独立判定。'},
|
|
1521
|
+
fallback: {type:'string',enum:['normal'],description:'仅用于 layout=giant。用户明确接受没整区时普通种,才填 normal。'},
|
|
1475
1522
|
};
|
|
1476
1523
|
let pending = Promise.resolve();
|
|
1477
1524
|
|
|
1478
1525
|
async function plan(args, catalog) {
|
|
1479
|
-
const {op, zone, bed, kind} = args;
|
|
1526
|
+
const {op, zone, bed, kind, layout, fallback} = args;
|
|
1480
1527
|
const item = string(args.item);
|
|
1528
|
+
if (layout!==undefined&&(op!=='plant'||layout!=='giant')||fallback!==undefined&&(layout!=='giant'||fallback!=='normal')) {
|
|
1529
|
+
throw new Error('整块和备用布局只能用于 plant;layout 填 giant,允许普通备用时 fallback 填 normal。');
|
|
1530
|
+
}
|
|
1481
1531
|
const count = args.count ?? (['harvest','water','replant'].includes(op) ? 65 : op==='catch' ? 8 : 1);
|
|
1532
|
+
if (args.fill!==undefined&&(typeof args.fill!=='boolean'||op!=='plant'||layout==='giant'||(args.fill&&args.count!==undefined))) throw new Error('种满用普通 plant 加 fill=true,不用填写 count。');
|
|
1533
|
+
if (args.buyMissing!==undefined&&(typeof args.buyMissing!=='boolean'||!['plant','replant'].includes(op))) throw new Error('buyMissing 只用于播种或补种。');
|
|
1482
1534
|
if (!operations.includes(op)) throw new Error('请选择有效的农活。');
|
|
1483
1535
|
if (args.plotId!==undefined) throw new Error('使用品种和数量批量操作,不需要地块编号。');
|
|
1484
1536
|
if (!Number.isSafeInteger(count) || count<1 || count>999) throw new Error('数量必须是 1 到 999 的整数。');
|
|
1485
1537
|
if (['plant','water','harvest','replant'].includes(op) && count>65) throw new Error('田地操作一次最多 65 格。');
|
|
1486
1538
|
if (['stock','catch'].includes(op) && count>8) throw new Error('池塘操作一次最多 8 条。');
|
|
1487
1539
|
if (zone!==undefined && !['vegetable','flower'].includes(zone)) throw new Error('请选择菜田或花田。');
|
|
1488
|
-
if (bed!==undefined && ![0,1,2].includes(bed)) throw new Error('
|
|
1540
|
+
if (bed!==undefined && (![0,1,2].includes(bed)||zone==='flower'||!['plant','water','harvest','replant'].includes(op))) throw new Error('请指定 0 到 2 号菜畦;花田不按菜畦编号。');
|
|
1489
1541
|
if (op==='feed') return {op, route:'feed', payload:{}};
|
|
1490
|
-
if (
|
|
1542
|
+
if (op==='sell' && !item) {
|
|
1543
|
+
if (args.count!==undefined || kind!==undefined) throw new Error('只卖本批收获时不用填 count 或 kind;要指定数量或分类请填品种。');
|
|
1544
|
+
return {op,route:'sell-current',payload:{}};
|
|
1545
|
+
}
|
|
1546
|
+
if (op==='replant' && !item) {
|
|
1547
|
+
if (zone!==undefined || bed!==undefined) throw new Error('原地补种不需要指定田地。');
|
|
1548
|
+
return {op,route:op,payload:{count,buyMissing:args.buyMissing===true}};
|
|
1549
|
+
}
|
|
1550
|
+
if (['water','harvest'].includes(op) && !item) return {op, route:op+'-batch', payload:{count,zone,bed}};
|
|
1491
1551
|
if (op==='catch' && !item) return {op, route:'catch-batch', payload:{count}};
|
|
1492
1552
|
|
|
1493
1553
|
const data = await catalog();
|
|
@@ -1495,7 +1555,9 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1495
1555
|
const match = list => list.find(x => x.id===item || x.name===item);
|
|
1496
1556
|
if (op==='buy' || op==='sell') {
|
|
1497
1557
|
const goods = op==='buy' && kind==='fish' ? fish : op==='buy' && kind==='seed' ? seeds : [...seeds,...fish,...(op==='sell'?giants:[])];
|
|
1498
|
-
const found =
|
|
1558
|
+
const found = op==='sell' && kind==='giant'
|
|
1559
|
+
? match(giants) || giants.find(giant=>giant.cropId===match(seeds)?.id)
|
|
1560
|
+
: match(goods);
|
|
1499
1561
|
if (!found) throw new Error('找不到商品 '+item+'。');
|
|
1500
1562
|
const category = fish.includes(found) ? 'fish' : giants.includes(found) ? 'giant' : op==='buy' ? 'seed' : 'crop';
|
|
1501
1563
|
if (kind && kind!==category) throw new Error(found.name+'的商品分类不符。');
|
|
@@ -1507,54 +1569,114 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1507
1569
|
if (!species) throw new Error('请指定有效的鱼种。');
|
|
1508
1570
|
return {op, route:op+'-batch', name:species.name, payload:{item:species.id,count}};
|
|
1509
1571
|
}
|
|
1510
|
-
const crop = match(seeds);
|
|
1511
|
-
if (!crop) throw new Error('找不到作物 '+item+'。');
|
|
1512
1572
|
if (op==='replant') {
|
|
1513
|
-
if (zone!==undefined || bed!==undefined) throw new Error('
|
|
1514
|
-
|
|
1573
|
+
if (zone!==undefined || bed!==undefined) throw new Error('原地补种不需要指定田地。');
|
|
1574
|
+
const crop = item && match(seeds);
|
|
1575
|
+
if (item && !crop) throw new Error('商店里没有「'+item+'」这个作物品种。');
|
|
1576
|
+
return {op, route:op, name:crop?.name, payload:{item:crop?.id,count,buyMissing:args.buyMissing===true}};
|
|
1577
|
+
}
|
|
1578
|
+
const crop = match(seeds);
|
|
1579
|
+
if (!crop && layout==='giant') return {op,route:'invalid-giant',payload:{item,bed},localError:`${bed===undefined?'巨型播种':'菜畦 '+bed}:商店里没有「${item||'未指定品种'}」这种种子,这一步没买种或播种。`};
|
|
1580
|
+
if (!crop) throw new Error('商店里没有「'+item+'」这种作物;这与田里是否成熟无关。');
|
|
1581
|
+
if (op==='plant' && (zone && zone!==(Number(crop.tier)===5?'flower':'vegetable') || bed!==undefined&&Number(crop.tier)===5)) {
|
|
1582
|
+
throw new Error(`${crop.name}要种在${Number(crop.tier)===5?'花田,不指定菜畦':'菜田'}。`);
|
|
1583
|
+
}
|
|
1584
|
+
if (layout==='giant' && Number(crop.tier)!==5) {
|
|
1585
|
+
if (args.count!==undefined && count!==9) return {op,route:'invalid-giant',payload:{item,bed},localError:'菜田 3×3 固定种 9 格,count 可以省略。'};
|
|
1586
|
+
if (!crop.巨大) return {op,route:'invalid-giant',payload:{item,bed},localError:crop.name+'在当前房间不能长成巨型。可尝试:'+seeds.filter(seed=>seed.巨大).map(seed=>seed.name).join('、')+'。'};
|
|
1587
|
+
return {op,route:'plant-giant-batch',name:crop.name,payload:{cropId:crop.id,bed,buyMissing:args.buyMissing===true,fallback}};
|
|
1515
1588
|
}
|
|
1516
|
-
const payload = op==='plant' ? {cropId:crop.id,count,bed} : {item:crop.id,count,zone};
|
|
1589
|
+
const payload = op==='plant' ? {cropId:crop.id,count,bed,...(args.fill?{fill:true}:{}),...(args.buyMissing?{buyMissing:true}:{})} : {item:crop.id,count,zone,bed};
|
|
1517
1590
|
return {op, route:op+'-batch', name:crop.name, payload};
|
|
1518
1591
|
}
|
|
1519
1592
|
|
|
1520
|
-
|
|
1593
|
+
// Previous harvests in this batch provide exact plot IDs for a subsequent replant.
|
|
1594
|
+
async function harvestForBatch(payload, write, work) {
|
|
1595
|
+
const before = await work.farm();
|
|
1596
|
+
const harvested = await write('harvest-batch',payload);
|
|
1597
|
+
work.update(harvested);
|
|
1598
|
+
const plots = new Map(before.plots.map(plot=>[plot.id,plot]));
|
|
1599
|
+
const claimed = harvested.harvestedPlots || (harvested.plotIds||[]).map(id=>({id,cropId:payload.item||plots.get(id)?.cropId}));
|
|
1600
|
+
for (const {id,cropId} of claimed) if (cropId) work.harvested.set(id,cropId);
|
|
1601
|
+
harvested.claimed = claimed;
|
|
1602
|
+
return harvested;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
async function executeAction(action, write, work, harvestOptions) {
|
|
1521
1606
|
const {op, route, payload, name} = action;
|
|
1607
|
+
if (action.localError) return {ok:false,说:action.localError,wallet:work.wallet};
|
|
1608
|
+
if (route==='sell-current') {
|
|
1609
|
+
if (!work.lots.size) return {ok:false,说:'本批没有新收获可在此步出售,现有库存没有扣减。',wallet:work.wallet};
|
|
1610
|
+
const lines=[];
|
|
1611
|
+
let ok=true;
|
|
1612
|
+
const lots=[...work.lots.values()];
|
|
1613
|
+
for (const {id,kind,name,quantity} of lots) {
|
|
1614
|
+
try {
|
|
1615
|
+
const sold=await write('sell',{id,kind,数量:quantity});
|
|
1616
|
+
work.update(sold);
|
|
1617
|
+
work.consume(id,sold.卖出.n);
|
|
1618
|
+
lines.push(saleReceipt(sold));
|
|
1619
|
+
} catch(error) {
|
|
1620
|
+
ok=false; work.update(error.result||{}); lines.push(`${name}没有卖出:${error.message}`);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
if (lots.some(lot=>lot.kind==='fish')) lines.push('卖完后鱼篓成鱼:'+inventoryLine(work.wallet?.fish)+'。');
|
|
1624
|
+
return {ok,说:lines.join(' '),wallet:work.wallet};
|
|
1625
|
+
}
|
|
1522
1626
|
if (op==='replant') {
|
|
1523
1627
|
const {item,count,buyMissing} = payload;
|
|
1524
|
-
const
|
|
1525
|
-
const
|
|
1526
|
-
let wallet =
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
if (
|
|
1536
|
-
|
|
1537
|
-
wallet = planted.wallet;
|
|
1538
|
-
lines.push(planted.say);
|
|
1539
|
-
if (planted.count<plots) lines.push(`还有 ${plots-planted.count} 格没有补种。`);
|
|
1540
|
-
} else if (plots) lines.push('背包没有种子,已收获,未补种。');
|
|
1541
|
-
return {ok:true,说:lines.join(' '),wallet};
|
|
1542
|
-
} catch (error) {
|
|
1543
|
-
lines.push('已收获,补种未全部完成:'+error.message);
|
|
1544
|
-
return {ok:false,说:lines.join(' '),wallet};
|
|
1628
|
+
const prior = [...work.harvested].filter(([,crop])=>!item || crop===item);
|
|
1629
|
+
const lines = [];
|
|
1630
|
+
let wallet, allOk = true;
|
|
1631
|
+
if (!prior.length) {
|
|
1632
|
+
const result = await harvestForBatch({item,count,forReplant:true},write,work);
|
|
1633
|
+
work.collect(result.collectedItems);
|
|
1634
|
+
lines.push(result.say); wallet=result.wallet;
|
|
1635
|
+
}
|
|
1636
|
+
const exact = prior.length ? prior.slice(0,count) : [...work.harvested].filter(([,crop])=>!item || crop===item);
|
|
1637
|
+
const groups = new Map();
|
|
1638
|
+
for (const [id,crop] of exact) {
|
|
1639
|
+
if (!groups.has(crop)) groups.set(crop,[]);
|
|
1640
|
+
groups.get(crop).push(id);
|
|
1545
1641
|
}
|
|
1642
|
+
wallet ??= work.wallet;
|
|
1643
|
+
if (!groups.size) return {ok:false,说:lines.join(' ')||'没有可补种的地块。',wallet};
|
|
1644
|
+
for (const [crop,plotIds] of groups) {
|
|
1645
|
+
try {
|
|
1646
|
+
const missing=Math.max(0,plotIds.length-(wallet.seeds?.[crop]||0));
|
|
1647
|
+
if (buyMissing && missing) {
|
|
1648
|
+
const bought=await write('buy',{kind:'seed',id:crop,数量:missing}); work.update(bought); wallet=bought.wallet;
|
|
1649
|
+
lines.push(`补买了 ${bought.买到.n} 份种子,花费 ${bought.花了} 金币。`);
|
|
1650
|
+
}
|
|
1651
|
+
if (!(wallet.seeds?.[crop]>0)) {
|
|
1652
|
+
allOk=false; lines.push(`收成已入账,缺少种子,${plotIds.length} 格未补种。`); continue;
|
|
1653
|
+
}
|
|
1654
|
+
const planted=await write('plant-batch',{cropId:crop,count:plotIds.length,plotIds});
|
|
1655
|
+
work.update(planted); wallet=planted.wallet; lines.push(planted.say);
|
|
1656
|
+
for (const id of planted.plotIds||[]) work.harvested.delete(id);
|
|
1657
|
+
if (planted.count<plotIds.length) { allOk=false; lines.push(`还有 ${plotIds.length-planted.count} 格未补种。`); }
|
|
1658
|
+
} catch(error) { work.update(error.result || {}); wallet=work.wallet; allOk=false; lines.push('收成已入账,补种未全部完成:'+error.message); }
|
|
1659
|
+
}
|
|
1660
|
+
return {ok:allOk,说:lines.join(' '),wallet};
|
|
1546
1661
|
}
|
|
1547
|
-
const result =
|
|
1662
|
+
const result = op==='harvest' && harvestOptions.forReplant
|
|
1663
|
+
? await harvestForBatch({...payload,...harvestOptions},write,work)
|
|
1664
|
+
: await write(route,{...payload,...harvestOptions});
|
|
1665
|
+
work.update(result);
|
|
1548
1666
|
let 说 = result.say;
|
|
1549
|
-
if (op==='buy') 说 = `买了 ${result.买到.n} 份${name},花费 ${result.花了} 金币。`;
|
|
1550
|
-
if (op==='sell')
|
|
1667
|
+
if (op==='buy') 说 = `买了 ${result.买到.n} 份${name}${payload.kind==='fish'?'鱼苗':'种子'},花费 ${result.花了} 金币。`;
|
|
1668
|
+
if (op==='sell') {
|
|
1669
|
+
work.consume(payload.id,result.卖出.n);
|
|
1670
|
+
说 = saleReceipt(result);
|
|
1671
|
+
}
|
|
1672
|
+
work.collect(result.collectedItems);
|
|
1551
1673
|
if (op==='stock' || op==='catch') 说 = 鱼塘回执(result,op,name);
|
|
1552
|
-
return {ok:true,说,wallet:result.wallet};
|
|
1674
|
+
return {ok:true,说,wallet:result.wallet,claimed:result.claimed};
|
|
1553
1675
|
}
|
|
1554
1676
|
|
|
1555
1677
|
return {
|
|
1556
1678
|
name:'fish_home_farm',
|
|
1557
|
-
description:'
|
|
1679
|
+
description:'种田、养鱼和买卖。用一次 batch 交全单。收、卖、原地补种可按 actions 顺序填 harvest → sell → replant;replant 会用本批刚收的地。sell 不填品种和数量,只卖本批刚收获或刚捞的,免查背包。只收后补种时,actions 里放一项 replant(可填 item)。种满某片田用 plant + fill=true,不查地、不猜数量;菜田巨型候选用 plant + layout=giant 找 3×3。花田普通播种,每朵花成熟时独立有 15% 概率变异。获准花钱才用 buyMissing,不另加 buy。stock 可用同批唯一买过的鱼种。没空区直接回报,允许普通备选才填 fallback=normal。以回执为准,无需重复查询。',
|
|
1558
1680
|
parameters:{type:'object',properties:{
|
|
1559
1681
|
op:{type:'string',enum:['batch','list']},
|
|
1560
1682
|
actions:{type:'array',minItems:1,maxItems:16,items:{type:'object',properties:actionFields,required:['op'],additionalProperties:false},description:'batch 的完整操作列表,按顺序执行。多个品种各放一项,数量填 count。'},
|
|
@@ -1565,13 +1687,15 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1565
1687
|
async execute(args={}, exec) {
|
|
1566
1688
|
const {op,bed} = args;
|
|
1567
1689
|
const request = (route,params) => roomRequest('/api/farm'+route,params,8000,exec?.signal);
|
|
1568
|
-
|
|
1690
|
+
|
|
1569
1691
|
try {
|
|
1570
1692
|
if(op==='list') {
|
|
1571
1693
|
if(args.scope!=='layout')return {ok:true,说:farmSummary(await request(''),args.scope)};
|
|
1572
1694
|
if(bed!==undefined&&![0,1,2].includes(bed))throw new Error('菜畦编号为 0 到 2。');
|
|
1573
|
-
const {beds}=await request('/layout'+(bed===undefined?'':'?bed='+bed));
|
|
1574
|
-
const
|
|
1695
|
+
const {beds,flowers}=await request('/layout'+(bed===undefined?'':'?bed='+bed));
|
|
1696
|
+
const emptyVeg=beds.reduce((n,field)=>n+field.blocks.reduce((sum,b)=>sum+b.empty,0),0);
|
|
1697
|
+
const emptyFlowers=flowers?.filter(p=>!p.cropId).length;
|
|
1698
|
+
const lines=[bed===undefined?(flowers?`总空位 ${emptyVeg+emptyFlowers} 格:菜田 ${emptyVeg}、花田 ${emptyFlowers}。`:`菜田共空 ${emptyVeg} 格。`):`菜畦 ${bed} 共空 ${emptyVeg} 格。`];
|
|
1575
1699
|
for(const field of beds){
|
|
1576
1700
|
const blocks=field.blocks.map((block,i)=>{
|
|
1577
1701
|
const marks=block.crops.map(c=>c.name+'×'+c.count);
|
|
@@ -1582,6 +1706,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1582
1706
|
});
|
|
1583
1707
|
lines.push('bed-'+field.bed+'\n'+blocks.join('\n'));
|
|
1584
1708
|
}
|
|
1709
|
+
if (flowers) lines.push('花田:'+flowers.map(p=>p.cropId?(p.giant?'巨型 ':'')+p.cropId:'空').join(' · '));
|
|
1585
1710
|
return {ok:true,说:lines.join('\n\n')};
|
|
1586
1711
|
}
|
|
1587
1712
|
// Keep accepting old single-action requests while the model learns the new schema.
|
|
@@ -1595,17 +1720,51 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1595
1720
|
try {
|
|
1596
1721
|
if (!entry || typeof entry!=='object' || Array.isArray(entry)) throw new Error('请填写操作对象。');
|
|
1597
1722
|
if (op==='batch' && Object.keys(entry).some(key=>!Object.hasOwn(actionFields,key))) throw new Error('该项包含不支持的参数。');
|
|
1598
|
-
|
|
1723
|
+
let normalized=entry;
|
|
1724
|
+
if (entry.op==='stock' && !string(entry.item)) {
|
|
1725
|
+
const purchased=new Set(actions.filter(step=>step.op==='buy'&&step.payload.kind==='fish').map(step=>step.payload.id));
|
|
1726
|
+
if (purchased.size!==1) throw new Error('放苗请指定鱼种;同一批前面只买了一种鱼苗时可以省略。');
|
|
1727
|
+
normalized={...entry,item:[...purchased][0]};
|
|
1728
|
+
}
|
|
1729
|
+
const action=await plan(normalized,getCatalog);
|
|
1730
|
+
if (action.route==='sell-current' && !actions.some(prev=>['harvest','replant','catch'].includes(prev.op))) {
|
|
1731
|
+
throw new Error('只卖本批收获时,请在 sell 前安排收获或捞鱼;要卖背包库存请指定品种和数量。');
|
|
1732
|
+
}
|
|
1733
|
+
actions.push(action);
|
|
1599
1734
|
} catch (error) {
|
|
1600
|
-
throw new Error(op==='batch' ?
|
|
1735
|
+
throw new Error(op==='batch' ? `整批未执行:第 ${index+1} 项:${error.message.replace(/[。;]+$/,'')}。前面的项目也没有提交。` : error.message);
|
|
1601
1736
|
}
|
|
1602
1737
|
}
|
|
1603
1738
|
const run = async () => {
|
|
1604
1739
|
const progress = turn ? (turn.farmWork ??= {batches:0,receipts:new Map()}) : {batches:0,receipts:new Map()};
|
|
1605
|
-
const keys = actions.map(({route,payload})=>JSON.stringify([route,payload
|
|
1740
|
+
const keys = actions.map(({route,payload},index)=>JSON.stringify([route,payload,...(route==='sell-current'
|
|
1741
|
+
? [actions.slice(0,index).filter(action=>['harvest','replant','catch'].includes(action.op)).map(action=>[action.route,action.payload])]
|
|
1742
|
+
: [])]));
|
|
1606
1743
|
const hasNewWork = keys.some(key=>!progress.receipts.has(key));
|
|
1607
1744
|
if (hasNewWork && progress.batches>=每轮农活上限) return {ok:false,说:'本轮已执行两次农活操作。请根据已有回执回复,剩余操作下一轮再安排。'};
|
|
1608
|
-
|
|
1745
|
+
let committed=false;
|
|
1746
|
+
const write=async (route,payload)=>{
|
|
1747
|
+
const result=await request('/'+route,{...payload,requestId:randomUUID(),actor:'dayu'});
|
|
1748
|
+
if (result.code!=='ALREADY_FULL') committed=true;
|
|
1749
|
+
return result;
|
|
1750
|
+
};
|
|
1751
|
+
let currentFarm;
|
|
1752
|
+
const work = {harvested:new Map(),lots:new Map(),wallet:null,
|
|
1753
|
+
collect(items){for (const item of items||[]) {
|
|
1754
|
+
const lot=this.lots.get(item.id);
|
|
1755
|
+
this.lots.set(item.id,{...item,quantity:(lot?.quantity||0)+item.quantity});
|
|
1756
|
+
}},consume(id,quantity){
|
|
1757
|
+
const lot=this.lots.get(id);
|
|
1758
|
+
if (!lot) return;
|
|
1759
|
+
lot.quantity-=quantity;
|
|
1760
|
+
if (lot.quantity<=0) this.lots.delete(id);
|
|
1761
|
+
},async farm(){
|
|
1762
|
+
if (!currentFarm) { const data=await getCatalog(); currentFarm=data.farm; this.wallet ??= data.wallet||data; }
|
|
1763
|
+
return currentFarm;
|
|
1764
|
+
},update(data){
|
|
1765
|
+
if (data.farm) currentFarm=data.farm;
|
|
1766
|
+
if (data.wallet) this.wallet=data.wallet;
|
|
1767
|
+
}};
|
|
1609
1768
|
let lastWallet;
|
|
1610
1769
|
const results = [];
|
|
1611
1770
|
for (const [index, action] of actions.entries()) {
|
|
@@ -1614,16 +1773,31 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1614
1773
|
let result = progress.receipts.get(key);
|
|
1615
1774
|
const repeated = Boolean(result);
|
|
1616
1775
|
if (!repeated) {
|
|
1617
|
-
|
|
1618
|
-
|
|
1776
|
+
const harvestOptions = {};
|
|
1777
|
+
if (action.op==='harvest') {
|
|
1778
|
+
const next=actions.slice(index+1);
|
|
1779
|
+
if (next.some(step=>step.op==='replant' &&
|
|
1780
|
+
(!step.payload.item || !action.payload.item || step.payload.item===action.payload.item))) harvestOptions.forReplant=true;
|
|
1781
|
+
const giant=next.find(step=>step.route==='plant-giant-batch');
|
|
1782
|
+
if (giant) harvestOptions.forGiant={cropId:giant.payload.cropId,bed:giant.payload.bed};
|
|
1783
|
+
}
|
|
1784
|
+
try { result = await executeAction(action,write,work,harvestOptions); }
|
|
1785
|
+
catch (error) { work.update(error.result || {}); result = {ok:false,说:error.message,wallet:error.result?.wallet}; }
|
|
1619
1786
|
progress.receipts.set(key,result);
|
|
1620
1787
|
}
|
|
1788
|
+
if (repeated && result.claimed) {
|
|
1789
|
+
const farm=await work.farm();
|
|
1790
|
+
const empty=new Set(farm.plots.filter(plot=>!plot.cropId).map(plot=>plot.id));
|
|
1791
|
+
for (const {id,cropId} of result.claimed) if (cropId&&empty.has(id)) work.harvested.set(id,cropId);
|
|
1792
|
+
}
|
|
1621
1793
|
if (!repeated && result.wallet) lastWallet = result.wallet;
|
|
1622
1794
|
const label = action.name ? action.name+':' : '';
|
|
1623
1795
|
const receipt = repeated ? '本轮已提交,原回执:'+result.说 : result.说;
|
|
1624
1796
|
results.push({ok:result.ok,说:op==='batch'?`${index+1}. ${label}${receipt}`:receipt});
|
|
1625
1797
|
}
|
|
1798
|
+
if (committed) progress.batches++;
|
|
1626
1799
|
const lines = results.map(row=>row.说);
|
|
1800
|
+
if (op==='batch' && results.some(row=>!row.ok)) lines.unshift('各项独立结算,已完成的操作已入账;未完成的见下。');
|
|
1627
1801
|
if (results.length<actions.length) lines.push(`已停止,还有 ${actions.length-results.length} 项未提交。`);
|
|
1628
1802
|
if (lastWallet && (op==='batch' || ['replant','buy','sell'].includes(op))) lines.push(`余额 ${lastWallet.coins} 金币。`);
|
|
1629
1803
|
return {ok:results.length===actions.length&&results.every(row=>row.ok),说:lines.join(op==='batch'?'\n':' ')};
|
|
@@ -1748,13 +1922,6 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1748
1922
|
if (typeof agent.ctx.tools?.register==='function') {
|
|
1749
1923
|
for (const create of [画工具,睡眠工具,鱼鱼窝工具,日常工具,抽卡工具,卡面工具,菜谱工具,走过去工具,农活工具,看一眼工具]) {
|
|
1750
1924
|
const tool = create();
|
|
1751
|
-
if (tool.name==='fish_home_farm' && 当前轮.get(target)?.farmWork?.batches>=每轮农活上限) {
|
|
1752
|
-
const off = entry.off们.get(tool.name);
|
|
1753
|
-
if (typeof off==='function') {
|
|
1754
|
-
try { off(); entry.off们.delete(tool.name); } catch {}
|
|
1755
|
-
}
|
|
1756
|
-
continue;
|
|
1757
|
-
}
|
|
1758
1925
|
register(tool.name,()=>agent.ctx.tools.register(tool));
|
|
1759
1926
|
}
|
|
1760
1927
|
}
|
|
@@ -2227,7 +2394,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2227
2394
|
let 体
|
|
2228
2395
|
try { 体 = await 读体(req) } catch (error) { return 回错(res, 400, 'BAD_BODY', String((error && error.message) || error)) }
|
|
2229
2396
|
if (!体 || 体.schema !== PET_STATE_SCHEMA) return 回错(res, 400, 'BAD_SCHEMA', '这份数据的版本不对')
|
|
2230
|
-
const 旧天气 = String(
|
|
2397
|
+
const 旧天气 = String(最近状态?.snapshot?.weather || '')
|
|
2231
2398
|
收下环境(体.snapshot)
|
|
2232
2399
|
if(typeof 体.room?.url==='string'){
|
|
2233
2400
|
try{
|
|
@@ -2294,13 +2461,15 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2294
2461
|
try {
|
|
2295
2462
|
await agent.followup({id:randomUUID(),role:'user',source:{kind:'fish-home-life'},
|
|
2296
2463
|
content:[{type:'text',text:'【鱼鱼窝】'+事件.text.slice(0,300)}]})
|
|
2464
|
+
事件.notified = true
|
|
2297
2465
|
} catch (error) {
|
|
2298
2466
|
return 回错(res,502,'SEND_FAILED','生活事件没送进会话')
|
|
2299
2467
|
} finally {互动送达中.delete(id)}
|
|
2300
2468
|
}
|
|
2301
2469
|
}
|
|
2302
|
-
if (事件.kind === 'scene' && 配置.开 &&
|
|
2303
|
-
|
|
2470
|
+
if (事件.kind === 'scene' && 配置.开 && targetSession && Math.abs(Date.now() - 事件.at) < SCENE_TTL_MS) {
|
|
2471
|
+
// A scene already delivered as a message does not need a second copy in context or status.
|
|
2472
|
+
if (事件.at >= (最近场景?.at||0)) 最近场景 = 事件.notified ? null : { sid: targetSession, at: 事件.at, text: 事件.text.slice(0, 240) }
|
|
2304
2473
|
}
|
|
2305
2474
|
生活事件.push(事件)
|
|
2306
2475
|
if (生活事件.length > 200) 生活事件.shift()
|