This commit is contained in:
shoopea 2019-06-14 14:28:26 +08:00
parent 0ea4d57c18
commit b4d10cc6eb

28
obj.go
View File

@ -598,42 +598,40 @@ func getObjItemID(c string, n string) int64 {
}
func silentGetObjItemID(code string, name string) int64 {
c := code
n := name
if v, ok := cacheObjItem.Load(c); ok {
if v, ok := cacheObjItem.Load(code); ok && len(code) > 0 {
i := v.(ChatWarsItem)
return i.ObjID64
}
if v, ok := cacheObjItem.Load(n); ok {
if v, ok := cacheObjItem.Load(name); ok && len(name) > 0 {
i := v.(ChatWarsItem)
return i.ObjID64
}
if ok, _ := regexp.MatchString(`^((u|e)[0-9]+|(a|w)[0-9]+[a-e]{0,1})$`, c); ok || len(c) == 0 {
if ok, _ := regexp.MatchString(`^((u|e)[0-9]+|(a|w)[0-9]+[a-e]{0,1})$`, code); ok || len(code) == 0 {
r := regexp.MustCompile(`^((?P<Modifier>⚡\+[0-9]+) ){0,1}(?P<BaseName>.+?)( \+(?P<Atk>[0-9]+)⚔){0,1}( \+(?P<Def>[0-9]+)🛡){0,1}( \+(?P<Mana>[0-9]+)💧){0,1}$`)
n2 := r.ReplaceAllString(n, "${BaseName}")
if v, ok := cacheObjItem.Load(n2); ok {
basename := r.ReplaceAllString(name, "${BaseName}")
if v, ok := cacheObjItem.Load(basename); ok && len(basename) > 0 {
i := v.(ChatWarsItem)
return i.ObjID64
}
i := ChatWarsItem{}
item := ChatWarsItem{}
cacheObjItem.Range(func(k, v interface{}) bool {
i = v.(ChatWarsItem)
if ok, _ := regexp.MatchString(`^(a|e|w)[0-9]+$`, i.Code); !ok { //only gear can be custom named
item = v.(ChatWarsItem)
if ok, _ := regexp.MatchString(`^(a|e|w)[0-9]+$`, item.Code); !ok { //only gear can be custom named
return true
}
m := fmt.Sprintf("^(%s.*|.*%s)$", regexp.QuoteMeta(i.Name), regexp.QuoteMeta(i.Name))
if ok, _ := regexp.MatchString(m, n2); ok {
m := fmt.Sprintf("^(%s.*|.*%s)$", regexp.QuoteMeta(item.Name), regexp.QuoteMeta(item.Name))
if ok, _ := regexp.MatchString(m, basename); ok {
return false
} else {
i = ChatWarsItem{
item = ChatWarsItem{
ObjID64: 0,
}
return true
}
})
if i.ObjID64 != 0 {
return i.ObjID64
if item.ObjID64 != 0 {
return item.ObjID64
} else {
fmt.Printf("silentGetObjItemID : Modifier : `%s`\n", r.ReplaceAllString(n, "${Modifier}"))
fmt.Printf("silentGetObjItemID : BaseName : `%s`\n", r.ReplaceAllString(n, "${BaseName}"))