各种bug fix (#241)

- 修复只观顶时出错的bug
- 修复主公框和正常框有重复将的bug
- 添加getN,帮助获得数组前/后X项

---------

Co-authored-by: notify <notify-ctrl@qq.com>
This commit is contained in:
YoumuKon 2023-08-11 03:24:22 +08:00 committed by GitHub
parent a82b8c1b0a
commit aa05984522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 70 deletions

View File

@ -53,9 +53,9 @@ end
--- Determine whether a target can be selected by this skill(in modifying targets) --- Determine whether a target can be selected by this skill(in modifying targets)
--- only used in skill of players --- only used in skill of players
---@param to_select integer @ id of the target ---@param to_select integer @ id of the target
---@param selected integer[] @ ids of selected targets ---@param selected nil|integer[] @ ids of selected targets
---@param user integer @ id of the userdata ---@param user nil|integer @ id of the userdata
---@param card Card @ helper ---@param card nil|Card @ helper
---@param distance_limited boolean @ is limited by distance ---@param distance_limited boolean @ is limited by distance
function ActiveSkill:modTargetFilter(to_select, selected, user, card, distance_limited) function ActiveSkill:modTargetFilter(to_select, selected, user, card, distance_limited)
return false return false

View File

@ -300,7 +300,7 @@ function table:slice(begin, _end)
if begin >= _end then return {} end if begin >= _end then return {} end
local ret = {} local ret = {}
for i = begin, _end - 1, 1 do for i = math.max(begin, 1), math.min(_end - 1, len), 1 do
table.insert(ret, self[i]) table.insert(ret, self[i])
end end
return ret return ret
@ -355,6 +355,7 @@ end
-- override default string.len -- override default string.len
string.rawlen = string.len string.rawlen = string.len
---@diagnostic disable-next-line: duplicate-set-field
function string:len() function string:len()
return utf8.len(self) return utf8.len(self)
end end

View File

@ -70,25 +70,26 @@ local function readStatusSpecToSkill(skill, spec)
end end
---@class UsableSkillSpec: UsableSkill ---@class UsableSkillSpec: UsableSkill
---@field public max_phase_use_time integer ---@field public max_phase_use_time nil|integer
---@field public max_turn_use_time integer ---@field public max_turn_use_time nil|integer
---@field public max_round_use_time integer ---@field public max_round_use_time nil|integer
---@field public max_game_use_time integer ---@field public max_game_use_time nil|integer
---@class StatusSkillSpec: StatusSkill ---@class StatusSkillSpec: StatusSkill
---@alias TrigFunc fun(self: TriggerSkill, event: Event, target: ServerPlayer, player: ServerPlayer, data: any):boolean|nil ---@alias TrigFunc fun(self: TriggerSkill, event: Event, target: ServerPlayer, player: ServerPlayer, data: any):boolean|nil
---@class TriggerSkillSpec: UsableSkillSpec ---@class TriggerSkillSpec: UsableSkillSpec
---@field public global boolean ---@field public global nil|boolean
---@field public events Event | Event[] ---@field public events nil|Event | Event[]
---@field public refresh_events Event | Event[] ---@field public refresh_events nil|Event | Event[]
---@field public priority number | table<Event, number> ---@field public priority nil|number | table<Event, number>
---@field public on_trigger TrigFunc ---@field public on_trigger nil|TrigFunc
---@field public can_trigger TrigFunc ---@field public can_trigger nil|TrigFunc
---@field public on_cost TrigFunc ---@field public on_cost nil|TrigFunc
---@field public on_use TrigFunc ---@field public on_use nil|TrigFunc
---@field public on_refresh TrigFunc ---@field public on_refresh nil|TrigFunc
---@field public can_refresh TrigFunc ---@field public can_refresh nil|TrigFunc
---@field public can_wake nil|TrigFunc
---@param spec TriggerSkillSpec ---@param spec TriggerSkillSpec
---@return TriggerSkill ---@return TriggerSkill
@ -164,16 +165,17 @@ function fk.CreateTriggerSkill(spec)
end end
---@class ActiveSkillSpec: UsableSkillSpec ---@class ActiveSkillSpec: UsableSkillSpec
---@field public can_use fun(self: ActiveSkill, player: Player, card: Card): boolean|nil ---@field public can_use nil|fun(self: ActiveSkill, player: Player, card: Card): boolean|nil
---@field public card_filter fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_targets: integer[]): boolean|nil ---@field public card_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_targets: integer[]): boolean|nil
---@field public target_filter fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_cards: integer[], card: Card): boolean|nil ---@field public target_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_cards: integer[], card: Card): boolean|nil
---@field public feasible fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): boolean|nil ---@field public feasible nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): boolean|nil
---@field public on_use fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct): boolean|nil ---@field public on_use nil|fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct): boolean|nil
---@field public about_to_effect fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil ---@field public about_to_effect nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil
---@field public on_effect fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil ---@field public on_effect nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil
---@field public on_nullified fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil ---@field public on_nullified nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil
---@field public mod_target_filter fun(self: ActiveSkill, to_select: integer, selected: integer[], user: integer, card: Card, distance_limited: boolean): boolean|nil ---@field public mod_target_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], user: integer, card: Card, distance_limited: boolean): boolean|nil
---@field public prompt fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string ---@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@field public interaction any
---@param spec ActiveSkillSpec ---@param spec ActiveSkillSpec
---@return ActiveSkill ---@return ActiveSkill
@ -215,13 +217,13 @@ function fk.CreateActiveSkill(spec)
end end
---@class ViewAsSkillSpec: UsableSkillSpec ---@class ViewAsSkillSpec: UsableSkillSpec
---@field public card_filter fun(self: ViewAsSkill, to_select: integer, selected: integer[]): boolean|nil ---@field public card_filter nil|fun(self: ViewAsSkill, to_select: integer, selected: integer[]): boolean|nil
---@field public view_as fun(self: ViewAsSkill, cards: integer[]): Card|nil ---@field public view_as fun(self: ViewAsSkill, cards: integer[]): Card|nil
---@field public pattern string ---@field public pattern nil|string
---@field public enabled_at_play fun(self: ViewAsSkill, player: Player): boolean|nil ---@field public enabled_at_play nil|fun(self: ViewAsSkill, player: Player): boolean|nil
---@field public enabled_at_response fun(self: ViewAsSkill, player: Player, response: boolean): boolean|nil ---@field public enabled_at_response nil|fun(self: ViewAsSkill, player: Player, response: boolean): boolean|nil
---@field public before_use fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct) ---@field public before_use nil|fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct)
---@field public prompt fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string ---@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@param spec ViewAsSkillSpec ---@param spec ViewAsSkillSpec
---@return ViewAsSkill ---@return ViewAsSkill
@ -271,8 +273,8 @@ function fk.CreateViewAsSkill(spec)
end end
---@class DistanceSpec: StatusSkillSpec ---@class DistanceSpec: StatusSkillSpec
---@field public correct_func fun(self: DistanceSkill, from: Player, to: Player): integer|nil ---@field public correct_func nil|fun(self: DistanceSkill, from: Player, to: Player): integer|nil
---@field public fixed_func fun(self: DistanceSkill, from: Player, to: Player): integer|nil ---@field public fixed_func nil|fun(self: DistanceSkill, from: Player, to: Player): integer|nil
---@param spec DistanceSpec ---@param spec DistanceSpec
---@return DistanceSkill ---@return DistanceSkill
@ -289,10 +291,10 @@ function fk.CreateDistanceSkill(spec)
end end
---@class ProhibitSpec: StatusSkillSpec ---@class ProhibitSpec: StatusSkillSpec
---@field public is_prohibited fun(self: ProhibitSkill, from: Player, to: Player, card: Card): boolean|nil ---@field public is_prohibited nil|fun(self: ProhibitSkill, from: Player, to: Player, card: Card): boolean|nil
---@field public prohibit_use fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil ---@field public prohibit_use nil|fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil
---@field public prohibit_response fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil ---@field public prohibit_response nil|fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil
---@field public prohibit_discard fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil ---@field public prohibit_discard nil|fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil
---@param spec ProhibitSpec ---@param spec ProhibitSpec
---@return ProhibitSkill ---@return ProhibitSkill
@ -310,8 +312,8 @@ function fk.CreateProhibitSkill(spec)
end end
---@class AttackRangeSpec: StatusSkillSpec ---@class AttackRangeSpec: StatusSkillSpec
---@field public correct_func fun(self: AttackRangeSkill, from: Player, to: Player): number|nil ---@field public correct_func nil|fun(self: AttackRangeSkill, from: Player, to: Player): number|nil
---@field public within_func fun(self: AttackRangeSkill, from: Player, to: Player): boolean|nil ---@field public within_func nil|fun(self: AttackRangeSkill, from: Player, to: Player): boolean|nil
---@param spec AttackRangeSpec ---@param spec AttackRangeSpec
---@return AttackRangeSkill ---@return AttackRangeSkill
@ -332,9 +334,9 @@ function fk.CreateAttackRangeSkill(spec)
end end
---@class MaxCardsSpec: StatusSkillSpec ---@class MaxCardsSpec: StatusSkillSpec
---@field public correct_func fun(self: MaxCardsSkill, player: Player): number|nil ---@field public correct_func nil|fun(self: MaxCardsSkill, player: Player): number|nil
---@field public fixed_func fun(self: MaxCardsSkill, player: Player): number|nil ---@field public fixed_func nil|fun(self: MaxCardsSkill, player: Player): number|nil
---@field public exclude_from fun(self: MaxCardsSkill, player: Player, card: Card): boolean|nil ---@field public exclude_from nil|fun(self: MaxCardsSkill, player: Player, card: Card): boolean|nil
---@param spec MaxCardsSpec ---@param spec MaxCardsSpec
---@return MaxCardsSkill ---@return MaxCardsSkill
@ -356,11 +358,11 @@ function fk.CreateMaxCardsSkill(spec)
end end
---@class TargetModSpec: StatusSkillSpec ---@class TargetModSpec: StatusSkillSpec
---@field public bypass_times fun(self: TargetModSkill, player: Player, skill: ActiveSkill, scope: integer, card: Card, to: Player): boolean|nil ---@field public bypass_times nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, scope: integer, card: Card, to: Player): boolean|nil
---@field public residue_func fun(self: TargetModSkill, player: Player, skill: ActiveSkill, scope: integer, card: Card, to: Player): number|nil ---@field public residue_func nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, scope: integer, card: Card, to: Player): number|nil
---@field public bypass_distances fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card, to: Player): boolean|nil ---@field public bypass_distances nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card, to: Player): boolean|nil
---@field public distance_limit_func fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card, to: Player): number|nil ---@field public distance_limit_func nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card, to: Player): number|nil
---@field public extra_target_func fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card): number|nil ---@field public extra_target_func nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card): number|nil
---@param spec TargetModSpec ---@param spec TargetModSpec
---@return TargetModSkill ---@return TargetModSkill
@ -389,8 +391,8 @@ function fk.CreateTargetModSkill(spec)
end end
---@class FilterSpec: StatusSkillSpec ---@class FilterSpec: StatusSkillSpec
---@field public card_filter fun(self: FilterSkill, card: Card, player: Player): boolean|nil ---@field public card_filter nil|fun(self: FilterSkill, card: Card, player: Player): boolean|nil
---@field public view_as fun(self: FilterSkill, card: Card, player: Player): Card|nil ---@field public view_as nil|fun(self: FilterSkill, card: Card, player: Player): Card|nil
---@param spec FilterSpec ---@param spec FilterSpec
---@return FilterSkill ---@return FilterSkill
@ -406,7 +408,7 @@ function fk.CreateFilterSkill(spec)
end end
---@class InvaliditySpec: StatusSkillSpec ---@class InvaliditySpec: StatusSkillSpec
---@field public invalidity_func fun(self: InvaliditySkill, from: Player, skill: Skill): boolean|nil ---@field public invalidity_func nil|fun(self: InvaliditySkill, from: Player, skill: Skill): boolean|nil
---@param spec InvaliditySpec ---@param spec InvaliditySpec
---@return InvaliditySkill ---@return InvaliditySkill
@ -421,11 +423,11 @@ function fk.CreateInvaliditySkill(spec)
end end
---@class CardSpec: Card ---@class CardSpec: Card
---@field public skill Skill ---@field public skill nil|Skill
---@field public equip_skill Skill ---@field public equip_skill nil|Skill
---@field public special_skills string[] | nil ---@field public special_skills string[] | nil
---@field public is_damage_card boolean ---@field public is_damage_card nil|boolean
---@field public multiple_targets boolean ---@field public multiple_targets nil|boolean
local defaultCardSkill = fk.CreateActiveSkill{ local defaultCardSkill = fk.CreateActiveSkill{
name = "default_card_skill", name = "default_card_skill",

View File

@ -93,16 +93,13 @@ function GameLogic:chooseGenerals()
local generals = {} local generals = {}
local lordlist = {} local lordlist = {}
local lordpools = {} 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 if room.settings.gameMode == "aaa_role_mode" then
for _, general in pairs(Fk:getAllGenerals()) do for _, general in pairs(Fk:getAllGenerals()) do
if (not general.hidden and not general.total_hidden) and if (not general.hidden and not general.total_hidden) and
table.find(general.skills, function(s) table.find(general.skills, function(s)
return s.lordSkill return s.lordSkill
end) and end) and
not table.find(generals, function(g) not table.find(lordlist, function(g)
return g.trueName == general.trueName return g.trueName == general.trueName
end) then end) then
table.insert(lordlist, general) table.insert(lordlist, general)
@ -110,6 +107,9 @@ function GameLogic:chooseGenerals()
end end
lordlist = table.random(lordlist, 3) or {} lordlist = table.random(lordlist, 3) or {}
end end
table.insertTable(generals, Fk:getGeneralsRandomly(generalNum, Fk:getAllGenerals(), nil, function(g)
return table.contains(table.map(lordlist, function(g) return g.trueName end), g.trueName)
end))
for i = 1, #generals do for i = 1, #generals do
generals[i] = generals[i].name generals[i] = generals[i].name
end end

View File

@ -242,7 +242,7 @@ end
--- 基本算是私有函数,别去用 --- 基本算是私有函数,别去用
---@param cardId integer ---@param cardId integer
---@param cardArea CardArea ---@param cardArea CardArea
---@param owner integer ---@param owner nil|integer
function Room:setCardArea(cardId, cardArea, owner) function Room:setCardArea(cardId, cardArea, owner)
self.card_place[cardId] = cardArea self.card_place[cardId] = cardArea
self.owner_map[cardId] = owner self.owner_map[cardId] = owner
@ -1550,11 +1550,11 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif
if result ~= "" then if result ~= "" then
local d = json.decode(result) local d = json.decode(result)
if #top_limit > 0 and top_limit[2] == 0 then if #top_limit > 0 and top_limit[2] == 0 then
top = {} top = Util.DummyTable
bottom = d[1] bottom = d[1]
else else
top = d[1] top = d[1]
bottom = d[2] bottom = d[2] or Util.DummyTable
end end
else else
top = table.random(cards, top_limit and top_limit[2] or #cards) or Util.DummyTable top = table.random(cards, top_limit and top_limit[2] or #cards) or Util.DummyTable

View File

@ -1,5 +1,7 @@
-- SPDX-License-Identifier: GPL-3.0-or-later -- SPDX-License-Identifier: GPL-3.0-or-later
---@alias PlayerId integer
---@class CardsMoveInfo ---@class CardsMoveInfo
---@field public ids integer[] ---@field public ids integer[]
---@field public from integer|null ---@field public from integer|null
@ -60,10 +62,10 @@ fk.IceDamage = 4
---@field public to ServerPlayer @ 伤害目标 ---@field public to ServerPlayer @ 伤害目标
---@field public damage integer @ 伤害值 ---@field public damage integer @ 伤害值
---@field public card Card | nil @ 造成伤害的牌 ---@field public card Card | nil @ 造成伤害的牌
---@field public chain boolean @ 伤害是否是铁索传导的伤害 ---@field public chain boolean | nil @ 伤害是否是铁索传导的伤害
---@field public damageType DamageType @ 伤害的属性 ---@field public damageType DamageType | nil @ 伤害的属性
---@field public skillName string @ 造成本次伤害的技能名 ---@field public skillName string | nil @ 造成本次伤害的技能名
---@field public beginnerOfTheDamage boolean @ 是否是本次铁索传导的起点 ---@field public beginnerOfTheDamage boolean | nil @ 是否是本次铁索传导的起点
--- 用来描述和回复体力有关的数据。 --- 用来描述和回复体力有关的数据。
---@class RecoverStruct ---@class RecoverStruct
@ -88,7 +90,7 @@ fk.IceDamage = 4
---@field public card Card ---@field public card Card
---@field public toCard Card|null ---@field public toCard Card|null
---@field public responseToEvent CardUseStruct|null ---@field public responseToEvent CardUseStruct|null
---@field public nullifiedTargets interger[]|null ---@field public nullifiedTargets integer[]|null
---@field public extraUse boolean|null ---@field public extraUse boolean|null
---@field public disresponsiveList integer[]|null ---@field public disresponsiveList integer[]|null
---@field public unoffsetableList integer[]|null ---@field public unoffsetableList integer[]|null
@ -123,7 +125,7 @@ fk.IceDamage = 4
---@field public card Card ---@field public card Card
---@field public toCard Card|null ---@field public toCard Card|null
---@field public responseToEvent CardEffectEvent|null ---@field public responseToEvent CardEffectEvent|null
---@field public nullifiedTargets interger[]|null ---@field public nullifiedTargets integer[]|null
---@field public extraUse boolean|null ---@field public extraUse boolean|null
---@field public disresponsiveList integer[]|null ---@field public disresponsiveList integer[]|null
---@field public unoffsetableList integer[]|null ---@field public unoffsetableList integer[]|null

View File

@ -10,6 +10,9 @@ TestExppattern = {
p(table.connectIfNeed(table1, table2)) p(table.connectIfNeed(table1, table2))
p(table1) p(table1)
p(table2) p(table2)
p(table.slice(table1,3,4))
p(table.slice(table1,1,6))
p(table.slice(table1,-2,-1))
end, end,
testMatchExp = function() testMatchExp = function()