From 770f078992a233ed6b95c7a2a28ae768ca9899ba Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Sat, 20 Mar 2021 16:48:44 +1300 Subject: [PATCH] start work on auto sell --- DataCollection/gamedata.json | 13 ++-- .../HorseIsleServer/Game/Messages.cs | 8 +++ .../HorseIsleServer/Game/Meta.cs | 6 ++ .../HorseIsleServer/Server/Database.cs | 59 +++++++++++++++++++ .../HorseIsleServer/Server/GameDataJson.cs | 3 + .../HorseIsleServer/Server/GameServer.cs | 9 +++ 6 files changed, 94 insertions(+), 4 deletions(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index b6ebf7a..a746fd8 100755 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -60,6 +60,7 @@ "player_here":"%USERNAME% here", "no_telescope":"You do not have a telescope to use! You try making circles with your hands and placing them in front of one eye, but it is of minimal aid...", "starved_horse":"You have been sent to Prison Isle for starving one of your horses! They have been fed for you.", + "message_queue":"OFFLINE MESSAGE:", "events":{ "real_time_riddle":{ "event_start":"CHAT RIDDLE: %RIDDLETEXT% (answer first via any chat method)", @@ -218,6 +219,14 @@ "password_input":"
^PLReply:|^PS14|ANSWER^R1", "last_poet":"^LLast Player Poet:%USERNAME% ^R1", "hammock":"You and all of your horses have fully rested.", + "auto_sell":{ + "not_standing_sameplace":"You must be at the same place as the seller or at their ranch.", + "success":"Horse %HORSENAME% Purchase Completed!", + "insufficent_money":"You cannot afford that horse!", + "toomany_horses":"You do not have any room for another horse. Barns on your ranch allow for more horses.", + "you_sold":"AUTO-SELL: You sold your horse %HORSE% for %PRICE% to %USERNAME%!", + "brought_offline":"You sold your horse %HORSE% for $%PRICE% to %USERNAME%!" + }, "two_player":{ "other_player":"^LThe following other players are in the game room:^R1", "player_name":"^T3%PLAYERNAME%", @@ -685,10 +694,6 @@ "llama_bucked":"Your inexperienced llama has become tired and lain down! (Llama gained 1exp)", "camel_bucked":"Your inexperienced camel got frustrated and spat angrily, bumping you off! (Camel gained 1exp)", - "auto_sell_success":"Horse %HORSENAME% Purchase Completed!", - "auto_sell_insufficent_money":"You cannot afford that horse!", - "auto_sell_toomany_horses":"You do not have any room for another horse. Barns on your ranch allow for more horses.", - "uniter_time_over":"The %HOSRENAME%' time with you has ended. You were taken back to the Uniter.", "allstats":{ "all_stats_header":"All of your horses' complete stats:", diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs index ceff899..e96c59f 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs @@ -10,6 +10,9 @@ namespace HISP.Game { public static int RequiredChatViolations; + // Message Queue + public static string MessageQueueHeader; + // Mod isle public static string ModIsleMessage; @@ -677,6 +680,7 @@ namespace HISP.Game public static string HorseProfileButtonFormat; public static string HorseNoAutoSell; + public static string HorseAutoSellOthersFormat; public static string HorseAutoSellFormat; public static string HorseAutoSellPriceFormat; public static string HorseCantAutoSellTacked; @@ -1994,6 +1998,10 @@ namespace HISP.Game { return HorseAutoSellPriceFormat.Replace("%MONEY%", money.ToString("N0", CultureInfo.InvariantCulture)); } + public static string FormatAutoSellOthers(int price) + { + return HorseAutoSellOthersFormat.Replace("%PRICE%", price.ToString("N0", CultureInfo.InvariantCulture)); + } public static string FormatAutoSell(string autoSellStr) { return HorseAutoSellFormat.Replace("%AUTOSELL%", autoSellStr); diff --git a/Horse Isle Server/HorseIsleServer/Game/Meta.cs b/Horse Isle Server/HorseIsleServer/Game/Meta.cs index 7617d19..8d9470a 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Meta.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Meta.cs @@ -2325,10 +2325,16 @@ namespace HISP.Game message += Messages.R1; } } + else + { + if (horse.AutoSell > 0) + message += Messages.FormatAutoSellOthers(horse.AutoSell); + } if (horse.Leaser == 0) { + if (isMyHorse) message += Messages.FormatHorseCategory(horse.Category, Messages.HorseMarkAsCategory); else diff --git a/Horse Isle Server/HorseIsleServer/Server/Database.cs b/Horse Isle Server/HorseIsleServer/Server/Database.cs index f629d7c..8be74a2 100755 --- a/Horse Isle Server/HorseIsleServer/Server/Database.cs +++ b/Horse Isle Server/HorseIsleServer/Server/Database.cs @@ -26,6 +26,7 @@ namespace HISP.Server string ExtTable = "CREATE TABLE IF NOT EXISTS UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(1028),IpAddress TEXT(1028),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)"; string MailTable = "CREATE TABLE IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(128), Message Text(1028), TimeSent INT, BeenRead TEXT(3))"; string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT)"; + string MessageQueue = "CREATE TABLE IF NOT EXISTS MessageQueue(Id INT, Message TEXT(1028))"; string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT, StartTime INT)"; string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))"; string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)"; @@ -56,6 +57,17 @@ namespace HISP.Server string SolvedRealTimeRiddle = "CREATE TABLE IF NOT EXISTS SolvedRealTimeRiddles(playerId INT, riddleId INT)"; string DeleteOnlineUsers = "DELETE FROM OnlineUsers"; + try + { + MySqlCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = MessageQueue; + sqlCommand.ExecuteNonQuery(); + sqlCommand.Dispose(); + } + catch (Exception e) + { + Logger.WarnPrint(e.Message); + }; try { @@ -543,6 +555,53 @@ namespace HISP.Server } } + public static void AddMessageToQueue(int userId, string message) + { + using (MySqlConnection db = new MySqlConnection(ConnectionString)) + { + db.Open(); + MySqlCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "INSERT INTO MessageQueue VALUES(@id,@message)"; + sqlCommand.Parameters.AddWithValue("@id", userId); + sqlCommand.Parameters.AddWithValue("@message", message); + sqlCommand.Prepare(); + sqlCommand.ExecuteNonQuery(); + sqlCommand.Dispose(); + } + } + public static void ClearMessageQueue(int userId) + { + using (MySqlConnection db = new MySqlConnection(ConnectionString)) + { + db.Open(); + MySqlCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "DELETE FROM MessageQueue WHERE Id=@id"; + sqlCommand.Parameters.AddWithValue("@id", userId); + sqlCommand.Prepare(); + sqlCommand.ExecuteNonQuery(); + sqlCommand.Dispose(); + } + } + public static string[] GetMessageQueue(int userId) + { + List msgQueue = new List(); + using (MySqlConnection db = new MySqlConnection(ConnectionString)) + { + db.Open(); + MySqlCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "SELECT message FROM MessageQueue WHERE Id=@id"; + sqlCommand.Parameters.AddWithValue("@id", userId); + sqlCommand.Prepare(); + MySqlDataReader reader = sqlCommand.ExecuteReader(); + while(reader.Read()) + { + msgQueue.Add(reader.GetString(0)); + } + sqlCommand.Dispose(); + } + return msgQueue.ToArray(); + } + public static void SetDressupRoomPeiceX(int roomId, int peiceId, int newX) { using (MySqlConnection db = new MySqlConnection(ConnectionString)) diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs index 9541327..d24f9b6 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs @@ -867,6 +867,8 @@ namespace HISP.Server Messages.SocialTypeFormat = gameData.messages.meta.player_interaction.socials.socials_menu_type; Messages.SocialPlayerNoLongerNearby = gameData.messages.meta.player_interaction.socials.no_longer_nearby; + // Message Queue + Messages.MessageQueueHeader = gameData.messages.message_queue; // Events : Real Time Riddle @@ -1512,6 +1514,7 @@ namespace HISP.Server Messages.HorseNoAutoSell = gameData.messages.meta.horse.horse_inventory.no_auto_sell; Messages.HorseAutoSellPriceFormat = gameData.messages.meta.horse.horse_inventory.auto_sell_format; + Messages.HorseAutoSellOthersFormat = gameData.messages.meta.horse.horse_inventory.auto_sell_others; Messages.HorseAutoSellFormat = gameData.messages.meta.horse.horse_inventory.auto_sell; Messages.HorseCantAutoSellTacked = gameData.messages.meta.horse.horse_inventory.cannot_auto_sell_tacked; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs index 6421ef3..59997d1 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs @@ -3286,6 +3286,15 @@ namespace HISP.Server byte[] MotdData = PacketBuilder.CreateMotd(); sender.SendPacket(MotdData); + // Send Queued Messages + string[] queuedMessages = Database.GetMessageQueue(sender.LoggedinUser.Id); + foreach(string queuedMessage in queuedMessages) + { + byte[] msg = PacketBuilder.CreateChat(Messages.MessageQueueHeader+queuedMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(msg); + } + Database.ClearMessageQueue(sender.LoggedinUser.Id); + } public static void OnSwfModuleCommunication(GameClient sender, byte[] packet)