Skip to content

Commit

Permalink
Added Expedition Gamble base values if Unique
Browse files Browse the repository at this point in the history
In the Gamble screen, each item will have data from poe.ninja pulled and uses the highest value unique of that base item and shows the result, some filtering may need to be applied.
  • Loading branch information
DetectiveSquirrel committed Nov 3, 2021
1 parent 3a51c95 commit a25f828
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 2 deletions.
Binary file removed .vs/PoeHUD/v15/.suo
Binary file not shown.
20 changes: 20 additions & 0 deletions Ninja Price/Enums/HaggleTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ninja_Price.Enums
{
class HaggleTypes
{
public enum HaggleType
{
None, // None
Exchange, // Dannig
Gamble, // Gwennen
Deal, // Rog
Haggle, // Tujen
}
}
}
13 changes: 13 additions & 0 deletions Ninja Price/Main/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CustomItem
public string UniqueName;
public int Width;
public ItemTypes ItemType;
public ItemTypes ItemTypeGamble;
public MapData MapInfo { get; set; } = new MapData();
public CurrencyData CurrencyInfo { get; set; } = new CurrencyData();
public Main.ReleventPriceData PriceData { get; set; } = new Main.ReleventPriceData();
Expand Down Expand Up @@ -268,6 +269,18 @@ public CustomItem(NormalInventoryItem item)
case ItemRarity.Unique when IsIdentified && item.Item.HasComponent<Weapon>():
ItemType = ItemTypes.UniqueWeapon;
break;
case ItemRarity.Normal when ClassName == "Amulet" || ClassName == "Ring" || ClassName == "Belt":
ItemTypeGamble = ItemTypes.UniqueAccessory;
break;
case ItemRarity.Normal when item.Item.HasComponent<Armour>() || ClassName == "Quiver":
ItemTypeGamble = ItemTypes.UniqueArmour;
break;
case ItemRarity.Normal when ClassName.Equals("Jewel"):
ItemTypeGamble = ItemTypes.UniqueJewel;
break;
case ItemRarity.Normal when item.Item.HasComponent<Weapon>():
ItemTypeGamble = ItemTypes.UniqueWeapon;
break;
}
}
catch (Exception exception)
Expand Down
4 changes: 3 additions & 1 deletion Ninja Price/Main/ReleventPriceData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ninja_Price.Enums;
using System.Collections.Generic;
using Ninja_Price.Enums;

