Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions src/TibiaCharactersCharacterV3.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,50 @@ func TibiaDataParseKiller(data string) (string, bool, bool, string) {
}

// get summon information
rs := summonRegex.FindAllStringSubmatch(data, -1)
if len(rs) >= 1 {
theSummon = rs[0][1]
data = rs[0][2]
if strings.HasPrefix(data, "a ") || strings.HasPrefix(data, "an ") {
if containsCreaturesWithOf(data) {
// this is not a summon, since it is a creature with a of in the middle
} else {
rs := summonRegex.FindAllStringSubmatch(data, -1)
if len(rs) >= 1 {
theSummon = rs[0][1]
data = rs[0][2]
}
}
}

// sanitizing string
data = TibiaDataSanitizeStrings(data)

return data, isPlayer, isTraded, theSummon
}

// containsCreaturesWithOf checks if creature is present in special creatures list
func containsCreaturesWithOf(str string) bool {

// this list should be based on the https://assets.tibiadata.com/data.json creatures name and plural_name field (currently only singular version)
creaturesWithOf := []string{
"acolyte of the cult",
"adept of the cult",
"cloak of terror",
"energuardian of tales",
"enlightened of the cult",
"guardian of tales",
"hand of cursed fate",
"monk of the order",
"novice of the cult",
"priestess of the wild sun",
"sight of surrender",
"son of verminor",
}

// trim away "an " and "a "
str = strings.TrimPrefix(strings.TrimPrefix(str, "an "), "a ")

for _, v := range creaturesWithOf {
if v == str {
return true
}
}
return false
}
24 changes: 24 additions & 0 deletions src/TibiaCharactersCharacterV3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ func TestNumber4(t *testing.T) {

firstDeath := characterJson.Characters.Deaths[0]
assert.Equal(28, len(firstDeath.Killers))

creatureWithOfDeath := characterJson.Characters.Deaths[16]
assert.Equal(2, len(creatureWithOfDeath.Killers))
assert.Equal(260, creatureWithOfDeath.Level)
assert.Equal("an undead elite gladiator", creatureWithOfDeath.Killers[0].Name)
assert.False(creatureWithOfDeath.Killers[0].Player)
assert.False(creatureWithOfDeath.Killers[0].Traded)
assert.Empty(creatureWithOfDeath.Killers[0].Summon)
assert.Equal("a priestess of the wild sun", creatureWithOfDeath.Killers[1].Name)

tradedInDeath := characterJson.Characters.Deaths[18]
assert.Equal(3, len(tradedInDeath.Assists))
assert.Equal(261, tradedInDeath.Level)
assert.Equal("Vithrann", tradedInDeath.Assists[1].Name)
assert.True(tradedInDeath.Assists[1].Player)
assert.Equal("Adam No Hands", tradedInDeath.Assists[2].Name)
assert.True(tradedInDeath.Assists[2].Traded)

longDeath := characterJson.Characters.Deaths[78]
assert.Equal(5, len(longDeath.Assists))
assert.Equal(231, longDeath.Level)
assert.Equal("Adam No Hands", longDeath.Assists[4].Name)
assert.Equal("a paladin familiar", longDeath.Assists[4].Summon)
assert.True(longDeath.Assists[4].Traded)
}

func TestNumber5(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion testdata/characters/Riley No Hands.html

Large diffs are not rendered by default.