mirror of
https://gitlab.com/EternalWanderer/sheet-parser.git
synced 2024-11-29 05:23:49 +01:00
Some cleanup
This commit is contained in:
parent
811dbf8581
commit
694bfc8cef
36
main.go
36
main.go
|
@ -5,9 +5,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
||||||
"gitlab.com/EternalWanderer/dice-roller/Dice"
|
"gitlab.com/EternalWanderer/dice-roller/Dice"
|
||||||
|
@ -22,12 +20,6 @@ var (
|
||||||
advantage, disadvantage bool
|
advantage, disadvantage bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func isError(err error) bool {
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
}
|
|
||||||
return (err != nil)
|
|
||||||
}
|
|
||||||
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")
|
||||||
|
@ -37,6 +29,13 @@ func parseFlags() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isError(err error) bool {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
return (err != nil)
|
||||||
|
}
|
||||||
|
|
||||||
func readJson() {
|
func readJson() {
|
||||||
fmt.Println("Opening file:", path)
|
fmt.Println("Opening file:", path)
|
||||||
var file, err = os.Open(path)
|
var file, err = os.Open(path)
|
||||||
|
@ -60,27 +59,26 @@ func initMaps() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().Unix())
|
|
||||||
parseFlags()
|
parseFlags()
|
||||||
readJson()
|
readJson()
|
||||||
initMaps()
|
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]]
|
return char.Skills[skillMap[skillName]]
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStat(statName string) Stat {
|
func getStat(statName string) Stat {
|
||||||
return char.Stats[statMap[statName]]
|
return char.Stats[statMap[statName]]
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetModifier(stat Stat) int {
|
func getModifier(stat Stat) int {
|
||||||
return (stat.Score - 10) / 2
|
return (stat.Score - 10) / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func SkillCheck(skill Skill) int {
|
func skillCheck(skill Skill) int {
|
||||||
var die, x, y int
|
var die, x, y int
|
||||||
switch {
|
switch {
|
||||||
case advantage:
|
case advantage:
|
||||||
|
@ -91,12 +89,14 @@ func SkillCheck(skill Skill) int {
|
||||||
die = Dice.SimpleCast()
|
die = Dice.SimpleCast()
|
||||||
}
|
}
|
||||||
fmt.Printf("%s%d%s\tx: %d\ty: %d\n", Colors.ColorGreen, die, Colors.ColorReset, x, y)
|
fmt.Printf("%s%d%s\tx: %d\ty: %d\n", Colors.ColorGreen, die, Colors.ColorReset, x, y)
|
||||||
|
|
||||||
|
die += getModifier(getStat(skill.BaseStat))
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case skill.Expertise:
|
case skill.Expertise:
|
||||||
return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency*2
|
die += char.Misc.Proficiency * 2
|
||||||
case skill.Proficient:
|
case skill.Proficient:
|
||||||
return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency
|
die += char.Misc.Proficiency
|
||||||
default:
|
|
||||||
return die + GetModifier(GetStat(skill.BaseStat))
|
|
||||||
}
|
}
|
||||||
|
return die
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue