// characters and moar by vypr package main import ( "encoding/json" "io/ioutil" "strconv" ) type Character struct { irc string personal PersonalData equipment EquipmentData stats StatData wealth WealthData } type PersonalData struct { name string lvl int race string xp int height int alignment string classes []string weight int sex string hp int ac int age int } type EquipmentData struct { armour []string weapons []string items []string missiles []string } type StatData struct { con int str int intl int cha int wis int dex int } type WealthData struct { coins int other []string gems []string } var charmap map[string]Character func accessChar(set bool, nick string, cat string, item string, val string) string { var pdata, edata, sdata, wdata bool switch (cat) { case "personal": pdata = true break case "equipment": edata = true break case "stats": sdata = true break case "wealth": wdata = true break case "nil": return charmap[nick].irc // can't be anything else but break default: return "invalid category" } if pdata { switch (item) { case "name": return charmap[nick].personal.name break case "lvl": return strconv.Itoa(charmap[nick].personal.lvl) break case "race": return charmap[nick].personal.race break case "xp": return strconv.Itoa(charmap[nick].personal.xp) break case "height": return strconv.Itoa(charmap[nick].personal.height) break case "alignment": return charmap[nick].personal.alignment break case "classes": var classes string for _, j := range charmap[nick].personal.classes { if len(charmap[nick].personal.classes) > 0 { if len(classes) > 0 { classes = classes + ", " + j } else { classes = j } } } break case "weight": return strconv.Itoa(charmap[nick].personal.weight) break case "sex": return charmap[nick].personal.sex break case "hp": return strconv.Itoa(charmap[nick].personal.hp) break case "ac": return strconv.Itoa(charmap[nick].personal.ac) break case "age": return strconv.Itoa(charmap[nick].personal.age) break default: return "invalid item" break } } else if edata { switch (item) { case "armour": var armour string for _, j := range charmap[nick].equipment.armour { if len(charmap[nick].equipment.armour) > 0 { if len(armour) > 0 { armour = armour + ", " + j } else { armour = j } } } break case "weapons": var weapons string for _, j := range charmap[nick].equipment.weapons { if len(charmap[nick].equipment.weapons) > 0 { if len(weapons) > 0 { weapons = weapons + ", " + j } else { weapons = j } } } break case "items": var items string for _, j := range charmap[nick].equipment.items { if len(charmap[nick].equipment.items) > 0 { if len(items) > 0 { items = items + ", " + j } else { items = j } } } break case "missiles": var missiles string for _, j := range charmap[nick].equipment.missiles { if len(charmap[nick].equipment.missiles) > 0 { if len(missiles) > 0 { missiles = missiles + ", " + j } else { missiles = j } } } break default: return "invalid item" break } } else if sdata { switch (item) { case "con": return strconv.Itoa(charmap[nick].stats.con) break case "str": return strconv.Itoa(charmap[nick].stats.str) break case "intl": return strconv.Itoa(charmap[nick].stats.intl) break case "cha": return strconv.Itoa(charmap[nick].stats.cha) break case "wis": return strconv.Itoa(charmap[nick].stats.wis) break case "dex": return strconv.Itoa(charmap[nick].stats.dex) break default: return "invalid item" break } } else if wdata { switch (item) { case "coins": return strconv.Itoa(charmap[nick].wealth.coins) break case "other": var other string for _, j := range charmap[nick].wealth.other { if len(charmap[nick].wealth.other) > 0 { if len(other) > 0 { other = other + ", " + j } else { other = j } } } break case "gems": var gems string for _, j := range charmap[nick].wealth.gems { if len(charmap[nick].wealth.gems) > 0 { if len(gems) > 0 { gems = gems + ", " + j } else { gems = j } } } break } } return "*shrug*" } func importChar(nick string) bool { file, err := ioutil.ReadFile("json/" + nick + ".json") if err != nil { panic(err) } var char Character json.Unmarshal(file, char) charmap = map[string]Character{ char.irc: char, } return true } func setChar(nick string, cat string, scat string, item string, value string) bool { // With the changes I'm currently making, this will have to be changed as well. return false }