From a82969a23bf22a572b56f792e03c4f925cccea83 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 27 Aug 2026 17:21:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E4=B8=83=E7=8E=8B=EF=BC=9A=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=20roomtype=20=E4=BD=8D=E4=B8=B2=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与服务端 class.config.js 的 parse() 同规则;缺失/非字符串/过短一律按 '0', 这是协议 §0.5 明文规定的行为。已逐位对照服务端确认。 Co-Authored-By: Claude Opus 5 (1M context) --- .../js/01_SubGame/codes/state/RoomOptions.js | 34 +++++++++++++++++++ client/tests/test_roomoptions.js | 34 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 client/js/01_SubGame/codes/state/RoomOptions.js create mode 100644 client/tests/test_roomoptions.js diff --git a/client/js/01_SubGame/codes/state/RoomOptions.js b/client/js/01_SubGame/codes/state/RoomOptions.js new file mode 100644 index 0000000..99a64df --- /dev/null +++ b/client/js/01_SubGame/codes/state/RoomOptions.js @@ -0,0 +1,34 @@ +/////////////////////////////////////////////////////////////// +////////// EQW_RoomOptions_Parse: roomtype 位串解析 /////////// +/////////////////////////////////////////////////////////////// +// 协议 §0.5:roomtype 是建房时拼好的定长数字位串(字符串),每一位 '0'/'1'。 +// 服务端解析入口是 class.config.js 的 parse(),本文件必须与之【同规则】。 +// +// 位0 局数 '0'=6局(缺省) '1'=12局 +// 位1 扣卡 '0'=房主扣卡 '1'=AA 每人扣卡 +// 位2 傍王 '0'=关 '1'=开 +// 位3 爬坡 '0'=常规算子 '1'=爬坡 +// 位4 查牌 '0'=可查牌 '1'=不查牌 +// +// 对【缺失、非字符串、过短】的 roomtype 一律按 '0' 处理(与服务端一致), +// 这是协议明文规定的行为,不是隐式兜底。 +var EQW_RoomOptions_Parse = (function() { + //取第 idx 位,越界或非字符串时按 '0' + function _bit(roomtype, idx) { + if (typeof roomtype !== 'string') { return 0; } + if (idx >= roomtype.length) { return 0; } + return roomtype.charAt(idx) === '1' ? 1 : 0; + } + + return { + parse: function (roomtype) { + return { + asetCount: _bit(roomtype, 0) ? 12 : 6, + deductAA: _bit(roomtype, 1), + bangwang: _bit(roomtype, 2), + climb: _bit(roomtype, 3), + nocheck: _bit(roomtype, 4) + }; + } + }; +})(); diff --git a/client/tests/test_roomoptions.js b/client/tests/test_roomoptions.js new file mode 100644 index 0000000..82b4c4c --- /dev/null +++ b/client/tests/test_roomoptions.js @@ -0,0 +1,34 @@ +// roomtype 位串解析(协议 §0.5),必须与服务端 class.config.js 的 parse() 同规则 +const { load } = require('./_load'); +const t = require('./_assert')(); + +load('client/js/01_SubGame/codes/state/RoomOptions.js'); + +const P = EQW_RoomOptions_Parse.parse; + +// ---- 缺省 "00000" = 6局 / 房主扣卡 / 无傍王 / 常规算子 / 可查牌 ---- +t.eq('缺省', P('00000'), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); + +// ---- 协议 §0.5 的示例:10100 = 12局 / 房主扣卡 / 傍王开 / 常规算子 / 可查牌 ---- +t.eq('示例 10100', P('10100'), { asetCount: 12, deductAA: 0, bangwang: 1, climb: 0, nocheck: 0 }); + +// ---- 逐位 ---- +t.eq('位0 局数', P('10000').asetCount, 12); +t.eq('位1 AA扣卡', P('01000').deductAA, 1); +t.eq('位2 傍王', P('00100').bangwang, 1); +t.eq('位3 爬坡', P('00010').climb, 1); +t.eq('位4 不查牌', P('00001').nocheck, 1); +t.eq('全开', P('11111'), { asetCount: 12, deductAA: 1, bangwang: 1, climb: 1, nocheck: 1 }); + +// ---- 反面:缺失/非字符串/过短一律按 '0' ---- +t.eq('undefined', P(undefined), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); +t.eq('null', P(null), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); +t.eq('空串', P(''), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); +t.eq('过短只有两位', P('11'), { asetCount: 12, deductAA: 1, bangwang: 0, climb: 0, nocheck: 0 }); +t.eq('非字符串(数字)', P(11111), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); +t.eq('非字符串(数组)', P([]), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); + +// ---- 超长不报错,只取前 5 位 ---- +t.eq('超长', P('1111199999').bangwang, 1); + +process.exit(t.done('roomoptions') ? 0 : 1);