Skip to content

Commit 3f97ea3

Browse files
authored
Merge pull request #1026 from Sidekick-Poe/feature/map-tiers
Restored map tier parsing for PoE1
2 parents 2163a2d + 9c5d6b2 commit 3f97ea3

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

src/Sidekick.Apis.Poe.Trade/Parser/Properties/Definitions/MapTierProperty.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ public class MapTierProperty(
1414
GameType game,
1515
ICurrentGameLanguage currentGameLanguage) : PropertyDefinition
1616
{
17-
private Regex Pattern { get; } = currentGameLanguage.Language.DescriptionMapTier.ToRegexIntCapture();
17+
private Regex Pattern { get; } = new(@"^[^\(]+\([^\d]+(\d+)\)$");
1818

1919
public override string Label => currentGameLanguage.Language.DescriptionMapTier;
2020

2121
public override void Parse(Item item)
2222
{
23-
if (item.Properties.ItemClass != ItemClass.Map) return;
23+
if (item.Properties.ItemClass != ItemClass.Map || string.IsNullOrEmpty(item.Type)) return;
2424

25-
var propertyBlock = item.Text.Blocks[1];
26-
item.Properties.MapTier = GetInt(Pattern, propertyBlock);
27-
if (item.Properties.MapTier > 0) propertyBlock.Parsed = true;
25+
item.Properties.MapTier = GetInt(Pattern, item.Type);
2826
}
2927

3028
public override Task<TradeFilter?> GetFilter(Item item)

src/Sidekick.Apis.Poe.Trade/Parser/Properties/PropertyDefinition.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ protected static int GetInt(Regex pattern, TextBlock textBlock)
4646
return int.TryParse(match.Groups[1].Value, out var result) ? result : 0;
4747
}
4848

49+
protected static int GetInt(Regex pattern, string value)
50+
{
51+
var match = pattern.Match(value);
52+
if (!match.Success) return 0;
53+
54+
return int.TryParse(match.Groups[1].Value, out var result) ? result : 0;
55+
}
56+
4957
protected static double GetDouble(Regex pattern, TextBlock textBlock)
5058
{
5159
if (!textBlock.TryParseRegex(pattern, out var match))
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using Sidekick.Apis.Poe.Items;
2+
using Sidekick.Apis.Poe.Trade.Parser;
3+
using Sidekick.Data.Items;
4+
using Xunit;
5+
namespace Sidekick.Apis.Poe.Tests.Poe1English.Parser;
6+
7+
[Collection(Collections.Poe1EnglishFixture)]
8+
public class MapParsing(Poe1EnglishFixture fixture)
9+
{
10+
private readonly IItemParser parser = fixture.Parser;
11+
12+
[Fact]
13+
public void Tier2()
14+
{
15+
var actual = parser.ParseItem(@"Item Class: Maps
16+
Rarity: Magic
17+
Armoured Map (Tier 2)
18+
--------
19+
Item Quantity: +13% (augmented)
20+
Item Rarity: +8% (augmented)
21+
Monster Pack Size: +5% (augmented)
22+
--------
23+
Item Level: 71
24+
--------
25+
Monster Level: 69
26+
--------
27+
+20% Monster Physical Damage Reduction
28+
--------
29+
Travel to a Map by using this in a personal Map Device. Maps can only be used once.
30+
31+
");
32+
33+
Assert.Equal(ItemClass.Map, actual.Properties.ItemClass);
34+
Assert.Equal(Rarity.Magic, actual.Properties.Rarity);
35+
Assert.Null(actual.ApiInformation.Name);
36+
Assert.Equal("Map", actual.ApiInformation.Type);
37+
Assert.Equal(2, actual.Properties.MapTier);
38+
39+
fixture.AssertHasStat(actual, StatCategory.Explicit, "+#% Monster Physical Damage Reduction", 20);
40+
}
41+
42+
[Fact]
43+
public void OlmecSanctum()
44+
{
45+
var actual = parser.ParseItem(@"Item Class: Maps
46+
Rarity: Unique
47+
Olmec's Sanctum
48+
Map (Tier 6)
49+
--------
50+
Item Quantity: +179% (augmented)
51+
--------
52+
Item Level: 73
53+
--------
54+
Monster Level: 73
55+
--------
56+
42% more Monster Life
57+
37% increased Monster Damage
58+
Final Boss drops higher Level Items
59+
--------
60+
They flew, and leapt, and clambered over,
61+
They crawled, and swam, and slithered under.
62+
Still its ancient secrets await unclaimed
63+
And of this hidden temple, only legends remain.
64+
--------
65+
Travel to a Map by using this in a personal Map Device. Maps can only be used once.
66+
");
67+
68+
Assert.Equal(ItemClass.Map, actual.Properties.ItemClass);
69+
Assert.Equal(Rarity.Unique, actual.Properties.Rarity);
70+
Assert.Equal("Olmec's Sanctum", actual.ApiInformation.Name);
71+
Assert.Equal("Map", actual.ApiInformation.Type);
72+
Assert.Equal(6, actual.Properties.MapTier);
73+
74+
fixture.AssertHasStat(actual, StatCategory.Explicit, "#% more Monster Life", 42);
75+
fixture.AssertHasStat(actual, StatCategory.Explicit, "#% increased Monster Damage", 37);
76+
fixture.AssertHasStat(actual, StatCategory.Explicit, "Final Boss drops higher Level Items");
77+
}
78+
}

0 commit comments

Comments
 (0)