LootDumpProcessor/Model/ComposedKey.cs

42 lines
1.1 KiB
C#
Raw Permalink Normal View History

using System.Text.Json.Serialization;
2023-08-12 19:08:38 +01:00
using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Utils;
2023-08-12 19:08:38 +01:00
using Newtonsoft.Json;
namespace LootDumpProcessor.Model;
public class ComposedKey
{
[JsonProperty("key")]
[JsonPropertyName("key")]
public string Key { get; init; }
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public Item? FirstItem { get; }
public ComposedKey(Template template) : this(template.Items)
{
}
public ComposedKey(List<Item>? items)
{
Key = items?.Select(i => i.Tpl)
.Where(i => !string.IsNullOrEmpty(i) &&
!LootDumpProcessorContext.GetTarkovItems().IsBaseClass(i, BaseClasses.Ammo))
.Cast<string>()
.Select(i => (double)i.GetHashCode())
.Sum()
.ToString() ?? KeyGenerator.GetNextKey();
2023-08-12 19:08:38 +01:00
FirstItem = items?[0];
}
public override bool Equals(object? obj)
{
if (obj is not ComposedKey key)
return false;
return Key == key.Key;
2023-08-12 19:08:38 +01:00
}
public override int GetHashCode() => Key.GetHashCode();
}