diff --git a/lua/core/engine.lua b/lua/core/engine.lua index 17044b41bb99bbc1b0a84088ecb969761eebcbc1..e6356a37677212a1dc0ab8608f0dc3b8b64895d1 100644 --- a/lua/core/engine.lua +++ b/lua/core/engine.lua @@ -75,6 +75,7 @@ function Engine:initialize() self.mini_games = {} self:loadPackages() + self:setLords() self:loadDisabled() self:addSkills(AuxSkills) end @@ -349,9 +350,9 @@ function Engine:addGeneral(general) table.insert(self.same_generals[tName], general.name) end - if table.find(general.skills, function(s) return s.lordSkill end) then - table.insert(self.lords, general.name) - end + -- if table.find(general.skills, function(s) return s.lordSkill end) then + -- table.insert(self.lords, general.name) + -- end end --- 加载一系列武将。 @@ -363,6 +364,15 @@ function Engine:addGenerals(generals) end end +--- 为所有武将加载主公技和主公判定 +function Engine:setLords() + for _, general in pairs(self.generals) do + if table.find(general.skills, function(s) return s.lordSkill end) then + table.insert(self.lords, general.name) + end + end +end + --- 为一个势力添加势力映射 --- --- 这意味着原势力登场时必须改变为添加的几个势力之一(须存在) diff --git a/lua/fk_ex.lua b/lua/fk_ex.lua index 1c1e6b5a9df1edc42be729279bbf91e9a1974451..bb2a05fd64e39ab01fd2366892ee730a3e317522 100644 --- a/lua/fk_ex.lua +++ b/lua/fk_ex.lua @@ -237,7 +237,7 @@ end ---@field public enabled_at_response? fun(self: ViewAsSkill, player: Player, response: boolean): boolean? ---@field public before_use? fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct): string? ---@field public after_use? fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct): string? ----@field public prompt? string|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public prompt? string|fun(self: ActiveSkill, selected_cards: integer[], selected: integer[]): string ---@param spec ViewAsSkillSpec ---@return ViewAsSkill diff --git a/lua/server/room.lua b/lua/server/room.lua index df6a9f09a5759ce6143dbaaae5239fed9f063b07..7eb19ecef2ad4cb8c9b42eb47f2c2d9f89cfe4e6 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -2115,8 +2115,9 @@ end ---@return table<"top"|"bottom", integer[]> function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotify, noPut, areaNames) -- 这一大堆都是来提前报错的 - top_limit = top_limit or Util.DummyTable - bottom_limit = bottom_limit or Util.DummyTable + local leng = #cards + top_limit = top_limit or { 0, leng } + bottom_limit = bottom_limit or { 0, leng } if #top_limit > 0 then assert(top_limit[1] >= 0 and top_limit[2] >= 0, "limits error: The lower limit should be greater than 0") assert(top_limit[1] <= top_limit[2], "limits error: The upper limit should be less than the lower limit") @@ -2126,40 +2127,40 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif assert(bottom_limit[1] <= bottom_limit[2], "limits error: The upper limit should be less than the lower limit") end if #top_limit > 0 and #bottom_limit > 0 then - assert(#cards >= top_limit[1] + bottom_limit[1] and #cards <= top_limit[2] + bottom_limit[2], "limits Error: No enough space") + assert(leng >= top_limit[1] + bottom_limit[1] and leng <= top_limit[2] + bottom_limit[2], "limits Error: No enough space") end if areaNames then assert(#areaNames == 2, "areaNames error: Should have 2 elements") + else + areaNames = { "Top", "Bottom" } end local command = "AskForGuanxing" self:notifyMoveFocus(player, customNotify or command) - local max_top = top_limit and top_limit[2] or #cards + local max_top = top_limit[2] local card_map = {} if max_top > 0 then table.insert(card_map, table.slice(cards, 1, max_top + 1)) - else - table.insert(card_map, {}) end - if max_top < #cards then + if max_top < leng then table.insert(card_map, table.slice(cards, max_top + 1)) end local data = { prompt = "", is_free = true, cards = card_map, - min_top_cards = top_limit and top_limit[1] or 0, - max_top_cards = top_limit and top_limit[2] or #cards, - min_bottom_cards = bottom_limit and bottom_limit[1] or 0, - max_bottom_cards = bottom_limit and bottom_limit[2] or #cards, - top_area_name = areaNames and areaNames[1] or "Top", - bottom_area_name = areaNames and areaNames[2] or "Bottom", + min_top_cards = top_limit[1], + max_top_cards = top_limit[2], + min_bottom_cards = bottom_limit[1], + max_bottom_cards = bottom_limit[2], + top_area_name = areaNames[1], + bottom_area_name = areaNames[2], } local result = self:doRequest(player, command, json.encode(data)) local top, bottom if result ~= "" then local d = json.decode(result) - if #top_limit > 0 and top_limit[2] == 0 then + if top_limit[2] == 0 then top = Util.DummyTable bottom = d[1] else @@ -2167,8 +2168,9 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif bottom = d[2] or Util.DummyTable end else - top = table.random(cards, top_limit and top_limit[2] or #cards) or Util.DummyTable - bottom = table.shuffle(table.filter(cards, function(id) return not table.contains(top, id) end)) or Util.DummyTable + local pos = math.min(top_limit[2], leng - bottom_limit[1]) + top = table.slice(cards, 1, pos + 1) + bottom = table.slice(cards, pos + 1) end if not noPut then