More cleaning and other cast options

This commit is contained in:
Nox Sluijtman 2022-08-20 17:56:01 +02:00
parent dd72976913
commit 67d8e210f8
3 changed files with 53 additions and 16 deletions

49
main.go
View file

@ -12,7 +12,7 @@ import (
)
var (
path, skillString, saveString string
path, skillString, saveString, checkString string
modifier, diceThrows, surfaces int
char Character
skillMap = make(map[string]int)
@ -23,7 +23,9 @@ var (
func parseFlags() {
flag.StringVar(&path, "file", "stats.json", "fock me")
flag.StringVar(&path, "f", "stats.json", "fock me")
flag.StringVar(&skillString, "s", "athletics", "Skill to parse")
flag.StringVar(&skillString, "skill", "athletics", "Skill to parse")
flag.StringVar(&checkString, "check", "strength", "Stat check")
flag.StringVar(&saveString, "save", "strength", "Saving throw to... throw")
flag.BoolVar(&advantage, "advantage", advantage, "Roll with advantage")
flag.BoolVar(&disadvantage, "disadvantage", disadvantage, "Roll with disadvantage")
flag.Parse()
@ -63,7 +65,18 @@ func main() {
readJson()
initMaps()
fmt.Println("Skill check:", skillString)
fmt.Println(skillCheck(getSkill(skillString)))
fmt.Println("Stat check", checkString)
fmt.Println(statCheck(getStat(checkString)))
fmt.Println("Saving throw", saveString)
fmt.Println(savingThrow(getStat(saveString)))
fmt.Println("Proficiency")
fmt.Println(getProficiency())
}
func getProficiency() int {
return (char.Misc.Level-1)/4 + 2
}
func getSkill(skillName string) Skill {
@ -78,6 +91,34 @@ func getModifier(stat Stat) int {
return (stat.Score - 10) / 2
}
func rollDice() int {
var die, x, y int
switch {
case advantage:
die, x, y = Dice.Advantage()
case disadvantage:
die, x, y = Dice.Disadvantage()
default:
die = Dice.SimpleCast()
}
fmt.Printf("%s%d%s\tx: %d\ty: %d\n", Colors.ColorGreen, die, Colors.ColorReset, x, y)
return die
}
func statCheck(stat Stat) int {
return rollDice() + getModifier(stat)
}
func savingThrow(stat Stat) int {
die := rollDice()
if stat.Proficient {
die += getModifier(stat)
}
return die
}
func skillCheck(skill Skill) int {
var die, x, y int
switch {
@ -94,9 +135,9 @@ func skillCheck(skill Skill) int {
switch {
case skill.Expertise:
die += char.Misc.Proficiency * 2
die += getProficiency() * 2
case skill.Proficient:
die += char.Misc.Proficiency
die += getProficiency()
}
return die
}

View file

@ -7,8 +7,6 @@ type Character struct {
}
type Misc struct {
Proficiency int `json:"proficiency"`
Inspiration int `json:"inspiration"`
Level int `json:"level"`
Name string `json:"name"`
}

View file

@ -1,8 +1,6 @@
{
"misc":{
"proficiency": 3,
"inspiration": 0,
"level": 0,
"level": 13,
"name": "Bob"
},
"stats":[