TigerEmu/Communication/Messages/Incoming/Achievement/RequestAchievementsMessageE...

33 lines
1.3 KiB
C#

using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Outgoing.Inventory.Achievements;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Achievements;
using Tiger.Networking.Game.Sessions;
namespace Tiger.Communication.Messages.Incoming.Achievement;
public class RequestAchievementsMessageEvent : IMessageEvent
{
private readonly IGameSessionManager _gameSessionManager;
private readonly IAchievementManager _achievementManager;
public RequestAchievementsMessageEvent(IGameSessionManager gameSessionManager, IAchievementManager achievementManager)
{
_gameSessionManager = gameSessionManager;
_achievementManager = achievementManager;
}
public IncomingHeaders Header => IncomingHeaders.AchievementList;
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
{
if (gameSession.Habbo == null)
{
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
return;
}
await gameSession.SendComposerAsync(new AchievementsScoreComposer(gameSession.Habbo.AchievementScore));
await gameSession.SendComposerAsync(new AchievementsComposer(_achievementManager.Achievements.Values,
gameSession.Habbo));
}
}