-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCustomItem.cs
More file actions
323 lines (299 loc) · 11.5 KB
/
CustomItem.cs
File metadata and controls
323 lines (299 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
using System;
using System.Collections.Generic;
using System.Linq;
using ExileCore2.PoEMemory;
using ExileCore2.PoEMemory.Components;
using ExileCore2.PoEMemory.Elements.InventoryElements;
using ExileCore2.PoEMemory.FilesInMemory;
using ExileCore2.PoEMemory.MemoryObjects;
using ExileCore2.PoEMemory.Models;
using ExileCore2.Shared.Enums;
using NinjaPricer.Enums;
namespace NinjaPricer;
public class CustomItem
{
public static NinjaPricer Core;
public string BaseName;
public string UniqueName;
public readonly string ClassName;
public readonly bool IsIdentified;
public readonly bool IsCorrupted;
public readonly bool IsWeapon;
public readonly bool IsHovered;
public Element Element;
public readonly Entity Entity;
public int ItemLevel;
public readonly string Path;
public readonly int Quality;
public readonly int GemLevel;
public string GemName;
public readonly ItemRarity Rarity;
public readonly int Sockets;
public readonly List<string> UniqueNameCandidates;
public ItemTypes ItemType;
public readonly List<string> EnchantedStats;
public readonly string CapturedMonsterName;
public readonly uint EntityId;
public MapData MapInfo { get; set; } = new MapData();
public CurrencyData CurrencyInfo { get; set; } = new CurrencyData();
public NinjaPricer.RelevantPriceData PriceData { get; set; } = new NinjaPricer.RelevantPriceData();
public static void InitCustomItem(NinjaPricer core)
{
Core = core;
}
public class MapData
{
public bool IsMap;
public int MapTier;
}
public class CurrencyData
{
public bool IsShard;
public int StackSize = 1;
public int MaxStackSize = 0;
}
public CustomItem()
{
}
public CustomItem(NormalInventoryItem item) : this(item.Item, item)
{
}
public CustomItem(BaseItemType baseItemType)
{
Path = baseItemType.Metadata;
ClassName = baseItemType.ClassName ?? string.Empty;
BaseName = baseItemType.BaseName ?? string.Empty;
ComputeType(null);
}
public CustomItem(Entity itemEntity, Element element)
{
try
{
EntityId = itemEntity.Id;
if (element != null && element.Address != 0)
Element = element;
Path = itemEntity.Path;
Entity = itemEntity;
var baseItemType = Core.GameController.Files.BaseItemTypes.Translate(itemEntity.Path);
ClassName = baseItemType?.ClassName ?? string.Empty;
BaseName = baseItemType?.BaseName ?? string.Empty;
var weaponClass = new List<string>
{
"One Hand Mace",
"Two Hand Mace",
"One Hand Axe",
"Two Hand Axe",
"One Hand Sword",
"Two Hand Sword",
"Thrusting One Hand Sword",
"Bow",
"Claw",
"Dagger",
"Sceptre",
"Staff",
"Wand"
};
if (itemEntity.TryGetComponent<Quality>(out var quality))
{
Quality = quality.ItemQuality;
}
if (itemEntity.TryGetComponent<SkillGem>(out var skillGem))
{
GemLevel = skillGem.Level;
GemName = skillGem.GemEffect?.Name;
}
if (itemEntity.TryGetComponent<Base>(out var @base))
{
IsCorrupted = @base.isCorrupted;
ItemLevel = @base.CurrencyItemLevel;
}
if (itemEntity.TryGetComponent<Mods>(out var mods))
{
Rarity = mods.ItemRarity;
IsIdentified = mods.Identified;
ItemLevel = mods.ItemLevel;
EnchantedStats = mods.EnchantedStats;
UniqueName = mods.UniqueName?.Replace('\x2019', '\x27');
if (!IsIdentified && Rarity == ItemRarity.Unique)
{
var artPath = itemEntity.GetComponent<RenderItem>()?.ResourcePath;
if (artPath != null)
{
UniqueNameCandidates = (Core.UniqueArtMapping.GetValueOrDefault(artPath) ?? Enumerable.Empty<string>())
.Where(x => !x.StartsWith("Replica "))
.ToList();
}
}
}
UniqueNameCandidates ??= [];
if (itemEntity.TryGetComponent<Sockets>(out var sockets))
{
try
{
Sockets = sockets.NumberOfSockets;
}
catch
{
}
}
if (weaponClass.Any(ClassName.Equals))
IsWeapon = true;
MapInfo.MapTier = itemEntity.TryGetComponent<Map>(out var map) ? map.Tier : 0;
MapInfo.IsMap = MapInfo.MapTier > 0;
if (itemEntity.TryGetComponent<Stack>(out var stack))
{
CurrencyInfo.StackSize = stack.Size;
CurrencyInfo.MaxStackSize = stack.Info.MaxStackSize;
if (BaseName.EndsWith(" Shard") ||
BaseName.EndsWith(" Fragment") ||
BaseName.EndsWith(" Splinter") ||
BaseName.StartsWith("Splinter of"))
CurrencyInfo.IsShard = true;
}
if (itemEntity.TryGetComponent<CapturedMonster>(out var capturedMonster))
{
CapturedMonsterName = capturedMonster.MonsterVariety?.MonsterName;
}
IsHovered = Core.GameController.Game.IngameState.UIHover.AsObject<NormalInventoryItem>().Address == Element?.Address;
ComputeType(itemEntity);
}
catch (Exception exception)
{
if (Core.Settings.DebugSettings.EnableDebugLogging)
Core.LogError($"Ninja Pricer.CustomItem Error:\n{exception}");
}
}
private void ComputeType(Entity itemEntity)
{
// sort items into types to use correct json data later from poe.ninja
// This might need tweaking since if this catches anything other than currency.
if (ClassName == "StackableCurrency" &&
!BaseName.StartsWith("Crescent Splinter") &&
!BaseName.StartsWith("Simulacrum") &&
!BaseName.EndsWith("Delirium Orb") &&
!BaseName.Contains("Essence") &&
!BaseName.Contains("Rune") &&
!BaseName.EndsWith(" Oil") &&
!BaseName.Contains("Tattoo ") &&
!BaseName.StartsWith("Omen ") &&
!BaseName.EndsWith("Artifact") &&
!BaseName.Contains("Astragali") &&
!BaseName.Contains("Burial Medallion") &&
!BaseName.Contains("Scrap Metal") &&
!BaseName.Contains("Exotic Coinage") &&
!BaseName.Contains("Remnant of") &&
!BaseName.Contains("Timeless ") &&
BaseName != "Prophecy" &&
BaseName != "Charged Compass" &&
ClassName != "MapFragment" &&
!BaseName.EndsWith(" Fossil") &&
!BaseName.StartsWith("Splinter of ") &&
ClassName != "Incubator" &&
!BaseName.EndsWith(" Catalyst") &&
BaseName != "Valdo's Puzzle Box" &&
!Path.Contains("Metadata/Items/Currency/Distilled", StringComparison.Ordinal) &&
!Path.Contains("Metadata/Items/Currency/Abyssal", StringComparison.Ordinal))
{
ItemType = ItemTypes.Currency;
}
else if (ClassName == "StackableCurrency" && Path.Contains("Metadata/Items/Currency/Distilled", StringComparison.Ordinal))
{
ItemType = ItemTypes.Delirium;
}
else if (ClassName == "StackableCurrency" && Path.Contains("Metadata/Items/Currency/Abyssal", StringComparison.Ordinal))
{
ItemType = ItemTypes.Abyss;
}
else if (BaseName.EndsWith(" Catalyst"))
{
ItemType = ItemTypes.Catalyst;
}
else if (BaseName.Contains("Astragali") || BaseName.Contains("Burial Medallion") || BaseName.Contains("Scrap Metal") || BaseName.Contains("Exotic Coinage"))
{
ItemType = ItemTypes.Artifact;
}
else if (BaseName.StartsWith("Omen "))
{
ItemType = ItemTypes.Omen;
}
else if (Path.Contains("Metadata/Items/DivinationCards"))
{
ItemType = ItemTypes.DivinationCard;
}
else if (BaseName.Contains("Essence") || BaseName.Contains("Remnant of"))
{
ItemType = ItemTypes.Essence;
}
else if (BaseName.Contains("Rune") && ClassName == "SoulCore")
{
ItemType = ItemTypes.Rune;
}
else if (BaseName.Contains("Soul Core") && ClassName == "SoulCore")
{
ItemType = ItemTypes.Ultimatum;
}
else if (BaseName.Contains("Talisman") && ClassName == "SoulCore")
{
ItemType = ItemTypes.Talisman;
}
else if (BaseName.EndsWith("Artifact") && ClassName == "StackableCurrency" ||
BaseName.Contains("Coinage") && ClassName == "StackableCurrency")
{
ItemType = ItemTypes.Expedition;
}
else if (BaseName.Contains("Waystone") && ClassName == "Map" ||
BaseName.Contains("Tablet") && ClassName == "TowerAugmentation")
{
ItemType = ItemTypes.Waystone;
}
else if (BaseName.Contains("Key") && ClassName == "VaultKey")
{
ItemType = ItemTypes.VaultKey;
}
else if (ClassName == "MapFragment" || BaseName.Contains("Timeless ") || BaseName.StartsWith("Simulacrum") ||
ClassName == "StackableCurrency" && BaseName.EndsWith("Splinter") ||
BaseName.StartsWith("Crescent Splinter") ||
ClassName == "VaultKey" ||
BaseName == "Valdo's Puzzle Box")
{
ItemType = ItemTypes.Fragment;
}
else if (MapInfo.IsMap && Rarity != ItemRarity.Unique)
{
ItemType = ItemTypes.Map;
}
else if (ClassName is "Support Skill Gem" or "Active Skill Gem")
{
ItemType = ItemTypes.SkillGem;
}
else if (ClassName is "UncutReservationGemStackable" or "UncutSkillGemStackable" or "UncutSupportGemStackable")
{
ItemType = ItemTypes.UncutGem;
}
else
{
switch (Rarity) // Unique information
{
case ItemRarity.Unique when ClassName is "Amulet" or "Ring" or "Belt":
ItemType = ItemTypes.UniqueAccessory;
break;
case ItemRarity.Unique when itemEntity?.HasComponent<Armour>() == true || ClassName == "Quiver":
ItemType = ItemTypes.UniqueArmour;
break;
case ItemRarity.Unique when itemEntity?.HasComponent<Flask>() == true:
ItemType = ItemTypes.UniqueFlask;
break;
case ItemRarity.Unique when ClassName == "Jewel":
ItemType = ItemTypes.UniqueJewel;
break;
case ItemRarity.Unique when itemEntity?.HasComponent<Weapon>() == true || ClassName == "Sceptre":
ItemType = ItemTypes.UniqueWeapon;
break;
}
}
}
public override string ToString()
{
return string.IsNullOrWhiteSpace(UniqueName) ? BaseName : UniqueName;
}
}