二七王:结算与解散 handler
三种结算来源组成不同(正常出牌 / 投降 / 解散),共用一套落地逻辑: 有哪组写哪组,缺的保持 null。 解散走平台的 Game_Modify.Free 入口而非收包分发表——它的 route 是 room, 被平台分流走了。取值路径因此比协议文档少一层,且参数可能为 null (首局发牌前解散),已覆盖。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
////////// EQW_ResultHandler: 结算(jiesuan)与解散(Free)///
|
||||
///////////////////////////////////////////////////////////////
|
||||
// 协议 §14:结算包由 chupai + bottom + aset 拼装,末局再加 account。
|
||||
// 三种来源的组成不同:
|
||||
// 正常出牌结算:chupai + bottom + aset(末局加 account)
|
||||
// 投降结算: 只有 aset(末局加 account),无 chupai、无 bottom
|
||||
// 解散结算: 只有 aset + account,且【走另一个入口】,见下
|
||||
//
|
||||
// 【解散的特殊性】(协议 §14.1,已对平台代码核实):
|
||||
// 解散包的 route 是平台的 "room",平台 12_Logic.js 按 route 分流时把它交给
|
||||
// Net[rpc] 而【不是】Game_Modify._ReceiveData——所以它根本进不了子游戏的分发表。
|
||||
// 平台另有专门入口:07_Desk.js 的 Game_Modify.Free(Desk.deskfree)。
|
||||
// 两个后果:
|
||||
// 1. 取值路径比协议文档少一层——平台已把 deskfree 取出来传进来,
|
||||
// 所以是 deskfree.data.aset,不是 data.deskfree.data.aset;
|
||||
// 2. 参数可能是 null——解散若发生在开战后、首局发牌前,服务端 get_disbandRoom
|
||||
// 返回 null,平台走「不带 deskfree」分支。这时只做房间收尾、不弹结算。
|
||||
var EQW_ResultHandler = EQW_ResultHandler || {
|
||||
|
||||
handleJiesuan: function (data) {
|
||||
if (!data.hasOwnProperty('aset')) {
|
||||
console.error('[EQW_ResultHandler] jiesuan 缺 aset,已跳过该包');
|
||||
return;
|
||||
}
|
||||
this._applyResult(data);
|
||||
},
|
||||
|
||||
//平台解散入口。deskfree = { rpc:"jiesuan", data:{ success, aset, account } },可能为 null
|
||||
handleFree: function (deskfree) {
|
||||
if (!deskfree || !deskfree.data) {
|
||||
//首局发牌前解散:没有结算数据,只做房间收尾,不弹结算面板
|
||||
console.warn('[EQW_ResultHandler] 解散包无 deskfree 数据(首局发牌前解散)');
|
||||
return;
|
||||
}
|
||||
var d = deskfree.data;
|
||||
if (!d.hasOwnProperty('aset')) {
|
||||
console.error('[EQW_ResultHandler] 解散包缺 aset,已跳过');
|
||||
return;
|
||||
}
|
||||
this._applyResult(d);
|
||||
},
|
||||
|
||||
//三种来源共用的落地逻辑:有哪组就写哪组,缺的保持 null
|
||||
_applyResult: function (d) {
|
||||
EQW_GameState._apply(EQW_GameState.result, d, {
|
||||
chupai: 'chupai',
|
||||
bottom: 'bottom',
|
||||
aset: 'aset',
|
||||
account: 'account'
|
||||
});
|
||||
EQW_GameState.aset.step = 6;
|
||||
|
||||
EventBus.emit(EQW_Events.EQW_ASET_RESULT);
|
||||
//account 只在末局或解散时才有
|
||||
if (d.hasOwnProperty('account')) {
|
||||
EventBus.emit(EQW_Events.EQW_ACCOUNT_RESULT);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
// 结算 / 解散 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);
|
||||
Reference in New Issue
Block a user