diff --git a/WaystoneHighlight.cs b/WaystoneHighlight.cs index b4d17a1..e393c53 100644 --- a/WaystoneHighlight.cs +++ b/WaystoneHighlight.cs @@ -12,17 +12,24 @@ using System.Diagnostics.Eventing.Reader; using RectangleF = ExileCore2.Shared.RectangleF; using ExileCore2.Shared.Nodes; - +using ExileCore2.Shared.Enums; +using static ItemFilterLibrary.ItemData; namespace WaystoneHighlight; public class WaystoneHighlight : BaseSettingsPlugin { - private IngameState InGameState => GameController.IngameState; + private IngameState InGameState => GameController?.IngameState; private List BannedModifiers; private void ParseBannedModifiers() { + if (Settings == null || Settings.Score == null) return; + if (Settings.Score.BannedModifiers?.Value == null) + { + BannedModifiers = new List(); + return; + } BannedModifiers = Settings.Score.BannedModifiers.Value .Split(',') .Select(x => x.Trim().ToLower()) @@ -32,66 +39,146 @@ private void ParseBannedModifiers() public override bool Initialise() { - //BannedModifiers = ParseBannedModifiers(); - Settings.Score.ReloadBannedModifiers.OnPressed = ParseBannedModifiers; + if (Settings?.Score?.ReloadBannedModifiers == null) + return false; + Settings.Score.ReloadBannedModifiers.OnPressed = ParseBannedModifiers; ParseBannedModifiers(); return base.Initialise(); } + public override void Render() { - IList waystones = []; + if (InGameState?.IngameUi == null) return; + IList waystones = new List(); var stashPanel = InGameState.IngameUi.StashElement; var stashPanelGuild = InGameState.IngameUi.GuildStashElement; var inventoryPanel = InGameState.IngameUi.InventoryPanel; + if (inventoryPanel == null) return; bool isQuadTab = false; - - // Run if inventory panel is opened if (inventoryPanel.IsVisible) { - // Add stash items - if (stashPanel.IsVisible && stashPanel.VisibleStash != null) + if (stashPanel != null && stashPanel.IsVisible && stashPanel.VisibleStash != null) { if (stashPanel.VisibleStash.TotalBoxesInInventoryRow == 24) { isQuadTab = true; } - foreach (var item in stashPanel.VisibleStash.VisibleInventoryItems) + var stashItems = stashPanel.VisibleStash.VisibleInventoryItems; + if (stashItems != null) { - waystones.Add(new WaystoneItem(item.Item.GetComponent(), item.Item.GetComponent(), item.Item.GetComponent(), item.GetClientRectCache, ItemLocation.Stash)); + foreach (var item in stashItems) + { + if (item?.Item == null) continue; + var modsComponent = item.Item.GetComponent(); + if (modsComponent != null) + { + var modsData = new ModsData( + modsComponent.ItemMods, + modsComponent.EnchantedMods, + modsComponent.ExplicitMods, + modsComponent.CorruptionImplicitMods, + modsComponent.ImplicitMods, + modsComponent.SynthesisMods + ); + waystones.Add(new WaystoneItem( + item.Item.GetComponent(), + item.Item.GetComponent(), + modsComponent, + item.GetClientRectCache, + ItemLocation.Stash, + modsData + )); + } + } } } - else if (stashPanelGuild.IsVisible && stashPanelGuild != null) + else if (stashPanelGuild != null && stashPanelGuild.IsVisible && stashPanelGuild.VisibleStash != null) { if (stashPanelGuild.VisibleStash.TotalBoxesInInventoryRow == 24) { isQuadTab = true; } - foreach (var item in stashPanelGuild.VisibleStash.VisibleInventoryItems) + var guildStashItems = stashPanelGuild.VisibleStash.VisibleInventoryItems; + if (guildStashItems != null) { - waystones.Add(new WaystoneItem(item.Item.GetComponent(), item.Item.GetComponent(), item.Item.GetComponent(), item.GetClientRectCache, ItemLocation.Stash)); + foreach (var item in guildStashItems) + { + if (item?.Item == null) continue; + var modsComponent = item.Item.GetComponent(); + if (modsComponent != null) + { + var modsData = new ModsData( + modsComponent.ItemMods, + null, + null, + null, + null, + null + ); + waystones.Add(new WaystoneItem( + item.Item.GetComponent(), + item.Item.GetComponent(), + modsComponent, + item.GetClientRectCache, + ItemLocation.Stash, + modsData + )); + } + } } - } - // Add inventory items - var inventoryItems = GameController.IngameState.ServerData.PlayerInventories[0].Inventory.InventorySlotItems; - foreach (var item in inventoryItems) + } + + var playerInventories = InGameState.ServerData?.PlayerInventories; + if (playerInventories != null && playerInventories.Count > 0) { - waystones.Add(new(item.Item.GetComponent(), item.Item.GetComponent(), item.Item.GetComponent(), item.GetClientRect(), ItemLocation.Inventory)); + var inventory = playerInventories[0]?.Inventory; + if (inventory?.InventorySlotItems != null) + { + foreach (var item in inventory.InventorySlotItems) + { + if (item?.Item == null) continue; + var modsComponent = item.Item.GetComponent(); + if (modsComponent != null) + { + var modsData = new ModsData( + modsComponent.ItemMods, + modsComponent.EnchantedMods, + modsComponent.ExplicitMods, + modsComponent.CorruptionImplicitMods, + modsComponent.ImplicitMods, + modsComponent.SynthesisMods + ); + waystones.Add(new WaystoneItem( + item.Item.GetComponent(), + item.Item.GetComponent(), + modsComponent, + item.GetClientRect(), + ItemLocation.Inventory, + modsData + )); + } + } + } } foreach (var waystone in waystones) { - - var item = waystone.map; - - if (item == null) + if (waystone.baseComponent == null || + waystone.mods == null || + waystone.modsData == null) + { continue; + } - // Check for map tier - if (item.Tier < Settings.Score.MinimumTier) + var itemMap = waystone.map; + if (itemMap == null) continue; + if (Settings?.Score == null) continue; + + if (itemMap.Tier < Settings.Score.MinimumTier) { continue; } @@ -99,11 +186,10 @@ public override void Render() var itemMods = waystone.mods; var bbox = waystone.rect; - int prefixCount = 0; - int suffixCount = 0; + int prefixCount = waystone.modsData.Prefixes?.Count() ?? 0; + int suffixCount = waystone.modsData.Suffixes?.Count() ?? 0; int score = 0; - int iiq = 0; int iir = 0; bool extraRareMod = false; @@ -114,85 +200,73 @@ public override void Render() int extraRarePack = 0; int additionalPacks = 0; - var drawColor = Color.White; bool hasBannedMod = false; bool isCorrupted = waystone.baseComponent.isCorrupted; + bool isRare = itemMods.ItemRarity == ItemRarity.Rare; - // Iterate through the mods - foreach (var mod in itemMods.ItemMods) + if (itemMods.ItemMods != null) { - // Check for banned modifiers - if (BannedModifiers.Count > 0) + foreach (var mod in itemMods.ItemMods) { - foreach (var bannedMod in BannedModifiers) + if (mod == null) continue; + if (BannedModifiers != null && BannedModifiers.Count > 0 && mod.DisplayName != null) { - - if (mod.DisplayName.Contains(bannedMod, StringComparison.OrdinalIgnoreCase)) + foreach (var bannedMod in BannedModifiers) { - hasBannedMod = true; - break; + if (mod.DisplayName.Contains(bannedMod, StringComparison.OrdinalIgnoreCase)) + { + hasBannedMod = true; + break; + } } } - } - // Count prefixes and suffixes - if (mod.DisplayName.StartsWith("of", StringComparison.OrdinalIgnoreCase)) - { - suffixCount++; - } - else - { - if (mod.Group != "AfflictionMapDeliriumStacks") + if (mod.Values == null || mod.Values.Count == 0) continue; + + switch (mod.Name) { - prefixCount++; + case "MapDroppedItemRarityIncrease": + iir += mod.Values[0]; + break; + case "MapDroppedItemQuantityIncrease": + iiq += mod.Values[0]; + if (mod.Values.Count > 1) + { + iir += mod.Values[1]; + } + break; + case "MapRareMonstersAdditionalModifier": + extraRareMod = true; + break; + case "MapPackSizeIncrease": + packSize += mod.Values[0]; + break; + case "MapMagicPackSizeIncrease": + magicPackSize += mod.Values[0]; + break; + case "MapTotalEffectivenessIncrease": + extraPacks += mod.Values[0]; + break; + case "MapMagicPackIncrease": + extraMagicPack += mod.Values[0]; + break; + case "MapMagicRarePackIncrease": + extraRarePack += mod.Values[0]; + if (mod.Values.Count > 1) + { + extraMagicPack += mod.Values[1]; + } + break; + case "MapRarePackIncrease": + extraRarePack += mod.Values[0]; + break; + case string s when s.StartsWith("MapMonsterAdditionalPacks"): + additionalPacks += mod.Values[0]; + break; } } - - // Find good mods - switch (mod.Name) - { - case "MapDroppedItemRarityIncrease": - iir += mod.Values[0]; - break; - case "MapDroppedItemQuantityIncrease": - iiq += mod.Values[0]; - if (mod.Values.Count != 1) - { - iir += mod.Values[1]; - } - break; - case "MapRareMonstersAdditionalModifier": - extraRareMod = true; - break; - case "MapPackSizeIncrease": - packSize += mod.Values[0]; - break; - case "MapMagicPackSizeIncrease": - magicPackSize += mod.Values[0]; - break; - case "MapTotalEffectivenessIncrease": - extraPacks += mod.Values[0]; - break; - case "MapMagicPackIncrease": - extraMagicPack += mod.Values[0]; - break; - case "MapMagicRarePackIncrease": - extraRarePack += mod.Values[0]; - if (mod.Values.Count != 1) - { - extraMagicPack += mod.Values[1]; - } - break; - case "MapRarePackIncrease": - extraRarePack += mod.Values[0]; - break; - case string s when s.StartsWith("MapMonsterAdditionalPacks"): - additionalPacks += mod.Values[0]; - break; - } } - // Sum the score score += iiq * Settings.Score.ScorePerQuantity; score += iir * Settings.Score.ScorePerRarity; score += packSize * Settings.Score.ScorePerPackSize; @@ -206,10 +280,6 @@ public override void Render() score += Settings.Score.ScoreForExtraRareMonsterModifier; } - - // Drawing - - // Frame if (hasBannedMod) { switch (Settings.Graphics.BannedHightlightStyle) @@ -224,36 +294,33 @@ public override void Render() } else { - if (score >= Settings.Score.MinimumCraftHighlightScore) + if (score >= Settings.Score.MinimumCraftHighlightScore && !isCorrupted && prefixCount < 3) { - if (prefixCount < 3 && !isCorrupted) + switch (Settings.Graphics.CraftHightlightStyle) { - switch (Settings.Graphics.CraftHightlightStyle) - { - case 1: - DrawBorderHighlight(bbox, Settings.Graphics.CraftHighlightColor, Settings.Graphics.BorderHighlight.CraftBorderThickness.Value); - break; - case 2: - DrawBoxHighlight(bbox, Settings.Graphics.CraftHighlightColor, Settings.Graphics.BoxHighlight.CraftBoxRounding.Value); - break; - } - + case 1: + DrawBorderHighlight(bbox, Settings.Graphics.CraftHighlightColor, Settings.Graphics.BorderHighlight.CraftBorderThickness.Value); + break; + case 2: + DrawBoxHighlight(bbox, Settings.Graphics.CraftHighlightColor, Settings.Graphics.BoxHighlight.CraftBoxRounding.Value); + break; } - else if (score >= Settings.Score.MinimumRunHighlightScore) + } + else if (score >= Settings.Score.MinimumRunHighlightScore) + { + switch (Settings.Graphics.RunHightlightStyle) { - switch (Settings.Graphics.RunHightlightStyle) - { - case 1: - DrawBorderHighlight(bbox, Settings.Graphics.RunHighlightColor, Settings.Graphics.BorderHighlight.RunBorderThickness.Value); - break; - case 2: - DrawBoxHighlight(bbox, Settings.Graphics.RunHighlightColor, Settings.Graphics.BoxHighlight.RunBoxRounding.Value); - break; - } + case 1: + DrawBorderHighlight(bbox, Settings.Graphics.RunHighlightColor, Settings.Graphics.BorderHighlight.RunBorderThickness.Value); + break; + case 2: + DrawBoxHighlight(bbox, Settings.Graphics.RunHighlightColor, Settings.Graphics.BoxHighlight.RunBoxRounding.Value); + break; } } } + // 在此处显示 prefixCount / suffixCount 到界面上 if (waystone.location == ItemLocation.Inventory || (waystone.location == ItemLocation.Stash && !isQuadTab)) { @@ -284,13 +351,13 @@ public override void Render() Graphics.DrawText(score.ToString(), new Vector2(bbox.Left + 5, bbox.Bottom - 5 - (15 * Settings.Graphics.FontSize.ScoreFontSizeMultiplier)), ExileCore2.Shared.Enums.FontAlign.Left); } } - } } } private void DrawBorderHighlight(RectangleF rect, ColorNode color, int thickness) { + if (color == null) return; int scale = thickness - 1; int innerX = (int)rect.X + 1 + (int)(0.5 * scale); int innerY = (int)rect.Y + 1 + (int)(0.5 * scale); @@ -302,6 +369,7 @@ private void DrawBorderHighlight(RectangleF rect, ColorNode color, int thickness private void DrawBoxHighlight(RectangleF rect, ColorNode color, int rounding) { + if (color == null) return; int innerX = (int)rect.X + 1 + (int)(0.5 * rounding); int innerY = (int)rect.Y + 1 + (int)(0.5 * rounding); int innerWidth = (int)rect.Width - 1 - rounding; @@ -309,4 +377,4 @@ private void DrawBoxHighlight(RectangleF rect, ColorNode color, int rounding) RectangleF scaledBox = new RectangleF(innerX, innerY, innerWidth, innerHeight); Graphics.DrawBox(scaledBox, color, rounding); } -} +} \ No newline at end of file diff --git a/WaystoneHighlight.csproj b/WaystoneHighlight.csproj index 793b3f8..da955ab 100644 --- a/WaystoneHighlight.csproj +++ b/WaystoneHighlight.csproj @@ -21,6 +21,10 @@ $(exapiPackage)\GameOffsets2.dll False + + $(exapiPackage)\ItemFilterLibrary.dll + False + diff --git a/WaystoneHighlightSettings.cs b/WaystoneHighlightSettings.cs index d489cd7..479a773 100644 --- a/WaystoneHighlightSettings.cs +++ b/WaystoneHighlightSettings.cs @@ -5,6 +5,7 @@ using ExileCore2.Shared.Interfaces; using ExileCore2.Shared.Nodes; using Newtonsoft.Json; +using System.Diagnostics; namespace WaystoneHighlight; diff --git a/WaystoneItem.cs b/WaystoneItem.cs index 19ee5d4..a672a10 100644 --- a/WaystoneItem.cs +++ b/WaystoneItem.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using ExileCore2.PoEMemory.Components; using ExileCore2.Shared; +using ItemFilterLibrary; // 添加引用 namespace WaystoneHighlight { @@ -13,12 +14,23 @@ internal enum ItemLocation Inventory = 0, Stash = 1 } - internal struct WaystoneItem(Base baseComponent, Map mapComponent, Mods modsComponent, RectangleF rectangleF, ItemLocation location) + internal struct WaystoneItem { - public Base baseComponent = baseComponent; - public Map map = mapComponent; - public Mods mods = modsComponent; - public RectangleF rect = rectangleF; - public ItemLocation location = location; + public Base baseComponent; + public Map map; + public Mods mods; + public RectangleF rect; + public ItemLocation location; + public ItemData.ModsData modsData; // 添加 ModsData 属性 + + public WaystoneItem(Base baseComponent, Map mapComponent, Mods modsComponent, RectangleF rectangleF, ItemLocation location, ItemData.ModsData modsData) + { + this.baseComponent = baseComponent; + this.map = mapComponent; + this.mods = modsComponent; + this.rect = rectangleF; + this.location = location; + this.modsData = modsData; // 初始化 ModsData 属性 + } } -} +} \ No newline at end of file