2023-09-29 18:20:28 +00:00
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using Tiger.Communication.Messages.Interfaces;
|
2023-10-14 16:21:53 +00:00
|
|
|
using Tiger.Communication.Messages.Outgoing.User.Data;
|
2023-09-29 18:20:28 +00:00
|
|
|
using Tiger.Communication.Messages.Types;
|
|
|
|
using Tiger.Game.Habbos;
|
|
|
|
using Tiger.Networking.Game.Sessions;
|
|
|
|
using Tiger.Storage;
|
|
|
|
|
|
|
|
namespace Tiger.Communication.Messages.Incoming.Inventory.Badges;
|
|
|
|
|
|
|
|
public class SetActivatedBadgesEvent : IMessageEvent
|
|
|
|
{
|
|
|
|
private readonly IGameSessionManager _gameSessionManager;
|
|
|
|
private readonly IRepository<Badge> _badgeRepository;
|
|
|
|
|
|
|
|
public SetActivatedBadgesEvent(IGameSessionManager gameSessionManager, IRepository<Badge> badgeRepository)
|
|
|
|
{
|
|
|
|
_gameSessionManager = gameSessionManager;
|
|
|
|
_badgeRepository = badgeRepository;
|
|
|
|
}
|
|
|
|
|
2023-10-14 16:21:53 +00:00
|
|
|
public IncomingHeaders Header => IncomingHeaders.UserBadgesCurrentUpdate;
|
2023-09-29 18:20:28 +00:00
|
|
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
|
|
|
{
|
|
|
|
if (gameSession.Habbo == null)
|
|
|
|
{
|
|
|
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var wearingBadges = new Collection<Badge>();
|
2023-10-07 13:32:19 +00:00
|
|
|
var badgesToUpdate = new Dictionary<int, Badge>();
|
2023-10-06 16:12:35 +00:00
|
|
|
var current = gameSession.Habbo.Badges.Where(b => b.Slot != 0);
|
|
|
|
foreach (var currentBadge in current)
|
2023-09-29 18:20:28 +00:00
|
|
|
{
|
|
|
|
currentBadge.Slot = 0;
|
2023-10-07 13:32:19 +00:00
|
|
|
badgesToUpdate.Add(currentBadge.Id, currentBadge);
|
2023-09-29 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
var slotId = request.ReadInt32();
|
|
|
|
var code = request.ReadString();
|
|
|
|
|
|
|
|
if (slotId == null || slotId is < 1 or > 5 || string.IsNullOrEmpty(code)) continue;
|
|
|
|
|
|
|
|
var badge = gameSession.Habbo.Badges.FirstOrDefault(b => b.Code == code);
|
|
|
|
|
|
|
|
if (badge == null) continue;
|
|
|
|
|
|
|
|
badge.Slot = slotId.Value;
|
|
|
|
wearingBadges.Add(badge);
|
2023-10-07 13:32:19 +00:00
|
|
|
|
|
|
|
badgesToUpdate.TryAdd(badge.Id, badge);
|
2023-09-29 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 13:32:19 +00:00
|
|
|
await _badgeRepository.SaveManyAsync(badgesToUpdate.Values);
|
2023-10-14 16:21:53 +00:00
|
|
|
await gameSession.SendComposerAsync(new UserCurrentBadgesComposer(gameSession.Habbo.Id, wearingBadges));
|
2023-09-29 18:20:28 +00:00
|
|
|
}
|
|
|
|
}
|