2015-02-26 05:24:31 -05:00
|
|
|
// characters and moar by vypr
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-05 23:07:18 -04:00
|
|
|
"encoding/json"
|
2015-02-26 05:24:31 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2015-06-05 23:07:18 -04:00
|
|
|
type Character struct {
|
2015-06-09 07:02:15 -04:00
|
|
|
Equipment struct {
|
|
|
|
Armour []interface{} `json:"armour"`
|
|
|
|
Items []interface{} `json:"items"`
|
|
|
|
Missiles []interface{} `json:"missiles"`
|
|
|
|
Weapons []interface{} `json:"weapons"`
|
|
|
|
} `json:"equipment"`
|
|
|
|
Personal struct {
|
|
|
|
Ac int `json:"ac"`
|
|
|
|
Age int `json:"age"`
|
|
|
|
Alignment string `json:"alignment"`
|
|
|
|
Classes []string `json:"classes"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Hp int `json:"hp"`
|
|
|
|
Lvl int `json:"lvl"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Race string `json:"race"`
|
|
|
|
Sex string `json:"sex"`
|
|
|
|
Weight int `json:"weight"`
|
|
|
|
Xp int `json:"xp"`
|
|
|
|
} `json:"personal"`
|
|
|
|
Stats struct {
|
|
|
|
Cha int `json:"cha"`
|
|
|
|
Con int `json:"con"`
|
|
|
|
Dex int `json:"dex"`
|
|
|
|
Intl int `json:"intl"`
|
|
|
|
Str int `json:"str"`
|
|
|
|
Wis int `json:"wis"`
|
|
|
|
} `json:"stats"`
|
|
|
|
Wealth struct {
|
|
|
|
Coins int `json:"coins"`
|
|
|
|
Gems []interface{} `json:"gems"`
|
|
|
|
Other []interface{} `json:"other"`
|
|
|
|
} `json:"wealth"`
|
2015-06-05 23:07:18 -04:00
|
|
|
}
|
|
|
|
|
2015-06-09 08:08:31 -04:00
|
|
|
var charmap map[string]*Character
|
2015-02-26 05:24:31 -05:00
|
|
|
|
2015-06-09 08:08:31 -04:00
|
|
|
func accessChar(nick string, cat string, item string) string {
|
2015-06-08 05:50:39 -04:00
|
|
|
var pdata, edata, sdata, wdata bool
|
2015-06-09 07:02:15 -04:00
|
|
|
|
|
|
|
switch cat {
|
|
|
|
case "personal":
|
|
|
|
pdata = true
|
|
|
|
break
|
|
|
|
case "equipment":
|
|
|
|
edata = true
|
|
|
|
break
|
|
|
|
case "stats":
|
|
|
|
sdata = true
|
|
|
|
break
|
|
|
|
case "wealth":
|
|
|
|
wdata = true
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid category"
|
2015-06-05 23:07:18 -04:00
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
|
2015-06-08 06:15:18 -04:00
|
|
|
if pdata {
|
2015-06-09 07:02:15 -04:00
|
|
|
switch item {
|
2015-06-08 05:50:39 -04:00
|
|
|
case "name":
|
2015-06-09 07:02:15 -04:00
|
|
|
return charmap[nick].Personal.Name
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "lvl":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Lvl)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "race":
|
2015-06-09 07:02:15 -04:00
|
|
|
return charmap[nick].Personal.Race
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "xp":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Xp)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "height":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Height)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "alignment":
|
2015-06-09 07:02:15 -04:00
|
|
|
return charmap[nick].Personal.Alignment
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "classes":
|
|
|
|
var classes string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Personal.Classes {
|
|
|
|
if len(charmap[nick].Personal.Classes) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(classes) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
classes = classes + ", " + j
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-08 06:15:18 -04:00
|
|
|
classes = j
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(classes) > 0 {
|
|
|
|
return classes
|
|
|
|
}
|
|
|
|
return "you've got no classes, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "weight":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Weight)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "sex":
|
2015-06-09 07:02:15 -04:00
|
|
|
return charmap[nick].Personal.Sex
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "hp":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Hp)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "ac":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Ac)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "age":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Personal.Age)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid item"
|
|
|
|
break
|
2015-02-26 05:24:31 -05:00
|
|
|
}
|
2015-06-08 06:15:18 -04:00
|
|
|
} else if edata {
|
2015-06-09 07:02:15 -04:00
|
|
|
switch item {
|
2015-06-08 05:50:39 -04:00
|
|
|
case "armour":
|
|
|
|
var armour string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Equipment.Armour {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Equipment.Armour) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(armour) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
armour = armour + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
armour = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(armour) > 0 {
|
|
|
|
return armour
|
|
|
|
}
|
|
|
|
return "you've got no armour, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "weapons":
|
|
|
|
var weapons string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Equipment.Weapons {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Equipment.Weapons) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(weapons) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
weapons = weapons + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
weapons = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(weapons) > 0 {
|
|
|
|
return weapons
|
|
|
|
}
|
|
|
|
return "you've got no weapons, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "items":
|
|
|
|
var items string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Equipment.Items {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Equipment.Items) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(items) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
items = items + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
items = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(items) > 0 {
|
|
|
|
return items
|
|
|
|
}
|
|
|
|
return "you've got no items, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "missiles":
|
|
|
|
var missiles string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Equipment.Missiles {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Equipment.Missiles) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(missiles) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
missiles = missiles + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
missiles = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(missiles) > 0 {
|
|
|
|
return missiles
|
|
|
|
}
|
|
|
|
return "you've got no missiles, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid item"
|
|
|
|
break
|
|
|
|
}
|
2015-06-08 06:15:18 -04:00
|
|
|
} else if sdata {
|
2015-06-09 07:02:15 -04:00
|
|
|
switch item {
|
2015-06-08 05:50:39 -04:00
|
|
|
case "con":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Con)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "str":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Str)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "intl":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Intl)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "cha":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Cha)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "wis":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Wis)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "dex":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Stats.Dex)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid item"
|
|
|
|
break
|
|
|
|
}
|
2015-06-08 06:15:18 -04:00
|
|
|
} else if wdata {
|
2015-06-09 07:02:15 -04:00
|
|
|
switch item {
|
2015-06-08 05:50:39 -04:00
|
|
|
case "coins":
|
2015-06-09 07:02:15 -04:00
|
|
|
return strconv.Itoa(charmap[nick].Wealth.Coins)
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "other":
|
|
|
|
var other string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Wealth.Other {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Wealth.Other) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(other) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
other = other + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
other = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(other) > 0 {
|
|
|
|
return other
|
|
|
|
}
|
|
|
|
return "you've got no other items, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "gems":
|
|
|
|
var gems string
|
2015-06-09 07:02:15 -04:00
|
|
|
for _, j := range charmap[nick].Wealth.Gems {
|
|
|
|
value, _ := j.(string)
|
|
|
|
if len(charmap[nick].Wealth.Gems) > 0 {
|
2015-06-08 05:50:39 -04:00
|
|
|
if len(gems) > 0 {
|
2015-06-09 07:02:15 -04:00
|
|
|
gems = gems + ", " + value
|
2015-06-08 05:50:39 -04:00
|
|
|
} else {
|
2015-06-09 07:02:15 -04:00
|
|
|
gems = value
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
if len(gems) > 0 {
|
|
|
|
return gems
|
|
|
|
}
|
|
|
|
return "you've got no gems, m80"
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:02:15 -04:00
|
|
|
|
2015-06-08 06:19:28 -04:00
|
|
|
return "*shrug*"
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
2015-02-28 06:46:44 -05:00
|
|
|
|
2015-06-08 05:50:39 -04:00
|
|
|
func importChar(nick string) bool {
|
|
|
|
file, err := ioutil.ReadFile("json/" + nick + ".json")
|
2015-02-28 06:46:44 -05:00
|
|
|
|
|
|
|
if err != nil {
|
2015-06-08 06:33:27 -04:00
|
|
|
panic(err)
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
|
2015-06-08 05:50:39 -04:00
|
|
|
var char Character
|
|
|
|
|
2015-06-09 07:02:15 -04:00
|
|
|
err = json.Unmarshal([]byte(file), &char)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:08:31 -04:00
|
|
|
charmap = map[string]*Character{
|
|
|
|
nick: &char,
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
|
2015-06-09 08:08:31 -04:00
|
|
|
func setChar(nick string, cat string, item string, value string) bool {
|
|
|
|
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
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if pdata {
|
|
|
|
switch item {
|
|
|
|
case "name":
|
|
|
|
charmap[nick].Personal.Name = value
|
|
|
|
break
|
|
|
|
case "lvl":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Lvl = value
|
|
|
|
break
|
|
|
|
case "race":
|
|
|
|
charmap[nick].Personal.Race = value
|
|
|
|
break
|
|
|
|
case "xp":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Xp = value
|
|
|
|
break
|
|
|
|
case "height":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Height = value
|
|
|
|
break
|
|
|
|
case "alignment":
|
|
|
|
charmap[nick].Personal.Alignment = value
|
|
|
|
break
|
|
|
|
case "classes":
|
|
|
|
charmap[nick].Personal.Classes = append(charmap[nick].Personal.Classes, value)
|
|
|
|
break
|
|
|
|
case "weight":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Weight = value
|
|
|
|
break
|
|
|
|
case "sex":
|
|
|
|
charmap[nick].Personal.Sex = value
|
|
|
|
break
|
|
|
|
case "hp":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Hp = value
|
|
|
|
break
|
|
|
|
case "ac":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Ac = value
|
|
|
|
break
|
|
|
|
case "age":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Personal.Age = value
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} else if edata {
|
|
|
|
switch item {
|
|
|
|
case "armour":
|
2015-06-09 18:24:38 -04:00
|
|
|
var armour string
|
2015-06-09 08:08:31 -04:00
|
|
|
armour = value
|
|
|
|
charmap[nick].Equipment.Armour = append(charmap[nick].Equipment.Armour, armour)
|
|
|
|
break
|
|
|
|
case "weapons":
|
2015-06-09 18:24:38 -04:00
|
|
|
var weapons string
|
2015-06-09 08:08:31 -04:00
|
|
|
weapons = value
|
|
|
|
charmap[nick].Equipment.Weapons = append(charmap[nick].Equipment.Weapons, weapons)
|
|
|
|
break
|
|
|
|
case "items":
|
2015-06-09 18:24:38 -04:00
|
|
|
var items string
|
2015-06-09 08:08:31 -04:00
|
|
|
items = value
|
|
|
|
charmap[nick].Equipment.Items = append(charmap[nick].Equipment.Items, items)
|
|
|
|
break
|
|
|
|
case "missiles":
|
2015-06-09 18:24:38 -04:00
|
|
|
var missiles string
|
2015-06-09 08:08:31 -04:00
|
|
|
missiles = value
|
|
|
|
charmap[nick].Equipment.Missiles = append(charmap[nick].Equipment.Missiles, missiles)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} else if sdata {
|
|
|
|
switch item {
|
|
|
|
case "con":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Con = value
|
|
|
|
break
|
|
|
|
case "str":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Str = value
|
|
|
|
break
|
|
|
|
case "intl":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Intl = value
|
|
|
|
break
|
|
|
|
case "cha":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Cha = value
|
|
|
|
break
|
|
|
|
case "wis":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Wis = value
|
|
|
|
break
|
|
|
|
case "dex":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Stats.Dex = value
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} else if wdata {
|
|
|
|
switch item {
|
|
|
|
case "coins":
|
|
|
|
value, _ := strconv.Atoi(value)
|
|
|
|
charmap[nick].Wealth.Coins = value
|
|
|
|
break
|
|
|
|
case "other":
|
2015-06-09 18:24:38 -04:00
|
|
|
var other string
|
2015-06-09 08:08:31 -04:00
|
|
|
other = value
|
|
|
|
charmap[nick].Wealth.Other = append(charmap[nick].Wealth.Other, other)
|
|
|
|
break
|
|
|
|
case "gems":
|
2015-06-09 18:24:38 -04:00
|
|
|
var gems string
|
2015-06-09 08:08:31 -04:00
|
|
|
gems = value
|
|
|
|
charmap[nick].Wealth.Gems = append(charmap[nick].Wealth.Gems, gems)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, _ := json.MarshalIndent(charmap[nick], "", " ")
|
|
|
|
|
|
|
|
err := ioutil.WriteFile("json/"+nick+".json", data, 0644)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|