TigerEmu/Game/Figuredata/FiguredataManager.cs

76 lines
2.0 KiB
C#
Raw Permalink Normal View History

using Newtonsoft.Json;
using Tiger.Game.Habbos;
namespace Tiger.Game.Figuredata;
public class FiguredataManager : IFigureDataManager
{
private readonly Figuredata? _figuredata;
public FiguredataManager()
{
try
{
_figuredata = JsonConvert.DeserializeObject<Figuredata>(File.ReadAllText("FigureData.json"));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public bool ValidateFigure(string newFigure, string newGender, Habbo habbo)
{
if (_figuredata is null)
return false;
var parts = newFigure.Split('.');
foreach (var part in parts)
{
if (!part.Contains('-'))
return false;
var subParts = part.Split('-');
var setType = _figuredata.SetTypes.SingleOrDefault(st => st.Type == subParts[0]);
if (setType is null)
return false;
var palette = _figuredata.Palettes.SingleOrDefault(p => p.Id == setType.PaletteId);
if (palette is null)
return false;
var set = setType.Sets.SingleOrDefault(s => s.Id == int.Parse(subParts.Length >= 2 ? subParts[1] : "-1"));
if (set is null)
return false;
// TODO: Check if is club
// TODO: Check for buyable clothes
if (set.Gender.ToUpper() != newGender)
return false;
if (set.Colorable && subParts.Length < 3)
return false;
if (!set.Colorable) continue;
var paletteColor1 = palette.Colors.SingleOrDefault(c => c.Id == int.Parse(subParts[2]));
if (paletteColor1 is null)
return false;
if (subParts.Length == 3) continue;
var paletteColor2 = palette.Colors.SingleOrDefault(c => c.Id == int.Parse(subParts[3]));
if (paletteColor2 is null)
return false;
}
return true;
}
}