Skip to content

Commit

Permalink
- Fixed multiple Maxroll missing affix messages.
Browse files Browse the repository at this point in the history
- Added tooltip to explain Maxroll import feature.
  • Loading branch information
josdemmers committed Feb 3, 2024
1 parent 32ea1a8 commit 3ba436b
Show file tree
Hide file tree
Showing 27 changed files with 9,695 additions and 25 deletions.
23 changes: 23 additions & 0 deletions D4Companion.Entities/AffixGlobal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace D4Companion.Entities
{
public class AffixGlobal
{
public List<PtContent> ptContent { get; set; }
}

public class PtContent
{
public List<ArSortedAffixGroups> arSortedAffixGroups { get; set; }
}

public class ArSortedAffixGroups
{
public List<ArSortedAffixes> arSortedAffixes { get; set; }
}

public class ArSortedAffixes
{
public int __raw__ { get; set; }
public string name { get; set; }
}
}
1 change: 1 addition & 0 deletions D4Companion.Interfaces/IAffixManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IAffixManager
string GetSigilDescription(string sigilId);
string GetSigilName(string sigilId);
bool IsAffixSelected(AffixInfo affixInfo, string itemType);
bool IsUniqueAffix(int affixSno);
void RemoveAffix(AffixInfo affixInfo, string itemType);
void RemoveAffix(ItemAffix itemAffix);
void RemoveAspect(ItemAffix itemAffix);
Expand Down
18 changes: 18 additions & 0 deletions D4Companion.Localization/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions D4Companion.Localization/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,10 @@
<data name="rsTooltipUpdate" xml:space="preserve">
<value>Update</value>
</data>
<data name="rsToolTipGitHubWiki" xml:space="preserve">
<value>Wiki on GitHub</value>
</data>
<data name="rsTooltipMaxrollImportHelp" xml:space="preserve">
<value>Enter the build id from the Maxroll website and click the add button. The build id is the last part of the url. For example: t3jx0916</value>
</data>
</root>
39 changes: 39 additions & 0 deletions D4Companion.Services/AffixManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AffixManager : IAffixManager
private readonly ISettingsManager _settingsManager;

private List<AffixInfo> _affixes = new List<AffixInfo>();
private AffixGlobal _affixGlobals = new AffixGlobal();
private List<AffixPreset> _affixPresets = new List<AffixPreset>();
private List<AspectInfo> _aspects = new List<AspectInfo>();
private List<SigilInfo> _sigils = new List<SigilInfo>();
Expand All @@ -38,6 +39,7 @@ public AffixManager(IEventAggregator eventAggregator, ILogger<AffixManager> logg

// Init store data
InitAffixData();
InitAffixDataGlobal();
InitAspectData();
InitSigilData();

Expand Down Expand Up @@ -243,6 +245,29 @@ private void InitAffixData()
}
}

private void InitAffixDataGlobal()
{
string language = _settingsManager.Settings.SelectedAffixLanguage;

string resourcePath = @$".\Data\affixes.glo.json";
using (FileStream? stream = File.OpenRead(resourcePath))
{
if (stream != null)
{
// create the options
var options = new JsonSerializerOptions()
{
WriteIndented = true
};
// register the converter
options.Converters.Add(new BoolConverter());
options.Converters.Add(new IntConverter());

_affixGlobals = JsonSerializer.Deserialize<AffixGlobal>(stream, options) ?? new AffixGlobal();
}
}
}

private void InitAspectData()
{
string language = _settingsManager.Settings.SelectedAffixLanguage;
Expand Down Expand Up @@ -302,6 +327,20 @@ public bool IsAffixSelected(AffixInfo affixInfo, string itemType)
return true;
}

public bool IsUniqueAffix(int affixSno)
{
string name = string.Empty;
foreach (var arSortedAffixGroup in _affixGlobals.ptContent[0].arSortedAffixGroups)
{
name = arSortedAffixGroup.arSortedAffixes.FirstOrDefault(a => a.__raw__ == affixSno)?.name ?? string.Empty;
if (!string.IsNullOrEmpty(name)) break;
}

return string.IsNullOrWhiteSpace(name) ||
name.Contains("_Unique_", StringComparison.OrdinalIgnoreCase) ||
name.EndsWith("_Unique", StringComparison.OrdinalIgnoreCase);
}

