update data

This commit is contained in:
shoopea 2020-04-18 12:18:01 +08:00
parent eb7d74d601
commit 1f74136180
3 changed files with 241 additions and 237 deletions

View File

@ -0,0 +1,136 @@
[
{
"item_type": "item_res",
"code": "01",
"weight": 1,
"exchange": "/t_01",
"auction": false,
"craftable": false,
"names": [
"Thread"
]
},
{
"item_type": "item_res",
"code": "02",
"weight": 1,
"exchange": "/t_02",
"auction": false,
"craftable": false,
"names": [
"Stick"
]
},
{
"item_type": "item_res",
"code": "03",
"weight": 1,
"exchange": "/t_03",
"auction": false,
"craftable": false,
"names": [
"Pelt"
]
},
{
"item_type": "item_res",
"code": "04",
"weight": 1,
"exchange": "/t_04",
"auction": false,
"craftable": false,
"names": [
"Bone"
]
},
{
"item_type": "item_res",
"code": "05",
"weight": 1,
"exchange": "/t_05",
"auction": false,
"craftable": false,
"names": [
"Coal"
]
},
{
"item_type": "item_res",
"code": "06",
"weight": 1,
"exchange": "/t_06",
"auction": false,
"craftable": false,
"names": [
"Charcoal"
]
},
{
"item_type": "item_res",
"code": "07",
"weight": 1,
"exchange": "/t_07",
"auction": false,
"craftable": false,
"names": [
"Powder"
]
},
{
"item_type": "item_res",
"code": "08",
"weight": 2,
"exchange": "/t_08",
"auction": false,
"craftable": false,
"names": [
"Iron Ore",
"Iron ore"
]
},
{
"item_type": "item_res",
"code": "09",
"weight": 1,
"exchange": "/t_09",
"auction": false,
"craftable": false,
"names": [
"Cloth"
]
},
{
"item_type": "item_res",
"code": "10",
"weight": 2,
"exchange": "/t_10",
"auction": false,
"craftable": false,
"names": [
"Silver Ore",
"Silver ore"
]
},
{
"item_type": "item_res",
"code": "100",
"weight": 0,
"exchange": "",
"auction": false,
"craftable": true,
"names": [
"Pouch of Gold"
]
},
{
"item_type": "item_res",
"code": "11",
"weight": 2,
"exchange": "/t_11",
"auction": false,
"craftable": false,
"names": [
"Bauxite"
]
}
]

View File

