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 {
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)
// passive perception
var passivePerception int
switch {
case getSkill("perception").Proficient && getSkill("perception").Expertise:
passivePerception = 10 + getModifier(getStat("wisdom")) + getProficiency()*2
case getSkill("perception").Proficient:
passivePerception = 10 + getModifier(getStat("wisdom")) + getProficiency()
case GetSkill("perception").Proficient && GetSkill("perception").Expertise:
passivePerception = 10 + GetModifier(GetStat("wisdom")) + GetProficiency()*2
case GetSkill("perception").Proficient:
passivePerception = 10 + GetModifier(GetStat("wisdom")) + GetProficiency()
default:
passivePerception = 10 + getModifier(getStat("wisdom"))
passivePerception = 10 + GetModifier(GetStat("wisdom"))
}
fmt.Printf("Passive perception: %d\n", passivePerception)
@ -121,7 +121,7 @@ func main() {
fmt.Println("You can't roll with both advantage and disadvantage")
os.Exit(1)
case len(saveString) > 0:
result, plainResult, err := savingThrow(getStat(saveString))
result, plainResult, err := savingThrow(GetStat(saveString))
badCheck(saveString, err)
if advantage {
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"):
result, plainResult, err := skillCheck(getSkill(skillString))
result, plainResult, err := skillCheck(GetSkill(skillString))
badCheck(skillString, err)
if advantage {
color.Yellow("Rolling %s check with advantage...", skillString)
@ -162,7 +162,7 @@ func main() {
}
case len(skillString) > 0:
result, plainResult, err := skillCheck(getSkill(skillString))
result, plainResult, err := skillCheck(GetSkill(skillString))
badCheck(skillString, err)
if advantage {
color.Yellow("Rolling %s check with advantage...", skillString)
@ -181,7 +181,7 @@ func main() {
}
case len(statString) > 0:
result, plainResult, err := statCheck(getStat(statString))
result, plainResult, err := statCheck(GetStat(statString))
badCheck(statString, err)
if advantage {
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/
return (char.Misc.Level-1)/4 + 2
}
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 {
// https://worldbuildersjunction.com/dungeon-and-dragons-ability-scores-explained-for-beginners/
return (stat.Score - 10) / 2
}
@ -269,7 +269,7 @@ func skillErrorCheck() error {
func statCheck(stat Stat) (int, int, error) {
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
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) {
@ -290,15 +290,15 @@ func skillCheck(skill Skill) (int, int, error) {
}
plainDie := die
die += getModifier(getStat(skill.BaseStat))
die += GetModifier(GetStat(skill.BaseStat))
switch {
case skill.Expertise:
die += getProficiency() * 2
die += GetProficiency() * 2
case skill.Proficient:
die += getProficiency()
die += GetProficiency()
case !skill.Proficient && char.Misc.JackOfAllTrades:
die += (getProficiency() / 2)
die += (GetProficiency() / 2)
}
return die, plainDie, skillErrorCheck()
}
@ -316,7 +316,7 @@ func printStatList(verbose bool) {
proficiency = "Not proficient"
}
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 {
for i := 0; i < len(char.Stats); i++ {
@ -332,16 +332,16 @@ func printSkillList(verbose bool) {
if verbose {
for i := 0; i < len(char.Skills); i++ {
name := char.Skills[i].SkillName
localModifier := getModifier(getStat(char.Skills[i].BaseStat))
localModifier := GetModifier(GetStat(char.Skills[i].BaseStat))
if char.Skills[i].Proficient {
proficiency = "Proficient"
localModifier += getProficiency()
localModifier += GetProficiency()
} else {
proficiency = "Not proficient"
}
if char.Skills[i].Expertise {
expertise = "Has expertise"
localModifier += getProficiency()
localModifier += GetProficiency()
} else {
expertise = "Doesn't have expertise"
}