koishi-plugin-rocom 1.0.17 → 1.0.18
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/lib/client.d.ts +1 -2
- package/lib/client.js +6 -16
- package/lib/commands/egg.js +41 -11
- package/lib/egg-service.d.ts +43 -12
- package/lib/egg-service.js +130 -78
- package/lib/index.js +180 -8740
- package/package.json +1 -1
package/lib/client.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export declare class RocomClient {
|
|
|
66
66
|
getLineupList(ctx: Context, fwToken: string, pageNo?: number, category?: string, userIdentifier?: string): Promise<any>;
|
|
67
67
|
getExchangePosters(ctx: Context, fwToken: string, pageNo?: number, userIdentifier?: string): Promise<any>;
|
|
68
68
|
getMerchantInfo(ctx: Context, refresh?: boolean): Promise<any>;
|
|
69
|
-
queryPetSize(ctx: Context, diameter: number, weight: number,
|
|
69
|
+
queryPetSize(ctx: Context, diameter: number, weight: number, pool?: string, pageNo?: number, pageSize?: number, userIdentifier?: string): Promise<any>;
|
|
70
70
|
getActivitiesInfo(ctx: Context, refresh?: boolean, userIdentifier?: string): Promise<any>;
|
|
71
71
|
syncConfig(ctx: Context, userIdentifier?: string): Promise<any>;
|
|
72
72
|
getAnnouncementList(ctx: Context, params?: {
|
|
@@ -80,7 +80,6 @@ export declare class RocomClient {
|
|
|
80
80
|
order?: string;
|
|
81
81
|
}, userIdentifier?: string): Promise<any>;
|
|
82
82
|
getAnnouncementDetail(ctx: Context, threadId: number | string, userIdentifier?: string): Promise<any>;
|
|
83
|
-
getEggSearch(ctx: Context, height: number, weight: number, pageNo?: number, pageSize?: number, userIdentifier?: string): Promise<any>;
|
|
84
83
|
getEggGroups(ctx: Context, userIdentifier?: string): Promise<any>;
|
|
85
84
|
getEggGroupPets(ctx: Context, groupIds: string | number[], matchMode?: 'any' | 'all', pageNo?: number, pageSize?: number, userIdentifier?: string): Promise<any>;
|
|
86
85
|
getEggPetGroups(ctx: Context, query: string, limit?: number, userIdentifier?: string): Promise<any>;
|
package/lib/client.js
CHANGED
|
@@ -616,23 +616,16 @@ class RocomClient {
|
|
|
616
616
|
random_goods: 'all',
|
|
617
617
|
});
|
|
618
618
|
}
|
|
619
|
-
async queryPetSize(ctx, diameter, weight,
|
|
620
|
-
|
|
621
|
-
const newParams = this.scopedParams({
|
|
619
|
+
async queryPetSize(ctx, diameter, weight, pool = 'magic', pageNo = 1, pageSize = 30, userIdentifier = '') {
|
|
620
|
+
const params = this.scopedParams({
|
|
622
621
|
diameter,
|
|
623
622
|
weight,
|
|
624
|
-
pool:
|
|
623
|
+
pool: pool || 'magic',
|
|
625
624
|
include_display_only: 'false',
|
|
626
|
-
page_no: 1,
|
|
627
|
-
page_size: 30,
|
|
625
|
+
page_no: Math.max(Number(pageNo) || 1, 1),
|
|
626
|
+
page_size: Math.min(Math.max(Number(pageSize) || 30, 1), 100),
|
|
628
627
|
}, userIdentifier);
|
|
629
|
-
|
|
630
|
-
if (newRes && Array.isArray(newRes.items))
|
|
631
|
-
return newRes;
|
|
632
|
-
const params = this.scopedParams({ diameter, weight }, userIdentifier);
|
|
633
|
-
if (sameRideEgg)
|
|
634
|
-
params.sameRideEgg = 1;
|
|
635
|
-
return this.get(ctx, '/api/v1/games/rocom/pet/size-query', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), params);
|
|
628
|
+
return this.get(ctx, '/api/v1/games/rocom/wiki/pet-size/query', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), params);
|
|
636
629
|
}
|
|
637
630
|
async getActivitiesInfo(ctx, refresh = false, userIdentifier = '') {
|
|
638
631
|
return this.get(ctx, '/api/v1/games/rocom/activities/info', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), this.scopedParams({ refresh: refresh ? 'true' : 'false' }, userIdentifier));
|
|
@@ -649,9 +642,6 @@ class RocomClient {
|
|
|
649
642
|
async getAnnouncementDetail(ctx, threadId, userIdentifier = '') {
|
|
650
643
|
return this.get(ctx, '/api/v1/games/rocom/announcement/detail', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), this.scopedParams({ thread_id: threadId }, userIdentifier));
|
|
651
644
|
}
|
|
652
|
-
async getEggSearch(ctx, height, weight, pageNo = 1, pageSize = 20, userIdentifier = '') {
|
|
653
|
-
return this.get(ctx, '/api/v1/games/rocom/egg/search', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), this.scopedParams({ height, weight, page_no: pageNo, page_size: pageSize }, userIdentifier));
|
|
654
|
-
}
|
|
655
645
|
async getEggGroups(ctx, userIdentifier = '') {
|
|
656
646
|
return this.get(ctx, '/api/v1/games/rocom/egg/groups', this.wegameHeaders('', userIdentifier, 'bot', 'koishi'), this.scopedParams({}, userIdentifier));
|
|
657
647
|
}
|
package/lib/commands/egg.js
CHANGED
|
@@ -111,17 +111,10 @@ function register(deps) {
|
|
|
111
111
|
let fallback = '';
|
|
112
112
|
if (height != null && weight != null) {
|
|
113
113
|
const heightInMeters = heightMeters ?? height / 100;
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
data = eggService.
|
|
117
|
-
fallback = eggService.
|
|
118
|
-
}
|
|
119
|
-
if (!data) {
|
|
120
|
-
const backendResults = await client.queryPetSize(ctx, heightInMeters, weight, false, session?.userId || '');
|
|
121
|
-
if (backendResults) {
|
|
122
|
-
data = eggService.buildSizeSearchDataFromApi(height, weight, backendResults, heightDisplay);
|
|
123
|
-
fallback = eggService.buildSizeSearchTextFromApi(height, weight, backendResults, heightDisplay);
|
|
124
|
-
}
|
|
114
|
+
const backendResults = await client.queryPetSize(ctx, heightInMeters, weight, 'magic', 1, 30, session?.userId || '');
|
|
115
|
+
if (backendResults) {
|
|
116
|
+
data = eggService.buildSizeSearchDataFromApi(height, weight, backendResults, heightDisplay);
|
|
117
|
+
fallback = eggService.buildSizeSearchTextFromApi(height, weight, backendResults, heightDisplay);
|
|
125
118
|
}
|
|
126
119
|
}
|
|
127
120
|
if (!data) {
|
|
@@ -135,6 +128,43 @@ function register(deps) {
|
|
|
135
128
|
const name = nameParts.join(' ');
|
|
136
129
|
if (!name)
|
|
137
130
|
return '请输入精灵名称。用法:洛克.查蛋 <精灵名>';
|
|
131
|
+
let backendDetail = null;
|
|
132
|
+
let backendProfile = null;
|
|
133
|
+
const backendList = await client.listWikiPets(ctx, name, 1, 10);
|
|
134
|
+
const backendItems = Array.isArray(backendList?.items) ? backendList.items : [];
|
|
135
|
+
if (backendItems.length) {
|
|
136
|
+
let selected = backendItems.find((item) => {
|
|
137
|
+
const itemName = String(item?.name || '').trim();
|
|
138
|
+
const itemForm = String(item?.form || '').trim();
|
|
139
|
+
return itemName === name || (itemForm && `${itemName}${itemForm}` === name);
|
|
140
|
+
});
|
|
141
|
+
if (!selected && backendItems.length === 1)
|
|
142
|
+
selected = backendItems[0];
|
|
143
|
+
const selectedId = selected?.pet_id ?? selected?.id;
|
|
144
|
+
if (selectedId != null && selectedId !== '') {
|
|
145
|
+
backendDetail = await client.getWikiPet(ctx, selectedId);
|
|
146
|
+
if (!backendDetail)
|
|
147
|
+
backendDetail = selected;
|
|
148
|
+
backendProfile = await client.getWikiPetProfile(ctx, selectedId);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (backendDetail) {
|
|
152
|
+
const compatibleByGroup = {};
|
|
153
|
+
const backendPet = { ...backendDetail, ...(backendProfile || {}) };
|
|
154
|
+
const eggGroups = Array.isArray(backendPet?.egg_groups) ? backendPet.egg_groups : [];
|
|
155
|
+
const eggGroupIds = eggGroups.length
|
|
156
|
+
? eggGroups.map((group) => group?.id).filter((id) => id != null && id !== '')
|
|
157
|
+
: Array.isArray(backendPet?.egg_group_ids) ? backendPet.egg_group_ids : [];
|
|
158
|
+
for (const groupId of eggGroupIds) {
|
|
159
|
+
const groupResults = await client.listWikiPets(ctx, '', 1, 31, { egg_group_id: groupId });
|
|
160
|
+
compatibleByGroup[String(groupId)] = Array.isArray(groupResults?.items) ? groupResults.items : [];
|
|
161
|
+
}
|
|
162
|
+
const data = eggService.buildSearchDataFromWiki(backendPet, compatibleByGroup);
|
|
163
|
+
data.commandHint = '数据来自新版 Wiki;接口不可用时自动回退本地查蛋';
|
|
164
|
+
data.copyright = 'Koishi & WeGame 洛克王国插件';
|
|
165
|
+
await sendEggImage(deps, session, 'searcheggs', data, eggService.buildSearchTextFromWiki(data));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
138
168
|
const sr = eggService.search(name);
|
|
139
169
|
if (sr.matchType === 'multi') {
|
|
140
170
|
const candidates = searchResultCandidates(sr);
|
package/lib/egg-service.d.ts
CHANGED
|
@@ -29,8 +29,6 @@ export declare class EggService {
|
|
|
29
29
|
private formatSizeApiCard;
|
|
30
30
|
private splitNewSizeApiItems;
|
|
31
31
|
private sizeApiResultGroups;
|
|
32
|
-
private formatEggSearchCard;
|
|
33
|
-
private formatEggSearchTextLine;
|
|
34
32
|
private mergeCardsByName;
|
|
35
33
|
private mergeSizeCard;
|
|
36
34
|
private minValue;
|
|
@@ -51,8 +49,8 @@ export declare class EggService {
|
|
|
51
49
|
range: any[];
|
|
52
50
|
}, heightDisplay?: string): string;
|
|
53
51
|
buildSizeSearchTextFromApi(height?: number, weight?: number, results?: any, heightDisplay?: string): string;
|
|
54
|
-
buildEggSearchText(heightMeters?: number, weight?: number, results?: any, heightDisplay?: string): string;
|
|
55
52
|
buildSearchText(pet: any): string;
|
|
53
|
+
buildSearchTextFromWiki(data: any): string;
|
|
56
54
|
buildCandidatesText(keyword: string, candidates: any[]): string;
|
|
57
55
|
buildWantPetText(pet: any): string;
|
|
58
56
|
buildPairText(a: any, b: any): string;
|
|
@@ -117,6 +115,48 @@ export declare class EggService {
|
|
|
117
115
|
commandHint: string;
|
|
118
116
|
copyright: string;
|
|
119
117
|
};
|
|
118
|
+
buildSearchDataFromWiki(pet: any, compatibleByGroup?: Record<string, any[]>): {
|
|
119
|
+
pet_name: any;
|
|
120
|
+
pet_id: any;
|
|
121
|
+
pet_icon: any;
|
|
122
|
+
pet_image: any;
|
|
123
|
+
type_label: string;
|
|
124
|
+
egg_groups_label: string;
|
|
125
|
+
egg_groups: (string | number)[];
|
|
126
|
+
egg_group_labels: {
|
|
127
|
+
[k: string]: string;
|
|
128
|
+
};
|
|
129
|
+
male_rate: number;
|
|
130
|
+
female_rate: number;
|
|
131
|
+
hatch_label: string;
|
|
132
|
+
weight_label: string;
|
|
133
|
+
height_label: string;
|
|
134
|
+
total_compatible: number;
|
|
135
|
+
is_undiscovered: boolean;
|
|
136
|
+
egg_group_sections: {
|
|
137
|
+
id: string | number;
|
|
138
|
+
label: string;
|
|
139
|
+
desc: string;
|
|
140
|
+
count: number;
|
|
141
|
+
members: {
|
|
142
|
+
name: any;
|
|
143
|
+
id: any;
|
|
144
|
+
type_label: string;
|
|
145
|
+
egg_groups_label: string;
|
|
146
|
+
}[];
|
|
147
|
+
has_more: boolean;
|
|
148
|
+
total: number;
|
|
149
|
+
}[];
|
|
150
|
+
total_stats: number;
|
|
151
|
+
egg_details: {
|
|
152
|
+
has_data: boolean;
|
|
153
|
+
};
|
|
154
|
+
commandHint: string;
|
|
155
|
+
copyright: string;
|
|
156
|
+
};
|
|
157
|
+
private wikiEggGroups;
|
|
158
|
+
private wikiTypeLabel;
|
|
159
|
+
private formatWikiMember;
|
|
120
160
|
buildPairData(a: any, b: any): {
|
|
121
161
|
commandHint: string;
|
|
122
162
|
copyright: string;
|
|
@@ -230,14 +270,5 @@ export declare class EggService {
|
|
|
230
270
|
commandHint: string;
|
|
231
271
|
copyright: string;
|
|
232
272
|
};
|
|
233
|
-
buildEggSearchData(heightMeters?: number, weight?: number, results?: any, heightDisplay?: string): {
|
|
234
|
-
query_label: string;
|
|
235
|
-
perfect_matches: any;
|
|
236
|
-
range_matches: any[];
|
|
237
|
-
total_count: any;
|
|
238
|
-
has_results: boolean;
|
|
239
|
-
commandHint: string;
|
|
240
|
-
copyright: string;
|
|
241
|
-
};
|
|
242
273
|
private buildEggDetails;
|
|
243
274
|
}
|
package/lib/egg-service.js
CHANGED
|
@@ -341,42 +341,6 @@ class EggService {
|
|
|
341
341
|
candidates: Array.isArray(results?.candidates) ? results.candidates : [],
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
|
-
formatEggSearchCard(item) {
|
|
345
|
-
const eggGroups = Array.isArray(item?.egg_groups)
|
|
346
|
-
? item.egg_groups
|
|
347
|
-
.map((group) => group?.official_name || group?.display_name || `蛋组${group?.group_id}`)
|
|
348
|
-
.filter(Boolean)
|
|
349
|
-
: [];
|
|
350
|
-
const heightRange = Array.isArray(item?.height_range_m) ? item.height_range_m : [];
|
|
351
|
-
const weightRange = Array.isArray(item?.weight_range_kg) ? item.weight_range_kg : [];
|
|
352
|
-
const typeLabel = Array.isArray(item?.unit_type) && item.unit_type.length
|
|
353
|
-
? item.unit_type.join(' / ')
|
|
354
|
-
: '未知';
|
|
355
|
-
return {
|
|
356
|
-
id: item?.id || '-',
|
|
357
|
-
name: item?.name || '未知精灵',
|
|
358
|
-
icon: item?.pet_icon_url || petIconUrl(item?.id),
|
|
359
|
-
image: item?.pet_img_url || petImageUrl(item?.id),
|
|
360
|
-
type_label: typeLabel,
|
|
361
|
-
egg_group_ids: Array.isArray(item?.egg_groups)
|
|
362
|
-
? item.egg_groups.map((group) => Number(group?.group_id)).filter((value) => Number.isFinite(value))
|
|
363
|
-
: [],
|
|
364
|
-
egg_groups_label: eggGroups.length ? eggGroups.join(' / ') : '暂无蛋组数据',
|
|
365
|
-
height_min: num(heightRange[0]),
|
|
366
|
-
height_max: num(heightRange[1]),
|
|
367
|
-
height_label: fmtRange(num(heightRange[0]), num(heightRange[1]), 'm'),
|
|
368
|
-
weight_min: num(weightRange[0]),
|
|
369
|
-
weight_max: num(weightRange[1]),
|
|
370
|
-
weight_label: fmtRange(num(weightRange[0]), num(weightRange[1]), 'kg'),
|
|
371
|
-
probability: null,
|
|
372
|
-
match_count: null,
|
|
373
|
-
match_info_label: '',
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
formatEggSearchTextLine(item) {
|
|
377
|
-
const card = this.formatEggSearchCard(item);
|
|
378
|
-
return `${card.name} (#${card.id}) — ${card.height_label} / ${card.weight_label} · ${card.egg_groups_label}`;
|
|
379
|
-
}
|
|
380
344
|
mergeCardsByName(perfect, ranged) {
|
|
381
345
|
const perfectMap = new Map();
|
|
382
346
|
const rangedMap = new Map();
|
|
@@ -552,26 +516,6 @@ class EggService {
|
|
|
552
516
|
}
|
|
553
517
|
return lines.join('\n');
|
|
554
518
|
}
|
|
555
|
-
buildEggSearchText(heightMeters, weight, results, heightDisplay) {
|
|
556
|
-
const cond = [];
|
|
557
|
-
if (heightMeters != null)
|
|
558
|
-
cond.push(`身高=${heightDisplay || `${formatNumber(heightMeters)}m`}`);
|
|
559
|
-
if (weight != null)
|
|
560
|
-
cond.push(`体重=${weight}kg`);
|
|
561
|
-
const condStr = cond.join(' + ') || '当前条件';
|
|
562
|
-
const items = Array.isArray(results?.items) ? results.items : [];
|
|
563
|
-
if (!items.length)
|
|
564
|
-
return `❌ 未找到符合 ${condStr} 的精灵。`;
|
|
565
|
-
const total = results?.total ?? items.length;
|
|
566
|
-
const lines = [`✅ 符合 ${condStr} 的精灵(共 ${total} 只):`];
|
|
567
|
-
items.slice(0, 10).forEach((item, index) => {
|
|
568
|
-
lines.push(` ${index + 1}. ${this.formatEggSearchTextLine(item)}`);
|
|
569
|
-
});
|
|
570
|
-
if (results?.has_more) {
|
|
571
|
-
lines.push(` ... 还有更多结果,可尝试更精确的尺寸或等待后续分页支持。`);
|
|
572
|
-
}
|
|
573
|
-
return lines.join('\n');
|
|
574
|
-
}
|
|
575
519
|
buildSearchText(pet) {
|
|
576
520
|
const egs = this.getEggGroups(pet);
|
|
577
521
|
const compat = this.getCompatiblePets(pet);
|
|
@@ -585,6 +529,17 @@ class EggService {
|
|
|
585
529
|
lines.push('⚠️ 该精灵属于「未发现」蛋组,无法配种。');
|
|
586
530
|
return lines.join('\n');
|
|
587
531
|
}
|
|
532
|
+
buildSearchTextFromWiki(data) {
|
|
533
|
+
const lines = [
|
|
534
|
+
`🥚 ${data?.pet_name || '未知精灵'} (#${data?.pet_id || '-'})`,
|
|
535
|
+
`属性:${data?.type_label || '未知'}`,
|
|
536
|
+
`蛋组:${data?.egg_groups_label || '暂无蛋组数据'}`,
|
|
537
|
+
`可配种精灵数:${data?.total_compatible || 0}`,
|
|
538
|
+
];
|
|
539
|
+
if (data?.is_undiscovered)
|
|
540
|
+
lines.push('⚠️ 该精灵属于「未发现」蛋组,无法配种。');
|
|
541
|
+
return lines.join('\n');
|
|
542
|
+
}
|
|
588
543
|
buildCandidatesText(keyword, candidates) {
|
|
589
544
|
const lines = [`🔍 「${keyword}」匹配到 ${candidates.length} 只精灵,请精确输入:`];
|
|
590
545
|
candidates.slice(0, 10).forEach((p, i) => {
|
|
@@ -683,6 +638,120 @@ class EggService {
|
|
|
683
638
|
copyright: 'Koishi & WeGame 洛克王国插件',
|
|
684
639
|
};
|
|
685
640
|
}
|
|
641
|
+
buildSearchDataFromWiki(pet, compatibleByGroup = {}) {
|
|
642
|
+
const eggGroups = this.wikiEggGroups(pet);
|
|
643
|
+
const eggGroupIds = eggGroups.map(group => group.id);
|
|
644
|
+
const eggGroupLabels = Object.fromEntries(eggGroups.map(group => [group.id, group.name]));
|
|
645
|
+
const seen = new Set();
|
|
646
|
+
let totalCompatible = 0;
|
|
647
|
+
const sections = eggGroups.map(group => {
|
|
648
|
+
const isUndiscovered = group.id === 1 || group.name.includes('未发现');
|
|
649
|
+
if (isUndiscovered) {
|
|
650
|
+
return {
|
|
651
|
+
id: 1,
|
|
652
|
+
label: '未发现',
|
|
653
|
+
desc: '不能和任何精灵生蛋,多用于传说中的精灵',
|
|
654
|
+
count: 0,
|
|
655
|
+
members: [],
|
|
656
|
+
has_more: false,
|
|
657
|
+
total: 0,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
const rawMembers = compatibleByGroup[String(group.id)] || [];
|
|
661
|
+
const members = rawMembers
|
|
662
|
+
.filter(item => String(item?.pet_id ?? item?.id ?? '') !== String(pet?.pet_id ?? pet?.id ?? ''))
|
|
663
|
+
.map(item => {
|
|
664
|
+
const key = String(item?.pet_id ?? item?.id ?? item?.name ?? '');
|
|
665
|
+
if (key && !seen.has(key)) {
|
|
666
|
+
seen.add(key);
|
|
667
|
+
totalCompatible += 1;
|
|
668
|
+
}
|
|
669
|
+
return this.formatWikiMember(item);
|
|
670
|
+
});
|
|
671
|
+
return {
|
|
672
|
+
id: group.id,
|
|
673
|
+
label: group.name,
|
|
674
|
+
desc: '',
|
|
675
|
+
count: members.length,
|
|
676
|
+
members: members.slice(0, 30),
|
|
677
|
+
has_more: members.length > 30,
|
|
678
|
+
total: members.length,
|
|
679
|
+
};
|
|
680
|
+
});
|
|
681
|
+
const petId = pet?.pet_id ?? pet?.id ?? '-';
|
|
682
|
+
const height = pet?.body_size?.height || {};
|
|
683
|
+
const weight = pet?.body_size?.weight || {};
|
|
684
|
+
const attributes = pet?.attributes || {};
|
|
685
|
+
const maleRate = num(pet?.gender_ratio?.male_percent);
|
|
686
|
+
const femaleRate = num(pet?.gender_ratio?.female_percent);
|
|
687
|
+
const totalStats = num(attributes?.sum) ?? ['hp', 'physical_attack', 'magic_attack', 'physical_defense', 'magic_defense', 'speed']
|
|
688
|
+
.reduce((sum, key) => sum + (num(attributes?.[key]) || 0), 0);
|
|
689
|
+
return {
|
|
690
|
+
pet_name: pet?.name || '未知精灵',
|
|
691
|
+
pet_id: petId,
|
|
692
|
+
pet_icon: pet?.icon || pet?.small_icon || petIconUrl(petId),
|
|
693
|
+
pet_image: pet?.small_icon || pet?.icon || petImageUrl(petId),
|
|
694
|
+
type_label: this.wikiTypeLabel(pet),
|
|
695
|
+
egg_groups_label: eggGroups.map(group => group.name).join(' / ') || '暂无蛋组数据',
|
|
696
|
+
egg_groups: eggGroupIds,
|
|
697
|
+
egg_group_labels: eggGroupLabels,
|
|
698
|
+
male_rate: maleRate,
|
|
699
|
+
female_rate: femaleRate,
|
|
700
|
+
hatch_label: '暂无数据',
|
|
701
|
+
weight_label: fmtRange(num(weight?.min_kg), num(weight?.max_kg), 'kg'),
|
|
702
|
+
height_label: fmtRange(num(height?.min_m), num(height?.max_m), 'm'),
|
|
703
|
+
total_compatible: totalCompatible,
|
|
704
|
+
is_undiscovered: eggGroups.some(group => group.id === 1 || group.name.includes('未发现')),
|
|
705
|
+
egg_group_sections: sections,
|
|
706
|
+
total_stats: totalStats,
|
|
707
|
+
egg_details: { has_data: false },
|
|
708
|
+
commandHint: '数据来自新版 Wiki;接口不可用时自动回退本地查蛋',
|
|
709
|
+
copyright: 'Koishi & WeGame 洛克王国插件',
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
wikiEggGroups(pet) {
|
|
713
|
+
const groups = Array.isArray(pet?.egg_groups) ? pet.egg_groups : [];
|
|
714
|
+
const normalized = groups
|
|
715
|
+
.map((group) => {
|
|
716
|
+
if (group && typeof group === 'object') {
|
|
717
|
+
const name = String(group?.name || group?.label || '').trim();
|
|
718
|
+
const id = group?.id ?? group?.group_id ?? (name.includes('未发现') ? 1 : name);
|
|
719
|
+
return name ? { id, name } : null;
|
|
720
|
+
}
|
|
721
|
+
const name = String(group || '').trim();
|
|
722
|
+
return name ? { id: name.includes('未发现') ? 1 : name, name } : null;
|
|
723
|
+
})
|
|
724
|
+
.filter(Boolean);
|
|
725
|
+
if (normalized.length)
|
|
726
|
+
return normalized;
|
|
727
|
+
const ids = Array.isArray(pet?.egg_group_ids) ? pet.egg_group_ids : [];
|
|
728
|
+
const names = Array.isArray(pet?.egg_group_names) ? pet.egg_group_names : [];
|
|
729
|
+
return names.map((rawName, index) => {
|
|
730
|
+
const name = String(rawName || '').trim();
|
|
731
|
+
return {
|
|
732
|
+
id: ids[index] ?? (name.includes('未发现') ? 1 : name),
|
|
733
|
+
name,
|
|
734
|
+
};
|
|
735
|
+
}).filter(group => group.name);
|
|
736
|
+
}
|
|
737
|
+
wikiTypeLabel(pet) {
|
|
738
|
+
const typeNames = Array.isArray(pet?.type_names) ? pet.type_names.filter(Boolean) : [];
|
|
739
|
+
if (typeNames.length)
|
|
740
|
+
return typeNames.join(' / ');
|
|
741
|
+
const types = Array.isArray(pet?.types)
|
|
742
|
+
? pet.types.map((type) => type?.name || type).filter(Boolean)
|
|
743
|
+
: [];
|
|
744
|
+
return types.length ? types.join(' / ') : '未知';
|
|
745
|
+
}
|
|
746
|
+
formatWikiMember(item) {
|
|
747
|
+
const groups = this.wikiEggGroups(item);
|
|
748
|
+
return {
|
|
749
|
+
name: item?.name || '未知精灵',
|
|
750
|
+
id: item?.pet_id ?? item?.id ?? '-',
|
|
751
|
+
type_label: this.wikiTypeLabel(item),
|
|
752
|
+
egg_groups_label: groups.map(group => group.name).join(' / ') || '暂无蛋组数据',
|
|
753
|
+
};
|
|
754
|
+
}
|
|
686
755
|
buildPairData(a, b) {
|
|
687
756
|
const ev = this.evaluatePair(a, b);
|
|
688
757
|
const makePetCard = (p) => ({
|
|
@@ -748,7 +817,10 @@ class EggService {
|
|
|
748
817
|
conditions.push(`体重 ${weight} kg`);
|
|
749
818
|
const groups = this.sizeApiResultGroups(results);
|
|
750
819
|
const [perfect, ranged] = this.mergeCardsByName(groups.exact.map((item) => this.formatSizeApiCard(item)), groups.candidates.map((item) => this.formatSizeApiCard(item)));
|
|
751
|
-
const
|
|
820
|
+
const poolName = results?.query?.pool && typeof results.query.pool === 'object'
|
|
821
|
+
? results.query.pool.name
|
|
822
|
+
: '';
|
|
823
|
+
const searchMode = results?.searchMode || poolName || '';
|
|
752
824
|
const queryLabel = `${conditions.join(' / ') || '尺寸反查'}${searchMode ? ` · 模式 ${searchMode}` : ''}`;
|
|
753
825
|
return {
|
|
754
826
|
query_label: queryLabel,
|
|
@@ -760,28 +832,8 @@ class EggService {
|
|
|
760
832
|
copyright: 'Koishi & WeGame 洛克王国插件',
|
|
761
833
|
};
|
|
762
834
|
}
|
|
763
|
-
buildEggSearchData(heightMeters, weight, results, heightDisplay) {
|
|
764
|
-
const conditions = [];
|
|
765
|
-
if (heightMeters != null)
|
|
766
|
-
conditions.push(`身高 ${heightDisplay || `${formatNumber(heightMeters)} m`}`);
|
|
767
|
-
if (weight != null)
|
|
768
|
-
conditions.push(`体重 ${weight} kg`);
|
|
769
|
-
const cards = (Array.isArray(results?.items) ? results.items : []).map((item) => this.formatEggSearchCard(item));
|
|
770
|
-
const pageNo = num(results?.page_no);
|
|
771
|
-
const totalPages = num(results?.total_pages);
|
|
772
|
-
const pageLabel = pageNo && totalPages ? ` · 第 ${pageNo}/${totalPages} 页` : '';
|
|
773
|
-
return {
|
|
774
|
-
query_label: `${conditions.join(' / ') || '孵蛋反查'}${pageLabel}`,
|
|
775
|
-
perfect_matches: cards,
|
|
776
|
-
range_matches: [],
|
|
777
|
-
total_count: results?.total ?? cards.length,
|
|
778
|
-
has_results: cards.length > 0,
|
|
779
|
-
commandHint: '洛克查蛋 <精灵名> | 洛克查蛋 0.18m 1.5kg | 洛克配种 <父体> <母体>',
|
|
780
|
-
copyright: 'Koishi & WeGame 洛克王国插件',
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
835
|
buildEggDetails(breeding) {
|
|
784
|
-
if (!breeding)
|
|
836
|
+
if (!breeding || !Object.keys(breeding).length)
|
|
785
837
|
return { has_data: false };
|
|
786
838
|
const baseProb = breeding.egg_base_glass_prob_array;
|
|
787
839
|
const addProb = breeding.egg_add_glass_prob_array;
|