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
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/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"
"time"
"gitlab.com/EternalWanderer/dice-roller/Colors"
"gitlab.com/EternalWanderer/dice-roller/Dice"
)
var (
path string
path, skillString, saveString string
modifier, diceThrows, surfaces int
char Character
skillMap = make(map[string]int)
statMap = make(map[string]int)
advantage, disadvantage bool
)
func isError(err error) bool {
@ -26,11 +30,15 @@ func isError(err error) bool {
}
func parseFlags() {
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()
}
func readJson() {
fmt.Println("Opening file...", path)
fmt.Println("Opening file:", path)
var file, err = os.Open(path)
if isError(err) {
return
@ -41,27 +49,54 @@ func readJson() {
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() {
rand.Seed(time.Now().Unix())
parseFlags()
readJson()
initMaps()
Dice.SimpleCast()
charismaChecks()
fmt.Println(SkillCheck(GetSkill(skillString)))
}
func charismaChecks() {
die := Dice.SimpleCast()
proficiencyScore := char.Misc.Proficiency
expertiseScore := char.Misc.Proficiency * 2
fmt.Println("proficiencyScore:", proficiencyScore)
fmt.Println("expertiseScore:", expertiseScore)
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)
fmt.Printf("After all, %s has expertise in intimidation\n", char.Misc.Name)
} 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 GetSkill(skillName string) Skill {
return char.Skills[skillMap[skillName]]
}
func GetSkillModifier(skill Skill) int {
return GetStat(skill.BaseStat).Modifier
}
func GetStat(statName string) Stat {
return char.Stats[statMap[statName]]
}
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
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 {
Misc Misc `json:"misc"`
Stats Stats `json:"stats"`
Skills Skills `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"`
Stats []Stat `json:"stats"`
Skills []Skill `json:"skills"`
}
type Misc struct {
Proficiency int `json:"proficiency"`
Inspiration int `json:"inspiration"`
Level int `json:"level"`
Name string `json:"name"`
}
type Nature struct {
Modifier int `json:"modifier"`
type Skill struct {
SkillName string `json:"skillName"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
BaseStat string `json:"baseStat"`
}
type Performance struct {
Modifier int `json:"modifier"`
Proficient bool `json:"proficient"`
Expertise bool `json:"expertise"`
}
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 {
type Stat struct {
StatName string `json:"statName"`
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,
"name": "Bob"
},
"stats":{
"strength": { "score":10, "modifier":0, "proficient":false },
"dexterity": { "score":10, "modifier":0, "proficient":false },
"constitution": { "score":10, "modifier":0, "proficient":false },
"intelligence": { "score":10, "modifier":0, "proficient":false },
"wisdom": { "score":10, "modifier":0, "proficient":false },
"charisma": { "score":10, "modifier":0, "proficient":false }
},
"skills":{
"strength":{
"athletics": {"modifier":123, "proficient":false, "expertise":false }
},
"dexterity":{
"acrobatics": {"modifier":0, "proficient":false, "expertise":false },
"sleight-of-hand": {"modifier":0, "proficient":false, "expertise":false },
"stealth": {"modifier":0, "proficient":false, "expertise":false }
},
"intelligence":{
"arcana": {"modifier":0, "proficient":false, "expertise":false },
"history": {"modifier":0, "proficient":false, "expertise":false },
"investigation": {"modifier":0, "proficient":false, "expertise":false },
"nature": {"modifier":0, "proficient":false, "expertise":false },
"religion": {"modifier":0, "proficient":false, "expertise":false }
},
"wisdom":{
"animal-handling": {"modifier":0, "proficient":false, "expertise":false },
"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 }
}
}
"stats":[
{"statName":"strength", "score":20, "modifier":5, "proficient":false },
{"statName":"dexterity", "score":10, "modifier":3, "proficient":false },
{"statName":"constitution", "score":10, "modifier":0, "proficient":false },
{"statName":"intelligence", "score":10, "modifier":0, "proficient":false },
{"statName":"wisdom", "score":10, "modifier":0, "proficient":false },
{"statName":"charisma", "score":10, "modifier":0, "proficient":false }
],
"skills":[
{"skillName":"athletics", "proficient":false, "expertise":false, "baseStat":"strength"},
{"skillName":"acrobatics", "proficient":false, "expertise":false, "baseStat":"dexterity"},
{"skillName":"sleight_of_hand", "proficient":false, "expertise":false, "baseStat":"dexteriy"},
{"skillName":"stealth", "proficient":false, "expertise":false, "baseStat":"dexterity"},
{"skillName":"arcana", "proficient":false, "expertise":false, "baseStat":"intelligence"},
{"skillName":"history", "proficient":false, "expertise":false, "baseStat":"intelligence"},
{"skillName":"investigation", "proficient":false, "expertise":false, "baseStat":"intelligence"},
{"skillName":"nature", "proficient":false, "expertise":false, "baseStat":"intelligence"},
{"skillName":"religion", "proficient":false, "expertise":false, "baseStat":"intelligence"},
{"skillName":"animal_handling", "proficient":false, "expertise":false, "baseStat":"wisdom"},
{"skillName":"insight", "proficient":false, "expertise":false, "baseStat":"wisdom"},
{"skillName":"medicine", "proficient":false, "expertise":false, "baseStat":"wisdom"},
{"skillName":"survival", "proficient":false, "expertise":false, "baseStat":"wisdom"},
{"skillName":"deception", "proficient":false, "expertise":false, "baseStat":"charisma"},
{"skillName":"intimidation", "proficient":false, "expertise":true, "baseStat":"charisma"},
{"skillName":"performance", "proficient":true, "expertise":false, "baseStat":"charisma"},
{"skillName":"persuasion", "proficient":false, "expertise":false, "baseStat":"charisma"}
]
}