BleeM rolls

This commit is contained in:
dakedres 2023-05-23 23:18:24 -06:00
parent e0c6c9c5c3
commit 1e6022c0bd
2 changed files with 27 additions and 2 deletions

View File

@ -1,6 +1,6 @@
const constants = {
rollRegex: /^(\d+)?([dhl])(\d+)(\s*([+\-*x\/])\s*(\d+))?/,
optionRollRegex: /^(\d+)?(([dhl])(\d+))?(\s*([+\-*x\/])\s*(\d+))?/,
rollRegex: /^(\d+)?([dhlfb])(\d+)(\s*([+\-*x\/])\s*(\d+))?/,
optionRollRegex: /^(\d+)?(([dhlfb])(\d+))?(\s*([+\-*x\/])\s*(\d+))?/,
descriptionRegex: /\s*((\d*-\d*)|(\d+))?([^;\n]+)/g,
macroNameRegex: /^[a-z0-9]+$/,

View File

@ -113,6 +113,22 @@ const handleMessage = (message, respond) => {
rollDice(dice, respond)
}
const bleemRoll = (dice, rolls, comparison, resultDistance = -1) => {
let result = 0
let pseudoMedian = Math.floor(dice.size / 2)
for(let roll of rolls) {
let distance = Math.abs(roll - pseudoMedian)
if(comparison(result, resultDistance)) {
result = roll
resultDistance = distance
}
}
return result
}
const rollDice = (dice, respond) => {
if(dice.size > 255) {
respond('That die is way too big... .-.')
@ -132,6 +148,7 @@ const rollDice = (dice, respond) => {
let result = 0
let operationSymbol = dice.operation
let response = ''
let comparison
switch(dice.mode.toLowerCase()) {
case 'd':
@ -145,6 +162,14 @@ const rollDice = (dice, respond) => {
case 'l':
result = rolls.reduce((a, v) => v < a ? v : a, Infinity)
break
case 'f':
result = bleemRoll(dice, rolls, (l, r) => l > r, -1)
break
case 'b':
result = bleemRoll(dice, rolls, (l, r) => l < r, Infinity)
break
}
switch(dice.operation) {