Files
youle_cocos/server/games/erqiwang/test/_rpc.js
T

57 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// L3 RPC 测试脚手架:装配 mod.js(含 RPC 方法),捕获下发包
require('./_shim');
// mod.js 的 RPC handler 按全局名引用这些类,先挂到 global
global.cls_youle_erqiwang_config = require('../class.config.js');
global.cls_youle_erqiwang_pai = require('../class.pai.js');
global.cls_youle_erqiwang_arith = require('../class.arith.js');
global.cls_youle_erqiwang_paiju = require('../class.paiju.js');
global.cls_youle_erqiwang_desk = require('../class.desk.js');
// mod.js 顶部依赖:cls_mod.new 造模块对象、min_loadJsFile 置为同步 no-op(类已单独 require)
global.cls_mod = { new: (name, route, app) => ({ modname: name, routename: route, app }) };
global.youle_app = {};
global.min_loadJsFile = (p, cb) => { if (cb) cb(); };
const mod = require('../mod.js'); // = youle_erqiwang,含 jiaofen/xuanzhu/.../mingpai/zhunbei
const clone = m => JSON.parse(JSON.stringify(m));
// 装配一局:给定 roomtype 与 o_paiju,返回 { sent, o_room },并把 check_player/SendPack/sendpack_toother
// 全部指向同一个 sent 数组(快照每个下发包,因 mod 会跨座位改删字段)
function setup(roomtype, o_paiju, seatlist) {
const sent = [];
const o_desk = {
paiju_list: [o_paiju],
o_room: null,
seatlist: [[0, [], 0, 0, 0], [0, [], 0, 0, 0], [0, [], 0, 0, 0]],
prepare: [0, 0, 0],
method: {
curr_paiju: () => o_paiju,
get_countdown_jiaofen: () => 15, get_countdown_xuanzhu: () => 20,
get_countdown_maipai: () => 25, get_countdown_chupai: () => 30,
do_prepare: () => { }, get_desk_account: m => m
}
};
const o_room = {
roomtype, asetcount: 6,
seatlist: seatlist || [{ conmode: 0, fromid: 0 }, { conmode: 0, fromid: 1 }, { conmode: 0, fromid: 2 }],
o_desk,
method: { sendpack_toother: m => sent.push(clone(m)) }
};
o_desk.o_room = o_room;
if (o_paiju) o_paiju.o_desk = o_desk;
mod.import = { check_player: () => o_room, deduct_roomcard: () => { }, save_grade: () => { } };
mod.app = { SendPack: m => sent.push(clone(m)) };
return { sent, o_room, o_desk };
}
// 构造 108 张牌(带 flower/number/dealowner/playround),供 get_seat_zhucards / get_seat_cards 用
function make108(deal) {
const A = global.cls_youle_erqiwang_arith;
const cards = [];
for (let i = 0; i < 108; i++) cards[i] = { id: i, dealowner: 1, playround: -1, playowner: -1, score: 0, flower: A.id_to_flower(i), number: A.id_to_number(i) };
if (deal) for (const [cid, owner] of deal) cards[cid].dealowner = owner;
return cards;
}
module.exports = { mod, setup, make108, id: (d, f, n) => (d - 1) * 54 + (f - 1) * 13 + (n - 1) };