From f72aaa23cf6b6e81080ff2054a92a088c855a35a Mon Sep 17 00:00:00 2001 From: Nyutanislavsky Date: Sun, 4 Feb 2024 15:30:27 +0800 Subject: [PATCH] Bugfix (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复传入数组的extraPile无法收回 2. 被弃置牌的log添加操作者 3. beforeMaxHpChanged的num可以被修改 4. 额外回合增加skillName 5. 修复亮将技能和禁止亮将 6. 水一些注释和格式 --------- Signed-off-by: Mechanel --- Fk/RoomElement/Dashboard.qml | 10 +++++++- lua/client/client.lua | 30 +++++++++++++++++------- lua/client/i18n/en_US.lua | 1 + lua/client/i18n/zh_CN.lua | 3 ++- lua/core/general.lua | 3 ++- lua/core/skill_type/active.lua | 2 +- lua/server/events/hp.lua | 17 ++++++++++---- lua/server/room.lua | 29 ++++++++++++++++------- lua/server/serverplayer.lua | 25 +++++++------------- lua/server/system_enum.lua | 4 ++++ packages/standard/aux_skills.lua | 40 ++++++++++++++++++++++++-------- packages/standard_cards/init.lua | 2 +- packages/test/init.lua | 33 ++++++++------------------ 13 files changed, 123 insertions(+), 76 deletions(-) diff --git a/Fk/RoomElement/Dashboard.qml b/Fk/RoomElement/Dashboard.qml index 39454312..e91a05e0 100644 --- a/Fk/RoomElement/Dashboard.qml +++ b/Fk/RoomElement/Dashboard.qml @@ -19,6 +19,7 @@ RowLayout { property alias skillButtons: skillPanel.skill_buttons property var expanded_piles: ({}) // name -> int[] + property var extra_cards: [] property var disabledSkillNames: [] @@ -86,6 +87,7 @@ RowLayout { footnote = "$Equip"; } else if (pile === "_extra") { ids = extra_ids; + extra_cards = ids; footnote = extra_footnote; } else { ids = lcall("GetPile", self.playerid, pile); @@ -122,7 +124,13 @@ RowLayout { }) handcardAreaItem.updateCardPosition(); } else { - const ids = lcall("GetPile", self.playerid, pile); + let ids = []; + if (pile === "_extra") { + ids = extra_cards; + extra_cards = []; + } else { + ids = lcall("GetPile", self.playerid, pile); + } ids.forEach(id => { const card = handcardAreaItem.remove([id])[0]; card.origX = parentPos.x; diff --git a/lua/client/client.lua b/lua/client/client.lua index b057794e..95978400 100644 --- a/lua/client/client.lua +++ b/lua/client/client.lua @@ -469,6 +469,7 @@ local function separateMoves(moves) moveReason = move.moveReason, specialName = move.specialName, fromSpecialName = info.fromSpecialName, + proposer = move.proposer, }) end end @@ -480,9 +481,9 @@ local function mergeMoves(moves) local ret = {} local temp = {} for _, move in ipairs(moves) do - local info = string.format("%q,%q,%q,%q,%s,%s", + local info = string.format("%q,%q,%q,%q,%s,%s,%q", move.from, move.to, move.fromArea, move.toArea, - move.specialName, move.fromSpecialName) + move.specialName, move.fromSpecialName, move.proposer) if temp[info] == nil then temp[info] = { ids = {}, @@ -493,6 +494,7 @@ local function mergeMoves(moves) moveReason = move.moveReason, specialName = move.specialName, fromSpecialName = move.fromSpecialName, + proposer = move.proposer, } end table.insert(temp[info].ids, move.ids[1]) @@ -504,7 +506,7 @@ local function mergeMoves(moves) end local function sendMoveCardLog(move) - local client = ClientInstance + local client = ClientInstance ---@class Client if #move.ids == 0 then return end local hidden = table.contains(move.ids, -1) local msgtype @@ -607,12 +609,22 @@ local function sendMoveCardLog(move) }) elseif move.toArea == Card.DiscardPile then if move.moveReason == fk.ReasonDiscard then - client:appendLog{ - type = "$DiscardCards", - from = move.from, - card = move.ids, - arg = #move.ids, - } + if move.proposer and move.proposer ~= move.from then + client:appendLog{ + type = "$DiscardOther", + from = move.from, + to = {move.proposer}, + card = move.ids, + arg = #move.ids, + } + else + client:appendLog{ + type = "$DiscardCards", + from = move.from, + card = move.ids, + arg = #move.ids, + } + end elseif move.moveReason == fk.ReasonPutIntoDiscardPile then client:appendLog{ type = "$PutToDiscard", diff --git a/lua/client/i18n/en_US.lua b/lua/client/i18n/en_US.lua index 29156e18..f0b12a8f 100644 --- a/lua/client/i18n/en_US.lua +++ b/lua/client/i18n/en_US.lua @@ -344,6 +344,7 @@ Fk:loadTranslationTable({ ["$LightningMove"] = "%card transfered from %from to %to", ["$PasteCard"] = "%from used %card to %to", ["$DiscardCards"] = "%from discarded %arg card(s) %card", + ["$DiscardOther"] = "%to discarded %arg card(s) %card from %from", ["$InstallEquip"] = "%from equipped %card", ["$UninstallEquip"] = "%from uninstalled %card", diff --git a/lua/client/i18n/zh_CN.lua b/lua/client/i18n/zh_CN.lua index 0163c376..d946ce20 100644 --- a/lua/client/i18n/zh_CN.lua +++ b/lua/client/i18n/zh_CN.lua @@ -330,7 +330,7 @@ Fk:loadTranslationTable{ ["fire_damage"] = "火属性", ["thunder_damage"] = "雷属性", ["ice_damage"] = "冰属性", - ["hp_lost"] = "体力流失", + ["hp_lost"] = "失去体力", ["lose_hp"] = "失去体力", ["phase_start"] = "准备阶段", @@ -412,6 +412,7 @@ Fk:loadTranslationTable{ ["$PutCard"] = "%from 的 %arg 张牌被置于牌堆", ["$PutKnownCard"] = "%from 的牌 %card 被置于牌堆", ["$DiscardCards"] = "%from 弃置了 %arg 张牌 %card", + ["$DiscardOther"] = "%to 弃置了 %from 的 %arg 张牌 %card", ["$PutToDiscard"] = "%arg 张牌 %card 被置入弃牌堆", ["#ShowCard"] = "%from 展示了牌 %card", diff --git a/lua/core/general.lua b/lua/core/general.lua index 33e220b4..24f4beee 100644 --- a/lua/core/general.lua +++ b/lua/core/general.lua @@ -94,7 +94,8 @@ function General:addRelatedSkill(skill) end --- 获取武将所有技能。 ----@param include_lord bool +---@param include_lord? boolean +---@return string[] function General:getSkillNameList(include_lord) local ret = {} local other_skills = table.map(self.other_skills, Util.Name2SkillMapper) diff --git a/lua/core/skill_type/active.lua b/lua/core/skill_type/active.lua index 20760a04..4e448c03 100644 --- a/lua/core/skill_type/active.lua +++ b/lua/core/skill_type/active.lua @@ -45,8 +45,8 @@ end ---@param to_select integer @ id of the target ---@param selected integer[] @ ids of selected targets ---@param selected_cards integer[] @ ids of selected cards ----@param extra_data any @ extra_data ---@param card Card @ helper +---@param extra_data? any @ extra_data function ActiveSkill:targetFilter(to_select, selected, selected_cards, card, extra_data) return false end diff --git a/lua/server/events/hp.lua b/lua/server/events/hp.lua index 06ef099f..e62f786a 100644 --- a/lua/server/events/hp.lua +++ b/lua/server/events/hp.lua @@ -74,14 +74,14 @@ GameEvent.functions[GameEvent.ChangeHp] = function(self) room:sendLog{ type = "#LoseHP", from = player.id, - arg = 0 - num, + arg = 0 - data.num, } room:sendLogEvent("LoseHP", {}) elseif reason == "recover" then room:sendLog{ type = "#HealHP", from = player.id, - arg = num, + arg = data.num, } end @@ -290,12 +290,19 @@ end GameEvent.functions[GameEvent.ChangeMaxHp] = function(self) local player, num = table.unpack(self.data) local room = self.room - if room.logic:trigger(fk.BeforeMaxHpChanged, player, { num = num }) or num == 0 then + + ---@type MaxHpChangedData + local data = { + num = num, + } + + if room.logic:trigger(fk.BeforeMaxHpChanged, player, data) or data.num == 0 then return false end - player.maxHp = math.max(player.maxHp + num, 0) - room:broadcastProperty(player, "maxHp") + num = data.num + + room:setPlayerProperty(player, "maxHp", math.max(player.maxHp + num, 0)) room:sendLogEvent("ChangeMaxHp", { player = player.id, num = num, diff --git a/lua/server/room.lua b/lua/server/room.lua index 98aceb58..47467285 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -872,11 +872,11 @@ function Room:notifyMoveCards(players, card_moves, forceVisible) if not (move.moveVisible or forceVisible or containArea(move.toArea, move.to and p.isBuddy and p:isBuddy(move.to))) then for _, info in ipairs(move.moveInfo) do if not containArea(info.fromArea, move.from == p.id) then - info.cardId = -1 + info.cardId = -1 + end end end end - end p:doNotify("MoveCards", json.encode(arg)) end end @@ -1195,7 +1195,7 @@ function Room:askForDiscard(player, minNum, maxNum, includeEquip, skillName, can toDiscard = ret.cards else if cancelable then return {} end - toDiscard = table.random(canDiscards, minNum) + toDiscard = table.random(canDiscards, minNum) ---@type integer[] end if not skipDiscard then @@ -1272,7 +1272,7 @@ function Room:askForCard(player, minNum, maxNum, includeEquip, skillName, cancel pattern = pattern, expand_pile = expand_pile, } - local prompt = prompt or ("#AskForCard:::" .. maxNum .. ":" .. minNum) + prompt = prompt or ("#AskForCard:::" .. maxNum .. ":" .. minNum) local _, ret = self:askForUseActiveSkill(player, "choose_cards_skill", prompt, cancelable, data, no_indicate) if ret then chosenCards = ret.cards @@ -2633,7 +2633,7 @@ function Room:doCardUseEffect(cardUseEvent) return end - ---@type CardEffectEvent + ---@class CardEffectEvent local cardEffectEvent = { from = cardUseEvent.from, tos = cardUseEvent.tos, @@ -2916,7 +2916,8 @@ end ---@param cid integer|Card @ 要拿到的卡牌 ---@param unhide? boolean @ 是否明着拿 ---@param reason? CardMoveReason @ 卡牌移动的原因 -function Room:obtainCard(player, cid, unhide, reason) +---@param proposer? integer @ 移动操作者的id +function Room:obtainCard(player, cid, unhide, reason, proposer) if type(cid) ~= "number" then assert(cid and cid:isInstanceOf(Card)) cid = cid:isVirtual() and cid.subcards or {cid.id} @@ -2935,7 +2936,7 @@ function Room:obtainCard(player, cid, unhide, reason) to = player, toArea = Card.PlayerHand, moveReason = reason or fk.ReasonJustMove, - proposer = player, + proposer = proposer or player, moveVisible = unhide or false, }) end @@ -2987,7 +2988,6 @@ function Room:moveCardTo(card, to_place, target, reason, skill_name, special_nam reason = reason or fk.ReasonJustMove skill_name = skill_name or "" special_name = special_name or "" - proposer = proposer or nil local ids = Card:getIdList(card) local to @@ -3587,6 +3587,10 @@ function Room:printCard(name, suit, number) return cd end +--- 刷新使命技状态 +---@param player ServerPlayer +---@param skillName Suit +---@param failed? boolean function Room:updateQuestSkillState(player, skillName, failed) assert(Fk.skills[skillName].frequency == Skill.Quest) @@ -3600,6 +3604,9 @@ function Room:updateQuestSkillState(player, skillName, failed) }) end +--- 废除区域 +---@param player ServerPlayer +---@param playerSlots string | string[] function Room:abortPlayerArea(player, playerSlots) assert(type(playerSlots) == "string" or type(playerSlots) == "table") @@ -3652,6 +3659,9 @@ function Room:abortPlayerArea(player, playerSlots) self.logic:trigger(fk.AreaAborted, player, { slots = slotsSealed }) end +--- 恢复区域 +---@param player ServerPlayer +---@param playerSlots string | string[] function Room:resumePlayerArea(player, playerSlots) assert(type(playerSlots) == "string" or type(playerSlots) == "table") @@ -3675,6 +3685,9 @@ function Room:resumePlayerArea(player, playerSlots) end end +--- 设置休整 +---@param player ServerPlayer +---@param roundNum integer function Room:setPlayerRest(player, roundNum) player.rest = roundNum self:broadcastProperty(player, "rest") diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index fb6e76ce..e76e88fe 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -630,15 +630,18 @@ function ServerPlayer:endPlayPhase() -- TODO: send log end +--- 获得一个额外回合 ---@param delay? boolean -function ServerPlayer:gainAnExtraTurn(delay) +---@param skillName? string +function ServerPlayer:gainAnExtraTurn(delay, skillName) local room = self.room delay = (delay == nil) and true or delay + skillName = (skillName == nil) and room.logic:getCurrentSkillName() or skillName if delay then local logic = room.logic local turn = logic:getCurrentEvent():findParent(GameEvent.Turn, true) if turn then - turn:prependExitFunc(function() self:gainAnExtraTurn(false) end) + turn:prependExitFunc(function() self:gainAnExtraTurn(false, skillName) end) return end end @@ -653,7 +656,6 @@ function ServerPlayer:gainAnExtraTurn(delay) self.tag["_extra_turn_count"] = self.tag["_extra_turn_count"] or {} local ex_tag = self.tag["_extra_turn_count"] - local skillName = room.logic:getCurrentSkillName() table.insert(ex_tag, skillName) GameEvent(GameEvent.Turn, self):exec() @@ -833,7 +835,7 @@ end -- Hegemony func ----@param skill Skill +---@param skill Skill | string function ServerPlayer:addFakeSkill(skill) assert(type(skill) == "string" or skill:isInstanceOf(Skill)) if type(skill) == "string" then @@ -854,7 +856,7 @@ function ServerPlayer:addFakeSkill(skill) self:doNotify("AddSkill", json.encode{ self.id, skill.name, true }) end ----@param skill Skill +---@param skill Skill | string function ServerPlayer:loseFakeSkill(skill) assert(type(skill) == "string" or skill:isInstanceOf(Skill)) if type(skill) == "string" then @@ -873,6 +875,7 @@ function ServerPlayer:loseFakeSkill(skill) self:doNotify("LoseSkill", json.encode{ self.id, skill.name, true }) end +---@param skill Skill | string function ServerPlayer:isFakeSkill(skill) if type(skill) == "string" then skill = Fk.skills[skill] end assert(skill:isInstanceOf(Skill)) @@ -1049,18 +1052,8 @@ function ServerPlayer:hideGeneral(isDeputy) end local general = Fk.generals[generalName] - local skills = general.skills local place = isDeputy and "m" or "d" - for _, s in ipairs(skills) do - room:handleAddLoseSkills(self, "-" .. s.name, nil, false, true) - if s.relate_to_place ~= place then - if s.frequency == Skill.Compulsory then - self:addFakeSkill("reveal_skill") - end - self:addFakeSkill(s) - end - end - for _, sname in ipairs(general.other_skills) do + for _, sname in ipairs(general:getSkillNameList()) do room:handleAddLoseSkills(self, "-" .. sname, nil, false, true) local s = Fk.skills[sname] if s.relate_to_place ~= place then diff --git a/lua/server/system_enum.lua b/lua/server/system_enum.lua index 5c8dd9bd..483de916 100644 --- a/lua/server/system_enum.lua +++ b/lua/server/system_enum.lua @@ -50,6 +50,10 @@ ---@field public num integer @ 失去体力的数值 ---@field public skillName string @ 导致这次失去的技能名 +--- 描述跟体力上限变化有关的数据 +---@class MaxHpChangedData +---@field public num integer @ 体力上限变化量,可能是正数或者负数 + ---@alias DamageType integer fk.NormalDamage = 1 diff --git a/packages/standard/aux_skills.lua b/packages/standard/aux_skills.lua index 3cc3a116..9c3d6b40 100644 --- a/packages/standard/aux_skills.lua +++ b/packages/standard/aux_skills.lua @@ -197,18 +197,14 @@ local revealProhibited = fk.CreateInvaliditySkill { end if #generals == 0 then return false end - if type(from._fake_skills) == "table" and not table.contains(from._fake_skills, skill) then return false end local sname = skill.name for _, g in ipairs(generals) do - if g == "m" then - if from.general ~= "anjiang" then return false end - else - if from.deputyGeneral ~= "anjiang" then return false end - end - local generalName = g == "m" and from:getMark("__heg_general") or from:getMark("__heg_deputy") - local general = Fk.generals[generalName] - if table.contains(general:getSkillNameList(true), sname) then - return true + if (g == "m" and from.general == "anjiang") or (g == "d" and from.deputyGeneral == "anjiang") then + local generalName = g == "m" and from:getMark("__heg_general") or from:getMark("__heg_deputy") + local general = Fk.generals[generalName] + if table.contains(general:getSkillNameList(true), sname) then + return true + end end end return false @@ -254,6 +250,30 @@ local revealSkill = fk.CreateActiveSkill{ elseif choice == "revealMain" then player:revealGeneral(false) elseif choice == "revealDeputy" then player:revealGeneral(true) end end, + can_use = function(self, player) + local choiceList = {} + if (player.general == "anjiang" and not player:prohibitReveal()) then + local general = Fk.generals[player:getMark("__heg_general")] + for _, sname in ipairs(general:getSkillNameList(true)) do + local s = Fk.skills[sname] + if s.frequency == Skill.Compulsory and s.relate_to_place ~= "m" then + table.insert(choiceList, "revealMain") + break + end + end + end + if (player.deputyGeneral == "anjiang" and not player:prohibitReveal(true)) then + local general = Fk.generals[player:getMark("__heg_deputy")] + for _, sname in ipairs(general:getSkillNameList(true)) do + local s = Fk.skills[sname] + if s.frequency == Skill.Compulsory and s.relate_to_place ~= "d" then + table.insert(choiceList, "revealDeputy") + break + end + end + end + return #choiceList > 0 + end } AuxSkills = { diff --git a/packages/standard_cards/init.lua b/packages/standard_cards/init.lua index 136dd20a..a8cc087c 100644 --- a/packages/standard_cards/init.lua +++ b/packages/standard_cards/init.lua @@ -1048,7 +1048,7 @@ local spearSkill = fk.CreateViewAsSkill{ pattern = "slash", card_filter = function(self, to_select, selected) if #selected == 2 then return false end - return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip + return table.contains(Self:getHandlyIds(true), to_select) end, view_as = function(self, cards) if #cards ~= 2 then diff --git a/packages/test/init.lua b/packages/test/init.lua index 3ae6a71a..98b9aa71 100644 --- a/packages/test/init.lua +++ b/packages/test/init.lua @@ -208,19 +208,10 @@ local test_vs = fk.CreateViewAsSkill{ } local test_trig = fk.CreateTriggerSkill{ name = "test_trig", - events = {fk.EventPhaseEnd}, - can_trigger = function(self, event, target, player, data) - return target == player and player:hasSkill(self.name) and player.phase == Player.Discard - end, - on_cost = function(self, event, target, player, data) - local cards = player.room:askForDiscard(player, 1, 1, false, self.name, true, nil, "#test_trig-ask", true) - if #cards > 0 then - self.cost_data = cards - return true - end - end, + events = {fk.BeforeHpChanged}, + on_cost = Util.TrueFunc, on_use = function(self, event, target, player, data) - player.room:throwCard(self.cost_data, self.name, player, player) + data.num = data.num - 1 end, } local damage_maker = fk.CreateActiveSkill{ @@ -245,7 +236,7 @@ local damage_maker = fk.CreateActiveSkill{ } end, on_use = function(self, room, effect) local from = room:getPlayerById(effect.from) - local victim = #effect.tos > 0 and room:getPlayerById(effect.tos[1]) + local victim = room:getPlayerById(effect.tos[1]) local target = #effect.tos > 1 and room:getPlayerById(effect.tos[2]) local choice = self.interaction.data local number @@ -254,7 +245,7 @@ local damage_maker = fk.CreateActiveSkill{ for i = 1, 99 do table.insert(choices, tostring(i)) end - number = tonumber(room:askForChoice(from, choices, self.name, nil)) + number = tonumber(room:askForChoice(from, choices, self.name, nil)) ---@type integer end if target then from = target end if choice == "heal_hp" then @@ -316,9 +307,6 @@ local change_hero = fk.CreateActiveSkill{ local choice = self.interaction.data local generals = room:getNGenerals(8) local general = room:askForGeneral(from, generals, 1) - if general == nil then - general = table.random(generals) - end table.removeOne(generals, general) room:changeHero(target, general, false, choice == "deputyGeneral", true) room:returnToGeneralPile(generals) @@ -330,7 +318,7 @@ local test_zhenggong = fk.CreateTriggerSkill{ frequency = Skill.Compulsory, anim_type = "negative", can_trigger = function(self, event, target, player, data) - return player:hasSkill(self.name) and player.room:getTag("RoundCount") == 1 + return player:hasSkill(self) and player.room:getTag("RoundCount") == 1 end, on_use = function(self, event, target, player, data) player:gainAnExtraTurn() @@ -359,8 +347,8 @@ test2.hidden = true test2:addSkill("rende") test2:addSkill(cheat) test2:addSkill(control) ---test2:addSkill(test_vs) ---test2:addSkill(test_trig) +-- test2:addSkill(test_vs) +-- test2:addSkill(test_trig) test2:addSkill(damage_maker) test2:addSkill(test_zhenggong) test2:addSkill(change_hero) @@ -390,7 +378,6 @@ Fk:loadTranslationTable{ ["$cheat"] = "喝啊!", -- ["@@test_cheat-phase"] = "苦肉", -- ["@@test_cheat-inhand"] = "连营", - --["#test_trig-ask"] = "你可弃置一张手牌", ["control"] = "控制", [":control"] = "出牌阶段,你可以控制/解除控制若干名其他角色。", ["$control"] = "战将临阵,斩关刈城!", @@ -416,8 +403,8 @@ Fk:loadTranslationTable{ ["~mouxusheng"] = "来世,愿再为我江东之臣……", ["heal_hp"] = "回复体力", - ["lose_max_hp"] = "减少体力上限", - ["heal_max_hp"] = "增加体力上限", + ["lose_max_hp"] = "减体力上限", + ["heal_max_hp"] = "加体力上限", ["revive"] = "复活", }