diff --git a/lua/core/skill_type/active.lua b/lua/core/skill_type/active.lua index c9d61fb9..fb7e7f61 100644 --- a/lua/core/skill_type/active.lua +++ b/lua/core/skill_type/active.lua @@ -53,9 +53,9 @@ end --- Determine whether a target can be selected by this skill(in modifying targets) --- only used in skill of players ---@param to_select integer @ id of the target ----@param selected integer[] @ ids of selected targets ----@param user integer @ id of the userdata ----@param card Card @ helper +---@param selected nil|integer[] @ ids of selected targets +---@param user nil|integer @ id of the userdata +---@param card nil|Card @ helper ---@param distance_limited boolean @ is limited by distance function ActiveSkill:modTargetFilter(to_select, selected, user, card, distance_limited) return false diff --git a/lua/core/util.lua b/lua/core/util.lua index 9ecb8976..29dd095b 100644 --- a/lua/core/util.lua +++ b/lua/core/util.lua @@ -300,7 +300,7 @@ function table:slice(begin, _end) if begin >= _end then return {} end 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]) end return ret @@ -355,6 +355,7 @@ end -- override default string.len string.rawlen = string.len +---@diagnostic disable-next-line: duplicate-set-field function string:len() return utf8.len(self) end diff --git a/lua/fk_ex.lua b/lua/fk_ex.lua index 09449c7a..fb94c48f 100644 --- a/lua/fk_ex.lua +++ b/lua/fk_ex.lua @@ -70,25 +70,26 @@ local function readStatusSpecToSkill(skill, spec) end ---@class UsableSkillSpec: UsableSkill ----@field public max_phase_use_time integer ----@field public max_turn_use_time integer ----@field public max_round_use_time integer ----@field public max_game_use_time integer +---@field public max_phase_use_time nil|integer +---@field public max_turn_use_time nil|integer +---@field public max_round_use_time nil|integer +---@field public max_game_use_time nil|integer ---@class StatusSkillSpec: StatusSkill ---@alias TrigFunc fun(self: TriggerSkill, event: Event, target: ServerPlayer, player: ServerPlayer, data: any):boolean|nil ---@class TriggerSkillSpec: UsableSkillSpec ----@field public global boolean ----@field public events Event | Event[] ----@field public refresh_events Event | Event[] ----@field public priority number | table ----@field public on_trigger TrigFunc ----@field public can_trigger TrigFunc ----@field public on_cost TrigFunc ----@field public on_use TrigFunc ----@field public on_refresh TrigFunc ----@field public can_refresh TrigFunc +---@field public global nil|boolean +---@field public events nil|Event | Event[] +---@field public refresh_events nil|Event | Event[] +---@field public priority nil|number | table +---@field public on_trigger nil|TrigFunc +---@field public can_trigger nil|TrigFunc +---@field public on_cost nil|TrigFunc +---@field public on_use nil|TrigFunc +---@field public on_refresh nil|TrigFunc +---@field public can_refresh nil|TrigFunc +---@field public can_wake nil|TrigFunc ---@param spec TriggerSkillSpec ---@return TriggerSkill @@ -164,16 +165,17 @@ function fk.CreateTriggerSkill(spec) end ---@class ActiveSkillSpec: UsableSkillSpec ----@field public can_use 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 target_filter 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 on_use 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 on_effect fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean|nil ----@field public on_nullified 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 prompt fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public can_use nil|fun(self: ActiveSkill, player: Player, card: Card): boolean|nil +---@field public card_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_targets: integer[]): 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 nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): boolean|nil +---@field public on_use nil|fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct): boolean|nil +---@field public about_to_effect nil|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 nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): 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 nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public interaction any ---@param spec ActiveSkillSpec ---@return ActiveSkill @@ -215,13 +217,13 @@ function fk.CreateActiveSkill(spec) end ---@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 pattern string ----@field public enabled_at_play fun(self: ViewAsSkill, player: Player): boolean|nil ----@field public enabled_at_response fun(self: ViewAsSkill, player: Player, response: boolean): boolean|nil ----@field public before_use fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct) ----@field public prompt fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string +---@field public pattern nil|string +---@field public enabled_at_play nil|fun(self: ViewAsSkill, player: Player): boolean|nil +---@field public enabled_at_response nil|fun(self: ViewAsSkill, player: Player, response: boolean): boolean|nil +---@field public before_use nil|fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct) +---@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string ---@param spec ViewAsSkillSpec ---@return ViewAsSkill @@ -271,8 +273,8 @@ function fk.CreateViewAsSkill(spec) end ---@class DistanceSpec: StatusSkillSpec ----@field public correct_func fun(self: DistanceSkill, from: Player, to: Player): integer|nil ----@field public fixed_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 nil|fun(self: DistanceSkill, from: Player, to: Player): integer|nil ---@param spec DistanceSpec ---@return DistanceSkill @@ -289,10 +291,10 @@ function fk.CreateDistanceSkill(spec) end ---@class ProhibitSpec: StatusSkillSpec ----@field public is_prohibited 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_response fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil ----@field public prohibit_discard fun(self: ProhibitSkill, player: 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 nil|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 nil|fun(self: ProhibitSkill, player: Player, card: Card): boolean|nil ---@param spec ProhibitSpec ---@return ProhibitSkill @@ -310,8 +312,8 @@ function fk.CreateProhibitSkill(spec) end ---@class AttackRangeSpec: StatusSkillSpec ----@field public correct_func fun(self: AttackRangeSkill, from: Player, to: Player): number|nil ----@field public within_func fun(self: AttackRangeSkill, from: Player, to: Player): boolean|nil +---@field public correct_func nil|fun(self: AttackRangeSkill, from: Player, to: Player): number|nil +---@field public within_func nil|fun(self: AttackRangeSkill, from: Player, to: Player): boolean|nil ---@param spec AttackRangeSpec ---@return AttackRangeSkill @@ -332,9 +334,9 @@ function fk.CreateAttackRangeSkill(spec) end ---@class MaxCardsSpec: StatusSkillSpec ----@field public correct_func fun(self: MaxCardsSkill, player: Player): number|nil ----@field public fixed_func fun(self: MaxCardsSkill, player: Player): number|nil ----@field public exclude_from fun(self: MaxCardsSkill, player: Player, card: Card): boolean|nil +---@field public correct_func nil|fun(self: MaxCardsSkill, player: Player): number|nil +---@field public fixed_func nil|fun(self: MaxCardsSkill, player: Player): number|nil +---@field public exclude_from nil|fun(self: MaxCardsSkill, player: Player, card: Card): boolean|nil ---@param spec MaxCardsSpec ---@return MaxCardsSkill @@ -356,11 +358,11 @@ function fk.CreateMaxCardsSkill(spec) end ---@class TargetModSpec: StatusSkillSpec ----@field public bypass_times 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 bypass_distances 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 extra_target_func fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card): number|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 nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, scope: integer, card: Card, to: Player): number|nil +---@field public bypass_distances nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card, to: Player): boolean|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 nil|fun(self: TargetModSkill, player: Player, skill: ActiveSkill, card: Card): number|nil ---@param spec TargetModSpec ---@return TargetModSkill @@ -389,8 +391,8 @@ function fk.CreateTargetModSkill(spec) end ---@class FilterSpec: StatusSkillSpec ----@field public card_filter fun(self: FilterSkill, card: Card, player: Player): boolean|nil ----@field public view_as fun(self: FilterSkill, card: Card, player: Player): Card|nil +---@field public card_filter nil|fun(self: FilterSkill, card: Card, player: Player): boolean|nil +---@field public view_as nil|fun(self: FilterSkill, card: Card, player: Player): Card|nil ---@param spec FilterSpec ---@return FilterSkill @@ -406,7 +408,7 @@ function fk.CreateFilterSkill(spec) end ---@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 ---@return InvaliditySkill @@ -421,11 +423,11 @@ function fk.CreateInvaliditySkill(spec) end ---@class CardSpec: Card ----@field public skill Skill ----@field public equip_skill Skill +---@field public skill nil|Skill +---@field public equip_skill nil|Skill ---@field public special_skills string[] | nil ----@field public is_damage_card boolean ----@field public multiple_targets boolean +---@field public is_damage_card nil|boolean +---@field public multiple_targets nil|boolean local defaultCardSkill = fk.CreateActiveSkill{ name = "default_card_skill", diff --git a/lua/server/gamelogic.lua b/lua/server/gamelogic.lua index 1507b2fb..186b3ec3 100644 --- a/lua/server/gamelogic.lua +++ b/lua/server/gamelogic.lua @@ -93,16 +93,13 @@ function GameLogic:chooseGenerals() 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 table.find(general.skills, function(s) return s.lordSkill end) and - not table.find(generals, function(g) + not table.find(lordlist, function(g) return g.trueName == general.trueName end) then table.insert(lordlist, general) @@ -110,6 +107,9 @@ function GameLogic:chooseGenerals() end lordlist = table.random(lordlist, 3) or {} 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 generals[i] = generals[i].name end diff --git a/lua/server/room.lua b/lua/server/room.lua index fec16da7..dbdcd035 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -242,7 +242,7 @@ end --- 基本算是私有函数,别去用 ---@param cardId integer ---@param cardArea CardArea ----@param owner integer +---@param owner nil|integer function Room:setCardArea(cardId, cardArea, owner) self.card_place[cardId] = cardArea self.owner_map[cardId] = owner @@ -1550,11 +1550,11 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif if result ~= "" then local d = json.decode(result) if #top_limit > 0 and top_limit[2] == 0 then - top = {} + top = Util.DummyTable bottom = d[1] else top = d[1] - bottom = d[2] + bottom = d[2] or Util.DummyTable end else top = table.random(cards, top_limit and top_limit[2] or #cards) or Util.DummyTable diff --git a/lua/server/system_enum.lua b/lua/server/system_enum.lua index b3907cf6..23814ab7 100644 --- a/lua/server/system_enum.lua +++ b/lua/server/system_enum.lua @@ -1,5 +1,7 @@ -- SPDX-License-Identifier: GPL-3.0-or-later +---@alias PlayerId integer + ---@class CardsMoveInfo ---@field public ids integer[] ---@field public from integer|null @@ -60,10 +62,10 @@ fk.IceDamage = 4 ---@field public to ServerPlayer @ 伤害目标 ---@field public damage integer @ 伤害值 ---@field public card Card | nil @ 造成伤害的牌 ----@field public chain boolean @ 伤害是否是铁索传导的伤害 ----@field public damageType DamageType @ 伤害的属性 ----@field public skillName string @ 造成本次伤害的技能名 ----@field public beginnerOfTheDamage boolean @ 是否是本次铁索传导的起点 +---@field public chain boolean | nil @ 伤害是否是铁索传导的伤害 +---@field public damageType DamageType | nil @ 伤害的属性 +---@field public skillName string | nil @ 造成本次伤害的技能名 +---@field public beginnerOfTheDamage boolean | nil @ 是否是本次铁索传导的起点 --- 用来描述和回复体力有关的数据。 ---@class RecoverStruct @@ -88,7 +90,7 @@ fk.IceDamage = 4 ---@field public card Card ---@field public toCard Card|null ---@field public responseToEvent CardUseStruct|null ----@field public nullifiedTargets interger[]|null +---@field public nullifiedTargets integer[]|null ---@field public extraUse boolean|null ---@field public disresponsiveList integer[]|null ---@field public unoffsetableList integer[]|null @@ -123,7 +125,7 @@ fk.IceDamage = 4 ---@field public card Card ---@field public toCard Card|null ---@field public responseToEvent CardEffectEvent|null ----@field public nullifiedTargets interger[]|null +---@field public nullifiedTargets integer[]|null ---@field public extraUse boolean|null ---@field public disresponsiveList integer[]|null ---@field public unoffsetableList integer[]|null diff --git a/test/lua/pattern.lua b/test/lua/pattern.lua index e3f95985..e8cecad3 100644 --- a/test/lua/pattern.lua +++ b/test/lua/pattern.lua @@ -10,6 +10,9 @@ TestExppattern = { p(table.connectIfNeed(table1, table2)) p(table1) p(table2) + p(table.slice(table1,3,4)) + p(table.slice(table1,1,6)) + p(table.slice(table1,-2,-1)) end, testMatchExp = function()