feedback7: merge fb7-loadout — per-operator 潜能 (1–6) and 练度 (未精英化 / 精英1 / 精英2 / 精英2 Lv.60) set in 干员调配, defaults 潜能 6 and 精英2 Lv.60 (the owner's decision of 2026-10-08); PR #301 ported as one aligned list; #398 the skill frame, #400 REA-Y's heal text
- Conflicts (the branch started at ae22335c): the four i18n packs (union of keys), game.js DetailPanel props (ops + the
voices' voice=true), detailPanel.js resolveDetail (cultOpts + the voices' tap), match/views.js (both helpers),
docs/PLAYING.md and design/network.md merged line by line against the base. test/match/bosshp.test.js's ATK formula
now includes the unit's 练度 multiplier (cultMul).
- Grok review: MERGE AFTER FIXES — the note and the module card at the set potential fixed on the branch.
- Golden: every owned operator ×1.1 ATK / DEF / max HP by default — roster 49, bonds 46, fields 22, matches 18, diy 134
(stand-in battles and prototype picks unchanged). Broad node --test 5666 (0 fail after the bosshp formula; 2 skipped);
lint 0 errors; typecheck; i18n strict clean (1152 msgids).
This commit is contained in:
commit
0ced21d321
82 files changed
+9156
-6840
No files matched your search
+35
-7
@@ -65,6 +65,9 @@
|
||||
// (or outside a room) it simply replaces the stored one; while the room's match runs it is also handed to
|
||||
// match.setLoadout(playerId, loadout), which accepts it only during INFO_CHECK (the 干员调配 entry of the briefing)
|
||||
// and refuses it afterwards (WRONG_PHASE: the match's loadout is locked, the stored one applies to the next match).
|
||||
// ▸ Its `ops` (0.2.2: the per-operator 潜能 / 练度, shared/protocol.js checkLoadoutOps — an operator of the 干员调配
|
||||
// roster or the 自选 owned pool, strict like the entries) travel with it: session.ops / seat.ops / seats[].ops and
|
||||
// match.setLoadout(playerId, loadout, ops); a message without `ops` sets none (every operator 潜能 6, 精英2 Lv.60).
|
||||
// * Operator ownership (干员持有, 0.2.0 补位, owner's decision 2026-10-05): room.ownership { notOwned } — the base chess
|
||||
// ids the player marked as not owned — is checked leniently (shared/protocol.js checkNotOwned: anything that is not
|
||||
// a droppable NORMAL chess is dropped, never the whole list; only a malformed list is BAD_MSG) and stored on the
|
||||
@@ -97,7 +100,7 @@
|
||||
|
||||
import { randomBytes, randomInt } from 'node:crypto';
|
||||
import { ERR, MAX_SEATS, MAX_SPECTATORS, ROOM_CODE_LEN, modeIdFor } from '../shared/constants.js';
|
||||
import { checkLoadout, checkNotOwned, checkDiyPicks } from '../shared/protocol.js';
|
||||
import { checkLoadout, checkLoadoutOps, cultivationCharIds, checkNotOwned, checkDiyPicks } from '../shared/protocol.js';
|
||||
import { encode, isDroppable, isErrCode, sendRaw, sendSession } from './net.js';
|
||||
import { getData as defaultGetData, lookup } from './data.js';
|
||||
import { Match as DefaultMatch } from './match/Match.js';
|
||||
@@ -129,6 +132,7 @@ const noopLog = { info() {}, warn() {}, error() {}, debug() {} };
|
||||
/**
|
||||
* @typedef {{ seat: number, playerId: string, name: string, isBot: boolean, ready: boolean,
|
||||
* connected: boolean, left: boolean, loadout?: Record<string, { skill: number, module: string|null }> | null,
|
||||
* ops?: Readonly<Record<string, { potential: number, cultivate: number }>> | null,
|
||||
* notOwned?: readonly string[] | null, diy?: Readonly<Record<string, DiyLoadout>> | null }} Seat
|
||||
* @typedef {{ charId: string, skillIndex: number, uniEquipId: string|null }} DiyLoadout
|
||||
*/
|
||||
@@ -140,6 +144,22 @@ function freezeLoadout(loadout) {
|
||||
return Object.freeze(out);
|
||||
}
|
||||
|
||||
/** Deep-frozen copy of checked operator settings (0.2.2 潜能 / 练度; shared by the session, the seat and the match). */
|
||||
function freezeOps(ops) {
|
||||
const out = {};
|
||||
for (const [id, e] of Object.entries(ops || {})) out[id] = Object.freeze({ potential: e.potential, cultivate: e.cultivate });
|
||||
return Object.freeze(out);
|
||||
}
|
||||
|
||||
/** The charIds a player may set a potential / 练度 for, per data object (shared/protocol.js cultivationCharIds). */
|
||||
const OPS_IDS = new WeakMap();
|
||||
function opsCharIds(data) {
|
||||
if (!data || typeof data !== 'object') return new Set();
|
||||
let ids = OPS_IDS.get(data);
|
||||
if (!ids) { ids = cultivationCharIds(data.chess, data.backups); OPS_IDS.set(data, ids); }
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** Deep-frozen copy of checked 自选 picks (shared by the session, the seat and the match's PlayerState). */
|
||||
function freezeDiy(picks) {
|
||||
const out = {};
|
||||
@@ -600,24 +620,30 @@ export class Lobby {
|
||||
}
|
||||
|
||||
/**
|
||||
* room.loadout (DESIGN §16): check the operator loadout against the game data, store it on the session and the seat,
|
||||
* and — while a match runs — hand it to the match (accepted only during INFO_CHECK, see the header).
|
||||
* room.loadout (DESIGN §16): check the operator loadout — and its per-operator 潜能 / 练度 `ops` (0.2.2) — against the
|
||||
* game data, store both on the session and the seat, and — while a match runs — hand them to the match (accepted only
|
||||
* during INFO_CHECK, see the header). Either part refused: nothing is stored.
|
||||
*/
|
||||
loadout(session, { entries }) {
|
||||
loadout(session, { entries, ops }) {
|
||||
const data = this.safeData();
|
||||
const res = checkLoadout(entries, (id) => lookup('chess', id, data));
|
||||
if (!res || res.error) return fail(res && isErrCode(res.error) ? res.error : ERR.BAD_MSG, res && res.detail);
|
||||
const ids = opsCharIds(data);
|
||||
const resOps = checkLoadoutOps(ops, (id) => ids.has(id));
|
||||
if (!resOps || resOps.error) return fail(resOps && isErrCode(resOps.error) ? resOps.error : ERR.BAD_MSG, resOps && resOps.detail);
|
||||
const loadout = freezeLoadout(res.loadout);
|
||||
const opsSet = freezeOps(resOps.ops);
|
||||
session.loadout = loadout;
|
||||
session.ops = opsSet;
|
||||
const room = this.roomOf(session);
|
||||
if (!room) return OK;
|
||||
const seat = room.seatOf(session.playerId);
|
||||
if (seat) seat.loadout = loadout;
|
||||
if (seat) { seat.loadout = loadout; seat.ops = opsSet; }
|
||||
if (!room.match || !seat) return OK; // a spectator's loadout stays on its session, never reaching the match
|
||||
if (typeof room.match.setLoadout !== 'function') return fail(ERR.ROOM_STARTED, 'stored for the next match');
|
||||
let r;
|
||||
try {
|
||||
r = room.match.setLoadout(session.playerId, loadout);
|
||||
r = room.match.setLoadout(session.playerId, loadout, opsSet);
|
||||
} catch (e) {
|
||||
this.log.error(`[lobby] ${room.code} match.setLoadout threw`, e);
|
||||
return fail(ERR.INTERNAL);
|
||||
@@ -679,8 +705,9 @@ export class Lobby {
|
||||
if (host) host.ready = true;
|
||||
const seats = room.seats.filter(Boolean).map((s) => ({
|
||||
seat: s.seat, playerId: s.playerId, name: s.name, isBot: s.isBot, connected: s.connected,
|
||||
// DESIGN §16: the human's checked operator loadout (bots fight with the defaults)
|
||||
// DESIGN §16: the human's checked operator loadout and (0.2.2) per-operator 潜能 / 练度 (bots fight with the defaults)
|
||||
loadout: s.isBot ? null : s.loadout || null,
|
||||
ops: s.isBot ? null : s.ops || null,
|
||||
// 0.2.0 补位: the chess the human marked as not owned (bots own every operator)
|
||||
notOwned: s.isBot ? null : s.notOwned || null,
|
||||
// 0.2.0 自选编队: the human's checked DIY picks (bots field no 自选 piece [ASSUMED])
|
||||
@@ -945,6 +972,7 @@ export class Lobby {
|
||||
return {
|
||||
seat: idx, playerId: session.playerId, name: session.name, isBot: false, ready: false, connected: session.connected, left: false,
|
||||
loadout: session.loadout || null,
|
||||
ops: session.ops || null,
|
||||
notOwned: session.notOwned || null,
|
||||
diy: session.diy || null,
|
||||
};
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
// (MatchPhases.humansFirst); only `true` turns it on; ignored in solo
|
||||
// opts.seats Array<{ seat: 0..3, playerId: string, name: string, isBot: boolean, connected: boolean,
|
||||
// loadout?: { [baseChessId]: { skill: index, module: uniEquipId|'none'|null } } | null,
|
||||
// ops?: { [charId]: { potential: 1–6, cultivate: 0–3 } } | null,
|
||||
// notOwned?: string[] | null,
|
||||
// diy?: { [slotBaseId]: { charId, skillIndex, uniEquipId } } | null }>
|
||||
// sorted by seat, 1–4 entries, ≥ 1 human; solo ⇒ exactly 1 human and no bots.
|
||||
// Bot playerIds start with 'ai_'. Seat indexes may have gaps (e.g. seats 0 and 2).
|
||||
// `loadout` (DESIGN §16, optional): the human's operator loadout, already checked by the lobby
|
||||
// (shared/protocol.js checkLoadout); PlayerState re-checks it against opts.data and ignores it for bots.
|
||||
// `ops` (0.2.2, optional): the human's per-operator 潜能 / 练度 (checkLoadoutOps; missing = 潜能 6, 精英2
|
||||
// Lv.60 — the owner's decision of 2026-10-08), re-checked and changed like the loadout (INFO_CHECK);
|
||||
// bots fight with the defaults.
|
||||
// `notOwned` (0.2.0 补位, optional): the base chess ids the human marked as not owned (干员持有) — fixed
|
||||
// for the match; those chess fight as their stand-ins (PlayerState setNotOwned; bots own everything).
|
||||
// `diy` (0.2.0 自选编队, optional): the human's 自选 picks (shared/protocol.js checkDiyPicks) — fixed for
|
||||
@@ -56,9 +60,10 @@
|
||||
// (a resync request). May be called without a preceding onDisconnect. Resend full
|
||||
// state: m.public, m.private and, if a battle is on (client-side combat), the
|
||||
// b.start of the field the player is on / watching (server-run mode: m.field + b.snap).
|
||||
// setLoadout(playerId, loadout) → { ok } | { error, detail? } (DESIGN §16; optional for the platform) a new checked
|
||||
// operator loadout from room.loadout. Accepted only during INFO_CHECK (the briefing's
|
||||
// 干员调配 entry); afterwards the match's loadout is locked (WRONG_PHASE).
|
||||
// setLoadout(playerId, loadout, ops?) → { ok } | { error, detail? } (DESIGN §16; optional for the platform) a new
|
||||
// checked operator loadout (and its 潜能 / 练度 `ops`, 0.2.2) from room.loadout. Accepted only
|
||||
// during INFO_CHECK (the briefing's 干员调配 entry); afterwards the match's loadout is locked
|
||||
// (WRONG_PHASE).
|
||||
// onLeave(playerId) The human quit permanently (g.leave, room.leave, or the 10-minute reconnect
|
||||
// window expired). They will never return under this playerId in this match;
|
||||
// treat as quit (AI takes over / eliminated per DESIGN). No onDisconnect follows.
|
||||
|
||||
@@ -73,6 +73,12 @@
|
||||
// mismatch falls back to the defaults) and kept frozen; bots always use the defaults. Match.setLoadout may replace
|
||||
// it during INFO_CHECK only. battleInput() resolves every chess unit to `skillIndex` + `moduleId` (resolveLoadout:
|
||||
// normal chess → moduleId null, elite → uniEquipId | 'none'); m.private exposes `loadout`.
|
||||
// * 潜能 / 练度 (0.2.2, the owner's decision of 2026-10-08 「调配干员里自己设置吧,默认满潜满加成」): the human's checked
|
||||
// `seat.ops` ({ [charId]: { potential, cultivate } }, defaults dropped) is re-checked (checkLoadoutOps) and changed
|
||||
// with the loadout; a missing entry — and every operator of a bot — is 潜能 6, 精英2 Lv.60. battleInput() states both
|
||||
// for every operator the player owns (a chess fielded as itself, an owned 自选 pick: `cultivationFor`), never for a
|
||||
// 补位 stand-in or a prototype pick (shared/potential.js cultivationOf); the 自选 summons' hand count follows the
|
||||
// owner's potential (望's 棋子). m.private exposes `ops`; the scouting views carry each unit's `potential` / `cultivate`.
|
||||
// * Operator ownership (0.2.0 补位, the approved plan — owner's decision 2026-10-05): the human's `seat.notOwned` (base
|
||||
// chess ids marked 未持有 on the 干员持有 screen) is re-checked against this match's data (shared/protocol.js
|
||||
// checkNotOwned + a stand-in record in data/backups.json) and fixed for the match (`standIns`; bots own every
|
||||
@@ -152,7 +158,9 @@ export class PlayerState {
|
||||
this.lastEmoteAt = -Infinity;
|
||||
/** operator loadout (DESIGN §16): frozen { [baseChessId]: { skill, module } }, {} = every chess on its defaults */
|
||||
this.loadout = Object.freeze({});
|
||||
if (!this.isBot && seat.loadout) this.setLoadout(seat.loadout);
|
||||
// 0.2.2: the per-operator 潜能 / 练度 ({} = every operator 潜能 6, 精英2 Lv.60 — bots always)
|
||||
this.ops = Object.freeze({});
|
||||
if (!this.isBot && (seat.loadout || seat.ops)) this.setLoadout(seat.loadout ?? null, seat.ops ?? null);
|
||||
/**
|
||||
* 补位 (0.2.0): the base chess ids this player fields as their stand-ins — the seat's not-owned list when the match
|
||||
* started, re-checked against this match's data; frozen, sorted; [] = every operator owned (bots always)
|
||||
|
||||
@@ -58,18 +58,20 @@ export class MatchPlatform {
|
||||
|
||||
/**
|
||||
* room.loadout during the match (DESIGN §16): only while INFO_CHECK runs (the briefing's 干员调配 entry); the lobby
|
||||
* already checked it against the data (PlayerState.setLoadout re-checks it).
|
||||
* already checked it against the data (PlayerState.setLoadout re-checks it). `ops` (0.2.2): the per-operator 潜能 /
|
||||
* 练度 that come with it (undefined = unchanged).
|
||||
* @param {string} playerId
|
||||
* @param {Record<string, { skill: number, module: string|null }> | null} loadout
|
||||
* @param {Record<string, { potential: number, cultivate: number }> | null} [ops]
|
||||
* @returns {{ ok: true } | { error: string, detail?: string }}
|
||||
*/
|
||||
setLoadout(playerId, loadout) {
|
||||
setLoadout(playerId, loadout, ops = undefined) {
|
||||
const ps = this.players.get(playerId);
|
||||
if (!ps || ps.isBot || ps.left) return fail(ERR.NOT_IN_ROOM);
|
||||
if (this.disposed || this.ended || this.phase !== PHASE.INFO_CHECK) return fail(ERR.WRONG_PHASE, 'loadout locked for this match');
|
||||
let res = OK;
|
||||
this.guard(() => {
|
||||
if (!ps.setLoadout(loadout)) { res = fail(ERR.BAD_TARGET, 'loadout does not match the game data'); return; }
|
||||
if (!ps.setLoadout(loadout, ops)) { res = fail(ERR.BAD_TARGET, 'loadout does not match the game data'); return; }
|
||||
this.markPrivate(ps);
|
||||
});
|
||||
return res;
|
||||
|
||||
@@ -21,6 +21,17 @@ const finiteOrNull = (v, cap = Infinity) => {
|
||||
return Math.max(0, Math.min(Number.isFinite(cap) ? cap : Infinity, Math.trunc(n)));
|
||||
};
|
||||
|
||||
/**
|
||||
* A scouted operator's potential (below 6) and 练度 (0.2.2), like the sim's UnitInfo: PlayerState.loadoutFor's
|
||||
* `potential` / `cultivate` (null for a stand-in or a prototype 自选 pick: neither field).
|
||||
*/
|
||||
function cultivationInfo(lo) {
|
||||
const out = {};
|
||||
if (lo && Number.isInteger(lo.potential) && lo.potential < 6) out.potential = lo.potential;
|
||||
if (lo && Number.isInteger(lo.cultivate)) out.cultivate = lo.cultivate;
|
||||
return out;
|
||||
}
|
||||
|
||||
export class MatchViews {
|
||||
statusOf(ps) {
|
||||
if (ps.left) return 'left';
|
||||
@@ -238,7 +249,7 @@ export class MatchViews {
|
||||
const rec = piece.kind === 'token' ? gd.token(piece.id) : ps.fieldRecord(chess);
|
||||
const assets = (rec && rec.assets) || {};
|
||||
// DESIGN §16: the skill / module THIS player's operator fights with (the scout's detail card shows it, like the
|
||||
// sim's UnitInfo in a shared field); moduleId only for an elite
|
||||
// sim's UnitInfo in a shared field); moduleId only for an elite; 0.2.2 its potential (below 6) and 练度
|
||||
const lo = piece.kind === 'chess' && chess ? ps.loadoutFor(chess) : null;
|
||||
units.push({
|
||||
id: piece.uid, uid: piece.uid, kind: piece.kind === 'token' ? 'token' : 'op', side: 'ally', ownerId: ps.playerId, defId: piece.id,
|
||||
@@ -252,6 +263,7 @@ export class MatchViews {
|
||||
items: piece.kind === 'chess' && Array.isArray(piece.items) && piece.items.length ? piece.items.map((it) => it.id) : undefined,
|
||||
standInFor: rec && rec.standInFor ? rec.standInFor : undefined,
|
||||
diy: this._diyInfo(ps, piece),
|
||||
...cultivationInfo(lo),
|
||||
});
|
||||
}
|
||||
return units;
|
||||
@@ -315,6 +327,7 @@ export class MatchViews {
|
||||
items: piece.kind === 'chess' && Array.isArray(piece.items) && piece.items.length ? piece.items.map((it) => it.id) : undefined,
|
||||
standInFor: standIn && standIn.standInFor ? standIn.standInFor : undefined,
|
||||
diy: this._diyInfo(ps, piece),
|
||||
...cultivationInfo(lo),
|
||||
});
|
||||
};
|
||||
for (let i = 0; i < ps.hand.length; i++) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// server/match/player/basics.js — PlayerState methods: the basics — seat flags and counts (isHumanActive,
|
||||
// botControlled, deployCap, deployCount, tempEmpty), the prep that resolves a temp piece (tempDue, _putTemp: every
|
||||
// write into a temp slot), the operator loadout (DESIGN §16: setLoadout, loadoutFor), the not-owned operators fielded
|
||||
// write into a temp slot), the operator loadout (DESIGN §16: setLoadout, loadoutFor; 0.2.2 潜能 / 练度: cultivationFor), the not-owned operators fielded
|
||||
// as their stand-ins (0.2.0 补位: setNotOwned, fieldsStandIn, fieldRecord), the deploy map on the field the
|
||||
// player deploys on (Match.deployFieldOf) and the withdrawal of pieces a terrain / deploy-field change left on tiles
|
||||
// they may no longer occupy (_evictIllegal), dirty.
|
||||
@@ -9,9 +9,19 @@
|
||||
|
||||
import { PHASE } from '../../../shared/constants.js';
|
||||
import { msg, dn } from '../../../shared/i18n.js';
|
||||
import { checkLoadout, checkNotOwned, resolveLoadout } from '../../../shared/protocol.js';
|
||||
import { checkLoadout, checkLoadoutOps, cultivationCharIds, checkNotOwned, resolveLoadout } from '../../../shared/protocol.js';
|
||||
import { cultivationOf } from '../../../shared/potential.js';
|
||||
import { tileKey, boardOrder } from '../board.js';
|
||||
|
||||
/** The charIds a player may set a potential / 练度 for, per game-data object (shared/protocol.js cultivationCharIds). */
|
||||
const OPS_IDS = new WeakMap();
|
||||
function opsCharIds(raw) {
|
||||
if (!raw || typeof raw !== 'object') return new Set();
|
||||
let ids = OPS_IDS.get(raw);
|
||||
if (!ids) { ids = cultivationCharIds(raw.chess, raw.backups); OPS_IDS.set(raw, ids); }
|
||||
return ids;
|
||||
}
|
||||
|
||||
export class PlayerBasics {
|
||||
get isHumanActive() { return !this.isBot && !this.left; }
|
||||
/** The engine acts for this seat (AI teammate or "AI 托管"; a departed human is eliminated, so nothing is left to do). */
|
||||
@@ -46,14 +56,35 @@ export class PlayerBasics {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the operator loadout (DESIGN §16) after re-checking it against this match's data. Accepts the checked
|
||||
* form `{ id: { skill, module|null } }` or raw `room.loadout` entries. Returns false (loadout unchanged) when it does
|
||||
* not fit the data; bots keep the defaults.
|
||||
* Replace the operator loadout (DESIGN §16) — and, when `ops` is given, the per-operator 潜能 / 练度 (0.2.2; null = none
|
||||
* set, undefined = unchanged) — after re-checking them against this match's data. Accepts the checked form
|
||||
* `{ id: { skill, module|null } }` or raw `room.loadout` entries, and the checked or raw `ops`. Returns false (nothing
|
||||
* changes) when either does not fit the data; bots keep the defaults.
|
||||
* @param {any} loadout
|
||||
* @param {any} [ops]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
setLoadout(loadout) {
|
||||
setLoadout(loadout, ops = undefined) {
|
||||
if (this.isBot) return false;
|
||||
let opsRes = null;
|
||||
if (ops !== undefined) {
|
||||
const raw = {};
|
||||
if (ops && typeof ops === 'object' && !Array.isArray(ops)) {
|
||||
for (const [id, e] of Object.entries(ops)) {
|
||||
if (!e || typeof e !== 'object') continue;
|
||||
const x = {};
|
||||
if (Number.isInteger(e.potential)) x.potential = e.potential;
|
||||
if (Number.isInteger(e.cultivate)) x.cultivate = e.cultivate;
|
||||
if (Object.keys(x).length) raw[id] = x;
|
||||
}
|
||||
}
|
||||
const ids = opsCharIds(this.gd.raw);
|
||||
opsRes = checkLoadoutOps(raw, (id) => ids.has(id));
|
||||
if (!opsRes || !opsRes.ok) {
|
||||
this.m.log?.warn?.(`[match ${this.m.roomCode}] operator settings of ${this.playerId} ignored: ${opsRes && opsRes.detail}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const entries = {};
|
||||
if (loadout && typeof loadout === 'object' && !Array.isArray(loadout)) {
|
||||
for (const [id, e] of Object.entries(loadout)) {
|
||||
@@ -72,9 +103,27 @@ export class PlayerBasics {
|
||||
const out = {};
|
||||
for (const [id, e] of Object.entries(res.loadout)) out[id] = Object.freeze({ skill: e.skill, module: e.module ?? null });
|
||||
this.loadout = Object.freeze(out);
|
||||
if (opsRes) {
|
||||
const o = {};
|
||||
for (const [id, e] of Object.entries(opsRes.ops)) o[id] = Object.freeze({ potential: e.potential, cultivate: e.cultivate });
|
||||
this.ops = Object.freeze(o);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The potential / 练度 this player's piece of chess record `chessRecord` fights at (0.2.2; shared/potential.js
|
||||
* cultivationOf over `this.ops` — defaults 潜能 6, 精英2 Lv.60): the operator the player owns — the chess fielded as
|
||||
* itself, an owned 自选 pick (its charId) — or null for a 补位 stand-in and a prototype 自选 pick.
|
||||
* @param {object|null} chessRecord
|
||||
* @returns {{ potential: number, cultivate: number } | null}
|
||||
*/
|
||||
cultivationFor(chessRecord) {
|
||||
if (!chessRecord || this.fieldsStandIn(chessRecord)) return null;
|
||||
const rec = chessRecord.isDiy && typeof chessRecord.chessId === 'string' ? this.gd.chess(chessRecord.chessId) || chessRecord : chessRecord;
|
||||
return cultivationOf(rec, this.ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* The skill index / module a chess record fights with under this player's loadout (DESIGN §16) — for a chess this
|
||||
* player fields as its stand-in (0.2.0 补位) the stand-in's backup selection, whatever the loadout says; for a slotted
|
||||
@@ -83,10 +132,12 @@ export class PlayerBasics {
|
||||
*/
|
||||
loadoutFor(chessRecord) {
|
||||
if (this.fieldsStandIn(chessRecord)) {
|
||||
return resolveLoadout(null, this.gd.standIn(chessRecord.chessId), (id) => this.gd.standIn(id) || this.gd.chess(id));
|
||||
return { ...resolveLoadout(null, this.gd.standIn(chessRecord.chessId), (id) => this.gd.standIn(id) || this.gd.chess(id)), potential: null, cultivate: null };
|
||||
}
|
||||
const rec = chessRecord && chessRecord.isDiy && typeof chessRecord.chessId === 'string' ? this.gd.chess(chessRecord.chessId) || chessRecord : chessRecord;
|
||||
return resolveLoadout(this.loadout, rec, (id) => this.gd.chess(id));
|
||||
// 0.2.2: with the operator's potential / 练度 (null for a prototype 自选 pick) — the 自选 summons' hand count reads it
|
||||
const cv = this.cultivationFor(chessRecord);
|
||||
return { ...resolveLoadout(this.loadout, rec, (id) => this.gd.chess(id)), potential: cv ? cv.potential : null, cultivate: cv ? cv.cultivate : null };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
import { KITTED_CHARS } from '../../sim/content/kits/index.js';
|
||||
import { checkDiyPicks } from '../../../shared/protocol.js';
|
||||
import { diyRecord, diySlot, diyTokenOwner } from '../../../shared/diy.js';
|
||||
import { atPotential } from '../../../shared/potential.js';
|
||||
|
||||
const posIntOr = (v, d) => (Number.isInteger(v) && v > 0 ? v : d);
|
||||
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
||||
@@ -102,7 +103,8 @@ export function diyGameData(gd, records) {
|
||||
* placeable, by the variant of the owner form (`bySkill[skillIndex]` sources) — the deploy limit as the count (PRTS
|
||||
* 卫戍协议/帮助 "根据召唤物部署数量上限(非初始持有量)"), the active module's own when its variant has one (`byModule`:
|
||||
* 望's TRP-X "可同时部署的陷阱数量提升", 6 → 7 棋子; SUM-Y stage 2+ 4 drones / summons). The data's deploy limit holds the
|
||||
* token's own talent additions (tools/build-data.mjs tokenTalentDeckBonus, 0.2.0): 麦哲伦 / 令 / 电弧 3, 白铁 2, 夜莺 3 幻影.
|
||||
* token's own talent additions (tools/build-data.mjs tokenTalentDeckBonus, 0.2.0): 麦哲伦 / 令 / 电弧 3, 白铁 2, 夜莺 3 幻影 —
|
||||
* at the owner's potential (`loadout.potential`, PlayerState.loadoutFor; 0.2.2: 望's 棋子 6 below 潜能3, 7 from it).
|
||||
*/
|
||||
placeableTokens: {
|
||||
value: (chessId, loadout = null) => {
|
||||
@@ -113,7 +115,7 @@ export function diyGameData(gd, records) {
|
||||
for (const tid of Array.isArray(rec.tokens) ? rec.tokens : []) {
|
||||
const t = tokenOf(tid);
|
||||
if (!t || t.kind !== 'summon' || t.placeable !== true) continue;
|
||||
const v = isObj(t.variants) ? t.variants[owner] ?? null : null;
|
||||
const v = isObj(t.variants) ? atPotential(t.variants[owner] ?? null, loadout?.potential) : null;
|
||||
if (v) {
|
||||
const alt = loadout && Number.isInteger(loadout.skillIndex) && v.bySkill ? v.bySkill[loadout.skillIndex] : null;
|
||||
const src = Array.isArray(alt?.sources) ? alt.sources : Array.isArray(v.sources) ? v.sources : [];
|
||||
|
||||
@@ -119,6 +119,10 @@ export class PlayerRound {
|
||||
u.skillIndex = lo.skillIndex;
|
||||
u.moduleId = lo.moduleId;
|
||||
}
|
||||
// 0.2.2: the potential / 练度 of an operator the player owns (the chess as itself, an owned 自选 pick — the player's
|
||||
// 干员调配 settings, 潜能 6 / 精英2 Lv.60 by default and for bots; never a stand-in's nor a prototype pick's)
|
||||
const cv = u.standIn ? null : this.cultivationFor(this.gd.chess(piece.id));
|
||||
if (cv) { u.potential = cv.potential; u.cultivate = cv.cultivate; }
|
||||
if (carry && carry.has(piece.uid)) u.carryState = carry.get(piece.uid);
|
||||
units.push(u);
|
||||
} else if (piece.kind === 'token') {
|
||||
|
||||
@@ -96,6 +96,9 @@ export class PlayerViews {
|
||||
nextEnemies: this.m.nextEnemiesFor(this),
|
||||
// DESIGN §16: the effective operator loadout ({ [baseChessId]: { skill, module } }; chess not listed use defaults)
|
||||
loadout: this.loadout,
|
||||
// 0.2.2: the effective per-operator 潜能 / 练度 ({ [charId]: { potential, cultivate } }; operators not listed: 潜能 6,
|
||||
// 精英2 Lv.60) — the client's cards compose the numbers from it (shared/potential.js)
|
||||
ops: this.ops,
|
||||
// 0.2.0 补位: the base chess ids this player fields as their stand-ins in this match (the not-owned list the seat had
|
||||
// at the match start; [] = every operator owned) — the client shows these as their stand-ins (cards, pieces, the
|
||||
// detail card, with a small 「替补」 mark)
|
||||
|
||||
+4
-1
@@ -62,7 +62,8 @@ export const NET_DEFAULTS = Object.freeze({
|
||||
|
||||
/**
|
||||
* Intents that also draw from the per-connection heavy bucket: g.watch (its reply is a large state resend, m.field),
|
||||
* room.loadout (a ≤ 160-entry map validated against the game data; the client debounces its edits), room.ownership
|
||||
* room.loadout (a ≤ 160-entry map and ≤ 256 operator settings validated against the game data; the client debounces its
|
||||
* edits), room.ownership
|
||||
* (a ≤ 160-id list, the same way), room.diy (≤ 8 自选 picks checked against the data, the same way) and room.spectate
|
||||
* (taking a spectator seat in a running match resends its state like a watcher's g.watch — server/lobby.js spectate).
|
||||
*/
|
||||
@@ -109,6 +110,8 @@ export class Session {
|
||||
this.resyncAt = -Infinity;
|
||||
/** @type {Record<string, { skill: number, module: string|null }> | null} checked operator loadout (lobby-owned, DESIGN §16) */
|
||||
this.loadout = null;
|
||||
/** @type {Readonly<Record<string, { potential: number, cultivate: number }>> | null} checked per-operator 潜能 / 练度 (lobby-owned, 0.2.2; room.loadout `ops`) */
|
||||
this.ops = null;
|
||||
/** @type {readonly string[] | null} checked not-owned chess ids (干员持有, lobby-owned, 0.2.0 补位) */
|
||||
this.notOwned = null;
|
||||
/** @type {Readonly<Record<string, { charId: string, skillIndex: number, uniEquipId: string|null }>> | null} checked 自选 picks (lobby-owned, 0.2.0 自选编队) */
|
||||
|
||||
@@ -9,6 +9,7 @@ import { normDir, mirrorDir } from '../dir.js';
|
||||
import { SkillRuntime } from '../skills.js';
|
||||
import { resolveProfile } from '../professions.js';
|
||||
import { normalizeToken } from '../simdata.js';
|
||||
import { isPotential, isCultivate } from '../../../shared/potential.js';
|
||||
import { setupUnitKit } from '../content/index.js';
|
||||
import { installTraitAttackSpeed } from '../content/traitMods.js';
|
||||
import { clone } from './util.js';
|
||||
@@ -145,10 +146,12 @@ export class BattlePlayers {
|
||||
// the unit's own loadout (DESIGN §16): an entry without loadout fields is the DEFAULT — never another player's
|
||||
// choice for the same chess id in a multi-player field (the per-battle data view maps id-only lookups); `standIn:
|
||||
// true` fields the chess as its 补位 stand-in (simdata getStandIn: the stand-in's body, the chess's identity); `diy`
|
||||
// fills a 自选 slot with its pick (simdata getDiy: the slot's identity, the operator's body, skill and module)
|
||||
// fills a 自选 slot with its pick (simdata getDiy: the slot's identity, the operator's body, skill and module);
|
||||
// `potential` (潜能 1–6, 0.2.2) composes the def at it (never a stand-in's)
|
||||
const lo = { skillIndex: inp.skillIndex ?? null, moduleId: inp.moduleId ?? null };
|
||||
if (inp.standIn === true) lo.standIn = true;
|
||||
if (inp.diy && typeof inp.diy === 'object') lo.diy = inp.diy;
|
||||
if (inp.standIn !== true && isPotential(inp.potential)) lo.potential = inp.potential;
|
||||
const def = this.data.getChess(inp.chessId, lo);
|
||||
if (!def) { this.log(`unknown chess ${inp.chessId}${lo.diy ? ' (illegal 自选 pick)' : ''}`); return null; }
|
||||
// a DIY slot has no body of its own (甄选干员): it fights only as a 自选 piece (its `diy` pick)
|
||||
@@ -156,6 +159,12 @@ export class BattlePlayers {
|
||||
const u = this._makeAlly(ps, def, 'op', r, c, { uid: inp.uid, dir });
|
||||
u.items = [...(inp.items ?? [])];
|
||||
u.carry = inp.carryState ?? null;
|
||||
// 练度 (自持有, 0.2.2): the owned operator's ×ATK / ×DEF / ×max HP (units.js Πmul) — never a 补位 stand-in's nor a
|
||||
// prototype 自选 pick's (another character than the one the player owns)
|
||||
if (isCultivate(inp.cultivate) && !def.standInFor && !def.raw?.diyProto) {
|
||||
const mul = typeof this.data.cultivateMul === 'function' ? this.data.cultivateMul(inp.cultivate) : null;
|
||||
if (mul) { u.cultivate = inp.cultivate; u.cultMul = Object.freeze({ ...mul }); u.markDirty(); }
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
import { genericKit, genericTalents } from './generic.js';
|
||||
import { withUnitLoadouts } from '../simdata.js';
|
||||
import { isPotential } from '../../../shared/potential.js';
|
||||
|
||||
// Content files are loaded with guarded dynamic imports: a module that fails to load (syntax error, throwing
|
||||
// top-level code, missing file) is logged and replaced by an empty module instead of breaking the server.
|
||||
@@ -136,7 +137,8 @@ function inputEntry(unit) {
|
||||
* The loadout `{ skillIndex, moduleId }` a unit's PlayerBattleInput entry gives; an entry without loadout fields means
|
||||
* the DEFAULT loadout (`{}`), never "whatever the data view maps this chess id to" (another player's choice in a
|
||||
* multi-player field). `standIn: true` rides along (补位: the stand-in def whatever the skill / module fields say), as
|
||||
* does `diy` (自选: the pick of a DIY slot's piece). Null when the unit has no input entry.
|
||||
* do `diy` (自选: the pick of a DIY slot's piece) and `potential` (0.2.2: 1–6, never a stand-in's). Null when the unit
|
||||
* has no input entry.
|
||||
*/
|
||||
function inputLoadout(unit) {
|
||||
const x = inputEntry(unit);
|
||||
@@ -144,6 +146,7 @@ function inputLoadout(unit) {
|
||||
const extra = {
|
||||
...(x.standIn === true ? { standIn: true } : null),
|
||||
...(x.diy && typeof x.diy === 'object' ? { diy: x.diy } : null),
|
||||
...(x.standIn !== true && isPotential(x.potential) ? { potential: x.potential } : null),
|
||||
};
|
||||
if (x.skillIndex == null && x.moduleId == null) return extra;
|
||||
return { skillIndex: x.skillIndex ?? null, moduleId: x.moduleId ?? null, ...extra };
|
||||
|
||||
@@ -206,7 +206,7 @@ hook), and clear the owner's `mem.summonStock[tokenId]` when the skill takes the
|
||||
`units: [op, { uid, kind: 'token', tokenId, ownerUid, row, col }]` (`test/content/op_bgsnow.test.js`); the match side is
|
||||
covered by `test/match/diy-shop.test.js` (a DIY 鸿雪's 打字机 from prep to battle). A 召唤师 whose talent holds a deck of
|
||||
summons ("可以使用5个召唤物(最多同时部署3个)") takes `shared/summoner.js summonDeck` — the holding, a placed piece's return
|
||||
on its tile, recalls, its pieces' kits (`op-mgllan.js`, `op-ling.js`, `op-radian.js`). Every pick fights at full potential, as every chess (the owner's decision of 2026-10-07: data/backups.json forms, build-data `OPERATOR_POTENTIAL`). A new kit makes the operator a legal pick at once:
|
||||
on its tile, recalls, its pieces' kits (`op-mgllan.js`, `op-ling.js`, `op-radian.js`). Every owned pick fights at its player's potential and 练度, as every chess (default 潜能 6 and 精英2 Lv.60 — the owner's decision of 2026-10-08; data/backups.json forms are built at full potential and carry the lower ranks, DATA.md §2.3); a prototype pick has neither. A new kit makes the operator a legal pick at once:
|
||||
the server's `welcome.diyKitted` lists `KITTED_CHARS`, so the 自选编队 picker offers it and `room.diy` keeps it.
|
||||
|
||||
**The fidelity rule and the checklist** above apply item by item: every skill at rank 4 and 7, every talent, every
|
||||
|
||||
@@ -58,6 +58,7 @@ import { num, talentBb, moduleBb, traitBb, up, toggleBuff, summonTileFree } from
|
||||
import { absoluteRangeKeys, canTargetEnemy } from '../../../targeting.js';
|
||||
import { bodyOnTile } from '../../../body.js';
|
||||
import { COLS } from '../../../constants.js';
|
||||
import { atPotential } from '../../../../../shared/potential.js';
|
||||
|
||||
const S1 = 'skchr_doroth_1';
|
||||
const S2 = 'skchr_doroth_2';
|
||||
@@ -112,7 +113,7 @@ export default {
|
||||
/** The token's deploy limit for her loadout (variant stats, the module's when it carries one); her max stock too. */
|
||||
function limitOf(battle, unit) {
|
||||
const raw = battle.data.rawToken?.(RESONATOR);
|
||||
const v = raw?.variants?.[unit.def?.tokenOwner];
|
||||
const v = atPotential(raw?.variants?.[unit.def?.tokenOwner], unit.def?.loadout?.potential);
|
||||
const mod = unit.def?.loadout?.moduleId;
|
||||
const n = num(v?.byModule?.[mod]?.stats?.deployLimit, num(v?.stats?.deployLimit, num(raw?.deployLimit, 0)));
|
||||
if (n > 0) return n;
|
||||
|
||||
@@ -59,6 +59,7 @@ import { num, skillRec, batMod, up } from '../shared/tier1.js';
|
||||
import { COLS } from '../../../constants.js';
|
||||
import { dirVec } from '../../../dir.js';
|
||||
import { hypot } from '../../../detmath.js';
|
||||
import { atPotential } from '../../../../../shared/potential.js';
|
||||
|
||||
const S1 = 'skchr_mcnist_1';
|
||||
const S2 = 'skchr_mcnist_2';
|
||||
@@ -286,7 +287,7 @@ export default {
|
||||
},
|
||||
talents: [
|
||||
{ install(battle, unit) { // 结构性原理: her pieces run the token's kit (set up before the battle starts)
|
||||
const raw = battle.data.rawToken?.(MCGRAF)?.variants?.[unit.def?.tokenOwner] ?? null;
|
||||
const raw = atPotential(battle.data.rawToken?.(MCGRAF)?.variants?.[unit.def?.tokenOwner] ?? null, unit.def?.loadout?.potential);
|
||||
for (const t of battle.allyUnits) {
|
||||
if (!isGrafOf(t, unit) || t.alive || t.deployed) continue;
|
||||
// its life: the base variant's (the SO-A stage-3 skill@duration −1 is 集成战略-only)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
// its owner), else the engine's removal reason.
|
||||
|
||||
import { num, up } from './tier1.js';
|
||||
import { atPotential } from '../../../../../shared/potential.js';
|
||||
|
||||
/** Seconds between two tries of a piece waiting to come back (its owner off the field, timer, holding, DP, tile). */
|
||||
export const DECK_RETRY = 0.25;
|
||||
@@ -73,8 +74,9 @@ export function summonTriggerArea(battle, owner, skillId, area) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A field of a summon's token record at its owner's form and module (data/backups.json `tokens[id].variants[<charId>@
|
||||
* <status>]`, `byModule[uniEquipId]`): the stats the normalised def drops (`deployLimit`, `deckStack`).
|
||||
* A field of a summon's token record at its owner's form, module and potential (data/backups.json `tokens[id].variants[<charId>@
|
||||
* <status>]`, `byModule[uniEquipId]`; shared/potential.js atPotential): the stats the normalised def drops (`deployLimit`,
|
||||
* `deckStack`).
|
||||
* @param {object} battle
|
||||
* @param {object} owner the summoner unit
|
||||
* @param {string} tokenId
|
||||
@@ -82,7 +84,7 @@ export function summonTriggerArea(battle, owner, skillId, area) {
|
||||
*/
|
||||
export function tokenStat(battle, owner, tokenId, key) {
|
||||
const raw = battle.data?.rawToken?.(tokenId) ?? null;
|
||||
const v = raw?.variants?.[owner?.def?.tokenOwner] ?? null;
|
||||
const v = atPotential(raw?.variants?.[owner?.def?.tokenOwner] ?? null, owner?.def?.loadout?.potential);
|
||||
const mod = owner?.def?.loadout?.diy?.uniEquipId ?? owner?.def?.loadout?.moduleId ?? null;
|
||||
const st = (mod && v?.byModule?.[mod]?.stats) || v?.stats || raw?.stats || null;
|
||||
return st && Number.isFinite(st[key]) ? st[key] : (Number.isFinite(raw?.[key]) ? raw[key] : null);
|
||||
|
||||
@@ -97,6 +97,7 @@ import { bardRegen } from '../professions.js';
|
||||
import { normDir, localOrder } from '../dir.js';
|
||||
import { SKILL_SUMMON_START_DEPLOY } from '../../../shared/constants.js';
|
||||
import { hypot } from '../detmath.js';
|
||||
import { atPotential } from '../../../shared/potential.js';
|
||||
|
||||
const num = (v, d = 0) => (typeof v === 'number' && Number.isFinite(v) ? v : (typeof v === 'string' && v.trim() !== '' && Number.isFinite(+v) ? +v : d));
|
||||
const GRID_3X3 = Object.freeze([[1, -1], [1, 0], [1, 1], [0, -1], [0, 0], [0, 1], [-1, -1], [-1, 0], [-1, 1]]);
|
||||
@@ -161,7 +162,8 @@ function ownVariant(raw, owner) {
|
||||
const oid = owner?.def?.tokenOwner ?? owner?.defId;
|
||||
if (!vs || typeof vs !== 'object' || !oid) return null;
|
||||
const v = vs[oid] ?? vs[String(oid).replace(/_b$/, '_a')] ?? null;
|
||||
return v ? withLoadout(v, owner.def?.loadout) : null;
|
||||
// at the owner's potential (0.2.2: a 自选 summon's deploy limit / count, the talents — shared/potential.js)
|
||||
return v ? withLoadout(atPotential(v, owner.def?.loadout?.potential), owner.def?.loadout) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+49
-13
@@ -27,6 +27,10 @@
|
||||
// slot's base id, `def.charId` = the operator (its kit, content/index.js kitOf), `def.loadout.diy` = the checked pick and
|
||||
// `def.tokenOwner` = the key of its summons' variants (data/backups.json `tokens`, read by getToken); null for an illegal
|
||||
// pick.
|
||||
// Potential (潜能 1–6, 0.2.2 — the player's 干员调配 setting; shared/potential.js): a loadout's `potential` composes the
|
||||
// chess / 自选 record at it (`def.loadout.potential`; full potential 6 is the default and the data's own) and the
|
||||
// summons' variants at their owner's potential (getToken / getDiyToken: talents, a 自选 summon's deploy limit / count).
|
||||
// A 补位 stand-in and a prototype 自选 pick have no potential.
|
||||
//
|
||||
// This module is pure ESM shared with browsers (served at /sim/): no Node API is imported here. Under Node the default
|
||||
// loader (./nodeData.js) is imported dynamically at module evaluation; browsers never load it.
|
||||
@@ -36,6 +40,7 @@
|
||||
// getSimData() the injected data (browser) or the generated data (Node), or null.
|
||||
|
||||
import { resolveRecordLoadout, composeStats, composeTalents, loadoutRecord } from '../../shared/loadoutRecord.js';
|
||||
import { atPotential, isPotential, POTENTIAL_DEFAULT, cultivateMul } from '../../shared/potential.js';
|
||||
import { standInRecord } from '../../shared/standIn.js';
|
||||
import { diyRecordOf, diyTokenOwner } from '../../shared/diy.js';
|
||||
import { normHitArea } from './body.js';
|
||||
@@ -230,7 +235,7 @@ export { composeStats, composeTalents, loadoutRecord };
|
||||
|
||||
/** Cache key suffix of a resolved non-default loadout ('' for the default). */
|
||||
export function loadoutKey(lo) {
|
||||
return lo && !lo.isDefault ? `|s${lo.skillIndex}|m${lo.moduleId ?? ''}` : '';
|
||||
return lo && !lo.isDefault ? `|s${lo.skillIndex}|m${lo.moduleId ?? ''}${lo.potentialIsDefault === false ? `|p${lo.potential}` : ''}` : '';
|
||||
}
|
||||
|
||||
/** Build an immunity Set from an object `{stun:true,…}` or an array `['stun', 'feared']`. */
|
||||
@@ -560,6 +565,7 @@ export class DataSource {
|
||||
stages: asMap(unwrap(raw.stages, 'stages'), 'id') ?? {},
|
||||
waves: asMap(unwrap(raw.waves, 'waves'), 'id') ?? {},
|
||||
backups: raw.backups && typeof raw.backups === 'object' && raw.backups.units ? raw.backups : null,
|
||||
effects: raw.effects && typeof raw.effects === 'object' ? raw.effects : null,
|
||||
};
|
||||
this.fallback = fallback;
|
||||
this._chess = new Map();
|
||||
@@ -578,6 +584,20 @@ export class DataSource {
|
||||
rawWave(id) { return this.raw.waves[id] ?? this.fallback?.rawWave(id) ?? null; }
|
||||
/** data/backups.json (`{ units, diy }`) of this source or its fallback, or null. */
|
||||
rawBackups() { return this.raw.backups ?? (typeof this.fallback?.rawBackups === 'function' ? this.fallback.rawBackups() : null); }
|
||||
/** A data/effects.json record of this source, its fallback, or the default game data (Node / the injected data). */
|
||||
rawEffect(id) {
|
||||
const own = this.raw.effects && Object.prototype.hasOwnProperty.call(this.raw.effects, id) ? this.raw.effects[id] : null;
|
||||
if (own) return own;
|
||||
if (typeof this.fallback?.rawEffect === 'function') return this.fallback.rawEffect(id);
|
||||
const fx = generatedCache && generatedCache.effects;
|
||||
return fx && Object.prototype.hasOwnProperty.call(fx, id) ? fx[id] : null;
|
||||
}
|
||||
/**
|
||||
* The 练度 (自持有) multipliers of tier `cultivate` (0–3): ATK / DEF / max HP from the effects.json CHAR_MAP record's
|
||||
* char_attribute_mul (shared/potential.js cultivateMul), or null.
|
||||
* @param {number} cultivate
|
||||
*/
|
||||
cultivateMul(cultivate) { return cultivateMul((id) => this.rawEffect(id), cultivate); }
|
||||
|
||||
/**
|
||||
* Chess def for the default loadout, or for `loadout` `{ skillIndex, moduleId }` (DESIGN §16; resolved with
|
||||
@@ -586,10 +606,11 @@ export class DataSource {
|
||||
* `loadout.standIn === true`: the 补位 def of the chess (getStandIn) — its skill and module are the chess's backup
|
||||
* selection whatever `skillIndex` / `moduleId` say; a chess without a stand-in (PRESET, DIY, no backups data) gives
|
||||
* its own def for that loadout. `loadout.diy` (`{ charId, skillIndex, uniEquipId }`): the 自选 def of a DIY slot
|
||||
* (getDiy; null when the pick is not legal for that slot).
|
||||
* (getDiy; null when the pick is not legal for that slot). `loadout.potential` (1–6): the record at that potential
|
||||
* (loadoutRecord; not for a stand-in).
|
||||
*/
|
||||
getChess(id, loadout = null) {
|
||||
if (loadout && loadout.diy && typeof loadout.diy === 'object') return this.getDiy(id, loadout.diy);
|
||||
if (loadout && loadout.diy && typeof loadout.diy === 'object') return this.getDiy(id, loadout.diy, loadout.potential);
|
||||
if (loadout && loadout.standIn === true) {
|
||||
const sd = this.getStandIn(id);
|
||||
if (sd) return sd;
|
||||
@@ -636,19 +657,26 @@ export class DataSource {
|
||||
* module, `def.charId` the operator's, `def.diyFor` the slot's base id, `def.loadout` = the selection (`isDefault`) with
|
||||
* `diy` = the checked pick, `def.tokenOwner` = its summons' variant key (shared/diy.js diyTokenOwner). Null for an
|
||||
* illegal pick (not a pick of the slot's tier, a prototype off its locked skill, an unknown skill or module — checkDiyPick)
|
||||
* or when the data lacks it. Cached per (id, pick).
|
||||
* or when the data lacks it. An owned pick is composed at `potential` (1–6, default 6; shared/diy.js diyRecordOf —
|
||||
* `def.loadout.potential`, its summons' variants follow); a prototype has none. Cached per (id, pick, potential).
|
||||
* @param {string} id
|
||||
* @param {{ charId?: string, skillIndex?: number|null, uniEquipId?: string|null }} pick
|
||||
* @param {number|null} [potential]
|
||||
*/
|
||||
getDiy(id, pick) {
|
||||
const key = `${id}|diy|${pick?.charId ?? ''}|${pick?.skillIndex ?? ''}|${pick?.uniEquipId ?? ''}`;
|
||||
getDiy(id, pick, potential = null) {
|
||||
const pot = isPotential(potential) ? potential : POTENTIAL_DEFAULT;
|
||||
const key = `${id}|diy|${pick?.charId ?? ''}|${pick?.skillIndex ?? ''}|${pick?.uniEquipId ?? ''}|p${pot}`;
|
||||
if (this._chess.has(key)) return this._chess.get(key);
|
||||
const r = this.rawChess(id);
|
||||
const rec = r && r.isDiy ? diyRecordOf(r, pick, this) : null;
|
||||
const rec = r && r.isDiy ? diyRecordOf(r, pick, this, { potential: pot }) : null;
|
||||
let d = null;
|
||||
if (rec) {
|
||||
d = normalizeChess({ ...rec, chessId: id });
|
||||
d.loadout = { ...resolveLoadout(rec, null), diy: { charId: rec.charId, skillIndex: rec.skill.index, uniEquipId: rec.module?.id ?? null } };
|
||||
const own = rec.diyProto ? POTENTIAL_DEFAULT : pot;
|
||||
d.loadout = {
|
||||
...resolveLoadout(rec, null), potential: own, potentialIsDefault: own === POTENTIAL_DEFAULT,
|
||||
diy: { charId: rec.charId, skillIndex: rec.skill.index, uniEquipId: rec.module?.id ?? null },
|
||||
};
|
||||
d.tokenOwner = diyTokenOwner(rec.charId, rec.status);
|
||||
freezeDef(d);
|
||||
}
|
||||
@@ -671,7 +699,7 @@ export class DataSource {
|
||||
* than 'display'; PlayerState / the kits' skill summons read them from here).
|
||||
*/
|
||||
getToken(id, ownerChessId = null, ownerLoadout = null) {
|
||||
if (ownerChessId && ownerLoadout && ownerLoadout.diy && typeof ownerLoadout.diy === 'object') return this.getDiyToken(id, ownerChessId, ownerLoadout.diy);
|
||||
if (ownerChessId && ownerLoadout && ownerLoadout.diy && typeof ownerLoadout.diy === 'object') return this.getDiyToken(id, ownerChessId, ownerLoadout.diy, ownerLoadout.potential);
|
||||
const olo = ownerChessId && ownerLoadout ? resolveLoadout(this.rawChess(ownerChessId), ownerLoadout) : null;
|
||||
const ck = id + '|' + (ownerChessId ?? '') + loadoutKey(olo);
|
||||
if (this._token.has(ck)) return this._token.get(ck);
|
||||
@@ -695,6 +723,8 @@ export class DataSource {
|
||||
}
|
||||
if (r && r.variants && !owner) owner = Object.keys(r.variants)[0] ?? null;
|
||||
let variant = r && r.variants && owner ? r.variants[owner] ?? null : null;
|
||||
// the owner's potential (0.2.2): the variant's talents (and counts) at it — before the skill / module parts merge
|
||||
if (variant && olo && olo.potentialIsDefault === false) variant = atPotential(variant, olo.potential);
|
||||
if (variant && olo && !olo.isDefault) {
|
||||
if (!olo.skillIsDefault && variant.bySkill && variant.bySkill[olo.skillIndex]) variant = { ...variant, ...variant.bySkill[olo.skillIndex] };
|
||||
if (!olo.moduleIsDefault && variant.byModule && variant.byModule[olo.moduleId]) variant = { ...variant, ...variant.byModule[olo.moduleId] };
|
||||
@@ -712,14 +742,17 @@ export class DataSource {
|
||||
* @param {string} id token id
|
||||
* @param {string} slotId the owner's DIY slot record id (`_a` / `_b`)
|
||||
* @param {{ charId?: string, skillIndex?: number|null, uniEquipId?: string|null }} pick the owner def's `loadout.diy`
|
||||
* @param {number|null} [potential] the owner's potential (its `loadout.potential`; default 6): the variant at it
|
||||
*/
|
||||
getDiyToken(id, slotId, pick) {
|
||||
getDiyToken(id, slotId, pick, potential = null) {
|
||||
const slot = this.rawChess(slotId);
|
||||
const owner = slot && typeof pick?.charId === 'string' ? diyTokenOwner(pick.charId, slot.status) : null;
|
||||
const ck = `${id}|diy|${owner ?? ''}|${pick?.skillIndex ?? ''}|${pick?.uniEquipId ?? ''}`;
|
||||
const pot = isPotential(potential) ? potential : POTENTIAL_DEFAULT;
|
||||
const ck = `${id}|diy|${owner ?? ''}|${pick?.skillIndex ?? ''}|${pick?.uniEquipId ?? ''}|p${pot}`;
|
||||
if (this._token.has(ck)) return this._token.get(ck);
|
||||
const r = this.rawToken(id);
|
||||
let variant = r && r.variants && owner ? r.variants[owner] ?? null : null;
|
||||
if (variant) variant = atPotential(variant, pot);
|
||||
if (variant) {
|
||||
const si = pick.skillIndex;
|
||||
if (Number.isInteger(si) && variant.bySkill && variant.bySkill[si]) variant = { ...variant, ...variant.bySkill[si] };
|
||||
@@ -821,7 +854,7 @@ export function toDataSource(data) {
|
||||
* loadout, and an existing view unchanged (`isLoadoutView`). Used by spec.js createBattleFromSpec and by
|
||||
* content/index.js installContent (every Battle, however constructed). An entry with `standIn: true` (补位) maps its
|
||||
* chess id to the stand-in def (`getChess(id, { standIn: true })`) the same way, and one with `diy` (自选: `{ charId,
|
||||
* skillIndex, uniEquipId }`) to its 自选 def (`getChess(id, { diy })`).
|
||||
* skillIndex, uniEquipId }`) to its 自选 def (`getChess(id, { diy })`); a `potential` (1–6) rides along (0.2.2).
|
||||
* @param {object} ds DataSource
|
||||
* @param {object[]} players PlayerBattleInput[] (spec players)
|
||||
*/
|
||||
@@ -834,13 +867,16 @@ export function withUnitLoadouts(ds, players) {
|
||||
for (const u of (p && Array.isArray(p.units) ? p.units : [])) {
|
||||
if (!u || u.kind === 'token' || typeof u.chessId !== 'string') continue;
|
||||
const diy = u.diy && typeof u.diy === 'object' ? u.diy : null;
|
||||
if (u.skillIndex != null || u.moduleId != null || u.standIn === true || diy) any = true;
|
||||
const pot = u.standIn !== true && isPotential(u.potential) ? u.potential : null;
|
||||
if (u.skillIndex != null || u.moduleId != null || u.standIn === true || diy || pot != null) any = true;
|
||||
const lo = { skillIndex: u.skillIndex ?? null, moduleId: u.moduleId ?? null };
|
||||
if (u.standIn === true) lo.standIn = true;
|
||||
if (diy) lo.diy = diy;
|
||||
if (pot != null) lo.potential = pot;
|
||||
const prev = map.get(u.chessId);
|
||||
if (!prev) map.set(u.chessId, lo);
|
||||
else if (prev.skillIndex !== lo.skillIndex || prev.moduleId !== lo.moduleId || !!prev.standIn !== !!lo.standIn
|
||||
|| (prev.potential ?? null) !== (lo.potential ?? null)
|
||||
|| JSON.stringify(prev.diy ?? null) !== JSON.stringify(lo.diy ?? null)) conflicts.add(u.chessId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ export function unitInfo(u) {
|
||||
standInFor: u.side === 'ally' && u.kind === 'op' && typeof d.standInFor === 'string' ? d.standInFor : undefined,
|
||||
// 自选: the pick of a DIY slot's piece (the detail card composes its record, shared/diy.js diyRecord)
|
||||
diy: u.side === 'ally' && u.kind === 'op' && d.diyFor && d.loadout?.diy ? { ...d.loadout.diy } : undefined,
|
||||
// 0.2.2: an ally operator's potential below 6 and its 练度 tier (a teammate's unit shows ITS owner's numbers; absent:
|
||||
// full potential, no 练度 — a stand-in, a prototype 自选 pick)
|
||||
potential: u.side === 'ally' && u.kind === 'op' && d.loadout?.potentialIsDefault === false ? d.loadout.potential : undefined,
|
||||
cultivate: u.side === 'ally' && u.kind === 'op' && Number.isInteger(u.cultivate) ? u.cultivate : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -25,9 +25,15 @@
|
||||
// 自选 (DATA.md §18): an operator entry of a DIY slot (`chessId` its `_a` / `_b` id) carries `diy: { charId, skillIndex?,
|
||||
// uniEquipId? }` (kept when well-formed; the data layer checks legality — shared/diy.js checkDiyPick) and is fielded as
|
||||
// simdata getChess(id, { diy }).
|
||||
// Potential and 练度 (0.2.2, shared/potential.js — the player's 干员调配 settings, the owner's decision of 2026-10-08): an
|
||||
// operator entry may carry `potential` (潜能 1–6: the def at that potential, its summons' talents at it) and
|
||||
// `cultivate` (练度 0–3: the effects.json CHAR_MAP aceffect_char_1…4 — a ×ATK / ×DEF / ×max HP of the unit, its own
|
||||
// multiplier); each kept only when well-formed and never on a stand-in. Absent: full potential and no 练度 (a raw
|
||||
// unit — the match always states both for an owned operator: PlayerState.battleInput).
|
||||
|
||||
import { Battle } from './Battle.js';
|
||||
import { toDataSource, withUnitLoadouts } from './simdata.js';
|
||||
import { isPotential, isCultivate } from '../../shared/potential.js';
|
||||
import { BOSS_POOL_MIN_HP } from './constants.js';
|
||||
|
||||
export const SPEC_VERSION = 1;
|
||||
@@ -101,14 +107,18 @@ function cleanDiyPick(d) {
|
||||
|
||||
/**
|
||||
* Keep a unit's `skillIndex` / `moduleId` only when well-formed (the data layer checks legality), `standIn` only when
|
||||
* exactly `true` (补位) and `diy` only as a well-formed pick (自选). Mutates `u`.
|
||||
* exactly `true` (补位), `diy` only as a well-formed pick (自选), `potential` (1–6) / `cultivate` (0–3) only when
|
||||
* well-formed and not on a stand-in. Mutates `u`.
|
||||
*/
|
||||
export function sanitizeUnitLoadout(u) {
|
||||
if ('skillIndex' in u && !(Number.isInteger(u.skillIndex) && u.skillIndex >= 0 && u.skillIndex <= 9)) delete u.skillIndex;
|
||||
if ('moduleId' in u && !(typeof u.moduleId === 'string' && LOADOUT_ID.test(u.moduleId))) delete u.moduleId;
|
||||
if ('standIn' in u && u.standIn !== true) delete u.standIn;
|
||||
if ('diy' in u) { const d = cleanDiyPick(u.diy); if (d) u.diy = d; else delete u.diy; }
|
||||
if (u.kind === 'token') { delete u.skillIndex; delete u.moduleId; delete u.standIn; delete u.diy; }
|
||||
if ('potential' in u && !isPotential(u.potential)) delete u.potential;
|
||||
if ('cultivate' in u && !isCultivate(u.cultivate)) delete u.cultivate;
|
||||
if (u.standIn === true) { delete u.potential; delete u.cultivate; }
|
||||
if (u.kind === 'token') { delete u.skillIndex; delete u.moduleId; delete u.standIn; delete u.diy; delete u.potential; delete u.cultivate; }
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -1,7 +1,7 @@
|
||||
// server/sim/units.js — Unit model (operators, tokens, enemies, devices) and stat aggregation (DESIGN §5.2).
|
||||
//
|
||||
// Aggregation (recomputed lazily whenever buffs change — `unit.markDirty()`):
|
||||
// ATK/DEF/maxHp = (base + Σflat) × (1 + Σpct) × Πmul
|
||||
// ATK/DEF/maxHp = (base + Σflat) × (1 + Σpct) × Πmul (Πmul includes the unit's 练度 `cultMul`, 0.2.2)
|
||||
// res = clamp((base + Σflat) × Πmul, 0, 100)
|
||||
// aspd = clamp(base + Σaspd, 20, 600) (base is 100 for almost everyone; floor 20 = PRTS 数值范围)
|
||||
// interval = bat × (1 + ΣbatPct) × 100 / aspd (ΣbatPct floored at −0.9)
|
||||
@@ -16,6 +16,8 @@ import { DIR_VEC, normDir } from './dir.js';
|
||||
|
||||
const clamp = (v, a, b) => (v < a ? a : v > b ? b : v);
|
||||
const EMPTY = Object.freeze({});
|
||||
/** No 练度 multiplier (a unit without one: enemies, summons, stand-ins, a raw spec unit). */
|
||||
const NO_MUL = Object.freeze({ atk: 1, def: 1, hp: 1 });
|
||||
/** Aggregates can overflow (huge stacked *Mul mods → Infinity) — fall back to `d` so no stat is ever non-finite. */
|
||||
const fin = (v, d) => (Number.isFinite(v) ? v : d);
|
||||
|
||||
@@ -103,6 +105,10 @@ export class Unit {
|
||||
// here so every unit keeps the same object shape (the hot loops' property reads)
|
||||
this.inTotal = false;
|
||||
this.bossPool = null;
|
||||
// 练度 (自持有, 0.2.2; battle/players.js): the owned operator's tier (0–3, effects.json aceffect_char_1…4) and its
|
||||
// char_attribute_mul — ATK / DEF / max HP, a multiplier of its own (never summed with the 直接乘算 percentages)
|
||||
this.cultivate = null;
|
||||
this.cultMul = null;
|
||||
}
|
||||
|
||||
markDirty() { this._dirty = true; }
|
||||
@@ -129,12 +135,13 @@ export class Unit {
|
||||
const a = (k) => add[k] ?? 0;
|
||||
const m = (k) => mul[k] ?? 1;
|
||||
const b = this.base;
|
||||
const cm = this.cultMul || NO_MUL;
|
||||
const bHp = fin(b.maxHp, 1) > 0 ? fin(b.maxHp, 1) : 1;
|
||||
const maxHp = Math.max(1, fin((bHp + a('hpFlat')) * Math.max(0, 1 + a('hpPct')) * m('hpMul'), bHp));
|
||||
const maxHp = Math.max(1, fin((bHp + a('hpFlat')) * Math.max(0, 1 + a('hpPct')) * m('hpMul') * cm.hp, bHp));
|
||||
// PRTS 游戏数据基础 属性基本公式 A_f = F_t[(A + D_p)(1 + D_t) + F_p]: `atkFinal` is the 最终加算 (FINAL_ADDITION) —
|
||||
// added after the percentages, inside the Πmul (阿戈尔's devoured base ATK, DESIGN §24.7)
|
||||
const atk = Math.max(0, fin(((b.atk + a('atkFlat')) * Math.max(0, 1 + a('atkPct')) + a('atkFinal')) * m('atkMul'), fin(b.atk, 0)));
|
||||
const def = Math.max(0, fin((b.def + a('defFlat')) * Math.max(0, 1 + a('defPct')) * m('defMul'), fin(b.def, 0)));
|
||||
const atk = Math.max(0, fin(((b.atk + a('atkFlat')) * Math.max(0, 1 + a('atkPct')) + a('atkFinal')) * m('atkMul') * cm.atk, fin(b.atk, 0)));
|
||||
const def = Math.max(0, fin((b.def + a('defFlat')) * Math.max(0, 1 + a('defPct')) * m('defMul') * cm.def, fin(b.def, 0)));
|
||||
const res = clamp(fin((b.res + a('resFlat')) * m('resMul'), fin(b.res, 0)), 0, 100);
|
||||
const aspd = clamp(fin(b.aspd + a('aspd'), 100), ASPD_MIN, ASPD_MAX);
|
||||
const bBat = fin(b.bat, 1) > 0 ? fin(b.bat, 1) : 1;
|
||||
|
||||
Reference in new issue
Block a user