Skip to content

Commit ab30a38

Browse files
committed
fix: character death parsings with creatures
1 parent 71ffb4e commit ab30a38

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/TibiaCharactersCharacter.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"net/http"
88
"reflect"
99
"strings"
10+
"unicode"
11+
"unicode/utf8"
1012

1113
"github.com/PuerkitoBio/goquery"
1214
"github.com/TibiaData/tibiadata-api-go/src/validation"
@@ -777,19 +779,19 @@ func TibiaDataParseKiller(data string) (string, bool, bool, string) {
777779
data = RemoveHtmlTag(data)
778780
}
779781

780-
// remove htlm, spaces and dots from data-string
782+
// remove htlm, spaces, dots and prefixes from data-string
781783
data = strings.TrimSpace(strings.TrimSuffix(strings.TrimSuffix(data, "</td>"), "."))
784+
data = strings.TrimPrefix(strings.TrimPrefix(data, "a "), "an ")
782785

786+
firstRune, _ := utf8.DecodeRuneInString(data)
783787
// get summon information
784-
if strings.HasPrefix(data, "a ") || strings.HasPrefix(data, "an ") {
785-
if containsCreaturesWithOf(data) {
786-
// this is not a summon, since it is a creature with a of in the middle
787-
} else {
788-
ofIdx := strings.Index(data, "of")
789-
if ofIdx != -1 {
790-
theSummon = data[:ofIdx-1]
791-
data = data[ofIdx+3:]
792-
}
788+
if containsCreaturesWithOf(data) {
789+
// this is not a summon, since it is a creature with a of in the middle
790+
} else if unicode.IsLower(firstRune) {
791+
ofIdx := strings.Index(data, "of")
792+
if ofIdx != -1 {
793+
theSummon = data[:ofIdx-1]
794+
data = data[ofIdx+3:]
793795
}
794796
}
795797

0 commit comments

Comments
 (0)