From 6fa6660d964fa6954465491427303d393c5f1b54 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Tue, 4 Jun 2024 19:08:02 +0900 Subject: [PATCH] fix: fix pick --- src/ts/parser.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 176784fe..f79a3f27 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -996,9 +996,10 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } if(p1.startsWith('pick')){ const selchar = db.characters[get(selectedCharID)] - const rand = sfc32(uuidtoNumber(selchar.chaId), chatID, uuidtoNumber(selchar.chaId), chatID) + const selChat = selchar.chats[selchar.chatPage] + const cid = (chatID < 0) ? selChat.message.length : chatID if(p1.startsWith('pick::')){ - const randomIndex = Math.floor(rand() * (arra.length - 1)) + 1 + const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId) * (arra.length - 1)) + 1 if(matcherArg.tokenizeAccurate){ return arra[0] } @@ -1006,7 +1007,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } else{ const arr = p1.replace(/\\,/g, '§X').split(/\:|\,/g) - const randomIndex = Math.floor(rand() * (arr.length - 1)) + 1 + const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId) * (arr.length - 1)) + 1 if(matcherArg.tokenizeAccurate){ return arra[0] } @@ -1028,8 +1029,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } if(p){ const selchar = db.characters[get(selectedCharID)] - const rand = sfc32(uuidtoNumber(selchar.chaId), chatID, uuidtoNumber(selchar.chaId), chatID) - return (Math.floor(rand() * maxRoll) + 1).toString() + const selChat = selchar.chats[selchar.chatPage] + const cid = (chatID < 0) ? selChat.message.length : chatID + return (Math.floor(pickHashRand(cid, selchar.chaId) * maxRoll) + 1).toString() } return (Math.floor(Math.random() * maxRoll) + 1).toString() } @@ -1065,6 +1067,18 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } } +function pickHashRand(cid:number,word:string) { + let hashAddress = cid * 23515 + const rand = (word:string) => { + for (let counter = 0; counter { const date = new Date() if(!main){