From edf10893e938f855484dbcf1ef8df5d3486b209e Mon Sep 17 00:00:00 2001 From: YoumuKon <38815081+YoumuKon@users.noreply.github.com> Date: Fri, 27 Oct 2023 22:19:30 +0800 Subject: [PATCH] bug fix (#277) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 堆一堆 - 更改了许褚台词 - 让lua认为prompt可以是string - 修改魄袭框,添加extra_data和cancelable - 修复GetNcards的洗牌判定逻辑 - 为聊天添加300字符限制 --- Fk/Common/ChatBox.qml | 1 + Fk/Pages/RoomLogic.js | 4 ++- Fk/RoomElement/PoxiBox.qml | 44 +++++++++++++++++++++++--------- lua/client/client_util.lua | 8 +++--- lua/core/util.lua | 1 + lua/fk_ex.lua | 14 +++++----- lua/server/room.lua | 22 +++++++++------- packages/standard/i18n/zh_CN.lua | 2 +- packages/test/init.lua | 8 +++--- src/server/room.cpp | 2 ++ 10 files changed, 68 insertions(+), 38 deletions(-) diff --git a/Fk/Common/ChatBox.qml b/Fk/Common/ChatBox.qml index 0a3dd829..43cdb081 100644 --- a/Fk/Common/ChatBox.qml +++ b/Fk/Common/ChatBox.qml @@ -114,6 +114,7 @@ Rectangle { color: "white" clip: true font.pixelSize: 14 + maximumLength: 300 onAccepted: { if (text != "") { diff --git a/Fk/Pages/RoomLogic.js b/Fk/Pages/RoomLogic.js index 03c32b55..2ba7fc21 100644 --- a/Fk/Pages/RoomLogic.js +++ b/Fk/Pages/RoomLogic.js @@ -1071,13 +1071,15 @@ callbacks["AskForCardsChosen"] = (jsonData) => { } callbacks["AskForPoxi"] = (jsonData) => { - const { type, data } = JSON.parse(jsonData); + const { type, data, extra_data, cancelable } = JSON.parse(jsonData); roomScene.state = "replying"; roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PoxiBox.qml"); const box = roomScene.popupBox.item; box.poxi_type = type; box.card_data = data; + box.extra_data = extra_data; + box.cancelable = cancelable; for (let d of data) { const arr = []; const ids = d[1]; diff --git a/Fk/RoomElement/PoxiBox.qml b/Fk/RoomElement/PoxiBox.qml index 1f30c8c1..f3c6ab30 100644 --- a/Fk/RoomElement/PoxiBox.qml +++ b/Fk/RoomElement/PoxiBox.qml @@ -11,13 +11,15 @@ GraphicsBox { // TODO: Adjust the UI design in case there are more than 7 cards width: 70 + 700 - height: 64 + Math.min(cardView.contentHeight, 400) + 20 + height: 64 + Math.min(cardView.contentHeight, 400) + 30 signal cardSelected(int cid) signal cardsSelected(var ids) property var selected_ids: [] property string poxi_type property var card_data + property bool cancelable: true + property var extra_data ListModel { id: cardModel @@ -29,14 +31,14 @@ GraphicsBox { anchors.topMargin: 40 anchors.leftMargin: 20 anchors.rightMargin: 20 - anchors.bottomMargin: 20 + anchors.bottomMargin: 30 spacing: 20 model: cardModel clip: true delegate: RowLayout { spacing: 15 - visible: areaCards.count > 0 + // visible: areaCards.count > 0 Rectangle { border.color: "#A6967A" @@ -72,7 +74,7 @@ GraphicsBox { selectable: { return root.selected_ids.includes(model.cid) || JSON.parse(Backend.callLuaFunction( "PoxiFilter", - [root.poxi_type, model.cid, root.selected_ids, root.card_data] + [root.poxi_type, model.cid, root.selected_ids, root.card_data, root.extra_data] )); } onSelectedChanged: { @@ -91,18 +93,36 @@ GraphicsBox { } } - MetroButton { + Row { + anchors.margins: 8 anchors.bottom: parent.bottom - text: Backend.translate("OK") - enabled: { - return JSON.parse(Backend.callLuaFunction( - "PoxiFeasible", - [root.poxi_type, root.selected_ids, root.card_data] - )); + anchors.horizontalCenter: parent.horizontalCenter + spacing: 32 + + MetroButton { + width: 120 + height: 35 + text: Backend.translate("OK") + enabled: { + return JSON.parse(Backend.callLuaFunction( + "PoxiFeasible", + [root.poxi_type, root.selected_ids, root.card_data, root.extra_data] + )); + } + onClicked: root.cardsSelected(root.selected_ids) } - onClicked: root.cardsSelected(root.selected_ids) + + MetroButton { + width: 120 + height: 35 + text: Backend.translate("Cancel") + enabled: root.cancelable + onClicked: root.cardsSelected([]) + } + } + onCardSelected: finished(); function findAreaModel(name) { diff --git a/lua/client/client_util.lua b/lua/client/client_util.lua index e84e7281..abd12a3f 100644 --- a/lua/client/client_util.lua +++ b/lua/client/client_util.lua @@ -722,16 +722,16 @@ function PoxiPrompt(poxi_type, data) return poxi.prompt(data) end -function PoxiFilter(poxi_type, to_select, selected, data) +function PoxiFilter(poxi_type, to_select, selected, data, extra_data) local poxi = Fk.poxi_methods[poxi_type] if not poxi then return "false" end - return json.encode(poxi.card_filter(to_select, selected, data)) + return json.encode(poxi.card_filter(to_select, selected, data, extra_data)) end -function PoxiFeasible(poxi_type, selected, data) +function PoxiFeasible(poxi_type, selected, data, extra_data) local poxi = Fk.poxi_methods[poxi_type] if not poxi then return "false" end - return json.encode(poxi.feasible(selected, data)) + return json.encode(poxi.feasible(selected, data, extra_data)) end dofile "lua/client/i18n/init.lua" diff --git a/lua/core/util.lua b/lua/core/util.lua index d994b1cc..d8705596 100644 --- a/lua/core/util.lua +++ b/lua/core/util.lua @@ -126,6 +126,7 @@ end Util.NameMapper = function(e) return e.name end Util.Name2GeneralMapper = function(e) return Fk.generals[e] end Util.Name2SkillMapper = function(e) return Fk.skills[e] end +Util.TranslateMapper = function(str) return Fk:translate(str) end -- for card preset Util.GlobalCanUse = function(self, player, card) diff --git a/lua/fk_ex.lua b/lua/fk_ex.lua index 3a1bcf85..d1b41306 100644 --- a/lua/fk_ex.lua +++ b/lua/fk_ex.lua @@ -179,7 +179,7 @@ end ---@field public on_effect nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): bool ---@field public on_nullified nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): bool ---@field public mod_target_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], user: integer, card: Card, distance_limited: boolean): bool ----@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public prompt nil|string|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string ---@field public interaction any ---@param spec ActiveSkillSpec @@ -228,7 +228,7 @@ end ---@field public enabled_at_play nil|fun(self: ViewAsSkill, player: Player): bool ---@field public enabled_at_response nil|fun(self: ViewAsSkill, player: Player, response: boolean): bool ---@field public before_use nil|fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct) ----@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public prompt nil|string|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string ---@param spec ViewAsSkillSpec ---@return ViewAsSkill @@ -593,8 +593,8 @@ end ---@class PoxiSpec ---@field name string ----@field card_filter fun(to_select: int, selected: int[], data: any): bool ----@field feasible fun(selected: int[], data: any): bool ----@field post_select nil | fun(selected: int[], data: any): int[] ----@field default_choice nil | fun(data: any): int[] ----@field prompt nil | string | fun(data: any): string +---@field card_filter fun(to_select: int, selected: int[], data: any, extra_data: any): bool +---@field feasible fun(selected: int[], data: any, extra_data: any): bool +---@field post_select nil | fun(selected: int[], data: any, extra_data: any): int[] +---@field default_choice nil | fun(data: any, extra_data: any): int[] +---@field prompt nil | string | fun(data: any, extra_data: any): string diff --git a/lua/server/room.lua b/lua/server/room.lua index 83d50569..cb3d4055 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -439,15 +439,15 @@ end function Room:getNCards(num, from) from = from or "top" assert(from == "top" or from == "bottom") + if #self.draw_pile < num then + self:shuffleDrawPile() + if #self.draw_pile < num then + self:gameOver("") + end + end local cardIds = {} while num > 0 do - if #self.draw_pile < 1 then - self:shuffleDrawPile() - if #self.draw_pile < 1 then - self:gameOver("") - end - end local index = from == "top" and 1 or #self.draw_pile table.insert(cardIds, self.draw_pile[index]) @@ -1565,8 +1565,10 @@ end ---@param player ServerPlayer ---@param poxi_type string ---@param data any +---@param extra_data any +---@param cancelable nil|bool ---@return integer[] -function Room:askForPoxi(player, poxi_type, data) +function Room:askForPoxi(player, poxi_type, data, extra_data, cancelable) local poxi = Fk.poxi_methods[poxi_type] if not poxi then return {} end @@ -1575,12 +1577,14 @@ function Room:askForPoxi(player, poxi_type, data) local result = self:doRequest(player, command, json.encode { type = poxi_type, data = data, + extra_data = extra_data, + cancelable = (cancelable == nil) and true or cancelable }) if result == "" then - return poxi.default_choice(data) + return poxi.default_choice(data, extra_data) else - return poxi.post_select(json.decode(result), data) + return poxi.post_select(json.decode(result), data, extra_data) end end diff --git a/packages/standard/i18n/zh_CN.lua b/packages/standard/i18n/zh_CN.lua index 8d8d4cdd..2396f98a 100644 --- a/packages/standard/i18n/zh_CN.lua +++ b/packages/standard/i18n/zh_CN.lua @@ -52,7 +52,7 @@ Fk:loadTranslationTable{ ["xuchu"] = "许褚", ["~xuchu"] = "冷,好冷啊……", - ["$luoyi1"] = "破!", + ["$luoyi1"] = "脱!", ["$luoyi2"] = "谁来与我大战三百回合?", ["luoyi"] = "裸衣", [":luoyi"] = "摸牌阶段,你可以少摸一张牌,若如此做,本回合你使用【杀】或【决斗】对目标角色造成伤害时,此伤害+1。", diff --git a/packages/test/init.lua b/packages/test/init.lua index d0a1b3a0..5f599725 100644 --- a/packages/test/init.lua +++ b/packages/test/init.lua @@ -93,7 +93,7 @@ local control = fk.CreateActiveSkill{ -- p(room:askForPoxi(from, "test", { -- { "你自己", from:getCardIds "h" }, -- { "对方", to:getCardIds "h" }, - -- })) + -- }, from.hp, false)) -- room:setPlayerMark(from, "@$a", {1,2,3}) -- room:setPlayerMark(from, "@$b", {'slash','duel','axe'}) if to:getMark("mouxushengcontrolled") == 0 then @@ -133,15 +133,15 @@ local control = fk.CreateActiveSkill{ --[[ Fk:addPoxiMethod{ name = "test", - card_filter = function(to_select, selected, data) + card_filter = function(to_select, selected, data, extra_data) local s = Fk:getCardById(to_select).suit for _, id in ipairs(selected) do if Fk:getCardById(id).suit == s then return false end end return true end, - feasible = function(selected, data) - return #selected == 0 or #selected == 4 + feasible = function(selected, data, extra_data) + return #selected == 0 or #selected == 4 or #selected == extra_data end, prompt = "魄袭:选你们俩手牌总共四个花色,或者不选直接按确定按钮" } diff --git a/src/server/room.cpp b/src/server/room.cpp index c0409b63..3241336e 100644 --- a/src/server/room.cpp +++ b/src/server/room.cpp @@ -370,6 +370,8 @@ void Room::chat(ServerPlayer *sender, const QString &jsonData) { // 屏蔽.号,防止有人在HTML文本发链接,而正常发链接看不出来有啥改动 auto msg = doc["msg"].toString(); msg.replace(".", "․"); + // 300字限制,与客户端相同 + msg.erase(msg.begin() + 300, msg.end()); doc["msg"] = msg; if (!server->checkBanWord(msg)) { return;