diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-05-05 20:12:35 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-05-05 20:12:35 +0900 |
| commit | 7aa66f438f4c7854fa9bacb4c15584920e41c278 (patch) | |
| tree | 997b71963ac530fe3add7e52224e040b8836423d /src/misc/aiscript | |
| parent | Fix #4852 (diff) | |
| download | sharkey-7aa66f438f4c7854fa9bacb4c15584920e41c278.tar.gz sharkey-7aa66f438f4c7854fa9bacb4c15584920e41c278.tar.bz2 sharkey-7aa66f438f4c7854fa9bacb4c15584920e41c278.zip | |
Resolve #4853
Diffstat (limited to 'src/misc/aiscript')
| -rw-r--r-- | src/misc/aiscript/evaluator.ts | 21 | ||||
| -rw-r--r-- | src/misc/aiscript/index.ts | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/misc/aiscript/evaluator.ts b/src/misc/aiscript/evaluator.ts index 78b6acf35c..5e511576c8 100644 --- a/src/misc/aiscript/evaluator.ts +++ b/src/misc/aiscript/evaluator.ts @@ -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; diff --git a/src/misc/aiscript/index.ts b/src/misc/aiscript/index.ts index 1ce09b7bdb..61a6b7b139 100644 --- a/src/misc/aiscript/index.ts +++ b/src/misc/aiscript/index.ts @@ -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; }> = { |