diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index a746fd8..f800cb7 100755 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -225,7 +225,7 @@ "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%!" + "sold_offline":"You sold your horse %HORSE% for $%PRICE% to %USERNAME%!" }, "two_player":{ "other_player":"^LThe following other players are in the game room:^R1", diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs index e96c59f..a64f5bb 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs @@ -22,6 +22,14 @@ namespace HISP.Game public static string AddBuddyYourNowBuddiesFormat; public static string AddBuddyDeleteBuddyFormat; + // Auto Sell + public static string AutoSellNotStandingInSamePlace; + public static string AutoSellSuccessFormat; + public static string AutoSellInsufficentFunds; + public static string AutoSellTooManyHorses; + public static string AutoSellYouSoldHorseFormat; + public static string AutoSellYouSoldHorseOfflineFormat; + // Tag public static string TagYourItFormat; public static string TagOtherBuddiesOnlineFormat; @@ -1069,6 +1077,23 @@ namespace HISP.Game // Click public static string NothingInterestingHere; + // AUTO SELL + + public static string FormatAutoSellSoldOffline(string horseName, int price, string toUsername) + { + return AutoSellYouSoldHorseOfflineFormat.Replace("%HORSE%", horseName).Replace("%PRICE%", price.ToString("N0", CultureInfo.InvariantCulture)).Replace("%USERNAME%", toUsername); + } + + public static string FormatAutoSellSold(string horseName, int price, string toUsername) + { + return AutoSellYouSoldHorseFormat.Replace("%HORSE%", horseName).Replace("%PRICE%", price.ToString("N0", CultureInfo.InvariantCulture)).Replace("%USERNAME%", toUsername); + } + + public static string FormatAutoSellSuccess(string horseName) + { + return AutoSellSuccessFormat.Replace("%HORSENAME%", horseName); + } + // MULTIHORSES public static string FormatMultiHorses(int placing, string horseName, string horseBreed, string swf) { diff --git a/Horse Isle Server/HorseIsleServer/Player/User.cs b/Horse Isle Server/HorseIsleServer/Player/User.cs index 0f725be..898ab68 100755 --- a/Horse Isle Server/HorseIsleServer/Player/User.cs +++ b/Horse Isle Server/HorseIsleServer/Player/User.cs @@ -88,6 +88,7 @@ namespace HISP.Player public Inn LastVisitedInn; public HorseInventory HorseInventory; public HorseInstance LastViewedHorse; + public HorseInstance LastViewedHorseOther; public int LastRiddenHorse = 0; public HorseInstance CurrentlyRidingHorse; public Tracking TrackedItems; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs index d24f9b6..016e59f 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs @@ -834,7 +834,14 @@ namespace HISP.Server Map.NewUserStartX = gameData.messages.new_user.starting_x; Map.NewUserStartY = gameData.messages.new_user.starting_y; - + // Auto Sell + Messages.AutoSellNotStandingInSamePlace = gameData.messages.meta.auto_sell.not_standing_sameplace; + Messages.AutoSellSuccessFormat = gameData.messages.meta.auto_sell.success; + Messages.AutoSellInsufficentFunds = gameData.messages.meta.auto_sell.insufficent_money; + Messages.AutoSellTooManyHorses = gameData.messages.meta.auto_sell.toomany_horses; + Messages.AutoSellYouSoldHorseFormat = gameData.messages.meta.auto_sell.you_sold; + Messages.AutoSellYouSoldHorseOfflineFormat = gameData.messages.meta.auto_sell.sold_offline; + // Warp Command Messages.SuccessfullyWarpedToPlayer = gameData.messages.commands.warp.player; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs index 59997d1..2f75b02 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs @@ -2680,6 +2680,85 @@ namespace HISP.Server metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAwardsLibary()); sender.SendPacket(metaPacket); break; + case "26": // Buy Horse (Auto Sell) + if(sender.LoggedinUser.LastViewedHorseOther != null) + { + bool isOnRanch = false; + bool isOnPlayer = false; + HorseInstance horseToSell = sender.LoggedinUser.LastViewedHorseOther; + if (Ranch.IsRanchOwned(horseToSell.Owner)) + { + Ranch ranch = Ranch.GetRanchOwnedBy(horseToSell.Owner); + if(sender.LoggedinUser.X == ranch.X && sender.LoggedinUser.Y == ranch.Y) + { + isOnRanch = true; + } + + } + if(GameServer.IsUserOnline(horseToSell.Owner)) + { + User user = GameServer.GetUserById(horseToSell.Owner); + if (user.X == sender.LoggedinUser.X && user.Y == sender.LoggedinUser.Y) + { + isOnPlayer = true; + } + } + + if (isOnRanch || isOnPlayer) + { + + if (horseToSell.AutoSell == 0) + break; + if(sender.LoggedinUser.Money >= horseToSell.AutoSell) + { + if (sender.LoggedinUser.HorseInventory.HorseList.Length + 1 > sender.LoggedinUser.MaxHorses) + { + byte[] tooManyHorses = PacketBuilder.CreateChat(Messages.AutoSellTooManyHorses, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(tooManyHorses); + break; + } + + if(IsUserOnline(horseToSell.Owner)) + { + User seller = GetUserById(horseToSell.Owner); + seller.HorseInventory.DeleteHorse(horseToSell, false); + + byte[] horseBrought = PacketBuilder.CreateChat(Messages.FormatAutoSellSold(horseToSell.Name, horseToSell.AutoSell, sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT); + seller.LoggedinClient.SendPacket(horseBrought); + } + else + { + Database.AddMessageToQueue(horseToSell.Owner, Messages.FormatAutoSellSoldOffline(horseToSell.Name, horseToSell.AutoSell, sender.LoggedinUser.Username)); + } + + horseToSell.Owner = sender.LoggedinUser.Id; + horseToSell.AutoSell = 0; + sender.LoggedinUser.HorseInventory.AddHorse(horseToSell, false); + + byte[] success = PacketBuilder.CreateChat(Messages.FormatAutoSellSuccess(horseToSell.Name), PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(success); + + UpdateArea(sender); + break; + } + else + { + byte[] noMoney = PacketBuilder.CreateChat(Messages.AutoSellInsufficentFunds, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(noMoney); + break; + } + + } + else + { + byte[] notInRightPlace = PacketBuilder.CreateChat(Messages.AutoSellNotStandingInSamePlace, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(notInRightPlace); + break; + } + + + } + break; case "24": // Award List sender.LoggedinUser.MetaPriority = true; metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAwardList(sender.LoggedinUser)); @@ -6882,9 +6961,11 @@ namespace HISP.Server { int TileID = Map.GetTileId(forClient.LoggedinUser.X, forClient.LoggedinUser.Y, false); string type = Map.TerrainTiles[TileID - 1].Type; - - if(horseInst.Owner == forClient.LoggedinUser.Id) + + if (horseInst.Owner == forClient.LoggedinUser.Id) forClient.LoggedinUser.LastViewedHorse = horseInst; + else + forClient.LoggedinUser.LastViewedHorseOther = horseInst; forClient.LoggedinUser.MetaPriority = true; byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildHorseInformation(horseInst, forClient.LoggedinUser));