Basic fucntionality works!

This commit is contained in:
Nox Sluijtman 2022-08-20 16:32:50 +02:00
parent 579dfc40d9
commit 6910c1bf65
5 changed files with 98 additions and 205 deletions

2
go.mod
View file

@ -2,4 +2,4 @@ module gitlab.com/EternalWanderer/sheet-parser/v2
go 1.19 go 1.19
require gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087 // indirect require gitlab.com/EternalWanderer/dice-roller v0.0.0-20220820120015-fa11a906e0aa

6
go.sum
View file

@ -1,4 +1,6 @@
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819100404-bed2f3df016e h1:pPt+f195MjWCtUITpZ65rNB/X+M9S3UiP8A1jCSwiXQ=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819100404-bed2f3df016e/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087 h1:0UCn74xm94G26W+6/LNb+Zc2dFFHKVgCVhVgam4zw/A= gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087 h1:0UCn74xm94G26W+6/LNb+Zc2dFFHKVgCVhVgam4zw/A=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs= gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220820113707-1e57a27bcf70 h1:Q3qDUsGJ+tEXz2vlC2ypIoipkcP34TvMs1vPw2p09LE=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220820113707-1e57a27bcf70/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220820120015-fa11a906e0aa h1:sSHBJ9+7N9m1gk+npe6wqs2Ghn4bYhyMN5eXWsKBH5Y=
gitlab.com/EternalWanderer/dice-roller v0.0.0-20220820120015-fa11a906e0aa/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs=

69
main.go
View file

@ -9,13 +9,17 @@ import (
"os" "os"
"time" "time"
"gitlab.com/EternalWanderer/dice-roller/Colors"
"gitlab.com/EternalWanderer/dice-roller/Dice" "gitlab.com/EternalWanderer/dice-roller/Dice"
) )
var ( var (
path string path, skillString, saveString string
modifier, diceThrows, surfaces int modifier, diceThrows, surfaces int
char Character char Character
skillMap = make(map[string]int)
statMap = make(map[string]int)
advantage, disadvantage bool
) )
func isError(err error) bool { func isError(err error) bool {
@ -26,11 +30,15 @@ func isError(err error) bool {
} }
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(&skillString, "s", "athletics", "Skill to parse")
flag.BoolVar(&advantage, "advantage", advantage, "Roll with advantage")
flag.BoolVar(&disadvantage, "disadvantage", disadvantage, "Roll with disadvantage")
flag.Parse() flag.Parse()
} }
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)
if isError(err) { if isError(err) {
return return
@ -41,27 +49,54 @@ func readJson() {
json.Unmarshal(byteValue, &char) json.Unmarshal(byteValue, &char)
} }
func initMaps() {
for i := 0; i < len(char.Skills); i++ {
skillMap[char.Skills[i].SkillName] = i
}
for i := 0; i < len(char.Stats); i++ {
statMap[char.Stats[i].StatName] = i
}
}
func main() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
parseFlags() parseFlags()
readJson() readJson()
initMaps()
Dice.SimpleCast() fmt.Println(SkillCheck(GetSkill(skillString)))
charismaChecks()
} }
func charismaChecks() { func GetSkill(skillName string) Skill {
die := Dice.SimpleCast() return char.Skills[skillMap[skillName]]
proficiencyScore := char.Misc.Proficiency }
expertiseScore := char.Misc.Proficiency * 2
fmt.Println("proficiencyScore:", proficiencyScore) func GetSkillModifier(skill Skill) int {
fmt.Println("expertiseScore:", expertiseScore) return GetStat(skill.BaseStat).Modifier
fmt.Println("die:", die) }
if char.Skills.Charisma.Intimidation.Expertise {
fmt.Printf("%s's Intimidation check results in %d\n", char.Misc.Name, die+char.Skills.Charisma.Intimidation.Modifier+expertiseScore) func GetStat(statName string) Stat {
fmt.Printf("After all, %s has expertise in intimidation\n", char.Misc.Name) return char.Stats[statMap[statName]]
} else if char.Skills.Charisma.Intimidation.Proficient { }
fmt.Printf("%s's Intimidation check results in %d\n", char.Misc.Name, die+char.Skills.Charisma.Intimidation.Modifier+proficiencyScore)
fmt.Printf("After all, %s is proficient with intimidation\n", char.Misc.Name) func SkillCheck(skill Skill) int {
var die, x, y int
switch {
case advantage:
die, x, y = Dice.Advantage()
case disadvantage:
die, x, y = Dice.Disadvantage()
default:
die = Dice.SimpleCast()
}
fmt.Printf("%s%d%s\tx: %d\ty: %d\n", Colors.ColorGreen, die, Colors.ColorReset, x, y)
switch {
case skill.Expertise:
return die + GetSkillModifier(skill) + char.Misc.Proficiency*2
case skill.Proficient:
return die + GetSkillModifier(skill) + char.Misc.Proficiency
default:
return die + GetSkillModifier(skill)
} }
} }

View file

