diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json
index 435cf88..a6548d6 100644
--- a/DataCollection/gamedata.json
+++ b/DataCollection/gamedata.json
@@ -19,7 +19,9 @@
"cant_afford_5":"You cannot afford 5 of that item!",
"cant_afford_25":"You cannot afford 25 of that item!",
"brought_1_but_inv_full":"Your inventory is full! Cannot buy that item.",
- "brought_1":"You bought a %ITEM% for $%PRICE%."
+ "brought_1":"You bought a %ITEM% for $%PRICE%.",
+ "sold_1":"You sold a %ITEM% for $%PRICE%.",
+ "sold_all":"You sold %AMOUNT% %ITEM% for $%PRICE%."
},
"tools":{
"binoculars":"You search high and low all around, but find nothing interesting.",
diff --git a/Horse Isle Server/Horse Isle Server/Game/Messages.cs b/Horse Isle Server/Horse Isle Server/Game/Messages.cs
index 3cc1c45..9cd4610 100644
--- a/Horse Isle Server/Horse Isle Server/Game/Messages.cs
+++ b/Horse Isle Server/Horse Isle Server/Game/Messages.cs
@@ -105,6 +105,8 @@ namespace HISP.Game
public static string Brought1ButInventoryFull;
public static string Brought5;
public static string Brought25;
+ public static string Sold1Format;
+ public static string SoldAllFormat;
// Npc
public static string NpcStartChatFormat;
@@ -147,6 +149,10 @@ namespace HISP.Game
public static string BallonCutscene;
+ public static string FormatSellMessage(string itemName, int price)
+ {
+ return Sold1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
+ }
public static string FormatBuyMessage(string itemName, int price)
{
return Brought1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
diff --git a/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj b/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj
index 2be96f4..b59d322 100644
--- a/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj
+++ b/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj
@@ -88,7 +88,7 @@
-
+
diff --git a/Horse Isle Server/Horse Isle Server/Program.cs b/Horse Isle Server/Horse Isle Server/Program.cs
index 245ff6b..37e9f10 100644
--- a/Horse Isle Server/Horse Isle Server/Program.cs
+++ b/Horse Isle Server/Horse Isle Server/Program.cs
@@ -18,7 +18,7 @@ namespace HISP
CrossDomainPolicy.GetPolicy();
Database.OpenDatabase();
Map.OpenMap();
- Gamedata.ReadGamedata();
+ GameDataJson.ReadGamedata();
World.ReadWorldData();
DroppedItems.Init();
GameServer.StartServer();
diff --git a/Horse Isle Server/Horse Isle Server/Server/Gamedata.cs b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs
similarity index 99%
rename from Horse Isle Server/Horse Isle Server/Server/Gamedata.cs
rename to Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs
index 01ec2b6..cf6e184 100644
--- a/Horse Isle Server/Horse Isle Server/Server/Gamedata.cs
+++ b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs
@@ -5,7 +5,7 @@ using HISP.Game;
namespace HISP.Server
{
- class Gamedata
+ class GameDataJson
{
public static void ReadGamedata()
@@ -440,6 +440,8 @@ namespace HISP.Server
Messages.CantAfford5 = gameData.messages.shop.cant_afford_5;
Messages.CantAfford25 = gameData.messages.shop.cant_afford_25;
Messages.Brought1Format = gameData.messages.shop.brought_1;
+ Messages.Sold1Format = gameData.messages.shop.sold_1;
+ Messages.SoldAllFormat = gameData.messages.shop.sold_all;
Messages.Brought1ButInventoryFull = gameData.messages.shop.brought_1_but_inv_full;
diff --git a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs
index 7f138c9..9941a76 100644
--- a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs
+++ b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs
@@ -690,10 +690,60 @@ namespace HISP.Server
sender.SendPacket(ChatPacket);
}
break;
+ case PacketBuilder.ITEM_SELL: // Handles selling an item.
+ packetStr = Encoding.UTF8.GetString(packet);
+ randomIdStr = packetStr.Substring(2, packet.Length - 2);
+ randomId = 0;
+ // Prevent crashing on non-int string.
+ try
+ {
+ randomId = Int32.Parse(randomIdStr);
+ }
+ catch (InvalidOperationException)
+ {
+ Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid object buy packet.");
+ return;
+ }
+
+ if(!sender.LoggedinUser.Inventory.HasItem(randomId))
+ {
+ Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to sell a item that they doesnt have in there inventory");
+ return;
+ }
+
+ InventoryItem thisItem = sender.LoggedinUser.Inventory.GetItemByRandomid(randomId);
+ int itemId = thisItem.ItemId;
+
+ Item.ItemInformation itemInfo = Item.GetItemById(itemId);
+ Shop shop = sender.LoggedinUser.LastShoppedAt;
+ if (shop != null)
+ {
+ int sellPrice = shop.CalculateSellCost(itemInfo);
+ if (shop.CanSell(itemInfo))
+ {
+ sender.LoggedinUser.Money += sellPrice;
+
+ ItemInstance itemInstance = thisItem.ItemInstances[0];
+ sender.LoggedinUser.Inventory.Remove(itemInstance);
+ shop.Inventory.Add(itemInstance);
+
+ UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
+
+ // Send chat message to client.
+ byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatSellMessage(itemInfo.Name, sellPrice), PacketBuilder.CHAT_BOTTOM_RIGHT);
+ sender.SendPacket(broughtItemMessage);
+
+ }
+ else
+ {
+ Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to sell a item that was not avalible to be sold.");
+ }
+ }
+ break;
case PacketBuilder.ITEM_BUY: // Handles buying an item.
packetStr = Encoding.UTF8.GetString(packet);
string itemIdStr = packetStr.Substring(2, packet.Length - 2);
- int itemId = 0;
+ itemId = 0;
// Prevent crashing on non-int string.
try
{
@@ -705,8 +755,8 @@ namespace HISP.Server
return;
}
- Item.ItemInformation itemInfo = Item.GetItemById(itemId);
- Shop shop = sender.LoggedinUser.LastShoppedAt;
+ itemInfo = Item.GetItemById(itemId);
+ shop = sender.LoggedinUser.LastShoppedAt;
if(shop != null)
{
int buyCost = shop.CalculateBuyCost(itemInfo);
@@ -716,9 +766,9 @@ namespace HISP.Server
sender.SendPacket(cantAffordMessage);
break;
}
- sender.LoggedinUser.Money -= buyCost;
if (shop.Inventory.HasItemId(itemId))
{
+ sender.LoggedinUser.Money -= buyCost;
ItemInstance itemInstance = shop.Inventory.GetItemByItemId(itemId).ItemInstances[0];
try
diff --git a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs
index 8442402..e81eb02 100644
--- a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs
+++ b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs
@@ -68,6 +68,7 @@ namespace HISP.Server
public const byte ITEM_DROP = 0x1E;
public const byte ITEM_PICKUP = 0x14;
public const byte ITEM_BUY = 0x33;
+ public const byte ITEM_SELL = 0x3C;
public const byte ITEM_BINOCULARS = 0x5C;
public const byte ITEM_MAGNIFYING = 0x5D;
public const byte ITEM_RAKE = 0x5B;