예제 #1
0
        private void SetText(string text)
        {
            var words = text.Split(' ');

            int wordCount, wordsPerLine, linesPerPage, index, pageCount;

            ParseFactors(words, out wordCount, out wordsPerLine, out linesPerPage, out index, out pageCount);

            for (var currentPage = 0; currentPage < pageCount; currentPage++)
            {
                for (var currentLine = 0; currentLine < linesPerPage; currentLine++)
                {
                    Pages[currentPage] = new BookPageInfo(new string[linesPerPage]);
                    var line = new StringBuilder();

                    for (var currentWord = 0; currentWord < wordsPerLine; currentWord++)
                    {
                        if (index >= wordCount)
                        {
                            continue;
                        }

                        line.AppendFormat(" {0}", words[index]);
                        index++;
                    }

                    Pages[currentPage].Lines[currentLine] = line.ToString();
                }
            }
        }
예제 #2
0
		public bool IsMatch( BookPageInfo[] cmp )
		{
			if ( cmp.Length != m_Pages.Length )
				return false;

			for ( int i = 0; i < cmp.Length; ++i )
			{
				string[] a = m_Pages[i].Lines;
				string[] b = cmp[i].Lines;

				if ( a.Length != b.Length )
				{
					return false;
				}
				else if ( a != b )
				{
					for ( int j = 0; j < a.Length; ++j )
					{
						if ( a[j] != b[j] )
							return false;
					}
				}
			}

			return true;
		}
예제 #3
0
        public static void ReadBookNode(XmlElement parent)
        {
            try
            {
                string         title  = parent.GetAttribute("Title");
                string         author = parent.GetAttribute("Author");
                int            pgcnt  = Utility.ToInt32(parent.GetAttribute("PagesCount"));
                BookPageInfo[] pages  = new BookPageInfo[pgcnt];

                if (parent.HasChildNodes)
                {
                    int        i     = 0;
                    XmlElement child = parent.FirstChild as XmlElement;
                    pages[i++] = ReadPageNode(child);
                    while (child.NextSibling != null && i < pages.Length)
                    {
                        child      = child.NextSibling as XmlElement;
                        pages[i++] = ReadPageNode(child);
                    }
                }
                Publisher.Books.Add(new BookContent(title, author, pages));
            }
            catch
            {
                Console.WriteLine("failed.");
            }
            Console.WriteLine("done.");
        }
예제 #4
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is BaseBook)
                {
                    BaseBook       book  = targeted as BaseBook;
                    BookPageInfo[] pages = book.Pages;

                    for (int i = 0; i < pages.Length && i < book.Pages.Length; i++)
                    {
                        BookPageInfo page = pages[i];

                        int length = page.Lines.Length;

                        for (int j = 0; j < length; j++)
                        {
                            m_PG.Lines.Add((page.Lines[j]).Trim());
                        }
                    }

                    m_PG.Post();
                    from.SendMessage("The message has been posted.");

                    if (!m_PG.m_ThreadEntry.StaffMessage)
                    {
                        World.Broadcast(0x482, false, "{0} has just posted a message on the forum! Type [Forum to read it.", from.Name);
                    }
                }
            }
예제 #5
0
		public BookPageInfo[] Copy()
		{
			BookPageInfo[] copy = new BookPageInfo[m_Pages.Length];

			for ( int i = 0; i < copy.Length; ++i )
				copy[i] = new BookPageInfo( m_Pages[i].Lines );

			return copy;
		}
예제 #6
0
        public TestBook(Serial serial) : base(serial)
        {
            Pages = new BookPageInfo[20];

            for (var i = 0; i < Pages.Length; ++i)
            {
                Pages[i] = new BookPageInfo();
            }
        }
예제 #7
0
        public BookPageInfo[] Copy()
        {
            var copy = new BookPageInfo[Pages.Length];

            for (var i = 0; i < copy.Length; ++i)
            {
                copy[i] = new BookPageInfo(Pages[i].Lines);
            }

            return(copy);
        }
예제 #8
0
        public BookPageInfo[] Copy()
        {
            BookPageInfo[] copy = new BookPageInfo[m_Pages.Length];

            for (int i = 0; i < copy.Length; ++i)
            {
                copy[i] = new BookPageInfo(m_Pages[i].Lines);
            }

            return(copy);
        }
예제 #9
0
        public static void WritePageNode(BookPageInfo bpi, XmlTextWriter xml)
        {
            xml.WriteStartElement("Page");
            xml.WriteAttributeString("Lines", bpi.Lines.Length.ToString());
            for (int i = 0; i < bpi.Lines.Length; i++)
            {
                xml.WriteAttributeString("Line" + i.ToString(), bpi.Lines[i]);
            }

            xml.WriteEndElement();
        }
