三种结算来源组成不同(正常出牌 / 投降 / 解散),共用一套落地逻辑: 有哪组写哪组,缺的保持 null。 解散走平台的 Game_Modify.Free 入口而非收包分发表——它的 route 是 room, 被平台分流走了。取值路径因此比协议文档少一层,且参数可能为 null (首局发牌前解散),已覆盖。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
73 lines
3.6 KiB
JavaScript
73 lines
3.6 KiB
JavaScript
// 结算 / 解散 handler
|
||
const { load } = require('./_load');
|
||
const t = require('./_assert')();
|
||
|
||
load('client/js/gameabc-framework/system/EventBus.js');
|
||
load('client/js/01_SubGame/codes/state/Events.js');
|
||
load('client/js/01_SubGame/codes/state/GameState.js');
|
||
load('client/js/01_SubGame/codes/net/handlers/ResultHandler.js');
|
||
|
||
const S = EQW_GameState;
|
||
const evts = [];
|
||
Object.keys(EQW_Events).forEach(k => EventBus.on(EQW_Events[k], () => evts.push(k)));
|
||
|
||
const ASET = { banker: 0, call: 60, multiple: 3, flower: 3, grade: 45, upgrade: 1,
|
||
bangwang: 0, climb: 0,
|
||
seatlist: [{ grade: 6, score: 6 }, { grade: -3, score: -3 }, { grade: -3, score: -3 }] };
|
||
|
||
// ================= 正常出牌结算 =================
|
||
S.reset(); evts.length = 0;
|
||
EQW_ResultHandler.handleJiesuan({ success: true,
|
||
chupai: { seat: 2, cards: [9], maxseat: 0, grade: 10 },
|
||
bottom: { cards: [1,2,3,4,5,6,7,8], multiple: 2, grade1: 20, grade2: 40 },
|
||
aset: ASET });
|
||
|
||
t.eq('小局结算入状态', S.result.aset, ASET);
|
||
t.eq('抠底入状态', S.result.bottom.grade2, 40);
|
||
t.eq('最后一手入状态', S.result.chupai.maxseat, 0);
|
||
t.eq('step 置为结算', S.aset.step, 6);
|
||
t.eq('结算发事件', evts.indexOf('EQW_ASET_RESULT') >= 0, true);
|
||
t.eq('非末局不发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') < 0, true);
|
||
|
||
// ================= 投降结算(无 chupai / 无 bottom)=================
|
||
S.reset(); evts.length = 0;
|
||
EQW_ResultHandler.handleJiesuan({ success: true, aset: { banker: 0, call: 70, multiple: 1,
|
||
upgrade: -99, seatlist: [] } });
|
||
t.eq('投降结算入状态', S.result.aset.upgrade, -99);
|
||
t.eq('投降无 chupai', S.result.chupai, null);
|
||
t.eq('投降无 bottom', S.result.bottom, null);
|
||
t.eq('投降也发结算事件', evts.indexOf('EQW_ASET_RESULT') >= 0, true);
|
||
|
||
// ================= 末局:带 account =================
|
||
const ACCOUNT = [{ score: 12, grades: [6,6], grade_jf_total: 8, grade_cg_total: 4, grade_bw_total: 0 },
|
||
{ score: -6, grades: [-3,-3], grade_jf_total: -4, grade_cg_total: -2, grade_bw_total: 0 },
|
||
{ score: -6, grades: [-3,-3], grade_jf_total: -4, grade_cg_total: -2, grade_bw_total: 0 }];
|
||
S.reset(); evts.length = 0;
|
||
EQW_ResultHandler.handleJiesuan({ success: true, aset: ASET, account: ACCOUNT });
|
||
t.eq('大局结算入状态', S.result.account, ACCOUNT);
|
||
t.eq('末局发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') >= 0, true);
|
||
|
||
// ================= 解散:走 Free 入口,取值少一层 =================
|
||
S.reset(); evts.length = 0;
|
||
EQW_ResultHandler.handleFree({ rpc: 'jiesuan',
|
||
data: { success: true, aset: { banker: -1, call: -1, multiple: 0, upgrade: 0, seatlist: [] },
|
||
account: ACCOUNT } });
|
||
t.eq('解散取到 aset', S.result.aset.multiple, 0);
|
||
t.eq('解散取到 account', S.result.account, ACCOUNT);
|
||
t.eq('解散发大局结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') >= 0, true);
|
||
|
||
// ================= 解散:deskfree 为 null(首局发牌前解散)=================
|
||
S.reset(); evts.length = 0;
|
||
let boom = false;
|
||
try { EQW_ResultHandler.handleFree(null); } catch (e) { boom = true; }
|
||
t.eq('deskfree 为 null 不崩', boom, false);
|
||
t.eq('deskfree 为 null 不写状态', S.result.aset, null);
|
||
t.eq('deskfree 为 null 不发结算事件', evts.indexOf('EQW_ACCOUNT_RESULT') < 0, true);
|
||
|
||
// deskfree 存在但 data 缺失也要容忍
|
||
boom = false;
|
||
try { EQW_ResultHandler.handleFree({ rpc: 'jiesuan' }); } catch (e) { boom = true; }
|
||
t.eq('deskfree.data 缺失不崩', boom, false);
|
||
|
||
process.exit(t.done('handlers_result') ? 0 : 1);
|