Refactor of skills and start of dice module

This commit is contained in:
Nox Sluijtman 2024-11-18 17:09:16 +01:00
parent 554a26fff6
commit f12134bf55
Signed by: Egg
SSH key fingerprint: SHA256:2sG9X3C7Xvq2svGumz1/k7cm8l4G9+qAtAeugqB4J9M
8 changed files with 104 additions and 54 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

View file

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1699169573,
"narHash": "sha256-cvUb1xZkvOp3W2SzylStrTirhVd9zCeo5utJl9nSIhw=",
"lastModified": 1704290814,
"narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "aeefe2054617cae501809b82b44a8e8f7be7cc4b",
"rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"type": "github"
},
"original": {

View file

@ -2,8 +2,10 @@ module DND
( module DND.Sheet.Content
, module DND.Sheet.Parser
, module DND.Bob
, module DND.Dice
) where
import DND.Sheet.Content
import DND.Sheet.Parser
import DND.Dice
import DND.Bob

View file

@ -3,7 +3,7 @@ module DND.Bob (bob) where
import DND.Sheet.Content
bob :: Character
bob = Character testPreamble testTrivia testStats (Just testSpells)
bob = Character {skills=testSkills, trivia=testTrivia, stats=testStats, spells=Just testSpells, preamble=testPreamble, feats=Just testFeatures}
testStats :: [Stat]
testStats = [strStat,dexStat,conStat,intStat,wisStat,chaStat]
@ -15,65 +15,72 @@ testTrivia :: Trivia
testTrivia = Trivia "farmer" "none" "I me likey fun things" "yay" "all" "idk"
strStat :: Stat
strStat = Stat "Strength" 10 False strSkills
strStat = Stat "Strength" 10 False
strSkills :: [Skill]
strSkills = [ Skill "Athletics" None ]
strSkills = [ Skill "Athletics" None "Strength" ]
dexStat :: Stat
dexStat = Stat "Dexterity" 10 False dexSkills
dexStat = Stat "Dexterity" 10 False
dexSkills :: [Skill]
dexSkills = [ Skill "Acrobatics" None
, Skill "Sleight of Hand" None
, Skill "Stealth" None
dexSkills = [ Skill "Acrobatics" None "Dexterity"
, Skill "Sleight of Hand" None "Dexterity"
, Skill "Stealth" None "Dexterity"
]
conStat :: Stat
conStat = Stat "Constitution" 10 False []
conStat = Stat "Constitution" 10 False
intStat :: Stat
intStat = Stat "Intelligence" 10 False intSkills
intStat = Stat "Intelligence" 10 False
intSkills :: [Skill]
intSkills = [ Skill "Arcana" None
, Skill "History" None
, Skill "Investigation" None
, Skill "Nature" None
, Skill "Religion" None
intSkills = [ Skill "Arcana" None "Intelligence"
, Skill "History" None "Intelligence"
, Skill "Investigation" None "Intelligence"
, Skill "Nature" None "Intelligence"
, Skill "Religion" None "Intelligence"
]
wisStat :: Stat
wisStat = Stat "Wisdom" 10 False wisSkills
wisStat = Stat "Wisdom" 10 False
wisSkills :: [Skill]
wisSkills = [ Skill "Animal Handling" None
, Skill "Insight" None
, Skill "Medicine" None
, Skill "Perception" None
, Skill "Survival" None
wisSkills = [ Skill "Animal Handling" None "Wisdom"
, Skill "Insight" None "Wisdom"
, Skill "Medicine" None "Wisdom"
, Skill "Perception" None "Wisdom"
, Skill "Survival" None "Wisdom"
]
chaStat :: Stat
chaStat = Stat "Charisma" 10 False chaSkills
chaStat = Stat "Charisma" 10 False
chaSkills :: [Skill]
chaSkills = [ Skill "Deception" None
, Skill "Intimidation" None
, Skill "Performance" None
, Skill "Persuasion" None
chaSkills = [ Skill "Deception" None "Charisma"
, Skill "Intimidation" None "Charisma"
, Skill "Performance" None "Charisma"
, Skill "Persuasion" None "Charisma"
]
testSkills :: [Skill]
testSkills = strSkills ++ dexSkills ++ intSkills ++ wisSkills ++ chaSkills
testSpells :: [Spell]
testSpells = [ Spell "Firetesticle" -- spellName
3 -- spellLevel
"3 Minutes" -- castingTime
50 -- range
[Verbal, Somatic] -- components
"Instant" -- duration
"Dexterity" -- attackSave
"Fire" -- damge/effect
"Shoots a huge testicle shaped fireball" -- description
"Conjuration" -- school
"Cast more of the sodding things" -- atHighLevel
testSpells = [ Spell { spellName = "Firetesticle"
, spellLevel = 3
, castingTime = "3 Minutes"
, range = 50
, components = [Verbal, Somatic]
, duration = "Instant"
, attackSave = "Dexterity"
, damageEffect = "Fire"
, description = "Shoots a huge testicle shaped fireball"
, school = "Conjuration"
, atHighLevel = "Cast more of the sodding things"
}
]
testFeatures :: [Feature]
testFeatures = [ Roleplay FeatInfo { featName = "fiets", featDescription = "allows you to ride a 'fiets'" } ]

16
lib/DND/Dice.hs Normal file
View file

@ -0,0 +1,16 @@
module DND.Dice
( rolls
, d20
, advantage
) where
import System.Random
rolls :: RandomGen a => Int -> Int -> a -> [Int]
rolls x y = take x . randomRs (1, y)
d20 :: RandomGen a => a -> Int
d20 = minimum . rolls 1 20
advantage :: RandomGen a => a -> Int
advantage = maximum . rolls 2 20

View file

@ -10,6 +10,8 @@ module DND.Sheet.Content
, Spell(..)
, SpellComponent(..)
, Feature(..)
, FeatInfo(..)
, fiets
) where
import Data.Aeson ( FromJSON, ToJSON )
@ -36,6 +38,12 @@ instance ToJSON ScoreMod
instance FromJSON Spell
instance ToJSON Spell
instance FromJSON Feature
instance ToJSON Feature
instance FromJSON FeatInfo
instance ToJSON FeatInfo
instance FromJSON SpellComponent
instance ToJSON SpellComponent
@ -48,8 +56,9 @@ data Character = Character
{ preamble :: Preamble
, trivia :: Trivia
, stats :: [Stat]
, skills :: [Skill]
, spells :: Maybe [Spell]
--, feats :: [Feat]
, feats :: Maybe [Feature]
} deriving ( Show, Eq, Ord, Generic)
data Preamble = Preamble
@ -72,13 +81,18 @@ data Trivia = Trivia
data Skill = Skill
{ skillName :: String
, skillMod :: ScoreMod
, relatedStat :: String
} deriving ( Show, Eq, Ord, Generic)
fiets = Skill { skillName = "Stuff"
, skillMod = None
, relatedStat = "Strength"
}
data Stat = Stat
{ stat :: String
{ statName :: String
, score :: Int
, proficient :: Bool
, skills :: [Skill]
} deriving ( Show, Eq, Ord, Generic)
data Spell = Spell
@ -100,21 +114,25 @@ data SpellComponent = Verbal
| Material
deriving ( Show, Eq, Ord, Generic)
data FeatInfo = FeatInfo { featName :: String
, featDescription :: String
} deriving ( Show, Eq, Ord, Generic)
data Feature = StatIncrease
{ increase :: [Stat] }
{ featInfo :: FeatInfo
, increase :: [Stat] }
| SetProficiency
{ changeModState :: [ScoreMod]
, featDescription :: String
{ featInfo :: FeatInfo
, changeModState :: [ScoreMod]
}
| SetExpertise
{ changeModState :: [ScoreMod]
, featDescription :: String
{ featInfo :: FeatInfo
, changeModState :: [ScoreMod]
}
| AddSpell
{ addSpell :: [Spell]
, featDescription :: String
{ featInfo :: FeatInfo
, addSpell :: [Spell]
}
| Roleplay
{ featDescription :: String
}
{ featInfo :: FeatInfo }
deriving ( Show, Eq, Ord, Generic)

View file

@ -4,6 +4,7 @@ module DND.Sheet.Parser
, listSkills
, createExample
, getName
, getStat
, listSkillNames
) where
@ -34,3 +35,6 @@ createExample = flip encodeFile bob
getName :: Character -> String
getName = charName . preamble
getStat :: Character -> String -> Stat
getStat char s = head . filter (\a -> statName a == s) . stats $ char

View file

@ -58,6 +58,7 @@ library
exposed-modules: DND
, DND.Bob
, DND.Dice
, DND.Sheet
, DND.Sheet.Content
, DND.Sheet.Parser
@ -66,6 +67,7 @@ library
, aeson
, bytestring
, utf8-string
, random
hs-source-dirs: lib