refactor: Improve pickHashRand function in parser.ts

This commit is contained in:
kwaroran
2024-06-14 08:30:48 +09:00
parent 27ad0810c4
commit 4f5171d16c

View File

@@ -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()
}