예제 #10
0
        public BookPageDetails(PacketReader reader, bool send) : base(reader, send)
        {
            reader.ReadUInt16();

            m_Serial = reader.ReadUInt32();

            int pagesCount = reader.ReadUInt16();

            m_Pages = new BookPageInfo[pagesCount];

            for (int i = 0; i < m_Pages.Length; i++)
            {
                int index = reader.ReadUInt16();

                int linesCount = reader.ReadInt16();
                if (linesCount < 0)
                {
                    m_Pages[i] = new BookPageInfo(index, true, new string[0]);
                    continue;
                }

                string[] lines = new string[linesCount];

                for (int j = 0; j < linesCount; j++)
                {
                    ArrayList buffer = new ArrayList();

                    while (true)
                    {
                        byte b = reader.ReadByte();

                        if (b != 0)
                        {
                            buffer.Add(b);
                        }
                        else
                        {
                            byte[] bytes = (byte[])buffer.ToArray(typeof(byte));
                            lines[j] = Encoding.UTF8.GetString(bytes);

                            break;
                        }
                    }
                }

                m_Pages[i] = new BookPageInfo(index, false, lines);
            }
        }
예제 #11
0
		public BookPageDetails( PacketReader reader, bool send ) : base( reader, send )
		{
			reader.ReadUInt16();

			m_Serial = reader.ReadUInt32();

			int pagesCount = reader.ReadUInt16();
			m_Pages = new BookPageInfo[pagesCount];

			for ( int i = 0; i < m_Pages.Length; i++ )
			{
				int index = reader.ReadUInt16();

				int linesCount = reader.ReadInt16();
				if ( linesCount < 0 )
				{
					m_Pages[i] = new BookPageInfo( index, true, new string[0] );
					continue;
				}

				string[] lines = new string[linesCount];

				for ( int j = 0; j < linesCount; j++ )
				{
					ArrayList buffer = new ArrayList();

					while ( true )
					{
						byte b = reader.ReadByte();

						if ( b != 0 )
						{
							buffer.Add( b );
						}
						else
						{
							byte[] bytes = (byte[])buffer.ToArray( typeof( byte ) );
							lines[j] = Encoding.UTF8.GetString( bytes );

							break;
						}
					}
				}

				m_Pages[i] = new BookPageInfo( index, false, lines );
			}
		}
예제 #12
0
        private void AddText()
        {
            BookPageInfo[] pages          = m_Book.Pages;
            int            totalGumpPages = m_Book.Pages.Length / 2 + 1;
            int            gumpPageNo     = 1;

            for (int i = 0; i < m_Book.Pages.Length; i++)
            {
                // The first book page, like all odd-numbered pages, is written on the
                // right side of the first gump page.
                int bookPageNo = i + 1;
                int firstCol   = 325;

                if (bookPageNo % 2 == 0)
                {
                    // Even numbered pages are written on the left side of the gump page.
                    // Book page 2 is on gump page 2; 4 is on 3, 6 is on 4, etc.
                    gumpPageNo++;
                    AddPage(gumpPageNo);
                    firstCol = 140;

                    // Turn page buttons
                    // After writing gump page 1, whenever a new gump page is created, add a back button.
                    AddButton(100, 10, 501, 501, 0, GumpButtonType.Page, gumpPageNo - 1);

                    // On all new pages, except the last one, add a forward button.
                    if (gumpPageNo < totalGumpPages)   // not the last gump page
                    {
                        AddButton(456, 10, 502, 502, 0, GumpButtonType.Page, gumpPageNo + 1);
                    }
                }

                BookPageInfo page = pages[i];

                for (int j = 0; j < page.Lines.Length; j++)
                {
                    // Write each line of the current book page to the gump in the appropriate place.
                    AddHtml(firstCol, 38 + (j * 18), 155, 20, "<body text = #943131 </body>" + page.Lines[j], false, false);
                }

                // Add the book page number to the middle of the bottom line
                AddHtml(firstCol + 70, 210, 50, 30, "<body text = #404040 </body>" + bookPageNo.ToString(), false, false);
            }
        }
