Skip to content

Beatmap Ruleset Expression

StageGuard edited this page Sep 24, 2021 · 8 revisions

总览

规则表达式是一串 JavaScript 表达式,通过 eval(表达式) 执行的结果来筛选符合条件的谱面。

可能需要你掌握基础的 JavaScript 语法之后才能看懂。

类似这样的过程:

let beatmap = BeatmapPool.filter(type => 表达式);

表达式规则

  • 表达式必须要返回一个 Column<boolean> 类型。

  • 可以多行表达式,但是要在最后返回 Column<boolean> 类型变量。

  • Column 变量的四则运算和逻辑判断只可以通过下方的 API 方法操作,不可用运算符和逻辑判断符。

表达式中可用的变量

变量名 类型 解释
bid Column<number> 谱面 ID
star Column<number> 星级
bpm Column<number> BPM
length Column<number> 长度(秒)
ar Column<number> 缩圈速度
od Column<number> 判定精度
cs Column<number> 圈的大小
hp Column<number> 生命衰减
jump Column<number> PP+ jump 指数
flow Column<number> PP+ flow 指数
speed Column<number> PP+ speed 指数
stamina Column<number> PP+ stamina 指数
precision Column<number> PP+ precision 指数
accuracy Column<number> PP+ accuracy 指数
recommendStar number 给这个玩家推荐的星级
matchIndex number 匹配的触发词序号
matchGroup string[] 匹配的触发词匹配捕获组

matchIndexmatchGroup

触发词中允许正则表达式匹配,如果想使用正则表达式捕获组捕获匹配后的具体内容,可以借助 matchIndexmatchGroup 变量。

例如:某个规则的触发词有: xx推荐好, xx推荐(.)星(.?)xx的优质 (注意有顺序)

  • 使用 来点xx推荐好图 触发这条规则时,表达式中的 matchIndex0 (第一个触发词),matchGroup 为 空数组(因为 xx推荐好 触发词不包含任何捕获组)。

  • 使用 来点xx推荐四星跳图 触发这条规则时,表达式中的 matchIndex1 (第二个触发词),matchGroup["四", "跳"]

  • 使用 来点xx推荐四星图 触发这条规则时,表达式中的 matchIndex1 (第二个触发词),matchGroup["四", ""]

  • 使用 来点xx的优质图 触发这条规则时,表达式中的 matchIndex2 (第三个触发词),matchGroup 为 空数组。

Column 类方法 和 其他工具函数

Column<T : any>

泛型 T 表示所有 Column 类型均有的方法。

  • function eq(other: Column<T> | T) : Column<boolean>

进行相等判断 this == other

  • function notEq(other: Column<T> | T) : Column<boolean>

进行不相等判断相等判断 this != other

Column<boolean>

  • function and(other: Column<boolean> | boolean) : Column<boolean>

进行和逻辑判断 this && other

  • function or(other: Column<boolean> | boolean) : Column<boolean>

进行或逻辑判断 this || other

  • function xor(other: Column<boolean> | boolean) : Column<boolean>

进行异或逻辑判断 !this ^ !other

Column<number>

  • function plus(other: Column<number> | number) : Column<number>

进行加法运算 this + other

  • function minus(other: Column<number> | number) : Column<number>

进行减法运算 this - other

  • function times(other: Column<number> | number) : Column<number>

进行乘法运算 this * other

  • function div(other: Column<number> | number) : Column<number>

进行除法运算 this / other

  • function rem(other: Column<number> | number) : Column<number>

进行余数运算 this % other

  • function less(other: Column<number> | number) : Column<boolean>

进行小于判断 this < other

  • function lessEq(other: Column<number> | number) : Column<boolean>

进行小于等于判断 this <= other

  • function greater(other: Column<number> | number) : Column<boolean>

进行大于判断 this > other

  • function greaterEq(other: Column<number> | number) : Column<boolean>

进行大于等于判断 this >= other

工具函数

  • function contains(beatmap: number[]) : Column<boolean>

bid.eq(beatmap[0]).or(bid.eq(beatmap[1])).or(bid.eq(beatmap[2])).or(...) 的简便写法,用于表示谱面 ID 是否包含于 beatmap 列表。

例子

  • contains([2153932, 2657188, 1751327, 2049347, 2470722, 2226975])

只从指定的 BID 里随机选择谱面,可以用于做一个固定谱面池 Collection。

  • contains([2153932, 2657188, 1751327, 2049347, 2470722, 2226975]).and(star.greater(5.0))

只从指定的 BID 里选取星级大于 5 的谱面。

  • star.greaterEq(recommendStar - 0.2).and(star.lessEq(recommendStar + 0.2))

从星级在 [-0.2 + recommendStar, +0.2 + recommendStar] 随机选择谱面。

简单来说就是从玩家推荐星级附近中选择。

  • star.greaterEq(recommendStar - 0.2).and(star.lessEq(recommendStar + 0.2)).and(flow.less(0.1))

从玩家推荐星级附近中选择 flow 值小于 0.1 的谱面(偏跳)。

  • bpm.greater(200.0).and(ar.lessEq(8.0)).and(star.greater(5.0))

寄吧图。

Clone this wiki locally