Skip to content

Commit cc7a897

Browse files
committed
fix spell_id parsing and test
1 parent 05d262d commit cc7a897

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

src/TibiaSpellsOverviewV3.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type Spells struct {
2929
Spells []Spell `json:"spell_list"`
3030
}
3131

32-
//
3332
// The base includes two levels: Spells and Information
3433
type SpellsOverviewResponse struct {
3534
Spells Spells `json:"spells"`
@@ -57,11 +56,12 @@ func TibiaSpellsOverviewV3Impl(vocationName string, BoxContentHTML string) Spell
5756

5857
s.Find("td").Each(func(index int, s2 *goquery.Selection) {
5958
selectionText := s2.Text()
59+
selectionHtml, _ := s2.Html()
6060

6161
switch index {
6262
case 0:
63-
spellBuilder.Name = selectionText
64-
spellBuilder.Spell = selectionText[0:strings.Index(selectionText, " (")]
63+
spellBuilder.Name = selectionText[0:strings.Index(selectionText, " (")]
64+
spellBuilder.Spell = selectionHtml[strings.Index(selectionHtml, "amp;spell=")+10 : strings.Index(selectionHtml, "&vocation")]
6565
spellBuilder.Formula = selectionText[strings.Index(selectionText, " (")+2 : strings.Index(selectionText, ")")]
6666
case 1:
6767
switch selectionText {

src/TibiaSpellsOverviewV3_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func TestOverviewAll(t *testing.T) {
1717
spellsOverviewJson := TibiaSpellsOverviewV3Impl("", string(data))
1818
assert := assert.New(t)
1919

20-
assert.Equal(142, len(spellsOverviewJson.Spells.Spells))
20+
assert.Equal(152, len(spellsOverviewJson.Spells.Spells))
2121

2222
firstSpell := spellsOverviewJson.Spells.Spells[0]
23-
assert.Equal("Animate Dead Rune (adana mort)", firstSpell.Name)
24-
assert.Equal("Animate Dead Rune", firstSpell.Spell)
23+
assert.Equal("Animate Dead Rune", firstSpell.Name)
24+
assert.Equal("animatedeadrune", firstSpell.Spell)
2525
assert.Equal("adana mort", firstSpell.Formula)
2626
assert.Equal(27, firstSpell.Level)
2727
assert.Equal(600, firstSpell.Mana)
@@ -33,9 +33,9 @@ func TestOverviewAll(t *testing.T) {
3333
assert.True(firstSpell.TypeRune)
3434
assert.True(firstSpell.PremiumOnly)
3535

36-
findPersonSpell := spellsOverviewJson.Spells.Spells[53]
37-
assert.Equal("Find Person (exiva \"name\")", findPersonSpell.Name)
38-
assert.Equal("Find Person", findPersonSpell.Spell)
36+
findPersonSpell := spellsOverviewJson.Spells.Spells[60]
37+
assert.Equal("Find Person", findPersonSpell.Name)
38+
assert.Equal("findperson", findPersonSpell.Spell)
3939
assert.Equal("exiva \"name\"", findPersonSpell.Formula)
4040
assert.Equal(8, findPersonSpell.Level)
4141
assert.Equal(20, findPersonSpell.Mana)

src/TibiaSpellsSpellV3.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type SpellsContainer struct {
5757
Spell SpellData `json:"spell"`
5858
}
5959

60-
//
6160
// The base includes two levels: Spell and Information
6261
type SpellInformationResponse struct {
6362
Spells SpellsContainer `json:"spells"`
@@ -85,19 +84,20 @@ func TibiaSpellsSpellV3Impl(spell string, BoxContentHTML string) SpellInformatio
8584
// creating empty vars for later use
8685
SpellsInfoVocation, SpellsInfoCity, RuneInfoVocation []string
8786
// var SpellsInfoName, RuneInfoName string
88-
SpellInformationSection, SpellName, SpellImageURL, SpellDescription, SpellsInfoFormula, SpellsInfoDamageType, RuneInfoDamageType string
87+
SpellInformationSection, SpellName, SpellID, SpellImageURL, SpellDescription, SpellsInfoFormula, SpellsInfoDamageType, RuneInfoDamageType string
8988
SpellsInfoCooldownAlone, SpellsInfoCooldownGroup, SpellsInfoSoulPoints, SpellsInfoAmount, SpellsInfoLevel, SpellsInfoMana, SpellsInfoPrice, RuneInfoLevel, RuneInfoMagicLevel int
9089
SpellsInfoGroupAttack, SpellsInfoGroupHealing, SpellsInfoGroupSupport, SpellsInfoTypeInstant, SpellsInfoTypeRune, RuneInfoGroupAttack, RuneInfoGroupHealing, RuneInfoGroupSupport, SpellsInfoPremium, SpellsHasSpellSection, SpellsHasRuneSection bool
9190
)
9291

9392
ReaderHTML.Find(".BoxContent").Each(func(index int, s *goquery.Selection) {
9493
NameAndImageSection, _ := s.Find("table tr").First().Html()
9594

96-
// Get the name and image
95+
// Get the name, spell_id and image
9796
subma2 := SpellNameAndImageRegex.FindAllStringSubmatch(NameAndImageSection, -1)
9897
if len(subma2) > 0 {
9998
SpellName = subma2[0][2]
10099
SpellImageURL = subma2[0][1]
100+
SpellID = SpellImageURL[strings.Index(SpellImageURL, "library/")+8 : strings.Index(SpellImageURL, ".png")]
101101
}
102102

103103
s.Find(".TableContainer").Each(func(index int, s *goquery.Selection) {
@@ -267,7 +267,7 @@ func TibiaSpellsSpellV3Impl(spell string, BoxContentHTML string) SpellInformatio
267267
SpellsContainer{
268268
SpellData{
269269
Name: SpellName,
270-
Spell: strings.ToLower(SpellName),
270+
Spell: SpellID,
271271
ImageURL: SpellImageURL,
272272
Description: SpellDescription,
273273
HasSpellInformation: SpellsHasSpellSection,

src/TibiaSpellsSpellV3_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestFindPerson(t *testing.T) {
1919

2020
assert.Empty(findPersonJson.Spells.Spell.Description)
2121
assert.Equal("Find Person", findPersonJson.Spells.Spell.Name)
22-
assert.Equal("find person", findPersonJson.Spells.Spell.Spell)
22+
assert.Equal("findperson", findPersonJson.Spells.Spell.Spell)
2323
assert.True(findPersonJson.Spells.Spell.HasSpellInformation)
2424
assert.NotNil(findPersonJson.Spells.Spell.SpellInformation)
2525
assert.Equal("exiva 'name'", findPersonJson.Spells.Spell.SpellInformation.Formula)
@@ -57,7 +57,7 @@ func TestHeavyMagicMissileRune(t *testing.T) {
5757

5858
assert.Empty(hmmJson.Spells.Spell.Description)
5959
assert.Equal("Heavy Magic Missile Rune", hmmJson.Spells.Spell.Name)
60-
assert.Equal("heavy magic missile rune", hmmJson.Spells.Spell.Spell)
60+
assert.Equal("heavymagicmissilerune", hmmJson.Spells.Spell.Spell)
6161
assert.True(hmmJson.Spells.Spell.HasSpellInformation)
6262
assert.NotNil(hmmJson.Spells.Spell.SpellInformation)
6363
assert.Equal("adori vis", hmmJson.Spells.Spell.SpellInformation.Formula)
@@ -139,7 +139,7 @@ func TestBruiseBane(t *testing.T) {
139139

140140
assert.Empty(bruisebaneJson.Spells.Spell.Description)
141141
assert.Equal("Bruise Bane", bruisebaneJson.Spells.Spell.Name)
142-
assert.Equal("bruise bane", bruisebaneJson.Spells.Spell.Spell)
142+
assert.Equal("bruisebane", bruisebaneJson.Spells.Spell.Spell)
143143
assert.True(bruisebaneJson.Spells.Spell.HasSpellInformation)
144144
assert.NotNil(bruisebaneJson.Spells.Spell.SpellInformation)
145145
assert.Equal("exura infir ico", bruisebaneJson.Spells.Spell.SpellInformation.Formula)
@@ -172,7 +172,7 @@ func TestCurePoisonRune(t *testing.T) {
172172

173173
assert.Empty(curepoisonruneJson.Spells.Spell.Description)
174174
assert.Equal("Cure Poison Rune", curepoisonruneJson.Spells.Spell.Name)
175-
assert.Equal("cure poison rune", curepoisonruneJson.Spells.Spell.Spell)
175+
assert.Equal("curepoisonrune", curepoisonruneJson.Spells.Spell.Spell)
176176
assert.True(curepoisonruneJson.Spells.Spell.HasSpellInformation)
177177
assert.NotNil(curepoisonruneJson.Spells.Spell.SpellInformation)
178178
assert.Equal("adana pox", curepoisonruneJson.Spells.Spell.SpellInformation.Formula)
@@ -201,7 +201,7 @@ func TestConvinceCreatureRune(t *testing.T) {
201201

202202
assert.Empty(convincecreatureruneJson.Spells.Spell.Description)
203203
assert.Equal("Convince Creature Rune", convincecreatureruneJson.Spells.Spell.Name)
204-
assert.Equal("convince creature rune", convincecreatureruneJson.Spells.Spell.Spell)
204+
assert.Equal("convincecreaturerune", convincecreatureruneJson.Spells.Spell.Spell)
205205
assert.True(convincecreatureruneJson.Spells.Spell.HasSpellInformation)
206206
assert.NotNil(convincecreatureruneJson.Spells.Spell.SpellInformation)
207207
assert.Equal("adeta sio", convincecreatureruneJson.Spells.Spell.SpellInformation.Formula)

0 commit comments

Comments
 (0)