Exemplo n.º 1
0
		public static bool Save(PublishedBook publishedBook)
		{
			XmlBook book = XmlBook.FromPublishedBook(publishedBook);
			string fileName = DataPath + book.ID.ToString() + ".xml";
			try
			{
				if(!Directory.Exists(Path.GetDirectoryName(fileName)))
					Directory.CreateDirectory(Path.GetDirectoryName(fileName));
				XmlSerializer serializer = new XmlSerializer(typeof(XmlBook));
				FileStream fs = new FileStream(fileName, FileMode.Create);
				serializer.Serialize(fs, book);
				fs.Close();
				return true;
			}
			catch(Exception)
			{
				return false;
			}
		}
Exemplo n.º 2
0
		private static XmlBook FromPublishedBook(PublishedBook publishedBook)
		{
			XmlBook book = new XmlBook();
			book.Title = publishedBook.Title;
			book.Author = publishedBook.Author;
			book.FirstPublished = publishedBook.FirstPublished.ToString("u").Replace(' ','T');
			book.LastPublished = publishedBook.LastPublished.ToString("u").Replace(' ','T');
			book.Hue = publishedBook.Hue;
			book.HuedItemID = publishedBook.HuedItemID;
			book.ItemID = publishedBook.ItemID;
			getBookContributors(publishedBook, book);
			getBookPages(publishedBook, book);
			try
			{
				book.ID = new Guid(publishedBook.PublishID);
			}
			catch(Exception)
			{
				book.ID = Guid.NewGuid();
				publishedBook.PublishID = book.ID.ToString();
			}
			return book;
		}
Exemplo n.º 3
0
		private void Publish(Mobile contributor, BaseBook book)
		{
			PublishedBook publishedBook = book as PublishedBook;
			if(publishedBook != null)
			{
				publishedBook.AddContributor(contributor.Name);
				Republish(contributor, publishedBook);
				return;
			}

			// change into published book
			publishedBook = new PublishedBook(book);
			publishedBook.AddContributor(contributor.Name);
			if(!publishedBook.IsPublishable())
			{
				publishedBook.Delete();
				this.SayTo(contributor, "You might want to try writing something of interest first.");
			}
			else if(XmlBook.Save(publishedBook))
			{
                switch (Utility.Random( 3 ) )
                {
                    case 0:
                    {
                        contributor.AddToBackpack(new Gold(1500, 3000));
                        this.SayTo(contributor, "This seems to be a excellent material. Let me see... hm... here - your royalty. You should see the story soon. I am sure it will sell well.");
                        contributor.SendMessage("You receive a good amount of gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 1:
                    {
                        contributor.AddToBackpack(new Gold(1000, 1250));
                        this.SayTo(contributor, "This seems to be decent material. Let me see... hm... here - your royalty. You should see the story soon. I hope it will sell well.");
                        contributor.SendMessage("You receive a decent amount of gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 2: 
                    {
                        contributor.AddToBackpack(new Gold(100, 500));
                        this.SayTo(contributor, "I don't know if this is good enough to be sold, but let me see... hm... here - I can't give you more for this. I am not sure it will sell at all.");
                        contributor.SendMessage("You receive some gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                  
                }


            }
			else
			{
				publishedBook.Delete();
				this.SayTo(contributor, "Our machines are not working right. Check back later.");
			}
		}
Exemplo n.º 4
0
		private void Republish(Mobile contributor, PublishedBook book)
		{
			if(!book.IsPublishable())
			{
				this.SayTo(contributor, "You might want to try writing something of interest first.");
			}
			else if(book.IsModified())
			{
				book.AddContributor(contributor.Name);
				if(XmlBook.Save(book))
				{
					book.RePublish();
					//contributor.AddToBackpack(new Gold (100));
					this.SayTo(contributor, "Your book appears to have changed. Let me publish that for you!");
                    //contributor.SendMessage("You receive some gold.");
                    //if (m_Sound)
                    //    Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
				}
				else
				{
					this.SayTo(contributor, "Our machines are not working right. Check back later.");
				}
			}
			else
			{
				this.SayTo(contributor, "It looks the same as the last story we printed.");
			}
		}
Exemplo n.º 5
0
		private static void getBookPages(PublishedBook publishedBook, XmlBook book)
		{
			int count = 0;
			for(int i = 0; i < publishedBook.Pages.Length; i++)
				for(int j = 0; j < publishedBook.Pages[i].Lines.Length; j++)
					if(publishedBook.Pages[i].Lines[j].Trim() != string.Empty)
						count++;
			book.Contents = new XmlBook.Content[count];
			count = 0;
			for(int i = 0; i < publishedBook.Pages.Length; i++)
				for(int j = 0; j < publishedBook.Pages[i].Lines.Length; j++)
					if(publishedBook.Pages[i].Lines[j].Trim() != string.Empty)
					{
						book.Contents[count] = new XmlBook.Content();
						book.Contents[count].Line = j + 1;
						book.Contents[count].Page = i + 1;
						book.Contents[count].Text = publishedBook.Pages[i].Lines[j];
						count++;
					}
		}
Exemplo n.º 6
0
		private static void getBookContributors(PublishedBook publishedBook, XmlBook book)
		{
			if(publishedBook.Contributors != null)
			{
				book.Contributors = new XmlBook.Contributor[publishedBook.Contributors.Length];
				for(int i = 0; i < publishedBook.Contributors.Length; i++)
				{
					book.Contributors[i] = new XmlBook.Contributor();
					book.Contributors[i].Name = publishedBook.Contributors[i];
				}
			}
		}