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"
|
2015-02-28 06:46:44 -05:00
|
|
|
"os"
|
2015-02-26 05:24:31 -05:00
|
|
|
"strconv"
|
2015-02-28 06:46:44 -05:00
|
|
|
"strings"
|
2015-02-26 05:24:31 -05:00
|
|
|
)
|
|
|
|
|
2015-06-05 23:07:18 -04:00
|
|
|
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
|
2015-02-26 05:24:31 -05:00
|
|
|
|
2015-06-08 05:50:39 -04:00
|
|
|
func accessChar(set bool, nick string, cat string, item string, val string) string {
|
|
|
|
var pdata, edata, sdata, wdata bool
|
2015-06-05 23:07:18 -04:00
|
|
|
|
|
|
|
switch (cat) {
|
|
|
|
case "personal":
|
2015-06-08 05:50:39 -04:00
|
|
|
pdata = true
|
2015-06-05 23:07:18 -04:00
|
|
|
break
|
|
|
|
case "equipment":
|
2015-06-08 05:50:39 -04:00
|
|
|
edata = true
|
2015-06-05 23:07:18 -04:00
|
|
|
break
|
|
|
|
case "stats":
|
2015-06-08 05:50:39 -04:00
|
|
|
sdata = true
|
2015-06-05 23:07:18 -04:00
|
|
|
break
|
|
|
|
case "wealth":
|
2015-06-08 05:50:39 -04:00
|
|
|
wdata = true
|
2015-06-05 23:07:18 -04:00
|
|
|
break
|
|
|
|
case "nil":
|
2015-06-08 05:50:39 -04:00
|
|
|
return charmap[nick].irc // can't be anything else but
|
2015-06-05 23:07:18 -04:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid category"
|
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
|
|
|
|
if personal {
|
|
|
|
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 i in range charmap[nick].personal.classes {
|
|
|
|
if len(charmap[nick].personal.classes > 0 {
|
|
|
|
if len(classes) > 0 {
|
|
|
|
classes = classes + ", " + i
|
|
|
|
} else {
|
|
|
|
classes = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2015-02-26 05:24:31 -05:00
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
} else if equipment {
|
|
|
|
switch (item) {
|
|
|
|
case "armour":
|
|
|
|
var armour string
|
|
|
|
for i in range charmap[nick].equipment.armour {
|
|
|
|
if len(charmap[nick].equipment.armour) > 0 {
|
|
|
|
if len(armour) > 0 {
|
|
|
|
armour = armour + ", " + i
|
|
|
|
} else {
|
|
|
|
armour = i
|
|
|
|
}
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
}
|
|
|
|
break
|
|
|
|
case "weapons":
|
|
|
|
var weapons string
|
|
|
|
for i in range charmap[nick].equipment.weapons {
|
|
|
|
if len(charmap[nick].equipment.weapons) > 0 {
|
|
|
|
if len(weapons) > 0 {
|
|
|
|
weapons = weapons + ", " + i
|
|
|
|
} else {
|
|
|
|
weapons = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case "items":
|
|
|
|
var items string
|
|
|
|
for i in range charmap[nick].equipment.items {
|
|
|
|
if len(charmap[nick].equipment.items) > 0 {
|
|
|
|
if len(items) > 0 {
|
|
|
|
items = items + ", " + i
|
|
|
|
} else {
|
|
|
|
items = i
|
|
|
|
}
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
break
|
|
|
|
case "missiles":
|
|
|
|
var missiles string
|
|
|
|
for i in range charmap[nick].equipment.missiles {
|
|
|
|
if len(charmap[nick].equipment.missiles) > 0 {
|
|
|
|
if len(missiles) > 0 {
|
|
|
|
missiles = missiles + ", " + i
|
|
|
|
} else {
|
|
|
|
missiles = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "invalid item"
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} else if stats {
|
|
|
|
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 wealth {
|
|
|
|
switch (item) {
|
|
|
|
case "coins":
|
|
|
|
return strconv.Itoa(charmap[nick].wealth.coins)
|
|
|
|
break
|
|
|
|
case "other":
|
|
|
|
var other string
|
|
|
|
for i in range charmap[nick].wealth.other {
|
|
|
|
if len(charmap[nick].wealth.other) > 0 {
|
|
|
|
if len(other) > 0 {
|
|
|
|
other = other + ", " + i
|
|
|
|
} else {
|
|
|
|
other = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case "gems":
|
|
|
|
var gems string
|
|
|
|
for i in range charmap[nick].wealth.gems {
|
|
|
|
if len(charmap[nick].wealth.gems) > 0 {
|
|
|
|
if len(gems) > 0 {
|
|
|
|
gems = gems + ", " + i
|
|
|
|
} else {
|
|
|
|
gems = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
}
|
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 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-06-08 05:50:39 -04:00
|
|
|
var char Character
|
|
|
|
|
|
|
|
json.Unmarshal(file, char)
|
|
|
|
|
|
|
|
charmap = map[string]*Character{
|
|
|
|
char.irc: char,
|
2015-02-28 06:46:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2015-06-08 05:50:39 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
}
|