public string GetAffixDescription(string affixId)
{
var affixInfo = _affixes.FirstOrDefault(a => a.IdName.Equals(affixId));
Expand Down
102 changes: 98 additions & 4 deletions D4Companion.Services/BuildsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class BuildsManager : IBuildsManager
private readonly ISettingsManager _settingsManager;

private List<MaxrollBuild> _maxrollBuilds = new();
private Dictionary<int, int> _maxrollMappings = new();
private Dictionary<int, int> _maxrollMappingsAspects = new();

// Start of Constructors region

Expand All @@ -36,6 +38,10 @@ public BuildsManager(IEventAggregator eventAggregator, ILogger<BuildsManager> lo
_httpClientHandler = httpClientHandler;
_settingsManager = settingsManager;

// Init sno mappings
InitMaxrollMappings();
InitMaxrollMappingsAspects();

// Load available Maxroll builds.
Task.Factory.StartNew(() =>
{
Expand Down Expand Up @@ -69,6 +75,63 @@ public BuildsManager(IEventAggregator eventAggregator, ILogger<BuildsManager> lo

#region Methods

private void InitMaxrollMappings()
{

//_maxrollMappings.Add(1669403, 000); // PassiveRankBonus_Rogue_Discipline_T3_N4_Scaled2H --> xxx (Ranks of the Concussive Passive)

//PassiveRankBonus_Rogue_Discipline_T3_N2_Impetus

_maxrollMappings.Clear();
_maxrollMappings.Add(1193773, 577217); // LuckJewelry --> Luck
_maxrollMappings.Add(1193845, 577051); // CritChanceJewelry --> CritChance
_maxrollMappings.Add(1227911, 577173); // Life_Flat_Quadruple_UBERUNIQUE --> Life
_maxrollMappings.Add(1227940, 583482); // CoreStats_All_Double_UBERUNIQUE --> CoreStats_All
_maxrollMappings.Add(1235087, 577093); // Damage_Double_UBERUNIQUE --> Damage
_maxrollMappings.Add(1316341, 577035); // Resource_Cost_Reduction_Barbarian_Lesser --> Resource_Cost_Reduction_Barbarian
_maxrollMappings.Add(1316343, 577037); // Resource_Cost_Reduction_Druid_Lesser --> Resource_Cost_Reduction_Druid
_maxrollMappings.Add(1316345, 577033); // Resource_Cost_Reduction_Necromancer_Lesser --> Resource_Cost_Reduction_Necromancer
_maxrollMappings.Add(1316347, 577034); // Resource_Cost_Reduction_Rogue_Lesser --> Resource_Cost_Reduction_Rogue
_maxrollMappings.Add(1316349, 577036); // Resource_Cost_Reduction_Sorcerer_Lesser --> Resource_Cost_Reduction_Sorcerer
_maxrollMappings.Add(1316491, 1290914); // Luck_With_Barrier_Jewelry --> Luck_With_Barrier
_maxrollMappings.Add(1320722, 577093); // Damage_FullScaling --> Damage
_maxrollMappings.Add(1320724, 577173); // LifePercent_Double_UBERUNIQUE --> Life
_maxrollMappings.Add(1321863, 583482); // CoreStats_All_Weapon --> CoreStats_All
_maxrollMappings.Add(1321865, 583654); // CoreStat_Willpower_Weapon --> CoreStat_Willpower
_maxrollMappings.Add(1321867, 583632); // CoreStat_Strength_Weapon --> CoreStat_Strength
_maxrollMappings.Add(1321869, 583646); // CoreStat_Intelligence_Weapon --> CoreStat_Intelligence
_maxrollMappings.Add(1321871, 583643); // CoreStat_Dexterity_Weapon --> CoreStat_Dexterity
_maxrollMappings.Add(1322044, 577053); // OverpowerDamage_Jewelry --> OverpowerDamage
_maxrollMappings.Add(1322163, 1091321); // PassiveRankBonus_Sorc_Elemental_T2_N2_Always1 --> PassiveRankBonus_Sorc_Elemental_T2_N1_GlassCannon
_maxrollMappings.Add(1322165, 1091984); // PassiveRankBonus_Rogue_Discipline_T3_N3_Scaled2H --> PassiveRankBonus_Rogue_Discipline_T3_N2_Impetus
_maxrollMappings.Add(1322167, 1091982); // PassiveRankBonus_Rogue_Cunning_T3_N2_Scaled2H --> PassiveRankBonus_Rogue_Cunning_T3_N1_Exploit
_maxrollMappings.Add(1341729, 577173); // Life_Greater --> Life
_maxrollMappings.Add(1439263, 1290758); // Damage_Type_Bonus_NonPhysical_Greater --> Damage_Type_Bonus_NonPhysical
_maxrollMappings.Add(1439265, 577213); // Movement_Speed_Lesser --> Movement_Speed
_maxrollMappings.Add(1480001, 1084591); // Resource_MaxEssence_Jewelry --> Resource_MaxEssence
_maxrollMappings.Add(1480004, 577017); // Resource_MaxFury_Jewelry --> Resource_MaxFury
_maxrollMappings.Add(1639491, 1085169); // Damage_Category_Spenders_UBERUNIQUE --> Damage_Category_Spenders
_maxrollMappings.Add(1639493, 577093); // Damage_FullScaling_UBERUNIQUE --> Damage
_maxrollMappings.Add(1639495, 577203); // Lucky_Hit_Heal_Life_UBERUNIQUE --> Lucky_Hit_Heal_Life
_maxrollMappings.Add(1639541, 1341724); // ResourceGain_UBERUNIQUE --> ResourceGain
_maxrollMappings.Add(1639572, 577021); // CD_Reduction_UBERUNIQUE --> CD_Reduction
_maxrollMappings.Add(1639574, 583482); // CoreStats_All_Weapon_UBERUNIQUE --> CoreStats_All
_maxrollMappings.Add(1639807, 577217); // LuckJewelry_UBERUNIQUE --> Luck
_maxrollMappings.Add(1639811, 577051); // CritChanceJewelry_UBERUNIQUE --> CritChance
_maxrollMappings.Add(1639815, 577177); // CritDamage_UBERUNIQUE --> CritDamage
_maxrollMappings.Add(1664583, 1087398); // Damage_Category_Ultimate_LessThanTriple_UNIQUE --> Damage_Category_Ultimate
_maxrollMappings.Add(1669468, 577093); // Damage_Greater_UNIQUE --> Damage
_maxrollMappings.Add(1669540, 1088076); // SkillRankBonus_Generic_Category_Core_Always1_UNIQUE --> SkillRankBonus_Generic_Category_Core
_maxrollMappings.Add(1730620, 577017); // Resource_MaxFury_Greater_Jewelry_Unique --> Resource_MaxFury
_maxrollMappings.Add(1730631, 1341724); // ResourceGain_Greater_UNIQUE --> ResourceGain
}

private void InitMaxrollMappingsAspects()
{
_maxrollMappingsAspects.Clear();
_maxrollMappingsAspects.Add(96035007, 1743946); // legendary_sorc_138 (of Shredding Blades).
}

public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profile)
{
// Note: Only allow one Maxroll build. Update if already exists.
Expand Down Expand Up @@ -134,13 +197,33 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
continue;
}

// Skip unique items
if (maxrollBuild.Data.Items[item.Value].Id.Contains("Unique", StringComparison.OrdinalIgnoreCase)) continue;

// Add all explicit affixes for current item.Value
foreach(var explicitAffix in maxrollBuild.Data.Items[item.Value].Explicits)
foreach (var explicitAffix in maxrollBuild.Data.Items[item.Value].Explicits)
{
int affixSno = explicitAffix.Nid;
string affixId = _affixManager.GetAffixId(affixSno);

if(string.IsNullOrWhiteSpace(affixId))
if (string.IsNullOrWhiteSpace(affixId))
{
// Check if there is a known mapping available
if (_maxrollMappings.TryGetValue(affixSno, out int affixSnoMapped))
{
affixSno = affixSnoMapped;
affixId = _affixManager.GetAffixId(affixSno);
}
}

bool isUniqueAffix = false;
if (string.IsNullOrWhiteSpace(affixId))
{
// Ignore unique item affix
isUniqueAffix = _affixManager.IsUniqueAffix(affixSno);
}

if (string.IsNullOrWhiteSpace(affixId) && !isUniqueAffix)
{
_logger.LogWarning($"{MethodBase.GetCurrentMethod()?.Name}: Unknown affix sno: {affixSno}");
_eventAggregator.GetEvent<WarningOccurredEvent>().Publish(new WarningOccurredEventParams
Expand All @@ -150,7 +233,7 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
}
else
{
if (!affixPreset.ItemAffixes.Any(a => a.Id.Equals(affixId) && a.Type.Equals(itemType)))
if (!affixPreset.ItemAffixes.Any(a => a.Id.Equals(affixId) && a.Type.Equals(itemType)) && !isUniqueAffix)
{
affixPreset.ItemAffixes.Add(new ItemAffix
{
Expand All @@ -170,10 +253,21 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
}

// Add all aspects to preset
foreach (var aspectSno in aspects)
foreach (var aspectSnoFA in aspects)
{
int aspectSno = aspectSnoFA;
string aspectId = _affixManager.GetAspectId(aspectSno);

if (string.IsNullOrWhiteSpace(aspectId))
{
// Check if there is a known mapping available
if (_maxrollMappingsAspects.TryGetValue(aspectSno, out int aspectSnoMapped))
{
aspectSno = aspectSnoMapped;
aspectId = _affixManager.GetAspectId(aspectSno);
}
}

if (string.IsNullOrWhiteSpace(aspectId))
{
_logger.LogWarning($"{MethodBase.GetCurrentMethod()?.Name}: Unknown aspect sno: {aspectSno}");
Expand Down
3 changes: 3 additions & 0 deletions D4Companion/D4Companion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<None Update="Data\Affixes.frFR.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\affixes.glo.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Affixes.itIT.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
22 changes: 22 additions & 0 deletions D4Companion/Data/Affixes.deDE.json
Original file line number Diff line number Diff line change
Expand Up @@ -5073,6 +5073,28 @@
}
]
},
{
"IdSno": 1669605,
"IdName": "Resource_Max_AllClasses_UNIQUE",
"Description": "+# max. Ressource",
"MagicType": 0,
"AllowedForPlayerClass": [
1,
1,
1,
1,
1
],
"AllowedItemLabels": [],
"AffixAttributes": [
{
"LocalisationId": "Resource_All_Primary_Max_Bonus",
"LocalisationParameter": 4294967295,
"LocalisationAttributeFormulaValue": "0",
"Localisation": "+[{vALUE2}] max. Ressource"
}
]
},
{
"IdSno": 577017,
"IdName": "Resource_MaxFury",
Expand Down
22 changes: 22 additions & 0 deletions D4Companion/Data/Affixes.enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,28 @@
}
]
},
{
"IdSno": 1669605,
"IdName": "Resource_Max_AllClasses_UNIQUE",
"Description": "+# Maximum Resource",
"MagicType": 0,
"AllowedForPlayerClass": [
1,
1,
1,
1,
1
],
"AllowedItemLabels": [],
"AffixAttributes": [
{
"LocalisationId": "Resource_All_Primary_Max_Bonus",
"LocalisationParameter": 4294967295,
"LocalisationAttributeFormulaValue": "0",
"Localisation": "+[{vALUE2}] Maximum Resource"
}
]
},
{
"IdSno": 1084592,
"IdName": "Resource_MaxSpirit",
Expand Down
22 changes: 22 additions & 0 deletions D4Companion/Data/Affixes.esES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,28 @@
}
]
},
{
"IdSno": 1669605,
"IdName": "Resource_Max_AllClasses_UNIQUE",
"Description": "+# de recurso máximo",
"MagicType": 0,
"AllowedForPlayerClass": [
1,
1,
1,
1,
1
],
"AllowedItemLabels": [],
"AffixAttributes": [
{
"LocalisationId": "Resource_All_Primary_Max_Bonus",
"LocalisationParameter": 4294967295,
"LocalisationAttributeFormulaValue": "0",
"Localisation": "+[{vALUE2}] de recurso máximo"
}
]
},
{
"IdSno": 577201,
"IdName": "LifeRegen",
Expand Down
Loading

0 comments on commit 3ba436b

Please sign in to comment.