#' Roll attack
#'
#' Roll an attack
#'
#' @param to_hit amount to add to the d20 attack roll
#' @param to_damage amount to add to the damage roll
#' @param type normal, advantage, or disadvantage
#' @param ... dice to roll, passed to \code{\link{roll_dice}}
#' @return attack and damage roll are printed
#' @export
#'
roll_attack <- function(to_hit, to_damage, type="normal",...) {
if (type == "normal") attack_roll = d20(1)
if (type == "advantage") attack_roll = max(d20(2))
if (type == "disadvantage") attack_roll = min(d20(2))
if (attack_roll == 1) {
return(data.frame(
type = "Critical miss!",
attack_roll = 1,
damage = 0)
)
}
if (attack_roll == 20) {
return(data.frame(
type = "Critical hit!",
attack_roll = 20+to_hit,
damage =
roll_dice(..., collapse = TRUE)$result +
roll_dice(..., collapse = TRUE)$result +
to_damage)
)
}
return(data.frame(
type = "Normal",
attack_roll = attack_roll+to_hit,
damage =
roll_dice(..., collapse = TRUE)$result +
to_damage)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.