Skip to content

Commit 4e32e43

Browse files
authored
enhancing death parsing of characters (#116)
* enhancing deaths parsing - detection if killer is a summon - extending testing of a death record * moving trim into containsCreaturesWithOf func
1 parent 4cccd0e commit 4e32e43

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

src/TibiaCharactersCharacterV3.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,50 @@ func TibiaDataParseKiller(data string) (string, bool, bool, string) {
495495
}
496496

497497
// get summon information
498-
rs := summonRegex.FindAllStringSubmatch(data, -1)
499-
if len(rs) >= 1 {
500-
theSummon = rs[0][1]
501-
data = rs[0][2]
498+
if strings.HasPrefix(data, "a ") || strings.HasPrefix(data, "an ") {
499+
if containsCreaturesWithOf(data) {
500+
// this is not a summon, since it is a creature with a of in the middle
501+
} else {
502+
rs := summonRegex.FindAllStringSubmatch(data, -1)
503+
if len(rs) >= 1 {
504+
theSummon = rs[0][1]
505+
data = rs[0][2]
506+
}
507+
}
502508
}
503509

504510
// sanitizing string
505511
data = TibiaDataSanitizeStrings(data)
506512

507513
return data, isPlayer, isTraded, theSummon
508514
}
515+
516+
// containsCreaturesWithOf checks if creature is present in special creatures list
517+
func containsCreaturesWithOf(str string) bool {
518+
519+
// this list should be based on the https://assets.tibiadata.com/data.json creatures name and plural_name field (currently only singular version)
520+
creaturesWithOf := []string{
521+
"acolyte of the cult",
522+
"adept of the cult",
523+
"cloak of terror",
524+
"energuardian of tales",
525+
"enlightened of the cult",
526+
"guardian of tales",
527+
"hand of cursed fate",
528+
"monk of the order",
529+
"novice of the cult",
530+
"priestess of the wild sun",
531+
"sight of surrender",
532+
"son of verminor",
533+
}
534+
535+
// trim away "an " and "a "
536+
str = strings.TrimPrefix(strings.TrimPrefix(str, "an "), "a ")
537+
538+
for _, v := range creaturesWithOf {
539+
if v == str {
540+
return true
541+
}
542+
}
543+
return false
544+
}

src/TibiaCharactersCharacterV3_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,30 @@ func TestNumber4(t *testing.T) {
134134

135135
firstDeath := characterJson.Characters.Deaths[0]
136136
assert.Equal(28, len(firstDeath.Killers))
137+
138+
creatureWithOfDeath := characterJson.Characters.Deaths[16]
139+
assert.Equal(2, len(creatureWithOfDeath.Killers))
140+
assert.Equal(260, creatureWithOfDeath.Level)
141+
assert.Equal("an undead elite gladiator", creatureWithOfDeath.Killers[0].Name)
142+
assert.False(creatureWithOfDeath.Killers[0].Player)
143+
assert.False(creatureWithOfDeath.Killers[0].Traded)
144+
assert.Empty(creatureWithOfDeath.Killers[0].Summon)
145+
assert.Equal("a priestess of the wild sun", creatureWithOfDeath.Killers[1].Name)
146+
147+
tradedInDeath := characterJson.Characters.Deaths[18]
148+
assert.Equal(3, len(tradedInDeath.Assists))
149+
assert.Equal(261, tradedInDeath.Level)
150+
assert.Equal("Vithrann", tradedInDeath.Assists[1].Name)
151+
assert.True(tradedInDeath.Assists[1].Player)
152+
assert.Equal("Adam No Hands", tradedInDeath.Assists[2].Name)
153+
assert.True(tradedInDeath.Assists[2].Traded)
154+
155+
longDeath := characterJson.Characters.Deaths[78]
156+
assert.Equal(5, len(longDeath.Assists))
157+
assert.Equal(231, longDeath.Level)
158+
assert.Equal("Adam No Hands", longDeath.Assists[4].Name)
159+
assert.Equal("a paladin familiar", longDeath.Assists[4].Summon)
160+
assert.True(longDeath.Assists[4].Traded)
137161
}
138162

139163
func TestNumber5(t *testing.T) {

testdata/characters/Riley No Hands.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)