diff --git a/lua/client/client_util.lua b/lua/client/client_util.lua index ffbcf4ed..a36ad385 100644 --- a/lua/client/client_util.lua +++ b/lua/client/client_util.lua @@ -444,6 +444,7 @@ Fk:loadTranslationTable{ [" thinking..."] = " 思考中...", ["AskForGeneral"] = "选择武将", + ["AskForGuanxiong"] = "观星", ["AskForChoice"] = "选择", ["PlayCard"] = "出牌", diff --git a/lua/core/engine.lua b/lua/core/engine.lua index 4b77c946..db7813ac 100644 --- a/lua/core/engine.lua +++ b/lua/core/engine.lua @@ -185,6 +185,9 @@ function Engine:getGeneralsRandomly(num, generalPool, except, filter) generalPool = generalPool or self.generals except = except or {} + for _, g in ipairs(self.packages["test_p_0"].generals) do + table.insert(except, g.name) + end local availableGenerals = {} for _, general in pairs(generalPool) do diff --git a/lua/core/util.lua b/lua/core/util.lua index b28c23d4..be0f6e96 100644 --- a/lua/core/util.lua +++ b/lua/core/util.lua @@ -66,6 +66,15 @@ function table.clone(self) return ret end +-- similar to table.clone but not recursively +function table.simpleClone(self) + local ret = {} + for k, v in pairs(self) do + ret[k] = v + end + return ret +end + -- if table does not contain the element, we insert it function table:insertIfNeed(element) if not table.contains(self, element) then diff --git a/lua/server/gamelogic.lua b/lua/server/gamelogic.lua index 9aaa106b..a7773a08 100644 --- a/lua/server/gamelogic.lua +++ b/lua/server/gamelogic.lua @@ -34,6 +34,7 @@ function GameLogic:run() self:chooseGenerals() self:prepareForStart() + self.room.game_started = true self:action() end diff --git a/lua/server/room.lua b/lua/server/room.lua index e2e8c782..af370497 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -4,6 +4,7 @@ ---@field alive_players ServerPlayer[] ---@field observers fk.ServerPlayer[] ---@field current ServerPlayer +---@field game_started boolean ---@field game_finished boolean ---@field timeout integer ---@field tag table @@ -80,6 +81,7 @@ function Room:initialize(_room) self.alive_players = {} self.observers = {} self.current = nil + self.game_started = false self.game_finished = false self.timeout = _room:getTimeout() self.tag = {} @@ -173,6 +175,9 @@ end ---@param sortBySeat boolean ---@return ServerPlayer[] function Room:getAllPlayers(sortBySeat) + if not self.game_started then + return { table.unpack(self.players) } + end if sortBySeat == nil or sortBySeat then local current = self.current local temp = current.next @@ -505,19 +510,28 @@ function Room:notifyMoveCards(players, card_moves, forceVisible) for _, move in ipairs(arg) do -- local to = self:getPlayerById(move.to) + local function infosContainArea(info, area) + for _, i in ipairs(info) do + if i.fromArea == area then + return true + end + end + return false + end + -- forceVisible make the move visible -- FIXME: move.moveInfo is an array, fix this move.moveVisible = (forceVisible) -- if move is relevant to player, it should be open or ((move.from == p.id) or (move.to == p.id and move.toArea ~= Card.PlayerSpecial)) -- cards move from/to equip/judge/discard/processing should be open - or move.moveInfo.fromArea == Card.PlayerEquip + or infosContainArea(move.moveInfo, Card.PlayerEquip) or move.toArea == Card.PlayerEquip - or move.moveInfo.fromArea == Card.PlayerJudge + or infosContainArea(move.moveInfo, Card.PlayerJudge) or move.toArea == Card.PlayerJudge - or move.moveInfo.fromArea == Card.DiscardPile + or infosContainArea(move.moveInfo, Card.DiscardPile) or move.toArea == Card.DiscardPile - or move.moveInfo.fromArea == Card.Processing + or infosContainArea(move.moveInfo, Card.Processing) or move.toArea == Card.Processing -- TODO: PlayerSpecial @@ -1413,7 +1427,7 @@ function Room:useCard(cardUseEvent) collaboratorsIndex[toId] = collaboratorsIndex[toId] + 1 - self:doCardEffect(cardEffectEvent) + self:doCardEffect(table.simpleClone(cardEffectEvent)) end end end @@ -2276,6 +2290,7 @@ function Room:shuffleDrawPile() end function Room:gameOver(winner) + self.game_started = false self.game_finished = true for _, p in ipairs(self.players) do diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index 02a085e9..38335186 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -93,6 +93,17 @@ end ---@param player ServerPlayer function ServerPlayer:marshal(player) local room = self.room + if not room.game_started then + -- If game does not starts, that mean we are entering room that + -- all players are choosing their generals. + -- Note that when we are in this function, the main thread must be + -- calling delay() or waiting for reply. + if self.role_shown then + room:notifyProperty(player, self, "role") + end + return + end + room:notifyProperty(player, self, "maxHp") room:notifyProperty(player, self, "hp") room:notifyProperty(player, self, "gender") @@ -165,7 +176,7 @@ function ServerPlayer:marshal(player) end for k, v in pairs(self.cardUsedHistory) do - player:doNotify("AddCardUseHistory", json.encode{k, v}) + player:doNotify("AddCardUseHistory", json.encode{k, v[1]}) end if self.role_shown then diff --git a/qml/Pages/RoomLogic.js b/qml/Pages/RoomLogic.js index e30a28e2..d5cee4fb 100644 --- a/qml/Pages/RoomLogic.js +++ b/qml/Pages/RoomLogic.js @@ -154,12 +154,13 @@ function getAreaItem(area, id) { if (area === Card.PlayerHand) { return photo.handcardArea; - } else if (area === Card.PlayerEquip) + } else if (area === Card.PlayerEquip) { return photo.equipArea; - else if (area === Card.PlayerJudge) + } else if (area === Card.PlayerJudge) { return photo.delayedTrickArea; - else if (area === Card.PlayerSpecial) + } else if (area === Card.PlayerSpecial) { return photo.specialArea; + } return null; }