namespace Ninja_Price.Main
{
Expand All @@ -10,6 +11,7 @@ public class ReleventPriceData // store data that was got from checking the item
public double ExaltedPrice { get; set; }
public double ChangeInLast7Days { get; set; }
public ItemTypes ItemType { get; set; }
public List<double> ItemBasePrices { get; set; } = new List<double>();

public override string ToString()
{
Expand Down
108 changes: 107 additions & 1 deletion Ninja Price/Main/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using ExileCore.PoEMemory;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.Elements;
using ExileCore.PoEMemory.Elements.InventoryElements;
Expand All @@ -13,6 +15,7 @@
using RectangleF = SharpDX.RectangleF;
using ExileCore.RenderQ;
using ImGuiNET;
using static Ninja_Price.Enums.HaggleTypes.HaggleType;

namespace Ninja_Price.Main
{
Expand All @@ -26,6 +29,8 @@ public partial class Main
public double StashTabValue { get; set; }
public double InventoryTabValue { get; set; }
public double ExaltedValue { get; set; } = 0;
public List<NormalInventoryItem> HaggleItemList { get; set; } = new List<NormalInventoryItem>();
public List<CustomItem> FortmattedHaggleItemList { get; set; } = new List<CustomItem>();
public List<NormalInventoryItem> ItemList { get; set; } = new List<NormalInventoryItem>();
public List<CustomItem> FortmattedItemList { get; set; } = new List<CustomItem>();

Expand All @@ -36,6 +41,7 @@ public partial class Main
public List<CustomItem> InventoryItemsToDrawList { get; set; } = new List<CustomItem>();
public StashElement StashPanel { get; set; }
public InventoryElement InventoryPanel { get; set; }
public Element HagglePanel { get; set; }

public CustomItem Hovereditem { get; set; }

Expand All @@ -52,6 +58,7 @@ public override void Render()

StashPanel = GameController.Game.IngameState.IngameUi.StashElement;
InventoryPanel = GameController.Game.IngameState.IngameUi.InventoryPanel;
HagglePanel = GameController.Game.IngameState.IngameUi.HaggleWindow;

#endregion

Expand Down Expand Up @@ -171,7 +178,63 @@ public override void Render()
}
}

// TODO: Graphical part from gathered data
if (HagglePanel.IsVisible)
{

var haggleType = None;

// Return Haggle Window Type
var haggleText = HagglePanel.GetChildAtIndex(6).GetChildAtIndex(2).GetChildAtIndex(0).Text;

switch (haggleText)
{
case "Exchange":
haggleType = Exchange;
break;
case "Gamble":
haggleType = Gamble;
break;
case "Deal":
haggleType = Deal;
break;
case "Haggle":
haggleType = Haggle;
break;
}

if (haggleType == Gamble)
{
HaggleItemList = new List<NormalInventoryItem>();
var itemChild = HagglePanel.GetChildAtIndex(8).GetChildAtIndex(1).GetChildAtIndex(0).GetChildAtIndex(0);

for (var i = 1; i < itemChild.ChildCount; ++i)
{
var item = itemChild.Children[i].AsObject<NormalInventoryItem>();
HaggleItemList.Add(item);

if (Settings.Debug)
{
LogMessage(
$"Haggle Item[{HaggleItemList.Count}]: {GameController.Files.BaseItemTypes.Translate(item.Item.Path).BaseName}");
}
}

// Format Haggle Items
FortmattedHaggleItemList = new List<CustomItem>();
FortmattedHaggleItemList = FormatItems(HaggleItemList);

foreach (var item in FortmattedHaggleItemList)
GetValueHaggle(item);
}
else
{
HaggleItemList = new List<NormalInventoryItem>();
FortmattedHaggleItemList = new List<CustomItem>();
}
}

// Expedition Gamble Func
ExpeditionGamble();

GetHoveredItem(); // Get information for the hovered item
DrawGraphics();
Expand Down Expand Up @@ -397,6 +460,49 @@ private void PriceBoxOverItem(CustomItem item)
//Graphics.DrawFrame(drawBox, 1, Settings.CurrencyTabBorderColor);
}

private void PriceBoxOverItemHaggle(CustomItem item)
{
var box = item.Item.GetClientRect();
var drawBox = new RectangleF(box.X, box.Y + 2, box.Width, +Settings.CurrencyTabBoxHeight);
var position = new Vector2(drawBox.Center.X, drawBox.Center.Y - Settings.CurrencyTabFontSize.Value / 2);

if (item.PriceData.ItemBasePrices.Count == 0)
return;

// Sort base unique price from High -> Low
item.PriceData.ItemBasePrices.Sort((a, b) => b.CompareTo(a));

if (Settings.Debug)
Graphics.DrawText(string.Join(",", item.PriceData.ItemBasePrices), position, Settings.CurrencyTabFontColor, FontAlign.Center);


Graphics.DrawText(Math.Round((decimal)item.PriceData.ItemBasePrices.FirstOrDefault(), Settings.CurrenctTabSigDigits.Value).ToString(CultureInfo.InvariantCulture), position, Settings.CurrencyTabFontColor, FontAlign.Center);
Graphics.DrawBox(drawBox, Settings.CurrencyTabBackgroundColor);
//Graphics.DrawFrame(drawBox, 1, Settings.CurrencyTabBorderColor);
}

