diff --git a/lua/client/client.lua b/lua/client/client.lua index dbbd2d9d65dea0171ab7817e7db232096a19afd7..7137e90c870c1bd76b26419d613227914708bd3b 100644 --- a/lua/client/client.lua +++ b/lua/client/client.lua @@ -137,9 +137,11 @@ function Client:moveCards(moves) pcardMax = self:getPlayerById(move.to):getMaxCards(), id = move.to, }) - if (not Self:isBuddy(self:getPlayerById(move.to)) and move.toArea == Card.PlayerHand) or table.contains(ids, -1) then - ids = table.map(ids, function() return -1 end) + if (move.toArea == Card.PlayerHand and not Self:isBuddy(self:getPlayerById(move.to))) or + (move.toArea == Card.PlayerSpecial and not move.moveVisible) then + ids = {-1} end + self:getPlayerById(move.to):addCards(move.toArea, ids, move.specialName) elseif move.toArea == Card.DiscardPile then table.insert(self.discard_pile, move.ids[1]) @@ -474,7 +476,32 @@ end ---@param moves CardsMoveStruct[] local function separateMoves(moves) local ret = {} ---@type CardsMoveInfo[] + + local function containArea(area, relevant, defaultVisible) --处理区的处理? + local areas = relevant + and {Card.PlayerEquip, Card.PlayerJudge, Card.PlayerHand} + or {Card.PlayerEquip, Card.PlayerJudge} + return table.contains(areas, area) or (defaultVisible and table.contains({Card.Processing, Card.DiscardPile}, area)) + end + for _, move in ipairs(moves) do + local singleVisible = move.moveVisible + if move.visiblePlayers and not singleVisible then + local visiblePlayers = move.visiblePlayers + if type(visiblePlayers) == "number" then + if Self:isBuddy(visiblePlayers) then + singleVisible = true + end + elseif type(visiblePlayers) == "table" then + if table.find(visiblePlayers, function(pid) return Self:isBuddy(pid) end) then + singleVisible = true + end + end + end + if not singleVisible then + singleVisible = containArea(move.toArea, move.to and Self:isBuddy(move.to), move.moveVisible == nil) + end + for _, info in ipairs(move.moveInfo) do table.insert(ret, { ids = {info.cardId}, @@ -486,6 +513,7 @@ local function separateMoves(moves) specialName = move.specialName, fromSpecialName = info.fromSpecialName, proposer = move.proposer, + moveVisible = singleVisible or containArea(info.fromArea, move.from and Self:isBuddy(move.from), move.moveVisible == nil) }) end end @@ -513,7 +541,7 @@ local function mergeMoves(moves) proposer = move.proposer, } end - table.insert(temp[info].ids, move.ids[1]) + table.insert(temp[info].ids, move.moveVisible and move.ids[1] or -1) end for _, v in pairs(temp) do table.insert(ret, v) diff --git a/lua/core/player.lua b/lua/core/player.lua index aaedad1ac18de0d31841dc9791423c26980e9542..5db1ea3022b632e532a7217cf26d7b8b8939b898 100644 --- a/lua/core/player.lua +++ b/lua/core/player.lua @@ -260,13 +260,7 @@ function Player:removeCards(playerArea, cardIds, specialName) if #fromAreaIds == 0 then break end - - if table.contains(fromAreaIds, id) then - table.removeOne(fromAreaIds, id) - -- FIXME: 为客户端移动id为-1的牌考虑,但总感觉有地方需要商讨啊! - elseif table.every(fromAreaIds, function(e) return e == -1 end) then - table.remove(fromAreaIds, 1) - elseif id == -1 then + if not table.removeOne(fromAreaIds, id) and not table.removeOne(fromAreaIds, -1) then table.remove(fromAreaIds, 1) end end diff --git a/lua/server/room.lua b/lua/server/room.lua index c760fcfcbcb8aaa1a2b1a433ff3dca6806105ef7..7d28b34715131b1fdbe02062dbfc756381b8d604 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -948,37 +948,6 @@ function Room:notifyMoveCards(players, card_moves, forceVisible) end end - local function containArea(area, relevant, defaultVisible) --处理区的处理? - local areas = relevant - and {Card.PlayerEquip, Card.PlayerJudge, Card.PlayerHand, Card.PlayerSpecial} - or {Card.PlayerEquip, Card.PlayerJudge} - return table.contains(areas, area) or (defaultVisible and table.contains({Card.Processing, Card.DiscardPile}, area)) - end - - -- forceVisible make the move visible - -- if move is relevant to player's hands or equips, it should be open - -- cards move from/to equip/judge/discard/processing should be open - - local singleVisible = move.moveVisible or forceVisible - if move.visiblePlayers and not singleVisible then - local visiblePlayers = move.visiblePlayers - if type(visiblePlayers) == "number" then - if p:isBuddy(visiblePlayers) then - singleVisible = true - end - elseif type(visiblePlayers) == "table" then - if table.find(visiblePlayers, function(pid) return p:isBuddy(pid) end) then - singleVisible = true - end - end - end - if not (singleVisible or containArea(move.toArea, move.to and p:isBuddy(move.to), move.moveVisible == nil)) then - for _, info in ipairs(move.moveInfo) do - if not containArea(info.fromArea, move.from and p:isBuddy(move.from), move.moveVisible == nil) then - info.cardId = -1 - end - end - end end p:doNotify("MoveCards", json.encode(arg)) end @@ -3147,34 +3116,18 @@ end --- 让一名玩家获得一张牌 ---@param player integer|ServerPlayer @ 要拿牌的玩家 ----@param cid integer|Card|integer[] @ 要拿到的卡牌 +---@param card integer|integer[]|Card|Card[] @ 要拿到的卡牌 ---@param unhide? boolean @ 是否明着拿 ---@param reason? CardMoveReason @ 卡牌移动的原因 ---@param proposer? integer @ 移动操作者的id -function Room:obtainCard(player, cid, unhide, reason, proposer) - if type(cid) ~= "number" then - assert(cid and type(cid) == "table") - if cid[1] == nil then - cid = cid:isVirtual() and cid.subcards or {cid.id} - end - else - cid = {cid} - end - if #cid == 0 then return end - - if type(player) == "table" then - player = player.id +---@param skill_name? string @ 技能名 +---@param moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值} +---@param visiblePlayers? integer|integer[] @ 控制移动对特定角色可见(在moveVisible为false时生效) +function Room:obtainCard(player, card, unhide, reason, proposer, skill_name, moveMark, visiblePlayers) + if type(player) == "number" then + player = self:getPlayerById(player) end - - self:moveCards({ - ids = cid, - from = self.owner_map[cid[1]], - to = player, - toArea = Card.PlayerHand, - moveReason = reason or fk.ReasonJustMove, - proposer = proposer or player, - moveVisible = unhide or false, - }) + self:moveCardTo(card, Card.PlayerHand, player, reason, skill_name, nil, unhide, proposer or player.id, moveMark, visiblePlayers) end --- 让玩家摸牌 diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index 2f1fdea02423b8b5fcf388434d52832d31e2b854..28f5bd43b0374b11cf9a1d3e32888e7aa0d92200 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -588,12 +588,14 @@ function ServerPlayer:drawCards(num, skillName, fromPlace, moveMark) end ---@param pile_name string ----@param card integer|Card +---@param card integer | integer[] | Card | Card[] ---@param visible? boolean ---@param skillName? string -function ServerPlayer:addToPile(pile_name, card, visible, skillName) - local room = self.room - room:moveCardTo(card, Card.PlayerSpecial, self, fk.ReasonJustMove, skillName, pile_name, visible, self.id) +---@param proposer? integer +---@param visiblePlayers? integer | integer[] +function ServerPlayer:addToPile(pile_name, card, visible, skillName, proposer, visiblePlayers) + self.room:moveCardTo(card, Card.PlayerSpecial, self, fk.ReasonJustMove, skillName, pile_name, visible, + proposer or self.id, nil, visiblePlayers or self.id) end function ServerPlayer:bury() diff --git a/standard/i18n/zh_CN.lua b/standard/i18n/zh_CN.lua index b633733ce6d830f1e0f94f0f53f0ce132ff9a735..495763164422f7255c5bc08a523e9e94c608ed5a 100644 --- a/standard/i18n/zh_CN.lua +++ b/standard/i18n/zh_CN.lua @@ -246,7 +246,7 @@ Fk:loadTranslationTable{ ["$lianying1"] = "牌不是万能的,但是没牌是万万不能的。", ["$lianying2"] = "旧的不去,新的不来。", ["lianying"] = "连营", - [":lianying"] = "当你失去最后的手牌后,你可以摸一张牌。", + [":lianying"] = "当你失去手牌后,若你没有手牌,你可以摸一张牌。", ["sunshangxiang"] = "孙尚香", ["#sunshangxiang"] = "弓腰姬",