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

59
main.go
View file

@ -12,18 +12,20 @@ import (
) )
var ( var (
path, skillString, saveString string path, skillString, saveString, checkString string
modifier, diceThrows, surfaces int modifier, diceThrows, surfaces int
char Character char Character
skillMap = make(map[string]int) skillMap = make(map[string]int)
statMap = make(map[string]int) statMap = make(map[string]int)
advantage, disadvantage bool advantage, disadvantage bool
) )
func parseFlags() { func parseFlags() {
flag.StringVar(&path, "file", "stats.json", "fock me") flag.StringVar(&path, "file", "stats.json", "fock me")
flag.StringVar(&path, "f", "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(&advantage, "advantage", advantage, "Roll with advantage")
flag.BoolVar(&disadvantage, "disadvantage", disadvantage, "Roll with disadvantage") flag.BoolVar(&disadvantage, "disadvantage", disadvantage, "Roll with disadvantage")
flag.Parse() flag.Parse()
@ -63,7 +65,18 @@ func main() {
readJson() readJson()
initMaps() initMaps()
fmt.Println("Skill check:", skillString)
fmt.Println(skillCheck(getSkill(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 { func getSkill(skillName string) Skill {
@ -78,6 +91,34 @@ func getModifier(stat Stat) int {
return (stat.Score - 10) / 2 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 { func skillCheck(skill Skill) int {
var die, x, y int var die, x, y int
switch { switch {
@ -94,9 +135,9 @@ func skillCheck(skill Skill) int {
switch { switch {
case skill.Expertise: case skill.Expertise:
die += char.Misc.Proficiency * 2 die += getProficiency() * 2
case skill.Proficient: case skill.Proficient:
die += char.Misc.Proficiency die += getProficiency()
} }
return die return die
} }

View file

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

View file

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