Got rid of explicit modifier

This commit is contained in:
Nox Sluijtman 2022-08-20 16:44:47 +02:00
parent 6910c1bf65
commit 811dbf8581
3 changed files with 13 additions and 14 deletions

14
main.go
View file

@ -72,14 +72,14 @@ func GetSkill(skillName string) Skill {
return char.Skills[skillMap[skillName]] return char.Skills[skillMap[skillName]]
} }
func GetSkillModifier(skill Skill) int {
return GetStat(skill.BaseStat).Modifier
}
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 {
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 {
@ -93,10 +93,10 @@ func SkillCheck(skill Skill) int {
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)
switch { switch {
case skill.Expertise: case skill.Expertise:
return die + GetSkillModifier(skill) + char.Misc.Proficiency*2 return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency*2
case skill.Proficient: case skill.Proficient:
return die + GetSkillModifier(skill) + char.Misc.Proficiency return die + GetModifier(GetStat(skill.BaseStat)) + char.Misc.Proficiency
default: default:
return die + GetSkillModifier(skill) return die + GetModifier(GetStat(skill.BaseStat))
} }
} }

View file

@ -21,6 +21,5 @@ type Skill struct {
type Stat struct { type Stat struct {
StatName string `json:"statName"` StatName string `json:"statName"`
Score int `json:"score"` Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"` Proficient bool `json:"proficient"`
} }

View file

@ -6,12 +6,12 @@
"name": "Bob" "name": "Bob"
}, },
"stats":[ "stats":[
{"statName":"strength", "score":20, "modifier":5, "proficient":false }, {"statName":"strength", "score":20, "proficient":false },
{"statName":"dexterity", "score":10, "modifier":3, "proficient":false }, {"statName":"dexterity", "score":10, "proficient":false },
{"statName":"constitution", "score":10, "modifier":0, "proficient":false }, {"statName":"constitution", "score":15, "proficient":false },
{"statName":"intelligence", "score":10, "modifier":0, "proficient":false }, {"statName":"intelligence", "score":10, "proficient":false },
{"statName":"wisdom", "score":10, "modifier":0, "proficient":false }, {"statName":"wisdom", "score":10, "proficient":false },
{"statName":"charisma", "score":10, "modifier":0, "proficient":false } {"statName":"charisma", "score":10, "proficient":false }
], ],
"skills":[ "skills":[
{"skillName":"athletics", "proficient":false, "expertise":false, "baseStat":"strength"}, {"skillName":"athletics", "proficient":false, "expertise":false, "baseStat":"strength"},