From d816ae49553c850dafb548dba220895df3260d7d Mon Sep 17 00:00:00 2001 From: Nyutanislavsky Date: Sat, 30 Sep 2023 11:51:17 +0800 Subject: [PATCH] Heg (#271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复亮将和暗将的性别判断。 2. 下N家和上N家函数。 3. 君主和双势力的脚手架。 --------- Signed-off-by: Mechanel --- Fk/Pages/GeneralsOverview.qml | 2 +- Fk/Pages/ModesOverview.qml | 2 +- lua/client/i18n/zh_CN.lua | 1 + lua/core/player.lua | 21 ++++++++++++++++++--- lua/server/room.lua | 10 ++++++---- lua/server/serverplayer.lua | 23 ++++++++++++++++------- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Fk/Pages/GeneralsOverview.qml b/Fk/Pages/GeneralsOverview.qml index 3efca887..ad87beb7 100644 --- a/Fk/Pages/GeneralsOverview.qml +++ b/Fk/Pages/GeneralsOverview.qml @@ -362,7 +362,7 @@ Item { } Button { - text: qsTr("Search") + text: Backend.translate("Search") enabled: word.text !== "" onClicked: { listView.currentIndex = 0; diff --git a/Fk/Pages/ModesOverview.qml b/Fk/Pages/ModesOverview.qml index bd8813fd..6001b4f9 100644 --- a/Fk/Pages/ModesOverview.qml +++ b/Fk/Pages/ModesOverview.qml @@ -60,7 +60,7 @@ Item { } Button { - text: qsTr("Quit") + text: Backend.translate("Quit") anchors.bottom: parent.bottom onClicked: { mainStack.pop(); diff --git a/lua/client/i18n/zh_CN.lua b/lua/client/i18n/zh_CN.lua index 5071ee73..956628b5 100644 --- a/lua/client/i18n/zh_CN.lua +++ b/lua/client/i18n/zh_CN.lua @@ -25,6 +25,7 @@ Fk:loadTranslationTable{ ["Disable message audio"] = "禁用聊天语音", ["Hide unselectable cards"] = "下移不可选卡牌", ["Ban General Settings"] = "禁将", + ["Search"] = "搜索", ["Back"] = "返回", ["Refresh Room List"] = "刷新房间列表", diff --git a/lua/core/player.lua b/lua/core/player.lua index 695d3124..af63be9a 100644 --- a/lua/core/player.lua +++ b/lua/core/player.lua @@ -562,8 +562,9 @@ end --- 获取下家。 ---@param ignoreRemoved bool @ 忽略被移除 +---@param num interger|nil @ 第几个,默认1 ---@return ServerPlayer -function Player:getNextAlive(ignoreRemoved) +function Player:getNextAlive(ignoreRemoved, num) if #Fk:currentRoom().alive_players == 0 then return self end @@ -572,13 +573,27 @@ function Player:getNextAlive(ignoreRemoved) return self end - local ret = self.next - while ret.dead or (doNotIgnore and ret:isRemoved()) do + local ret = self + num = num or 1 + for _ = 1, num do ret = ret.next + while ret.dead or (doNotIgnore and ret:isRemoved()) do + ret = ret.next + end end return ret end +--- 获取上家。 +---@param ignoreRemoved bool @ 忽略被移除 +---@param num interger|nil @ 第几个,默认1 +---@return ServerPlayer +function Player:getLastAlive(ignoreRemoved, num) + num = num or 1 + local index = ignoreRemoved and #Fk:currentRoom().alive_players or #table.filter(Fk:currentRoom().alive_players, function(p) return not p:isRemoved() end) - num + return self:getNextAlive(ignoreRemoved, index) +end + --- 增加玩家使用特定牌的历史次数。 ---@param cardName string @ 牌名 ---@param num integer|nil @ 次数 diff --git a/lua/server/room.lua b/lua/server/room.lua index c092c8f9..21bd6b4c 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -605,14 +605,15 @@ end ---@param isDeputy bool @ 是否变的是副将 ---@param sendLog bool @ 是否发Log ---@param maxHpChange bool @ 是否改变体力上限,默认改变 -function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChange) +function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChange, kingdomChange) local new = Fk.generals[new_general] or Fk.generals["sunce"] or Fk.generals["blank_shibing"] - local kingdom = isDeputy and player.kingdom or new.kingdom - if not isDeputy and (new.kingdom == "god" or new.subkingdom) then + kingdomChange = (kingdomChange == nil) and true or kingdomChange + local kingdom = (isDeputy or not kingdomChange) and player.kingdom or new.kingdom + if not isDeputy and kingdomChange and (new.kingdom == "god" or new.subkingdom) then local allKingdoms = {} if new.kingdom == "god" then - allKingdoms = {"wei", "shu", "wu", "qun", "jin"} + allKingdoms = table.filter({"wei", "shu", "wu", "qun", "jin"}, function(k) return table.contains(Fk.kingdoms, k) end) elseif new.subkingdom then allKingdoms = { new.kingdom, new.subkingdom } end @@ -2757,6 +2758,7 @@ function Room:drawCards(player, num, skillName, fromPlace) num = drawData.num fromPlace = drawData.fromPlace + player = drawData.who local topCards = self:getNCards(num, fromPlace) self:moveCards({ diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index c1d8ec26..02aa5bea 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -891,14 +891,14 @@ function ServerPlayer:revealGeneral(isDeputy, no_trigger) end local oldKingdom = self.kingdom - room:changeHero(self, generalName, false, isDeputy, false, false) + room:changeHero(self, generalName, false, isDeputy, false, false, false) if oldKingdom ~= "wild" then - local kingdom = general.kingdom + local kingdom = (self:getMark("__heg_wild") == 1 and not isDeputy) and "wild" or self:getMark("__heg_kingdom") self.kingdom = kingdom - if oldKingdom == "unknown" and #table.filter(room:getOtherPlayers(self, false, true), + if oldKingdom == "unknown" and kingdom ~= "wild" and #table.filter(room:getOtherPlayers(self, false, true), function(p) return p.kingdom == kingdom - end) >= #room.players // 2 then + end) >= #room.players // 2 and table.every(room.alive_players, function(p) return p.kingdom ~= kingdom or not string.find(p.general, "lord") end) then self.kingdom = "wild" end room:broadcastProperty(self, "kingdom") @@ -906,8 +906,8 @@ function ServerPlayer:revealGeneral(isDeputy, no_trigger) room:setPlayerProperty(self, "kingdom", "wild") end - if self.gender == General.Agender then - self.gender = general.gender + if self.gender == General.Agender or self.gender ~= Fk.generals[self.general].gender then + room:setPlayerProperty(self, "gender", general.gender) end room:sendLog{ @@ -982,8 +982,17 @@ function ServerPlayer:hideGeneral(isDeputy) end end - room.logic:trigger(fk.GeneralHidden, room, generalName) + self.gender = General.Agender + if Fk.generals[self.general].gender ~= General.Agender then + self.gender = Fk.generals[self.general].gender + elseif self.deputyGeneral and Fk.generals[self.deputyGeneral].gender ~= General.Agender then + self.gender = Fk.generals[self.deputyGeneral].gender + end + room:broadcastProperty(self, "gender") + + room.logic:trigger(fk.GeneralHidden, self, generalName) end + -- 神貂蝉 ---@param p ServerPlayer