From 48bb6ac9991223a82141121f5a766511da6d0ba9 Mon Sep 17 00:00:00 2001 From: YoumuKon <38815081+YoumuKon@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:08:01 +0800 Subject: [PATCH] bug fix (#239) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了人人主公框+无主公酱报错的bug - 修复了random(n)不返回表的bug - 为table添加connect(不改变输入数组的连接各数组)方法及其IfNeed版本(包括insertTable) - 修复了有死人不能喝酒的bug --- lua/core/util.lua | 29 ++++++++++++++++++++++++++++- lua/server/gamelogic.lua | 16 ++++++++++------ packages/maneuvering/init.lua | 4 ++-- packages/standard/hegemony.lua | 2 +- packages/standard/init.lua | 3 +++ packages/standard_cards/init.lua | 2 +- test/lua/pattern.lua | 13 +++++++++++++ 7 files changed, 58 insertions(+), 11 deletions(-) diff --git a/lua/core/util.lua b/lua/core/util.lua index a2bef8c1..9ecb8976 100644 --- a/lua/core/util.lua +++ b/lua/core/util.lua @@ -245,6 +245,33 @@ function table:insertIfNeed(element) end end +-- similar to table.insertTable but insertIfNeed inside +function table:insertTableIfNeed(list) + for _, e in ipairs(list) do + table.insertIfNeed(self, e) + end +end + +---@generic T +---@return T[] +function table.connect(...) + local ret = {} + for _, v in ipairs({...}) do + table.insertTable(ret, v) + end + return ret +end + +---@generic T +---@return T[] +function table.connectIfNeed(...) + local ret = {} + for _, v in ipairs({...}) do + table.insertTableIfNeed(ret, v) + end + return ret +end + ---@generic T ---@param self T[] ---@param n integer|nil @@ -252,7 +279,7 @@ end function table:random(n) local n0 = n n = n or 1 - if #self == 0 then return nil end + if #self == 0 then return n0 ~= nil and {} or nil end local tmp = {table.unpack(self)} local ret = {} while n > 0 and #tmp > 0 do diff --git a/lua/server/gamelogic.lua b/lua/server/gamelogic.lua index 0ebdaead..1507b2fb 100644 --- a/lua/server/gamelogic.lua +++ b/lua/server/gamelogic.lua @@ -91,6 +91,11 @@ function GameLogic:chooseGenerals() if lord ~= nil then room.current = lord local generals = {} + local lordlist = {} + local lordpools = {} + table.insertTable(generals, Fk:getGeneralsRandomly(generalNum, Fk:getAllGenerals(), table.map(generals, function (g) + return g.name + end))) if room.settings.gameMode == "aaa_role_mode" then for _, general in pairs(Fk:getAllGenerals()) do if (not general.hidden and not general.total_hidden) and @@ -100,18 +105,17 @@ function GameLogic:chooseGenerals() not table.find(generals, function(g) return g.trueName == general.trueName end) then - table.insert(generals, general) + table.insert(lordlist, general) end end - generals = table.random(generals, 3) + lordlist = table.random(lordlist, 3) or {} end - table.insertTable(generals, Fk:getGeneralsRandomly(generalNum, Fk:getAllGenerals(), table.map(generals, function (g) - return g.name - end))) for i = 1, #generals do generals[i] = generals[i].name end - lord_generals = room:askForGeneral(lord, generals, n) + lordpools = table.simpleClone(generals) + table.insertTable(lordpools, table.map(lordlist, function(g) return g.name end)) + lord_generals = room:askForGeneral(lord, lordpools, n) local lord_general, deputy if type(lord_generals) == "table" then deputy = lord_generals[2] diff --git a/packages/maneuvering/init.lua b/packages/maneuvering/init.lua index 9ed84281..5a1e9ebe 100644 --- a/packages/maneuvering/init.lua +++ b/packages/maneuvering/init.lua @@ -83,12 +83,12 @@ local analepticSkill = fk.CreateActiveSkill{ max_turn_use_time = 1, mod_target_filter = function(self, to_select, selected, user, card, distance_limited) return self:withinTimesLimit(Fk:currentRoom():getPlayerById(to_select), Player.HistoryTurn, card, "analeptic", Fk:currentRoom():getPlayerById(to_select)) and - not table.find(Fk:currentRoom().players, function(p) + not table.find(Fk:currentRoom().alive_players, function(p) return p.dying end) end, can_use = function(self, player, card) - return self:modTargetFilter(player.id, Util.DummyTable, player.id, card) + return self:withinTimesLimit(player, Player.HistoryTurn, card, "analeptic", player) end, on_use = function(self, room, use) if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then diff --git a/packages/standard/hegemony.lua b/packages/standard/hegemony.lua index c877e820..a84baaf4 100644 --- a/packages/standard/hegemony.lua +++ b/packages/standard/hegemony.lua @@ -362,7 +362,7 @@ heg = fk.CreateGameMode{ maxPlayer = 8, rule = heg_rule, logic = heg_getlogic, - countInFunc = Util.FalseFunc + is_counted = Util.FalseFunc } Fk:loadTranslationTable{ diff --git a/packages/standard/init.lua b/packages/standard/init.lua index e7240c9f..d94dad89 100644 --- a/packages/standard/init.lua +++ b/packages/standard/init.lua @@ -1165,6 +1165,9 @@ local role_mode = fk.CreateGameMode{ name = "aaa_role_mode", -- just to let it at the top of list minPlayer = 2, maxPlayer = 8, + is_counted = function(self, room) + return #room.players >= 5 + end, surrender_func = function(self, playedTime) local roleCheck = false local roleText = "" diff --git a/packages/standard_cards/init.lua b/packages/standard_cards/init.lua index 695bcfdd..340d76ea 100644 --- a/packages/standard_cards/init.lua +++ b/packages/standard_cards/init.lua @@ -125,7 +125,7 @@ local peachSkill = fk.CreateActiveSkill{ name = "peach_skill", mod_target_filter = function(self, to_select) return Fk:currentRoom():getPlayerById(to_select):isWounded() and - not table.find(Fk:currentRoom().players, function(p) + not table.find(Fk:currentRoom().alive_players, function(p) return p.dying end) end, diff --git a/test/lua/pattern.lua b/test/lua/pattern.lua index 782f0601..e3f95985 100644 --- a/test/lua/pattern.lua +++ b/test/lua/pattern.lua @@ -1,4 +1,17 @@ TestExppattern = { + testUtil = function() + local table1 = {1, 3, 5, 8} + local table2 = {2, 3, 5, 7} + p(table1) + p(table2) + p(table.connect(table1, table2)) + p(table1) + p(table2) + p(table.connectIfNeed(table1, table2)) + p(table1) + p(table2) + end, + testMatchExp = function() local exp1 = Exppattern:Parse("slash,jink") lu.assertTrue(exp1:matchExp("peack,jink"))