Roleplayer's Dice
你的角色扮演服务器在聊天中打印出 [13 out of 20]。此模组会拦截该行,为其掷骰子,并在骰子停稳显示为十三后,才允许该行通过。

仅客户端生效。服务器永远不会知道该模组的存在,无需插件支持,且关于投掷结果的任何内容都不会改变——数字在命令发送的那一刻就已经确定。该模组只是拒绝提前剧透。
投掷过程
你输入 /dice 20 strength of the blow。命令原封不动地发送给服务器;模组仅记录它已发送以及其参数。
服务器回复类似 Eliandrelle von Silverheim strength of the blow [13 out of 20]。该行不会进入聊天窗口。取而代之的是:
一颗骰子出现在屏幕中央,上方显示你的名字和你正在投掷的内容。它不像图片那样悬挂在那里:它会缓慢旋转、颤抖、每隔几秒跳动一次,并伴随着咔哒声落地——如果你忽视它越久,它就会变得越发不耐烦。一个光环围绕在它周围,因为没有什么会永远等待。

你投掷它。 点击即可触发。或者按住按钮,骰子就会出现在你手中:画面冻结,出现一个指针,骰子会略微滞后地跟随它——这种延迟体现了物体的重量。当拖拽开始时,它会顺势倾斜,随着被拖拽的方式翻倒,当你突然停止时,它会回摆。松开鼠标,它便朝着鼠标移动的方向飞出,力度取决于鼠标移动的快慢。摄像机始终保持静止,因此从外部看,投掷骰子的玩家是静止不动的,而不是对着空气猛甩头。
它落在你投掷的位置。 一声撞击,正面朝上显示巨大的数字。然后它保持静止以便阅读,移回屏幕中央,此时其他所有元素才一次性呈现——颜色、光效、声音和文字:critical failure / failure / success / critical success(大失败 / 失败 / 成功 / 大成功),下方显示 13 out of 20。
随后它淡出,它所代表的那一行按照服务器写入的格式(包括颜色、悬停提示、可点击组件等)完整地进入聊天窗口。

数字由服务器决定
骰子围绕随机轴翻滚,并在投掷的最后三分之一阶段被引导至特定面朝上,因此它最终显示的数字与服务器掷出的结果完全一致——正面朝向摄像机,直立端正,而不是停在某个随意的角度。
骰子的各个面承载不同的数字,就像真实的骰子一样:绘制时不重复,且掷出的数字会被交换到对应的获胜面上,而不是覆盖在上面。如果在二十面体的骰子上进行 d100 投掷,它将携带一百个数字中的二十个不同数字。六面骰子显示点状图案而非数字,除非你希望它显示数字。
每个人的骰子都是自己的颜色
每个玩家的骰子颜色源自其 UUID——这与 Voice Subtitles 赋予其语音的颜色相同。谁用浅绿色说话,就投掷浅绿色的骰子;在一个十人同时投掷的场景中,这比任何标题都更清晰易辨。

默认情况下,其他人的投掷结果以小尺寸显示在角落:一个小骰子位于边缘,无变暗效果,也无需点击等待——那不是由你来投掷的。关闭此选项后,他们的投掷将以全尺寸播放,如同你自己的投掷一样。
退出机制
Escape 键会将骰子收起并立即打印结果,而不会打开游戏菜单。受到伤害也会产生相同的效果:如果屏幕变暗且中间有一枚骰子,那将是身后悄悄靠近你的人极好的掩护。
此外,没有任何东西会丢失。无人点击的骰子会在超时后自动投掷,无法显示的投掷会立即释放,而你离开服务器时,所有仍持有的数据都会被打印出来。
适配你的服务器

