This commit is contained in:
shoopea 2019-07-22 17:02:53 +08:00
parent e7b171fcbb
commit 00135161e7

14
obj.go
View File

@ -661,8 +661,8 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int) (int64
c.Code = code c.Code = code
c.Name = name c.Name = name
c.Weight = weight c.Weight = weight
cacheObjItem[code] = c cacheObjItem[code] = *c
cacheObjItem[name] = c cacheObjItem[name] = *c
return objId, nil return objId, nil
} }
@ -709,7 +709,7 @@ func getSilentObjItemID(code string, name string) int64 {
i := ChatWarsItem{ i := ChatWarsItem{
ObjID64: 0, ObjID64: 0,
} }
for k, obj := range items { for k, obj := range cacheObjItem {
if ok, _ := regexp.MatchString(`^(a|e|w)[0-9]+$`, obj.Code); ok { //only gear can be custom named if ok, _ := regexp.MatchString(`^(a|e|w)[0-9]+$`, obj.Code); ok { //only gear can be custom named
m := fmt.Sprintf("^((%s.*)|(.*%s))$", regexp.QuoteMeta(obj.Name), regexp.QuoteMeta(obj.Name)) m := fmt.Sprintf("^((%s.*)|(.*%s))$", regexp.QuoteMeta(obj.Name), regexp.QuoteMeta(obj.Name))
if ok, _ := regexp.MatchString(m, basename); ok { if ok, _ := regexp.MatchString(m, basename); ok {
@ -767,8 +767,8 @@ func loadObjItem() error {
c.Name = name c.Name = name
c.Weight = weight c.Weight = weight
muxObjItem.Lock() muxObjItem.Lock()
cacheObjItem[intl_id] = c cacheObjItem[intl_id] = *c
cacheObjItem[name] = c cacheObjItem[name] = *c
muxObjItem.Unlock() muxObjItem.Unlock()
} }
@ -784,14 +784,14 @@ func loadObjItem() error {
return err return err
} }
if _, ok := cacheObjItem.Load(intl_id); ok { if _, ok := cacheObjItem[intl_id]; ok {
c := new(ChatWarsItem) c := new(ChatWarsItem)
c.ObjID64 = id c.ObjID64 = id
c.Code = intl_id c.Code = intl_id
c.Name = name c.Name = name
c.Weight = weight c.Weight = weight
muxObjItem.Lock() muxObjItem.Lock()
cacheObjItem[name] = c cacheObjItem[name] = *c
muxObjItem.Unlock() muxObjItem.Unlock()
} else { } else {
log.Printf("loadObjItem : orphaned obj_name for `%s` : %s.\n", intl_id, name) log.Printf("loadObjItem : orphaned obj_name for `%s` : %s.\n", intl_id, name)