From 38b360f041e0e39e46328296aba53d78e16c1607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E5=A6=96=E6=A2=A6=E5=8E=A8?= <12796194+youmuKon-supreme@user.noreply.gitee.com> Date: Sat, 30 Nov 2024 03:41:09 +0800 Subject: [PATCH 1/2] setCurrent --- lua/client/client.lua | 6 ++++++ lua/core/room/abstract_room.lua | 6 ++++++ lua/server/events/gameflow.lua | 2 +- lua/server/gamelogic.lua | 4 ++-- lua/server/room.lua | 8 ++++++++ lua/server/serverplayer.lua | 4 ++-- standard/init.lua | 2 +- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lua/client/client.lua b/lua/client/client.lua index 1a37f9a..0473f00 100644 --- a/lua/client/client.lua +++ b/lua/client/client.lua @@ -981,6 +981,12 @@ fk.client_callback["SetBanner"] = function(self, data) end end +fk.client_callback["SetCurrent"] = function(self, data) + -- jsonData: [ int id ] + local playerId = data[1] + self:setCurrent(self:getPlayerById(playerId)) +end + fk.client_callback["SetCardMark"] = function(self, data) -- jsonData: [ int id, string mark, int value ] local card, mark, value = data[1], data[2], data[3] diff --git a/lua/core/room/abstract_room.lua b/lua/core/room/abstract_room.lua index 22292fa..696fd86 100644 --- a/lua/core/room/abstract_room.lua +++ b/lua/core/room/abstract_room.lua @@ -59,6 +59,12 @@ function AbstractRoom:getBanner(name) return self.banners[name] end +--- 设置房间的当前行动者 +---@param player Player +function AbstractRoom:setCurrent(player) + self.current = player +end + function AbstractRoom:toJsonObject() local card_manager = CardManager.toJsonObject(self) diff --git a/lua/server/events/gameflow.lua b/lua/server/events/gameflow.lua index 1324cbb..1903bea 100644 --- a/lua/server/events/gameflow.lua +++ b/lua/server/events/gameflow.lua @@ -114,7 +114,7 @@ function Round:action() if room.current.seat > nextTurnOwner.seat and not changingData.skipRoundPlus then break else - room.current = nextTurnOwner + room:setCurrent(nextTurnOwner) end end end diff --git a/lua/server/gamelogic.lua b/lua/server/gamelogic.lua index fd9c3ca..707e67e 100644 --- a/lua/server/gamelogic.lua +++ b/lua/server/gamelogic.lua @@ -105,7 +105,7 @@ function GameLogic:chooseGenerals() local lord_generals = {} if lord ~= nil then - room.current = lord + room:setCurrent(lord) local generals = room:getNGenerals(generalNum) lord_generals = room:askForGeneral(lord, generals, n) local lord_general, deputy @@ -265,7 +265,7 @@ function GameLogic:action() execGameEvent(GameEvent.Round) if room.game_finished then break end if table.every(room.players, function(p) return p.dead and p.rest == 0 end) then room:gameOver("") end - room.current = room.players[1] + room:setCurrent(room.players[1]) end end diff --git a/lua/server/room.lua b/lua/server/room.lua index 42ff5e3..37dd552 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -481,6 +481,14 @@ function Room:setBanner(name, value) self:doBroadcastNotify("SetBanner", json.encode{ name, value }) end +--- 设置房间的当前行动者 +---@param player ServerPlayer +function Room:setCurrent(player) + AbstractRoom.setCurrent(self, player) + -- rawset(self, "current", player) + self:doBroadcastNotify("SetCurrent", json.encode{ player and player.id or nil }) +end + ---@param player ServerPlayer ---@param general string ---@param changeKingdom? boolean diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index dec1e1e..d147fbf 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -403,7 +403,7 @@ function ServerPlayer:gainAnExtraTurn(delay, skillName, turnData) } local current = room.current - room.current = self + room:setCurrent(self) room:addTableMark(self, "_extra_turn_count", skillName) @@ -415,7 +415,7 @@ function ServerPlayer:gainAnExtraTurn(delay, skillName, turnData) room:setPlayerMark(self, "_extra_turn_count", mark) end - room.current = current + room:setCurrent(current) end --- 当前是否处于额外的回合。 diff --git a/standard/init.lua b/standard/init.lua index 29fb2e4..ec78651 100644 --- a/standard/init.lua +++ b/standard/init.lua @@ -1131,7 +1131,7 @@ local role_getlogic = function() local lord_num = 3 if lord ~= nil then - room.current = lord + room:setCurrent(lord) local a1 = #room.general_pile local a2 = #room.players * generalNum if a1 < a2 then -- Gitee From 3e499a4f72688aee57ba74b258779c53eb984700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E5=A6=96=E6=A2=A6=E5=8E=A8?= <12796194+youmuKon-supreme@user.noreply.gitee.com> Date: Sat, 30 Nov 2024 03:52:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/core/room/abstract_room.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/core/room/abstract_room.lua b/lua/core/room/abstract_room.lua index 696fd86..32115f4 100644 --- a/lua/core/room/abstract_room.lua +++ b/lua/core/room/abstract_room.lua @@ -76,6 +76,7 @@ function AbstractRoom:toJsonObject() return { card_manager = card_manager, circle = table.map(self.players, Util.IdMapper), + current = self.current, banners = self.banners, timeout = self.timeout, settings = self.settings, @@ -88,6 +89,7 @@ function AbstractRoom:loadJsonObject(o) CardManager.loadJsonObject(self, o.card_manager) -- 需要上层(目前是Client)自己根据circle添加玩家 + self.current = o.current self.banners = o.banners self.timeout = o.timeout self.settings = o.settings -- Gitee