From 620780ac088d2764e550055393f80ca27c92345f Mon Sep 17 00:00:00 2001 From: notify Date: Sun, 16 Jul 2023 15:32:16 +0800 Subject: [PATCH] bugfix (#225) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修双头武将的双将和头像 - 修客户端不知道别人阶段 - 修出牌高亮 - 修无懈响应不准 - 以&结尾的牌堆如手牌使用打出 --- Fk/LobbyElement/PersonalSettings.qml | 8 ++++---- Fk/Pages/RoomLogic.js | 7 +++++++ Fk/RoomElement/Dashboard.qml | 7 ++++++- Fk/RoomElement/Photo.qml | 21 ++++++++++++++++++--- Fk/skin-bank.js | 9 +++++++++ lua/core/player.lua | 12 ++++++++++++ lua/core/util.lua | 2 ++ lua/server/events/gameflow.lua | 2 +- lua/server/room.lua | 10 ++++++++++ lua/server/serverplayer.lua | 8 ++++---- 10 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Fk/LobbyElement/PersonalSettings.qml b/Fk/LobbyElement/PersonalSettings.qml index ea2b8fe6..523a96d1 100644 --- a/Fk/LobbyElement/PersonalSettings.qml +++ b/Fk/LobbyElement/PersonalSettings.qml @@ -23,10 +23,10 @@ Item { Image { Layout.preferredWidth: 64 Layout.preferredHeight: 64 - source: SkinBank.getGeneralPicture(Self.avatar) - sourceSize.width: 250 - sourceSize.height: 292 - sourceClipRect: Qt.rect(61, 0, 128, 128) + source: SkinBank.getGeneralExtraPic(Self.avatar, "avatar/") ?? SkinBank.getGeneralPicture(Self.avatar) + // sourceSize.width: 250 + // sourceSize.height: 292 + sourceClipRect: sourceSize.width > 200 ? Qt.rect(61, 0, 128, 128) : undefined Rectangle { anchors.fill: parent diff --git a/Fk/Pages/RoomLogic.js b/Fk/Pages/RoomLogic.js index 5303e6aa..b7f84964 100644 --- a/Fk/Pages/RoomLogic.js +++ b/Fk/Pages/RoomLogic.js @@ -661,6 +661,11 @@ callbacks["PropertyUpdate"] = (jsonData) => { if (typeof(model) !== "undefined") { model[property_name] = value; } + + if (property_name === "phase") { + let item = getPhoto(uid); + item.playing = value < 8; // Player.NotActive + } } callbacks["UpdateCard"] = (j) => { @@ -748,6 +753,7 @@ callbacks["MoveFocus"] = (jsonData) => { item.progressTip = Backend.translate(command) + Backend.translate(" thinking..."); + /* if (command === "PlayCard") { item.playing = true; } @@ -756,6 +762,7 @@ callbacks["MoveFocus"] = (jsonData) => { if (command === "PlayCard") { item.playing = false; } + */ } } } diff --git a/Fk/RoomElement/Dashboard.qml b/Fk/RoomElement/Dashboard.qml index 1abb4686..748f63b8 100644 --- a/Fk/RoomElement/Dashboard.qml +++ b/Fk/RoomElement/Dashboard.qml @@ -158,6 +158,12 @@ RowLayout { return ret; } + + const pile_data = JSON.parse(Backend.callLuaFunction("GetAllPiles", [self.playerid])); + for (let name in pile_data) { + if (name.endsWith("&")) expandPile(name); + } + if (cname) { const ids = []; let cards = handcardAreaItem.cards; @@ -178,7 +184,6 @@ RowLayout { // Must manually analyze pattern here let pile_list = cname.split("|")[4]; - const pile_data = JSON.parse(Backend.callLuaFunction("GetAllPiles", [self.playerid])); if (pile_list && pile_list !== "." && !(pile_data instanceof Array)) { pile_list = pile_list.split(","); for (let pile_name of pile_list) { diff --git a/Fk/RoomElement/Photo.qml b/Fk/RoomElement/Photo.qml index 6eb735cb..f9a27683 100644 --- a/Fk/RoomElement/Photo.qml +++ b/Fk/RoomElement/Photo.qml @@ -177,7 +177,16 @@ Item { height: parent.height smooth: true fillMode: Image.PreserveAspectCrop - source: (general != "") ? SkinBank.getGeneralPicture(general) : "" + source: { + if (general === "") { + return ""; + } + if (deputyGeneral) { + return SkinBank.getGeneralExtraPic(general, "dual/") ?? SkinBank.getGeneralPicture(general); + } else { + return SkinBank.getGeneralPicture(general) + } + } } Image { @@ -187,8 +196,14 @@ Item { height: parent.height smooth: true fillMode: Image.PreserveAspectCrop - source: (deputyGeneral != "") ? - SkinBank.getGeneralPicture(deputyGeneral) : "" + source: { + const general = deputyGeneral; + if (deputyGeneral != "") { + return SkinBank.getGeneralExtraPic(general, "dual/") ?? SkinBank.getGeneralPicture(general); + } else { + return ""; + } + } } Image { diff --git a/Fk/skin-bank.js b/Fk/skin-bank.js index f40169cb..d45e2fc4 100644 --- a/Fk/skin-bank.js +++ b/Fk/skin-bank.js @@ -19,6 +19,15 @@ var PIXANIM_DIR = AppPath + "/image/anim/" var TILE_ICON_DIR = AppPath + "/image/button/tileicon/" var LOBBY_IMG_DIR = AppPath + "/image/lobby/"; +function getGeneralExtraPic(name, extra) { + const data = JSON.parse(Backend.callLuaFunction("GetGeneralData", [name])); + const extension = data.extension; + const path = AppPath + "/packages/" + extension + "/image/generals/" + extra + name + ".jpg"; + if (Backend.exists(path)) { + return path; + } +} + function getGeneralPicture(name) { const data = JSON.parse(Backend.callLuaFunction("GetGeneralData", [name])); const extension = data.extension; diff --git a/lua/core/player.lua b/lua/core/player.lua index cb34e90f..e6bf3398 100644 --- a/lua/core/player.lua +++ b/lua/core/player.lua @@ -352,6 +352,18 @@ function Player:getPileNameOfId(id) end end +--- 返回所有“如手牌般使用或打出”的牌。 +--- 或者说,返回所有名字以“&”结尾的pile的牌。 +---@param include_hand boolean|nil @ 是否包含真正的手牌 +---@return integer[] +function Player:getHandlyIds(include_hand) + local ret = include_hand and self:getCardIds("h") or {} + for k, v in pairs(self.special_cards) do + if k:endsWith("&") then table.insertTable(ret, v) end + end + return ret +end + -- for fkp only function Player:getHandcardNum() return #self:getCardIds(Player.Hand) diff --git a/lua/core/util.lua b/lua/core/util.lua index 0bb1da0a..d8c35711 100644 --- a/lua/core/util.lua +++ b/lua/core/util.lua @@ -2,6 +2,8 @@ local Util = {} Util.DummyFunc = function() end +Util.TrueFunc = function() return true end +Util.FalseFunc = function() return false end Util.DummyTable = setmetatable({}, { __newindex = function() error("Cannot assign to dummy table") end }) diff --git a/lua/server/events/gameflow.lua b/lua/server/events/gameflow.lua index bf1117d7..dc62a3cb 100644 --- a/lua/server/events/gameflow.lua +++ b/lua/server/events/gameflow.lua @@ -227,7 +227,7 @@ GameEvent.cleaners[GameEvent.Turn] = function(self) logic:trigger(fk.EventPhaseEnd, current, nil, true) current.phase = Player.NotActive - room:notifyProperty(current, current, "phase") + room:broadcastProperty(current, "phase") logic:trigger(fk.EventPhaseChanging, current, { from = Player.Finish, to = Player.NotActive }, true) logic:trigger(fk.EventPhaseStart, current, nil, true) diff --git a/lua/server/room.lua b/lua/server/room.lua index 699f151d..b9cfa5eb 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -175,6 +175,13 @@ function Room:isReady() p._splayer:setThinking(false) end end + + if self.race_request_list and table.contains(self.race_request_list, p) then + local result = p.serverplayer:waitForReply(0) + if result ~= "__notready" and result ~= "__cancel" and result ~= "" then + return true + end + end end return ret, (rest and rest > 1) and rest or nil end @@ -645,6 +652,7 @@ end function Room:doRequest(player, command, jsonData, wait) if wait == nil then wait = true end self.request_queue = {} + self.race_request_list = nil player:doRequest(command, jsonData, self.timeout) if wait then @@ -662,6 +670,7 @@ end function Room:doBroadcastRequest(command, players, jsonData) players = players or self.players self.request_queue = {} + self.race_request_list = nil for _, p in ipairs(players) do p:doRequest(command, jsonData or p.request_data) end @@ -695,6 +704,7 @@ function Room:doRaceRequest(command, players, jsonData) local player_len = #players -- self:notifyMoveFocus(players, command) self.request_queue = {} + self.race_request_list = players for _, p in ipairs(players) do p:doRequest(command, jsonData or p.request_data) end diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index b72e940e..3abc0ef5 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -402,7 +402,7 @@ function ServerPlayer:changePhase(from_phase, to_phase) end self.phase = to_phase - room:notifyProperty(self, self, "phase") + room:broadcastProperty(self, "phase") if #self.phases > 0 then table.remove(self.phases, 1) @@ -427,7 +427,7 @@ function ServerPlayer:gainAnExtraPhase(phase, delay) local current = self.phase self.phase = phase - room:notifyProperty(self, self, "phase") + room:broadcastProperty(self, "phase") room:sendLog{ type = "#GainAnExtraPhase", @@ -439,7 +439,7 @@ function ServerPlayer:gainAnExtraPhase(phase, delay) GameEvent(GameEvent.Phase, self):exec() self.phase = current - room:notifyProperty(self, self, "phase") + room:broadcastProperty(self, "phase") end ---@param phase_table Phase[]|nil @@ -494,7 +494,7 @@ function ServerPlayer:play(phase_table) phase_state[i].phase = phases[i] self.phase = phases[i] - room:notifyProperty(self, self, "phase") + room:broadcastProperty(self, "phase") local cancel_skip = true if phases[i] ~= Player.NotActive and (skip) then