From cb497ef7d29116ae4b5ca5dd6650eb21af123408 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Mon, 4 Jan 2021 15:58:06 +1300 Subject: [PATCH] Allow searching for NPCS. --- DataCollection/gamedata.json | 8 +++ .../Horse Isle Server/Game/Messages.cs | 14 +++++ .../Horse Isle Server/Game/Meta.cs | 60 ++++++++++++++++++- .../Horse Isle Server/Server/GameDataJson.cs | 9 +++ .../Horse Isle Server/Server/GameServer.cs | 35 +++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index 36799b3..9634583 100644 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -130,6 +130,14 @@ "venus_flytrap_format":"The Giant Venus Flytrap chomped at you!
OUCH!!
It chomped your pocket, taking $%MONEY% with it!!", "password_input":"
^PLReply:|^PS14|ANSWER^R1", "last_poet":"^R1^LLast Player Poet:%USERNAME% ^R1", + "libary":{ + "main_menu":"Welcome to the Library! You can research different subjects.
^T2Search Residents: ^D30|SEARCH NPC^R1^T2Search Ranches: ^D31|SEARCH RANCH^R1^T2Research Horses: ^D4|VIEW BREEDS^R1^T2Research Tack: ^D9|VIEW TACK^R1^T2Research Companions: ^D10|VIEW COMPANIONS^R1^T2Research Mini-Games: ^D12|VIEW MINIGAMES^R1^T2Research Locations: ^D22|VIEW LOCATIONS^R1^T2Research Awards: ^D23|VIEW AWARDS^R1^T2Read Books: ^D38|READ BOOKS^R1", + "find_npc":"SEARCH FOR A RESIDENT:
Enter a resident's name below(not players). It will match on partial names.
^PLResident Locator(NPC):|NPC name^PS4|FIND RESIDENTS^R3", + "find_npc_results_header":"The following residents match closely:
", + "find_npc_results_format":"^T7%NPCNAME%^B1M%MAPXY%^R1", + "find_npc_no_results":"The following residents match closely:
None were found by that name, try looking for a partial name.", + "find_npc_limit5":"^L- Limited to 5 results. Try narrowing the search.^R1" + }, "multiroom":{ "other_players_participating":"
^LThe following other players are participating:", "partcipent_format":"^R1^T3%USERNAME%" diff --git a/Horse Isle Server/Horse Isle Server/Game/Messages.cs b/Horse Isle Server/Horse Isle Server/Game/Messages.cs index 3505e5c..73d5bed 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Messages.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Messages.cs @@ -75,7 +75,16 @@ namespace HISP.Game public static string LoginMessageFormat; public static string LogoutMessageFormat; + // Libary + public static string LibaryMainMenu; + public static string LibaryFindNpc; + public static string LibaryFindNpcSearchResultsHeader; + public static string LibaryFindNpcSearchResultFormat; + public static string LibaryFindNpcSearchNoResults; + public static string LibaryFindNpcLimit5; + // Records + public static string ProfileSavedMessage; public static string PrivateNotesSavedMessage; public static string PrivateNotesMetaFormat; @@ -338,6 +347,11 @@ namespace HISP.Game // Click public static string NothingInterestingHere; + public static string FormatNpcSearchResult(string name, int x, int y) + { + string mapXy = FormatMapLocation(x, y); + return LibaryFindNpcSearchResultFormat.Replace("%NPCNAME%", name).Replace("%MAPXY%", mapXy); + } public static string FormatLastPoet(string name) { return LastPoetFormat.Replace("%USERNAME%", name); diff --git a/Horse Isle Server/Horse Isle Server/Game/Meta.cs b/Horse Isle Server/Horse Isle Server/Game/Meta.cs index 1e02750..e9ffad1 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Meta.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Meta.cs @@ -247,7 +247,10 @@ namespace HISP.Game return message; } - + public static string buildLibary() + { + return Messages.LibaryMainMenu + Messages.ExitThisPlace + Messages.MetaTerminator; + } private static string buildNpc(User user, int x, int y) { string message = ""; @@ -617,6 +620,57 @@ namespace HISP.Game return message; } + public static string BuildNpcSearch(string search) + { + List foundNpcs = new List(); + foreach(Npc.NpcEntry npc in Npc.NpcList) + { + if(npc.Name.ToLower().Contains(search.ToLower())) + { + if(npc.LibarySearchable) + { + if (foundNpcs.Count >= 5) + break; + foundNpcs.Add(npc); + } + else + { + continue; + } + } + else + { + continue; + } + } + string message = Messages.LibaryFindNpcSearchNoResults; + if(foundNpcs.Count >= 1) + { + message = Messages.LibaryFindNpcSearchResultsHeader; + foreach(Npc.NpcEntry npc in foundNpcs) + { + string searchResult = Messages.FormatNpcSearchResult(npc.Name, npc.X, npc.Y); + Logger.DebugPrint(searchResult); + message += searchResult; + } + } + if(foundNpcs.Count >= 5) + { + message += Messages.LibaryFindNpcLimit5; + } + + message += Messages.BackToMap; + message += Messages.MetaTerminator; + return message; + + } + public static string BuildFindNpcMenu() + { + string message = Messages.LibaryFindNpc; + message += Messages.BackToMap; + message += Messages.MetaTerminator; + return message; + } private static string buildFountain() { return Messages.FountainMeta; @@ -721,6 +775,10 @@ namespace HISP.Game { message += buildVenusFlyTrap(user); } + if(TileCode == "LIBRARY") + { + message += buildLibary(); + } if(TileCode == "MULTIROOM") { user.MetaPriority = false; // acturally want to track updates here >-< diff --git a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs index 6e75567..10ef3b5 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs @@ -554,6 +554,15 @@ namespace HISP.Server Messages.BankDepositedMoneyFormat = gameData.messages.bank.deposit_format; Messages.BankWithdrewMoneyFormat = gameData.messages.bank.withdraw_format; + + // Libary + Messages.LibaryMainMenu = gameData.messages.meta.libary.main_menu; + Messages.LibaryFindNpc = gameData.messages.meta.libary.find_npc; + Messages.LibaryFindNpcSearchResultsHeader = gameData.messages.meta.libary.find_npc_results_header; + Messages.LibaryFindNpcSearchResultFormat = gameData.messages.meta.libary.find_npc_results_format; + Messages.LibaryFindNpcSearchNoResults = gameData.messages.meta.libary.find_npc_no_results; + Messages.LibaryFindNpcLimit5 = gameData.messages.meta.libary.find_npc_limit5; + // Chat Messages.ChatViolationMessageFormat = gameData.messages.chat.violation_format; diff --git a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs index 298c923..db2c915 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs @@ -148,6 +148,20 @@ namespace HISP.Server Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to send a invalid dynamic input (private notes, wrong size)"); break; } + case 4: // NPC Search + if(dynamicInput.Length >= 2) + { + sender.LoggedinUser.MetaPriority = true; + string metaWindow = Meta.BuildNpcSearch(dynamicInput[1]); + byte[] metaPacket = PacketBuilder.CreateMetaPacket(metaWindow); + sender.SendPacket(metaPacket); + break; + } + else + { + Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to send a invalid dynamic input (NPC Search, wrong size)"); + break; + } case 7: // Private Notes if (dynamicInput.Length >= 2) { @@ -335,6 +349,27 @@ namespace HISP.Server metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildPlayerListAlphabetical()); sender.SendPacket(metaPacket); break; + case "30": // Find NPC + sender.LoggedinUser.MetaPriority = true; + metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildFindNpcMenu()); + sender.SendPacket(metaPacket); + break; + case "31": // Find Ranch + break; + case "4": // View Horse Breed + break; + case "9": // View Tack + break; + case "10": // View Competitions + break; + case "12": // View Miigames + break; + case "22": // View Locations + break; + case "23": // View Awards + break; + case "38": // Read Books + break; case "28c1": sender.LoggedinUser.MetaPriority = true; metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAbuseReportPage());