Example #1
0
        private void UpdateTables(TimePacket packet)
        {
            if (packet.Packet is WorldItem)
            {
                WorldItem item = (WorldItem)packet.Packet;
                m_Items[item.Serial] = packet.Packet;

                if (m_Books[item.Serial] != null)
                {
                    ((BookInfo)m_Books[item.Serial]).Item = item;
                }
            }
            else if (packet.Packet is BookHeader)
            {
                BookHeader header = (BookHeader)packet.Packet;

                if (m_Books[header.Serial] != null)
                {
                    BookInfo book = (BookInfo)m_Books[header.Serial];

                    book.Title    = header.Title;
                    book.Author   = header.Author;
                    book.Writable = header.Writable;

                    if (book.Lines.Length != header.PagesCount)
                    {
                        book.Lines = new string[header.PagesCount][];
                    }
                }
                else
                {
                    BookInfo book = new BookInfo(header.Serial, header.Title, header.Author, header.Writable, header.PagesCount);

                    if (m_Items[book.Serial] != null)
                    {
                        book.Item = (WorldItem)m_Items[book.Serial];
                    }

                    m_Books[book.Serial] = book;
                }
            }
            else if (packet.Packet is BookPageDetails)
            {
                BookPageDetails details = (BookPageDetails)packet.Packet;

                if (m_Books[details.Serial] != null)
                {
                    BookInfo book = (BookInfo)m_Books[details.Serial];

                    for (int i = 0; i < details.Pages.Length; i++)
                    {
                        if (!details.Pages[i].Request && details.Pages[i].Index - 1 < book.Lines.Length)
                        {
                            book.Lines[details.Pages[i].Index - 1] = details.Pages[i].Lines;
                        }
                    }
                }
            }
        }
Example #2
0
        public void TestBookContent()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            Serial serial = 0x1001;
            var    book   = new TestBook(serial)
            {
                Author = "Some Author", Title = "Some Title"
            };

            book.Pages[0].Lines = new[]
            {
                "Some books start with actual content",
                "This book does not have any actual content",
                "Instead it has several pages of useless text"
            };

            book.Pages[1].Lines = new[]
            {
                "Another page exists but this page:",
                "Has lots of: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
                "And just more: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
                "So everyone can read: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃"
            };

            book.Pages[2].Lines = new[]
            {
                "The end"
            };

            var expected = new BookPageDetails(book).Compile();

            var ns = PacketTestUtilities.CreateTestNetState();

            ns.SendBookContent(book);

            var result = ns.SendPipe.Reader.TryRead();

            AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
        }