220 lines
4.5 KiB
Lua
220 lines
4.5 KiB
Lua
-- 房间基本数据类
|
||
--author:--
|
||
|
||
StateType =
|
||
{
|
||
Ready = 0,
|
||
Palying = 1,
|
||
PalyingWait = 2
|
||
}
|
||
|
||
---房间数据对象
|
||
local Room = {
|
||
-- 房间ID
|
||
room_id = "",
|
||
-- 游戏ID
|
||
game_id = 0,
|
||
-- 服务器地址
|
||
server_host = "",
|
||
-- 玩家session
|
||
session = "",
|
||
-- 自己
|
||
self_player = nil,
|
||
-- 房主ID
|
||
owner_id = "",
|
||
-- 庄家座位号
|
||
banker_seat = 0,
|
||
-- 当前回合
|
||
curren_round = 0,
|
||
-- 当前转向的座位号
|
||
curren_turn_seat = 0,
|
||
|
||
-- 房间配置
|
||
room_config = nil,
|
||
|
||
-- 玩家列表
|
||
player_list = nil,
|
||
|
||
-- 游戏中
|
||
playing = false,
|
||
|
||
create_time = "",
|
||
|
||
group_id = 0,
|
||
-- 自己在当前房间所在圈子的职位,1盟主,2管理员,3用户,非圈子房间就是3
|
||
lev = 3,
|
||
-- 房间倍数
|
||
score_times = 1,
|
||
-- 体力值开关
|
||
hpOnOff = 0,
|
||
-- 牌友圈的游戏id
|
||
pid = 0,
|
||
|
||
-- 房间重连标记
|
||
reloading = false,
|
||
}
|
||
|
||
---
|
||
-- a RoomConfig
|
||
RoomConfig = {
|
||
-- 人数
|
||
people_num = 2,
|
||
-- 回合数
|
||
opt_round = 1,
|
||
}
|
||
|
||
---
|
||
-- @type Room
|
||
local M = Room
|
||
|
||
|
||
--- Create a new Room
|
||
function Room.new()
|
||
local self = {}
|
||
setmetatable(self, {__index = M})
|
||
self:init()
|
||
return self
|
||
end
|
||
|
||
function M:init()
|
||
self.player_list = {}
|
||
self.room_config ={}
|
||
end
|
||
|
||
-- 创建玩家
|
||
function M:NewPlayer()
|
||
return Player.new()
|
||
end
|
||
|
||
-- 添加玩家
|
||
function M:AddPlayer(player)
|
||
if (not player) then return end
|
||
for k , tem in ipairs(self.player_list) do
|
||
if(tem.self_user.account_id == player.self_user.account_id) then
|
||
-- tem = player
|
||
self.player_list[k] = player
|
||
return
|
||
end
|
||
end
|
||
self.player_list[#self.player_list+1] = player
|
||
|
||
|
||
end
|
||
|
||
-- 是否为不可负分房间
|
||
function M:checkHpNonnegative()
|
||
local isNonnegative = self.room_config.isNonnegative
|
||
if isNonnegative and isNonnegative == 1 then
|
||
return true
|
||
end
|
||
return false
|
||
end
|
||
|
||
|
||
-- 删除指定玩家
|
||
-- <param name="player"></param>
|
||
function M:RemovePlayer(player)
|
||
for i , _player in ipairs(self.player_list) do
|
||
if _player == player then
|
||
table.remove(self.player_list , i)
|
||
return
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
-- 获取指定玩家_userid
|
||
-- <param name="id"></param>
|
||
-- <returns></returns>
|
||
function M:GetPlayerById(id)
|
||
for _ , tem in pairs(self.player_list) do
|
||
if (tem.self_user.account_id == id) then
|
||
return tem
|
||
end
|
||
end
|
||
return nil;
|
||
end
|
||
|
||
|
||
-- 获取指定玩家_桌号
|
||
-- <param name="id"></param>
|
||
-- <returns></returns>
|
||
function M:GetPlayerBySeat(seat)
|
||
for _ , tem in ipairs(self.player_list) do
|
||
if (tem.seat == seat) then
|
||
return tem
|
||
end
|
||
end
|
||
return nil
|
||
end
|
||
|
||
-- 获取大结算显示的积分
|
||
function M:GetTotalScore(score)
|
||
if self.hpOnOff == 1 then
|
||
return d2ad(score)
|
||
else
|
||
return score
|
||
end
|
||
end
|
||
-- 获取乘倍数前的积分
|
||
function M:GetOriginScore(total_score)
|
||
if self.hpOnOff == 1 then
|
||
return total_score / self.score_times
|
||
else
|
||
return total_score
|
||
end
|
||
end
|
||
-- 设置房间重连状态
|
||
function M:SetReloadStatus(flag)
|
||
self.reloading = flag
|
||
end
|
||
-- 获取房间重连状态
|
||
function M:GetReloadStatus()
|
||
return self.reloading
|
||
end
|
||
|
||
--- Create a new RoomConfig
|
||
function RoomConfig:init(config)
|
||
--人数
|
||
self.people_num = config["maxPlayers"]
|
||
--支付类型
|
||
self.AA = config["AA"] == 1 and true or false
|
||
--托管
|
||
self.tuoguan = config["tuoguan"]
|
||
self.tuoguan_active_time = config["tuoguan_active_time"]
|
||
self.tuoguan_result_type = config["tuoguan_result_type"]
|
||
--不可负分
|
||
self.isNonnegative = config["isNonnegative"]
|
||
self.pid = config["pid"]
|
||
return self
|
||
end
|
||
|
||
local str_tuoguan = {"当局结算", "二局结算", "三局结算","满局结算"}
|
||
function RoomConfig:GetDes(sp, str_people_num)
|
||
local str = ""
|
||
if not str_people_num and self.people_num then
|
||
str = str .. self.people_num .. "人"
|
||
--str = str .. sp
|
||
end
|
||
-- if self.AA then
|
||
-- str = str .. "AA支付" .. sp
|
||
-- else
|
||
-- str = str .. "房主支付" .. sp
|
||
-- end
|
||
-- if self.isNonnegative == 1 then
|
||
-- str = str .. "不可负分" .. sp
|
||
-- end
|
||
if self.tuoguan then
|
||
str = str .. "托管" .. sp
|
||
str = str .. "离线" .. self.tuoguan_active_time .. "秒托管" .. sp
|
||
str = str .. str_tuoguan[self.tuoguan_result_type] .. sp
|
||
end
|
||
return str
|
||
end
|
||
|
||
function RoomConfig:GetGameName()
|
||
|
||
end
|
||
|
||
return M
|