mirror of
https://github.com/islehorse/HISP.git
synced 2025-05-24 12:06:25 +12:00
Implement "Read Books"
This commit is contained in:
parent
0b06cd1810
commit
6c42c57bfe
6 changed files with 243 additions and 1 deletions
Horse Isle Server/HorseIsleServer
55
Horse Isle Server/HorseIsleServer/Game/Book.cs
Normal file
55
Horse Isle Server/HorseIsleServer/Game/Book.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP.Game.Services
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
private static List<Book> libaryBooks = new List<Book>();
|
||||
public static Book[] LibaryBooks
|
||||
{
|
||||
get
|
||||
{
|
||||
return libaryBooks.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public int Id;
|
||||
public string Title;
|
||||
public string Author;
|
||||
public string Text;
|
||||
public Book(int id, string title, string author, string text)
|
||||
{
|
||||
Id = id;
|
||||
Title = title;
|
||||
Author = author;
|
||||
Text = text;
|
||||
libaryBooks.Add(this);
|
||||
}
|
||||
|
||||
public static bool BookExists(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetBookById(id);
|
||||
return true;
|
||||
}
|
||||
catch(KeyNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static Book GetBookById(int id)
|
||||
{
|
||||
foreach(Book libaryBook in LibaryBooks)
|
||||
{
|
||||
if (libaryBook.Id == id)
|
||||
return libaryBook;
|
||||
}
|
||||
throw new KeyNotFoundException("no book with id: " + id.ToString() + " found.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -185,6 +185,11 @@ namespace HISP.Game
|
|||
public static string MaxJewelryMessage;
|
||||
public static string RemoveJewelry;
|
||||
|
||||
// Books (Libary)
|
||||
public static string BooksOfHorseIsle;
|
||||
public static string BookEntryFormat;
|
||||
public static string BookReadFormat;
|
||||
|
||||
// Awards (Libary)
|
||||
public static string AwardsAvalible;
|
||||
public static string AwardEntryFormat;
|
||||
|
@ -542,6 +547,15 @@ namespace HISP.Game
|
|||
|
||||
// Click
|
||||
public static string NothingInterestingHere;
|
||||
|
||||
public static string FormatBookReadMeta(string author, string title, string bookText)
|
||||
{
|
||||
return BookReadFormat.Replace("%AUTHOR%", author).Replace("%TITLE%", title).Replace("%TEXT%", bookText);
|
||||
}
|
||||
public static string FormatBookEntry(string title, string author, int id)
|
||||
{
|
||||
return BookEntryFormat.Replace("%TITLE%", title).Replace("%AUTHOR%", author).Replace("%ID%", id.ToString());
|
||||
}
|
||||
public static string FormatIpBannedMessage(string Ip)
|
||||
{
|
||||
return LoginFailedReasonBannedIpFormat.Replace("%IP%", Ip);
|
||||
|
|
|
@ -458,6 +458,26 @@ namespace HISP.Game
|
|||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
public static string BuildBookReadLibary(Book book)
|
||||
{
|
||||
string message = "";
|
||||
message = Messages.FormatBookReadMeta(book.Author, book.Title, book.Text);
|
||||
message += Messages.BackToMap;
|
||||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
public static string BuildBooksLibary()
|
||||
{
|
||||
string message = "";
|
||||
message += Messages.BooksOfHorseIsle;
|
||||
foreach(Book libaryBook in Book.LibaryBooks.OrderBy(o => o.Title).ToArray())
|
||||
{
|
||||
message += Messages.FormatBookEntry(libaryBook.Title, libaryBook.Author, libaryBook.Id);
|
||||
}
|
||||
message += Messages.BackToMap;
|
||||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string BuildHorseReleased()
|
||||
{
|
||||
|
|
|
@ -525,6 +525,17 @@ namespace HISP.Server
|
|||
Vet vet = new Vet(id, cost);
|
||||
Logger.DebugPrint("Registered Vet: " + vet.Id + " selling at: " + vet.PriceMultiplier);
|
||||
}
|
||||
int totalBooks = gameData.books.Count;
|
||||
for (int i = 0; i < totalBooks; i++)
|
||||
{
|
||||
int id = gameData.books[i].id;
|
||||
string author = gameData.books[i].author;
|
||||
string title = gameData.books[i].title;
|
||||
string text = gameData.books[i].text;
|
||||
Book book = new Book(id, title, author, text);
|
||||
Logger.DebugPrint("Registered Libary Book: " + book.Id + " " + book.Title + " by " + book.Author);
|
||||
|
||||
}
|
||||
HorseInfo.HorseNames = gameData.horses.names.ToObject<string[]>();
|
||||
|
||||
Item.Present = gameData.item.special.present;
|
||||
|
@ -602,6 +613,11 @@ namespace HISP.Server
|
|||
Messages.StatMiscNoneRecorded = gameData.messages.meta.misc_stats.no_stats_recorded;
|
||||
Messages.StatMiscEntryFormat = gameData.messages.meta.misc_stats.stat_format;
|
||||
|
||||
// Books (Libary)
|
||||
Messages.BooksOfHorseIsle = gameData.messages.meta.libary.books.books_of_horseisle;
|
||||
Messages.BookEntryFormat = gameData.messages.meta.libary.books.book_entry;
|
||||
Messages.BookReadFormat = gameData.messages.meta.libary.books.book_read;
|
||||
|
||||
// Awards (Libary)
|
||||
Messages.AwardsAvalible = gameData.messages.meta.libary.awards.all_earnable_awards;
|
||||
Messages.AwardEntryFormat = gameData.messages.meta.libary.awards.award_entry;
|
||||
|
|
|
@ -1370,6 +1370,11 @@ namespace HISP.Server
|
|||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAllStats(sender.LoggedinUser));
|
||||
sender.SendPacket(metaPacket);
|
||||
break;
|
||||
case "38":
|
||||
sender.LoggedinUser.MetaPriority = true;
|
||||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildBooksLibary());
|
||||
sender.SendPacket(metaPacket);
|
||||
break;
|
||||
case "53": // Misc Stats / Tracked Items
|
||||
sender.LoggedinUser.MetaPriority = true;
|
||||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildMiscStats(sender.LoggedinUser));
|
||||
|
@ -1405,6 +1410,33 @@ namespace HISP.Server
|
|||
break;
|
||||
|
||||
default:
|
||||
if(buttonIdStr.StartsWith("39c")) // Book Read
|
||||
{
|
||||
string idStr = buttonIdStr.Substring(3);
|
||||
int bookId = -1;
|
||||
try
|
||||
{
|
||||
bookId = int.Parse(idStr);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
Logger.DebugPrint(sender.LoggedinUser.Username + " Tried to read a book of id NaN");
|
||||
break;
|
||||
};
|
||||
|
||||
if(Book.BookExists(bookId))
|
||||
{
|
||||
Book book = Book.GetBookById(bookId);
|
||||
sender.LoggedinUser.MetaPriority = true;
|
||||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildBookReadLibary(book));
|
||||
sender.SendPacket(metaPacket);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.HackerPrint(sender.LoggedinUser.Username + "Tried to read a book that doesnt exist.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(buttonIdStr.StartsWith("32c")) // Horse Whisperer
|
||||
{
|
||||
string idStr = buttonIdStr.Substring(3);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue