sheet-parser-hs/lib/DND/Dice.hs

35 lines
908 B
Haskell

module DND.Dice
( rolls
, d20
, rollCheck
, rollAttackDamage
, RollMod(..)
) where
import Prelude hiding (mod)
import System.Random
data RollMod = Advantage | Disadvantage | Neutral
rolls :: RandomGen a => a -> Int -> Int -> [Int]
rolls rnd x y = take x . randomRs (1, y) $ rnd
d20 :: RandomGen a => a -> Int
d20 rnd = minimum $ rolls rnd 1 20
rollCheck :: Int -> RollMod -> IO (Int, [Int])
rollCheck scoreMod rollMod = do
rnd <- getStdGen
let dice = rolls rnd 2 20
mod = (+) scoreMod $ case rollMod of
Advantage -> maximum dice
Disadvantage -> minimum dice
Neutral -> head dice
return (mod,dice)
rollAttackDamage :: Int -> Int -> Int -> IO Int
-- dmgMod is proficiency in normal DND rules
rollAttackDamage sides count dmgMod = do
rnd <- getStdGen
return $ (+) dmgMod . sum $ rolls rnd sides count