@chrischall/warapp-mcp 0.0.0 → 0.1.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 +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +199 -8
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +159 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +551 -0
- package/dist/analysis/opponents.js +1245 -0
- package/dist/analysis/outlook.js +633 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1218 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +927 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2922 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +577 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1109 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +117959 -36172
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +192 -0
- package/dist/client.js +361 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/live.js +278 -0
- package/dist/map-stats.js +152 -0
- package/dist/map-store.js +204 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +180 -0
- package/dist/normalize.js +411 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +138 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +229 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +677 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +531 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +215 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +269 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2168 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +146 -0
- package/dist/tools/chat.js +483 -0
- package/dist/tools/check-plan.js +688 -0
- package/dist/tools/commander-check.js +102 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/game.js +126 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +142 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-stats.js +117 -0
- package/dist/tools/map.js +133 -0
- package/dist/tools/my-games.js +123 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +151 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/picks.js +292 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +385 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +200 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender.js +240 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +182 -0
- package/dist/tools/turn.js +2761 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +275 -0
- package/dist/tools/write-kit.js +158 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +452 -0
- package/dist/version.js +4 -0
- package/manifest.json +174 -4
- package/mint.yaml +101 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +969 -21
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// The targeted card plays warapp_submit_turn sends (PLAN-TEAMS part D): Spy, Reconnaissance,
|
|
2
|
+
// Surveillance, Airlift, Gift, Diplomacy and Sanctions, and the combat cards Bomb and Emergency Blockade. Each card's fields come from the client
|
|
3
|
+
// bundle's `GameOrderPlayCard<X>` writer and its refusals mirror the bundle's `GameValidateOrders`
|
|
4
|
+
// (the error code each check stands in for is named), so a target war.app would refuse is refused
|
|
5
|
+
// here before anything is sent. The encodings are golden-pinned but UNVERIFIED live (V9,
|
|
6
|
+
// docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
|
|
7
|
+
// `untrustedText`.
|
|
8
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
9
|
+
import { inGameId } from '../live.js';
|
|
10
|
+
import { untrustedText } from './common.js';
|
|
11
|
+
import { resolveBonus, resolvePlayer, resolveTerritory } from './resolve.js';
|
|
12
|
+
/** The fields each card takes; every one is required except an Airlift's `commander`. */
|
|
13
|
+
const TAKES = {
|
|
14
|
+
Reinforcement: [],
|
|
15
|
+
OrderPriority: [],
|
|
16
|
+
OrderDelay: [],
|
|
17
|
+
Blockade: ['target'],
|
|
18
|
+
EmergencyBlockade: ['target'],
|
|
19
|
+
Bomb: ['target'],
|
|
20
|
+
Reconnaissance: ['target'],
|
|
21
|
+
Spy: ['player'],
|
|
22
|
+
Sanctions: ['player'],
|
|
23
|
+
Gift: ['target', 'player'],
|
|
24
|
+
Diplomacy: ['players'],
|
|
25
|
+
Surveillance: ['bonus'],
|
|
26
|
+
Airlift: ['from', 'to', 'armies', 'commander'],
|
|
27
|
+
};
|
|
28
|
+
const OPTIONAL = new Set(['commander']);
|
|
29
|
+
/** What each field means, for the refusal that names a missing or stray one. */
|
|
30
|
+
const FIELD_HELP = {
|
|
31
|
+
Reinforcement: 'it takes no target',
|
|
32
|
+
OrderPriority: 'it takes no target',
|
|
33
|
+
OrderDelay: 'it takes no target (only `before`)',
|
|
34
|
+
Blockade: '`target`: your territory to blockade',
|
|
35
|
+
EmergencyBlockade: '`target`: your territory to turn into a neutral wall before the attacks',
|
|
36
|
+
Bomb: "`target`: a territory next to one of yours, not yours or a teammate's (its armies are halved)",
|
|
37
|
+
Reconnaissance: '`target`: the territory to see',
|
|
38
|
+
Spy: "`player`: the player whose territories to see (0 or \"neutral\": the neutral, when the game's Spy card allows it)",
|
|
39
|
+
Sanctions: "`player`: the player whose income it cuts",
|
|
40
|
+
Gift: '`target`: your territory to give, and `player`: who receives it',
|
|
41
|
+
Diplomacy: '`players`: the two players who may not attack each other (usually you and one opponent)',
|
|
42
|
+
Surveillance: '`bonus`: the bonus to see',
|
|
43
|
+
Airlift: '`from` (yours), `to` (yours or a teammate\'s), `armies`, and optionally `commander`',
|
|
44
|
+
};
|
|
45
|
+
const article = (name) => (/^[aeiou]/i.test(name) ? 'An' : 'A');
|
|
46
|
+
const given = (v) => v !== undefined && !(typeof v === 'string' && v.trim() === '') && v !== false;
|
|
47
|
+
/**
|
|
48
|
+
* Refuse a card order whose fields do not fit its card: a required field missing, or a field the
|
|
49
|
+
* card does not take (`before` is checked by the caller).
|
|
50
|
+
*/
|
|
51
|
+
export function checkCardFields(kind, name, input) {
|
|
52
|
+
const takes = TAKES[kind];
|
|
53
|
+
const stray = Object.keys(input).filter((k) => given(input[k]) && !takes.includes(k));
|
|
54
|
+
if (stray.length) {
|
|
55
|
+
throw new McpToolError(`${article(name)} ${name} card takes no ${stray.join(' or ')}.`, {
|
|
56
|
+
hint: `${name}: ${FIELD_HELP[kind]}.`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const missing = takes.filter((k) => !OPTIONAL.has(k) && !given(input[k]));
|
|
60
|
+
if (missing.length) {
|
|
61
|
+
throw new McpToolError(`${article(name)} ${name} card needs ${missing.map((k) => `\`${k}\``).join(' and ')}.`, {
|
|
62
|
+
hint: `${name}: ${FIELD_HELP[kind]}.`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** A fresh `seen` for one turn's plays. */
|
|
67
|
+
export const newCardPlaySeen = () => ({
|
|
68
|
+
gifted: new Set(),
|
|
69
|
+
blockaded: new Set(),
|
|
70
|
+
airliftedFrom: new Map(),
|
|
71
|
+
commanderAirlifted: false,
|
|
72
|
+
});
|
|
73
|
+
const place = (t) => `${untrustedText(t.name)} (${t.id})`;
|
|
74
|
+
const who = (p) => `${untrustedText(p.name)} (${p.id})`;
|
|
75
|
+
function player(ctx, ref, card) {
|
|
76
|
+
const p = resolvePlayer(ctx.players, ref);
|
|
77
|
+
let id;
|
|
78
|
+
try {
|
|
79
|
+
id = inGameId(p);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new McpToolError(`${untrustedText(p.name)} (${p.id}) has no in-game id this tool can derive, so the ${card} card cannot name it.`, {
|
|
83
|
+
hint: 'Play this card in the game itself.',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return { id: p.id, inGameId: id, name: p.name };
|
|
87
|
+
}
|
|
88
|
+
const isMe = (ctx, p) => p.id === ctx.me.id;
|
|
89
|
+
const isTeammate = (ctx, p) => ctx.teammates.has(p.id);
|
|
90
|
+
/** Whether GameFeed says the player is still playing (unknown counts as playing: war.app has the last word). */
|
|
91
|
+
const playing = (ctx, p) => {
|
|
92
|
+
const state = ctx.players.find((x) => x.id === p.id)?.state;
|
|
93
|
+
return state === undefined || state === 'Playing';
|
|
94
|
+
};
|
|
95
|
+
function requirePlaying(ctx, p, card, code) {
|
|
96
|
+
if (playing(ctx, p))
|
|
97
|
+
return;
|
|
98
|
+
throw new McpToolError(`${who(p)} is no longer playing, so the ${card} card cannot name them (war.app refuses it: ${code}).`, {
|
|
99
|
+
hint: "warapp_get_game shows each player's state.",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const standingOf = (ctx, id) => ctx.board.find((t) => t.territoryId === id);
|
|
103
|
+
const mine = (ctx, id) => {
|
|
104
|
+
const t = standingOf(ctx, id);
|
|
105
|
+
return t !== undefined && !t.fogged && t.owner === ctx.myInGameId;
|
|
106
|
+
};
|
|
107
|
+
/** My teammates' in-game ids (a teammate without a derivable one owns nothing on the board by it). */
|
|
108
|
+
function teammateIds(ctx) {
|
|
109
|
+
const out = new Set();
|
|
110
|
+
for (const p of ctx.players) {
|
|
111
|
+
if (!ctx.teammates.has(p.id))
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
out.add(inGameId(p));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// An AI seat: no wrapped id.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** The Emergency Blockade's `MultiplyAmount`, when the settings carry one. */
|
|
123
|
+
function wallMultiplier(settings) {
|
|
124
|
+
const raw = settings?.raw.EmergencyBlockadeCard;
|
|
125
|
+
if (typeof raw !== 'object' || raw === null)
|
|
126
|
+
return undefined;
|
|
127
|
+
const m = Number(raw.MultiplyAmount);
|
|
128
|
+
return Number.isFinite(m) && m > 0 ? m : undefined;
|
|
129
|
+
}
|
|
130
|
+
/** A bonus's territories, its member bonuses' included (a superbonus). */
|
|
131
|
+
function bonusMembers(map, id, seen = new Set()) {
|
|
132
|
+
const b = map.bonuses.find((x) => x.id === id);
|
|
133
|
+
if (!b || seen.has(id))
|
|
134
|
+
return [];
|
|
135
|
+
seen.add(id);
|
|
136
|
+
return [...b.territoryIds, ...b.bonusIds.flatMap((m) => bonusMembers(map, m, seen))];
|
|
137
|
+
}
|
|
138
|
+
/** The bonuses worth something that I hold whole at the start of the turn and `territory` is in, by ascending id. */
|
|
139
|
+
function heldBonusesWith(ctx, territory) {
|
|
140
|
+
return ctx.map.bonuses
|
|
141
|
+
.filter((b) => b.value > 0)
|
|
142
|
+
.map((b) => ({ id: b.id, value: b.value, members: bonusMembers(ctx.map, b.id) }))
|
|
143
|
+
.filter((b) => b.members.includes(territory) && b.members.every((m) => mine(ctx, m)))
|
|
144
|
+
.map(({ id, value }) => ({ id, value }))
|
|
145
|
+
.sort((a, b) => a.id - b.id);
|
|
146
|
+
}
|
|
147
|
+
/** The neutral as a Spy card names it (target 0; the client bundle's `GameOrderPlayCardSpy`). */
|
|
148
|
+
const NEUTRAL_PLAYER = { id: 0, inGameId: 0, name: 'neutral' };
|
|
149
|
+
/** Whether a player reference means the neutral: 0, or the word "neutral". */
|
|
150
|
+
const isNeutralRef = (ref) => ref === 0 || (typeof ref === 'string' && /^\s*(0|neutral)\s*$/i.test(ref));
|
|
151
|
+
/** The game's Spy card may target the neutral (`SpyCard.CanSpyOnNeutral`; absent reads as no). */
|
|
152
|
+
function canSpyOnNeutral(settings) {
|
|
153
|
+
const raw = settings?.raw.SpyCard;
|
|
154
|
+
if (typeof raw !== 'object' || raw === null)
|
|
155
|
+
return false;
|
|
156
|
+
const v = raw.CanSpyOnNeutral;
|
|
157
|
+
return v === true || (typeof v === 'string' && v.toLowerCase() === 'true');
|
|
158
|
+
}
|
|
159
|
+
/** The Sanctions percentage (`SanctionsCard.Percentage`), when the settings carry one. */
|
|
160
|
+
function sanctionsPercentage(settings) {
|
|
161
|
+
const raw = settings?.raw.SanctionsCard;
|
|
162
|
+
if (typeof raw !== 'object' || raw === null)
|
|
163
|
+
return undefined;
|
|
164
|
+
const pct = raw.Percentage;
|
|
165
|
+
return typeof pct === 'number' ? pct : undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Resolve a targeted card play's fields against the map, the players and the live board, refusing
|
|
169
|
+
* what war.app's validator (the client bundle's `GameValidateOrders`) or the card's rules exclude.
|
|
170
|
+
* A card not in this game's card list is refused too. Blockade's own checks stay with the caller.
|
|
171
|
+
*/
|
|
172
|
+
export function resolveCardTargets(kind, cardName, input, ctx) {
|
|
173
|
+
const warnings = [];
|
|
174
|
+
if (kind !== 'Blockade' && TAKES[kind].length && ctx.rules.inPlay.length && !ctx.rules.inPlay.includes(cardName)) {
|
|
175
|
+
throw new McpToolError(`The ${cardName} card is not in play in this game.`, {
|
|
176
|
+
hint: `This game's cards: ${ctx.rules.inPlay.join(', ')}.`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
switch (kind) {
|
|
180
|
+
case 'Spy': {
|
|
181
|
+
// GameValidateOrders: target 0 is the neutral, allowed only when the game's CardGameSpy has
|
|
182
|
+
// CanSpyOnNeutral (else 225); 80 CannotSpyOnTeammateOrSelf, 79 CannotSpyOnThatPlayer (not playing).
|
|
183
|
+
if (isNeutralRef(input.player)) {
|
|
184
|
+
if (!canSpyOnNeutral(ctx.settings)) {
|
|
185
|
+
throw new McpToolError("This game's Spy card cannot spy on the neutral (war.app refuses it: error 225).", {
|
|
186
|
+
hint: 'Spy on an opponent instead: you see their territories for the rest of the turn.',
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
warnings.push('Spy on the neutral: you see the neutral territories for the rest of the turn.');
|
|
190
|
+
return { fields: { player: 0 }, player: NEUTRAL_PLAYER, warnings };
|
|
191
|
+
}
|
|
192
|
+
const p = player(ctx, input.player, cardName);
|
|
193
|
+
if (isMe(ctx, p) || isTeammate(ctx, p)) {
|
|
194
|
+
throw new McpToolError(`A Spy card cannot target ${isMe(ctx, p) ? 'yourself' : `your teammate ${who(p)}`} (war.app refuses it: error 80).`, {
|
|
195
|
+
hint: 'Spy on an opponent: you see their territories for the rest of the turn.',
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
requirePlaying(ctx, p, cardName, 'error 79');
|
|
199
|
+
return { fields: { player: p.inGameId }, player: p, warnings };
|
|
200
|
+
}
|
|
201
|
+
case 'Sanctions': {
|
|
202
|
+
// GameValidateOrders refuses only a player not playing (219); the target is our rule: a sanction
|
|
203
|
+
// cuts income, so never on me or a teammate — unless the game's percentage is negative (a boost).
|
|
204
|
+
const p = player(ctx, input.player, cardName);
|
|
205
|
+
requirePlaying(ctx, p, cardName, 'error 219');
|
|
206
|
+
const pct = sanctionsPercentage(ctx.settings);
|
|
207
|
+
const friendly = isMe(ctx, p) || isTeammate(ctx, p);
|
|
208
|
+
if (pct !== undefined && pct < 0) {
|
|
209
|
+
if (!friendly) {
|
|
210
|
+
throw new McpToolError(`This game's Sanctions percentage is negative (${Math.round(pct * 100)}%): a sanction raises the target's income, so it does not go on an opponent (${who(p)}).`, { hint: 'Play it on yourself or a teammate, or keep it.' });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (friendly) {
|
|
214
|
+
throw new McpToolError(`Sanctions cut the target's income, so they do not go on ${isMe(ctx, p) ? 'yourself' : `your teammate ${who(p)}`}.`, {
|
|
215
|
+
hint: 'Sanction an opponent — usually the leader.',
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return { fields: { player: p.inGameId }, player: p, warnings };
|
|
219
|
+
}
|
|
220
|
+
case 'Diplomacy': {
|
|
221
|
+
// GameValidateOrders: 20 InvalidPlayer, 214 CannotDoDiplomacyBetweenTeammates (the same player twice
|
|
222
|
+
// is one team), 381 DiplomacyPlayerInvalid (not playing) — checked for both named players, the first
|
|
223
|
+
// and then the second, so either one out is refused.
|
|
224
|
+
const refs = input.players;
|
|
225
|
+
if (refs.length !== 2) {
|
|
226
|
+
throw new McpToolError(`A Diplomacy card names exactly two players, not ${refs.length}.`, { hint: `Diplomacy: ${FIELD_HELP.Diplomacy}.` });
|
|
227
|
+
}
|
|
228
|
+
const a = player(ctx, refs[0], cardName);
|
|
229
|
+
const b = player(ctx, refs[1], cardName);
|
|
230
|
+
if (a.id === b.id) {
|
|
231
|
+
throw new McpToolError(`A Diplomacy card names one player twice (${who(a)}) (war.app refuses it: error 214).`, {
|
|
232
|
+
hint: 'Name two different players, e.g. you and the opponent you want peace with.',
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const team = (p) => isMe(ctx, p) || isTeammate(ctx, p);
|
|
236
|
+
if (team(a) && team(b)) {
|
|
237
|
+
throw new McpToolError(`${who(a)} and ${who(b)} are on one team, so a Diplomacy card between them does nothing (war.app refuses it: error 214).`, {
|
|
238
|
+
hint: 'Name an opponent as one of the two.',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
requirePlaying(ctx, a, cardName, 'error 381');
|
|
242
|
+
requirePlaying(ctx, b, cardName, 'error 381');
|
|
243
|
+
if (!isMe(ctx, a) && !isMe(ctx, b)) {
|
|
244
|
+
warnings.push(`Diplomacy between players ${a.id} and ${b.id} does not name you: it stops them attacking each other, not you.`);
|
|
245
|
+
}
|
|
246
|
+
return { fields: { players: [a.inGameId, b.inGameId] }, players: [a, b], warnings };
|
|
247
|
+
}
|
|
248
|
+
case 'Reconnaissance': {
|
|
249
|
+
// GameValidateOrders: 41 InvalidTerritory (resolving it against the map covers that).
|
|
250
|
+
const t = resolveTerritory(ctx.map, input.target);
|
|
251
|
+
return { fields: { target: t.id }, territory: { id: t.id, name: t.name }, warnings };
|
|
252
|
+
}
|
|
253
|
+
case 'Surveillance': {
|
|
254
|
+
// GameValidateOrders: 223 InvalidBonus, 224 CannotSurveillanceBonusValuedAtZero.
|
|
255
|
+
const b = resolveBonus(ctx.map, input.bonus);
|
|
256
|
+
if (b.value === 0) {
|
|
257
|
+
throw new McpToolError(`${place(b)} is worth 0 in this game, so it cannot be surveilled (war.app refuses it: error 224).`, {
|
|
258
|
+
hint: 'Pick a bonus worth something.',
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return { fields: { bonus: b.id }, bonus: { id: b.id, name: b.name }, warnings };
|
|
262
|
+
}
|
|
263
|
+
case 'Gift': {
|
|
264
|
+
// GameValidateOrders: 212 CannotGiftTerritoryYouDoNotOwn, 211 CannotGiftToYourself,
|
|
265
|
+
// 213 CannotGiftSameTerritoryMoreThanOnce, 210 CannotGiftToNonPlayingPlayer, 536 CannotGiftSpecialUnit.
|
|
266
|
+
const t = resolveTerritory(ctx.map, input.target);
|
|
267
|
+
const terr = { id: t.id, name: t.name };
|
|
268
|
+
if (!mine(ctx, t.id)) {
|
|
269
|
+
throw new McpToolError(`${place(terr)} is not yours at the start of this turn, so it cannot be gifted (war.app refuses it: error 212).`, {
|
|
270
|
+
hint: 'A Gift gives away a territory you hold on the live board (warapp_get_live_board).',
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
const p = player(ctx, input.player, cardName);
|
|
274
|
+
if (isMe(ctx, p)) {
|
|
275
|
+
throw new McpToolError('A Gift cannot go to yourself (war.app refuses it: error 211).', { hint: 'Name the player who receives the territory.' });
|
|
276
|
+
}
|
|
277
|
+
requirePlaying(ctx, p, cardName, 'error 210');
|
|
278
|
+
if (ctx.seen.gifted.has(t.id)) {
|
|
279
|
+
throw new McpToolError(`${place(terr)} is gifted twice (war.app refuses it: error 213).`, { hint: 'Gift each territory once.' });
|
|
280
|
+
}
|
|
281
|
+
const units = standingOf(ctx, t.id)?.specialUnits ?? [];
|
|
282
|
+
if (units.length) {
|
|
283
|
+
const commander = units.some((u) => u.kind === 'commander');
|
|
284
|
+
throw new McpToolError(`${place(terr)} holds ${commander ? 'a commander' : 'a special unit'}, which cannot be gifted (war.app refuses it: error 536).`, { hint: 'Move the unit off first, or gift another territory.' });
|
|
285
|
+
}
|
|
286
|
+
ctx.seen.gifted.add(t.id);
|
|
287
|
+
if (!isTeammate(ctx, p)) {
|
|
288
|
+
warnings.push(`Gift to an opponent: territory ${t.id} goes to player ${p.id}, an opponent (not you or a teammate) — it strengthens them, and its armies fight for them from this turn.`);
|
|
289
|
+
}
|
|
290
|
+
warnings.push(`Gift: territory ${t.id} and every army on it (this turn's deploys there included) go to player ${p.id} before the attacks run` +
|
|
291
|
+
(ctx.movesFrom.has(t.id) ? '; the moves from it in these orders will not run, since it is no longer yours by then.' : '.'));
|
|
292
|
+
return { fields: { player: p.inGameId, target: t.id }, territory: terr, player: p, warnings };
|
|
293
|
+
}
|
|
294
|
+
case 'Bomb':
|
|
295
|
+
return bomb(input, ctx, warnings);
|
|
296
|
+
case 'EmergencyBlockade':
|
|
297
|
+
return emergencyBlockade(input, ctx, warnings);
|
|
298
|
+
case 'Airlift':
|
|
299
|
+
return airlift(input, ctx, warnings);
|
|
300
|
+
default:
|
|
301
|
+
return { fields: {}, warnings };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* A Bomb (`GameOrderPlayCardBomb`), as GameValidateOrders checks it: 526 CannotBombTeammates (the
|
|
306
|
+
* target's owner at the start of the turn is me or a teammate), 527 CannotBombNonAdjacent (none of the
|
|
307
|
+
* target's neighbours, by the map's own list for it, is mine). A neutral or fogged target is allowed.
|
|
308
|
+
* It runs in phase 30, after the deploys and before every move.
|
|
309
|
+
*/
|
|
310
|
+
function bomb(input, ctx, warnings) {
|
|
311
|
+
const t = resolveTerritory(ctx.map, input.target);
|
|
312
|
+
const terr = { id: t.id, name: t.name };
|
|
313
|
+
const standing = standingOf(ctx, t.id);
|
|
314
|
+
const visible = standing !== undefined && !standing.fogged;
|
|
315
|
+
if (mine(ctx, t.id)) {
|
|
316
|
+
throw new McpToolError(`${place(terr)} is yours: you cannot bomb your own territory (war.app refuses it: error 526).`, {
|
|
317
|
+
hint: 'Bomb an opponent\'s or a neutral territory next to one of yours.',
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (visible && teammateIds(ctx).has(standing.owner)) {
|
|
321
|
+
throw new McpToolError(`${place(terr)} is your teammate's: you cannot bomb your teammate's territory (war.app refuses it: error 526).`, {
|
|
322
|
+
hint: 'Bomb an opponent\'s or a neutral territory next to one of yours.',
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (!t.connectedTo.some((n) => mine(ctx, n))) {
|
|
326
|
+
throw new McpToolError(`${place(terr)} is next to none of yours at the start of this turn, so it cannot be bombed (war.app refuses it: error 527).`, {
|
|
327
|
+
hint: 'A Bomb hits a territory that borders one you hold on the live board (warapp_get_live_board).',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
warnings.push(`Bomb: territory ${t.id}'s armies (its owner's deploys there included) are halved after the deploys and before every move; a commander there is unharmed.` +
|
|
331
|
+
(visible ? '' : ` Territory ${t.id} is fogged: its owner and armies are not known here.`));
|
|
332
|
+
return { fields: { target: t.id }, territory: terr, warnings };
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* An Emergency Blockade (`GameOrderPlayCardAbandon`), as GameValidateOrders checks it: 95
|
|
336
|
+
* AbandonCardMustTargetYourTerritory, 96 AbandonCannotBeUsedOnSameSpotMoreThanOnce. Ours (#163): never
|
|
337
|
+
* on my commander's territory (it would be lost with it). It runs in phase 37, after the deploys and
|
|
338
|
+
* before Airlift and the attacks: the territory turns neutral with its armies multiplied, so a move from
|
|
339
|
+
* it does not run and a held bonus it is in is broken (both warnings).
|
|
340
|
+
*/
|
|
341
|
+
function emergencyBlockade(input, ctx, warnings) {
|
|
342
|
+
const t = resolveTerritory(ctx.map, input.target);
|
|
343
|
+
const terr = { id: t.id, name: t.name };
|
|
344
|
+
if (!mine(ctx, t.id)) {
|
|
345
|
+
throw new McpToolError(`${place(terr)} is not yours at the start of this turn, so it cannot be blockaded (war.app refuses it: error 95).`, {
|
|
346
|
+
hint: 'An Emergency Blockade targets a territory you hold on the live board (warapp_get_live_board).',
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (ctx.seen.blockaded.has(t.id)) {
|
|
350
|
+
throw new McpToolError(`${place(terr)} is blockaded twice (war.app refuses it: error 96).`, { hint: 'Play one Emergency Blockade per territory.' });
|
|
351
|
+
}
|
|
352
|
+
if (standingOf(ctx, t.id)?.specialUnits?.some((u) => u.kind === 'commander' && u.owner === ctx.myInGameId)) {
|
|
353
|
+
throw new McpToolError(`${place(terr)} holds your commander, so it cannot be blockaded.`, {
|
|
354
|
+
hint: 'An Emergency Blockade makes the territory neutral and your commander on it would be lost. Move the commander out first, or blockade another territory.',
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
ctx.seen.blockaded.add(t.id);
|
|
358
|
+
const m = wallMultiplier(ctx.settings);
|
|
359
|
+
warnings.push(`Emergency Blockade: territory ${t.id} turns neutral with its armies (this turn's deploys there included) ${m !== undefined ? `× ${m}` : 'multiplied'} ` +
|
|
360
|
+
'before the attacks, and is no longer yours' +
|
|
361
|
+
(ctx.movesFrom.has(t.id) ? '; the moves from it in these orders will not run.' : '.'));
|
|
362
|
+
for (const b of heldBonusesWith(ctx, t.id)) {
|
|
363
|
+
warnings.push(`Emergency Blockade: territory ${t.id} is in bonus ${b.id}, which you hold: the blockade breaks it (+${b.value} a turn).`);
|
|
364
|
+
}
|
|
365
|
+
return { fields: { target: t.id }, territory: terr, warnings };
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* An Airlift, as GameValidateOrders checks it: 184 CannotAirliftFromSameSpotAsOrigin, 182
|
|
369
|
+
* CannotAirliftFromWhereYouDoNotControl, 183 CannotAirliftToWhereYouDoNotControl (mine or a
|
|
370
|
+
* teammate's), 537 CannotAirliftSpecialUnit (a commander or boss goes only to my own territory).
|
|
371
|
+
* It runs after the deploys (phase 43), so it may send the armies there plus this turn's deploys.
|
|
372
|
+
*/
|
|
373
|
+
function airlift(input, ctx, warnings) {
|
|
374
|
+
const f = resolveTerritory(ctx.map, input.from);
|
|
375
|
+
const t = resolveTerritory(ctx.map, input.to);
|
|
376
|
+
const from = { id: f.id, name: f.name };
|
|
377
|
+
const to = { id: t.id, name: t.name };
|
|
378
|
+
const armies = input.armies;
|
|
379
|
+
if (f.id === t.id) {
|
|
380
|
+
throw new McpToolError(`An Airlift goes from ${place(from)} to itself (war.app refuses it: error 184).`, { hint: 'Airlift between two different territories.' });
|
|
381
|
+
}
|
|
382
|
+
if (!mine(ctx, f.id)) {
|
|
383
|
+
throw new McpToolError(`${place(from)} is not yours at the start of this turn, so nothing can be airlifted from it (war.app refuses it: error 182).`, {
|
|
384
|
+
hint: 'Airlift from a territory you hold on the live board (warapp_get_live_board).',
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
const dest = standingOf(ctx, t.id);
|
|
388
|
+
const toTeammate = dest !== undefined && !dest.fogged && teammateIds(ctx).has(dest.owner);
|
|
389
|
+
if (!mine(ctx, t.id) && !toTeammate) {
|
|
390
|
+
throw new McpToolError(`${place(to)} is neither yours nor a teammate's, so nothing can be airlifted to it (war.app refuses it: error 183).`, {
|
|
391
|
+
hint: "An Airlift lands on your own territory or a teammate's; attack to take a territory.",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
// The validator does not check the count: an Airlift of the commander alone sends 0 armies.
|
|
395
|
+
if (!Number.isInteger(armies) || armies < 0 || (armies === 0 && !input.commander)) {
|
|
396
|
+
throw new McpToolError(`An Airlift sends at least one army, not ${armies} (0 armies only with \`commander\`: the commander alone).`, {
|
|
397
|
+
hint: 'Give `armies` as a whole number of 1 or more, or 0 with `commander: true`.',
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const there = (standingOf(ctx, f.id)?.armies ?? 0) + (ctx.deployedOn.get(f.id) ?? 0);
|
|
401
|
+
const total = (ctx.seen.airliftedFrom.get(f.id) ?? 0) + armies;
|
|
402
|
+
if (total > there) {
|
|
403
|
+
throw new McpToolError(`These orders airlift ${total} armies from ${place(from)}, but at most ${there} stand there when the Airlift runs (its armies now plus this turn's deploys).`, { hint: 'Airlift no more armies than stand on the territory.' });
|
|
404
|
+
}
|
|
405
|
+
ctx.seen.airliftedFrom.set(f.id, total);
|
|
406
|
+
const out = { fields: { from: f.id, to: t.id, armies }, from, to, armies, warnings };
|
|
407
|
+
if (input.commander) {
|
|
408
|
+
if (ctx.settings?.commanders !== true) {
|
|
409
|
+
throw new McpToolError('This game has no commanders, so the Airlift cannot take one.', { hint: 'Leave `commander` out.' });
|
|
410
|
+
}
|
|
411
|
+
if (toTeammate) {
|
|
412
|
+
throw new McpToolError(`A commander cannot be airlifted to a teammate's territory (${place(to)}) (war.app refuses it: error 537).`, {
|
|
413
|
+
hint: 'Airlift the commander to a territory of your own, or leave `commander` out.',
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const unit = standingOf(ctx, f.id)?.specialUnits?.find((u) => u.kind === 'commander' && u.owner === ctx.myInGameId);
|
|
417
|
+
if (!unit) {
|
|
418
|
+
throw new McpToolError(`Your commander is not on ${place(from)} at the start of this turn.`, {
|
|
419
|
+
hint: 'Airlift it from where it stands (warapp_get_live_board shows it), or leave `commander` out.',
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
if (ctx.seen.commanderAirlifted) {
|
|
423
|
+
throw new McpToolError('Your commander is airlifted twice.', { hint: 'Take it on one Airlift only.' });
|
|
424
|
+
}
|
|
425
|
+
ctx.seen.commanderAirlifted = true;
|
|
426
|
+
const commander = { id: unit.id, owner: ctx.myInGameId };
|
|
427
|
+
out.fields.commander = commander;
|
|
428
|
+
out.commander = true;
|
|
429
|
+
}
|
|
430
|
+
if (toTeammate) {
|
|
431
|
+
warnings.push(`Airlift: the ${armies} armies landing on territory ${t.id} become your teammate's.`);
|
|
432
|
+
}
|
|
433
|
+
return out;
|
|
434
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// PLAN-TEAMS D2: where to play my Diplomacy, Sanctions, Airlift and Gift cards this turn, read against the
|
|
2
|
+
// plan (src/analysis/card-support.ts). Advice only, never auto-played: each carries the `order` to pass to
|
|
3
|
+
// warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9). Players and territories by id only.
|
|
4
|
+
import { airliftAdvice, diplomacyAdvice, giftAdvice, intelAdvice, sanctionsAdvice } from '../analysis/card-support.js';
|
|
5
|
+
import { visibleIncomeFor } from '../analysis/plan/shared.js';
|
|
6
|
+
import { STRENGTH_INCOME_TURNS } from '../analysis/profile.js';
|
|
7
|
+
const CARD_SPY = 2;
|
|
8
|
+
const CARD_RECONNAISSANCE = 10;
|
|
9
|
+
const CARD_SURVEILLANCE = 11;
|
|
10
|
+
const INTEL = [
|
|
11
|
+
[CARD_SPY, 'Spy'],
|
|
12
|
+
[CARD_RECONNAISSANCE, 'Reconnaissance'],
|
|
13
|
+
[CARD_SURVEILLANCE, 'Surveillance'],
|
|
14
|
+
];
|
|
15
|
+
const CARD_AIRLIFT = 6;
|
|
16
|
+
const CARD_GIFT = 7;
|
|
17
|
+
const CARD_DIPLOMACY = 8;
|
|
18
|
+
const CARD_SANCTIONS = 9;
|
|
19
|
+
const PLAY_IT = 'Advice only, not in the orders: pass its `order` to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).';
|
|
20
|
+
/** The Sanctions percentage (`SanctionsCard.Percentage`), when the settings carry one. */
|
|
21
|
+
function percentage(game) {
|
|
22
|
+
const raw = game.settings?.raw.SanctionsCard;
|
|
23
|
+
const pct = typeof raw === 'object' && raw !== null ? raw.Percentage : undefined;
|
|
24
|
+
return typeof pct === 'number' ? pct : undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Each player in sight by strength (visible armies + {@link STRENGTH_INCOME_TURNS} × income): the
|
|
28
|
+
* profile's free-for-all ranking when the plan has one, else read off the board (visible bonuses only:
|
|
29
|
+
* an opponent's figure is a lower bound under fog; every income before any army cap, as the profile's
|
|
30
|
+
* ranking reads mine, #253). Teammates and players no longer playing are left out.
|
|
31
|
+
*/
|
|
32
|
+
function strengths(input) {
|
|
33
|
+
const ranking = input.plan.profile?.ranking;
|
|
34
|
+
if (ranking)
|
|
35
|
+
return ranking.players.map((p) => ({ playerId: p.playerId, strength: p.strength }));
|
|
36
|
+
const out = new Map();
|
|
37
|
+
const playing = (id) => (input.game.players.find((p) => p.id === id)?.state ?? 'Playing') === 'Playing';
|
|
38
|
+
for (const t of input.cb.board.territories) {
|
|
39
|
+
if (t.owner.kind !== 'player')
|
|
40
|
+
continue;
|
|
41
|
+
const p = t.owner.playerId;
|
|
42
|
+
if ((p !== input.me.id && input.cb.friends?.has(p)) || !playing(p))
|
|
43
|
+
continue;
|
|
44
|
+
out.set(p, (out.get(p) ?? 0) + (t.armies ?? 0));
|
|
45
|
+
}
|
|
46
|
+
return [...out].map(([playerId, armies]) => ({
|
|
47
|
+
playerId,
|
|
48
|
+
strength: armies + STRENGTH_INCOME_TURNS * visibleIncomeFor(input.cb.graph, input.cb.board, playerId, input.game.settings),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
/** The D2 advice for the cards in `cards`: a view and one warning per card advised. */
|
|
52
|
+
export function supportAdvice(input) {
|
|
53
|
+
const { me, cards, cb } = input;
|
|
54
|
+
const view = {};
|
|
55
|
+
const warnings = [];
|
|
56
|
+
const first = (type) => cards.find((c) => c.type === type);
|
|
57
|
+
const dip = first(CARD_DIPLOMACY);
|
|
58
|
+
if (dip) {
|
|
59
|
+
const d = diplomacyAdvice(cb, { atPeace: input.atPeace, truces: input.truces });
|
|
60
|
+
if (d) {
|
|
61
|
+
if (d.player !== undefined && d.pressure) {
|
|
62
|
+
view.diplomacy = {
|
|
63
|
+
player: d.player,
|
|
64
|
+
borders: d.pressure.borders,
|
|
65
|
+
armies: d.pressure.armies,
|
|
66
|
+
...(d.overTruce ? { overTruce: d.overTruce } : {}),
|
|
67
|
+
...(d.skipped.length ? { skipped: d.skipped } : {}),
|
|
68
|
+
order: { kind: 'card', card: dip.id, players: [me.id, d.player] },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
warnings.push(`${d.why}${d.skipped.length ? ` Passed over: ${d.skipped.join('; ')}.` : ''}` +
|
|
72
|
+
(d.player !== undefined ? ` It starts the turn after it is played: this turn's attacks still run. ${PLAY_IT}` : ''));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const san = first(CARD_SANCTIONS);
|
|
76
|
+
if (san) {
|
|
77
|
+
// G2: a truce partner and a player a Diplomacy card keeps at peace with me are passed over, the reason stated.
|
|
78
|
+
const pass = new Map();
|
|
79
|
+
for (const t of input.truces)
|
|
80
|
+
pass.set(t.player, `your truce with it is ${t.state === 'notice' ? 'in notice' : 'in force'} — a sanction on a partner invites a break`);
|
|
81
|
+
for (const p of input.atPeace)
|
|
82
|
+
pass.set(p, 'a Diplomacy card between you is in force — it cannot attack you, so sanction a player who can');
|
|
83
|
+
const pct = percentage(input.game);
|
|
84
|
+
const s = sanctionsAdvice({ me: me.id, players: strengths(input), ...(pct !== undefined ? { percentage: pct } : {}), ...(pass.size ? { pass } : {}) });
|
|
85
|
+
if (s?.player !== undefined) {
|
|
86
|
+
view.sanctions = { player: s.player, ...(s.skipped?.length ? { skipped: s.skipped } : {}), order: { kind: 'card', card: san.id, player: s.player } };
|
|
87
|
+
warnings.push(`${s.why} ${PLAY_IT}`);
|
|
88
|
+
}
|
|
89
|
+
else if (s)
|
|
90
|
+
warnings.push(s.why);
|
|
91
|
+
}
|
|
92
|
+
const air = first(CARD_AIRLIFT);
|
|
93
|
+
if (air) {
|
|
94
|
+
const a = airliftAdvice(cb);
|
|
95
|
+
if (a) {
|
|
96
|
+
view.airlift = {
|
|
97
|
+
from: a.from,
|
|
98
|
+
to: a.to,
|
|
99
|
+
armies: a.armies,
|
|
100
|
+
...(a.teammate !== undefined ? { teammate: a.teammate } : {}),
|
|
101
|
+
order: { kind: 'card', card: air.id, from: a.from, to: a.to, armies: a.armies },
|
|
102
|
+
};
|
|
103
|
+
warnings.push(`${a.why} ${PLAY_IT}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// G2: Spy, Reconnaissance and Surveillance, only where the fog hides what the plan needs.
|
|
107
|
+
const intelCards = new Map(INTEL.flatMap(([type, name]) => (first(type) ? [[name, first(type)]] : [])));
|
|
108
|
+
if (intelCards.size) {
|
|
109
|
+
const opponents = input.game.players
|
|
110
|
+
.filter((p) => p.id !== me.id && !cb.friends?.has(p.id) && (p.state ?? 'Playing') === 'Playing')
|
|
111
|
+
.map((p) => p.id);
|
|
112
|
+
const fog = input.game.settings?.fog;
|
|
113
|
+
const intel = intelAdvice(cb, { ...(fog !== undefined ? { fog } : {}), opponents, held: new Set(intelCards.keys()) });
|
|
114
|
+
for (const a of intel.advice) {
|
|
115
|
+
const id = intelCards.get(a.card).id;
|
|
116
|
+
if (a.card === 'Spy' && a.player !== undefined)
|
|
117
|
+
view.spy = { player: a.player, order: { kind: 'card', card: id, player: a.player } };
|
|
118
|
+
if (a.card === 'Reconnaissance' && a.target !== undefined)
|
|
119
|
+
view.reconnaissance = { target: a.target, order: { kind: 'card', card: id, target: a.target } };
|
|
120
|
+
if (a.card === 'Surveillance' && a.bonus !== undefined)
|
|
121
|
+
view.surveillance = { bonus: a.bonus, order: { kind: 'card', card: id, bonus: a.bonus } };
|
|
122
|
+
warnings.push(`${a.why} ${PLAY_IT}`);
|
|
123
|
+
}
|
|
124
|
+
warnings.push(...intel.hold);
|
|
125
|
+
}
|
|
126
|
+
const gifts = cards.filter((c) => c.type === CARD_GIFT);
|
|
127
|
+
if (gifts.length) {
|
|
128
|
+
const g = giftAdvice(cb, input.plan.team?.sharedBonuses ?? [], gifts.length);
|
|
129
|
+
if (g) {
|
|
130
|
+
view.gift = {
|
|
131
|
+
player: g.player,
|
|
132
|
+
bonus: g.bonus,
|
|
133
|
+
territories: g.territories,
|
|
134
|
+
orders: g.territories.map((t, i) => ({ kind: 'card', card: gifts[i].id, target: t, player: g.player })),
|
|
135
|
+
};
|
|
136
|
+
warnings.push(`${g.why} ${PLAY_IT}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { view, warnings };
|
|
140
|
+
}
|