Exported a few functions

This commit is contained in:
Nox Sluijtman 2022-12-29 17:46:23 +01:00
parent c5faafb072
commit 01252f30c3

50
main.go
View file

@ -94,18 +94,18 @@ func main() {
switch { switch {
case trivia: case trivia:
fmt.Printf("Name: %s\tLevel: %d\tProficiency: %d\n", char.Misc.Name, char.Misc.Level, getProficiency()) fmt.Printf("Name: %s\tLevel: %d\tProficiency: %d\n", char.Misc.Name, char.Misc.Level, GetProficiency())
fmt.Printf("Race: %s\tClass: %s\tBackground: %s\n", char.Misc.Race, char.Misc.Class, char.Misc.Background) fmt.Printf("Race: %s\tClass: %s\tBackground: %s\n", char.Misc.Race, char.Misc.Class, char.Misc.Background)
// passive perception // passive perception
var passivePerception int var passivePerception int
switch { switch {
case getSkill("perception").Proficient && getSkill("perception").Expertise: case GetSkill("perception").Proficient && GetSkill("perception").Expertise:
passivePerception = 10 + getModifier(getStat("wisdom")) + getProficiency()*2 passivePerception = 10 + GetModifier(GetStat("wisdom")) + GetProficiency()*2
case getSkill("perception").Proficient: case GetSkill("perception").Proficient:
passivePerception = 10 + getModifier(getStat("wisdom")) + getProficiency() passivePerception = 10 + GetModifier(GetStat("wisdom")) + GetProficiency()
default: default:
passivePerception = 10 + getModifier(getStat("wisdom")) passivePerception = 10 + GetModifier(GetStat("wisdom"))
} }
fmt.Printf("Passive perception: %d\n", passivePerception) fmt.Printf("Passive perception: %d\n", passivePerception)
@ -121,7 +121,7 @@ func main() {
fmt.Println("You can't roll with both advantage and disadvantage") fmt.Println("You can't roll with both advantage and disadvantage")
os.Exit(1) os.Exit(1)
case len(saveString) > 0: case len(saveString) > 0:
result, plainResult, err := savingThrow(getStat(saveString)) result, plainResult, err := savingThrow(GetStat(saveString))
badCheck(saveString, err) badCheck(saveString, err)
if advantage { if advantage {
color.Yellow("Rolling %s saving throw with advantage...", saveString) color.Yellow("Rolling %s saving throw with advantage...", saveString)
@ -140,7 +140,7 @@ func main() {
} }
case len(skillString) > 0 && char.Misc.IsKurthog && strings.Contains(skillString, "performance"): case len(skillString) > 0 && char.Misc.IsKurthog && strings.Contains(skillString, "performance"):
result, plainResult, err := skillCheck(getSkill(skillString)) result, plainResult, err := skillCheck(GetSkill(skillString))
badCheck(skillString, err) badCheck(skillString, err)
if advantage { if advantage {
color.Yellow("Rolling %s check with advantage...", skillString) color.Yellow("Rolling %s check with advantage...", skillString)
@ -162,7 +162,7 @@ func main() {
} }
case len(skillString) > 0: case len(skillString) > 0:
result, plainResult, err := skillCheck(getSkill(skillString)) result, plainResult, err := skillCheck(GetSkill(skillString))
badCheck(skillString, err) badCheck(skillString, err)
if advantage { if advantage {
color.Yellow("Rolling %s check with advantage...", skillString) color.Yellow("Rolling %s check with advantage...", skillString)
@ -181,7 +181,7 @@ func main() {
} }
case len(statString) > 0: case len(statString) > 0:
result, plainResult, err := statCheck(getStat(statString)) result, plainResult, err := statCheck(GetStat(statString))
badCheck(statString, err) badCheck(statString, err)
if advantage { if advantage {
color.Yellow("Rolling %s check with advantage...", statString) color.Yellow("Rolling %s check with advantage...", statString)
@ -204,20 +204,20 @@ func main() {
} }
} }
func getProficiency() int { func GetProficiency() int {
// https://worldbuildersjunction.com/what-is-proficiency-bonus-in-dd-5e-how-it-works-calculated/ // https://worldbuildersjunction.com/what-is-proficiency-bonus-in-dd-5e-how-it-works-calculated/
return (char.Misc.Level-1)/4 + 2 return (char.Misc.Level-1)/4 + 2
} }
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 {
// https://worldbuildersjunction.com/dungeon-and-dragons-ability-scores-explained-for-beginners/ // https://worldbuildersjunction.com/dungeon-and-dragons-ability-scores-explained-for-beginners/
return (stat.Score - 10) / 2 return (stat.Score - 10) / 2
} }
@ -269,7 +269,7 @@ func skillErrorCheck() error {
func statCheck(stat Stat) (int, int, error) { func statCheck(stat Stat) (int, int, error) {
die := rollDice() die := rollDice()
return die + getModifier(stat), die, statErrorCheck() return die + GetModifier(stat), die, statErrorCheck()
} }
@ -278,9 +278,9 @@ func savingThrow(stat Stat) (int, int, error) {
plainDie := die plainDie := die
if stat.Proficient { if stat.Proficient {
die += getProficiency() die += GetProficiency()
} }
return die + getModifier(stat), plainDie, statErrorCheck() return die + GetModifier(stat), plainDie, statErrorCheck()
} }
func skillCheck(skill Skill) (int, int, error) { func skillCheck(skill Skill) (int, int, error) {
@ -290,15 +290,15 @@ func skillCheck(skill Skill) (int, int, error) {
} }
plainDie := die plainDie := die
die += getModifier(getStat(skill.BaseStat)) die += GetModifier(GetStat(skill.BaseStat))
switch { switch {
case skill.Expertise: case skill.Expertise:
die += getProficiency() * 2 die += GetProficiency() * 2
case skill.Proficient: case skill.Proficient:
die += getProficiency() die += GetProficiency()
case !skill.Proficient && char.Misc.JackOfAllTrades: case !skill.Proficient && char.Misc.JackOfAllTrades:
die += (getProficiency() / 2) die += (GetProficiency() / 2)
} }
return die, plainDie, skillErrorCheck() return die, plainDie, skillErrorCheck()
} }
@ -316,7 +316,7 @@ func printStatList(verbose bool) {
proficiency = "Not proficient" proficiency = "Not proficient"
} }
score := char.Stats[i].Score score := char.Stats[i].Score
fmt.Printf("Stat: %13s\t%s\tStat score: %2d\tStat modifier: %2d\n", name, proficiency, score, getModifier(char.Stats[i])) fmt.Printf("Stat: %13s\t%s\tStat score: %2d\tStat modifier: %2d\n", name, proficiency, score, GetModifier(char.Stats[i]))
} }
} else { } else {
for i := 0; i < len(char.Stats); i++ { for i := 0; i < len(char.Stats); i++ {
@ -332,16 +332,16 @@ func printSkillList(verbose bool) {
if verbose { if verbose {
for i := 0; i < len(char.Skills); i++ { for i := 0; i < len(char.Skills); i++ {
name := char.Skills[i].SkillName name := char.Skills[i].SkillName
localModifier := getModifier(getStat(char.Skills[i].BaseStat)) localModifier := GetModifier(GetStat(char.Skills[i].BaseStat))
if char.Skills[i].Proficient { if char.Skills[i].Proficient {
proficiency = "Proficient" proficiency = "Proficient"
localModifier += getProficiency() localModifier += GetProficiency()
} else { } else {
proficiency = "Not proficient" proficiency = "Not proficient"
} }
if char.Skills[i].Expertise { if char.Skills[i].Expertise {
expertise = "Has expertise" expertise = "Has expertise"
localModifier += getProficiency() localModifier += GetProficiency()
} else { } else {
expertise = "Doesn't have expertise" expertise = "Doesn't have expertise"
} }