From 4f5171d16c1035065bb9c2cf653bb3a159c24d94 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Fri, 14 Jun 2024 08:30:48 +0900 Subject: [PATCH] refactor: Improve pickHashRand function in parser.ts --- src/ts/parser.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 322d6010..925226b8 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -1055,9 +1055,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => { if(p1.startsWith('pick')){ const selchar = db.characters[get(selectedCharID)] const selChat = selchar.chats[selchar.chatPage] - const cid = (chatID < 0) ? selChat.message.length : chatID + const cid = selChat.message.length if(p1.startsWith('pick::')){ - const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId) * (arra.length - 1)) + 1 + const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId + (selChat.id ?? '')) * (arra.length - 1)) + 1 if(matcherArg.tokenizeAccurate){ return arra[0] } @@ -1065,7 +1065,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } else{ const arr = p1.replace(/\\,/g, '§X').split(/\:|\,/g) - const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId) * (arr.length - 1)) + 1 + const randomIndex = Math.floor(pickHashRand(cid, selchar.chaId + (selChat.id ?? '')) * (arr.length - 1)) + 1 if(matcherArg.tokenizeAccurate){ return arra[0] } @@ -1088,8 +1088,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => { if(p){ const selchar = db.characters[get(selectedCharID)] const selChat = selchar.chats[selchar.chatPage] - const cid = (chatID < 0) ? selChat.message.length : chatID - return (Math.floor(pickHashRand(cid, selchar.chaId) * maxRoll) + 1).toString() + const cid = selChat.message.length + return (Math.floor(pickHashRand(cid, selchar.chaId + (selChat.id ?? '')) * maxRoll) + 1).toString() } return (Math.floor(Math.random() * maxRoll) + 1).toString() }