@ -1,160 +1,26 @@
package main package main
type Acrobatics struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Animal_handling struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Arcana struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Athletics struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Character struct { type Character struct {
Misc Misc `json:"misc"` Misc Misc `json:"misc"`
Stats Stats `json:"stats"` Stats []Stat `json:"stats"`
Skills Skills `json:"skills"` Skills []Skill `json:"skills"`
}
type Charisma struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Deception Deception `json:"deception"`
Intimidation Intimidation `json:"intimidation"`
Performance Performance `json:"performance"`
Persuasion Persuasion `json:"persuasion"`
}
type Constitution struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
}
type Deception struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Dexterity struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Acrobatics Acrobatics `json:"acrobatics"`
Sleight_of_hand Sleight_of_hand `json:"sleight_of_hand"`
Stealth Stealth `json:"stealth"`
}
type History struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Insight struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Intelligence struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Arcana Arcana `json:"arcana"`
History History `json:"history"`
Investigation Investigation `json:"investigation"`
Nature Nature `json:"nature"`
Religion Religion `json:"religion"`
}
type Intimidation struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Investigation struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Medicine struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
} }
type Misc struct { type Misc struct {
Proficiency int `json:"proficiency"` Proficiency int `json:"proficiency"`
Inspiration int `json:"inspiration"` Inspiration int `json:"inspiration"`
Level int `json:"level"` Level int `json:"level"`
Name string `json:"name"` Name string `json:"name"`
} }
type Nature struct { type Skill struct {
Modifier int `json:"modifier"` SkillName string `json:"skillName"`
Proficient bool `json:"proficient"` Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"` Expertise bool `json:"expertise"`
BaseStat string `json:"baseStat"`
} }
type Performance struct { type Stat struct {
Modifier int `json:"modifier"` StatName string `json:"statName"`
Proficient bool `json:"proficient"` Score int `json:"score"`
Expertise bool `json:"expertise"` Modifier int `json:"modifier"`
} Proficient bool `json:"proficient"`
type Persuasion struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Religion struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Skills struct {
Strength Strength `json:"strength"`
Dexterity Dexterity `json:"dexterity"`
Intelligence Intelligence `json:"intelligence"`
Wisdom Wisdom `json:"wisdom"`
Charisma Charisma `json:"charisma"`
}
type Sleight_of_hand struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Stats struct {
Strength Strength `json:"strength"`
Dexterity Dexterity `json:"dexterity"`
Constitution Constitution `json:"constitution"`
Intelligence Intelligence `json:"intelligence"`
Wisdom Wisdom `json:"wisdom"`
Charisma Charisma `json:"charisma"`
}
type Stealth struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Strength struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Athletics Athletics `json:"athletics"`
}
type Survival struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
type Wisdom struct {
Score int `json:"score"`
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Animal_handling Animal_handling `json:"animal_handling"`
Insight Insight `json:"insight"`
Medicine Medicine `json:"medicine"`
Survival Survival `json:"survival"`
} }

View file

@ -5,41 +5,31 @@
"level": 0, "level": 0,
"name": "Bob" "name": "Bob"
}, },
"stats":{ "stats":[
"strength": { "score":10, "modifier":0, "proficient":false }, {"statName":"strength", "score":20, "modifier":5, "proficient":false },
"dexterity": { "score":10, "modifier":0, "proficient":false }, {"statName":"dexterity", "score":10, "modifier":3, "proficient":false },
"constitution": { "score":10, "modifier":0, "proficient":false }, {"statName":"constitution", "score":10, "modifier":0, "proficient":false },
"intelligence": { "score":10, "modifier":0, "proficient":false }, {"statName":"intelligence", "score":10, "modifier":0, "proficient":false },
"wisdom": { "score":10, "modifier":0, "proficient":false }, {"statName":"wisdom", "score":10, "modifier":0, "proficient":false },
"charisma": { "score":10, "modifier":0, "proficient":false } {"statName":"charisma", "score":10, "modifier":0, "proficient":false }
}, ],
"skills":{ "skills":[
"strength":{ {"skillName":"athletics", "proficient":false, "expertise":false, "baseStat":"strength"},
"athletics": {"modifier":123, "proficient":false, "expertise":false } {"skillName":"acrobatics", "proficient":false, "expertise":false, "baseStat":"dexterity"},
}, {"skillName":"sleight_of_hand", "proficient":false, "expertise":false, "baseStat":"dexteriy"},
"dexterity":{ {"skillName":"stealth", "proficient":false, "expertise":false, "baseStat":"dexterity"},
"acrobatics": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"arcana", "proficient":false, "expertise":false, "baseStat":"intelligence"},
"sleight-of-hand": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"history", "proficient":false, "expertise":false, "baseStat":"intelligence"},
"stealth": {"modifier":0, "proficient":false, "expertise":false } {"skillName":"investigation", "proficient":false, "expertise":false, "baseStat":"intelligence"},
}, {"skillName":"nature", "proficient":false, "expertise":false, "baseStat":"intelligence"},
"intelligence":{ {"skillName":"religion", "proficient":false, "expertise":false, "baseStat":"intelligence"},
"arcana": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"animal_handling", "proficient":false, "expertise":false, "baseStat":"wisdom"},
"history": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"insight", "proficient":false, "expertise":false, "baseStat":"wisdom"},
"investigation": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"medicine", "proficient":false, "expertise":false, "baseStat":"wisdom"},
"nature": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"survival", "proficient":false, "expertise":false, "baseStat":"wisdom"},
"religion": {"modifier":0, "proficient":false, "expertise":false } {"skillName":"deception", "proficient":false, "expertise":false, "baseStat":"charisma"},
}, {"skillName":"intimidation", "proficient":false, "expertise":true, "baseStat":"charisma"},
"wisdom":{ {"skillName":"performance", "proficient":true, "expertise":false, "baseStat":"charisma"},
"animal-handling": {"modifier":0, "proficient":false, "expertise":false }, {"skillName":"persuasion", "proficient":false, "expertise":false, "baseStat":"charisma"}
"insight": {"modifier":0, "proficient":false, "expertise":false }, ]
"medicine": {"modifier":0, "proficient":false, "expertise":false },
"survival": {"modifier":0, "proficient":false, "expertise":false }
},
"charisma":{
"deception": {"modifier":0, "proficient":false, "expertise":false },
"intimidation": {"modifier":0, "proficient":false, "expertise":true },
"performance": {"modifier":0, "proficient":true, "expertise":false },
"persuasion": {"modifier":0, "proficient":false, "expertise":false }
}
}
} }