mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-08 22:25:42 +12:00
Add basic sell functionlaity on serverside.
This commit is contained in:
parent
d0393f84c2
commit
68975171bb
7 changed files with 69 additions and 8 deletions
|
@ -19,7 +19,9 @@
|
||||||
"cant_afford_5":"You cannot afford 5 of that item!",
|
"cant_afford_5":"You cannot afford 5 of that item!",
|
||||||
"cant_afford_25":"You cannot afford 25 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_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":{
|
"tools":{
|
||||||
"binoculars":"You search high and low all around, but find nothing interesting.",
|
"binoculars":"You search high and low all around, but find nothing interesting.",
|
||||||
|
|
|
@ -105,6 +105,8 @@ namespace HISP.Game
|
||||||
public static string Brought1ButInventoryFull;
|
public static string Brought1ButInventoryFull;
|
||||||
public static string Brought5;
|
public static string Brought5;
|
||||||
public static string Brought25;
|
public static string Brought25;
|
||||||
|
public static string Sold1Format;
|
||||||
|
public static string SoldAllFormat;
|
||||||
|
|
||||||
// Npc
|
// Npc
|
||||||
public static string NpcStartChatFormat;
|
public static string NpcStartChatFormat;
|
||||||
|
@ -147,6 +149,10 @@ namespace HISP.Game
|
||||||
public static string BallonCutscene;
|
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)
|
public static string FormatBuyMessage(string itemName, int price)
|
||||||
{
|
{
|
||||||
return Brought1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
|
return Brought1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
<Compile Include="Server\Converters.cs" />
|
<Compile Include="Server\Converters.cs" />
|
||||||
<Compile Include="Server\Database.cs" />
|
<Compile Include="Server\Database.cs" />
|
||||||
<Compile Include="Player\Friends.cs" />
|
<Compile Include="Player\Friends.cs" />
|
||||||
<Compile Include="Server\Gamedata.cs" />
|
<Compile Include="Server\GameDataJson.cs" />
|
||||||
<Compile Include="Game\Inventory\IInventory.cs" />
|
<Compile Include="Game\Inventory\IInventory.cs" />
|
||||||
<Compile Include="Game\DroppedItems.cs" />
|
<Compile Include="Game\DroppedItems.cs" />
|
||||||
<Compile Include="Game\ItemInstance.cs" />
|
<Compile Include="Game\ItemInstance.cs" />
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace HISP
|
||||||
CrossDomainPolicy.GetPolicy();
|
CrossDomainPolicy.GetPolicy();
|
||||||
Database.OpenDatabase();
|
Database.OpenDatabase();
|
||||||
Map.OpenMap();
|
Map.OpenMap();
|
||||||
Gamedata.ReadGamedata();
|
GameDataJson.ReadGamedata();
|
||||||
World.ReadWorldData();
|
World.ReadWorldData();
|
||||||
DroppedItems.Init();
|
DroppedItems.Init();
|
||||||
GameServer.StartServer();
|
GameServer.StartServer();
|
||||||
|
|
|
@ -5,7 +5,7 @@ using HISP.Game;
|
||||||
|
|
||||||
namespace HISP.Server
|
namespace HISP.Server
|
||||||
{
|
{
|
||||||
class Gamedata
|
class GameDataJson
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void ReadGamedata()
|
public static void ReadGamedata()
|
||||||
|
@ -440,6 +440,8 @@ namespace HISP.Server
|
||||||
Messages.CantAfford5 = gameData.messages.shop.cant_afford_5;
|
Messages.CantAfford5 = gameData.messages.shop.cant_afford_5;
|
||||||
Messages.CantAfford25 = gameData.messages.shop.cant_afford_25;
|
Messages.CantAfford25 = gameData.messages.shop.cant_afford_25;
|
||||||
Messages.Brought1Format = gameData.messages.shop.brought_1;
|
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;
|
Messages.Brought1ButInventoryFull = gameData.messages.shop.brought_1_but_inv_full;
|
||||||
|
|
|
@ -690,10 +690,60 @@ namespace HISP.Server
|
||||||
sender.SendPacket(ChatPacket);
|
sender.SendPacket(ChatPacket);
|
||||||
}
|
}
|
||||||
break;
|
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.
|
case PacketBuilder.ITEM_BUY: // Handles buying an item.
|
||||||
packetStr = Encoding.UTF8.GetString(packet);
|
packetStr = Encoding.UTF8.GetString(packet);
|
||||||
string itemIdStr = packetStr.Substring(2, packet.Length - 2);
|
string itemIdStr = packetStr.Substring(2, packet.Length - 2);
|
||||||
int itemId = 0;
|
itemId = 0;
|
||||||
// Prevent crashing on non-int string.
|
// Prevent crashing on non-int string.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -705,8 +755,8 @@ namespace HISP.Server
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.ItemInformation itemInfo = Item.GetItemById(itemId);
|
itemInfo = Item.GetItemById(itemId);
|
||||||
Shop shop = sender.LoggedinUser.LastShoppedAt;
|
shop = sender.LoggedinUser.LastShoppedAt;
|
||||||
if(shop != null)
|
if(shop != null)
|
||||||
{
|
{
|
||||||
int buyCost = shop.CalculateBuyCost(itemInfo);
|
int buyCost = shop.CalculateBuyCost(itemInfo);
|
||||||
|
@ -716,9 +766,9 @@ namespace HISP.Server
|
||||||
sender.SendPacket(cantAffordMessage);
|
sender.SendPacket(cantAffordMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sender.LoggedinUser.Money -= buyCost;
|
|
||||||
if (shop.Inventory.HasItemId(itemId))
|
if (shop.Inventory.HasItemId(itemId))
|
||||||
{
|
{
|
||||||
|
sender.LoggedinUser.Money -= buyCost;
|
||||||
ItemInstance itemInstance = shop.Inventory.GetItemByItemId(itemId).ItemInstances[0];
|
ItemInstance itemInstance = shop.Inventory.GetItemByItemId(itemId).ItemInstances[0];
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -68,6 +68,7 @@ namespace HISP.Server
|
||||||
public const byte ITEM_DROP = 0x1E;
|
public const byte ITEM_DROP = 0x1E;
|
||||||
public const byte ITEM_PICKUP = 0x14;
|
public const byte ITEM_PICKUP = 0x14;
|
||||||
public const byte ITEM_BUY = 0x33;
|
public const byte ITEM_BUY = 0x33;
|
||||||
|
public const byte ITEM_SELL = 0x3C;
|
||||||
public const byte ITEM_BINOCULARS = 0x5C;
|
public const byte ITEM_BINOCULARS = 0x5C;
|
||||||
public const byte ITEM_MAGNIFYING = 0x5D;
|
public const byte ITEM_MAGNIFYING = 0x5D;
|
||||||
public const byte ITEM_RAKE = 0x5B;
|
public const byte ITEM_RAKE = 0x5B;
|
||||||
|
|
Loading…
Add table
Reference in a new issue