@nonz250/ai-rotom 0.1.0 → 1.0.0
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/THIRD_PARTY_LICENSES.md +48 -0
- package/dist/index.mjs +1696 -329
- package/package.json +8 -3
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
5
9
|
//#region \0rolldown/runtime.js
|
|
6
10
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
7
11
|
//#endregion
|
|
@@ -203,6 +207,97 @@ function applyDefensiveOverrides(baseMultiplier, attackingType, context) {
|
|
|
203
207
|
if (abilityId !== void 0 && FILTER_LIKE_ABILITIES.has(abilityId) && multiplier >= SUPER_EFFECTIVE_THRESHOLD) multiplier *= FILTER_SUPER_EFFECTIVE_MULTIPLIER;
|
|
204
208
|
return multiplier;
|
|
205
209
|
}
|
|
210
|
+
/** ??? タイプは計算対象から除外するためのマーカー */
|
|
211
|
+
const UNKNOWN_TYPE_NAME$1 = "???";
|
|
212
|
+
/** 偶奇判定に使う剰余の除数 (中央値計算で偶数長を判定するため) */
|
|
213
|
+
const EVEN_ODD_MODULUS = 2;
|
|
214
|
+
/** 中央値計算の偶数長時に合計を半分にするための除数 */
|
|
215
|
+
const MEDIAN_AVERAGE_DIVISOR = 2;
|
|
216
|
+
/**
|
|
217
|
+
* 単体ポケモンのタイプ構成に対する全攻撃タイプの相性を分類する。
|
|
218
|
+
* 倍率 >= 2 を weaknesses、< 1 を resistances、0 を immunities に振り分ける。
|
|
219
|
+
*
|
|
220
|
+
* `context` を渡すと特性 (Levitate / Filter 等) を加味した補正を適用する。
|
|
221
|
+
* 省略時は純粋なタイプ相性のみで分類する。
|
|
222
|
+
*/
|
|
223
|
+
function classifyPokemonTypeMatchups(pokemonTypes, gen, context = {}) {
|
|
224
|
+
const weaknesses = [];
|
|
225
|
+
const resistances = [];
|
|
226
|
+
const immunities = [];
|
|
227
|
+
const defenderTypes = pokemonTypes;
|
|
228
|
+
for (const attackType of gen.types) {
|
|
229
|
+
if (attackType.name === UNKNOWN_TYPE_NAME$1) continue;
|
|
230
|
+
const multiplier = applyDefensiveOverrides(calculateTypeEffectiveness(gen, attackType.name, defenderTypes), attackType.name, context);
|
|
231
|
+
if (multiplier === 0) immunities.push(attackType.name);
|
|
232
|
+
else if (multiplier >= 2) weaknesses.push({
|
|
233
|
+
type: attackType.name,
|
|
234
|
+
multiplier
|
|
235
|
+
});
|
|
236
|
+
else if (multiplier < 1) resistances.push({
|
|
237
|
+
type: attackType.name,
|
|
238
|
+
multiplier
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
weaknesses,
|
|
243
|
+
resistances,
|
|
244
|
+
immunities
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* パーティ全メンバーの「弱点タイプ」のユニーク集合を返す。
|
|
249
|
+
* あるタイプに対して 2 倍以上の弱点を持つメンバーが 1 体でもいれば含まれる。
|
|
250
|
+
*/
|
|
251
|
+
function collectPartyWeaknessTypes(memberTypes, gen) {
|
|
252
|
+
const result = /* @__PURE__ */ new Set();
|
|
253
|
+
for (const types of memberTypes) {
|
|
254
|
+
const { weaknesses } = classifyPokemonTypeMatchups(types, gen);
|
|
255
|
+
for (const w of weaknesses) result.add(w.type);
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* パーティ全メンバーの「耐性タイプ (半減・無効)」のユニーク集合を返す。
|
|
261
|
+
* あるタイプに対して半減以下の耐性を持つメンバーが 1 体でもいれば含まれる。
|
|
262
|
+
*/
|
|
263
|
+
function collectPartyResistanceTypes(memberTypes, gen) {
|
|
264
|
+
const result = /* @__PURE__ */ new Set();
|
|
265
|
+
for (const types of memberTypes) {
|
|
266
|
+
const { resistances, immunities } = classifyPokemonTypeMatchups(types, gen);
|
|
267
|
+
for (const r of resistances) result.add(r.type);
|
|
268
|
+
for (const t of immunities) result.add(t);
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 数値配列の min / max / mean / median を返す。
|
|
274
|
+
* 空配列は全て 0 を返す (比較ツールで差分 0 として扱うためのフォールバック)。
|
|
275
|
+
*/
|
|
276
|
+
function computeNumericStats(values) {
|
|
277
|
+
if (values.length === 0) return {
|
|
278
|
+
min: 0,
|
|
279
|
+
max: 0,
|
|
280
|
+
mean: 0,
|
|
281
|
+
median: 0
|
|
282
|
+
};
|
|
283
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
284
|
+
const min = sorted[0];
|
|
285
|
+
const max = sorted[sorted.length - 1];
|
|
286
|
+
const mean = sorted.reduce((acc, v) => acc + v, 0) / sorted.length;
|
|
287
|
+
const mid = Math.floor(sorted.length / EVEN_ODD_MODULUS);
|
|
288
|
+
return {
|
|
289
|
+
min,
|
|
290
|
+
max,
|
|
291
|
+
mean,
|
|
292
|
+
median: sorted.length % EVEN_ODD_MODULUS === 1 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / MEDIAN_AVERAGE_DIVISOR
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 種族値 6 つの合計 (BST, base stats total)。
|
|
297
|
+
*/
|
|
298
|
+
function baseStatsTotal(stats) {
|
|
299
|
+
return stats.hp + stats.atk + stats.def + stats.spa + stats.spd + stats.spe;
|
|
300
|
+
}
|
|
206
301
|
//#endregion
|
|
207
302
|
//#region ../../shared/src/analysis/offensive-ability-overrides.ts
|
|
208
303
|
/**
|
|
@@ -312,6 +407,39 @@ const conditionsSchema = z.object({
|
|
|
312
407
|
isAuroraVeil: z.boolean().optional().describe("オーロラベール"),
|
|
313
408
|
isCriticalHit: z.boolean().optional().describe("急所")
|
|
314
409
|
});
|
|
410
|
+
/** メモの最大文字数。 */
|
|
411
|
+
const MAX_PARTY_MEMO_LENGTH = 4e3;
|
|
412
|
+
const nameField$1 = z.string().min(1, { message: "名前は 1 文字以上で指定してください。" }).max(100, { message: `名前は 100 文字以下で指定してください。` });
|
|
413
|
+
const optionalNameField = nameField$1.optional();
|
|
414
|
+
/**
|
|
415
|
+
* パーティに所属する 1 匹分の入力スキーマ。
|
|
416
|
+
*/
|
|
417
|
+
const partyMemberSchema = z.object({
|
|
418
|
+
name: nameField$1.describe("ポケモン名 (日本語 or 英語)。"),
|
|
419
|
+
nature: optionalNameField.describe("性格名 (日本語 or 英語)。"),
|
|
420
|
+
ability: optionalNameField.describe("特性名 (日本語 or 英語)。"),
|
|
421
|
+
item: optionalNameField.describe("持ち物名 (日本語 or 英語)。"),
|
|
422
|
+
evs: evsSchema.optional().describe("能力ポイント (SP) の配分。"),
|
|
423
|
+
moves: z.array(nameField$1).max(4, { message: `技は 4 個までです。` }).optional().describe("技リスト (日本語 or 英語、最大 4)。")
|
|
424
|
+
});
|
|
425
|
+
const isoDateTimeField = z.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "ISO 8601 形式の日時文字列で指定してください。" });
|
|
426
|
+
/**
|
|
427
|
+
* 1 パーティ分の入力スキーマ。
|
|
428
|
+
*/
|
|
429
|
+
const partySchema = z.object({
|
|
430
|
+
name: z.string().min(1, { message: "パーティ名は 1 文字以上で指定してください。" }).max(50, { message: `パーティ名は 50 文字以下で指定してください。` }).describe("パーティの識別子。"),
|
|
431
|
+
memo: z.string().max(MAX_PARTY_MEMO_LENGTH, { message: `メモは ${MAX_PARTY_MEMO_LENGTH} 文字以下で指定してください。` }).optional().describe("自由記述メモ。"),
|
|
432
|
+
members: z.array(partyMemberSchema).min(1, { message: `パーティには 1 匹以上を含めてください。` }).max(6, { message: `パーティには 6 匹までしか含められません。` }).describe("1〜6 匹のメンバー。"),
|
|
433
|
+
createdAt: isoDateTimeField.describe("作成日時 (ISO 8601)。"),
|
|
434
|
+
updatedAt: isoDateTimeField.describe("更新日時 (ISO 8601)。")
|
|
435
|
+
});
|
|
436
|
+
/**
|
|
437
|
+
* `~/.ai-rotom/parties.json` 全体のスキーマ。
|
|
438
|
+
*/
|
|
439
|
+
const partiesFileSchema = z.object({
|
|
440
|
+
schemaVersion: z.number().int().positive().describe("パーティファイルの schemaVersion。"),
|
|
441
|
+
parties: z.array(partySchema).describe("登録済みパーティの一覧。")
|
|
442
|
+
});
|
|
315
443
|
//#endregion
|
|
316
444
|
//#region ../../node_modules/@smogon/calc/dist/util.js
|
|
317
445
|
var require_util$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -45129,7 +45257,7 @@ function toSmogonBoosts(boosts) {
|
|
|
45129
45257
|
* @smogon/calc の Specie 型は types を文字列 union のタプル ([TypeName] | [TypeName, TypeName]) として
|
|
45130
45258
|
* 厳密に定義しているが、PokemonEntry 側は string[] で保持するため、呼び出し側でキャストする。
|
|
45131
45259
|
*/
|
|
45132
|
-
function buildSpeciesOverrides$
|
|
45260
|
+
function buildSpeciesOverrides$2(entry) {
|
|
45133
45261
|
return {
|
|
45134
45262
|
types: entry.types,
|
|
45135
45263
|
baseStats: entry.baseStats
|
|
@@ -45155,7 +45283,7 @@ function buildPokemonOptions(input, natureEn, abilityEn, itemEn, pokemonEntry) {
|
|
|
45155
45283
|
item: itemEn,
|
|
45156
45284
|
status: input.status ?? ""
|
|
45157
45285
|
};
|
|
45158
|
-
if (pokemonEntry !== void 0) baseOptions.overrides = buildSpeciesOverrides$
|
|
45286
|
+
if (pokemonEntry !== void 0) baseOptions.overrides = buildSpeciesOverrides$2(pokemonEntry);
|
|
45159
45287
|
return baseOptions;
|
|
45160
45288
|
}
|
|
45161
45289
|
//#endregion
|
|
@@ -45205,8 +45333,8 @@ function toPercent(value, maxHP) {
|
|
|
45205
45333
|
}
|
|
45206
45334
|
//#endregion
|
|
45207
45335
|
//#region ../../shared/src/calc/damage-calculator.ts
|
|
45208
|
-
const CHAMPIONS_GEN_NUM$
|
|
45209
|
-
const DEFAULT_NATURE_EN$
|
|
45336
|
+
const CHAMPIONS_GEN_NUM$10 = 0;
|
|
45337
|
+
const DEFAULT_NATURE_EN$2 = "Serious";
|
|
45210
45338
|
function buildTypeMetrics(gen, move, attacker, defender) {
|
|
45211
45339
|
const moveType = move.type;
|
|
45212
45340
|
const typeMultiplier = calculateTypeEffectiveness(gen, moveType, defender.types);
|
|
@@ -45328,7 +45456,7 @@ var DamageCalculatorAdapter = class {
|
|
|
45328
45456
|
};
|
|
45329
45457
|
}
|
|
45330
45458
|
getGen() {
|
|
45331
|
-
return import_dist.Generations.get(CHAMPIONS_GEN_NUM$
|
|
45459
|
+
return import_dist.Generations.get(CHAMPIONS_GEN_NUM$10);
|
|
45332
45460
|
}
|
|
45333
45461
|
get pokemonResolver() {
|
|
45334
45462
|
return this.resolvers.pokemon;
|
|
@@ -45340,7 +45468,7 @@ var DamageCalculatorAdapter = class {
|
|
|
45340
45468
|
return this.resolvers.nature;
|
|
45341
45469
|
}
|
|
45342
45470
|
resolveNature(nature) {
|
|
45343
|
-
if (nature === void 0) return DEFAULT_NATURE_EN$
|
|
45471
|
+
if (nature === void 0) return DEFAULT_NATURE_EN$2;
|
|
45344
45472
|
return resolveNameWithFallback(this.resolvers.nature, nature, "性格");
|
|
45345
45473
|
}
|
|
45346
45474
|
};
|
|
@@ -45411,6 +45539,62 @@ ai-rotom はポケモンチャンピオンズ (Pokemon Champions) の対戦ア
|
|
|
45411
45539
|
- 計算・対面分析系ツール (calculate_damage_single / calculate_damage_all_moves / calculate_damage_party_matchup / analyze_damage_range / analyze_matchup / analyze_selection / find_counters) を呼ぶ前に、攻撃側・防御側の ability / item を確認してから指定すること。
|
|
45412
45540
|
- 省略時の挙動: ability は通常特性 (pokemon.json の abilities[0]) が自動設定され、item は持ち物なし扱いとなる。そのためメガシンカ・こだわり系・半減きのみ・ちからのハチマキ 等が反映されず、実戦想定の build と乖離した結果になる。
|
|
45413
45541
|
- 正確な計算のためには ability / item を明示的に指定することを強く推奨する。
|
|
45542
|
+
|
|
45543
|
+
## パーティデータの扱い
|
|
45544
|
+
|
|
45545
|
+
- セッション開始時 (初回ユーザー発話への応答前) に必ず list_parties を呼び、保存済みパーティの名前一覧を把握すること。
|
|
45546
|
+
- ユーザーが「メインパ」「ドラゴン軸」等の保存名に言及したら load_party で詳細を取得し、分析ツールに渡すこと。
|
|
45547
|
+
- ユーザーが新規構築を説明した際は「保存しますか」と確認し、同意があれば save_party を呼ぶこと。
|
|
45548
|
+
- パーティの削除依頼は delete_party を使うこと。
|
|
45549
|
+
- 起動時にパーティ詳細まで自動読み込みしないこと (トークン消費を抑えるため、詳細は都度 load_party で取得する)。
|
|
45550
|
+
|
|
45551
|
+
## パーティ登録の対話スタイル
|
|
45552
|
+
|
|
45553
|
+
ユーザーが「パーティを保存したい」「構築を覚えて」等と依頼した場合:
|
|
45554
|
+
|
|
45555
|
+
### テキスト一括投入の場合 (ケース A)
|
|
45556
|
+
|
|
45557
|
+
- ユーザーが Showdown 風 or ポケソルテキストを貼り付けた → import_party_from_text を呼ぶ (原文をそのまま渡す)。
|
|
45558
|
+
- ユーザーがゲーム内画面のスクショを添付した → 画像から build を読み取り、下記の対話ケース (B) と同じ手順でポケソルテキストに整理してから import_party_from_text を呼ぶ。
|
|
45559
|
+
|
|
45560
|
+
### 対話で埋める場合 (ケース B)
|
|
45561
|
+
|
|
45562
|
+
- ユーザーがテキストもスクショも提供しない → AI が段階的に質問する。
|
|
45563
|
+
- 1 匹ずつ以下の順で聞く (ユーザーが知っている情報から埋める):
|
|
45564
|
+
1. ポケモン名 (日本語 or 英語)
|
|
45565
|
+
2. 性格 (候補を 4-5 個提示: いじっぱり / ようき / ひかえめ / おくびょう / ずぶとい など)
|
|
45566
|
+
3. 特性 (該当ポケモンの候補を提示)
|
|
45567
|
+
4. もちもの (省略可能、候補があれば提示)
|
|
45568
|
+
5. 技 4 つ
|
|
45569
|
+
6. SP 配分 (省略時は無振り 0、指定あれば各 0〜32 / 合計 0〜66 で受け付け)
|
|
45570
|
+
|
|
45571
|
+
### 整理ステップ (重要)
|
|
45572
|
+
|
|
45573
|
+
- 対話で情報が揃ったら、必ずポケソルテキスト形式にまとめて表示し、ユーザーに確認を取ること:
|
|
45574
|
+
|
|
45575
|
+
例:
|
|
45576
|
+
ガブリアス @ こだわりスカーフ
|
|
45577
|
+
特性: さめはだ
|
|
45578
|
+
能力補正: いじっぱり
|
|
45579
|
+
170(2)-200(32)-115(0)-90(0)-100(0)-167(32)
|
|
45580
|
+
じしん / ドラゴンクロー / つのドリル / いわなだれ
|
|
45581
|
+
|
|
45582
|
+
- 実数値が不明な場合は calculate_stats を呼んで補完する (パーサー仕様上、実数値行は省略可能だが、ユーザー確認用に含めることを推奨)。
|
|
45583
|
+
- 複数匹の場合は空行区切りで並べる。
|
|
45584
|
+
- ユーザー確認後 import_party_from_text(text, name, memo) を呼ぶ。
|
|
45585
|
+
- パーサーがエラーを返した場合は、原因を提示してユーザーに修正を確認する。
|
|
45586
|
+
|
|
45587
|
+
### 質問の書き方ルール
|
|
45588
|
+
|
|
45589
|
+
- 質問は短く、候補があれば列挙する (「性格はどうしますか? いじっぱり / ようき / ひかえめ」のような形式)。
|
|
45590
|
+
- 一度に 1 項目だけ聞く (複数同時の質問は避ける)。
|
|
45591
|
+
- ユーザーが「後で決める」と言った項目はデフォルト値で埋める (性格=まじめ、特性=基本特性、SP=無振り 等)。
|
|
45592
|
+
- 不明な項目は tool 呼び出しで確認する (例: 覚える技 → get_learnset)。
|
|
45593
|
+
|
|
45594
|
+
### 絶対に守ること
|
|
45595
|
+
|
|
45596
|
+
- 対話で得た情報を JSON 化して save_party を直接呼ばない (ハルシネーションリスク軽減のため必ずポケソルテキスト経由)。
|
|
45597
|
+
- ユーザー確認なしに save / import を実行しない。
|
|
45414
45598
|
`.trim();
|
|
45415
45599
|
//#endregion
|
|
45416
45600
|
//#region ../../data/champions/abilities.json
|
|
@@ -76743,9 +76927,9 @@ const itemNameResolver = new NameResolver(toNameEntries(items_default));
|
|
|
76743
76927
|
const moveNameResolver = new NameResolver(toNameEntries(moves_default));
|
|
76744
76928
|
//#endregion
|
|
76745
76929
|
//#region src/tools/info/ability-info.ts
|
|
76746
|
-
const TOOL_NAME$
|
|
76747
|
-
const TOOL_DESCRIPTION$
|
|
76748
|
-
const inputSchema$
|
|
76930
|
+
const TOOL_NAME$20 = "get_ability_info";
|
|
76931
|
+
const TOOL_DESCRIPTION$20 = "ポケモンの特性の詳細情報(効果説明)を取得する。ポケモンチャンピオンズで使える特性のみ返す。対戦でポケモンの特性を理解したいときに使用する。";
|
|
76932
|
+
const inputSchema$17 = { name: z.string().describe("特性名(日本語 or 英語)") };
|
|
76749
76933
|
/**
|
|
76750
76934
|
* 特性名を英語に解決する。日本語名・英語名どちらでも受け付ける。
|
|
76751
76935
|
*/
|
|
@@ -76758,7 +76942,7 @@ function resolveAbilityNameEn$1(input) {
|
|
|
76758
76942
|
throw new Error(`特性「${input}」が見つかりません。${suggestionMessage}`);
|
|
76759
76943
|
}
|
|
76760
76944
|
function registerAbilityInfoTool(server) {
|
|
76761
|
-
server.tool(TOOL_NAME$
|
|
76945
|
+
server.tool(TOOL_NAME$20, TOOL_DESCRIPTION$20, inputSchema$17, async (args) => {
|
|
76762
76946
|
try {
|
|
76763
76947
|
const abilityId = toDataId(resolveAbilityNameEn$1(args.name));
|
|
76764
76948
|
const entry = abilitiesById.get(abilityId);
|
|
@@ -76786,6 +76970,504 @@ function registerAbilityInfoTool(server) {
|
|
|
76786
76970
|
});
|
|
76787
76971
|
}
|
|
76788
76972
|
//#endregion
|
|
76973
|
+
//#region src/tools/analysis/party-coverage.ts
|
|
76974
|
+
const CHAMPIONS_GEN_NUM$9 = 0;
|
|
76975
|
+
/** 複合タイプを構成するタイプ数 */
|
|
76976
|
+
const DUAL_TYPE_COUNT = 2;
|
|
76977
|
+
/** 複合タイプ集合キーのセパレータ(タイプ名に現れない文字) */
|
|
76978
|
+
const DUAL_TYPE_KEY_SEPARATOR = "/";
|
|
76979
|
+
/** `dualTypeCoverage` の `examplePokemon` に収める最大件数 */
|
|
76980
|
+
const MAX_EXAMPLE_POKEMON = 3;
|
|
76981
|
+
/** ステータス技(攻撃タイプから除外するため) */
|
|
76982
|
+
const STATUS_CATEGORY$3 = "Status";
|
|
76983
|
+
const TOOL_NAME$19 = "analyze_party_coverage";
|
|
76984
|
+
const TOOL_DESCRIPTION$19 = "パーティの攻撃カバレッジを分析する。各防御タイプ(18種)に対して、パーティのどの技が最も効果的かを算出し、抜群を取れないタイプを洗い出す。 `uncoveredTypes` は『抜群(>1 倍)を取れる技が 1 つも無い防御タイプ』を列挙する(等倍 1 倍も含む)。抜群倍率の内訳は `coverage[].maxMultiplier` を参照。 実在する複合タイプ(データ内に 1 匹以上存在する 2 タイプ組合せ)に対するカバレッジは `dualTypeCoverage` を参照。抜群を取れない複合タイプ数は `dualTypeUncoveredCount`。 攻撃側のタイプ変換系特性(Pixilate 等)は単一/複合カバレッジ双方に反映される。 ポケモンチャンピオンズ対応。";
|
|
76985
|
+
const inputSchema$16 = {
|
|
76986
|
+
myParty: z.array(pokemonSchema).describe("自分のパーティ(moves 未指定時は learnset 内の全攻撃技を候補にする)"),
|
|
76987
|
+
moves: z.record(z.string(), z.array(z.string())).optional().describe("ポケモン名(日本語 or 英語)をキーに技名配列を値とする map。省略時は learnset から全攻撃技を候補にする。")
|
|
76988
|
+
};
|
|
76989
|
+
/**
|
|
76990
|
+
* 1 メンバー分の「覚えている攻撃技 ID」を取得する。
|
|
76991
|
+
* moves 指定があればそれを使い、未指定時は learnset から category !== Status の技を全て拾う。
|
|
76992
|
+
*/
|
|
76993
|
+
function resolveAttackingMoveIds(pokemonEntry, explicitMoves) {
|
|
76994
|
+
if (explicitMoves !== void 0) {
|
|
76995
|
+
const result = [];
|
|
76996
|
+
for (const moveName of explicitMoves) {
|
|
76997
|
+
const moveId = toDataId(moveName);
|
|
76998
|
+
const move = movesById.get(moveId);
|
|
76999
|
+
if (move !== void 0 && move.category !== STATUS_CATEGORY$3) result.push(move);
|
|
77000
|
+
}
|
|
77001
|
+
return result;
|
|
77002
|
+
}
|
|
77003
|
+
const learnset = championsLearnsets[pokemonEntry.id];
|
|
77004
|
+
if (learnset === void 0) return [];
|
|
77005
|
+
const moves = [];
|
|
77006
|
+
for (const moveId of learnset) {
|
|
77007
|
+
const move = movesById.get(moveId);
|
|
77008
|
+
if (move !== void 0 && move.category !== STATUS_CATEGORY$3) moves.push(move);
|
|
77009
|
+
}
|
|
77010
|
+
return moves;
|
|
77011
|
+
}
|
|
77012
|
+
/**
|
|
77013
|
+
* 日本語・英語のどちらの名前でも英語名に解決する。
|
|
77014
|
+
* 未知の名前は undefined を返し、呼び出し側で silent ignore する。
|
|
77015
|
+
*
|
|
77016
|
+
* 未知の特性文字列でエラーにしないのは、party_coverage が
|
|
77017
|
+
* 「構築入力を緩く受け取る」UX を取っているため。
|
|
77018
|
+
* 未知の特性は単に override なし扱いとする。
|
|
77019
|
+
*/
|
|
77020
|
+
function resolveOptionalName$1(resolver, name) {
|
|
77021
|
+
if (name === void 0) return void 0;
|
|
77022
|
+
const english = resolver.toEnglish(name);
|
|
77023
|
+
if (english !== void 0) return english;
|
|
77024
|
+
if (resolver.hasEnglishName(name)) return name;
|
|
77025
|
+
}
|
|
77026
|
+
/**
|
|
77027
|
+
* ポケモン名を pokemon.json のエントリに解決する。
|
|
77028
|
+
*/
|
|
77029
|
+
function resolvePokemonEntry$4(name) {
|
|
77030
|
+
const englishName = pokemonNameResolver.toEnglish(name) ?? (pokemonNameResolver.hasEnglishName(name) ? name : null);
|
|
77031
|
+
if (englishName === null) {
|
|
77032
|
+
const suggestions = pokemonNameResolver.suggestSimilar(name);
|
|
77033
|
+
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
77034
|
+
throw new Error(`ポケモン「${name}」が見つかりません。${suggestionMessage}`);
|
|
77035
|
+
}
|
|
77036
|
+
const entry = pokemonById.get(toDataId(englishName));
|
|
77037
|
+
if (entry === void 0) throw new Error(`ポケモン「${name}」のデータが見つかりません。`);
|
|
77038
|
+
return entry;
|
|
77039
|
+
}
|
|
77040
|
+
/**
|
|
77041
|
+
* moves マップのキー(日本語 or 英語ポケモン名)を英語 ID に正規化する。
|
|
77042
|
+
*/
|
|
77043
|
+
function normalizeMovesMap(moves) {
|
|
77044
|
+
const result = /* @__PURE__ */ new Map();
|
|
77045
|
+
if (moves === void 0) return result;
|
|
77046
|
+
for (const [pokemonName, moveList] of Object.entries(moves)) {
|
|
77047
|
+
const entry = resolvePokemonEntry$4(pokemonName);
|
|
77048
|
+
result.set(entry.id, moveList);
|
|
77049
|
+
}
|
|
77050
|
+
return result;
|
|
77051
|
+
}
|
|
77052
|
+
/**
|
|
77053
|
+
* 攻撃タイプ → 単一防御タイプへの倍率を計算する。
|
|
77054
|
+
*/
|
|
77055
|
+
function getEffectivenessForDefenderType(attackTypeName, defenderTypeName, gen) {
|
|
77056
|
+
return calculateTypeEffectiveness(gen, attackTypeName, [defenderTypeName]);
|
|
77057
|
+
}
|
|
77058
|
+
/**
|
|
77059
|
+
* 攻撃タイプ → 複合防御タイプへの倍率を計算する。
|
|
77060
|
+
*/
|
|
77061
|
+
function getEffectivenessForDualTypes(attackTypeName, defenderTypes, gen) {
|
|
77062
|
+
return calculateTypeEffectiveness(gen, attackTypeName, defenderTypes);
|
|
77063
|
+
}
|
|
77064
|
+
/**
|
|
77065
|
+
* 実在する複合タイプ(データ内に 1 匹以上存在するタイプ組合せ)の集合を構築する。
|
|
77066
|
+
* 対称性解消のため、キーは英名辞書順の 2 タイプを `/` で連結した文字列とする。
|
|
77067
|
+
*
|
|
77068
|
+
* `examplePokemon` 用の代表ポケモンも同時に収集する:
|
|
77069
|
+
* - メガ進化・リージョンフォーム等の派生フォーム(`baseSpecies !== null`)は後置し、
|
|
77070
|
+
* ベース種族を優先表示する(同じ実体の重複を避けるため)
|
|
77071
|
+
* - 同一優先度内では英名の辞書順で安定化
|
|
77072
|
+
* - 先頭 `MAX_EXAMPLE_POKEMON` 件を採用
|
|
77073
|
+
*/
|
|
77074
|
+
function buildRealDualTypeMap(pokemon) {
|
|
77075
|
+
const accumulator = /* @__PURE__ */ new Map();
|
|
77076
|
+
for (const entry of pokemon) {
|
|
77077
|
+
if (entry.types.length !== DUAL_TYPE_COUNT) continue;
|
|
77078
|
+
const sortedTypes = [...entry.types].sort((a, b) => a.localeCompare(b));
|
|
77079
|
+
const key = `${sortedTypes[0]}${DUAL_TYPE_KEY_SEPARATOR}${sortedTypes[1]}`;
|
|
77080
|
+
const existing = accumulator.get(key);
|
|
77081
|
+
if (existing === void 0) accumulator.set(key, {
|
|
77082
|
+
types: sortedTypes,
|
|
77083
|
+
entries: [entry]
|
|
77084
|
+
});
|
|
77085
|
+
else existing.entries.push(entry);
|
|
77086
|
+
}
|
|
77087
|
+
const result = /* @__PURE__ */ new Map();
|
|
77088
|
+
for (const [key, { types, entries }] of accumulator) {
|
|
77089
|
+
const examplePokemon = [...entries].sort((a, b) => {
|
|
77090
|
+
const aIsForme = a.baseSpecies !== null ? 1 : 0;
|
|
77091
|
+
const bIsForme = b.baseSpecies !== null ? 1 : 0;
|
|
77092
|
+
if (aIsForme !== bIsForme) return aIsForme - bIsForme;
|
|
77093
|
+
return a.name.localeCompare(b.name);
|
|
77094
|
+
}).slice(0, MAX_EXAMPLE_POKEMON).map((entry) => pokemonNameResolver.toJapanese(entry.name) ?? entry.name);
|
|
77095
|
+
result.set(key, {
|
|
77096
|
+
types,
|
|
77097
|
+
examplePokemon
|
|
77098
|
+
});
|
|
77099
|
+
}
|
|
77100
|
+
return result;
|
|
77101
|
+
}
|
|
77102
|
+
/**
|
|
77103
|
+
* 候補の attacker で `bestAttackers` を更新する共通ロジック。
|
|
77104
|
+
*
|
|
77105
|
+
* - `candidate.multiplier > currentMax` の場合は bestAttackers をクリアして入れ替え、新しい max を返す
|
|
77106
|
+
* - タイの場合は同一ポケモンが未登録であれば追加する(multiplier > 0 のときのみ、0 倍無効は列挙しない)
|
|
77107
|
+
* - それ以外は現状維持
|
|
77108
|
+
*
|
|
77109
|
+
* bestAttackers は in-place で更新する。maxMultiplier は戻り値として返す。
|
|
77110
|
+
*/
|
|
77111
|
+
function updateBestAttackers(currentMax, bestAttackers, candidate) {
|
|
77112
|
+
if (candidate.multiplier > currentMax) {
|
|
77113
|
+
bestAttackers.length = 0;
|
|
77114
|
+
bestAttackers.push(candidate);
|
|
77115
|
+
return candidate.multiplier;
|
|
77116
|
+
}
|
|
77117
|
+
if (candidate.multiplier === currentMax && candidate.multiplier > 0) {
|
|
77118
|
+
if (!bestAttackers.some((ba) => ba.pokemon === candidate.pokemon)) bestAttackers.push(candidate);
|
|
77119
|
+
}
|
|
77120
|
+
return currentMax;
|
|
77121
|
+
}
|
|
77122
|
+
/**
|
|
77123
|
+
* パーティの攻撃カバレッジを計算する純関数。
|
|
77124
|
+
* MCP tool handler からも直接テストからも呼び出せる。
|
|
77125
|
+
*/
|
|
77126
|
+
function analyzePartyCoverage(args) {
|
|
77127
|
+
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$9);
|
|
77128
|
+
const movesMap = normalizeMovesMap(args.moves);
|
|
77129
|
+
const members = [];
|
|
77130
|
+
const attackingTypesSet = /* @__PURE__ */ new Set();
|
|
77131
|
+
for (const member of args.myParty) {
|
|
77132
|
+
const entry = resolvePokemonEntry$4(member.name);
|
|
77133
|
+
const rawAttackingMoves = resolveAttackingMoveIds(entry, movesMap.get(entry.id));
|
|
77134
|
+
const ability = resolveOptionalName$1(abilityNameResolver, member.ability);
|
|
77135
|
+
const attackingMoves = [];
|
|
77136
|
+
for (const move of rawAttackingMoves) {
|
|
77137
|
+
const effectiveType = applyOffensiveTypeOverride(move.type, move.category, ability);
|
|
77138
|
+
attackingTypesSet.add(effectiveType);
|
|
77139
|
+
attackingMoves.push({
|
|
77140
|
+
move,
|
|
77141
|
+
effectiveType
|
|
77142
|
+
});
|
|
77143
|
+
}
|
|
77144
|
+
members.push({
|
|
77145
|
+
entry,
|
|
77146
|
+
attackingMoves
|
|
77147
|
+
});
|
|
77148
|
+
}
|
|
77149
|
+
const attackingTypes = [];
|
|
77150
|
+
const typeJaMap = new Map(championsTypes.map((t) => [t.name, t.nameJa]));
|
|
77151
|
+
for (const typeName of attackingTypesSet) attackingTypes.push({
|
|
77152
|
+
type: typeName,
|
|
77153
|
+
nameJa: typeJaMap.get(typeName) ?? typeName
|
|
77154
|
+
});
|
|
77155
|
+
attackingTypes.sort((a, b) => a.type.localeCompare(b.type));
|
|
77156
|
+
const coverage = [];
|
|
77157
|
+
const uncoveredTypes = [];
|
|
77158
|
+
for (const defenderType of championsTypes) {
|
|
77159
|
+
let maxMultiplier = 0;
|
|
77160
|
+
const bestAttackers = [];
|
|
77161
|
+
for (const member of members) for (const { move, effectiveType } of member.attackingMoves) {
|
|
77162
|
+
const multiplier = getEffectivenessForDefenderType(effectiveType, defenderType.name, gen);
|
|
77163
|
+
const attacker = {
|
|
77164
|
+
pokemon: member.entry.name,
|
|
77165
|
+
move: move.name,
|
|
77166
|
+
multiplier
|
|
77167
|
+
};
|
|
77168
|
+
if (effectiveType !== move.type) attacker.effectiveType = effectiveType;
|
|
77169
|
+
maxMultiplier = updateBestAttackers(maxMultiplier, bestAttackers, attacker);
|
|
77170
|
+
}
|
|
77171
|
+
coverage.push({
|
|
77172
|
+
defenderType: defenderType.name,
|
|
77173
|
+
defenderTypeJa: defenderType.nameJa,
|
|
77174
|
+
maxMultiplier,
|
|
77175
|
+
bestAttackers
|
|
77176
|
+
});
|
|
77177
|
+
if (maxMultiplier <= 1) uncoveredTypes.push({
|
|
77178
|
+
type: defenderType.name,
|
|
77179
|
+
nameJa: defenderType.nameJa
|
|
77180
|
+
});
|
|
77181
|
+
}
|
|
77182
|
+
const dualTypeMap = buildRealDualTypeMap(championsPokemon);
|
|
77183
|
+
const dualTypeCoverage = [];
|
|
77184
|
+
let dualTypeUncoveredCount = 0;
|
|
77185
|
+
for (const { types, examplePokemon } of dualTypeMap.values()) {
|
|
77186
|
+
let maxMultiplier = 0;
|
|
77187
|
+
const bestAttackers = [];
|
|
77188
|
+
for (const member of members) for (const { move, effectiveType } of member.attackingMoves) {
|
|
77189
|
+
const multiplier = getEffectivenessForDualTypes(effectiveType, types, gen);
|
|
77190
|
+
const attacker = {
|
|
77191
|
+
pokemon: member.entry.name,
|
|
77192
|
+
move: move.name,
|
|
77193
|
+
multiplier
|
|
77194
|
+
};
|
|
77195
|
+
if (effectiveType !== move.type) attacker.effectiveType = effectiveType;
|
|
77196
|
+
maxMultiplier = updateBestAttackers(maxMultiplier, bestAttackers, attacker);
|
|
77197
|
+
}
|
|
77198
|
+
dualTypeCoverage.push({
|
|
77199
|
+
defenderTypes: types,
|
|
77200
|
+
defenderTypesJa: [typeJaMap.get(types[0]) ?? types[0], typeJaMap.get(types[1]) ?? types[1]],
|
|
77201
|
+
maxMultiplier,
|
|
77202
|
+
bestAttackers,
|
|
77203
|
+
examplePokemon
|
|
77204
|
+
});
|
|
77205
|
+
if (maxMultiplier <= 1) dualTypeUncoveredCount += 1;
|
|
77206
|
+
}
|
|
77207
|
+
dualTypeCoverage.sort((a, b) => {
|
|
77208
|
+
if (a.maxMultiplier !== b.maxMultiplier) return a.maxMultiplier - b.maxMultiplier;
|
|
77209
|
+
if (a.defenderTypes[0] !== b.defenderTypes[0]) return a.defenderTypes[0].localeCompare(b.defenderTypes[0]);
|
|
77210
|
+
return a.defenderTypes[1].localeCompare(b.defenderTypes[1]);
|
|
77211
|
+
});
|
|
77212
|
+
return {
|
|
77213
|
+
attackingTypes,
|
|
77214
|
+
coverage,
|
|
77215
|
+
uncoveredTypes,
|
|
77216
|
+
dualTypeCoverage,
|
|
77217
|
+
dualTypeUncoveredCount
|
|
77218
|
+
};
|
|
77219
|
+
}
|
|
77220
|
+
function registerPartyCoverageTool(server) {
|
|
77221
|
+
server.tool(TOOL_NAME$19, TOOL_DESCRIPTION$19, inputSchema$16, async (args) => {
|
|
77222
|
+
try {
|
|
77223
|
+
const output = analyzePartyCoverage(args);
|
|
77224
|
+
return { content: [{
|
|
77225
|
+
type: "text",
|
|
77226
|
+
text: JSON.stringify(output)
|
|
77227
|
+
}] };
|
|
77228
|
+
} catch (error) {
|
|
77229
|
+
const message = error instanceof Error ? error.message : "不明なエラーが発生しました";
|
|
77230
|
+
return {
|
|
77231
|
+
content: [{
|
|
77232
|
+
type: "text",
|
|
77233
|
+
text: JSON.stringify({ error: message })
|
|
77234
|
+
}],
|
|
77235
|
+
isError: true
|
|
77236
|
+
};
|
|
77237
|
+
}
|
|
77238
|
+
});
|
|
77239
|
+
}
|
|
77240
|
+
//#endregion
|
|
77241
|
+
//#region src/tools/analysis/compare-parties.ts
|
|
77242
|
+
const CHAMPIONS_GEN_NUM$8 = 0;
|
|
77243
|
+
/** 対戦に組めるパーティメンバーの上限 (ポケモンチャンピオンズ仕様) */
|
|
77244
|
+
const MAX_PARTY_SIZE = 6;
|
|
77245
|
+
/** 性格未指定時の既定 (無補正性格) */
|
|
77246
|
+
const DEFAULT_NATURE_EN$1 = "Serious";
|
|
77247
|
+
const TOOL_NAME$18 = "compare_parties";
|
|
77248
|
+
const TOOL_DESCRIPTION$18 = "2 つのパーティ (A / B) の統計差分を比較する。メンバー差分・タイプ分布・弱点/耐性/カバレッジ集合・素早さ分布・種族値合計の構造化データを 1 コールで返す。 パーティ改修案の比較や入れ替え検討に使用する。優劣判定は行わず、差分データのみを返す (解釈は AI 側の責務)。 moves は指定できないため、カバレッジ差分は learnset 全攻撃技ベースで評価される。ポケモンチャンピオンズ対応。";
|
|
77249
|
+
const labelsSchema = z.object({
|
|
77250
|
+
partyA: z.string().optional(),
|
|
77251
|
+
partyB: z.string().optional()
|
|
77252
|
+
}).optional().describe("表示用ラベル (例: { partyA: '現行', partyB: '改修案' })");
|
|
77253
|
+
const inputSchema$15 = {
|
|
77254
|
+
partyA: z.array(pokemonSchema).min(1).max(MAX_PARTY_SIZE).describe("比較対象のパーティ A"),
|
|
77255
|
+
partyB: z.array(pokemonSchema).min(1).max(MAX_PARTY_SIZE).describe("比較対象のパーティ B"),
|
|
77256
|
+
labels: labelsSchema
|
|
77257
|
+
};
|
|
77258
|
+
/**
|
|
77259
|
+
* ポケモン名を pokemon.json のエントリに解決する。
|
|
77260
|
+
* 未登録名は類似候補付きエラーを投げる。
|
|
77261
|
+
*/
|
|
77262
|
+
function resolvePokemonEntry$3(name) {
|
|
77263
|
+
const englishName = pokemonNameResolver.toEnglish(name) ?? (pokemonNameResolver.hasEnglishName(name) ? name : null);
|
|
77264
|
+
if (englishName === null) {
|
|
77265
|
+
const suggestions = pokemonNameResolver.suggestSimilar(name);
|
|
77266
|
+
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
77267
|
+
throw new Error(`ポケモン「${name}」が見つかりません。${suggestionMessage}`);
|
|
77268
|
+
}
|
|
77269
|
+
const entry = pokemonById.get(toDataId(englishName));
|
|
77270
|
+
if (entry === void 0) throw new Error(`ポケモン「${name}」のデータが見つかりません。`);
|
|
77271
|
+
return entry;
|
|
77272
|
+
}
|
|
77273
|
+
/**
|
|
77274
|
+
* 性格名を英語に解決する。省略時は無補正性格。
|
|
77275
|
+
*/
|
|
77276
|
+
function resolveNatureName$1(nature) {
|
|
77277
|
+
if (nature === void 0) return DEFAULT_NATURE_EN$1;
|
|
77278
|
+
const englishName = natureNameResolver.toEnglish(nature);
|
|
77279
|
+
if (englishName !== void 0) return englishName;
|
|
77280
|
+
if (natureNameResolver.hasEnglishName(nature)) return nature;
|
|
77281
|
+
const suggestions = natureNameResolver.suggestSimilar(nature);
|
|
77282
|
+
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
77283
|
+
throw new Error(`性格「${nature}」が見つかりません。${suggestionMessage}`);
|
|
77284
|
+
}
|
|
77285
|
+
/**
|
|
77286
|
+
* pokemon.json のエントリから @smogon/calc 用 overrides を組み立てる。
|
|
77287
|
+
*/
|
|
77288
|
+
function buildSpeciesOverrides$1(entry) {
|
|
77289
|
+
return {
|
|
77290
|
+
types: entry.types,
|
|
77291
|
+
baseStats: entry.baseStats
|
|
77292
|
+
};
|
|
77293
|
+
}
|
|
77294
|
+
/**
|
|
77295
|
+
* 入力ポケモンの素早さ実数値を @smogon/calc で算出する。
|
|
77296
|
+
* ランク補正・状態異常は加味しない (build としての素早さ比較が目的のため)。
|
|
77297
|
+
*/
|
|
77298
|
+
function calculateMemberSpeed(input, entry, gen) {
|
|
77299
|
+
const natureEn = resolveNatureName$1(input.nature);
|
|
77300
|
+
return new import_dist.Pokemon(gen, entry.name, {
|
|
77301
|
+
nature: natureEn,
|
|
77302
|
+
evs: { spe: input.evs?.spe ?? 0 },
|
|
77303
|
+
overrides: buildSpeciesOverrides$1(entry)
|
|
77304
|
+
}).stats.spe;
|
|
77305
|
+
}
|
|
77306
|
+
function toMemberRef(entry) {
|
|
77307
|
+
return {
|
|
77308
|
+
name: entry.name,
|
|
77309
|
+
nameJa: entry.nameJa ?? entry.name,
|
|
77310
|
+
types: [...entry.types],
|
|
77311
|
+
baseStatsTotal: baseStatsTotal(entry.baseStats)
|
|
77312
|
+
};
|
|
77313
|
+
}
|
|
77314
|
+
function resolveMembers(party) {
|
|
77315
|
+
return party.map((input) => {
|
|
77316
|
+
const entry = resolvePokemonEntry$3(input.name);
|
|
77317
|
+
return {
|
|
77318
|
+
input,
|
|
77319
|
+
entry,
|
|
77320
|
+
memberRef: toMemberRef(entry)
|
|
77321
|
+
};
|
|
77322
|
+
});
|
|
77323
|
+
}
|
|
77324
|
+
function partyBaseStatsTotal(members) {
|
|
77325
|
+
let total = 0;
|
|
77326
|
+
for (const m of members) total += m.memberRef.baseStatsTotal;
|
|
77327
|
+
return total;
|
|
77328
|
+
}
|
|
77329
|
+
function buildPartySummary(members, label, gen) {
|
|
77330
|
+
const speeds = members.map((m) => calculateMemberSpeed(m.input, m.entry, gen));
|
|
77331
|
+
return {
|
|
77332
|
+
label: label ?? null,
|
|
77333
|
+
members: members.map((m) => m.memberRef),
|
|
77334
|
+
baseStatsTotal: partyBaseStatsTotal(members),
|
|
77335
|
+
speedStats: computeNumericStats(speeds)
|
|
77336
|
+
};
|
|
77337
|
+
}
|
|
77338
|
+
function computeMemberDifferences(membersA, membersB) {
|
|
77339
|
+
const idsA = /* @__PURE__ */ new Map();
|
|
77340
|
+
for (const m of membersA) idsA.set(m.entry.id, m);
|
|
77341
|
+
const idsB = /* @__PURE__ */ new Map();
|
|
77342
|
+
for (const m of membersB) idsB.set(m.entry.id, m);
|
|
77343
|
+
const partyAOnly = [];
|
|
77344
|
+
const partyBOnly = [];
|
|
77345
|
+
const shared = [];
|
|
77346
|
+
for (const [id, member] of idsA) if (idsB.has(id)) shared.push(member.memberRef);
|
|
77347
|
+
else partyAOnly.push(member.memberRef);
|
|
77348
|
+
for (const [id, member] of idsB) if (!idsA.has(id)) partyBOnly.push(member.memberRef);
|
|
77349
|
+
return {
|
|
77350
|
+
partyAOnly,
|
|
77351
|
+
partyBOnly,
|
|
77352
|
+
shared
|
|
77353
|
+
};
|
|
77354
|
+
}
|
|
77355
|
+
function countTypes(members) {
|
|
77356
|
+
const counts = /* @__PURE__ */ new Map();
|
|
77357
|
+
for (const m of members) for (const t of m.entry.types) counts.set(t, (counts.get(t) ?? 0) + 1);
|
|
77358
|
+
return counts;
|
|
77359
|
+
}
|
|
77360
|
+
function computeTypeDistributionChanges(membersA, membersB) {
|
|
77361
|
+
const countsA = countTypes(membersA);
|
|
77362
|
+
const countsB = countTypes(membersB);
|
|
77363
|
+
const changes = [];
|
|
77364
|
+
for (const t of championsTypes) {
|
|
77365
|
+
const countA = countsA.get(t.name) ?? 0;
|
|
77366
|
+
const countB = countsB.get(t.name) ?? 0;
|
|
77367
|
+
changes.push({
|
|
77368
|
+
type: t.name,
|
|
77369
|
+
nameJa: t.nameJa,
|
|
77370
|
+
countA,
|
|
77371
|
+
countB,
|
|
77372
|
+
diff: countB - countA
|
|
77373
|
+
});
|
|
77374
|
+
}
|
|
77375
|
+
return changes;
|
|
77376
|
+
}
|
|
77377
|
+
function diffTypeSets(setA, setB) {
|
|
77378
|
+
const partyAOnly = [];
|
|
77379
|
+
const partyBOnly = [];
|
|
77380
|
+
const both = [];
|
|
77381
|
+
for (const type of setA) if (setB.has(type)) both.push(type);
|
|
77382
|
+
else partyAOnly.push(type);
|
|
77383
|
+
for (const type of setB) if (!setA.has(type)) partyBOnly.push(type);
|
|
77384
|
+
partyAOnly.sort();
|
|
77385
|
+
partyBOnly.sort();
|
|
77386
|
+
both.sort();
|
|
77387
|
+
return {
|
|
77388
|
+
partyAOnly,
|
|
77389
|
+
partyBOnly,
|
|
77390
|
+
both
|
|
77391
|
+
};
|
|
77392
|
+
}
|
|
77393
|
+
/**
|
|
77394
|
+
* パーティが抜群 (> 1 倍) を取れる防御タイプ集合。
|
|
77395
|
+
*/
|
|
77396
|
+
function collectCoveredDefenderTypes(party) {
|
|
77397
|
+
const result = /* @__PURE__ */ new Set();
|
|
77398
|
+
const output = analyzePartyCoverage({ myParty: [...party] });
|
|
77399
|
+
for (const entry of output.coverage) if (entry.maxMultiplier > 1) result.add(entry.defenderType);
|
|
77400
|
+
return result;
|
|
77401
|
+
}
|
|
77402
|
+
function computeCoverageDiff(partyA, partyB) {
|
|
77403
|
+
const coveredA = collectCoveredDefenderTypes(partyA);
|
|
77404
|
+
const coveredB = collectCoveredDefenderTypes(partyB);
|
|
77405
|
+
const symmetric = diffTypeSets(coveredA, coveredB);
|
|
77406
|
+
const neither = [];
|
|
77407
|
+
for (const t of championsTypes) if (!coveredA.has(t.name) && !coveredB.has(t.name)) neither.push(t.name);
|
|
77408
|
+
neither.sort();
|
|
77409
|
+
return {
|
|
77410
|
+
...symmetric,
|
|
77411
|
+
neither
|
|
77412
|
+
};
|
|
77413
|
+
}
|
|
77414
|
+
/**
|
|
77415
|
+
* パーティ比較の純関数。MCP ツールハンドラとテストから共通で利用する。
|
|
77416
|
+
*/
|
|
77417
|
+
function comparePartiesAnalysis(args) {
|
|
77418
|
+
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$8);
|
|
77419
|
+
const membersA = resolveMembers(args.partyA);
|
|
77420
|
+
const membersB = resolveMembers(args.partyB);
|
|
77421
|
+
const partyASummary = buildPartySummary(membersA, args.labels?.partyA, gen);
|
|
77422
|
+
const partyBSummary = buildPartySummary(membersB, args.labels?.partyB, gen);
|
|
77423
|
+
const memberTypesA = membersA.map((m) => m.entry.types);
|
|
77424
|
+
const memberTypesB = membersB.map((m) => m.entry.types);
|
|
77425
|
+
const weaknessesA = collectPartyWeaknessTypes(memberTypesA, gen);
|
|
77426
|
+
const weaknessesB = collectPartyWeaknessTypes(memberTypesB, gen);
|
|
77427
|
+
const resistancesA = collectPartyResistanceTypes(memberTypesA, gen);
|
|
77428
|
+
const resistancesB = collectPartyResistanceTypes(memberTypesB, gen);
|
|
77429
|
+
return {
|
|
77430
|
+
partyA: partyASummary,
|
|
77431
|
+
partyB: partyBSummary,
|
|
77432
|
+
differences: {
|
|
77433
|
+
memberDifferences: computeMemberDifferences(membersA, membersB),
|
|
77434
|
+
typeDistribution: { changes: computeTypeDistributionChanges(membersA, membersB) },
|
|
77435
|
+
weaknesses: diffTypeSets(weaknessesA, weaknessesB),
|
|
77436
|
+
resistances: diffTypeSets(resistancesA, resistancesB),
|
|
77437
|
+
coverage: computeCoverageDiff(args.partyA, args.partyB),
|
|
77438
|
+
speedDistribution: {
|
|
77439
|
+
partyA: partyASummary.speedStats,
|
|
77440
|
+
partyB: partyBSummary.speedStats
|
|
77441
|
+
},
|
|
77442
|
+
baseStatsTotal: {
|
|
77443
|
+
partyA: partyASummary.baseStatsTotal,
|
|
77444
|
+
partyB: partyBSummary.baseStatsTotal,
|
|
77445
|
+
diff: partyBSummary.baseStatsTotal - partyASummary.baseStatsTotal
|
|
77446
|
+
}
|
|
77447
|
+
}
|
|
77448
|
+
};
|
|
77449
|
+
}
|
|
77450
|
+
function registerComparePartiesTool(server) {
|
|
77451
|
+
server.tool(TOOL_NAME$18, TOOL_DESCRIPTION$18, inputSchema$15, async (args) => {
|
|
77452
|
+
try {
|
|
77453
|
+
const output = comparePartiesAnalysis(args);
|
|
77454
|
+
return { content: [{
|
|
77455
|
+
type: "text",
|
|
77456
|
+
text: JSON.stringify(output)
|
|
77457
|
+
}] };
|
|
77458
|
+
} catch (error) {
|
|
77459
|
+
const message = error instanceof Error ? error.message : "不明なエラーが発生しました";
|
|
77460
|
+
return {
|
|
77461
|
+
content: [{
|
|
77462
|
+
type: "text",
|
|
77463
|
+
text: JSON.stringify({ error: message })
|
|
77464
|
+
}],
|
|
77465
|
+
isError: true
|
|
77466
|
+
};
|
|
77467
|
+
}
|
|
77468
|
+
});
|
|
77469
|
+
}
|
|
77470
|
+
//#endregion
|
|
76789
77471
|
//#region src/tools/info/condition-info.ts
|
|
76790
77472
|
const TOOL_NAME$17 = "get_condition_info";
|
|
76791
77473
|
const TOOL_DESCRIPTION$17 = "バトル条件(天候・フィールド・状態異常・サイド効果)の情報を取得する。category と name で絞り込める。省略時は全カテゴリ・全件を返す。ポケモンチャンピオンズ対応。";
|
|
@@ -77193,11 +77875,11 @@ function registerDamageRangeTool(server) {
|
|
|
77193
77875
|
}
|
|
77194
77876
|
//#endregion
|
|
77195
77877
|
//#region src/tools/analysis/find-counters.ts
|
|
77196
|
-
const CHAMPIONS_GEN_NUM$
|
|
77878
|
+
const CHAMPIONS_GEN_NUM$7 = 0;
|
|
77197
77879
|
/** 弱点タイプ判定のしきい値(候補プール抽出で使用) */
|
|
77198
77880
|
const SUPER_EFFECTIVE_MIN = 2;
|
|
77199
77881
|
/** Status 技 */
|
|
77200
|
-
const STATUS_CATEGORY$
|
|
77882
|
+
const STATUS_CATEGORY$2 = "Status";
|
|
77201
77883
|
const TOOL_NAME$15 = "find_counters";
|
|
77202
77884
|
const TOOL_DESCRIPTION$15 = "target の弱点タイプ攻撃技を持つポケモンを候補プールとして抽出し、各候補の双方向ダメ計・素早さ・タイプ相性を返す。`candidatePool` は文字列(名前のみ)と PokemonInput オブジェクト(ability / item / nature / evs 指定)を混在可能で、同一ポケモンの build 違い比較にも対応する。正確な計算のため target 側の ability / item の指定を推奨(省略時は通常特性・持ち物なし扱い)。判断(受け型か速度勝ち型か等)は AI が行う前提。ポケモンチャンピオンズ対応。";
|
|
77203
77885
|
const battleFormatValues = ["singles", "doubles"];
|
|
@@ -77233,7 +77915,7 @@ function buildPriorityMoves(pokemonId) {
|
|
|
77233
77915
|
/**
|
|
77234
77916
|
* ポケモン名を pokemon.json のエントリに解決する。
|
|
77235
77917
|
*/
|
|
77236
|
-
function resolvePokemonEntry$
|
|
77918
|
+
function resolvePokemonEntry$2(name) {
|
|
77237
77919
|
const englishName = pokemonNameResolver.toEnglish(name) ?? (pokemonNameResolver.hasEnglishName(name) ? name : null);
|
|
77238
77920
|
if (englishName === null) {
|
|
77239
77921
|
const suggestions = pokemonNameResolver.suggestSimilar(name);
|
|
@@ -77280,7 +77962,7 @@ function hasAttackingMoveOfAnyType(pokemonId, weaknessTypes) {
|
|
|
77280
77962
|
for (const moveId of learnset) {
|
|
77281
77963
|
const move = movesById.get(moveId);
|
|
77282
77964
|
if (move === void 0) continue;
|
|
77283
|
-
if (move.category === STATUS_CATEGORY$
|
|
77965
|
+
if (move.category === STATUS_CATEGORY$2) continue;
|
|
77284
77966
|
if (weaknessTypes.has(move.type)) return true;
|
|
77285
77967
|
}
|
|
77286
77968
|
return false;
|
|
@@ -77324,14 +78006,14 @@ function buildCandidateEntries(candidatePool, target, gen) {
|
|
|
77324
78006
|
if (candidatePool !== void 0) {
|
|
77325
78007
|
const candidates = [];
|
|
77326
78008
|
for (const item of candidatePool) if (typeof item === "string") {
|
|
77327
|
-
const entry = resolvePokemonEntry$
|
|
78009
|
+
const entry = resolvePokemonEntry$2(item);
|
|
77328
78010
|
candidates.push({
|
|
77329
78011
|
entry,
|
|
77330
78012
|
input: { name: entry.name },
|
|
77331
78013
|
hasExplicitBuild: false
|
|
77332
78014
|
});
|
|
77333
78015
|
} else {
|
|
77334
|
-
const entry = resolvePokemonEntry$
|
|
78016
|
+
const entry = resolvePokemonEntry$2(item.name);
|
|
77335
78017
|
candidates.push({
|
|
77336
78018
|
entry,
|
|
77337
78019
|
input: {
|
|
@@ -77360,9 +78042,9 @@ function registerFindCountersTool(server) {
|
|
|
77360
78042
|
}, pokemonEntryProvider);
|
|
77361
78043
|
server.tool(TOOL_NAME$15, TOOL_DESCRIPTION$15, inputSchema$12, async (args) => {
|
|
77362
78044
|
try {
|
|
77363
|
-
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$
|
|
78045
|
+
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$7);
|
|
77364
78046
|
const damageConditions = { battleFormat: args.battleFormat };
|
|
77365
|
-
const targetEntry = resolvePokemonEntry$
|
|
78047
|
+
const targetEntry = resolvePokemonEntry$2(args.target.name);
|
|
77366
78048
|
const { pokemon: targetObj, resolvedName: targetName } = calculator.createPokemonObject(args.target);
|
|
77367
78049
|
const targetNameJa = pokemonNameResolver.toJapanese(targetName) ?? targetName;
|
|
77368
78050
|
const typeWeaknesses = findTypeWeaknesses(targetEntry.types, gen);
|
|
@@ -77457,10 +78139,864 @@ function registerFindCountersTool(server) {
|
|
|
77457
78139
|
});
|
|
77458
78140
|
}
|
|
77459
78141
|
//#endregion
|
|
78142
|
+
//#region src/party-store.ts
|
|
78143
|
+
/** ai-rotom の永続化用ディレクトリ名 (ホーム直下)。 */
|
|
78144
|
+
const AI_ROTOM_DIR_NAME = ".ai-rotom";
|
|
78145
|
+
/** パーティ永続化ファイル名。 */
|
|
78146
|
+
const PARTIES_FILE_NAME = "parties.json";
|
|
78147
|
+
/** atomic write 用の一時ファイル拡張子。 */
|
|
78148
|
+
const TEMP_FILE_EXT = ".tmp";
|
|
78149
|
+
/** JSON.stringify の indent。 */
|
|
78150
|
+
const JSON_INDENT = 2;
|
|
78151
|
+
/** 一時ファイル名用のランダムサフィックスバイト数。 */
|
|
78152
|
+
const TEMP_SUFFIX_BYTES = 8;
|
|
78153
|
+
/**
|
|
78154
|
+
* 永続化ファイル (`~/.ai-rotom/parties.json`) の絶対パスを返す。
|
|
78155
|
+
* ホームディレクトリが解決できない場合はエラーを投げる。
|
|
78156
|
+
*/
|
|
78157
|
+
function resolvePartiesFilePath() {
|
|
78158
|
+
const home = homedir();
|
|
78159
|
+
if (home === "" || home === void 0 || home === null) throw new Error("ホームディレクトリが解決できませんでした。$HOME 環境変数を確認してください。");
|
|
78160
|
+
return join(home, AI_ROTOM_DIR_NAME, PARTIES_FILE_NAME);
|
|
78161
|
+
}
|
|
78162
|
+
/**
|
|
78163
|
+
* 永続化ファイルの読み込み結果。
|
|
78164
|
+
* 存在しない場合は空の PartiesFile を返す。
|
|
78165
|
+
* 破損・権限・schemaVersion 不整合の場合はエラーを投げる。
|
|
78166
|
+
*/
|
|
78167
|
+
function loadPartiesFile(filePath = resolvePartiesFilePath()) {
|
|
78168
|
+
let raw;
|
|
78169
|
+
try {
|
|
78170
|
+
raw = readFileSync(filePath, { encoding: "utf-8" });
|
|
78171
|
+
} catch (error) {
|
|
78172
|
+
if (isNodeErrnoException(error) && error.code === "ENOENT") return {
|
|
78173
|
+
schemaVersion: 1,
|
|
78174
|
+
parties: []
|
|
78175
|
+
};
|
|
78176
|
+
throw wrapIoError("パーティファイルの読み込みに失敗しました", error);
|
|
78177
|
+
}
|
|
78178
|
+
let parsed;
|
|
78179
|
+
try {
|
|
78180
|
+
parsed = JSON.parse(raw);
|
|
78181
|
+
} catch (error) {
|
|
78182
|
+
const cause = error instanceof Error ? error.message : String(error);
|
|
78183
|
+
throw new Error(`パーティファイル (${filePath}) の JSON パースに失敗しました: ${cause}`);
|
|
78184
|
+
}
|
|
78185
|
+
const result = partiesFileSchema.safeParse(parsed);
|
|
78186
|
+
if (!result.success) {
|
|
78187
|
+
const issues = result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ");
|
|
78188
|
+
throw new Error(`パーティファイル (${filePath}) のスキーマ検証に失敗しました: ${issues}`);
|
|
78189
|
+
}
|
|
78190
|
+
if (result.data.schemaVersion !== 1) throw new Error(`未対応の schemaVersion (${result.data.schemaVersion}) です。現行は 1 です。`);
|
|
78191
|
+
return result.data;
|
|
78192
|
+
}
|
|
78193
|
+
/**
|
|
78194
|
+
* 永続化ファイルを atomic に書き込む。
|
|
78195
|
+
* 親ディレクトリが存在しない場合は作成する。
|
|
78196
|
+
* 一時ファイル → rename で置き換えるため、途中失敗でも元ファイルは壊れない。
|
|
78197
|
+
*/
|
|
78198
|
+
function savePartiesFile(data, filePath = resolvePartiesFilePath()) {
|
|
78199
|
+
const validated = partiesFileSchema.parse(data);
|
|
78200
|
+
const dir = dirname(filePath);
|
|
78201
|
+
try {
|
|
78202
|
+
mkdirSync(dir, { recursive: true });
|
|
78203
|
+
} catch (error) {
|
|
78204
|
+
throw wrapIoError(`パーティ保存ディレクトリ (${dir}) の作成に失敗しました`, error);
|
|
78205
|
+
}
|
|
78206
|
+
const tempPath = `${filePath}.${randomBytes(TEMP_SUFFIX_BYTES).toString("hex")}${TEMP_FILE_EXT}`;
|
|
78207
|
+
const serialized = JSON.stringify(validated, null, JSON_INDENT);
|
|
78208
|
+
try {
|
|
78209
|
+
writeFileSync(tempPath, serialized, {
|
|
78210
|
+
encoding: "utf-8",
|
|
78211
|
+
mode: 384
|
|
78212
|
+
});
|
|
78213
|
+
renameSync(tempPath, filePath);
|
|
78214
|
+
} catch (error) {
|
|
78215
|
+
try {
|
|
78216
|
+
rmSync(tempPath, { force: true });
|
|
78217
|
+
} catch {}
|
|
78218
|
+
throw wrapIoError(`パーティファイル (${filePath}) の保存に失敗しました`, error);
|
|
78219
|
+
}
|
|
78220
|
+
}
|
|
78221
|
+
function isNodeErrnoException(value) {
|
|
78222
|
+
return value instanceof Error && typeof value.code === "string";
|
|
78223
|
+
}
|
|
78224
|
+
function wrapIoError(prefix, error) {
|
|
78225
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
78226
|
+
const code = isNodeErrnoException(error) && error.code !== void 0 ? ` [${error.code}]` : "";
|
|
78227
|
+
return /* @__PURE__ */ new Error(`${prefix}${code}: ${message}`);
|
|
78228
|
+
}
|
|
78229
|
+
//#endregion
|
|
78230
|
+
//#region ../../node_modules/@pokesol/pokesol-text-parser-ts/dist/parser.js
|
|
78231
|
+
var ASTKinds;
|
|
78232
|
+
(function(ASTKinds) {
|
|
78233
|
+
ASTKinds["POKESOL_TEXT"] = "POKESOL_TEXT";
|
|
78234
|
+
ASTKinds["POKESOL_TEXT_$0_1"] = "POKESOL_TEXT_$0_1";
|
|
78235
|
+
ASTKinds["POKESOL_TEXT_$0_2"] = "POKESOL_TEXT_$0_2";
|
|
78236
|
+
ASTKinds["POKESOL_TEXT_$1"] = "POKESOL_TEXT_$1";
|
|
78237
|
+
ASTKinds["POKESOL_TEXT_$2"] = "POKESOL_TEXT_$2";
|
|
78238
|
+
ASTKinds["POKESOL_TEXT_$3"] = "POKESOL_TEXT_$3";
|
|
78239
|
+
ASTKinds["POKEMON_AND_ITEM_LINE"] = "POKEMON_AND_ITEM_LINE";
|
|
78240
|
+
ASTKinds["POKEMON_LINE"] = "POKEMON_LINE";
|
|
78241
|
+
ASTKinds["POKEMON_VALUE"] = "POKEMON_VALUE";
|
|
78242
|
+
ASTKinds["ITEM_VALUE"] = "ITEM_VALUE";
|
|
78243
|
+
ASTKinds["TERATYPE_LINE"] = "TERATYPE_LINE";
|
|
78244
|
+
ASTKinds["TERATYPE_VALUE"] = "TERATYPE_VALUE";
|
|
78245
|
+
ASTKinds["ABILITY_LINE"] = "ABILITY_LINE";
|
|
78246
|
+
ASTKinds["ABILITY_LINE_$0"] = "ABILITY_LINE_$0";
|
|
78247
|
+
ASTKinds["ABILITY_VALUE"] = "ABILITY_VALUE";
|
|
78248
|
+
ASTKinds["NATURE_LINE"] = "NATURE_LINE";
|
|
78249
|
+
ASTKinds["NATURE_VALUE"] = "NATURE_VALUE";
|
|
78250
|
+
ASTKinds["STATS_LINE"] = "STATS_LINE";
|
|
78251
|
+
ASTKinds["STATS"] = "STATS";
|
|
78252
|
+
ASTKinds["STAT_1"] = "STAT_1";
|
|
78253
|
+
ASTKinds["STAT_2"] = "STAT_2";
|
|
78254
|
+
ASTKinds["ACTUAL_AND_EFFORT"] = "ACTUAL_AND_EFFORT";
|
|
78255
|
+
ASTKinds["ACTUAL"] = "ACTUAL";
|
|
78256
|
+
ASTKinds["ACTUAL_VALUE"] = "ACTUAL_VALUE";
|
|
78257
|
+
ASTKinds["EFFORT_VALUE"] = "EFFORT_VALUE";
|
|
78258
|
+
ASTKinds["MOVES_LINE_1"] = "MOVES_LINE_1";
|
|
78259
|
+
ASTKinds["MOVES_LINE_2"] = "MOVES_LINE_2";
|
|
78260
|
+
ASTKinds["MOVES_LINE_3"] = "MOVES_LINE_3";
|
|
78261
|
+
ASTKinds["MOVES_LINE_4"] = "MOVES_LINE_4";
|
|
78262
|
+
ASTKinds["MOVES_FOUR"] = "MOVES_FOUR";
|
|
78263
|
+
ASTKinds["MOVES_THREE"] = "MOVES_THREE";
|
|
78264
|
+
ASTKinds["MOVES_TWO"] = "MOVES_TWO";
|
|
78265
|
+
ASTKinds["MOVES_ONE"] = "MOVES_ONE";
|
|
78266
|
+
ASTKinds["MOVE_VALUE"] = "MOVE_VALUE";
|
|
78267
|
+
ASTKinds["_"] = "_";
|
|
78268
|
+
})(ASTKinds || (ASTKinds = {}));
|
|
78269
|
+
var Parser = class {
|
|
78270
|
+
input;
|
|
78271
|
+
pos;
|
|
78272
|
+
negating = false;
|
|
78273
|
+
memoSafe = true;
|
|
78274
|
+
constructor(input) {
|
|
78275
|
+
this.pos = {
|
|
78276
|
+
overallPos: 0,
|
|
78277
|
+
line: 1,
|
|
78278
|
+
offset: 0
|
|
78279
|
+
};
|
|
78280
|
+
this.input = input;
|
|
78281
|
+
}
|
|
78282
|
+
reset(pos) {
|
|
78283
|
+
this.pos = pos;
|
|
78284
|
+
}
|
|
78285
|
+
finished() {
|
|
78286
|
+
return this.pos.overallPos === this.input.length;
|
|
78287
|
+
}
|
|
78288
|
+
clearMemos() {}
|
|
78289
|
+
matchPOKESOL_TEXT($$dpth, $$cr) {
|
|
78290
|
+
return this.run($$dpth, () => {
|
|
78291
|
+
let $scope$line1;
|
|
78292
|
+
let $scope$line2;
|
|
78293
|
+
let $scope$line3;
|
|
78294
|
+
let $scope$line4;
|
|
78295
|
+
let $scope$line5;
|
|
78296
|
+
let $scope$line6;
|
|
78297
|
+
let $$res = null;
|
|
78298
|
+
if (($scope$line1 = this.matchPOKESOL_TEXT_$0($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\n+)`, "", $$dpth + 1, $$cr) !== null && (($scope$line2 = this.matchPOKESOL_TEXT_$1($$dpth + 1, $$cr)) || true) && ($scope$line3 = this.matchABILITY_LINE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\n+)`, "", $$dpth + 1, $$cr) !== null && ($scope$line4 = this.matchNATURE_LINE($$dpth + 1, $$cr)) !== null && (($scope$line5 = this.matchPOKESOL_TEXT_$2($$dpth + 1, $$cr)) || true) && (($scope$line6 = this.matchPOKESOL_TEXT_$3($$dpth + 1, $$cr)) || true)) $$res = {
|
|
78299
|
+
kind: ASTKinds.POKESOL_TEXT,
|
|
78300
|
+
line1: $scope$line1,
|
|
78301
|
+
line2: $scope$line2,
|
|
78302
|
+
line3: $scope$line3,
|
|
78303
|
+
line4: $scope$line4,
|
|
78304
|
+
line5: $scope$line5,
|
|
78305
|
+
line6: $scope$line6
|
|
78306
|
+
};
|
|
78307
|
+
return $$res;
|
|
78308
|
+
});
|
|
78309
|
+
}
|
|
78310
|
+
matchPOKESOL_TEXT_$0($$dpth, $$cr) {
|
|
78311
|
+
return this.choice([() => this.matchPOKESOL_TEXT_$0_1($$dpth + 1, $$cr), () => this.matchPOKESOL_TEXT_$0_2($$dpth + 1, $$cr)]);
|
|
78312
|
+
}
|
|
78313
|
+
matchPOKESOL_TEXT_$0_1($$dpth, $$cr) {
|
|
78314
|
+
return this.matchPOKEMON_AND_ITEM_LINE($$dpth + 1, $$cr);
|
|
78315
|
+
}
|
|
78316
|
+
matchPOKESOL_TEXT_$0_2($$dpth, $$cr) {
|
|
78317
|
+
return this.matchPOKEMON_LINE($$dpth + 1, $$cr);
|
|
78318
|
+
}
|
|
78319
|
+
matchPOKESOL_TEXT_$1($$dpth, $$cr) {
|
|
78320
|
+
return this.run($$dpth, () => {
|
|
78321
|
+
let $scope$body;
|
|
78322
|
+
let $$res = null;
|
|
78323
|
+
if (($scope$body = this.matchTERATYPE_LINE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\n+)`, "", $$dpth + 1, $$cr) !== null) $$res = {
|
|
78324
|
+
kind: ASTKinds.POKESOL_TEXT_$1,
|
|
78325
|
+
body: $scope$body
|
|
78326
|
+
};
|
|
78327
|
+
return $$res;
|
|
78328
|
+
});
|
|
78329
|
+
}
|
|
78330
|
+
matchPOKESOL_TEXT_$2($$dpth, $$cr) {
|
|
78331
|
+
return this.run($$dpth, () => {
|
|
78332
|
+
let $scope$body;
|
|
78333
|
+
let $$res = null;
|
|
78334
|
+
if (this.regexAccept(String.raw`(?:\n+)`, "", $$dpth + 1, $$cr) !== null && ($scope$body = this.matchSTATS_LINE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78335
|
+
kind: ASTKinds.POKESOL_TEXT_$2,
|
|
78336
|
+
body: $scope$body
|
|
78337
|
+
};
|
|
78338
|
+
return $$res;
|
|
78339
|
+
});
|
|
78340
|
+
}
|
|
78341
|
+
matchPOKESOL_TEXT_$3($$dpth, $$cr) {
|
|
78342
|
+
return this.run($$dpth, () => {
|
|
78343
|
+
let $scope$body;
|
|
78344
|
+
let $$res = null;
|
|
78345
|
+
if (this.regexAccept(String.raw`(?:\n+)`, "", $$dpth + 1, $$cr) !== null && ($scope$body = this.matchMOVES_LINE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78346
|
+
kind: ASTKinds.POKESOL_TEXT_$3,
|
|
78347
|
+
body: $scope$body
|
|
78348
|
+
};
|
|
78349
|
+
return $$res;
|
|
78350
|
+
});
|
|
78351
|
+
}
|
|
78352
|
+
matchPOKEMON_AND_ITEM_LINE($$dpth, $$cr) {
|
|
78353
|
+
return this.run($$dpth, () => {
|
|
78354
|
+
let $scope$pokemon;
|
|
78355
|
+
let $scope$item;
|
|
78356
|
+
let $$res = null;
|
|
78357
|
+
if (($scope$pokemon = this.matchPOKEMON_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:@)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$item = this.matchITEM_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78358
|
+
kind: ASTKinds.POKEMON_AND_ITEM_LINE,
|
|
78359
|
+
pokemon: $scope$pokemon,
|
|
78360
|
+
item: $scope$item
|
|
78361
|
+
};
|
|
78362
|
+
return $$res;
|
|
78363
|
+
});
|
|
78364
|
+
}
|
|
78365
|
+
matchPOKEMON_LINE($$dpth, $$cr) {
|
|
78366
|
+
return this.run($$dpth, () => {
|
|
78367
|
+
let $scope$pokemon;
|
|
78368
|
+
let $$res = null;
|
|
78369
|
+
if (($scope$pokemon = this.matchPOKEMON_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78370
|
+
kind: ASTKinds.POKEMON_LINE,
|
|
78371
|
+
pokemon: $scope$pokemon
|
|
78372
|
+
};
|
|
78373
|
+
return $$res;
|
|
78374
|
+
});
|
|
78375
|
+
}
|
|
78376
|
+
matchPOKEMON_VALUE($$dpth, $$cr) {
|
|
78377
|
+
return this.regexAccept(String.raw`(?:[0-90-9a-zA-ZA-Zぁ-んァ-ヶー一-龠・()♂♀%]+)`, "", $$dpth + 1, $$cr);
|
|
78378
|
+
}
|
|
78379
|
+
matchITEM_VALUE($$dpth, $$cr) {
|
|
78380
|
+
return this.regexAccept(String.raw`(?:[ぁ-んァ-ヶー]+)`, "", $$dpth + 1, $$cr);
|
|
78381
|
+
}
|
|
78382
|
+
matchTERATYPE_LINE($$dpth, $$cr) {
|
|
78383
|
+
return this.run($$dpth, () => {
|
|
78384
|
+
let $scope$teratype;
|
|
78385
|
+
let $$res = null;
|
|
78386
|
+
if (this.regexAccept(String.raw`(?:テラスタイプ)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?::)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$teratype = this.matchTERATYPE_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78387
|
+
kind: ASTKinds.TERATYPE_LINE,
|
|
78388
|
+
teratype: $scope$teratype
|
|
78389
|
+
};
|
|
78390
|
+
return $$res;
|
|
78391
|
+
});
|
|
78392
|
+
}
|
|
78393
|
+
matchTERATYPE_VALUE($$dpth, $$cr) {
|
|
78394
|
+
return this.regexAccept(String.raw`(?:[ぁ-んァ-ヶー]*)`, "", $$dpth + 1, $$cr);
|
|
78395
|
+
}
|
|
78396
|
+
matchABILITY_LINE($$dpth, $$cr) {
|
|
78397
|
+
return this.run($$dpth, () => {
|
|
78398
|
+
let $scope$ability;
|
|
78399
|
+
let $scope$preMega;
|
|
78400
|
+
let $$res = null;
|
|
78401
|
+
if (this.regexAccept(String.raw`(?:特性)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?::)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && (($scope$ability = this.matchABILITY_VALUE($$dpth + 1, $$cr)) || true) && this.match_($$dpth + 1, $$cr) !== null && (($scope$preMega = this.matchABILITY_LINE_$0($$dpth + 1, $$cr)) || true)) $$res = {
|
|
78402
|
+
kind: ASTKinds.ABILITY_LINE,
|
|
78403
|
+
ability: $scope$ability,
|
|
78404
|
+
preMega: $scope$preMega
|
|
78405
|
+
};
|
|
78406
|
+
return $$res;
|
|
78407
|
+
});
|
|
78408
|
+
}
|
|
78409
|
+
matchABILITY_LINE_$0($$dpth, $$cr) {
|
|
78410
|
+
return this.run($$dpth, () => {
|
|
78411
|
+
let $scope$body;
|
|
78412
|
+
let $$res = null;
|
|
78413
|
+
if (this.regexAccept(String.raw`(?:\()`, "", $$dpth + 1, $$cr) !== null && ($scope$body = this.matchABILITY_VALUE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\))`, "", $$dpth + 1, $$cr) !== null) $$res = {
|
|
78414
|
+
kind: ASTKinds.ABILITY_LINE_$0,
|
|
78415
|
+
body: $scope$body
|
|
78416
|
+
};
|
|
78417
|
+
return $$res;
|
|
78418
|
+
});
|
|
78419
|
+
}
|
|
78420
|
+
matchABILITY_VALUE($$dpth, $$cr) {
|
|
78421
|
+
return this.regexAccept(String.raw`(?:[ぁ-んァ-ヶー]+)`, "", $$dpth + 1, $$cr);
|
|
78422
|
+
}
|
|
78423
|
+
matchNATURE_LINE($$dpth, $$cr) {
|
|
78424
|
+
return this.run($$dpth, () => {
|
|
78425
|
+
let $scope$nature;
|
|
78426
|
+
let $$res = null;
|
|
78427
|
+
if (this.regexAccept(String.raw`(?:能力補正)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?::)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && (($scope$nature = this.matchNATURE_VALUE($$dpth + 1, $$cr)) || true)) $$res = {
|
|
78428
|
+
kind: ASTKinds.NATURE_LINE,
|
|
78429
|
+
nature: $scope$nature
|
|
78430
|
+
};
|
|
78431
|
+
return $$res;
|
|
78432
|
+
});
|
|
78433
|
+
}
|
|
78434
|
+
matchNATURE_VALUE($$dpth, $$cr) {
|
|
78435
|
+
return this.regexAccept(String.raw`(?:[ぁ-ん]+)`, "", $$dpth + 1, $$cr);
|
|
78436
|
+
}
|
|
78437
|
+
matchSTATS_LINE($$dpth, $$cr) {
|
|
78438
|
+
return this.run($$dpth, () => {
|
|
78439
|
+
let $scope$stats;
|
|
78440
|
+
let $$res = null;
|
|
78441
|
+
if (($scope$stats = this.matchSTATS($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78442
|
+
kind: ASTKinds.STATS_LINE,
|
|
78443
|
+
stats: $scope$stats
|
|
78444
|
+
};
|
|
78445
|
+
return $$res;
|
|
78446
|
+
});
|
|
78447
|
+
}
|
|
78448
|
+
matchSTATS($$dpth, $$cr) {
|
|
78449
|
+
return this.run($$dpth, () => {
|
|
78450
|
+
let $scope$h;
|
|
78451
|
+
let $scope$a;
|
|
78452
|
+
let $scope$b;
|
|
78453
|
+
let $scope$c;
|
|
78454
|
+
let $scope$d;
|
|
78455
|
+
let $scope$s;
|
|
78456
|
+
let $$res = null;
|
|
78457
|
+
if (($scope$h = this.matchSTAT($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:-)`, "", $$dpth + 1, $$cr) !== null && ($scope$a = this.matchSTAT($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:-)`, "", $$dpth + 1, $$cr) !== null && ($scope$b = this.matchSTAT($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:-)`, "", $$dpth + 1, $$cr) !== null && ($scope$c = this.matchSTAT($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:-)`, "", $$dpth + 1, $$cr) !== null && ($scope$d = this.matchSTAT($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:-)`, "", $$dpth + 1, $$cr) !== null && ($scope$s = this.matchSTAT($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78458
|
+
kind: ASTKinds.STATS,
|
|
78459
|
+
h: $scope$h,
|
|
78460
|
+
a: $scope$a,
|
|
78461
|
+
b: $scope$b,
|
|
78462
|
+
c: $scope$c,
|
|
78463
|
+
d: $scope$d,
|
|
78464
|
+
s: $scope$s
|
|
78465
|
+
};
|
|
78466
|
+
return $$res;
|
|
78467
|
+
});
|
|
78468
|
+
}
|
|
78469
|
+
matchSTAT($$dpth, $$cr) {
|
|
78470
|
+
return this.choice([() => this.matchSTAT_1($$dpth + 1, $$cr), () => this.matchSTAT_2($$dpth + 1, $$cr)]);
|
|
78471
|
+
}
|
|
78472
|
+
matchSTAT_1($$dpth, $$cr) {
|
|
78473
|
+
return this.matchACTUAL_AND_EFFORT($$dpth + 1, $$cr);
|
|
78474
|
+
}
|
|
78475
|
+
matchSTAT_2($$dpth, $$cr) {
|
|
78476
|
+
return this.matchACTUAL($$dpth + 1, $$cr);
|
|
78477
|
+
}
|
|
78478
|
+
matchACTUAL_AND_EFFORT($$dpth, $$cr) {
|
|
78479
|
+
return this.run($$dpth, () => {
|
|
78480
|
+
let $scope$actual;
|
|
78481
|
+
let $scope$effort;
|
|
78482
|
+
let $$res = null;
|
|
78483
|
+
if (($scope$actual = this.matchACTUAL_VALUE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\()`, "", $$dpth + 1, $$cr) !== null && ($scope$effort = this.matchEFFORT_VALUE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\))`, "", $$dpth + 1, $$cr) !== null) $$res = {
|
|
78484
|
+
kind: ASTKinds.ACTUAL_AND_EFFORT,
|
|
78485
|
+
actual: $scope$actual,
|
|
78486
|
+
effort: $scope$effort
|
|
78487
|
+
};
|
|
78488
|
+
return $$res;
|
|
78489
|
+
});
|
|
78490
|
+
}
|
|
78491
|
+
matchACTUAL($$dpth, $$cr) {
|
|
78492
|
+
return this.run($$dpth, () => {
|
|
78493
|
+
let $scope$actual;
|
|
78494
|
+
let $$res = null;
|
|
78495
|
+
if (($scope$actual = this.matchACTUAL_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78496
|
+
kind: ASTKinds.ACTUAL,
|
|
78497
|
+
actual: $scope$actual
|
|
78498
|
+
};
|
|
78499
|
+
return $$res;
|
|
78500
|
+
});
|
|
78501
|
+
}
|
|
78502
|
+
matchACTUAL_VALUE($$dpth, $$cr) {
|
|
78503
|
+
return this.regexAccept(String.raw`(?:[1-9][0-9]*)`, "", $$dpth + 1, $$cr);
|
|
78504
|
+
}
|
|
78505
|
+
matchEFFORT_VALUE($$dpth, $$cr) {
|
|
78506
|
+
return this.regexAccept(String.raw`(?:[1-9][0-9]*)`, "", $$dpth + 1, $$cr);
|
|
78507
|
+
}
|
|
78508
|
+
matchMOVES_LINE($$dpth, $$cr) {
|
|
78509
|
+
return this.choice([
|
|
78510
|
+
() => this.matchMOVES_LINE_1($$dpth + 1, $$cr),
|
|
78511
|
+
() => this.matchMOVES_LINE_2($$dpth + 1, $$cr),
|
|
78512
|
+
() => this.matchMOVES_LINE_3($$dpth + 1, $$cr),
|
|
78513
|
+
() => this.matchMOVES_LINE_4($$dpth + 1, $$cr)
|
|
78514
|
+
]);
|
|
78515
|
+
}
|
|
78516
|
+
matchMOVES_LINE_1($$dpth, $$cr) {
|
|
78517
|
+
return this.matchMOVES_FOUR($$dpth + 1, $$cr);
|
|
78518
|
+
}
|
|
78519
|
+
matchMOVES_LINE_2($$dpth, $$cr) {
|
|
78520
|
+
return this.matchMOVES_THREE($$dpth + 1, $$cr);
|
|
78521
|
+
}
|
|
78522
|
+
matchMOVES_LINE_3($$dpth, $$cr) {
|
|
78523
|
+
return this.matchMOVES_TWO($$dpth + 1, $$cr);
|
|
78524
|
+
}
|
|
78525
|
+
matchMOVES_LINE_4($$dpth, $$cr) {
|
|
78526
|
+
return this.matchMOVES_ONE($$dpth + 1, $$cr);
|
|
78527
|
+
}
|
|
78528
|
+
matchMOVES_FOUR($$dpth, $$cr) {
|
|
78529
|
+
return this.run($$dpth, () => {
|
|
78530
|
+
let $scope$move1;
|
|
78531
|
+
let $scope$move2;
|
|
78532
|
+
let $scope$move3;
|
|
78533
|
+
let $scope$move4;
|
|
78534
|
+
let $$res = null;
|
|
78535
|
+
if (($scope$move1 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move2 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move3 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move4 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78536
|
+
kind: ASTKinds.MOVES_FOUR,
|
|
78537
|
+
move1: $scope$move1,
|
|
78538
|
+
move2: $scope$move2,
|
|
78539
|
+
move3: $scope$move3,
|
|
78540
|
+
move4: $scope$move4
|
|
78541
|
+
};
|
|
78542
|
+
return $$res;
|
|
78543
|
+
});
|
|
78544
|
+
}
|
|
78545
|
+
matchMOVES_THREE($$dpth, $$cr) {
|
|
78546
|
+
return this.run($$dpth, () => {
|
|
78547
|
+
let $scope$move1;
|
|
78548
|
+
let $scope$move2;
|
|
78549
|
+
let $scope$move3;
|
|
78550
|
+
let $$res = null;
|
|
78551
|
+
if (($scope$move1 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move2 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move3 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78552
|
+
kind: ASTKinds.MOVES_THREE,
|
|
78553
|
+
move1: $scope$move1,
|
|
78554
|
+
move2: $scope$move2,
|
|
78555
|
+
move3: $scope$move3
|
|
78556
|
+
};
|
|
78557
|
+
return $$res;
|
|
78558
|
+
});
|
|
78559
|
+
}
|
|
78560
|
+
matchMOVES_TWO($$dpth, $$cr) {
|
|
78561
|
+
return this.run($$dpth, () => {
|
|
78562
|
+
let $scope$move1;
|
|
78563
|
+
let $scope$move2;
|
|
78564
|
+
let $$res = null;
|
|
78565
|
+
if (($scope$move1 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?:/)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && ($scope$move2 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78566
|
+
kind: ASTKinds.MOVES_TWO,
|
|
78567
|
+
move1: $scope$move1,
|
|
78568
|
+
move2: $scope$move2
|
|
78569
|
+
};
|
|
78570
|
+
return $$res;
|
|
78571
|
+
});
|
|
78572
|
+
}
|
|
78573
|
+
matchMOVES_ONE($$dpth, $$cr) {
|
|
78574
|
+
return this.run($$dpth, () => {
|
|
78575
|
+
let $scope$move1;
|
|
78576
|
+
let $$res = null;
|
|
78577
|
+
if (($scope$move1 = this.matchMOVE_VALUE($$dpth + 1, $$cr)) !== null) $$res = {
|
|
78578
|
+
kind: ASTKinds.MOVES_ONE,
|
|
78579
|
+
move1: $scope$move1
|
|
78580
|
+
};
|
|
78581
|
+
return $$res;
|
|
78582
|
+
});
|
|
78583
|
+
}
|
|
78584
|
+
matchMOVE_VALUE($$dpth, $$cr) {
|
|
78585
|
+
return this.regexAccept(String.raw`(?:[0-9A-Zぁ-んァ-ヶー・]+)`, "", $$dpth + 1, $$cr);
|
|
78586
|
+
}
|
|
78587
|
+
match_($$dpth, $$cr) {
|
|
78588
|
+
return this.regexAccept(String.raw`(?:[ \t]*)`, "", $$dpth + 1, $$cr);
|
|
78589
|
+
}
|
|
78590
|
+
test() {
|
|
78591
|
+
const mrk = this.mark();
|
|
78592
|
+
const ans = this.matchPOKESOL_TEXT(0) !== null;
|
|
78593
|
+
this.reset(mrk);
|
|
78594
|
+
return ans;
|
|
78595
|
+
}
|
|
78596
|
+
parse() {
|
|
78597
|
+
const mrk = this.mark();
|
|
78598
|
+
const res = this.matchPOKESOL_TEXT(0);
|
|
78599
|
+
if (res) return {
|
|
78600
|
+
ast: res,
|
|
78601
|
+
errs: []
|
|
78602
|
+
};
|
|
78603
|
+
this.reset(mrk);
|
|
78604
|
+
const rec = new ErrorTracker();
|
|
78605
|
+
this.clearMemos();
|
|
78606
|
+
this.matchPOKESOL_TEXT(0, rec);
|
|
78607
|
+
const err = rec.getErr();
|
|
78608
|
+
return {
|
|
78609
|
+
ast: res,
|
|
78610
|
+
errs: err !== null ? [err] : []
|
|
78611
|
+
};
|
|
78612
|
+
}
|
|
78613
|
+
mark() {
|
|
78614
|
+
return this.pos;
|
|
78615
|
+
}
|
|
78616
|
+
loopPlus(func) {
|
|
78617
|
+
return this.loop(func, 1, -1);
|
|
78618
|
+
}
|
|
78619
|
+
loop(func, lb, ub) {
|
|
78620
|
+
const mrk = this.mark();
|
|
78621
|
+
const res = [];
|
|
78622
|
+
while (ub === -1 || res.length < ub) {
|
|
78623
|
+
const preMrk = this.mark();
|
|
78624
|
+
const t = func();
|
|
78625
|
+
if (t === null || this.pos.overallPos === preMrk.overallPos) break;
|
|
78626
|
+
res.push(t);
|
|
78627
|
+
}
|
|
78628
|
+
if (res.length >= lb) return res;
|
|
78629
|
+
this.reset(mrk);
|
|
78630
|
+
return null;
|
|
78631
|
+
}
|
|
78632
|
+
run($$dpth, fn) {
|
|
78633
|
+
const mrk = this.mark();
|
|
78634
|
+
const res = fn();
|
|
78635
|
+
if (res !== null) return res;
|
|
78636
|
+
this.reset(mrk);
|
|
78637
|
+
return null;
|
|
78638
|
+
}
|
|
78639
|
+
choice(fns) {
|
|
78640
|
+
for (const f of fns) {
|
|
78641
|
+
const res = f();
|
|
78642
|
+
if (res !== null) return res;
|
|
78643
|
+
}
|
|
78644
|
+
return null;
|
|
78645
|
+
}
|
|
78646
|
+
regexAccept(match, mods, dpth, cr) {
|
|
78647
|
+
return this.run(dpth, () => {
|
|
78648
|
+
const reg = new RegExp(match, "y" + mods);
|
|
78649
|
+
const mrk = this.mark();
|
|
78650
|
+
reg.lastIndex = mrk.overallPos;
|
|
78651
|
+
const res = this.tryConsume(reg);
|
|
78652
|
+
if (cr) cr.record(mrk, res, {
|
|
78653
|
+
kind: "RegexMatch",
|
|
78654
|
+
literal: match.substring(3, match.length - 1),
|
|
78655
|
+
negated: this.negating
|
|
78656
|
+
});
|
|
78657
|
+
return res;
|
|
78658
|
+
});
|
|
78659
|
+
}
|
|
78660
|
+
tryConsume(reg) {
|
|
78661
|
+
const res = reg.exec(this.input);
|
|
78662
|
+
if (res) {
|
|
78663
|
+
let lineJmp = 0;
|
|
78664
|
+
let lind = -1;
|
|
78665
|
+
for (let i = 0; i < res[0].length; ++i) if (res[0][i] === "\n") {
|
|
78666
|
+
++lineJmp;
|
|
78667
|
+
lind = i;
|
|
78668
|
+
}
|
|
78669
|
+
this.pos = {
|
|
78670
|
+
overallPos: reg.lastIndex,
|
|
78671
|
+
line: this.pos.line + lineJmp,
|
|
78672
|
+
offset: lind === -1 ? this.pos.offset + res[0].length : res[0].length - lind - 1
|
|
78673
|
+
};
|
|
78674
|
+
return res[0];
|
|
78675
|
+
}
|
|
78676
|
+
return null;
|
|
78677
|
+
}
|
|
78678
|
+
noConsume(fn) {
|
|
78679
|
+
const mrk = this.mark();
|
|
78680
|
+
const res = fn();
|
|
78681
|
+
this.reset(mrk);
|
|
78682
|
+
return res;
|
|
78683
|
+
}
|
|
78684
|
+
negate(fn) {
|
|
78685
|
+
const mrk = this.mark();
|
|
78686
|
+
const oneg = this.negating;
|
|
78687
|
+
this.negating = !oneg;
|
|
78688
|
+
const res = fn();
|
|
78689
|
+
this.negating = oneg;
|
|
78690
|
+
this.reset(mrk);
|
|
78691
|
+
return res === null ? true : null;
|
|
78692
|
+
}
|
|
78693
|
+
memoise(rule, memo) {
|
|
78694
|
+
const $scope$pos = this.mark();
|
|
78695
|
+
const $scope$memoRes = memo.get($scope$pos.overallPos);
|
|
78696
|
+
if (this.memoSafe && $scope$memoRes !== void 0) {
|
|
78697
|
+
this.reset($scope$memoRes[1]);
|
|
78698
|
+
return $scope$memoRes[0];
|
|
78699
|
+
}
|
|
78700
|
+
const $scope$result = rule();
|
|
78701
|
+
if (this.memoSafe) memo.set($scope$pos.overallPos, [$scope$result, this.mark()]);
|
|
78702
|
+
return $scope$result;
|
|
78703
|
+
}
|
|
78704
|
+
};
|
|
78705
|
+
function parse$1(s) {
|
|
78706
|
+
return new Parser(s).parse();
|
|
78707
|
+
}
|
|
78708
|
+
var SyntaxErr = class {
|
|
78709
|
+
pos;
|
|
78710
|
+
expmatches;
|
|
78711
|
+
constructor(pos, expmatches) {
|
|
78712
|
+
this.pos = pos;
|
|
78713
|
+
this.expmatches = [...expmatches];
|
|
78714
|
+
}
|
|
78715
|
+
toString() {
|
|
78716
|
+
return `Syntax Error at line ${this.pos.line}:${this.pos.offset}. Expected one of ${this.expmatches.map((x) => x.kind === "EOF" ? " EOF" : ` ${x.negated ? "not " : ""}'${x.literal}'`)}`;
|
|
78717
|
+
}
|
|
78718
|
+
};
|
|
78719
|
+
var ErrorTracker = class {
|
|
78720
|
+
mxpos = {
|
|
78721
|
+
overallPos: -1,
|
|
78722
|
+
line: -1,
|
|
78723
|
+
offset: -1
|
|
78724
|
+
};
|
|
78725
|
+
regexset = /* @__PURE__ */ new Set();
|
|
78726
|
+
pmatches = [];
|
|
78727
|
+
record(pos, result, att) {
|
|
78728
|
+
if (result === null === att.negated) return;
|
|
78729
|
+
if (pos.overallPos > this.mxpos.overallPos) {
|
|
78730
|
+
this.mxpos = pos;
|
|
78731
|
+
this.pmatches = [];
|
|
78732
|
+
this.regexset.clear();
|
|
78733
|
+
}
|
|
78734
|
+
if (this.mxpos.overallPos === pos.overallPos) if (att.kind === "RegexMatch") {
|
|
78735
|
+
if (!this.regexset.has(att.literal)) this.pmatches.push(att);
|
|
78736
|
+
this.regexset.add(att.literal);
|
|
78737
|
+
} else this.pmatches.push(att);
|
|
78738
|
+
}
|
|
78739
|
+
getErr() {
|
|
78740
|
+
if (this.mxpos.overallPos !== -1) return new SyntaxErr(this.mxpos, this.pmatches);
|
|
78741
|
+
return null;
|
|
78742
|
+
}
|
|
78743
|
+
};
|
|
78744
|
+
//#endregion
|
|
78745
|
+
//#region ../../node_modules/@pokesol/pokesol-text-parser-ts/dist/index.js
|
|
78746
|
+
const parse = (pokesolText) => {
|
|
78747
|
+
const result = parse$1(chomp(pokesolText));
|
|
78748
|
+
if (!result.ast) throw new Error(`Failed to parse Pokesol Text: ${JSON.stringify(result.errs)}`);
|
|
78749
|
+
const pokemonName = result.ast.line1.pokemon;
|
|
78750
|
+
const itemName = result.ast.line1.kind === ASTKinds.POKEMON_AND_ITEM_LINE ? result.ast.line1.item : null;
|
|
78751
|
+
const terastalName = result.ast.line2?.body.teratype || null;
|
|
78752
|
+
const abilityName = result.ast.line3.ability || null;
|
|
78753
|
+
const preMegaAbilityName = result.ast.line3.preMega?.body || null;
|
|
78754
|
+
const natureName = result.ast.line4.nature || null;
|
|
78755
|
+
const evs = {
|
|
78756
|
+
hp: 0,
|
|
78757
|
+
attack: 0,
|
|
78758
|
+
defense: 0,
|
|
78759
|
+
specialAttack: 0,
|
|
78760
|
+
specialDefense: 0,
|
|
78761
|
+
speed: 0
|
|
78762
|
+
};
|
|
78763
|
+
const actualValue = {
|
|
78764
|
+
hp: null,
|
|
78765
|
+
attack: null,
|
|
78766
|
+
defense: null,
|
|
78767
|
+
specialAttack: null,
|
|
78768
|
+
specialDefense: null,
|
|
78769
|
+
speed: null
|
|
78770
|
+
};
|
|
78771
|
+
if (result.ast.line5 !== null) {
|
|
78772
|
+
evs.hp = result.ast.line5.body.stats.h.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.h.effort) : 0;
|
|
78773
|
+
evs.attack = result.ast.line5.body.stats.a.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.a.effort) : 0;
|
|
78774
|
+
evs.defense = result.ast.line5.body.stats.b.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.b.effort) : 0;
|
|
78775
|
+
evs.specialAttack = result.ast.line5.body.stats.c.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.c.effort) : 0;
|
|
78776
|
+
evs.specialDefense = result.ast.line5.body.stats.d.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.d.effort) : 0;
|
|
78777
|
+
evs.speed = result.ast.line5.body.stats.s.kind === ASTKinds.ACTUAL_AND_EFFORT ? Number(result.ast.line5.body.stats.s.effort) : 0;
|
|
78778
|
+
actualValue.hp = Number(result.ast.line5.body.stats.h.actual);
|
|
78779
|
+
actualValue.attack = Number(result.ast.line5.body.stats.a.actual);
|
|
78780
|
+
actualValue.defense = Number(result.ast.line5.body.stats.b.actual);
|
|
78781
|
+
actualValue.specialAttack = Number(result.ast.line5.body.stats.c.actual);
|
|
78782
|
+
actualValue.specialDefense = Number(result.ast.line5.body.stats.d.actual);
|
|
78783
|
+
actualValue.speed = Number(result.ast.line5.body.stats.s.actual);
|
|
78784
|
+
}
|
|
78785
|
+
const moveNames = [];
|
|
78786
|
+
if (result.ast.line6 !== null) {
|
|
78787
|
+
if (result.ast.line6.body.kind === ASTKinds.MOVES_FOUR) {
|
|
78788
|
+
moveNames.push(result.ast.line6.body.move1);
|
|
78789
|
+
moveNames.push(result.ast.line6.body.move2);
|
|
78790
|
+
moveNames.push(result.ast.line6.body.move3);
|
|
78791
|
+
moveNames.push(result.ast.line6.body.move4);
|
|
78792
|
+
} else if (result.ast.line6.body.kind === ASTKinds.MOVES_THREE) {
|
|
78793
|
+
moveNames.push(result.ast.line6.body.move1);
|
|
78794
|
+
moveNames.push(result.ast.line6.body.move2);
|
|
78795
|
+
moveNames.push(result.ast.line6.body.move3);
|
|
78796
|
+
} else if (result.ast.line6.body.kind === ASTKinds.MOVES_TWO) {
|
|
78797
|
+
moveNames.push(result.ast.line6.body.move1);
|
|
78798
|
+
moveNames.push(result.ast.line6.body.move2);
|
|
78799
|
+
} else if (result.ast.line6.body.kind === ASTKinds.MOVES_ONE) moveNames.push(result.ast.line6.body.move1);
|
|
78800
|
+
}
|
|
78801
|
+
return {
|
|
78802
|
+
pokemonName,
|
|
78803
|
+
itemName,
|
|
78804
|
+
abilityName,
|
|
78805
|
+
preMegaAbilityName,
|
|
78806
|
+
terastalName,
|
|
78807
|
+
natureName,
|
|
78808
|
+
evs,
|
|
78809
|
+
actualValue,
|
|
78810
|
+
moveNames
|
|
78811
|
+
};
|
|
78812
|
+
};
|
|
78813
|
+
const chomp = (text) => {
|
|
78814
|
+
return text.split("\n").map((line) => line.split("//")[0]).map((line) => line.trim()).filter((line) => line.length > 0).join("\n");
|
|
78815
|
+
};
|
|
78816
|
+
//#endregion
|
|
78817
|
+
//#region src/party-text.ts
|
|
78818
|
+
/** ポケソルテキストで性格を省略した場合のデフォルト。 */
|
|
78819
|
+
const DEFAULT_NATURE_NAME = "まじめ";
|
|
78820
|
+
/**
|
|
78821
|
+
* ポケソルテキストを空行区切りで個別ブロックに分割する。
|
|
78822
|
+
* 改行 (LF / CRLF) のどちらにも対応する。
|
|
78823
|
+
* 空白のみのブロックは除外する。
|
|
78824
|
+
*/
|
|
78825
|
+
function splitPokesolTextBlocks(text) {
|
|
78826
|
+
return text.replace(/\r\n/g, "\n").split(/\n\s*\n/).map((block) => block.trim()).filter((block) => block.length > 0);
|
|
78827
|
+
}
|
|
78828
|
+
/**
|
|
78829
|
+
* パーサー出力 (`PokesolTextParseReult`) を `PartyMember` に変換する。
|
|
78830
|
+
* - メガ前特性 (`preMegaAbilityName`) が存在すればそれを `ability` として保存
|
|
78831
|
+
* (通常状態の特性が基本。メガ進化時の特性変化は計算側の責務)
|
|
78832
|
+
* - `natureName` が null の場合は `DEFAULT_NATURE_NAME` で補完
|
|
78833
|
+
* - `terastalName` が存在する場合はポケチャン未対応のため無視
|
|
78834
|
+
* - `moveNames` が空配列の場合は `moves` フィールド自体を省く
|
|
78835
|
+
*
|
|
78836
|
+
* 補完・無視を行った場合はブロック番号付きの warnings を返す。
|
|
78837
|
+
*/
|
|
78838
|
+
function mapPokesolResultToPartyMember(result, blockNumber) {
|
|
78839
|
+
const warnings = [];
|
|
78840
|
+
if (result.pokemonName === null || result.pokemonName === "") throw new Error(`ブロック ${blockNumber}: ポケモン名が読み取れませんでした。`);
|
|
78841
|
+
const member = { name: result.pokemonName };
|
|
78842
|
+
if (result.itemName !== null) member.item = result.itemName;
|
|
78843
|
+
if (result.preMegaAbilityName !== null) {
|
|
78844
|
+
member.ability = result.preMegaAbilityName;
|
|
78845
|
+
if (result.abilityName !== null && result.abilityName !== result.preMegaAbilityName) warnings.push(`ブロック ${blockNumber}: メガ進化特性「${result.abilityName}」は無視し、メガ前特性「${result.preMegaAbilityName}」を ability として保存しました。`);
|
|
78846
|
+
} else if (result.abilityName !== null) member.ability = result.abilityName;
|
|
78847
|
+
if (result.natureName !== null) member.nature = result.natureName;
|
|
78848
|
+
else {
|
|
78849
|
+
member.nature = DEFAULT_NATURE_NAME;
|
|
78850
|
+
warnings.push(`ブロック ${blockNumber}: 性格が省略されていたためデフォルト「${DEFAULT_NATURE_NAME}」を補完しました。`);
|
|
78851
|
+
}
|
|
78852
|
+
if (result.terastalName !== null && result.terastalName !== "") warnings.push(`ブロック ${blockNumber}: テラスタイプ「${result.terastalName}」はポケモンチャンピオンズ未対応のため無視しました。`);
|
|
78853
|
+
const evs = buildEvsFromResult(result.evs);
|
|
78854
|
+
if (evs !== void 0) member.evs = evs;
|
|
78855
|
+
if (result.moveNames.length > 0) member.moves = [...result.moveNames];
|
|
78856
|
+
else warnings.push(`ブロック ${blockNumber}: 技行が省略されていたため moves を空で登録しました。`);
|
|
78857
|
+
return {
|
|
78858
|
+
member,
|
|
78859
|
+
warnings
|
|
78860
|
+
};
|
|
78861
|
+
}
|
|
78862
|
+
/**
|
|
78863
|
+
* パーサー出力の SP (努力値フィールド) を `EvsInput` に変換する。
|
|
78864
|
+
* 全て 0 の場合は undefined を返し、`PartyMember.evs` を省く。
|
|
78865
|
+
*/
|
|
78866
|
+
function buildEvsFromResult(parserEvs) {
|
|
78867
|
+
const mapped = {
|
|
78868
|
+
hp: parserEvs.hp,
|
|
78869
|
+
atk: parserEvs.attack,
|
|
78870
|
+
def: parserEvs.defense,
|
|
78871
|
+
spa: parserEvs.specialAttack,
|
|
78872
|
+
spd: parserEvs.specialDefense,
|
|
78873
|
+
spe: parserEvs.speed
|
|
78874
|
+
};
|
|
78875
|
+
return Object.values(mapped).some((value) => value !== void 0 && value !== 0) ? mapped : void 0;
|
|
78876
|
+
}
|
|
78877
|
+
//#endregion
|
|
78878
|
+
//#region src/tools/party/import-party-from-text.ts
|
|
78879
|
+
const TOOL_NAME$14 = "import_party_from_text";
|
|
78880
|
+
const TOOL_DESCRIPTION$14 = "ポケソルテキスト (Showdown 風に 1 匹あたり 3〜6 行・複数匹は空行区切り) からパーティを一括取り込みして保存する (upsert)。各メンバーはポケモン名 / 特性 / 性格 / 技 / 持ち物をポケチャン内の既知データと照合する。エラーがある場合は部分保存せず全体を失敗させる。";
|
|
78881
|
+
/** ポケソルテキスト入力の最大文字数 (6 匹 × 数百文字 + メモ想定)。 */
|
|
78882
|
+
const MAX_POKESOL_TEXT_LENGTH = 8e3;
|
|
78883
|
+
const defaultNowProvider$1 = () => /* @__PURE__ */ new Date();
|
|
78884
|
+
const defaultStoreIO$1 = {
|
|
78885
|
+
load: () => loadPartiesFile(),
|
|
78886
|
+
save: (data) => savePartiesFile(data)
|
|
78887
|
+
};
|
|
78888
|
+
const inputSchema$11 = {
|
|
78889
|
+
text: z.string().min(1, { message: "ポケソルテキストは 1 文字以上で指定してください。" }).max(MAX_POKESOL_TEXT_LENGTH, { message: `ポケソルテキストは ${MAX_POKESOL_TEXT_LENGTH} 文字以下で指定してください。` }).describe("ポケソルテキスト。1 匹あたり 3〜6 行 (ポケモン名[@持ち物] / テラスタイプ行 省略可 / 特性 / 能力補正 / 実数値(SP) 省略可 / 技 省略可)。複数匹は空行で区切る。"),
|
|
78890
|
+
name: z.string().min(1, { message: "パーティ名は 1 文字以上で指定してください。" }).max(50, { message: `パーティ名は 50 文字以下で指定してください。` }).describe("保存名 (識別子。同名は上書き)。"),
|
|
78891
|
+
memo: z.string().max(MAX_PARTY_MEMO_LENGTH, { message: `メモは ${MAX_PARTY_MEMO_LENGTH} 文字以下で指定してください。` }).optional().describe("構築メモ (自由記述)。")
|
|
78892
|
+
};
|
|
78893
|
+
function toErrorResponse$1(error) {
|
|
78894
|
+
const message = error instanceof Error ? error.message : "不明なエラーが発生しました";
|
|
78895
|
+
return {
|
|
78896
|
+
content: [{
|
|
78897
|
+
type: "text",
|
|
78898
|
+
text: JSON.stringify({ error: message })
|
|
78899
|
+
}],
|
|
78900
|
+
isError: true
|
|
78901
|
+
};
|
|
78902
|
+
}
|
|
78903
|
+
function toTextResponse$1(value) {
|
|
78904
|
+
return { content: [{
|
|
78905
|
+
type: "text",
|
|
78906
|
+
text: JSON.stringify(value)
|
|
78907
|
+
}] };
|
|
78908
|
+
}
|
|
78909
|
+
/**
|
|
78910
|
+
* NameResolver の既知名 (日英どちらでも) として存在するかを判定する。
|
|
78911
|
+
* 未知の場合は類似候補付きのメッセージを投げる。
|
|
78912
|
+
*/
|
|
78913
|
+
function assertKnownName(resolver, name, label, blockNumber) {
|
|
78914
|
+
if (resolver.hasJapaneseName(name) || resolver.hasEnglishName(name)) return;
|
|
78915
|
+
const suggestions = resolver.suggestSimilar(name, 3);
|
|
78916
|
+
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
78917
|
+
throw new Error(`ブロック ${blockNumber}: ${label}「${name}」が見つかりません。${suggestionMessage}`);
|
|
78918
|
+
}
|
|
78919
|
+
/**
|
|
78920
|
+
* PartyMember の各名前フィールドを NameResolver で検証する。
|
|
78921
|
+
* 未知名があれば該当ブロックのエラーとして throw。
|
|
78922
|
+
*/
|
|
78923
|
+
function validateMemberNames(member, blockNumber) {
|
|
78924
|
+
assertKnownName(pokemonNameResolver, member.name, "ポケモン名", blockNumber);
|
|
78925
|
+
if (member.nature !== void 0) assertKnownName(natureNameResolver, member.nature, "性格", blockNumber);
|
|
78926
|
+
if (member.ability !== void 0) assertKnownName(abilityNameResolver, member.ability, "特性", blockNumber);
|
|
78927
|
+
if (member.item !== void 0) assertKnownName(itemNameResolver, member.item, "持ち物", blockNumber);
|
|
78928
|
+
if (member.moves !== void 0) for (const move of member.moves) assertKnownName(moveNameResolver, move, "技", blockNumber);
|
|
78929
|
+
}
|
|
78930
|
+
/**
|
|
78931
|
+
* 本ツールの全処理 (split → parse → map → validate → persist) を実行する。
|
|
78932
|
+
* テストから直接呼び出せるようエクスポートする。
|
|
78933
|
+
*/
|
|
78934
|
+
function runImportPartyFromText(input, deps = {}) {
|
|
78935
|
+
const storeIO = deps.storeIO ?? defaultStoreIO$1;
|
|
78936
|
+
const now = deps.now ?? defaultNowProvider$1;
|
|
78937
|
+
const blocks = splitPokesolTextBlocks(input.text);
|
|
78938
|
+
if (blocks.length < 1) throw new Error(`パーティには 1 匹以上を含めてください (検出: ${blocks.length} 匹)。`);
|
|
78939
|
+
if (blocks.length > 6) throw new Error(`パーティには 6 匹までしか含められません (検出: ${blocks.length} 匹)。`);
|
|
78940
|
+
const warnings = [];
|
|
78941
|
+
const members = [];
|
|
78942
|
+
blocks.forEach((block, index) => {
|
|
78943
|
+
const blockNumber = index + 1;
|
|
78944
|
+
let parsed;
|
|
78945
|
+
try {
|
|
78946
|
+
parsed = parse(block);
|
|
78947
|
+
} catch (error) {
|
|
78948
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
78949
|
+
throw new Error(`ブロック ${blockNumber} のパースに失敗しました: ${reason}`);
|
|
78950
|
+
}
|
|
78951
|
+
const mapped = mapPokesolResultToPartyMember(parsed, blockNumber);
|
|
78952
|
+
validateMemberNames(mapped.member, blockNumber);
|
|
78953
|
+
members.push(mapped.member);
|
|
78954
|
+
warnings.push(...mapped.warnings);
|
|
78955
|
+
});
|
|
78956
|
+
const file = storeIO.load();
|
|
78957
|
+
const existingIndex = file.parties.findIndex((p) => p.name === input.name);
|
|
78958
|
+
const nowIso = now().toISOString();
|
|
78959
|
+
const createdAt = existingIndex >= 0 ? file.parties[existingIndex].createdAt : nowIso;
|
|
78960
|
+
const party = {
|
|
78961
|
+
name: input.name,
|
|
78962
|
+
members,
|
|
78963
|
+
createdAt,
|
|
78964
|
+
updatedAt: nowIso
|
|
78965
|
+
};
|
|
78966
|
+
if (input.memo !== void 0) party.memo = input.memo;
|
|
78967
|
+
partySchema.parse(party);
|
|
78968
|
+
const nextParties = [...file.parties];
|
|
78969
|
+
if (existingIndex >= 0) nextParties[existingIndex] = party;
|
|
78970
|
+
else nextParties.push(party);
|
|
78971
|
+
storeIO.save({
|
|
78972
|
+
schemaVersion: 1,
|
|
78973
|
+
parties: nextParties
|
|
78974
|
+
});
|
|
78975
|
+
return {
|
|
78976
|
+
saved: true,
|
|
78977
|
+
party,
|
|
78978
|
+
warnings,
|
|
78979
|
+
filePath: resolvePartiesFilePath(),
|
|
78980
|
+
overwrote: existingIndex >= 0
|
|
78981
|
+
};
|
|
78982
|
+
}
|
|
78983
|
+
/**
|
|
78984
|
+
* import_party_from_text ツールをサーバーに登録する。
|
|
78985
|
+
*/
|
|
78986
|
+
function registerImportPartyFromTextTool(server, deps = {}) {
|
|
78987
|
+
server.tool(TOOL_NAME$14, TOOL_DESCRIPTION$14, inputSchema$11, async (args) => {
|
|
78988
|
+
try {
|
|
78989
|
+
return toTextResponse$1(runImportPartyFromText(args, deps));
|
|
78990
|
+
} catch (error) {
|
|
78991
|
+
return toErrorResponse$1(error);
|
|
78992
|
+
}
|
|
78993
|
+
});
|
|
78994
|
+
}
|
|
78995
|
+
//#endregion
|
|
77460
78996
|
//#region src/tools/info/item-info.ts
|
|
77461
|
-
const TOOL_NAME$
|
|
77462
|
-
const TOOL_DESCRIPTION$
|
|
77463
|
-
const inputSchema$
|
|
78997
|
+
const TOOL_NAME$13 = "get_item_info";
|
|
78998
|
+
const TOOL_DESCRIPTION$13 = "ポケモンの持ち物(アイテム)の詳細情報(効果説明、メガストーン情報)を取得する。ポケモンチャンピオンズで使える持ち物のみ返す。パーティ構築で持ち物を選ぶ際に使用する。";
|
|
78999
|
+
const inputSchema$10 = { name: z.string().describe("持ち物名(日本語 or 英語)") };
|
|
77464
79000
|
/**
|
|
77465
79001
|
* 持ち物名を英語に解決する。日本語名・英語名どちらでも受け付ける。
|
|
77466
79002
|
*/
|
|
@@ -77473,7 +79009,7 @@ function resolveItemNameEn(input) {
|
|
|
77473
79009
|
throw new Error(`持ち物「${input}」が見つかりません。${suggestionMessage}`);
|
|
77474
79010
|
}
|
|
77475
79011
|
function registerItemInfoTool(server) {
|
|
77476
|
-
server.tool(TOOL_NAME$
|
|
79012
|
+
server.tool(TOOL_NAME$13, TOOL_DESCRIPTION$13, inputSchema$10, async (args) => {
|
|
77477
79013
|
try {
|
|
77478
79014
|
const itemId = toDataId(resolveItemNameEn(args.name));
|
|
77479
79015
|
const entry = itemsById.get(itemId);
|
|
@@ -77506,9 +79042,9 @@ function registerItemInfoTool(server) {
|
|
|
77506
79042
|
}
|
|
77507
79043
|
//#endregion
|
|
77508
79044
|
//#region src/tools/info/learnset.ts
|
|
77509
|
-
const TOOL_NAME$
|
|
77510
|
-
const TOOL_DESCRIPTION$
|
|
77511
|
-
const inputSchema$
|
|
79045
|
+
const TOOL_NAME$12 = "get_learnset";
|
|
79046
|
+
const TOOL_DESCRIPTION$12 = "ポケモンチャンピオンズで特定のポケモンが覚える技の一覧を取得する。パーティ構築や技構成の検討に使用する。チャンピオンズ固有の技プール変更(没収技等)を反映。";
|
|
79047
|
+
const inputSchema$9 = { name: z.string().describe("ポケモン名(日本語 or 英語)") };
|
|
77512
79048
|
/**
|
|
77513
79049
|
* ポケモン名を英語に解決する。日本語名・英語名どちらでも受け付ける。
|
|
77514
79050
|
*/
|
|
@@ -77536,7 +79072,7 @@ function buildLearnsetMoveEntry(moveId) {
|
|
|
77536
79072
|
};
|
|
77537
79073
|
}
|
|
77538
79074
|
function registerLearnsetTool(server) {
|
|
77539
|
-
server.tool(TOOL_NAME$
|
|
79075
|
+
server.tool(TOOL_NAME$12, TOOL_DESCRIPTION$12, inputSchema$9, async (args) => {
|
|
77540
79076
|
try {
|
|
77541
79077
|
const englishName = resolvePokemonNameEn(args.name);
|
|
77542
79078
|
const moveIds = championsLearnsets[toDataId(englishName)];
|
|
@@ -77564,8 +79100,8 @@ function registerLearnsetTool(server) {
|
|
|
77564
79100
|
}
|
|
77565
79101
|
//#endregion
|
|
77566
79102
|
//#region src/tools/analysis/matchup.ts
|
|
77567
|
-
const TOOL_NAME$
|
|
77568
|
-
const TOOL_DESCRIPTION$
|
|
79103
|
+
const TOOL_NAME$11 = "analyze_matchup";
|
|
79104
|
+
const TOOL_DESCRIPTION$11 = "ポケモン2体の対面を分析する。双方向のダメージ計算と素早さ比較を行い、どちらが有利かを判断するためのデータを提供する。ポケモン対戦の対面判断に使用する。pokemon1Faster は静的な素早さ実数値のみの比較のため、素早さ負けでも先制技で逆転できる判断は pokemon{1,2}PriorityMoves を併用すること。正確な計算のため双方の ability / item の指定を推奨(省略時は通常特性・持ち物なし扱い)。";
|
|
77569
79105
|
const matchupInputSchema = {
|
|
77570
79106
|
pokemon1: pokemonSchema.describe("ポケモン1"),
|
|
77571
79107
|
pokemon2: pokemonSchema.describe("ポケモン2"),
|
|
@@ -77606,7 +79142,7 @@ function registerMatchupTool(server) {
|
|
|
77606
79142
|
item: itemNameResolver,
|
|
77607
79143
|
nature: natureNameResolver
|
|
77608
79144
|
}, pokemonEntryProvider);
|
|
77609
|
-
server.tool(TOOL_NAME$
|
|
79145
|
+
server.tool(TOOL_NAME$11, TOOL_DESCRIPTION$11, matchupInputSchema, async (args) => {
|
|
77610
79146
|
try {
|
|
77611
79147
|
const { pokemon: p1, resolvedName: name1 } = calculator.createPokemonObject(args.pokemon1);
|
|
77612
79148
|
const { pokemon: p2, resolvedName: name2 } = calculator.createPokemonObject(args.pokemon2);
|
|
@@ -77663,9 +79199,9 @@ function registerMatchupTool(server) {
|
|
|
77663
79199
|
}
|
|
77664
79200
|
//#endregion
|
|
77665
79201
|
//#region src/tools/info/move-info.ts
|
|
77666
|
-
const TOOL_NAME$
|
|
77667
|
-
const TOOL_DESCRIPTION$
|
|
77668
|
-
const inputSchema$
|
|
79202
|
+
const TOOL_NAME$10 = "get_move_info";
|
|
79203
|
+
const TOOL_DESCRIPTION$10 = "ポケモンの技の詳細情報(タイプ・威力・命中率・分類・優先度・効果説明)を取得する。対戦で使う技の仕様を確認したいときに使用する。ポケモンチャンピオンズ対応。";
|
|
79204
|
+
const inputSchema$8 = { name: z.string().describe("技名(日本語 or 英語)") };
|
|
77669
79205
|
/**
|
|
77670
79206
|
* 技名を英語に解決する。日本語名・英語名どちらでも受け付ける。
|
|
77671
79207
|
* 名前変換辞書には登録されているがチャンピオンズで使えない技の場合はエラー。
|
|
@@ -77686,7 +79222,7 @@ function normalizeBasePower(category, basePower) {
|
|
|
77686
79222
|
return basePower;
|
|
77687
79223
|
}
|
|
77688
79224
|
function registerMoveInfoTool(server) {
|
|
77689
|
-
server.tool(TOOL_NAME$
|
|
79225
|
+
server.tool(TOOL_NAME$10, TOOL_DESCRIPTION$10, inputSchema$8, async (args) => {
|
|
77690
79226
|
try {
|
|
77691
79227
|
const moveId = toDataId(resolveMoveNameEn$1(args.name));
|
|
77692
79228
|
const entry = movesById.get(moveId);
|
|
@@ -77724,9 +79260,9 @@ function registerMoveInfoTool(server) {
|
|
|
77724
79260
|
}
|
|
77725
79261
|
//#endregion
|
|
77726
79262
|
//#region src/tools/info/nature-info.ts
|
|
77727
|
-
const TOOL_NAME$
|
|
77728
|
-
const TOOL_DESCRIPTION$
|
|
77729
|
-
const inputSchema$
|
|
79263
|
+
const TOOL_NAME$9 = "get_nature_info";
|
|
79264
|
+
const TOOL_DESCRIPTION$9 = "ポケモンの性格の詳細情報(上昇ステ・下降ステ)を取得する。育成方針の検討や性格選びに使用する。plus/minus が null の性格は無補正。ポケモンチャンピオンズ対応。";
|
|
79265
|
+
const inputSchema$7 = { name: z.string().describe("性格名(日本語 or 英語、例: 'ひかえめ'、'Modest')") };
|
|
77730
79266
|
/**
|
|
77731
79267
|
* 性格名を英語に解決する。日本語名・英語名どちらでも受け付ける。
|
|
77732
79268
|
*/
|
|
@@ -77739,7 +79275,7 @@ function resolveNatureNameEn(input) {
|
|
|
77739
79275
|
throw new Error(`性格「${input}」が見つかりません。${suggestionMessage}`);
|
|
77740
79276
|
}
|
|
77741
79277
|
function registerNatureInfoTool(server) {
|
|
77742
|
-
server.tool(TOOL_NAME$
|
|
79278
|
+
server.tool(TOOL_NAME$9, TOOL_DESCRIPTION$9, inputSchema$7, async (args) => {
|
|
77743
79279
|
try {
|
|
77744
79280
|
const englishName = resolveNatureNameEn(args.name);
|
|
77745
79281
|
const entry = naturesById.get(toDataId(englishName));
|
|
@@ -77768,14 +79304,12 @@ function registerNatureInfoTool(server) {
|
|
|
77768
79304
|
}
|
|
77769
79305
|
//#endregion
|
|
77770
79306
|
//#region src/tools/analysis/party-analysis.ts
|
|
77771
|
-
const CHAMPIONS_GEN_NUM$
|
|
77772
|
-
const TOOL_NAME$
|
|
77773
|
-
const TOOL_DESCRIPTION$
|
|
79307
|
+
const CHAMPIONS_GEN_NUM$6 = 0;
|
|
79308
|
+
const TOOL_NAME$8 = "analyze_party_weakness";
|
|
79309
|
+
const TOOL_DESCRIPTION$8 = "パーティ各メンバーのタイプ相性データを集計する。どのタイプが何匹の弱点か(teamWeaknesses)、どのタイプに抜群を取れないか(uncoveredTypes)を返す。致命性の判断は AI が文脈で行う前提。ポケモンチャンピオンズ対応。";
|
|
77774
79310
|
const partyAnalysisInputSchema = { party: z.array(pokemonSchema).describe("パーティメンバー") };
|
|
77775
|
-
/**
|
|
77776
|
-
const
|
|
77777
|
-
const RESISTANCE_THRESHOLD = 1;
|
|
77778
|
-
const IMMUNITY_THRESHOLD = 0;
|
|
79311
|
+
/** ???タイプは計算対象から除外するためのマーカー */
|
|
79312
|
+
const UNKNOWN_TYPE_NAME = "???";
|
|
77779
79313
|
/**
|
|
77780
79314
|
* ポケモン名を英語に解決する。
|
|
77781
79315
|
*/
|
|
@@ -77787,47 +79321,17 @@ function resolvePokemonName$2(name) {
|
|
|
77787
79321
|
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
77788
79322
|
throw new Error(`ポケモン「${name}」が見つかりません。${suggestionMessage}`);
|
|
77789
79323
|
}
|
|
77790
|
-
/** ???タイプは計算対象から除外するためのマーカー */
|
|
77791
|
-
const UNKNOWN_TYPE_NAME = "???";
|
|
77792
79324
|
/**
|
|
77793
79325
|
* 日本語・英語のどちらの名前でも英語名に解決する。
|
|
77794
79326
|
* 未知の名前は undefined を返し、呼び出し側で silent ignore する。
|
|
77795
79327
|
*/
|
|
77796
|
-
function resolveOptionalName
|
|
79328
|
+
function resolveOptionalName(resolver, name) {
|
|
77797
79329
|
if (name === void 0) return void 0;
|
|
77798
79330
|
const english = resolver.toEnglish(name);
|
|
77799
79331
|
if (english !== void 0) return english;
|
|
77800
79332
|
if (resolver.hasEnglishName(name)) return name;
|
|
77801
79333
|
}
|
|
77802
79334
|
/**
|
|
77803
|
-
* ポケモンのタイプに対する各攻撃タイプの倍率を計算する。
|
|
77804
|
-
* 特性・もちものが指定されていれば相性補正を適用する。
|
|
77805
|
-
*/
|
|
77806
|
-
function calculateTypeMatchups(pokemonTypes, gen, context = {}) {
|
|
77807
|
-
const weaknesses = [];
|
|
77808
|
-
const resistances = [];
|
|
77809
|
-
const immunities = [];
|
|
77810
|
-
const defenderTypes = pokemonTypes;
|
|
77811
|
-
for (const attackType of gen.types) {
|
|
77812
|
-
if (attackType.name === UNKNOWN_TYPE_NAME) continue;
|
|
77813
|
-
const multiplier = applyDefensiveOverrides(calculateTypeEffectiveness(gen, attackType.name, defenderTypes), attackType.name, context);
|
|
77814
|
-
if (multiplier === IMMUNITY_THRESHOLD) immunities.push(attackType.name);
|
|
77815
|
-
else if (multiplier >= WEAKNESS_THRESHOLD$1) weaknesses.push({
|
|
77816
|
-
type: attackType.name,
|
|
77817
|
-
multiplier
|
|
77818
|
-
});
|
|
77819
|
-
else if (multiplier < RESISTANCE_THRESHOLD) resistances.push({
|
|
77820
|
-
type: attackType.name,
|
|
77821
|
-
multiplier
|
|
77822
|
-
});
|
|
77823
|
-
}
|
|
77824
|
-
return {
|
|
77825
|
-
weaknesses,
|
|
77826
|
-
resistances,
|
|
77827
|
-
immunities
|
|
77828
|
-
};
|
|
77829
|
-
}
|
|
77830
|
-
/**
|
|
77831
79335
|
* パーティ全体の攻撃範囲でカバーされていないタイプを判定する。
|
|
77832
79336
|
* あるタイプに対して、パーティのどのメンバーのタイプからも等倍以上の攻撃が出せない場合、
|
|
77833
79337
|
* そのタイプは uncovered とみなす。
|
|
@@ -77838,7 +79342,7 @@ function findUncoveredTypes(memberTypes, gen) {
|
|
|
77838
79342
|
if (targetType.name === UNKNOWN_TYPE_NAME) continue;
|
|
77839
79343
|
let isCovered = false;
|
|
77840
79344
|
for (const types of memberTypes) {
|
|
77841
|
-
for (const memberType of types) if (calculateTypeEffectiveness(gen, memberType, [targetType.name]) >=
|
|
79345
|
+
for (const memberType of types) if (calculateTypeEffectiveness(gen, memberType, [targetType.name]) >= 2) {
|
|
77842
79346
|
isCovered = true;
|
|
77843
79347
|
break;
|
|
77844
79348
|
}
|
|
@@ -77849,9 +79353,9 @@ function findUncoveredTypes(memberTypes, gen) {
|
|
|
77849
79353
|
return uncovered;
|
|
77850
79354
|
}
|
|
77851
79355
|
function registerPartyAnalysisTool(server) {
|
|
77852
|
-
server.tool(TOOL_NAME$
|
|
79356
|
+
server.tool(TOOL_NAME$8, TOOL_DESCRIPTION$8, partyAnalysisInputSchema, async (args) => {
|
|
77853
79357
|
try {
|
|
77854
|
-
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$
|
|
79358
|
+
const gen = import_dist.Generations.get(CHAMPIONS_GEN_NUM$6);
|
|
77855
79359
|
const members = [];
|
|
77856
79360
|
const teamWeaknesses = {};
|
|
77857
79361
|
const memberTypesList = [];
|
|
@@ -77862,7 +79366,7 @@ function registerPartyAnalysisTool(server) {
|
|
|
77862
79366
|
const nameJa = entry.nameJa ?? entry.name;
|
|
77863
79367
|
const types = [...entry.types];
|
|
77864
79368
|
memberTypesList.push(types);
|
|
77865
|
-
const { weaknesses, resistances, immunities } =
|
|
79369
|
+
const { weaknesses, resistances, immunities } = classifyPokemonTypeMatchups(types, gen, { ability: resolveOptionalName(abilityNameResolver, member.ability) });
|
|
77866
79370
|
members.push({
|
|
77867
79371
|
name: entry.name,
|
|
77868
79372
|
nameJa,
|
|
@@ -77902,270 +79406,130 @@ function registerPartyAnalysisTool(server) {
|
|
|
77902
79406
|
});
|
|
77903
79407
|
}
|
|
77904
79408
|
//#endregion
|
|
77905
|
-
//#region src/tools/
|
|
77906
|
-
const
|
|
77907
|
-
|
|
77908
|
-
const
|
|
77909
|
-
|
|
77910
|
-
const
|
|
77911
|
-
|
|
77912
|
-
const
|
|
77913
|
-
|
|
77914
|
-
const
|
|
77915
|
-
const
|
|
77916
|
-
|
|
77917
|
-
|
|
77918
|
-
myParty: z.array(pokemonSchema).describe("自分のパーティ(moves 未指定時は learnset 内の全攻撃技を候補にする)"),
|
|
77919
|
-
moves: z.record(z.string(), z.array(z.string())).optional().describe("ポケモン名(日本語 or 英語)をキーに技名配列を値とする map。省略時は learnset から全攻撃技を候補にする。")
|
|
79409
|
+
//#region src/tools/party/party-tools.ts
|
|
79410
|
+
const SAVE_TOOL_NAME = "save_party";
|
|
79411
|
+
const SAVE_TOOL_DESCRIPTION = "パーティを保存する (upsert)。同名のパーティが既に存在する場合は上書きされる。createdAt は新規時のみ現在時刻が記録され、同名上書きの場合は保持される。updatedAt は毎回現在時刻に更新される。";
|
|
79412
|
+
const LOAD_TOOL_NAME = "load_party";
|
|
79413
|
+
const LOAD_TOOL_DESCRIPTION = "保存済みパーティを name 指定で 1 件取得する。存在しない場合はエラーを返す。";
|
|
79414
|
+
const LIST_TOOL_NAME = "list_parties";
|
|
79415
|
+
const LIST_TOOL_DESCRIPTION = "保存済みパーティの一覧 (サマリ) を返す。各要素は { name, memo, updatedAt, memberCount } のみで、メンバー詳細は含まない。詳細は load_party を使用する。";
|
|
79416
|
+
const DELETE_TOOL_NAME = "delete_party";
|
|
79417
|
+
const DELETE_TOOL_DESCRIPTION = "保存済みパーティを name 指定で削除する。存在しない場合はエラーを返す。";
|
|
79418
|
+
const defaultNowProvider = () => /* @__PURE__ */ new Date();
|
|
79419
|
+
const defaultStoreIO = {
|
|
79420
|
+
load: () => loadPartiesFile(),
|
|
79421
|
+
save: (data) => savePartiesFile(data)
|
|
77920
79422
|
};
|
|
77921
|
-
|
|
77922
|
-
|
|
77923
|
-
|
|
77924
|
-
|
|
77925
|
-
|
|
77926
|
-
|
|
77927
|
-
|
|
77928
|
-
|
|
77929
|
-
|
|
77930
|
-
|
|
77931
|
-
|
|
77932
|
-
|
|
77933
|
-
|
|
77934
|
-
}
|
|
77935
|
-
|
|
77936
|
-
|
|
77937
|
-
|
|
77938
|
-
|
|
77939
|
-
|
|
77940
|
-
|
|
77941
|
-
|
|
77942
|
-
|
|
77943
|
-
|
|
77944
|
-
|
|
77945
|
-
|
|
77946
|
-
|
|
77947
|
-
|
|
77948
|
-
* 未知の特性文字列でエラーにしないのは、party_coverage が
|
|
77949
|
-
* 「構築入力を緩く受け取る」UX を取っているため。
|
|
77950
|
-
* 未知の特性は単に override なし扱いとする。
|
|
77951
|
-
*/
|
|
77952
|
-
function resolveOptionalName(resolver, name) {
|
|
77953
|
-
if (name === void 0) return void 0;
|
|
77954
|
-
const english = resolver.toEnglish(name);
|
|
77955
|
-
if (english !== void 0) return english;
|
|
77956
|
-
if (resolver.hasEnglishName(name)) return name;
|
|
77957
|
-
}
|
|
77958
|
-
/**
|
|
77959
|
-
* ポケモン名を pokemon.json のエントリに解決する。
|
|
77960
|
-
*/
|
|
77961
|
-
function resolvePokemonEntry$2(name) {
|
|
77962
|
-
const englishName = pokemonNameResolver.toEnglish(name) ?? (pokemonNameResolver.hasEnglishName(name) ? name : null);
|
|
77963
|
-
if (englishName === null) {
|
|
77964
|
-
const suggestions = pokemonNameResolver.suggestSimilar(name);
|
|
77965
|
-
const suggestionMessage = suggestions.length > 0 ? ` もしかして: ${suggestions.join(", ")}` : "";
|
|
77966
|
-
throw new Error(`ポケモン「${name}」が見つかりません。${suggestionMessage}`);
|
|
77967
|
-
}
|
|
77968
|
-
const entry = pokemonById.get(toDataId(englishName));
|
|
77969
|
-
if (entry === void 0) throw new Error(`ポケモン「${name}」のデータが見つかりません。`);
|
|
77970
|
-
return entry;
|
|
77971
|
-
}
|
|
77972
|
-
/**
|
|
77973
|
-
* moves マップのキー(日本語 or 英語ポケモン名)を英語 ID に正規化する。
|
|
77974
|
-
*/
|
|
77975
|
-
function normalizeMovesMap(moves) {
|
|
77976
|
-
const result = /* @__PURE__ */ new Map();
|
|
77977
|
-
if (moves === void 0) return result;
|
|
77978
|
-
for (const [pokemonName, moveList] of Object.entries(moves)) {
|
|
77979
|
-
const entry = resolvePokemonEntry$2(pokemonName);
|
|
77980
|
-
result.set(entry.id, moveList);
|
|
77981
|
-
}
|
|
77982
|
-
return result;
|
|
77983
|
-
}
|
|
77984
|
-
/**
|
|
77985
|
-
* 攻撃タイプ → 単一防御タイプへの倍率を計算する。
|
|
77986
|
-
*/
|
|
77987
|
-
function getEffectivenessForDefenderType(attackTypeName, defenderTypeName, gen) {
|
|
77988
|
-
return calculateTypeEffectiveness(gen, attackTypeName, [defenderTypeName]);
|
|
79423
|
+
const nameField = z.string().min(1, { message: "名前は 1 文字以上で指定してください。" }).max(100, { message: `名前は 100 文字以下で指定してください。` });
|
|
79424
|
+
const partyMemberInputSchema = z.object({
|
|
79425
|
+
name: nameField.describe("ポケモン名 (日本語 or 英語)。"),
|
|
79426
|
+
nature: nameField.optional().describe("性格名 (日本語 or 英語)。"),
|
|
79427
|
+
ability: nameField.optional().describe("特性名 (日本語 or 英語)。"),
|
|
79428
|
+
item: nameField.optional().describe("持ち物名 (日本語 or 英語)。"),
|
|
79429
|
+
evs: evsSchema.optional().describe("能力ポイント (SP) 配分。"),
|
|
79430
|
+
moves: z.array(nameField).max(4, { message: `技は 4 個までです。` }).optional().describe("技リスト (最大 4)。")
|
|
79431
|
+
}).describe("パーティメンバー 1 匹分のビルド情報。");
|
|
79432
|
+
const partyNameField = z.string().min(1, { message: "パーティ名は 1 文字以上で指定してください。" }).max(50, { message: `パーティ名は 50 文字以下で指定してください。` });
|
|
79433
|
+
const saveInputSchema = {
|
|
79434
|
+
name: partyNameField.describe("パーティの識別子 (同名は上書き)。"),
|
|
79435
|
+
memo: z.string().max(MAX_PARTY_MEMO_LENGTH, { message: `メモは ${MAX_PARTY_MEMO_LENGTH} 文字以下で指定してください。` }).optional().describe("自由記述メモ。"),
|
|
79436
|
+
members: z.array(partyMemberInputSchema).min(1, { message: `パーティには 1 匹以上を含めてください。` }).max(6, { message: `パーティには 6 匹までしか含められません。` }).describe("1〜6 匹のメンバー。")
|
|
79437
|
+
};
|
|
79438
|
+
const loadInputSchema = { name: partyNameField.describe("取得するパーティ名。") };
|
|
79439
|
+
const deleteInputSchema = { name: partyNameField.describe("削除するパーティ名。") };
|
|
79440
|
+
const listInputSchema = {};
|
|
79441
|
+
function toErrorResponse(error) {
|
|
79442
|
+
const message = error instanceof Error ? error.message : "不明なエラーが発生しました";
|
|
79443
|
+
return {
|
|
79444
|
+
content: [{
|
|
79445
|
+
type: "text",
|
|
79446
|
+
text: JSON.stringify({ error: message })
|
|
79447
|
+
}],
|
|
79448
|
+
isError: true
|
|
79449
|
+
};
|
|
77989
79450
|
}
|
|
77990
|
-
|
|
77991
|
-
|
|
77992
|
-
|
|
77993
|
-
|
|
77994
|
-
|
|
79451
|
+
function toTextResponse(value) {
|
|
79452
|
+
return { content: [{
|
|
79453
|
+
type: "text",
|
|
79454
|
+
text: JSON.stringify(value)
|
|
79455
|
+
}] };
|
|
77995
79456
|
}
|
|
77996
|
-
|
|
77997
|
-
|
|
77998
|
-
|
|
77999
|
-
|
|
78000
|
-
|
|
78001
|
-
|
|
78002
|
-
|
|
78003
|
-
|
|
78004
|
-
* - 先頭 `MAX_EXAMPLE_POKEMON` 件を採用
|
|
78005
|
-
*/
|
|
78006
|
-
function buildRealDualTypeMap(pokemon) {
|
|
78007
|
-
const accumulator = /* @__PURE__ */ new Map();
|
|
78008
|
-
for (const entry of pokemon) {
|
|
78009
|
-
if (entry.types.length !== DUAL_TYPE_COUNT) continue;
|
|
78010
|
-
const sortedTypes = [...entry.types].sort((a, b) => a.localeCompare(b));
|
|
78011
|
-
const key = `${sortedTypes[0]}${DUAL_TYPE_KEY_SEPARATOR}${sortedTypes[1]}`;
|
|
78012
|
-
const existing = accumulator.get(key);
|
|
78013
|
-
if (existing === void 0) accumulator.set(key, {
|
|
78014
|
-
types: sortedTypes,
|
|
78015
|
-
entries: [entry]
|
|
78016
|
-
});
|
|
78017
|
-
else existing.entries.push(entry);
|
|
78018
|
-
}
|
|
78019
|
-
const result = /* @__PURE__ */ new Map();
|
|
78020
|
-
for (const [key, { types, entries }] of accumulator) {
|
|
78021
|
-
const examplePokemon = [...entries].sort((a, b) => {
|
|
78022
|
-
const aIsForme = a.baseSpecies !== null ? 1 : 0;
|
|
78023
|
-
const bIsForme = b.baseSpecies !== null ? 1 : 0;
|
|
78024
|
-
if (aIsForme !== bIsForme) return aIsForme - bIsForme;
|
|
78025
|
-
return a.name.localeCompare(b.name);
|
|
78026
|
-
}).slice(0, MAX_EXAMPLE_POKEMON).map((entry) => pokemonNameResolver.toJapanese(entry.name) ?? entry.name);
|
|
78027
|
-
result.set(key, {
|
|
78028
|
-
types,
|
|
78029
|
-
examplePokemon
|
|
78030
|
-
});
|
|
78031
|
-
}
|
|
78032
|
-
return result;
|
|
78033
|
-
}
|
|
78034
|
-
/**
|
|
78035
|
-
* 候補の attacker で `bestAttackers` を更新する共通ロジック。
|
|
78036
|
-
*
|
|
78037
|
-
* - `candidate.multiplier > currentMax` の場合は bestAttackers をクリアして入れ替え、新しい max を返す
|
|
78038
|
-
* - タイの場合は同一ポケモンが未登録であれば追加する(multiplier > 0 のときのみ、0 倍無効は列挙しない)
|
|
78039
|
-
* - それ以外は現状維持
|
|
78040
|
-
*
|
|
78041
|
-
* bestAttackers は in-place で更新する。maxMultiplier は戻り値として返す。
|
|
78042
|
-
*/
|
|
78043
|
-
function updateBestAttackers(currentMax, bestAttackers, candidate) {
|
|
78044
|
-
if (candidate.multiplier > currentMax) {
|
|
78045
|
-
bestAttackers.length = 0;
|
|
78046
|
-
bestAttackers.push(candidate);
|
|
78047
|
-
return candidate.multiplier;
|
|
78048
|
-
}
|
|
78049
|
-
if (candidate.multiplier === currentMax && candidate.multiplier > 0) {
|
|
78050
|
-
if (!bestAttackers.some((ba) => ba.pokemon === candidate.pokemon)) bestAttackers.push(candidate);
|
|
78051
|
-
}
|
|
78052
|
-
return currentMax;
|
|
79457
|
+
function toSummary(party) {
|
|
79458
|
+
const summary = {
|
|
79459
|
+
name: party.name,
|
|
79460
|
+
updatedAt: party.updatedAt,
|
|
79461
|
+
memberCount: party.members.length
|
|
79462
|
+
};
|
|
79463
|
+
if (party.memo !== void 0) summary.memo = party.memo;
|
|
79464
|
+
return summary;
|
|
78053
79465
|
}
|
|
78054
79466
|
/**
|
|
78055
|
-
*
|
|
78056
|
-
*
|
|
79467
|
+
* パーティ永続化 4 ツールをサーバーに登録する。
|
|
79468
|
+
* deps は主にテスト用。本番は省略してデフォルト (ファイル I/O + 現在時刻) を使う。
|
|
78057
79469
|
*/
|
|
78058
|
-
function
|
|
78059
|
-
const
|
|
78060
|
-
const
|
|
78061
|
-
|
|
78062
|
-
|
|
78063
|
-
|
|
78064
|
-
|
|
78065
|
-
|
|
78066
|
-
|
|
78067
|
-
|
|
78068
|
-
|
|
78069
|
-
|
|
78070
|
-
|
|
78071
|
-
|
|
78072
|
-
|
|
78073
|
-
|
|
79470
|
+
function registerPartyTools(server, deps = {}) {
|
|
79471
|
+
const storeIO = deps.storeIO ?? defaultStoreIO;
|
|
79472
|
+
const now = deps.now ?? defaultNowProvider;
|
|
79473
|
+
server.tool(SAVE_TOOL_NAME, SAVE_TOOL_DESCRIPTION, saveInputSchema, async (args) => {
|
|
79474
|
+
try {
|
|
79475
|
+
const file = storeIO.load();
|
|
79476
|
+
const nowIso = now().toISOString();
|
|
79477
|
+
const existingIndex = file.parties.findIndex((p) => p.name === args.name);
|
|
79478
|
+
const createdAt = existingIndex >= 0 ? file.parties[existingIndex].createdAt : nowIso;
|
|
79479
|
+
const party = {
|
|
79480
|
+
name: args.name,
|
|
79481
|
+
members: args.members,
|
|
79482
|
+
createdAt,
|
|
79483
|
+
updatedAt: nowIso
|
|
79484
|
+
};
|
|
79485
|
+
if (args.memo !== void 0) party.memo = args.memo;
|
|
79486
|
+
if (existingIndex >= 0) file.parties[existingIndex] = party;
|
|
79487
|
+
else file.parties.push(party);
|
|
79488
|
+
storeIO.save({
|
|
79489
|
+
schemaVersion: 1,
|
|
79490
|
+
parties: file.parties
|
|
79491
|
+
});
|
|
79492
|
+
return toTextResponse({
|
|
79493
|
+
saved: true,
|
|
79494
|
+
overwrote: existingIndex >= 0,
|
|
79495
|
+
party,
|
|
79496
|
+
filePath: resolvePartiesFilePath()
|
|
78074
79497
|
});
|
|
79498
|
+
} catch (error) {
|
|
79499
|
+
return toErrorResponse(error);
|
|
78075
79500
|
}
|
|
78076
|
-
members.push({
|
|
78077
|
-
entry,
|
|
78078
|
-
attackingMoves
|
|
78079
|
-
});
|
|
78080
|
-
}
|
|
78081
|
-
const attackingTypes = [];
|
|
78082
|
-
const typeJaMap = new Map(championsTypes.map((t) => [t.name, t.nameJa]));
|
|
78083
|
-
for (const typeName of attackingTypesSet) attackingTypes.push({
|
|
78084
|
-
type: typeName,
|
|
78085
|
-
nameJa: typeJaMap.get(typeName) ?? typeName
|
|
78086
79501
|
});
|
|
78087
|
-
|
|
78088
|
-
|
|
78089
|
-
|
|
78090
|
-
|
|
78091
|
-
|
|
78092
|
-
|
|
78093
|
-
|
|
78094
|
-
const multiplier = getEffectivenessForDefenderType(effectiveType, defenderType.name, gen);
|
|
78095
|
-
const attacker = {
|
|
78096
|
-
pokemon: member.entry.name,
|
|
78097
|
-
move: move.name,
|
|
78098
|
-
multiplier
|
|
78099
|
-
};
|
|
78100
|
-
if (effectiveType !== move.type) attacker.effectiveType = effectiveType;
|
|
78101
|
-
maxMultiplier = updateBestAttackers(maxMultiplier, bestAttackers, attacker);
|
|
79502
|
+
server.tool(LOAD_TOOL_NAME, LOAD_TOOL_DESCRIPTION, loadInputSchema, async (args) => {
|
|
79503
|
+
try {
|
|
79504
|
+
const party = storeIO.load().parties.find((p) => p.name === args.name);
|
|
79505
|
+
if (party === void 0) throw new Error(`パーティ「${args.name}」が見つかりません。list_parties で一覧を確認してください。`);
|
|
79506
|
+
return toTextResponse({ party });
|
|
79507
|
+
} catch (error) {
|
|
79508
|
+
return toErrorResponse(error);
|
|
78102
79509
|
}
|
|
78103
|
-
|
|
78104
|
-
|
|
78105
|
-
|
|
78106
|
-
|
|
78107
|
-
|
|
78108
|
-
|
|
78109
|
-
if (maxMultiplier <= 1) uncoveredTypes.push({
|
|
78110
|
-
type: defenderType.name,
|
|
78111
|
-
nameJa: defenderType.nameJa
|
|
78112
|
-
});
|
|
78113
|
-
}
|
|
78114
|
-
const dualTypeMap = buildRealDualTypeMap(championsPokemon);
|
|
78115
|
-
const dualTypeCoverage = [];
|
|
78116
|
-
let dualTypeUncoveredCount = 0;
|
|
78117
|
-
for (const { types, examplePokemon } of dualTypeMap.values()) {
|
|
78118
|
-
let maxMultiplier = 0;
|
|
78119
|
-
const bestAttackers = [];
|
|
78120
|
-
for (const member of members) for (const { move, effectiveType } of member.attackingMoves) {
|
|
78121
|
-
const multiplier = getEffectivenessForDualTypes(effectiveType, types, gen);
|
|
78122
|
-
const attacker = {
|
|
78123
|
-
pokemon: member.entry.name,
|
|
78124
|
-
move: move.name,
|
|
78125
|
-
multiplier
|
|
78126
|
-
};
|
|
78127
|
-
if (effectiveType !== move.type) attacker.effectiveType = effectiveType;
|
|
78128
|
-
maxMultiplier = updateBestAttackers(maxMultiplier, bestAttackers, attacker);
|
|
79510
|
+
});
|
|
79511
|
+
server.tool(LIST_TOOL_NAME, LIST_TOOL_DESCRIPTION, listInputSchema, async () => {
|
|
79512
|
+
try {
|
|
79513
|
+
return toTextResponse({ parties: storeIO.load().parties.map(toSummary) });
|
|
79514
|
+
} catch (error) {
|
|
79515
|
+
return toErrorResponse(error);
|
|
78129
79516
|
}
|
|
78130
|
-
dualTypeCoverage.push({
|
|
78131
|
-
defenderTypes: types,
|
|
78132
|
-
defenderTypesJa: [typeJaMap.get(types[0]) ?? types[0], typeJaMap.get(types[1]) ?? types[1]],
|
|
78133
|
-
maxMultiplier,
|
|
78134
|
-
bestAttackers,
|
|
78135
|
-
examplePokemon
|
|
78136
|
-
});
|
|
78137
|
-
if (maxMultiplier <= 1) dualTypeUncoveredCount += 1;
|
|
78138
|
-
}
|
|
78139
|
-
dualTypeCoverage.sort((a, b) => {
|
|
78140
|
-
if (a.maxMultiplier !== b.maxMultiplier) return a.maxMultiplier - b.maxMultiplier;
|
|
78141
|
-
if (a.defenderTypes[0] !== b.defenderTypes[0]) return a.defenderTypes[0].localeCompare(b.defenderTypes[0]);
|
|
78142
|
-
return a.defenderTypes[1].localeCompare(b.defenderTypes[1]);
|
|
78143
79517
|
});
|
|
78144
|
-
|
|
78145
|
-
attackingTypes,
|
|
78146
|
-
coverage,
|
|
78147
|
-
uncoveredTypes,
|
|
78148
|
-
dualTypeCoverage,
|
|
78149
|
-
dualTypeUncoveredCount
|
|
78150
|
-
};
|
|
78151
|
-
}
|
|
78152
|
-
function registerPartyCoverageTool(server) {
|
|
78153
|
-
server.tool(TOOL_NAME$8, TOOL_DESCRIPTION$8, inputSchema$7, async (args) => {
|
|
79518
|
+
server.tool(DELETE_TOOL_NAME, DELETE_TOOL_DESCRIPTION, deleteInputSchema, async (args) => {
|
|
78154
79519
|
try {
|
|
78155
|
-
const
|
|
78156
|
-
|
|
78157
|
-
|
|
78158
|
-
|
|
78159
|
-
|
|
79520
|
+
const file = storeIO.load();
|
|
79521
|
+
const nextParties = file.parties.filter((p) => p.name !== args.name);
|
|
79522
|
+
if (nextParties.length === file.parties.length) throw new Error(`パーティ「${args.name}」が見つかりません。`);
|
|
79523
|
+
storeIO.save({
|
|
79524
|
+
schemaVersion: 1,
|
|
79525
|
+
parties: nextParties
|
|
79526
|
+
});
|
|
79527
|
+
return toTextResponse({
|
|
79528
|
+
deleted: true,
|
|
79529
|
+
name: args.name
|
|
79530
|
+
});
|
|
78160
79531
|
} catch (error) {
|
|
78161
|
-
|
|
78162
|
-
return {
|
|
78163
|
-
content: [{
|
|
78164
|
-
type: "text",
|
|
78165
|
-
text: JSON.stringify({ error: message })
|
|
78166
|
-
}],
|
|
78167
|
-
isError: true
|
|
78168
|
-
};
|
|
79532
|
+
return toErrorResponse(error);
|
|
78169
79533
|
}
|
|
78170
79534
|
});
|
|
78171
79535
|
}
|
|
@@ -79233,10 +80597,12 @@ function createServer() {
|
|
|
79233
80597
|
version: SERVER_VERSION
|
|
79234
80598
|
}, { instructions: SERVER_INSTRUCTIONS });
|
|
79235
80599
|
registerAbilityInfoTool(server);
|
|
80600
|
+
registerComparePartiesTool(server);
|
|
79236
80601
|
registerConditionInfoTool(server);
|
|
79237
80602
|
registerDamageCalculationTools(server);
|
|
79238
80603
|
registerDamageRangeTool(server);
|
|
79239
80604
|
registerFindCountersTool(server);
|
|
80605
|
+
registerImportPartyFromTextTool(server);
|
|
79240
80606
|
registerItemInfoTool(server);
|
|
79241
80607
|
registerLearnsetTool(server);
|
|
79242
80608
|
registerMatchupTool(server);
|
|
@@ -79244,6 +80610,7 @@ function createServer() {
|
|
|
79244
80610
|
registerNatureInfoTool(server);
|
|
79245
80611
|
registerPartyAnalysisTool(server);
|
|
79246
80612
|
registerPartyCoverageTool(server);
|
|
80613
|
+
registerPartyTools(server);
|
|
79247
80614
|
registerPokemonInfoTools(server);
|
|
79248
80615
|
registerPokemonSummaryTool(server);
|
|
79249
80616
|
registerSearchByAbilityTool(server);
|