-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path不定性疯狂提醒.js
102 lines (89 loc) · 3.93 KB
/
不定性疯狂提醒.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ==UserScript==
// @name 不定性疯狂提醒
// @author 错误
// @version 1.2.1
// @description 在特定指令后对san值进行不定性疯狂检测。将角色的sanmax属性作为检测不定性疯狂的san值上限(默认等于意志)。由于无法得知团内“一天”的开始和结束,故需使用指令.st sanmax数字 或 .rest 设置sanmax。
// @timestamp 1725024341
// 2024-08-30 21:25:41
// @license MIT
// @homepageURL https://github.com/error2913/sealdice-js/
// @updateUrl https://raw.githubusercontent.com/error2913/sealdice-js/main/%E4%B8%8D%E5%AE%9A%E6%80%A7%E7%96%AF%E7%8B%82%E6%8F%90%E9%86%92.js
// ==/UserScript==
let ext = seal.ext.find('insaneNotice');
if (!ext) {
ext = seal.ext.new('insaneNotice', '错误', '1.2.1');
// 注册扩展
seal.ext.register(ext);
seal.ext.registerStringConfig(ext, '不定性疯狂提醒词', '{$t玩家}已不定性疯狂。当新的“一天”开始时,可使用 .rest 重置用于检测不定性疯狂的san值上限。', '');
seal.ext.registerTemplateConfig(ext, '进行检测的指令', ['sc', 'st'], '');
function getVar(ctx, s) {
return parseInt(seal.format(ctx, `{${s}}`));
}
// 为什么数值变动时不能用intGet读取数值?害我试了半天最后改成用format读取
function checkSan(ctx, msg) {
setTimeout(() => {
const san = getVar(ctx, 'san');
if (isNaN(san)) {
return;
}
let sanmax = getVar(ctx, 'sanmax');
if (isNaN(sanmax) || sanmax === 0) {
const pow = getVar(ctx, 'pow');
if (isNaN(pow)) {
return;
}
sanmax = pow;
}
if (sanmax - san < sanmax / 5) {
return;
}
getVar(ctx, 'sanmax=-1');
const s = seal.format(ctx, seal.ext.getStringConfig(ext, '不定性疯狂提醒词'));
seal.replyToSender(ctx, msg, s);
}, 500)
}
ext.onCommandReceived = (ctx, msg, cmdArgs) => {
const command = cmdArgs.command;
const cmds = seal.ext.getTemplateConfig(ext, '进行检测的指令');
if (cmds.includes(command)) {
checkSan(ctx, msg);
}
}
const cmd = seal.ext.newCmdItemInfo();
cmd.name = 'rest';
cmd.help = `帮助: 重置sanmax值,作为检测不定性疯狂的san值上限。
【.rest】设置为当前san值
【.rest pow】设置为当前意志值
另可使用 .st sanmax数字 设置sanmax为想要的数值`;
cmd.solve = (ctx, msg, cmdArgs) => {
let val = cmdArgs.getArgN(1);
switch (val) {
case 'help': {
const ret = seal.ext.newCmdExecuteResult(true);
ret.showHelp = true;
return ret;
}
case 'pow': {
const [pow, e3] = seal.vars.intGet(ctx, 'pow');
if (!e3) {
seal.replyToSender(ctx, msg, `未检测到<${ctx.player.name}>的pow值,请用 .st 指令录入`);
return seal.ext.newCmdExecuteResult(true);
}
seal.vars.intSet(ctx, 'sanmax', pow);
seal.replyToSender(ctx, msg, `<${ctx.player.name}>的sanmax已设置为${pow}`);
return seal.ext.newCmdExecuteResult(true);
}
default: {
const [san, e1] = seal.vars.intGet(ctx, 'san');
if (!e1) {
seal.replyToSender(ctx, msg, `未检测到<${ctx.player.name}>的san值,请用 .st 指令录入`);
return seal.ext.newCmdExecuteResult(true);
}
seal.vars.intSet(ctx, 'sanmax', san);
seal.replyToSender(ctx, msg, `<${ctx.player.name}>的sanmax已设置为${san}`);
return seal.ext.newCmdExecuteResult(true);
}
}
};
ext.cmdMap['rest'] = cmd;
}