DndDice/R/disadvantage_advantage.R
Joel Therrien 566b48ff62 Bug fixes for when die roll is non-integer
Also added a reroll function and simplified code greatly
2019-05-29 10:35:13 -07:00

44 lines
900 B
R

#'
#' Disadvantage
#'
#' Disadvantage a die roll, which means that when both die are rolled, the result
#' is the lower number.
#'
#' @param x A die to roll.
#' @param y A die to roll. If not specified, then x is disadvantaged against itself.
#' @return A die representing the minimum of both die
#' @examples
#' disadvantage(d20,d20)
#'
#' @export
disadvantage <- function(x, y=NULL){
if(is.null(y)){
y = x
}
return(combineDice(x, y, pmin))
}
#'
#' Advantage
#'
#' Advantage a die roll, which means that when both die are rolled, the result
#' is the higher number.
#'
#' @param x A die to roll.
#' @param y A die to roll. If not specified, then x is advantaged against itself.
#' @return A die representing the maximum of both die
#' @examples
#' advantage(d20,d20)
#'
#' @export
advantage <- function(x, y=NULL){
if(is.null(y)){
y = x
}
return(combineDice(x, y, pmax))
}