Files
youlegames/codes/games/server/youle/server_room/class.game.js
2026-02-04 23:47:45 +08:00

194 lines
5.5 KiB
JavaScript

///////////////////////////////////////////////////
////////// cls_youle_room_game: 游戏 //////////
///////////////////////////////////////////////////
var cls_youle_room_game = cls_youle_room_game || {
//构造函数
new: function(o_agent, gameid, gameidx, gamename, seatcount, makewar, modename, roomserver, tcpport, httpport, minroomcode, maxroomcode){
var game = {};
//基本信息
game.o_agent = o_agent; //代理商
game.gameid = gameid; //游戏id
game.idx = gameidx; //游戏的数组下标
game.gamename = gamename; //游戏名称
game.seatcount = seatcount; //房间内的座位数量
game.makewar = makewar; //达成开战条件的人数
game.modename = modename; //游戏服务器模块名称
game.roomserver = roomserver; //房间服务器地址
game.tcpport = tcpport; //房间服务器tcp端口
game.httpport = httpport; //房间服务器http端口
game.minroomcode = minroomcode; //房间服务器最小房号
game.maxroomcode = maxroomcode; //房间服务器最大房号
//房间列表
game.rooms = [];
game.rooms.length = maxroomcode - minroomcode + 1;
//方法
game.method = {};
//创建房间
game.method.create_room = function(roomcode, roomtype, needroomcard, asetcount){
return cls_youle_room_game.create_room(game, roomcode, roomtype, needroomcard, asetcount);
}
//查找房间
game.method.find_room = function(roomcode){
return cls_youle_room_game.find_room(game, roomcode);
}
//释放房间
game.method.free_room = function(o_room){
cls_youle_room_game.free_room(game, o_room);
}
//调试状态
game.method.isdebugger = function(){
return cls_youle_room_game.isdebugger(game);
}
return game;
},
//创建房间
create_room: function(o_game, roomcode, roomtype, needroomcard, asetcount){
//判断房号是否在范围内
if (roomcode < o_game.minroomcode || roomcode > o_game.maxroomcode){
return null;
}
//判断房间是否已经存在
var idx = cls_youle_room_game.aryidx_room(o_game, roomcode);
if (o_game.rooms[idx]){
return null;
}
var o_room = cls_youle_room_room.new(o_game, roomcode, roomtype, needroomcard, asetcount);
o_game.rooms[idx] = o_room;
return o_room;
},
//查找房间
find_room: function(o_game, roomcode){
var idx = cls_youle_room_game.aryidx_room(o_game, roomcode);
if (o_game.rooms.length <= idx) {
return null;
}
return o_game.rooms[idx];
},
//释放房间
free_room: function(o_game, o_room){
var idx = cls_youle_room_game.aryidx_room(o_game, o_room.roomcode);
//更新tcp连接列表
var o_room = o_game.rooms[idx];
if (o_room){
for (var i = 0; i < o_room.seatlist.length; i++) {
if (o_room.seatlist[i]) {
var o_player = o_room.seatlist[i];
if (o_player.conmode == "tcp"){
youle_room.tcps.method.delete_tcp(o_player.fromid, o_player);
}
}
}
try{
if (o_room.game){//针对牛牛写的
if (o_room.game.room){
o_room.game.room = null;
}
if (o_room.game.pList){
o_room.game.pList = null;
}
o_room.game = null;
}
if (o_room.o_desk){//通用
if (o_room.o_desk.o_room){
o_room.o_desk.o_room = null;
}
o_room.o_desk = null;
}
for (var i = 0; i < o_room.seatlist.length; i++) {
if (o_room.seatlist[i]){
o_room.seatlist[i].seat = null;
o_room.seatlist[i].cards = null;
o_room.seatlist[i].rubcard = null;
o_room.seatlist[i].putcard = null;
o_room.seatlist[i].scores = null;
o_room.seatlist[i].betScore = null;
o_room.seatlist[i].winScore = null;
o_room.seatlist[i].isJoin = null;
o_room.seatlist[i].isBet = null;
o_room.seatlist[i].isAuto = null;
o_room.seatlist[i].auto = null;
o_room.seatlist[i] = null;
}
}
}
catch(e){}
if (o_room.freetimer){
min_closetime(o_room.freetimer);
o_room.freetimer = null;
}
if (o_room.freetimer24){
min_closetime(o_room.freetimer24);
o_room.freetimer24 = null;
}
if (o_room.timer_robot){
min_closetime(o_room.timer_robot);
o_room.timer_robot = null;
}
if (o_room.timer_robot_active){
min_closetime(o_room.timer_robot_active);
o_room.timer_robot_active = null;
}
if (o_room.timer_robot_passive){
for (var i = 0; i < o_room.timer_robot_passive.length; i++) {
min_closetime(o_room.timer_robot_passive[i]);
}
o_room.timer_robot_passive = [];
}
}
o_game.rooms[idx] = null;
//固定房号的房间需要自动再次创建
if (o_room.advanced_type){
var msg = {};
msg.app = youle_room.app.appname;
msg.route = youle_room.app.youle_agent.routename;
msg.rpc = "advanced_createroom_roomcode";
msg.data = {};
msg.data.agentid = o_room.o_game.o_agent.agentid;
msg.data.playerid = o_room.owner.playerid;
msg.data.gameid = o_room.o_game.gameid;
msg.data.roomcode = o_room.roomcode;
msg.data.shortcode = o_room.shortcode;
//msg.data.rebateType = o_room.rebateType;
youle_room.app.youle_agent[msg.rpc](msg);
}else{
//非vip房且有需要更新的roomtype自动创建
}
},
//调试状态
isdebugger: function(o_game){
var o_cfg = youle_room.app.youle_platform.config;
var re = o_cfg.method.get_paravalue("isdebugger", o_game.o_agent.agentid, o_game.gameid);
if (!re){
return 0; //正式
} else {
return 1; //调试
}
},
//计算房间的数组下标
aryidx_room: function(o_game, roomcode){
return roomcode - o_game.minroomcode;
}
}