mirror of
https://github.com/raeleus/Hashtag-DnD.git
synced 2025-07-12 16:32:19 -04:00
Allow adding a value to dice rolls in #roll.
This commit is contained in:
parent
09b404cbdc
commit
ca76856c90
4 changed files with 24 additions and 11 deletions
8
Input.js
8
Input.js
|
@ -591,9 +591,10 @@ function doRoll(command) {
|
|||
if (dice == null) dice = "d20"
|
||||
dice = formatRoll(dice)
|
||||
|
||||
var roll = calculateRoll(dice)
|
||||
if (rollType == "advantage") roll = Math.max(roll, calculateRoll(dice))
|
||||
if (rollType == "disadvantage") roll = Math.min(roll, calculateRoll(dice))
|
||||
var addition = getAddition(dice)
|
||||
var roll = calculateRoll(dice) - addition
|
||||
if (rollType == "advantage") roll = Math.max(roll, calculateRoll(dice) - addition)
|
||||
if (rollType == "disadvantage") roll = Math.min(roll, calculateRoll(dice) - addition)
|
||||
|
||||
state.show = "none"
|
||||
|
||||
|
@ -603,6 +604,7 @@ function doRoll(command) {
|
|||
|
||||
if (roll == 20) text += " Critical Success!"
|
||||
else if (roll == 1) text += " Critical Failure!"
|
||||
else if (addition > 0) text += ` + ${addition} = ${roll + addition}`
|
||||
|
||||
text += "]\n"
|
||||
return text
|
||||
|
|
24
Library.js
24
Library.js
|
@ -185,7 +185,7 @@ function statsToOrPattern(stats) {
|
|||
function getDice(rolltext) {
|
||||
var matches = rolltext.match(/\d+(?=d)/)
|
||||
if (matches != null) {
|
||||
return matches[0]
|
||||
return parseInt(matches[0])
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
@ -193,16 +193,25 @@ function getDice(rolltext) {
|
|||
function getSides(rolltext) {
|
||||
var matches = rolltext.match(/(?<=d)\d+/)
|
||||
if (matches != null) {
|
||||
return matches[0]
|
||||
return parseInt(matches[0])
|
||||
}
|
||||
|
||||
return 20
|
||||
}
|
||||
|
||||
function formatRoll(text) {
|
||||
var matches = text.match(/(?<=.*)\d*d\d+(?=.*)/)
|
||||
function getAddition(rolltext) {
|
||||
var matches = rolltext.match(/(?<=(\+|-)\s*)\d+/)
|
||||
if (matches != null) {
|
||||
return matches[0]
|
||||
return parseInt(matches[0])
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function formatRoll(text) {
|
||||
var matches = text.match(/(?<=.*)\d*d\d+(?=.*)(\s*\+\s*\d+)?/)
|
||||
if (matches != null) {
|
||||
return matches[0].replaceAll(/\s*\+\s*/g, "+").replaceAll(/\s*-\s*/g, "-")
|
||||
}
|
||||
|
||||
matches = text.match(/\d+/)
|
||||
|
@ -218,13 +227,14 @@ function calculateRoll(rolltext) {
|
|||
|
||||
var dice = getDice(rolltext)
|
||||
var sides = getSides(rolltext)
|
||||
var addition = getAddition(rolltext)
|
||||
|
||||
var score = 0;
|
||||
var score = addition;
|
||||
for (i = 0; i < dice; i++) {
|
||||
score += getRandomInteger(1, sides)
|
||||
}
|
||||
|
||||
return score
|
||||
return Math.max(0, score)
|
||||
}
|
||||
|
||||
function getCharacter(characterName) {
|
||||
|
|
|
@ -224,7 +224,7 @@ const modifier = (text) => {
|
|||
|
||||
text += "--Basic Hashtags--"
|
||||
text += "\n#roll (advantage|disadvantage) (dice_value)"
|
||||
text += "\n Rolls a die/dice and shows the result. dice_value can be in the following formats 5d20 or d20 or 20. The parameters can be listed in any order."
|
||||
text += "\n Rolls a die/dice and shows the result. dice_value can be in the following formats 5d20+6 or 5d20 or d20 or 20. The parameters can be listed in any order."
|
||||
text += "\n#generatename (male|female) (fantasy|modern|scifi|nordic)"
|
||||
text += "\n Retrieves a random name from a list of names in the specified gender and genre. The parameters can be listed in any order."
|
||||
text += "\n#shownotes"
|
||||
|
|
|
@ -25,6 +25,7 @@ v. 0.2.0
|
|||
* The scenario keeps track of how many days have passed since the adventure has started. See `#rest`, `#showday`, `#setday`.
|
||||
* Added automatic difficulty which is DC 0
|
||||
* Added `#version`
|
||||
* Allow adding a plus or minus number to `#roll`. ie. `#roll 5d20+6`
|
||||
* Minor bug fixes and improvements
|
||||
|
||||
v. 0.1.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue