diff --git a/main.go b/main.go index dfbbc1d..9928e6d 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,7 @@ import ( "flag" "fmt" "io/ioutil" - "math/rand" "os" - "time" "gitlab.com/EternalWanderer/dice-roller/Colors" "gitlab.com/EternalWanderer/dice-roller/Dice" @@ -22,12 +20,6 @@ var ( advantage, disadvantage bool ) -func isError(err error) bool { - if err != nil { - fmt.Println(err.Error()) - } - return (err != nil) -} func parseFlags() { flag.StringVar(&path, "file", "stats.json", "fock me") flag.StringVar(&path, "f", "stats.json", "fock me") @@ -37,6 +29,13 @@ func parseFlags() { flag.Parse() } +func isError(err error) bool { + if err != nil { + fmt.Println(err.Error()) + } + return (err != nil) +} + func readJson() { fmt.Println("Opening file:", path) var file, err = os.Open(path) @@ -60,27 +59,26 @@ func initMaps() { } func main() { - rand.Seed(time.Now().Unix()) parseFlags() readJson() initMaps() - fmt.Println(SkillCheck(GetSkill(skillString))) + fmt.Println(skillCheck(getSkill(skillString))) } -func GetSkill(skillName string) Skill { +func getSkill(skillName string) Skill { return char.Skills[skillMap[skillName]] } -func GetStat(statName string) Stat { +func getStat(statName string) Stat { return char.Stats[statMap[statName]] } -func GetModifier(stat Stat) int { +func getModifier(stat Stat) int { return (stat.Score - 10) / 2 } -func SkillCheck(skill Skill) int { +func skillCheck(skill Skill) int { var die, x, y int switch { case advantage: @@ -91,12 +89,14 @@ func SkillCheck(skill Skill) int { die = Dice.SimpleCast() } fmt.Printf("%s%d%s\tx: %d\ty: %d\n", Colors.ColorGreen, die, Colors.ColorReset, x, y) + + die += getModifier(getStat(skill.BaseStat)) + switch { case skill.Expertise: - return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency*2 + die += char.Misc.Proficiency * 2 case skill.Proficient: - return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency - default: - return die + GetModifier(GetStat(skill.BaseStat)) + die += char.Misc.Proficiency } + return die }