refactor: Improve pickHashRand function in parser.ts
This commit is contained in:
@@ -1055,9 +1055,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
if(p1.startsWith('pick')){
|
if(p1.startsWith('pick')){
|
||||||
const selchar = db.characters[get(selectedCharID)]
|
const selchar = db.characters[get(selectedCharID)]
|
||||||
const selChat = selchar.chats[selchar.chatPage]
|
const selChat = selchar.chats[selchar.chatPage]
|
||||||
const cid = (chatID < 0) ? selChat.message.length : chatID
|
const cid = selChat.message.length
|
||||||
if(p1.startsWith('pick::')){
|
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){
|
if(matcherArg.tokenizeAccurate){
|
||||||
return arra[0]
|
return arra[0]
|
||||||
}
|
}
|
||||||
@@ -1065,7 +1065,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const arr = p1.replace(/\\,/g, '§X').split(/\:|\,/g)
|
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){
|
if(matcherArg.tokenizeAccurate){
|
||||||
return arra[0]
|
return arra[0]
|
||||||
}
|
}
|
||||||
@@ -1088,8 +1088,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
if(p){
|
if(p){
|
||||||
const selchar = db.characters[get(selectedCharID)]
|
const selchar = db.characters[get(selectedCharID)]
|
||||||
const selChat = selchar.chats[selchar.chatPage]
|
const selChat = selchar.chats[selchar.chatPage]
|
||||||
const cid = (chatID < 0) ? selChat.message.length : chatID
|
const cid = selChat.message.length
|
||||||
return (Math.floor(pickHashRand(cid, selchar.chaId) * maxRoll) + 1).toString()
|
return (Math.floor(pickHashRand(cid, selchar.chaId + (selChat.id ?? '')) * maxRoll) + 1).toString()
|
||||||
}
|
}
|
||||||
return (Math.floor(Math.random() * maxRoll) + 1).toString()
|
return (Math.floor(Math.random() * maxRoll) + 1).toString()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user