예제 #13
0
        public static void Copy(BaseBook bookSrc, BaseBook bookDst)
        {
            bookDst.Title  = bookSrc.Title;
            bookDst.Author = bookSrc.Author;

            BookPageInfo[] pagesSrc = bookSrc.Pages;
            BookPageInfo[] pagesDst = bookDst.Pages;
            for (int i = 0; i < pagesSrc.Length && i < pagesDst.Length; i++)
            {
                BookPageInfo pageSrc = pagesSrc[i];
                BookPageInfo pageDst = pagesDst[i];

                int length = pageSrc.Lines.Length;
                pageDst.Lines = new string[length];

                for (int j = 0; j < length; j++)
                {
                    pageDst.Lines[j] = pageSrc.Lines[j];
                }
            }
        }
예제 #14
0
        public BaseBook(int itemID, string title, string author, int pageCount, bool writable) : base(itemID)
        {
            BookContent content = DefaultContent;

            m_Title  = title ?? content?.Title;
            m_Author = author ?? content?.Author;
            Writable = writable;

            if (content == null)
            {
                Pages = new BookPageInfo[pageCount];

                for (int i = 0; i < Pages.Length; ++i)
                {
                    Pages[i] = new BookPageInfo();
                }
            }
            else
            {
                Pages = content.Copy();
            }
        }
예제 #15
0
        private static void StartCS(Mobile from, BaseBook book)
        {
            from.SendMessage("Writing book to C# file...");

            try
            {
                string writetitle = String.Format("Book{0}", book.Serial);

                if (!Directory.Exists("CSBooks/"))
                {
                    Directory.CreateDirectory("CSBooks/");
                }

                string filepath = Path.Combine(String.Format("CSBooks/{0}.cs", writetitle));

                if (File.Exists(filepath))
                {
                    from.SendMessage("File already exists for this book.  Dupe this item to change its serial.");
                }
                else
                {
                    using (StreamWriter op = new StreamWriter(filepath))
                    {
                        op.WriteLine("using System;");
                        op.WriteLine("using Server;");
                        op.WriteLine();
                        op.WriteLine("namespace Server.Items");
                        op.WriteLine("{");
                        op.WriteLine("	public class {0} : BaseBook", writetitle);
                        op.WriteLine("	{");
                        op.WriteLine("		public static readonly BookContent Content = new BookContent");
                        op.WriteLine("			(");
                        op.WriteLine("				\"{0}\", \"{1}\",", book.Title, String.IsNullOrEmpty(book.Author) ? "unknown" : book.Author);
                        BookPageInfo[] pages    = book.Pages;
                        int            lastpage = 0;
                        for (int i = pages.Length - 1; i >= 0; i--)
                        {
                            if (pages[i].Lines.Length > 0)                               //This page has something on it
                            {
                                lastpage = i;
                                break;
                            }
                        }

                        for (int i = 0; i < lastpage; i++)
                        {
                            BookPageInfo pageinfo = pages[i];
                            op.WriteLine("				new BookPageInfo");
                            op.WriteLine("				(");
                            for (int j = 0; j < pageinfo.Lines.Length; j++)
                            {
                                op.WriteLine("					\"{0}\"{1}", pageinfo.Lines[j], j < pageinfo.Lines.Length - 1 ? "," : "");
                            }
                            op.WriteLine("				){0}", i < pages.Length - 1 ? "," : "");
                        }
                        op.WriteLine("			);");
                        op.WriteLine();
                        op.WriteLine("		public override BookContent DefaultContent{ get{ return Content; } }");
                        op.WriteLine();
                        op.WriteLine("		[Constructable]");
                        op.WriteLine("		public {0}() : base( {1}, false )", writetitle, book.ItemID);
                        op.WriteLine("		{");
                        op.WriteLine("			LootType = LootType.Blessed;");
                        op.WriteLine("		{");
                        op.WriteLine("		public {0}( Serial serial ) : base( serial )", writetitle);
                        op.WriteLine("		{");
                        op.WriteLine("		}");
                        op.WriteLine();
                        op.WriteLine("		public override void Serialize( GenericWriter writer )");
                        op.WriteLine("		{");
                        op.WriteLine("			base.Serialize( writer );");
                        op.WriteLine("			writer.WriteEncodedInt( (int)0 ); // version");
                        op.WriteLine("		}");
                        op.WriteLine();
                        op.WriteLine("		public override void Deserialize( GenericReader reader )");
                        op.WriteLine("		{");
                        op.WriteLine("			base.Deserialize( reader );");
                        op.WriteLine("			int version = reader.ReadEncodedInt();");
                        op.WriteLine("		}");
                        op.WriteLine("	}");
                        op.WriteLine("}");
                    }
                    from.SendMessage("finished.");
                }
            }
            catch (Exception e)
            {
                from.SendMessage("failed. {0}", e.ToString());
            }
        }