From 7500dc0230e0979afcf4fe0e5d2a984f33738cb6 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Wed, 13 Jan 2021 22:14:13 +1300 Subject: [PATCH] implement pet function --- DataCollection/gamedata.json | 2 + .../Horse Isle Server/Game/Messages.cs | 12 +++++ .../Horse Isle Server/Game/Meta.cs | 4 +- .../Horse Isle Server/Server/GameDataJson.cs | 3 ++ .../Horse Isle Server/Server/GameServer.cs | 51 ++++++++++++++++++- .../Horse Isle Server/Server/PacketBuilder.cs | 1 + 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index 0f5b4fb..6313f7e 100644 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -151,6 +151,8 @@ "stop_riding_message":"You are now not riding a horse!", "unequip_tack_message":"You removed the tack off %HORSENAME%.", "back_to_horse":"^R1^D5|BACK TO HORSE^R1", + "pet_horse":"Your horse whinnies lightly. (+%MOOD% mood / -%TIREDNESS% tiredness)", + "pet_horse_too_happy":"Your horse is as happy as it can be now. Your horse whinnies lightly. (+%MOOD% mood / -%TIREDNESS% tiredness)", "feed_horse":{ "horse_neigh":"Your horse neighs a thank you!", "horse_could_not_finish":"The horse could not finish it all. Some was wasted.", diff --git a/Horse Isle Server/Horse Isle Server/Game/Messages.cs b/Horse Isle Server/Horse Isle Server/Game/Messages.cs index d19c72b..ac9d9b7 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Messages.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Messages.cs @@ -217,6 +217,9 @@ namespace HISP.Game public static string HorseUnEquipTackMessageFormat; public static string HorseStopRidingMessage; + public static string HorsePetMessageFormat; + public static string HorsePetTooHappyFormat; + // Horse Feed Menu public static string HorseCurrentStatusFormat; @@ -426,6 +429,15 @@ namespace HISP.Game // Click public static string NothingInterestingHere; + public static string FormatHorsePetMessage(int mood, int tiredness) + { + return HorsePetMessageFormat.Replace("%MOOD%", mood.ToString()).Replace("%TIREDNESS%", tiredness.ToString()); + } + public static string FormatHorsePetTooHappyMessage(int mood, int tiredness) + { + return HorsePetTooHappyFormat.Replace("%MOOD%", mood.ToString()).Replace("%TIREDNESS%", tiredness.ToString()); + } + public static string FormatHorseCurrentStatus(string name) { return HorseCurrentStatusFormat.Replace("%HORSENAME%", name); diff --git a/Horse Isle Server/Horse Isle Server/Game/Meta.cs b/Horse Isle Server/Horse Isle Server/Game/Meta.cs index f6aa668..c9691f1 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Meta.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Meta.cs @@ -975,7 +975,7 @@ namespace HISP.Game { string message = ""; message += Messages.FormatHorseCurrentStatus(horse.Name); - message += Messages.FormatHorseBasicStat(horse.BasicStats.Health, horse.BasicStats.Hunger, horse.BasicStats.Thirst, horse.BasicStats.Mood, 1000, horse.BasicStats.Groom, horse.BasicStats.Groom); + message += Messages.FormatHorseBasicStat(horse.BasicStats.Health, horse.BasicStats.Hunger, horse.BasicStats.Thirst, horse.BasicStats.Mood, horse.BasicStats.Tiredness, horse.BasicStats.Groom, horse.BasicStats.Groom); message += Messages.HorseHoldingHorseFeed; foreach(InventoryItem item in user.Inventory.GetItemList()) { @@ -1022,7 +1022,7 @@ namespace HISP.Game message += Messages.HorseStats; // What is energy? - message += Messages.FormatHorseBasicStat(horse.BasicStats.Health, horse.BasicStats.Hunger, horse.BasicStats.Thirst, horse.BasicStats.Mood, 1000, horse.BasicStats.Groom, horse.BasicStats.Groom); + message += Messages.FormatHorseBasicStat(horse.BasicStats.Health, horse.BasicStats.Hunger, horse.BasicStats.Thirst, horse.BasicStats.Mood, horse.BasicStats.Tiredness, horse.BasicStats.Groom, horse.BasicStats.Groom); message += Messages.HorseTacked; if (horse.Equipment.Saddle != null) diff --git a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs index 450c0b5..92401e5 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs @@ -652,6 +652,9 @@ namespace HISP.Server Messages.HorseUnEquipTackMessageFormat = gameData.messages.meta.horse.unequip_tack_message; Messages.HorseStopRidingMessage = gameData.messages.meta.horse.stop_riding_message; + Messages.HorsePetMessageFormat = gameData.messages.meta.horse.pet_horse; + Messages.HorsePetTooHappyFormat = gameData.messages.meta.horse.pet_horse_too_happy; + // Horse Feed Menu Messages.HorseCurrentStatusFormat = gameData.messages.meta.horse.feed_horse.current_status; Messages.HorseHoldingHorseFeed = gameData.messages.meta.horse.feed_horse.holding_horse_feed; diff --git a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs index c43ae4f..cb14d62 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs @@ -130,7 +130,56 @@ namespace HISP.Server } else { - Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to tack at a non existant horse."); + Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to feed at a non existant horse."); + break; + } + case PacketBuilder.HORSE_PET: + randomId = 0; + packetStr = Encoding.UTF8.GetString(packet); + randomIdStr = packetStr.Substring(2, packetStr.Length - 4); + try + { + randomId = int.Parse(randomIdStr); + + } + catch (Exception) + { + Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid randomid to horse interaction packet "); + break; + } + if (sender.LoggedinUser.HorseInventory.HorseIdExist(randomId)) + { + HorseInstance horseInst = sender.LoggedinUser.HorseInventory.GetHorseById(randomId); + sender.LoggedinUser.LastViewedHorse = horseInst; + int randMoodAddition = RandomNumberGenerator.Next(0, 20); + int randTiredMinus = RandomNumberGenerator.Next(0, 10); + horseInst.BasicStats.Tiredness -= randTiredMinus; + horseInst.BasicStats.Mood += randMoodAddition; + + + string message = ""; + if(horseInst.BasicStats.Mood < 1000) + { + horseInst.BasicStats.Mood = 1000; + message = Messages.FormatHorsePetMessage(randMoodAddition, randTiredMinus); + } + else + message = Messages.FormatHorsePetTooHappyMessage(randMoodAddition, randTiredMinus); + + if (horseInst.BasicStats.Tiredness < 0) + horseInst.BasicStats.Tiredness = 0; + + Database.SetHorseTiredness(horseInst.RandomId, horseInst.BasicStats.Tiredness); + Database.SetHorseMood(horseInst.RandomId, horseInst.BasicStats.Mood); + + byte[] petMessagePacket = PacketBuilder.CreateChat(message, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(petMessagePacket); + + break; + } + else + { + Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to feed at a non existant horse."); break; } case PacketBuilder.HORSE_GIVE_FEED: diff --git a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs index 47e412b..d167691 100644 --- a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs +++ b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs @@ -49,6 +49,7 @@ namespace HISP.Server public const byte HORSE_LIST = 0x0A; public const byte HORSE_LOOK = 0x14; public const byte HORSE_FEED = 0x15; + public const byte HORSE_PET = 0x18; public const byte HORSE_TRY_CAPTURE = 0x1C; public const byte HORSE_TACK = 0x16; public const byte HORSE_GIVE_FEED = 0x1B;