Skip to content

Commit

Permalink
Fixed issue with implicit / tempered affixes for D4Builds and Mobalyt…
Browse files Browse the repository at this point in the history
…ics.
  • Loading branch information
josdemmers committed Jun 12, 2024
1 parent 5e0a761 commit f560c6c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 41 deletions.
1 change: 1 addition & 0 deletions D4Companion.Entities/ItemAffix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ItemAffix
public string Id { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public Color Color { get; set; } = Colors.Green;
public bool IsGreater { get; set; } = false;
public bool IsImplicit { get; set; } = false;
public bool IsTempered { get; set; } = false;
}
Expand Down
28 changes: 18 additions & 10 deletions D4Companion.Entities/MobalyticsBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ public class MobalyticsBuildVariant
public string Name { get; set; } = string.Empty;
public AffixPreset AffixPreset { get; set; } = new();

public List<string> Helm { get; set; } = new();
public List<string> Chest { get; set; } = new();
public List<string> Gloves { get; set; } = new();
public List<string> Pants { get; set; } = new();
public List<string> Boots { get; set; } = new();
public List<string> Amulet { get; set; } = new();
public List<string> Ring { get; set; } = new();
public List<string> Weapon { get; set; } = new();
public List<string> Ranged { get; set; } = new();
public List<string> Offhand { get; set; } = new();
public List<MobalyticsAffix> Helm { get; set; } = new();
public List<MobalyticsAffix> Chest { get; set; } = new();
public List<MobalyticsAffix> Gloves { get; set; } = new();
public List<MobalyticsAffix> Pants { get; set; } = new();
public List<MobalyticsAffix> Boots { get; set; } = new();
public List<MobalyticsAffix> Amulet { get; set; } = new();
public List<MobalyticsAffix> Ring { get; set; } = new();
public List<MobalyticsAffix> Weapon { get; set; } = new();
public List<MobalyticsAffix> Ranged { get; set; } = new();
public List<MobalyticsAffix> Offhand { get; set; } = new();
public List<string> Aspect { get; set; } = new();
}

public class MobalyticsAffix
{
public string AffixText { get; set; } = string.Empty;
public bool IsGreater { get; set; } = false;
public bool IsImplicit { get; set; } = false;
public bool IsTempered { get; set; } = false;
}
}
5 changes: 3 additions & 2 deletions D4Companion.Services/BuildsManagerD4Builds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ private ItemAffix ConvertItemAffix(Tuple<string,string> affixD4Builds)
string itemType = affixD4Builds.Item1;

// Clean string for implicit affixes
string affixClean = affixD4Builds.Item2.Contains(":") ? affixD4Builds.Item2.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1] : affixD4Builds.Item2;
string affixClean = affixD4Builds.Item2.Contains(":") ? affixD4Builds.Item2.Substring(affixD4Builds.Item2.IndexOf(":") + 1) : affixD4Builds.Item2;

// Clean string for tempered
affixClean = Regex.Replace(affixClean, @"\[(.+?)\]", string.Empty);
affixClean = Regex.Replace(affixClean, @"\((.+?)\)", string.Empty);
Expand All @@ -403,7 +404,7 @@ private ItemAffix ConvertItemAffix(Tuple<string,string> affixD4Builds)
var result = Process.ExtractOne(affixClean, _affixDescriptions, scorer: ScorerCache.Get<DefaultRatioScorer>());
affixId = _affixMapDescriptionToId[result.Value];

bool isImplicit = affixD4Builds.Item2.Contains(":");
bool isImplicit = affixD4Builds.Item2.Contains(":") && !affixD4Builds.Item2.Contains(")");
bool isTempered = affixD4Builds.Item2.Contains(")");

return new ItemAffix
Expand Down
64 changes: 37 additions & 27 deletions D4Companion.Services/BuildsManagerMobalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,47 +306,47 @@ private void ConvertBuildVariants(MobalyticsBuild mobalyticsBuild)
};

// Prepare affixes
List<Tuple<string, string>> affixesMobalytics = new List<Tuple<string, string>>();
List<Tuple<string, MobalyticsAffix>> affixesMobalytics = new List<Tuple<string, MobalyticsAffix>>();

foreach (var affixMobalytics in variant.Helm)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Helm, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Helm, affixMobalytics));
}
foreach (var affixMobalytics in variant.Chest)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Chest, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Chest, affixMobalytics));
}
foreach (var affixMobalytics in variant.Gloves)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Gloves, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Gloves, affixMobalytics));
}
foreach (var affixMobalytics in variant.Pants)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Pants, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Pants, affixMobalytics));
}
foreach (var affixMobalytics in variant.Boots)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Boots, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Boots, affixMobalytics));
}
foreach (var affixMobalytics in variant.Amulet)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Amulet, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Amulet, affixMobalytics));
}
foreach (var affixMobalytics in variant.Ring)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Ring, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Ring, affixMobalytics));
}
foreach (var affixMobalytics in variant.Weapon)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Weapon, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Weapon, affixMobalytics));
}
foreach (var affixMobalytics in variant.Ranged)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Ranged, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Ranged, affixMobalytics));
}
foreach (var affixMobalytics in variant.Offhand)
{
affixesMobalytics.Add(new Tuple<string, string>(Constants.ItemTypeConstants.Offhand, affixMobalytics));
affixesMobalytics.Add(new Tuple<string, MobalyticsAffix>(Constants.ItemTypeConstants.Offhand, affixMobalytics));
}

