using Tiger.Communication.Messages.Interfaces; using Tiger.Communication.Messages.Types; using Tiger.Game.Achievements; using Tiger.Game.Habbos; namespace Tiger.Communication.Messages.Outgoing.Inventory.Achievements; public class AchievementsComposer : IMessageComposer { private readonly ICollection _achievements; private readonly Habbo _habbo; public AchievementsComposer(ICollection achievements, Habbo habbo) { _achievements = achievements; _habbo = habbo; } public OutgoingHeaders Header => OutgoingHeaders.AchievementsComposer; public void Compose(ServerMessage message) { message.AppendInt32(_achievements.Count); foreach (var achievement in _achievements) { var targetLevel = 1; if (_habbo.Achievements.TryGetValue(achievement.Id, out var habboAchievement)) targetLevel = habboAchievement.Level == achievement.Levels.Count ? habboAchievement.Level : habboAchievement.Level + 1; message.AppendInt32(achievement.Id); message.AppendInt32(targetLevel); message.AppendString($"{achievement.Badge}{targetLevel}"); message.AppendInt32(habboAchievement?.Progress ?? 0); message.AppendInt32(achievement.Levels[targetLevel].ProgressNeeded); message.AppendInt32(achievement.Levels[targetLevel].RewardAmount); message.AppendInt32(achievement.Levels[targetLevel].RewardType); message.AppendInt32(habboAchievement?.Progress ?? 0); message.AppendBoolean((habboAchievement?.Level ?? 0) >= achievement.Levels.Count); message.AppendString(achievement.Category); message.AppendString(string.Empty); message.AppendInt32(achievement.Levels.Count); message.AppendInt32((habboAchievement?.Level ?? 0) >= achievement.Levels.Count ? 1 : 0); } message.AppendString(string.Empty); } }