@ -1,138 +1,4 @@
[
{
"item_type": "item_res",
"code": "01",
"weight": 1,
"exchange": "/t_01",
"auction": false,
"craftable": false,
"names": [
"Thread"
]
},
{
"item_type": "item_res",
"code": "02",
"weight": 1,
"exchange": "/t_02",
"auction": false,
"craftable": false,
"names": [
"Stick"
]
},
{
"item_type": "item_res",
"code": "03",
"weight": 1,
"exchange": "/t_03",
"auction": false,
"craftable": false,
"names": [
"Pelt"
]
},
{
"item_type": "item_res",
"code": "04",
"weight": 1,
"exchange": "/t_04",
"auction": false,
"craftable": false,
"names": [
"Bone"
]
},
{
"item_type": "item_res",
"code": "05",
"weight": 1,
"exchange": "/t_05",
"auction": false,
"craftable": false,
"names": [
"Coal"
]
},
{
"item_type": "item_res",
"code": "06",
"weight": 1,
"exchange": "/t_06",
"auction": false,
"craftable": false,
"names": [
"Charcoal"
]
},
{
"item_type": "item_res",
"code": "07",
"weight": 1,
"exchange": "/t_07",
"auction": false,
"craftable": false,
"names": [
"Powder"
]
},
{
"item_type": "item_res",
"code": "08",
"weight": 2,
"exchange": "/t_08",
"auction": false,
"craftable": false,
"names": [
"Iron Ore",
"Iron ore"
]
},
{
"item_type": "item_res",
"code": "09",
"weight": 1,
"exchange": "/t_09",
"auction": false,
"craftable": false,
"names": [
"Cloth"
]
},
{
"item_type": "item_res",
"code": "10",
"weight": 2,
"exchange": "/t_10",
"auction": false,
"craftable": false,
"names": [
"Silver Ore",
"Silver ore"
]
},
{
"item_type": "item_res",
"code": "100",
"weight": 0,
"exchange": "",
"auction": false,
"craftable": true,
"names": [
"Pouch of Gold"
]
},
{
"item_type": "item_res",
"code": "11",
"weight": 2,
"exchange": "/t_11",
"auction": false,
"craftable": false,
"names": [
"Bauxite"
]
},
{
"item_type": "item_res",
"code": "12",

208
item.go
View File

@ -277,12 +277,13 @@ func getCraftItemID(cmd string) (int64, error) {
func loadObjItem() error {
var (
obj_id int64
type_id int64
intl_id string
name string
weight int64
craftable int
obj_id int64
type_id int64
intl_id string
name string
weight int64
craftable int
objItemsBuf []ChatWarsItem
)
muxObjItem.Lock()
@ -295,122 +296,123 @@ func loadObjItem() error {
for _, a := range AssetNames() {
m, err := regexp.MatchString("data/obj_item/.*\\.json", a)
logOnError(err, "loadObjItem : MatchString")
itemsBefore := len(objItems)
if m {
b, err := Asset(a)
logOnError(err, "loadObjItem : load Asset("+a+")")
if err != nil {
return err
}
objItemsBuf = make([]ChatWarsItem, 0)
err = json.Unmarshal(b, &objItemsBuf)
objItems = append(objItems, objItemsBuf)
log.Printf("%d items parsed from %s.\n", len(objItemsBuf), a)
}
}
err = json.Unmarshal(b, &objItems)
var k int64
for k = 0; k < int64(len(objItems)); k++ {
if len(objItems[k].Names) == 0 {
log.Printf("loadObjItems : %s : name missing.\n", objItems[k].Code)
} else {
if id, ok := cacheObjItem[objItems[k].Code]; ok {
log.Printf("loadObjItem : %s : duplicate code found. Belong to %s\n", objItems[id].Code, objItems[id].Names[0])
var k int64
for k = 0; k < int64(len(objItems)); k++ {
if len(objItems[k].Names) == 0 {
log.Printf("loadObjItems : %s : name missing.\n", objItems[k].Code)
} else {
if id, ok := cacheObjItem[objItems[k].Code]; ok {
log.Printf("loadObjItem : %s : duplicate code found. Belong to %s\n", objItems[id].Code, objItems[id].Names[0])
} else {
cacheObjItem[objItems[k].Code] = k
objItems[k].ItemTypeID = cacheObjSubType[objItems[k].ItemType]
for _, n := range objItems[k].Names {
if id, ok := cacheObjItem[n]; ok {
log.Printf("loadObjItem : %s - %s : duplicate name found. Belongs to %s\n", objItems[k].Code, n, objItems[id].Code)
} else {
cacheObjItem[objItems[k].Code] = k
objItems[k].ItemTypeID = cacheObjSubType[objItems[k].ItemType]
for _, n := range objItems[k].Names {
if id, ok := cacheObjItem[n]; ok {
log.Printf("loadObjItem : %s - %s : duplicate name found. Belongs to %s\n", objItems[k].Code, n, objItems[id].Code)
} else {
cacheObjItem[n] = k
}
}
cacheObjItem[n] = k
}
}
}
}
}
objs, err := db.Query(`SELECT oi.obj_id, o.obj_sub_type_id, oi.intl_id, oi.weight, oi.craftable FROM obj o, obj_item oi WHERE o.id = oi.obj_id;`)
if err != nil {
logOnError(err, "loadObjItem : querying items")
return err
objs, err := db.Query(`SELECT oi.obj_id, o.obj_sub_type_id, oi.intl_id, oi.weight, oi.craftable FROM obj o, obj_item oi WHERE o.id = oi.obj_id;`)
if err != nil {
logOnError(err, "loadObjItem : querying items")
return err
}
defer objs.Close()
for objs.Next() {
err = objs.Scan(&obj_id, &type_id, &intl_id, &weight, &craftable)
if err != nil {
logOnError(err, "loadObjItem : scanning items")
return err
}
if id, ok := cacheObjItem[intl_id]; !ok {
log.Printf("loadObjItem : %s : orphaned item in database (id : %d)\n", intl_id, obj_id)
} else {
objItems[id].ObjID64 = obj_id
if weight != objItems[id].Weight {
log.Printf("loadObjItem : %s - %s : weight changed : %d => %d\n", objItems[id].Code, objItems[id].Names[0], weight, objItems[id].Weight)
setObjItemWeight(obj_id, objItems[id].Weight)
}
defer objs.Close()
for objs.Next() {
err = objs.Scan(&obj_id, &type_id, &intl_id, &weight, &craftable)
if err != nil {
logOnError(err, "loadObjItem : scanning items")
return err
}
if (craftable == 0 && objItems[id].Craftable) || (craftable == 1 && !objItems[id].Craftable) {
log.Printf("loadObjItem : %s - %s : craftable changed : %v => %v\n", objItems[id].Code, objItems[id].Names[0], !objItems[id].Craftable, objItems[id].Craftable)
setObjItemCraftable(obj_id, objItems[id].Craftable)
}
if id, ok := cacheObjItem[intl_id]; !ok {
log.Printf("loadObjItem : %s : orphaned item in database (id : %d)\n", intl_id, obj_id)
cacheObjItemId[obj_id] = id
}
}
names, err := db.Query(`SELECT oi.obj_id, obn.name FROM obj_item oi, obj_name obn WHERE oi.obj_id = obn.obj_id;`)
if err != nil {
logOnError(err, "loadObjItem : querying names")
return err
}
defer names.Close()
for names.Next() {
err = names.Scan(&obj_id, &name)
if err != nil {
logOnError(err, "loadObjItem : scanning names")
return err
}
if _, ok := cacheObjItem[name]; !ok {
if id, ok := cacheObjItemId[obj_id]; ok {
log.Printf("loadObjItem : %s : orphaned name in database for item %s\n", name, objItems[id].Code)
}
}
}
for _, i := range cacheObjItem {
if objItems[i].ObjID64 == 0 {
id, _ := addObjItem(objItems[i].Code, objItems[i].Names[0], objItems[i].ItemTypeID, objItems[i].Weight, objItems[i].Exchange, objItems[i].Auction, objItems[i].Craftable)
objItems[i].ObjID64 = id
cacheObjItemId[id] = i
for _, n := range objItems[i].Names {
objAddName(id, n)
cacheObjItem[n] = id
}
}
}
for _, i := range cacheObjItem {
if objItems[i].Craft != nil {
cacheObjItemCraft[objItems[i].Craft.Command] = i
setObjItemCraft(objItems[i].ObjID64, objItems[i].Craft.Command, objItems[i].Craft.Mana)
emptyObjItemCraftItem(objItems[i].ObjID64)
for k, o := range objItems[i].Craft.Items {
if id, ok := cacheObjItem[o.Code]; !ok {
log.Printf("loadObjItem : %s : unknown item %s for recipe.\n", objItems[i].Code, o.Code)
} else {
objItems[id].ObjID64 = obj_id
if weight != objItems[id].Weight {
log.Printf("loadObjItem : %s - %s : weight changed : %d => %d\n", objItems[id].Code, objItems[id].Names[0], weight, objItems[id].Weight)
setObjItemWeight(obj_id, objItems[id].Weight)
}
if (craftable == 0 && objItems[id].Craftable) || (craftable == 1 && !objItems[id].Craftable) {
log.Printf("loadObjItem : %s - %s : craftable changed : %v => %v\n", objItems[id].Code, objItems[id].Names[0], !objItems[id].Craftable, objItems[id].Craftable)
setObjItemCraftable(obj_id, objItems[id].Craftable)
}
cacheObjItemId[obj_id] = id
objItems[i].Craft.Items[k].ItemID64 = objItems[id].ObjID64
}
}
names, err := db.Query(`SELECT oi.obj_id, obn.name FROM obj_item oi, obj_name obn WHERE oi.obj_id = obn.obj_id;`)
if err != nil {
logOnError(err, "loadObjItem : querying names")
return err
for _, o := range objItems[i].Craft.Items {
addObjItemCraftItem(objItems[i].ObjID64, o.ItemID64, o.Quantity)
}
defer names.Close()
for names.Next() {
err = names.Scan(&obj_id, &name)
if err != nil {
logOnError(err, "loadObjItem : scanning names")
return err
}
if _, ok := cacheObjItem[name]; !ok {
if id, ok := cacheObjItemId[obj_id]; ok {
log.Printf("loadObjItem : %s : orphaned name in database for item %s\n", name, objItems[id].Code)
}
}
}
for _, i := range cacheObjItem {
if objItems[i].ObjID64 == 0 {
id, _ := addObjItem(objItems[i].Code, objItems[i].Names[0], objItems[i].ItemTypeID, objItems[i].Weight, objItems[i].Exchange, objItems[i].Auction, objItems[i].Craftable)
objItems[i].ObjID64 = id
cacheObjItemId[id] = i
for _, n := range objItems[i].Names {
objAddName(id, n)
cacheObjItem[n] = id
}
}
}
for _, i := range cacheObjItem {
if objItems[i].Craft != nil {
cacheObjItemCraft[objItems[i].Craft.Command] = i
setObjItemCraft(objItems[i].ObjID64, objItems[i].Craft.Command, objItems[i].Craft.Mana)
emptyObjItemCraftItem(objItems[i].ObjID64)
for k, o := range objItems[i].Craft.Items {
if id, ok := cacheObjItem[o.Code]; !ok {
log.Printf("loadObjItem : %s : unknown item %s for recipe.\n", objItems[i].Code, o.Code)
} else {
objItems[i].Craft.Items[k].ItemID64 = objItems[id].ObjID64
}
}
for _, o := range objItems[i].Craft.Items {
addObjItemCraftItem(objItems[i].ObjID64, o.ItemID64, o.Quantity)
}
}
}
log.Printf("%d items loaded for %s.\n", len(objItems)-itemsBefore, a)
}
}