模组读取的模式、监听的命令名称、形状、大小、声音、颜色以及所有时间间隔均位于设置中——可通过 Mod Menu 配合 Cloth Config 访问,或者如果你两者都没有,则通过模组自带的屏幕访问。
开箱即用,它可以识别 [13 out of 20]、[13 of 20] 和 [13/20],并响应 /dice、/roll 及其俄语等价命令。它能理解 /dice 20、/dice d20 和 /dice 2d6。
/rpdice demo 会投出一枚不响应任何内容的演示骰子,以便你可以针对它们所描述的项目调整滑块。
教会服务器如何书写投掷结果
每个插件的表达方式各不相同,因此模组查找的行是一个设置项:Result pattern(结果模式),这是一个包含两个捕获组的正则表达式——第一个捕获组是出现的数字,第二个捕获组是骰子的大小。这就是整个契约。默认值为
\[\s*(-?\d+)\s*(?:из|out\s+of|of|/)\s*(-?\d+)\s*]
如果你的服务器采用其他格式,请按以下方式编写:
| 服务器打印内容 |
模式 (Pattern) |
Kara persuasion [13 out of 20] |
默认值 |
Kara persuasion [13/20] |
默认值 |
Kara rolls 13 (d20) |
(\d+)\s*\(\s*d(\d+)\s*\) |
Kara rolled a 13 on a d20 |
rolled a (\d+) on a d(\d+) |
❰ Kara ❱ 13 ⁄ 20 |
(\d+)\s*[/⁄]\s*(\d+) |
Kara: 13 (max 20) |
(\d+)\s*\(max\s*(\d+)\) |
在编写自定义规则之前,有五点值得注意:
- 正则表达式是用于搜索,而非匹配整行。 它只需在行中的某个位置出现即可。
- 从数字开始匹配,而不是从行首开始。 匹配项之前的所有内容被视为名称以及掷骰子的目的,这些内容最终会显示在骰子上方。
- 两个数字都必须出现在该行中。 “大小”(size)字段用于让模组判断该掷骰结果是在响应 你的 命令,而不是别人稍早前的命令;因此,如果服务器只打印结果而不包含完整信息,则无法被正确识别。
- 已经区分大小写无关,
из、ИЗ 和 Из 均可匹配。无需使用 (?i)。
- 在设置界面中输入时,反斜杠只需输入一次:
\[\s*(\d+)。手动编辑 config/roleplayers_dice.json 文件时,JSON 格式要求将反斜杠加倍:"\\[\\s*(\\d+)"。如果正则表达式无法编译,系统会静默忽略该模式并回退到默认值,因此拼写错误不会导致聊天功能崩溃。
然后掷一次骰子。如果骰子正常显示,说明正则表达式成功找到了对应行;如果掷骰结果像往常一样直接发送到聊天框,则说明未找到匹配项。
源码与许可证
Codeberg – LGPL 3.0 或更高版本。
Roleplayer's Dice
Your roleplay server prints [13 out of 20] in the chat. This mod holds that line back, throws a die for it, and lets the line through once the die has landed on the thirteen.

Client side only. The server is never told the mod exists, needs no plugin, and nothing about the roll changes – the number was decided the moment the command was sent. The mod only refuses to spoil it.
How a roll goes
You type /dice 20 strength of the blow. The command goes to the server untouched; the mod merely notes that it went, and out of what.
The server answers with something like Eliandrelle von Silverheim strength of the blow [13 out of 20]. That line does not reach the chat. Instead:
A die appears in the middle of the screen, your name and what you are rolling for above it. It does not hang there like a picture: it turns slowly, shivers, hops every couple of seconds and lands with a rattle – and the longer it is ignored, the more impatient it gets. A ring closes around it, because nothing waits forever.

You throw it. Click and it goes. Or hold the button and the die is in your hand: the camera freezes, a pointer appears, and the die follows it a moment late – that lag is the weight of the thing. It leans into the drag as it comes, tips over the way it is being hauled, and rocks back when you stop dead. Let go and it flies where the hand was going, as hard as the hand was going. The camera never moves, so from the outside a player throwing a die stands still instead of jerking their head at nothing.
It lands where you threw it. A knock, and the number, large, on the face. Then it holds still long enough to be read, walks back to the middle, and only then does everything else arrive at once – the colour, the glow, the sound and the words: critical failure / failure / success / critical success, and 13 out of 20 beneath.
Then it fades, and the line it was standing in for goes into the chat exactly as the server wrote it, colours, hovers, clickable pieces and all.

The number is the server's number
The die tumbles about a random axis and is guided onto its face over the last third of the throw, so it lands on precisely what the server rolled – upright, square to the camera, rather than at whatever angle it happened to stop at.
The faces carry different numbers, like a real die: drawn without repeats, and the number that came up is swapped onto the winning face rather than written over it. Roll d100 on a twenty-sided body and it carries twenty different numbers out of the hundred. A six-sided die shows pips, not digits, unless you would rather it did not.
Everyone's die is their own colour
Each player's die takes its colour from their UUID – the same colour Voice Subtitles gives their speech. Whoever speaks in pale green throws pale green dice, and in a square where ten people are rolling that is clearer than any heading.

Other people's rolls come up small and out of the way by default: a little die by the edge, no dimming, no waiting to be clicked – it is not yours to throw. Turn that off and their rolls play out full size like your own.
Getting out of one
Escape puts the die away and prints the result at once, without opening the game menu. Taking damage does the same, immediately: a die in the middle of a dimmed screen is far too good a cover for whoever just walked up behind you.
And nothing is ever lost. A die nobody clicks throws itself on a timeout, a roll that cannot be shown is released on the spot, and everything still held is printed when you leave the server.
Fitting it to your server

The pattern the mod reads, the command names it watches, the shapes, the sizes, the sounds, the colours and every timing are in the settings – under Mod Menu with Cloth Config, or through a screen of the mod's own if you have neither.
Out of the box it reads [13 out of 20], [13 of 20] and [13/20], and answers to /dice, /roll and their Russian equivalents. It understands /dice 20, /dice d20 and /dice 2d6 alike.
/rpdice demo throws a die that answers to nothing, so you can set the sliders against the thing they describe.
Teaching it how your server writes a roll
Every plugin words it differently, so the line the mod looks for is a setting: Result pattern, a regular expression with two capture groups – the number that came up first, the size of the die second. That is the whole contract. The default is
\[\s*(-?\d+)\s*(?:из|out\s+of|of|/)\s*(-?\d+)\s*]
and here is what to write when your server does something else:
| The server prints |
Pattern |
Kara persuasion [13 out of 20] |
the default |
Kara persuasion [13/20] |
the default |
Kara rolls 13 (d20) |
(\d+)\s*\(\s*d(\d+)\s*\) |
Kara rolled a 13 on a d20 |
rolled a (\d+) on a d(\d+) |
❰ Kara ❱ 13 ⁄ 20 |
(\d+)\s*[/⁄]\s*(\d+) |
Kara: 13 (max 20) |
(\d+)\s*\(max\s*(\d+)\) |
Five things worth knowing before you write your own:
- The pattern is searched for, not matched against the whole line. It only has to turn up somewhere in it.
- Start it at the number, not at the start of the line. Everything in front of the match is taken as the name and what the roll was for, and that is what ends up above the die.
- Both numbers have to be in the line. The size is how the mod knows the roll is answering your command rather than somebody else's a second earlier, so a server that prints only the result cannot be followed.
- It is already case insensitive,
из, ИЗ and Из alike. No need for (?i).
- Typed in the settings screen, backslashes go in once:
\[\s*(\d+). Editing config/roleplayers_dice.json by hand, JSON wants them doubled: "\\[\\s*(\\d+)". A pattern that does not compile is quietly ignored in favour of the default, so a typo cannot take the chat down with it.
Then roll once. If the die appears, the pattern found the line; if the roll goes straight into the chat as it always did, it did not.
Source and licence
Codeberg – LGPL 3.0 or later.
评论 0
登录后参与评分
还没有评论,来抢沙发吧