@chrischall/warapp-mcp 0.8.0 → 0.10.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -2
- package/dist/analysis/bonus-delay.js +91 -0
- package/dist/analysis/calibrate.js +94 -2
- package/dist/analysis/plan/captures.js +10 -1
- package/dist/analysis/plan/deploy-estimates.js +36 -5
- package/dist/analysis/plan/estimates.js +1 -0
- package/dist/analysis/plan/spread-bind.js +49 -0
- package/dist/analysis/plan/targets.js +6 -2
- package/dist/analysis/plan/threats.js +11 -5
- package/dist/analysis/planner.js +74 -39
- package/dist/bundle.js +918 -268
- package/dist/calibration-source.js +45 -2
- package/dist/cards.js +37 -0
- package/dist/my-games.js +23 -3
- package/dist/my-orders.js +134 -0
- package/dist/team-cards.js +2 -2
- package/dist/team-orders.js +51 -23
- package/dist/tools/card-advice.js +31 -2
- package/dist/tools/chat-inbox.js +95 -14
- package/dist/tools/chat-read-mark.js +241 -107
- package/dist/tools/chat.js +52 -0
- package/dist/tools/check-plan.js +14 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/live.js +13 -3
- package/dist/tools/my-games.js +7 -1
- package/dist/tools/my-orders.js +110 -0
- package/dist/tools/picks.js +8 -4
- package/dist/tools/team-brief.js +1 -1
- package/dist/tools/team.js +25 -9
- package/dist/tools/turn.js +39 -5
- package/dist/tools/uncommit.js +27 -5
- package/dist/trend.js +36 -1
- package/dist/version.js +1 -1
- package/manifest.json +5 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +30 -8
|
@@ -3,10 +3,34 @@ import { anonymousHistoryOfRecord, finishedPath, historyOfRecord, listFinishedRe
|
|
|
3
3
|
import { readStoredMap } from './map-store.js';
|
|
4
4
|
import { playerRecordSalt } from './player-record-store.js';
|
|
5
5
|
import { gamesDir, loadReplay } from './replay.js';
|
|
6
|
-
import {
|
|
6
|
+
import { readCachedOrders } from './trend.js';
|
|
7
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
7
9
|
const count = (o, k) => {
|
|
8
10
|
o[k] = (o[k] ?? 0) + 1;
|
|
9
11
|
};
|
|
12
|
+
/** Every (game, player) a local per-game cache names: boards, outlook and decision logs. Never throws. */
|
|
13
|
+
async function cachedGames(dir) {
|
|
14
|
+
const out = new Map();
|
|
15
|
+
for (const sub of ['boards', 'outlook', 'decisions']) {
|
|
16
|
+
const names = await readdir(join(dir, sub)).catch(() => []);
|
|
17
|
+
for (const n of names.filter((x) => /^\d+\.json$/.test(x)).sort()) {
|
|
18
|
+
const id = Number(n.slice(0, -5));
|
|
19
|
+
if (out.has(id))
|
|
20
|
+
continue;
|
|
21
|
+
try {
|
|
22
|
+
const v = JSON.parse(await readFile(join(dir, sub, n), 'utf8'));
|
|
23
|
+
const o = v;
|
|
24
|
+
if (o && o.gameId === id && typeof o.playerId === 'number')
|
|
25
|
+
out.set(id, o.playerId);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// unreadable: names nothing
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [...out].map(([gameId, playerId]) => ({ gameId, playerId }));
|
|
33
|
+
}
|
|
10
34
|
async function settingsRecordIds(dir) {
|
|
11
35
|
const names = await readdir(gamesDir(dir)).catch(() => []);
|
|
12
36
|
return names
|
|
@@ -29,6 +53,11 @@ export async function calibrationSources(dir) {
|
|
|
29
53
|
byPath.set(finishedPath(dir, salt, replay.playerId, id), replay);
|
|
30
54
|
}
|
|
31
55
|
const paths = salt ? await listFinishedRecords(dir) : [];
|
|
56
|
+
// #503: the game ids local caches still name, by the record path they would match.
|
|
57
|
+
const named = new Map();
|
|
58
|
+
if (salt && paths.length)
|
|
59
|
+
for (const c of await cachedGames(dir))
|
|
60
|
+
named.set(finishedPath(dir, salt, c.playerId, c.gameId), c);
|
|
32
61
|
const seen = new Set();
|
|
33
62
|
for (const path of paths) {
|
|
34
63
|
seen.add(path);
|
|
@@ -65,7 +94,21 @@ export async function calibrationSources(dir) {
|
|
|
65
94
|
return { turn: b.turn, board: b.board, ...(o ? { orders: o } : {}) };
|
|
66
95
|
})
|
|
67
96
|
: [];
|
|
68
|
-
|
|
97
|
+
const recovered = fromReplay ? undefined : named.get(path);
|
|
98
|
+
const gameId = fromReplay ? replay.game.id : recovered?.gameId;
|
|
99
|
+
const sentTurns = cached.length
|
|
100
|
+
? cached.flatMap((b) => (b.orders ? [b.turn] : []))
|
|
101
|
+
: recovered
|
|
102
|
+
? [...(await readCachedOrders(dir, recovered.gameId, recovered.playerId)).keys()]
|
|
103
|
+
: [];
|
|
104
|
+
const opening = {
|
|
105
|
+
...(gameId !== undefined ? { gameId } : {}),
|
|
106
|
+
planned: rec.outlook !== undefined,
|
|
107
|
+
bootedTurn: rec.outcome?.result === 'booted' ? (rec.outcome.leftTurn ?? rec.outcome.outTurn ?? null) : null,
|
|
108
|
+
failedAttackTurns: [...new Set((rec.failedAttacks ?? []).map((f) => f.turn))].sort((a, b) => a - b),
|
|
109
|
+
sentTurns: [...new Set(sentTurns)].sort((a, b) => a - b),
|
|
110
|
+
};
|
|
111
|
+
out.inputs.push({ source: fromReplay ? 'settings-record' : 'record-only', history, settings, map, cached, opening });
|
|
69
112
|
}
|
|
70
113
|
// A settings record whose game has no record: its pass has not run (or the record was pruned).
|
|
71
114
|
for (const path of byPath.keys())
|
package/dist/cards.js
CHANGED
|
@@ -435,3 +435,40 @@ export function readActiveCards(info) {
|
|
|
435
435
|
walk(standing, 0);
|
|
436
436
|
return out;
|
|
437
437
|
}
|
|
438
|
+
const GAME_TURN = /\.GameTurn$/;
|
|
439
|
+
const REINFORCEMENT_PLAY = /\.GameOrderPlayCardReinforcement$/;
|
|
440
|
+
/**
|
|
441
|
+
* #427: who played a Reinforcement card in the last turn, from a decoded LatestGameInfo's `GameTurn` — the
|
|
442
|
+
* turn just resolved: its order list, every player's orders in it that this player may see — and that
|
|
443
|
+
* turn's number (1-based: the GameTurn carries it 0-based). In-game player ids, in order; `undefined` when
|
|
444
|
+
* the info carries no readable GameTurn. Never walks my pending orders (the info's own order list).
|
|
445
|
+
*
|
|
446
|
+
* VERIFIED live 2026-11-22 (read-only GetLatestGameInfo on games in progress): the info carries one
|
|
447
|
+
* `warlight.shared.GameTurn` { null, the order list, int32 turn (0-based: one less than the turns
|
|
448
|
+
* completed), a date }; a card play there is `GameOrderPlayCard<X>` { its own fields, the card GUID, the
|
|
449
|
+
* player (in-game id), its result (pointing back at the order), null } — a Reinforcement play has no own
|
|
450
|
+
* field and no armies. In a game with `CardPlayingsFogged` false an opponent's Reinforcement play showed
|
|
451
|
+
* though none of its deploys were in view. Whether a fogged game hides them was not seen; callers read
|
|
452
|
+
* this only when the game does not fog card plays.
|
|
453
|
+
*/
|
|
454
|
+
export function readTurnReinforcementPlays(info) {
|
|
455
|
+
if (!isObj(info))
|
|
456
|
+
return undefined;
|
|
457
|
+
const turn = fields(info).find((v) => isObj(v) && typeof v.$type === 'string' && GAME_TURN.test(v.$type));
|
|
458
|
+
if (!turn)
|
|
459
|
+
return undefined;
|
|
460
|
+
const own = fields(turn);
|
|
461
|
+
const ints = own.filter((v) => typeof v === 'number' && Number.isInteger(v));
|
|
462
|
+
const orders = own.find((v) => Array.isArray(v));
|
|
463
|
+
if (ints.length !== 1 || !orders)
|
|
464
|
+
return undefined;
|
|
465
|
+
const players = [];
|
|
466
|
+
for (const o of orders) {
|
|
467
|
+
if (!isObj(o) || typeof o.$type !== 'string' || !REINFORCEMENT_PLAY.test(o.$type))
|
|
468
|
+
continue;
|
|
469
|
+
const player = fields(o).filter((v) => typeof v === 'number' && Number.isInteger(v)).at(-1);
|
|
470
|
+
if (player !== undefined)
|
|
471
|
+
players.push(player);
|
|
472
|
+
}
|
|
473
|
+
return { turn: ints[0] + 1, players };
|
|
474
|
+
}
|
package/dist/my-games.js
CHANGED
|
@@ -39,6 +39,15 @@ export const GAME_INFO_FIELDS = 27;
|
|
|
39
39
|
/** GameInfoPlayer field positions in read order, and its whole field count. */
|
|
40
40
|
const GP = { committed: 2, name: 5, id: 6, state: 7, team: 8 };
|
|
41
41
|
export const GAME_INFO_PLAYER_FIELDS = 10;
|
|
42
|
+
/** The view of the flags, or null when they did not read. */
|
|
43
|
+
export const unreadChatView = (f) => f ? { public: f.public, team: f.team, private: f.private, group: f.group, toMe: f.private } : null;
|
|
44
|
+
/** The flag each chat channel's unread state shows in (the web client's `unknown` is the game groups). */
|
|
45
|
+
export const CHANNEL_FLAG = {
|
|
46
|
+
public: 'public',
|
|
47
|
+
team: 'team',
|
|
48
|
+
private: 'private',
|
|
49
|
+
unknown: 'group',
|
|
50
|
+
};
|
|
42
51
|
/** Whether any of the flags is set. */
|
|
43
52
|
export const anyUnreadChat = (f) => f !== undefined && (f.group || f.private || f.public || f.team);
|
|
44
53
|
/** The game's unread-chat flags in the list, or undefined (not listed, or the flags did not read). */
|
|
@@ -161,9 +170,16 @@ export function summarizeMyGames(games, myInGameId) {
|
|
|
161
170
|
state: playerStateName(p.stateCode),
|
|
162
171
|
committed: p.committed,
|
|
163
172
|
})),
|
|
173
|
+
unreadChat: unreadChatView(g.unreadChat),
|
|
164
174
|
};
|
|
165
175
|
});
|
|
166
|
-
|
|
176
|
+
// Waiting on me first, then unread private chat, then the rest (war.app's order within each).
|
|
177
|
+
const privateUnread = (g) => !g.waitingOnYou && g.unreadChat?.private === true;
|
|
178
|
+
return [
|
|
179
|
+
...out.filter((g) => g.waitingOnYou),
|
|
180
|
+
...out.filter(privateUnread),
|
|
181
|
+
...out.filter((g) => !g.waitingOnYou && !privateUnread(g)),
|
|
182
|
+
];
|
|
167
183
|
}
|
|
168
184
|
/**
|
|
169
185
|
* Games I can still take a turn in (`myInGameId`): being played or distributing
|
|
@@ -204,14 +220,18 @@ export function unflaggedFinished(games) {
|
|
|
204
220
|
/** The longest line `view: 'brief'` answers (the context-groups contract). */
|
|
205
221
|
const BRIEF_MAX = 120;
|
|
206
222
|
/**
|
|
207
|
-
* One brief line, `name — <turn N | state> — waiting on you | waiting on others`,
|
|
223
|
+
* One brief line, `name — <turn N | state> — waiting on you | waiting on others`, then ` — unread private`
|
|
224
|
+
* and ` — unread <channels>` from the game list's unread flags (flags, not counts),
|
|
208
225
|
* at most {@link BRIEF_MAX} characters: the name (another player's text) is
|
|
209
226
|
* flattened to one line and shortened first; a name starting `-- ` or `\` gets
|
|
210
227
|
* one leading `\` so it can never read as a note line.
|
|
211
228
|
*/
|
|
212
229
|
export function briefGameLine(game) {
|
|
213
230
|
const where = game.state === 'Playing' && game.turn !== null ? `turn ${game.turn}` : game.state;
|
|
214
|
-
const
|
|
231
|
+
const u = game.unreadChat;
|
|
232
|
+
const others = u ? ['public', 'team', 'group'].filter((c) => u[c]) : [];
|
|
233
|
+
const unread = (u?.private ? ' — unread private' : '') + (others.length ? ` — unread ${others.join(', ')}` : '');
|
|
234
|
+
const tail = ` — ${where} — ${game.waitingOnYou ? 'waiting on you' : 'waiting on others'}${unread}`;
|
|
215
235
|
const flat = game.name.replace(/\s+/g, ' ').trim() || '(untitled)';
|
|
216
236
|
const escaped = flat.startsWith('-- ') || flat.startsWith('\\') ? `\\${flat}` : flat;
|
|
217
237
|
const room = BRIEF_MAX - tail.length;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// My own orders this turn, read back from a decoded LatestGameInfo (warapp_get_my_orders).
|
|
2
|
+
//
|
|
3
|
+
// From the client bundle (6.08.0.2, read 2026-11-22): LatestGameInfo's FIRST field is a list of GameOrder —
|
|
4
|
+
// the client's "active orders" (its log line "EndCommit Wrote N active orders"), which it fills on a commit and
|
|
5
|
+
// shows again in "Modify orders" (its ShowCommittedTurn state). The server builds it from the game's
|
|
6
|
+
// ActiveTurnOrders entry for the asking player only, while the game is being played (its second field is the
|
|
7
|
+
// same for picks while distributing). VERIFIED live 2026-11-22: a committed turn read back exactly — two
|
|
8
|
+
// deploys, a Gift card play (recipient and territory), six moves — and five more committed games read their
|
|
9
|
+
// deploys, moves and an Order Priority play. Still UNVERIFIED: what it holds while my orders are entered but not
|
|
10
|
+
// committed (the same ActiveTurnOrders carries a teammate's entered orders before it commits, V5).
|
|
11
|
+
//
|
|
12
|
+
// The field is found by its values, not its minified name: the one field of the info that is a non-empty list of
|
|
13
|
+
// GameOrder records (a teammate's orders sit inside the TeammateOrders dict, never directly in the info). An empty
|
|
14
|
+
// list or none names no field, so it reads as unknown, never as "no orders". Each order is decoded by
|
|
15
|
+
// `decodeOrder` (src/team-orders.ts, shared with the teammate reader) and projected into the shape
|
|
16
|
+
// warapp_submit_turn takes; a card play's own fields are read by class, in the order the bundle's writer puts them
|
|
17
|
+
// (src/protocol/methods.ts `writeCardPlayOrder`). Players come back as GameFeed ids. Never throws.
|
|
18
|
+
import { playersByInGameId } from './live.js';
|
|
19
|
+
import { fields, isObj } from './protocol/decoded.js';
|
|
20
|
+
import { armiesOf, decodeOrder, orderClass } from './team-orders.js';
|
|
21
|
+
const ORDER_PREFIX = 'warlight.shared.GameOrder';
|
|
22
|
+
const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
|
|
23
|
+
const isOrder = (v) => isObj(v) && typeof v.$type === 'string' && v.$type.startsWith(ORDER_PREFIX);
|
|
24
|
+
/**
|
|
25
|
+
* The list of my orders in a decoded LatestGameInfo: the one field that is a non-empty list of GameOrder
|
|
26
|
+
* records. `undefined` (unknown) when there is none, or more than one.
|
|
27
|
+
*/
|
|
28
|
+
export function readMyOrderList(info) {
|
|
29
|
+
if (!isObj(info))
|
|
30
|
+
return undefined;
|
|
31
|
+
const lists = fields(info).filter((v) => Array.isArray(v) && v.length > 0 && v.every((o) => o === null || isOrder(o)) && v.some(isOrder));
|
|
32
|
+
return lists.length === 1 ? lists[0].filter((o) => o !== null) : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Which own fields each card play carries, by class (the bundle's writers; `Abandon` is Emergency Blockade). */
|
|
35
|
+
const TERRITORY_CARDS = new Set(['Blockade', 'Abandon', 'Bomb', 'Reconnaissance']);
|
|
36
|
+
const PLAYER_CARDS = new Set(['Spy', 'Sanctions']);
|
|
37
|
+
const PLAIN_CARDS = new Set(['Reinforcement', 'OrderPriority', 'OrderDelay']);
|
|
38
|
+
/**
|
|
39
|
+
* My orders projected into `warapp_submit_turn`'s shape; `null` (unknown) when the info carries no list of them.
|
|
40
|
+
* A card naming a player not in `players` (in-game ids) is unread, never sent back with a wrong id.
|
|
41
|
+
*/
|
|
42
|
+
export function myOrdersOf(info, players) {
|
|
43
|
+
const list = readMyOrderList(info);
|
|
44
|
+
if (!list)
|
|
45
|
+
return null;
|
|
46
|
+
const byInGame = playersByInGameId(players);
|
|
47
|
+
const feedId = (inGame) => (inGame === 0 ? 0 : byInGame.get(inGame)?.id);
|
|
48
|
+
const orders = [];
|
|
49
|
+
const unread = [];
|
|
50
|
+
let movesSeen = 0;
|
|
51
|
+
const delays = [];
|
|
52
|
+
for (const raw of list) {
|
|
53
|
+
const cls = orderClass(raw);
|
|
54
|
+
const d = decodeOrder(raw);
|
|
55
|
+
if (!d) {
|
|
56
|
+
unread.push(cls);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (d.kind === 'deploy') {
|
|
60
|
+
orders.push({ kind: 'deploy', territory: d.territoryId, armies: d.armies });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (d.kind === 'move') {
|
|
64
|
+
movesSeen += 1;
|
|
65
|
+
orders.push({
|
|
66
|
+
kind: 'move',
|
|
67
|
+
from: d.from,
|
|
68
|
+
to: d.to,
|
|
69
|
+
armies: d.armies,
|
|
70
|
+
...(d.mode === 'attack' ? { mode: 'attack-only' } : {}),
|
|
71
|
+
...(d.mode === 'transfer' ? { mode: 'transfer-only' } : {}),
|
|
72
|
+
...(d.percent ? { percent: true } : {}),
|
|
73
|
+
...(d.attackTeammates ? { attack_teammates: true } : {}),
|
|
74
|
+
...(d.commander ? { commander: true } : {}),
|
|
75
|
+
});
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (d.kind === 'discard') {
|
|
79
|
+
if (d.cardId === undefined)
|
|
80
|
+
unread.push(`${cls} (no card id)`);
|
|
81
|
+
else
|
|
82
|
+
orders.push({ kind: 'discard', card: d.cardId });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const card = { kind: 'card', card: d.cardId ?? d.name, cardType: d.name };
|
|
86
|
+
const ints = d.own.filter(isInt);
|
|
87
|
+
let fieldsOf;
|
|
88
|
+
let missingPlayer;
|
|
89
|
+
const who = (n) => {
|
|
90
|
+
if (n === undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
const id = feedId(n);
|
|
93
|
+
if (id === undefined)
|
|
94
|
+
missingPlayer = n;
|
|
95
|
+
return id;
|
|
96
|
+
};
|
|
97
|
+
if (PLAIN_CARDS.has(d.cls))
|
|
98
|
+
fieldsOf = {};
|
|
99
|
+
else if (TERRITORY_CARDS.has(d.cls) && ints.length === 1)
|
|
100
|
+
fieldsOf = { target: ints[0] };
|
|
101
|
+
else if (d.cls === 'Surveillance' && ints.length === 1)
|
|
102
|
+
fieldsOf = { bonus: ints[0] };
|
|
103
|
+
else if (PLAYER_CARDS.has(d.cls) && ints.length === 1)
|
|
104
|
+
fieldsOf = { player: who(ints[0]) };
|
|
105
|
+
else if (d.cls === 'Gift' && ints.length === 2)
|
|
106
|
+
fieldsOf = { target: ints[1], player: who(ints[0]) };
|
|
107
|
+
else if (d.cls === 'Diplomacy' && ints.length === 2)
|
|
108
|
+
fieldsOf = { players: [who(ints[0]), who(ints[1])] };
|
|
109
|
+
else if (d.cls === 'Airlift') {
|
|
110
|
+
// An optional Armies, then from, a legacy count the client leaves 0, to.
|
|
111
|
+
const army = armiesOf(d.own[0]);
|
|
112
|
+
if (army && ints.length === 3) {
|
|
113
|
+
fieldsOf = { from: ints[0], to: ints[2], armies: army.count, ...(army.commander ? { commander: true } : {}) };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (missingPlayer !== undefined) {
|
|
117
|
+
unread.push(`${cls} (player ${missingPlayer} is not in the game)`);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (!fieldsOf) {
|
|
121
|
+
unread.push(cls);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const order = { ...card, ...fieldsOf };
|
|
125
|
+
orders.push(order);
|
|
126
|
+
if (d.cls === 'OrderDelay')
|
|
127
|
+
delays.push({ order, movesBefore: movesSeen });
|
|
128
|
+
}
|
|
129
|
+
// Order Delay is written above the move it delays (`before`, 1-based over the moves); after every move, none.
|
|
130
|
+
for (const { order, movesBefore } of delays)
|
|
131
|
+
if (movesBefore < movesSeen)
|
|
132
|
+
order.before = movesBefore + 1;
|
|
133
|
+
return { orders, unread };
|
|
134
|
+
}
|
package/dist/team-cards.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// card my teammate has already entered a play or a discard of is theirs this turn: the plan never plays it
|
|
3
3
|
// too, and the card advice says who plays each card.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
5
|
+
// VERIFIED live 2026-11-22 (V5, #435): war.app sends a teammate's entered orders before they commit. VERIFIED (V8, #310): how a
|
|
6
6
|
// team's hand and its limit are keyed (teamCardLimit). Tolerant: no teammate orders read means no claim.
|
|
7
7
|
import { cardsToShed } from './cards.js';
|
|
8
8
|
/** Every card play and discard in my teammates' entered orders (`teammates`: their player ids), in entry order. */
|
|
@@ -82,7 +82,7 @@ export function claimedCardWarning(uses) {
|
|
|
82
82
|
return undefined;
|
|
83
83
|
const each = uses.map((u) => `${u.mine === 'play' ? 'plays' : 'discards'} the ${u.card.name} card ${u.card.id}, which player ${u.player} has already entered a ${u.theirs} of`);
|
|
84
84
|
return (`These orders ${each.join('; ')}. A team shares one hand and must not use one card twice: leave it to them, or agree in ` +
|
|
85
|
-
'team chat who uses it before committing. Their entered orders are read from the live board (
|
|
85
|
+
'team chat who uses it before committing. Their entered orders are read from the live board (V5, verified live before commit).');
|
|
86
86
|
}
|
|
87
87
|
/** The hand with the cards my teammates have claimed moved last (order otherwise kept): a card named by type is then an unclaimed one when there is one. */
|
|
88
88
|
export function unclaimedFirst(hand, claimed) {
|
package/dist/team-orders.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// in-game player id → `warlight.shared.TeammateOrders` { a stamp (int), the orders entered (a list of
|
|
5
5
|
// GameOrder, during a turn), the picks entered (a list of territory ids, while distributing) }. The client
|
|
6
6
|
// shows a teammate's orders and picks from it, and counts the card plays and discards in it against the
|
|
7
|
-
// team's hand.
|
|
8
|
-
//
|
|
7
|
+
// team's hand. VERIFIED live 2026-11-22 (V5, #435): war.app fills it with a teammate's entered orders before the
|
|
8
|
+
// teammate commits, never with mine, and sends it empty when no teammate has entered anything (no value names
|
|
9
|
+
// it then: read as unknown). Still UNVERIFIED: the pick list while distributing, and what it holds after a commit.
|
|
9
10
|
//
|
|
10
11
|
// Field names are minified, so the dict is found by the registered type name of its values, and an order's
|
|
11
12
|
// kind by its class name. Within an order, fields are read by kind and read order, as the bundle's readers
|
|
@@ -44,7 +45,10 @@ function teammateDict(info) {
|
|
|
44
45
|
}
|
|
45
46
|
return undefined;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
/** The short class name of a decoded order (`GameOrderDeploy`), `unknown` when it has none. */
|
|
49
|
+
export const orderClass = (o) => (isObj(o) ? shortName(o.$type) : 'unknown');
|
|
50
|
+
/** An Armies record's count and whether my commander rides in it; `undefined` when it is not one. */
|
|
51
|
+
export function armiesOf(a) {
|
|
48
52
|
if (!isObj(a) || a.$type !== ARMIES)
|
|
49
53
|
return undefined;
|
|
50
54
|
const f = fields(a);
|
|
@@ -54,27 +58,30 @@ function armiesOf(a) {
|
|
|
54
58
|
const units = f.find((x) => Array.isArray(x)) ?? [];
|
|
55
59
|
return { count: numbers[0], commander: units.some((u) => isObj(u) && u.$type === COMMANDER) };
|
|
56
60
|
}
|
|
57
|
-
/**
|
|
58
|
-
function
|
|
59
|
-
|
|
61
|
+
/** Decodes one GameOrder record by class and read order; `undefined` when its shape is not understood. */
|
|
62
|
+
export function decodeOrder(o) {
|
|
63
|
+
if (!isObj(o) || typeof o.$type !== 'string' || !o.$type.startsWith(ORDER_PREFIX))
|
|
64
|
+
return undefined;
|
|
65
|
+
const type = o.$type;
|
|
60
66
|
const f = fields(o);
|
|
61
67
|
const ints = f.filter(isInt);
|
|
62
68
|
if (type === DEPLOY) {
|
|
63
69
|
if (ints.length < 2)
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
return true;
|
|
70
|
+
return undefined;
|
|
71
|
+
return { kind: 'deploy', territoryId: ints[0], armies: ints[1] };
|
|
67
72
|
}
|
|
68
73
|
if (type === ATTACK_TRANSFER) {
|
|
69
74
|
// attackTeammates, mode, byPercent, from, Armies, to, then the base (player …).
|
|
70
75
|
const [attackTeammates, mode, percent, from, armies, to] = f;
|
|
71
76
|
const army = armiesOf(armies);
|
|
72
|
-
if (typeof attackTeammates !== 'boolean' || typeof percent !== 'boolean' || !isInt(mode) || !isInt(from) || !isInt(to) || !army)
|
|
73
|
-
return
|
|
77
|
+
if (typeof attackTeammates !== 'boolean' || typeof percent !== 'boolean' || !isInt(mode) || !isInt(from) || !isInt(to) || !army) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
74
80
|
const m = MODES[mode];
|
|
75
81
|
if (!m)
|
|
76
|
-
return
|
|
77
|
-
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
kind: 'move',
|
|
78
85
|
from,
|
|
79
86
|
to,
|
|
80
87
|
armies: army.count,
|
|
@@ -82,21 +89,42 @@ function readOrder(o, out) {
|
|
|
82
89
|
...(percent ? { percent: true } : {}),
|
|
83
90
|
...(attackTeammates ? { attackTeammates: true } : {}),
|
|
84
91
|
...(army.commander ? { commander: true } : {}),
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
const cardId = f.map(normalizeGuid).find((g) => g !== undefined);
|
|
89
|
-
if (type === DISCARD) {
|
|
90
|
-
out.discards.push(cardId !== undefined ? { cardId } : {});
|
|
91
|
-
return true;
|
|
92
|
+
};
|
|
92
93
|
}
|
|
94
|
+
const at = f.findIndex((v) => normalizeGuid(v) !== undefined);
|
|
95
|
+
const cardId = at >= 0 ? normalizeGuid(f[at]) : undefined;
|
|
96
|
+
if (type === DISCARD)
|
|
97
|
+
return { kind: 'discard', ...(cardId !== undefined ? { cardId } : {}) };
|
|
93
98
|
if (type.startsWith(PLAY_CARD)) {
|
|
94
99
|
const cls = type.slice(PLAY_CARD.length);
|
|
95
100
|
const t = CARD_CLASS_TYPES[cls] ?? cardTypeByName(cls) ?? null;
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
return {
|
|
102
|
+
kind: 'card',
|
|
103
|
+
cls,
|
|
104
|
+
type: t,
|
|
105
|
+
name: t !== null ? cardTypeName(t) : cls || 'card',
|
|
106
|
+
...(cardId !== undefined ? { cardId } : {}),
|
|
107
|
+
own: at >= 0 ? f.slice(0, at) : [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
/** Reads one order into `out`; false when its shape is not understood. */
|
|
113
|
+
function readOrder(o, out) {
|
|
114
|
+
const d = decodeOrder(o);
|
|
115
|
+
if (!d)
|
|
116
|
+
return false;
|
|
117
|
+
if (d.kind === 'deploy')
|
|
118
|
+
out.deploys.push({ territoryId: d.territoryId, armies: d.armies });
|
|
119
|
+
else if (d.kind === 'move') {
|
|
120
|
+
const { kind: _kind, ...move } = d;
|
|
121
|
+
out.moves.push(move);
|
|
98
122
|
}
|
|
99
|
-
|
|
123
|
+
else if (d.kind === 'discard')
|
|
124
|
+
out.discards.push(d.cardId !== undefined ? { cardId: d.cardId } : {});
|
|
125
|
+
else
|
|
126
|
+
out.cards.push({ ...(d.cardId !== undefined ? { cardId: d.cardId } : {}), type: d.type, name: d.name });
|
|
127
|
+
return true;
|
|
100
128
|
}
|
|
101
129
|
function ordersOf(list) {
|
|
102
130
|
if (!Array.isArray(list))
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
// (Diplomacy, Sanctions), and (PLAN-TEAMS D2) where to play my Diplomacy, Sanctions, Airlift and
|
|
5
5
|
// Gift. Read-only; everything here is advice — of these only the advised Order Delay is added to the
|
|
6
6
|
// orders; my Bomb and Emergency Blockade and the D2 cards carry an `order` to pass to warapp_submit_turn.
|
|
7
|
-
import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
|
|
7
|
+
import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards, readTurnReinforcementPlays } from '../cards.js';
|
|
8
8
|
import { blockadeOffer, bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
|
|
9
9
|
import { bonusTerritories } from '../analysis/bonuses.js';
|
|
10
10
|
import { diplomacyOpponents, supportAdvice } from './card-support-advice.js';
|
|
11
11
|
export { giftInOrders, intelOrders } from './card-support-advice.js';
|
|
12
|
-
import { inGameId } from '../live.js';
|
|
12
|
+
import { inGameId, playersByInGameId } from '../live.js';
|
|
13
13
|
import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
|
|
14
14
|
import { isTeamGame, teammatesOf as teamOf } from '../teams.js';
|
|
15
15
|
const CARD_BOMB = 13;
|
|
@@ -298,6 +298,35 @@ export function cardPieceOption(settings, hand) {
|
|
|
298
298
|
const v = capturePieceValue(settings, inHand);
|
|
299
299
|
return v.armies !== null && v.armies > 0 ? { cardPieceValue: v.armies } : {};
|
|
300
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* #427: who played a Reinforcement card in the turn just before `turn` (the one being planned), by GameFeed
|
|
303
|
+
* id, from the LatestGameInfo's last GameTurn (`readTurnReinforcementPlays`); `undefined` when the info has
|
|
304
|
+
* none, the turn is unknown, or the GameTurn is another turn's. A player no seat matches is left out.
|
|
305
|
+
*/
|
|
306
|
+
export function lastTurnPlays(info, players, turn) {
|
|
307
|
+
const read = readTurnReinforcementPlays(info);
|
|
308
|
+
if (!read || turn === null || read.turn !== turn - 1)
|
|
309
|
+
return undefined;
|
|
310
|
+
const byInGame = playersByInGameId(players);
|
|
311
|
+
return { turn: read.turn, players: read.players.flatMap((id) => (byInGame.has(id) ? [byInGame.get(id).id] : [])) };
|
|
312
|
+
}
|
|
313
|
+
/** #427: whether the game shows every Reinforcement play: a Reinforcement card in play and `CardPlayingsFogged` false. */
|
|
314
|
+
export function reinforcementPlaysShown(settings) {
|
|
315
|
+
const clock = cardClock(settings);
|
|
316
|
+
return clock !== undefined && clock.playsHidden === false && clock.cards.some((c) => c.card === 'Reinforcement');
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* #427: the Reinforcement plays seen turn by turn (`seen`: turn → the GameFeed ids that played one; a turn
|
|
320
|
+
* present was read), for the threat model — only when the game says card plays are not fogged
|
|
321
|
+
* (`CardPlayingsFogged` false) and a Reinforcement card is in play: there every play shows. `undefined`
|
|
322
|
+
* otherwise, or with no turn read: the clock alone, as before.
|
|
323
|
+
*/
|
|
324
|
+
export function seenReinforcementPlays(settings, seen) {
|
|
325
|
+
if (!reinforcementPlaysShown(settings) || seen.size === 0)
|
|
326
|
+
return undefined;
|
|
327
|
+
const read = [...seen.keys()].sort((a, b) => a - b);
|
|
328
|
+
return { read, plays: read.flatMap((turn) => seen.get(turn).map((player) => ({ player, turn }))) };
|
|
329
|
+
}
|
|
301
330
|
/**
|
|
302
331
|
* #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand,
|
|
303
332
|
* the armies it adds (a fixed card's `FixedArmies`, else the Reinforcement card in my hand as it is
|