Added look updating and made a start on a figure validator
parent
59d90aeeb2
commit
e1fd118ade
|
@ -0,0 +1,48 @@
|
|||
using Tiger.Communication.Messages.Interfaces;
|
||||
using Tiger.Communication.Messages.Outgoing.Avatar;
|
||||
using Tiger.Communication.Messages.Types;
|
||||
using Tiger.Game.Figuredata;
|
||||
using Tiger.Game.Habbos;
|
||||
using Tiger.Networking.Game.Sessions;
|
||||
using Tiger.Storage;
|
||||
|
||||
namespace Tiger.Communication.Messages.Incoming.Register;
|
||||
|
||||
public class UpdateFigureDataMessageEvent : IMessageEvent
|
||||
{
|
||||
private readonly IGameSessionManager _gameSessionManager;
|
||||
private readonly IFigureDataManager _figureDataManager;
|
||||
private readonly IRepository<Habbo> _habboRepository;
|
||||
|
||||
public UpdateFigureDataMessageEvent(IGameSessionManager gameSessionManager, IFigureDataManager figureDataManager, IRepository<Habbo> habboRepository)
|
||||
{
|
||||
_gameSessionManager = gameSessionManager;
|
||||
_figureDataManager = figureDataManager;
|
||||
_habboRepository = habboRepository;
|
||||
}
|
||||
|
||||
public IncomingHeaders Header => IncomingHeaders.UpdateFigureDataEvent;
|
||||
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||
{
|
||||
if (gameSession.Habbo == null)
|
||||
{
|
||||
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||
return;
|
||||
}
|
||||
|
||||
var gender = request.ReadString()?.ToUpper();
|
||||
var figure = request.ReadString();
|
||||
|
||||
if (gender is null || figure is null || (gender != "M" && gender != "F") /*||
|
||||
!_figureDataManager.ValidateFigure(figure, gender, gameSession.Habbo)*/)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gameSession.Habbo.Figure = figure;
|
||||
gameSession.Habbo.Gender = gender;
|
||||
_habboRepository.SaveAsync(gameSession.Habbo);
|
||||
|
||||
await gameSession.SendComposerAsync(new FigureUpdateComposer(figure, gender));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using Tiger.Communication.Messages.Interfaces;
|
||||
using Tiger.Communication.Messages.Types;
|
||||
|
||||
namespace Tiger.Communication.Messages.Outgoing.Avatar;
|
||||
|
||||
public class FigureUpdateComposer : IMessageComposer
|
||||
{
|
||||
private readonly string _figure;
|
||||
private readonly string _gender;
|
||||
|
||||
public FigureUpdateComposer(string figure, string gender)
|
||||
{
|
||||
_figure = figure;
|
||||
_gender = gender;
|
||||
}
|
||||
|
||||
public OutgoingHeaders Header => OutgoingHeaders.FigureUpdateComposer;
|
||||
public void Compose(ServerMessage message)
|
||||
{
|
||||
message.AppendString(_figure);
|
||||
message.AppendString(_gender);
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,10 @@
|
|||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class Color
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Index { get; set; }
|
||||
public int Club { get; set; }
|
||||
public bool Selectable { get; set; }
|
||||
public string HexCode { get; set; } = null!;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class Figuredata
|
||||
{
|
||||
public List<Palette> Palettes { get; set; } = new();
|
||||
public List<SetType> SetTypes { get; set; } = new();
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
using Tiger.Game.Habbos;
|
||||
|
||||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public interface IFigureDataManager
|
||||
{
|
||||
bool ValidateFigure(string newFigure, string newGender, Habbo habbo);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class Palette
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public List<Color> Colors { get; set; } = new();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class Part
|
||||
{
|
||||
public bool Colorable { get; set; }
|
||||
public int ColorIndex { get; set; }
|
||||
public uint Id { get; set; }
|
||||
public int Index { get; set; }
|
||||
public string Type { get; set; } = null!;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class Set
|
||||
{
|
||||
public int Club { get; set; }
|
||||
public bool Colorable { get; set; }
|
||||
public string Gender { get; set; } = null!;
|
||||
public int Id { get; set; }
|
||||
public bool Preselectable { get; set; }
|
||||
public bool Selectable { get; set; }
|
||||
public bool Sellable { get; set; }
|
||||
public List<Part> Parts { get; set; } = new();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tiger.Game.Figuredata;
|
||||
|
||||
public class SetType
|
||||
{
|
||||
public string Type { get; set; } = null!;
|
||||
[JsonProperty("mandatory_f_0")]
|
||||
public bool MandatoryF0 { get; set; }
|
||||
[JsonProperty("mandatory_f_1")]
|
||||
public bool MandatoryF1 { get; set; }
|
||||
[JsonProperty("mandatory_m_0")]
|
||||
public bool MandatoryM0 { get; set; }
|
||||
[JsonProperty("mandatory_m_1")]
|
||||
public bool MandatoryM1 { get; set; }
|
||||
public int PaletteId { get; set; }
|
||||
public List<Set> Sets { get; set; } = new();
|
||||
}
|
|
@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Tiger.Communication.Messages;
|
||||
using Tiger.Game.Catalogue;
|
||||
using Tiger.Game.Figuredata;
|
||||
using Tiger.Game.Habbos;
|
||||
using Tiger.Game.Settings;
|
||||
using Tiger.Networking.Game;
|
||||
|
@ -35,12 +36,14 @@ collection.AddScoped(serviceProvider => serviceProvider.GetRequiredService<INhSe
|
|||
collection.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
||||
collection.AddSingleton<ISettingManager, SettingManager>();
|
||||
collection.AddSingleton<ICatalogueManager, CatalogueManager>();
|
||||
collection.AddSingleton<IFigureDataManager, FiguredataManager>();
|
||||
collection.RegisterMessageEvents();
|
||||
|
||||
var provider = collection.BuildServiceProvider();
|
||||
|
||||
await provider.GetRequiredService<ISettingManager>().ReloadSettingsAsync();
|
||||
await provider.GetRequiredService<ICatalogueManager>().LoadPagesAsync();
|
||||
provider.GetRequiredService<IFigureDataManager>();
|
||||
|
||||
provider.GetRequiredService<IWebSocketServer>().Start($"http://{configuration["Network:Game:Ip"]}:{configuration["Network:Game:Port"]}/");
|
||||
|
||||
|
|
|
@ -19,11 +19,15 @@
|
|||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-rc.1.23419.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.1.23419.4" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.0-beta.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NHibernate.Driver.MySqlConnector" Version="2.0.5-ci.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.yaml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="FigureData.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
Loading…
Reference in New Issue