Files
erqiwang_youle/server/games/erqiwang/class.desk.js
T
joywayerandClaude Opus 4.8 60271175d6 二七王:逻辑文件补双运行时守卫,解锁 Node 单测
按 dev-guide 01 §1「一套代码,两个运行时」补齐 erqiwang 缺失的守卫(此前只支持友乐全局加载模型):
- 顶部:跨模块依赖走 `if (typeof require!=='undefined') var X=require('./class.X.js')`
  (config/pai/arith 无跨模块依赖;paiju 依赖 arith/config/pai;desk 依赖 paiju;export 依赖 arith/config/desk)
- 底部:`if (typeof module!=='undefined') module.exports = cls_X`
- export/import 的平台接线 `youle_erqiwang.X=...` 加 `typeof youle_erqiwang` 守卫,Node 无此全局时跳过

纯增量:友乐无 require(浏览器模型),守卫全部跳过、全局名仍无条件暴露,线上行为不变;
仅在 Node 下额外启用 require/module.exports,从而可用 node 直接单测。min_*/youle_erqiwang 等平台全局仍按全局名引用(Node 侧由测试 shim 提供)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 23:51:12 +08:00

196 lines
6.0 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.
///////////////////////////////////////////////////
////////// cls_youle_erqiwang_desk: 牌桌 //////////
///////////////////////////////////////////////////
//跨模块依赖:Node 走 require 守卫;友乐/浏览器由 min_loadJsFile 加载为同名全局(dev-guide 01 §1)
if (typeof require !== "undefined"){
var cls_youle_erqiwang_paiju = require("./class.paiju.js");
}
var cls_youle_erqiwang_desk = cls_youle_erqiwang_desk || {
countdown_jiaofen: 15, //叫分倒计时
countdown_xuanzhu: 20, //选主倒计时
countdown_maipai: 25, //埋牌倒计时
countdown_chupai: 30, //出牌倒计时
//创建牌桌对象
new: function(o_room){
var desk = {};
desk.o_room = o_room; //桌所属的房间对象
desk.seatlist = []; //玩家得分
desk.seatlist.push([0, []]); //第一位为累积得分,第二位为每局得分
desk.seatlist.push([0, []]);
desk.seatlist.push([0, []]);
desk.prepare = [0,0,0]; //玩家准备状态
desk.paiju_list = []; //牌局列表
//方法
desk.method = {};
//当前牌局
desk.method.curr_paiju = function(){
return desk.paiju_list[desk.paiju_list.length - 1];
}
//新牌局
desk.method.do_new_paiju = function(firstseat){
cls_youle_erqiwang_desk.do_new_paiju(desk, firstseat);
}
//叫分倒计时
desk.method.get_countdown_jiaofen = function(){
return cls_youle_erqiwang_desk.countdown_jiaofen;
}
//叫主倒计时
desk.method.get_countdown_xuanzhu = function(){
return cls_youle_erqiwang_desk.countdown_xuanzhu;
}
//埋牌倒计时
desk.method.get_countdown_maipai = function(){
return cls_youle_erqiwang_desk.countdown_maipai;
}
//出牌倒计时
desk.method.get_countdown_chupai = function(){
return cls_youle_erqiwang_desk.countdown_chupai;
}
//准备
desk.method.do_prepare = function(seat){
return cls_youle_erqiwang_desk.do_prepare(desk, seat);
}
//获取大局结算包
desk.method.get_desk_account = function(msg){
return cls_youle_erqiwang_desk.get_desk_account(desk, msg);
}
return desk;
},
//新开一局
do_new_paiju: function(o_desk, firstseat){
//恢复玩家准备状态
o_desk.prepare = [0,0,0];
if (o_desk.paiju_list.length > 0){
delete o_desk.paiju_list[o_desk.paiju_list.length - 1].tmp_jiesuan_aset;
}
//新开一局
cls_youle_erqiwang_paiju.new(o_desk, firstseat);
var msg = {};
msg.app = "youle";
msg.route = "erqiwang";
msg.rpc = "fapai";
msg.data = {};
msg.data.asetidx = o_desk.paiju_list.length;
msg.data.asetcount = o_desk.o_room.asetcount;
msg.data.seat = o_desk.method.curr_paiju().method.get_callgrade_seat();
msg.data.countdown = o_desk.method.get_countdown_jiaofen();
for (var i = 0; i < o_desk.o_room.seatlist.length; i++) {
msg.conmode = o_desk.o_room.seatlist[i].conmode;
msg.fromid = o_desk.o_room.seatlist[i].fromid;
msg.data.cards = o_desk.method.curr_paiju().method.get_seat_cards(i);
youle_erqiwang.app.SendPack(msg);
}
},
//准备
do_prepare: function(o_desk, seat){
o_desk.prepare[seat] = 1;
if (o_desk.prepare[0] && o_desk.prepare[1] && o_desk.prepare[2]){
//新开一局
var paiju = o_desk.method.curr_paiju();
var firstseat = paiju.banker;
if (paiju.result == 1 || paiju.result == 2){
firstseat = (firstseat + 1) % 3;
}
cls_youle_erqiwang_desk.do_new_paiju(o_desk, firstseat);
} else {
var msg = {};
msg.app = "youle";
msg.route = "erqiwang";
msg.rpc = "zhunbei";
msg.data = {};
msg.data.seat = seat;
o_desk.o_room.method.sendpack_toother(msg, -1);
}
},
//大局结算包
get_desk_account: function(o_desk, msg){
//保存战绩
var do_save_grade = function(){
var o_gameinfo1 = {};
o_gameinfo1.roomcode = o_desk.o_room.roomcode;
o_gameinfo1.asetcount = o_desk.paiju_list.length;
o_gameinfo1.createtime = o_desk.o_room.createtime;
o_gameinfo1.makewartime = o_desk.o_room.makewartime;
o_gameinfo1.players = [];
for (var i = 0; i < o_desk.o_room.seatlist.length; i++){
var _player = {};
_player.seat = i;
_player.playerid = o_desk.o_room.seatlist[i].playerid;
_player.name = o_desk.o_room.seatlist[i].nickname;
_player.avatar = o_desk.o_room.seatlist[i].avatar;
_player.score = o_desk.seatlist[i][0];
o_gameinfo1.players.push(_player);
}
var o_gameinfo2 = [];
for (var i = 0; i < o_desk.paiju_list.length; i++) {
var _paiju = {};
_paiju.starttime = o_desk.paiju_list[i].starttime;
_paiju.endtime = o_desk.paiju_list[i].endtime;
_paiju.seatlist = [0, 0, 0];
_paiju.seatlist[0] = o_desk.seatlist[0][1][i];
_paiju.seatlist[1] = o_desk.seatlist[1][1][i];
_paiju.seatlist[2] = o_desk.seatlist[2][1][i];
_paiju.callproc = o_desk.paiju_list[i].callproc;
_paiju.banker = o_desk.paiju_list[i].banker;
_paiju.call = o_desk.paiju_list[i].call;
_paiju.flower = o_desk.paiju_list[i].flower;
_paiju.result = o_desk.paiju_list[i].result;
//数据量太多,json转数组后进行存储
_paiju.cards = [];
for (var j = 0; j < o_desk.paiju_list[i].cards.length; j++) {
var _pai = o_desk.paiju_list[i].cards[j];
var _card = [];
_card.push(_pai.id);
_card.push(_pai.flower);
_card.push(_pai.number);
_card.push(_pai.score);
_card.push(_pai.dealowner);
_card.push(_pai.playround);
_card.push(_pai.playindex);
_card.push(_pai.playowner);
_paiju.cards.push(_card);
}
o_gameinfo2.push(_paiju);
}
//累积游戏得分
for (var i = 0; i < o_desk.o_room.seatlist.length; i++) {
o_desk.o_room.seatlist[i].gameinfo.grade = o_desk.seatlist[i][0];
}
//保存战绩
youle_erqiwang.import.save_grade(o_desk.o_room, o_gameinfo1, o_gameinfo2, 1);
}
min_ontimeout(do_save_grade, 1000);
msg.data.account = o_desk.seatlist;
return msg;
}
}
//Node 导出;友乐/浏览器无 module 时跳过(dev-guide 01 §1)。SendPack/youle_erqiwang.* 为平台全局
if (typeof module !== "undefined"){
module.exports = cls_youle_erqiwang_desk;
}