mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 06:03:09 +02:00
Resolve #4853
This commit is contained in:
parent
73641fd78d
commit
7aa66f438f
3 changed files with 25 additions and 0 deletions
|
@ -2059,6 +2059,9 @@ pages:
|
||||||
_seedRandomPick:
|
_seedRandomPick:
|
||||||
arg1: "シード"
|
arg1: "シード"
|
||||||
arg2: "リスト"
|
arg2: "リスト"
|
||||||
|
dailyRPWPM: "確率付きリストからランダムに選択 (ユーザーごとに日替わり)"
|
||||||
|
_ddailyRPWPM:
|
||||||
|
arg1: "テキストのリスト"
|
||||||
number: "数値"
|
number: "数値"
|
||||||
stringToNumber: "テキストを数値に"
|
stringToNumber: "テキストを数値に"
|
||||||
_stringToNumber:
|
_stringToNumber:
|
||||||
|
|
|
@ -178,6 +178,27 @@ export class ASEvaluator {
|
||||||
seedRandom: (seed: any, probability: number) => Math.floor(seedrandom(seed)() * 100) < probability,
|
seedRandom: (seed: any, probability: number) => Math.floor(seedrandom(seed)() * 100) < probability,
|
||||||
seedRannum: (seed: any, min: number, max: number) => min + Math.floor(seedrandom(seed)() * (max - min + 1)),
|
seedRannum: (seed: any, min: number, max: number) => min + Math.floor(seedrandom(seed)() * (max - min + 1)),
|
||||||
seedRandomPick: (seed: any, list: any[]) => list[Math.floor(seedrandom(seed)() * list.length)],
|
seedRandomPick: (seed: any, list: any[]) => list[Math.floor(seedrandom(seed)() * list.length)],
|
||||||
|
dailyRPWPM: (list: string[]) => {
|
||||||
|
const xs = [];
|
||||||
|
let totalFactor = 0;
|
||||||
|
for (const x of list) {
|
||||||
|
const parts = x.split(' ');
|
||||||
|
const factor = parseInt(parts.pop()!, 10);
|
||||||
|
const text = parts.join(' ');
|
||||||
|
totalFactor += factor;
|
||||||
|
xs.push({ factor, text });
|
||||||
|
}
|
||||||
|
const r = seedrandom(`${day}:${block.id}`)() * totalFactor;
|
||||||
|
let stackedFactor = 0;
|
||||||
|
for (const x of xs) {
|
||||||
|
if (r >= stackedFactor && r <= x.factor) {
|
||||||
|
return x.text;
|
||||||
|
} else {
|
||||||
|
stackedFactor += x.factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xs[0].text;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const fnName = block.type;
|
const fnName = block.type;
|
||||||
|
|
|
@ -81,6 +81,7 @@ export const funcDefs: Record<string, { in: any[]; out: any; category: string; i
|
||||||
randomPick: { in: [0], out: 0, category: 'random', icon: faDice, },
|
randomPick: { in: [0], out: 0, category: 'random', icon: faDice, },
|
||||||
dailyRandomPick: { in: [0], out: 0, category: 'random', icon: faDice, },
|
dailyRandomPick: { in: [0], out: 0, category: 'random', icon: faDice, },
|
||||||
seedRandomPick: { in: [null, 0], out: 0, category: 'random', icon: faDice, },
|
seedRandomPick: { in: [null, 0], out: 0, category: 'random', icon: faDice, },
|
||||||
|
dailyRPWPM: { in: ['stringArray'], out: 'string', category: 'random', icon: faDice, }, // dailyRandomPickWithProbabilityMapping
|
||||||
};
|
};
|
||||||
|
|
||||||
export const literalDefs: Record<string, { out: any; category: string; icon: any; }> = {
|
export const literalDefs: Record<string, { out: any; category: string; icon: any; }> = {
|
||||||
|
|
Loading…
Reference in a new issue