1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-28 14:58:29 +09:00
This commit is contained in:
syuilo 2019-05-05 20:12:35 +09:00
parent 73641fd78d
commit 7aa66f438f
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
3 changed files with 25 additions and 0 deletions

View File

@ -2059,6 +2059,9 @@ pages:
_seedRandomPick:
arg1: "シード"
arg2: "リスト"
dailyRPWPM: "確率付きリストからランダムに選択 (ユーザーごとに日替わり)"
_ddailyRPWPM:
arg1: "テキストのリスト"
number: "数値"
stringToNumber: "テキストを数値に"
_stringToNumber:

View File

@ -178,6 +178,27 @@ export class ASEvaluator {
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)),
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;

View File

@ -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, },
dailyRandomPick: { in: [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; }> = {