// Find matching affix ids
Expand Down Expand Up @@ -401,27 +401,22 @@ private void ConvertBuildVariants(MobalyticsBuild mobalyticsBuild)
}
}

private ItemAffix ConvertItemAffix(Tuple<string, string> affixMobalytics)
private ItemAffix ConvertItemAffix(Tuple<string, MobalyticsAffix> affixDescription)
{
string affixId = string.Empty;
string itemType = affixMobalytics.Item1;
string itemType = affixDescription.Item1;
MobalyticsAffix mobalyticsAffix = affixDescription.Item2;

// Clean string for tempered affixes
string affixClean = affixMobalytics.Item2.Contains(":") ? affixMobalytics.Item2.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1] : affixMobalytics.Item2;

// Clean string
affixClean = affixClean.Trim();

var result = Process.ExtractOne(affixClean, _affixDescriptions, scorer: ScorerCache.Get<DefaultRatioScorer>());
var result = Process.ExtractOne(mobalyticsAffix.AffixText, _affixDescriptions, scorer: ScorerCache.Get<DefaultRatioScorer>());
affixId = _affixMapDescriptionToId[result.Value];

bool isTempered = affixMobalytics.Item2.Contains(":");

return new ItemAffix
{
Id = affixId,
Type = itemType,
IsTempered = isTempered
IsGreater = mobalyticsAffix.IsGreater,
IsImplicit = mobalyticsAffix.IsImplicit,
IsTempered = mobalyticsAffix.IsTempered
};
}

Expand Down Expand Up @@ -488,7 +483,7 @@ private void ExportBuildVariant(string variantName, MobalyticsBuild mobalyticsBu
// "Gear Stats"
string header = "Aspects & Uniques";
var aspectAndGearStatsHeader = _webDriver.FindElement(By.XPath($"//header[./div[contains(text(), '{header}')]]")).FindElements(By.TagName("div"));

// Aspects
_ = _webDriver?.ExecuteScript("arguments[0].click();", aspectAndGearStatsHeader[0]);
Thread.Sleep(_delayClick);
Expand Down Expand Up @@ -528,11 +523,11 @@ private void ExportBuildVariant(string variantName, MobalyticsBuild mobalyticsBu
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(10 * 1000);
}

private List<string> GetAllAffixes(string itemType)
private List<MobalyticsAffix> GetAllAffixes(string itemType)
{
try
{
List<string> affixes = new List<string>();
List<MobalyticsAffix> affixes = new List<MobalyticsAffix>();

string header = "Gear Stats";
var affixContainer = _webDriver.FindElement(By.XPath($"//div[./header[./div[contains(text(), '{header}')]]]"))
Expand All @@ -559,11 +554,26 @@ private List<string> GetAllAffixes(string itemType)
var elementAffixes = affixContainerType.FindElements(By.TagName("li"));
foreach (var elementAffix in elementAffixes)
{
MobalyticsAffix mobalyticsAffix = new MobalyticsAffix();
var asHtml = elementAffix.GetAttribute("innerHTML");

var elementSpans = elementAffix.FindElements(By.TagName("span"));
string affix = elementSpans.Count == 1 || (elementSpans.Count > 1 && string.IsNullOrWhiteSpace(elementSpans[1].Text)) ? elementSpans[0].Text :
elementSpans[0].Text.Replace(elementSpans[1].Text, string.Empty).Trim();

affixes.Add(affix);
var textColor = elementSpans[0].GetCssValue("color");
mobalyticsAffix.IsGreater = asHtml.Contains("Greater.svg") || textColor.Equals("rgba(252, 124, 0, 1)");
mobalyticsAffix.IsImplicit = asHtml.Contains(">Implicit</span>");
mobalyticsAffix.IsTempered = asHtml.Contains("Tempreing.svg") || asHtml.Contains("Tempering.svg");

if(mobalyticsAffix.IsImplicit || mobalyticsAffix.IsTempered)
{
affix = affix.Contains(":") ? affix.Substring(affix.IndexOf(":") + 1) : affix;
affix = affix.Trim();
}

mobalyticsAffix.AffixText = affix;
affixes.Add(mobalyticsAffix);
}
}
return affixes;
Expand Down
4 changes: 2 additions & 2 deletions D4Companion/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<FileVersion>3.6.1.0</FileVersion>
<Version>3.6.1.0</Version>
<FileVersion>3.6.2.0</FileVersion>
<Version>3.6.2.0</Version>
<Copyright>Copyright © 2024</Copyright>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
Expand Down

0 comments on commit f560c6c

Please sign in to comment.