--[[ Descripttion:房间 version: Author: Neo,Huang Date: 2022-07-05 17:32:01 LastEditors: Neo,Huang LastEditTime: 2022-07-05 20:29:29 --]] local code = require("code") local util_match = require("utils.util_match") local gameConst = require("const.gameConst") local nodeMgr = require("nodeMgr") local nodeUtil = require("utils.nodeUtil") local util_battle = require("utils.util_battle") local boxAdapt = require("adapt.boxAdapt") local bagData = require("data.bag") local battleData = require("data.battle") local root = {} -- 获取房间列表 function root:room_get_info(role, msg) local ret = { roomList = util_match:pack_room_info_list(), myRoom = util_match:pack_player_room_info(role.uid) } return code.OK, ret end -- 创建房间 function root:room_create_room(role, msg) local playCount = msg.playCount local battleBoxList = msg.battleBoxList local uid = role.uid -- 检查箱子 if not boxAdapt:battle_is_box_list_valid(battleBoxList) then return code.BATTLE.CREATE_BOX_VALID end -- 对战人数限制 local minPlayCount = boxAdapt:battle_const("min_play_count") or 2 local maxPlayCount = boxAdapt:battle_const("max_play_count") or 3 if playCount < minPlayCount or playCount > maxPlayCount then return code.BATTLE.CREATE_PLAY_COUNT_ERR end -- 消耗 local price = boxAdapt:battle_get_box_price(battleBoxList) local ok, costItems = bagData:is_enough(uid, {{id = gameConst.ITEM_ID.DIAMOND, count = price}}) if not ok then return code.BAG.ITEM_NOT_ENOUGH end -- 创建房间 local ok, roomId = util_match:create_room(uid, playCount, battleBoxList) if not ok then return code.PARAMTER_ERROR end -- 玩家绑定房间信息 - 且消耗道具 util_match:band_room(uid, roomId, costItems) -- 全服广播 local pack = { room = util_match:pack_room_info(roomId) } nodeMgr.broadcast_proto_notify("on_room_new", pack) local ret = { room = util_match:pack_room_info(roomId) } return code.OK, ret end -- 进入房间 function root:room_player_enter(role, msg) local uid = role.uid local roomId = msg.roomId if is_empty(roomId) then return code.PARAMTER_ERROR end -- 房间是否存在 local ok = util_match:is_room_exist(roomId) if not ok then -- 房间不存在 return code.BATTLE.ENTER_ROOM_NOT_EXIST end ok = util_match:enter_room(uid, roomId) if not ok then -- 进入房间失败 return code.BATTLE.ENTER_PLAYER_EXIST end -- 通知在线玩家 local pack = { type = 100, roomId = roomId, changeRoomPlayer = {util_match:pack_room_player_info(roomId, uid)} } nodeMgr.broadcast_proto_notify("on_room_player_change", pack) local ret = { room = util_match:pack_room_info(roomId) } return code.OK, ret end -- 坐下 function root:room_player_seat(role, msg) local uid = role.uid local roomId = msg.roomId local seatId = msg.seatId if is_empty(roomId) or is_empty(seatId) then return code.PARAMTER_ERROR end -- 避免数据竞争 nodeUtil:send_to_node("match", ".srvRoom", "seat_down", uid, roomId, seatId) return code.OK end -- 站起 function root:room_stand_up(role, msg) local uid = role.uid local roomId = battleData:get_room_id() -- 玩家未进入房间 if is_empty(roomId) then return code.BATTLE.STAND_NOT_ENTER_ROOM end -- 房间状态 local status = util_match:get_room_status(roomId) if status ~= 0 then return code.BATTLE.STAND_BATTLE_START end -- 房间是否存在 local ok = util_match:stand_up(uid, roomId) if not ok then -- 玩家未坐下 return code.BATTLE.STAND_NOT_SEAT_DOWN end -- 玩家解绑房间信息 - 且返还房费 util_match:unband_room(uid, "seat") -- 通知在线玩家 - 站起 local pack = { type = 103, roomId = roomId, changeRoomPlayer = {util_match:pack_room_player_info(roomId, uid)} } nodeMgr.broadcast_proto_notify("on_room_player_change", pack) return code.OK end -- 离开房间 function root:room_player_leave(role, msg) local uid = role.uid local roomId = battleData:get_room_id(uid) -- 玩家未进入房间 if is_empty(roomId) then return code.BATTLE.LEAVE_NOT_ENTER_ROOM end -- 房间状态 local status = util_match:get_room_status(roomId) if status > 0 then return code.BATTLE.LEAVE_BATTLE_START end -- 通知在线玩家 - 站起 local pack = { type = 101, roomId = roomId, changeRoomPlayer = {util_match:pack_room_player_info(roomId, uid)} } nodeMgr.broadcast_proto_notify("on_room_player_change", pack) util_match:leave(uid, roomId) -- 玩家解绑房间信息 - 且返还房费 util_match:unband_room(uid, "leave") return code.OK end -- 获取房间对战记录列表 - 每次请求返回20条 function root:room_get_record_list(role, msg) local lastTime = msg.lastTime local list = util_battle:get_record_list(lastTime) return code.OK, {list = list} end -- 获取玩家个人对战记录 - 每次请求返回20条 function root:room_get_player_record_list(role, msg) local lastTime = msg.lastTime local list = util_battle:get_player_record_list(role.uid, lastTime) return code.OK, {list = list} end -- 获取精彩对战记录列表 - 仅返回当前最近20(配置)条记录 function root:room_get_brilliant_record_list(role, msg) local list = util_battle:get_brilliant_record_list() return code.OK, {list = list} end return root