2022-03-27 06:49:41 +00:00
|
|
|
local Room = class("Room")
|
2022-03-25 04:28:07 +00:00
|
|
|
|
2022-03-27 06:49:41 +00:00
|
|
|
function Room:initialize(_room)
|
|
|
|
self.room = _room
|
2022-03-28 14:24:30 +00:00
|
|
|
self.players = {} -- ServerPlayer[]
|
2022-03-27 06:49:41 +00:00
|
|
|
self.gameFinished = false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- When this function returns, the Room(C++) thread stopped.
|
|
|
|
function Room:run()
|
|
|
|
for _, p in freekill.qlist(self.room:getPlayers()) do
|
|
|
|
local player = ServerPlayer:new(p)
|
2022-03-28 14:24:30 +00:00
|
|
|
table.insert(self.players, player)
|
|
|
|
self.server.players[player:getId()] = player
|
2022-03-27 06:49:41 +00:00
|
|
|
end
|
2022-03-28 14:24:30 +00:00
|
|
|
|
|
|
|
self.logic = GameLogic:new(self)
|
|
|
|
self.logic:run()
|
2022-03-27 06:49:41 +00:00
|
|
|
end
|
2022-03-25 04:28:07 +00:00
|
|
|
|
2022-03-28 14:24:30 +00:00
|
|
|
function Room:broadcastProperty(player, property)
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
self:notifyProperty(p, player, property)
|
2022-03-27 06:49:41 +00:00
|
|
|
end
|
2022-03-25 04:28:07 +00:00
|
|
|
end
|
|
|
|
|
2022-03-28 14:24:30 +00:00
|
|
|
function Room:notifyProperty(p, player, property)
|
|
|
|
p:doNotify("PropertyUpdate", json.encode{
|
|
|
|
player:getId(),
|
|
|
|
property,
|
|
|
|
player[property],
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function Room:doBroadcastNotify(command, jsonData)
|
|
|
|
self.room:doBroadcastNotify(self.room:getPlayers(), command, jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Room:adjustSeats()
|
|
|
|
local players = {}
|
|
|
|
local p = 0
|
|
|
|
|
|
|
|
for i = 1, #self.players do
|
|
|
|
if self.players[i].role == "lord" then
|
|
|
|
p = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for j = p, #self.players do
|
|
|
|
table.insert(players, self.players[j])
|
|
|
|
end
|
|
|
|
for j = 1, p - 1 do
|
|
|
|
table.insert(players, self.players[j])
|
|
|
|
end
|
|
|
|
|
|
|
|
self.players = players
|
|
|
|
|
|
|
|
local player_circle = {}
|
|
|
|
for i = 1, #self.players do
|
|
|
|
self.players[i].seat = i
|
|
|
|
table.insert(player_circle, self.players[i]:getId())
|
|
|
|
end
|
|
|
|
|
|
|
|
self:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
|
|
|
|
end
|
|
|
|
|
2022-03-27 06:49:41 +00:00
|
|
|
function Room:gameOver()
|
|
|
|
self.gameFinished = true
|
|
|
|
-- dosomething
|
|
|
|
self.room:gameOver()
|
2022-03-25 04:28:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return Room
|