using Tiger.Communication.Messages.Interfaces; using Tiger.Communication.Messages.Types; using Tiger.Game.Catalogue; namespace Tiger.Communication.Messages.Outgoing.Catalog; public class CatalogPageMessageComposer : IMessageComposer { private readonly CataloguePage _page; private readonly int _offerId; private readonly string _mode; private readonly ICollection _featuredPages; public CatalogPageMessageComposer(CataloguePage page, int offerId, string mode, ICollection featuredPages) { _page = page; _offerId = offerId; _mode = mode; _featuredPages = featuredPages; } public OutgoingHeaders Header => OutgoingHeaders.CatalogPage; public void Compose(ServerMessage message) { message.AppendInt32(_page.Id); message.AppendString(_mode); message.AppendString(_page.Layout); message.AppendInt32(_page.Images.Count); foreach (var image in _page.Images) { message.AppendString(image); } message.AppendInt32(_page.Texts.Count); foreach (var text in _page.Texts) { message.AppendString(text); } message.AppendInt32(0); message.AppendInt32(_offerId); message.AppendBoolean(_page.SeasonalCurrency); message.AppendInt32(_featuredPages.Count); foreach (var featuredPage in _featuredPages) { message.AppendInt32(featuredPage.SlotId); message.AppendString(featuredPage.Caption); message.AppendString(featuredPage.Image); message.AppendInt32((int)featuredPage.Type); switch (featuredPage.Type) { default: case CatalogueFeaturedPageType.PageName: case CatalogueFeaturedPageType.ProductName: message.AppendString(featuredPage.Data); break; case CatalogueFeaturedPageType.PageId: message.AppendInt32(int.TryParse(featuredPage.Data, out var pageId) ? pageId : -1); break; } message.AppendInt32((int)(DateTime.Now - featuredPage.Expire).TotalSeconds); } } }