104 lines
2.9 KiB
C#
104 lines
2.9 KiB
C#
using AssortValidator.Common.Helpers;
|
|
using AssortValidator.Common.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace AssortValidator.Common
|
|
{
|
|
public static class ItemTemplateHelper
|
|
{
|
|
private static Dictionary<string, ItemLookup> _itemCache;
|
|
|
|
public static Dictionary<string, ItemLookup> Items
|
|
{
|
|
get
|
|
{
|
|
if (_itemCache == null)
|
|
{
|
|
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json";
|
|
if (!File.Exists(itemsFilePath))
|
|
{
|
|
throw new Exception($"Missing items.json under assets ({itemsFilePath})");
|
|
}
|
|
|
|
var itemsJson = File.ReadAllText(itemsFilePath);
|
|
_itemCache = JsonSerializer.Deserialize<Dictionary<string, ItemLookup>>(itemsJson);
|
|
}
|
|
|
|
return _itemCache;
|
|
}
|
|
}
|
|
|
|
public static ItemLookup GetTemplateById(string templateId)
|
|
{
|
|
if (templateId == "5449016a4bdc2d6f028b456f")
|
|
{
|
|
return new ItemLookup
|
|
{
|
|
_id = templateId,
|
|
_name = "Roubles",
|
|
_parent = "543be5dd4bdc2deb348b4569",
|
|
_type = ""
|
|
};
|
|
}
|
|
|
|
if (templateId == "569668774bdc2da2298b4568")
|
|
{
|
|
return new ItemLookup
|
|
{
|
|
_id = templateId,
|
|
_name = "Euros",
|
|
_parent = "543be5dd4bdc2deb348b4569",
|
|
_type = ""
|
|
};
|
|
}
|
|
|
|
if (templateId == "5696686a4bdc2da3298b456a")
|
|
{
|
|
return new ItemLookup
|
|
{
|
|
_id = templateId,
|
|
_name = "Dollars",
|
|
_parent = "543be5dd4bdc2deb348b4569",
|
|
_type = ""
|
|
};
|
|
}
|
|
|
|
if (Items.ContainsKey(templateId))
|
|
{
|
|
return Items[templateId];
|
|
}
|
|
|
|
LoggingHelpers.LogToConsole($"Could not locate item template with id {templateId}", ConsoleColor.Red);
|
|
return null;
|
|
}
|
|
|
|
public static bool IsMoney(string tplId)
|
|
{
|
|
if (tplId == "5449016a4bdc2d6f028b456f")
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (tplId == "569668774bdc2da2298b4568")
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (tplId == "5696686a4bdc2da3298b456a")
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
return false;
|
|
}
|
|
|
|
public static string GetNameById(string id)
|
|
{
|
|
return Items.ContainsKey(id) ? Items[id]._name : "Unknown item";
|
|
}
|
|
}
|
|
} |