From 67d8e210f87ed3489c2c8ae272c5ee3a6905dc9d Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sat, 20 Aug 2022 17:56:01 +0200 Subject: [PATCH] More cleaning and other cast options --- main.go | 59 +++++++++++++++++++++++++++++++++++++++++-------- sheetContent.go | 6 ++--- stats.json | 4 +--- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 9928e6d..dafc5de 100644 --- a/main.go +++ b/main.go @@ -12,18 +12,20 @@ import ( ) var ( - path, skillString, saveString string - modifier, diceThrows, surfaces int - char Character - skillMap = make(map[string]int) - statMap = make(map[string]int) - advantage, disadvantage bool + path, skillString, saveString, checkString string + modifier, diceThrows, surfaces int + char Character + skillMap = make(map[string]int) + statMap = make(map[string]int) + advantage, disadvantage bool ) 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 } diff --git a/sheetContent.go b/sheetContent.go index 005604a..71b5a8f 100644 --- a/sheetContent.go +++ b/sheetContent.go @@ -7,10 +7,8 @@ type Character struct { } type Misc struct { - Proficiency int `json:"proficiency"` - Inspiration int `json:"inspiration"` - Level int `json:"level"` - Name string `json:"name"` + Level int `json:"level"` + Name string `json:"name"` } type Skill struct { SkillName string `json:"skillName"` diff --git a/stats.json b/stats.json index 496b4c0..2339dd7 100644 --- a/stats.json +++ b/stats.json @@ -1,8 +1,6 @@ { "misc":{ - "proficiency": 3, - "inspiration": 0, - "level": 0, + "level": 13, "name": "Bob" }, "stats":[