debug message

update bindata
This commit is contained in:
shoopea 2020-04-18 11:44:42 +08:00
parent 14fe8d2d10
commit 7c5d823c72
2 changed files with 162 additions and 132 deletions

File diff suppressed because one or more lines are too long

206
item.go
View File

@ -292,121 +292,127 @@ func loadObjItem() error {
cacheObjItemCraft = make(map[string]int64)
objItems = make([]ChatWarsItem, 0)
b, err := Asset("data/obj_item.json")
logOnError(err, "loadObjItem : load data/obj_item.json")
if err != nil {
return err
}
for _, a := range AssetNames() {
m, err := regexp.MatchString("data/obj_item/.*\\.json", a)
logOnError(err, "loadObjItem : MatchString")
if m {
b, err := Asset(a)
logOnError(err, "loadObjItem : load Asset("+a+")")
if err != nil {
return err
}
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])
} 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)
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])
} else {
cacheObjItem[n] = k
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
}
}
}
}
}
}
}
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)
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()
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
}
}
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[i].Craft.Items[k].ItemID64 = objItems[id].ObjID64
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)
}
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
}
}
for _, o := range objItems[i].Craft.Items {
addObjItemCraftItem(objItems[i].ObjID64, o.ItemID64, o.Quantity)
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[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), a)
}
}
log.Printf("%d items loaded.\n", len(objItems))
/*
for _, v := range cacheObjItemId {
log.Printf("Item cached : %d\n", v.ObjID64)