private void ExpeditionGamble()
{
var window = HagglePanel;
if (!window.IsVisible) return;
foreach (var customItem in FortmattedHaggleItemList)
{
try
{
PriceBoxOverItemHaggle(customItem);
}
catch (Exception e)
{
// ignored
if (Settings.Debug)
{
LogMessage("Error in: ExpeditionGamble, restart PoEHUD.", 5, Color.Red);
LogMessage(e.ToString(), 5, Color.Orange);
}
}
}
}

/// <summary>
/// Displays price for unique items, and highlights the uniques under X value by drawing a border arround them.
/// </summary>
Expand Down
63 changes: 63 additions & 0 deletions Ninja Price/Methods/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,69 @@ public void GetValue(CustomItem item)
}
}

public void GetValueHaggle(CustomItem item)
{
try
{
item.PriceData.ExaltedPrice = (double)CollectedData.Currency.Lines.Find(x => x.CurrencyTypeName == "Exalted Orb").ChaosEquivalent;
switch (item.ItemTypeGamble) // easier to get data for each item type and handle logic based on that
{
case ItemTypes.UniqueArmour:
var uniqueArmourSearch = CollectedData.UniqueArmours.Lines.FindAll(x => x.BaseType == item.BaseName && !x.Name.StartsWith("Replica ") && (x.Links < 5 || x.Links == null));
if (uniqueArmourSearch.Count > 0)
{

foreach (var result in uniqueArmourSearch)
{
item.PriceData.ItemBasePrices.Add((double)result.ChaosValue);
}
}
break;
case ItemTypes.UniqueWeapon:
var uniqueWeaponSearch = CollectedData.UniqueWeapons.Lines.FindAll(x => x.BaseType == item.BaseName && !x.Name.StartsWith("Replica ") && (x.Links < 5 || x.Links == null));
if (uniqueWeaponSearch.Count > 0)
{

foreach (var result in uniqueWeaponSearch)
{
item.PriceData.ItemBasePrices.Add((double)result.ChaosValue);
}
}
break;
case ItemTypes.UniqueAccessory:
var uniqueAccessorySearch = CollectedData.UniqueAccessories.Lines.FindAll(x => x.BaseType == item.BaseName && !x.Name.StartsWith("Replica "));
if (uniqueAccessorySearch.Count > 0)
{

foreach (var result in uniqueAccessorySearch)
{
item.PriceData.ItemBasePrices.Add((double)result.ChaosValue);
}
}
break;
case ItemTypes.UniqueJewel:
var uniqueJewelSearch = CollectedData.UniqueJewels.Lines.FindAll(x => x.DetailsId.Contains(item.BaseName.ToLower().Replace(" ", "-")) && !x.Name.StartsWith("Replica "));
if (uniqueJewelSearch.Count > 0)
{

foreach (var result in uniqueJewelSearch)
{
item.PriceData.ItemBasePrices.Add((double)result.ChaosValue);
}
}
break;
}
}
catch (Exception e)
{
if (Settings.Debug)
{
LogMessage($"{GetCurrentMethod()}.GetValueHaggle() Error that i dont understand, Item: {item.BaseName}", 5, Color.Red);
LogMessage($"{GetCurrentMethod()}.GetValueHaggle() {e.Message}", 5, Color.Red);
}
}
}

public bool ShouldUpdateValues()
{
if (ValueUpdateTimer.ElapsedMilliseconds > Settings.ValueLoopTimerMS)
Expand Down
1 change: 1 addition & 0 deletions Ninja Price/Ninja Price.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="API\PoeNinja\Classes\DeliriumOrb.cs" />
<Compile Include="API\PoeNinja\Classes\UniqueWeapons.cs" />
<Compile Include="API\PoeNinja\Classes\WhiteMaps.cs" />
<Compile Include="Enums\HaggleTypes.cs" />
<Compile Include="Enums\MapTypes.cs" />
<Compile Include="Main\CollectiveAPIData.cs" />
<Compile Include="Main\CustomItem.cs" />
Expand Down

0 comments on commit a25f828

Please sign in to comment.