Skip to content

Commit d0fee14

Browse files
authored
fix: improve character death parsing and removing creature prefix (#456)
1 parent 086f483 commit d0fee14

File tree

4 files changed

+1888
-28
lines changed

4 files changed

+1888
-28
lines changed

src/TibiaCharactersCharacter.go

Lines changed: 20 additions & 11 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"
@@ -560,6 +562,13 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string, url string) (CharacterR
560562
}
561563
}
562564
buffer.WriteByte(cur)
565+
566+
if cur == ')' {
567+
str := buffer.String()
568+
569+
buffer.Reset()
570+
ListOfKillers = append(ListOfKillers, str)
571+
}
563572
case openAnchorTag:
564573
if cur == '>' {
565574
state = nonTag
@@ -777,19 +786,19 @@ func TibiaDataParseKiller(data string) (string, bool, bool, string) {
777786
data = RemoveHtmlTag(data)
778787
}
779788

780-
// remove htlm, spaces and dots from data-string
789+
// remove htlm, spaces, dots and prefixes from data-string
781790
data = strings.TrimSpace(strings.TrimSuffix(strings.TrimSuffix(data, "</td>"), "."))
791+
data = strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(data, "and "), "a "), "an ")
782792

793+
firstRune, _ := utf8.DecodeRuneInString(data)
783794
// 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-
}
795+
if containsCreaturesWithOf(data) {
796+
// this is not a summon, since it is a creature with a of in the middle
797+
} else if unicode.IsLower(firstRune) {
798+
ofIdx := strings.Index(data, "of")
799+
if ofIdx != -1 {
800+
theSummon = data[:ofIdx-1]
801+
data = data[ofIdx+3:]
793802
}
794803
}
795804

@@ -876,9 +885,9 @@ func containsCreaturesWithOf(str string) bool {
876885
"pillar of summoning",
877886
"priestess of the wild sun",
878887
"rage of mazoran",
888+
"reflection of a mage",
879889
"reflection of mawhawk",
880890
"reflection of obujos",
881-
"reflection of a mage",
882891
"retainer of baeloc",
883892
"scorn of the emperor",
884893
"servant of tentugly",

0 commit comments

Comments
 (0)