mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 21:55:42 +12:00
Allow for purchasing multiple items at a time.
This commit is contained in:
parent
68975171bb
commit
979007c5d8
5 changed files with 112 additions and 28 deletions
|
@ -19,7 +19,11 @@
|
||||||
"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_5_but_inv_full":"Your inventory cannot hold 5 more! Cannot buy those items.",
|
||||||
|
"brought_25_but_inv_full":"Your inventory cannot hold 25 more! Cannot buy those items.",
|
||||||
"brought_1":"You bought a %ITEM% for $%PRICE%.",
|
"brought_1":"You bought a %ITEM% for $%PRICE%.",
|
||||||
|
"brought_5":"You bought 5 %ITEM% for $%PRICE%.",
|
||||||
|
"brought_25":"You bought 25 %ITEM% for $%PRICE%.",
|
||||||
"sold_1":"You sold a %ITEM% for $%PRICE%.",
|
"sold_1":"You sold a %ITEM% for $%PRICE%.",
|
||||||
"sold_all":"You sold %AMOUNT% %ITEM% for $%PRICE%."
|
"sold_all":"You sold %AMOUNT% %ITEM% for $%PRICE%."
|
||||||
},
|
},
|
||||||
|
|
|
@ -103,8 +103,10 @@ namespace HISP.Game
|
||||||
public static string CantAfford25;
|
public static string CantAfford25;
|
||||||
public static string Brought1Format;
|
public static string Brought1Format;
|
||||||
public static string Brought1ButInventoryFull;
|
public static string Brought1ButInventoryFull;
|
||||||
public static string Brought5;
|
public static string Brought5ButInventoryFull;
|
||||||
public static string Brought25;
|
public static string Brought25ButInventoryFull;
|
||||||
|
public static string Brought5Format;
|
||||||
|
public static string Brought25Format;
|
||||||
public static string Sold1Format;
|
public static string Sold1Format;
|
||||||
public static string SoldAllFormat;
|
public static string SoldAllFormat;
|
||||||
|
|
||||||
|
@ -153,6 +155,14 @@ namespace HISP.Game
|
||||||
{
|
{
|
||||||
return Sold1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
|
return Sold1Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
|
||||||
}
|
}
|
||||||
|
public static string FormatBuy25Message(string itemName, int price)
|
||||||
|
{
|
||||||
|
return Brought25Format.Replace("%ITEM%", itemName).Replace("%PRICE%", price.ToString());
|
||||||
|
}
|
||||||
|
public static string FormatBuy5Message(string itemName, int price)
|
||||||
|
{
|
||||||
|
return Brought5Format.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());
|
||||||
|
|
|
@ -440,10 +440,14 @@ 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.Brought5Format = gameData.messages.shop.brought_5;
|
||||||
|
Messages.Brought25Format = gameData.messages.shop.brought_25;
|
||||||
Messages.Sold1Format = gameData.messages.shop.sold_1;
|
Messages.Sold1Format = gameData.messages.shop.sold_1;
|
||||||
Messages.SoldAllFormat = gameData.messages.shop.sold_all;
|
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;
|
||||||
|
Messages.Brought5ButInventoryFull = gameData.messages.shop.brought_5_but_inv_full;
|
||||||
|
Messages.Brought25ButInventoryFull = gameData.messages.shop.brought_25_but_inv_full;
|
||||||
|
|
||||||
// Meta Format
|
// Meta Format
|
||||||
|
|
||||||
|
|
|
@ -691,6 +691,7 @@ namespace HISP.Server
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PacketBuilder.ITEM_SELL: // Handles selling an item.
|
case PacketBuilder.ITEM_SELL: // Handles selling an item.
|
||||||
|
int message = 1;
|
||||||
packetStr = Encoding.UTF8.GetString(packet);
|
packetStr = Encoding.UTF8.GetString(packet);
|
||||||
randomIdStr = packetStr.Substring(2, packet.Length - 2);
|
randomIdStr = packetStr.Substring(2, packet.Length - 2);
|
||||||
randomId = 0;
|
randomId = 0;
|
||||||
|
@ -705,7 +706,7 @@ namespace HISP.Server
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sender.LoggedinUser.Inventory.HasItem(randomId))
|
if (!sender.LoggedinUser.Inventory.HasItem(randomId))
|
||||||
{
|
{
|
||||||
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to sell a item that they doesnt have in there inventory");
|
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to sell a item that they doesnt have in there inventory");
|
||||||
return;
|
return;
|
||||||
|
@ -728,10 +729,12 @@ namespace HISP.Server
|
||||||
shop.Inventory.Add(itemInstance);
|
shop.Inventory.Add(itemInstance);
|
||||||
|
|
||||||
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
|
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
|
||||||
|
if (message == 1)
|
||||||
// Send chat message to client.
|
{
|
||||||
byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatSellMessage(itemInfo.Name, sellPrice), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
// Send chat message to client.
|
||||||
sender.SendPacket(broughtItemMessage);
|
byte[] soldItemMessage = PacketBuilder.CreateChat(Messages.FormatSellMessage(itemInfo.Name, sellPrice), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(soldItemMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -741,6 +744,15 @@ namespace HISP.Server
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PacketBuilder.ITEM_BUY: // Handles buying an item.
|
case PacketBuilder.ITEM_BUY: // Handles buying an item.
|
||||||
|
message = 1;
|
||||||
|
int count = 1;
|
||||||
|
goto doPurchase;
|
||||||
|
case PacketBuilder.ITEM_BUY_5:
|
||||||
|
message = 2;
|
||||||
|
count = 5;
|
||||||
|
goto doPurchase;
|
||||||
|
|
||||||
|
doPurchase:;
|
||||||
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);
|
||||||
itemId = 0;
|
itemId = 0;
|
||||||
|
@ -757,37 +769,89 @@ namespace HISP.Server
|
||||||
|
|
||||||
itemInfo = Item.GetItemById(itemId);
|
itemInfo = Item.GetItemById(itemId);
|
||||||
shop = sender.LoggedinUser.LastShoppedAt;
|
shop = sender.LoggedinUser.LastShoppedAt;
|
||||||
if(shop != null)
|
if (shop != null)
|
||||||
{
|
{
|
||||||
int buyCost = shop.CalculateBuyCost(itemInfo);
|
int buyCost = shop.CalculateBuyCost(itemInfo) * count;
|
||||||
if (sender.LoggedinUser.Money < buyCost)
|
if (sender.LoggedinUser.Money < buyCost)
|
||||||
{
|
{
|
||||||
byte[] cantAffordMessage = PacketBuilder.CreateChat(Messages.CantAfford1, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
byte[] cantAffordMessage = PacketBuilder.CreateChat(Messages.CantAfford1, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
sender.SendPacket(cantAffordMessage);
|
sender.SendPacket(cantAffordMessage);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
if (shop.Inventory.HasItemId(itemId))
|
if (shop.Inventory.HasItemId(itemId))
|
||||||
{
|
{
|
||||||
sender.LoggedinUser.Money -= buyCost;
|
if (shop.Inventory.GetItemByItemId(itemId).ItemInstances.Count < count)
|
||||||
ItemInstance itemInstance = shop.Inventory.GetItemByItemId(itemId).ItemInstances[0];
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
sender.LoggedinUser.Inventory.Add(itemInstance);
|
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to buy more of an item than is in stock.");
|
||||||
}
|
|
||||||
catch(InventoryException)
|
|
||||||
{
|
|
||||||
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.Brought1ButInventoryFull, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
|
||||||
sender.SendPacket(inventoryFullMessage);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
shop.Inventory.Remove(itemInstance);
|
|
||||||
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
|
|
||||||
// Send chat message to client.
|
|
||||||
byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatBuyMessage(itemInfo.Name,buyCost), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
|
||||||
sender.SendPacket(broughtItemMessage);
|
|
||||||
|
|
||||||
|
|
||||||
|
if (sender.LoggedinUser.Inventory.HasItemId(itemId))
|
||||||
|
{
|
||||||
|
InventoryItem items = sender.LoggedinUser.Inventory.GetItemByItemId(itemId);
|
||||||
|
if (items.ItemInstances.Count + count > ConfigReader.MAX_STACK || sender.LoggedinUser.Inventory.Count >= Messages.DefaultInventoryMax)
|
||||||
|
{
|
||||||
|
if (message == 1)
|
||||||
|
{
|
||||||
|
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.Brought1ButInventoryFull, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(inventoryFullMessage);
|
||||||
|
}
|
||||||
|
else if (message == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.Brought5ButInventoryFull, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(inventoryFullMessage);
|
||||||
|
}
|
||||||
|
else if (message == 3)
|
||||||
|
{
|
||||||
|
|
||||||
|
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.Brought25ButInventoryFull, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(inventoryFullMessage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
ItemInstance itemInstance = shop.Inventory.GetItemByItemId(itemId).ItemInstances[0];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sender.LoggedinUser.Inventory.Add(itemInstance);
|
||||||
|
}
|
||||||
|
catch (InventoryException)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
shop.Inventory.Remove(itemInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.LoggedinUser.Money -= buyCost;
|
||||||
|
|
||||||
|
|
||||||
|
// Send chat message to client.
|
||||||
|
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
|
||||||
|
if (message == 1)
|
||||||
|
{
|
||||||
|
byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatBuyMessage(itemInfo.Name, buyCost), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(broughtItemMessage);
|
||||||
|
}
|
||||||
|
else if (message == 2)
|
||||||
|
{
|
||||||
|
byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatBuy5Message(itemInfo.PluralName, buyCost), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(broughtItemMessage);
|
||||||
|
}
|
||||||
|
else if (message == 3)
|
||||||
|
{
|
||||||
|
byte[] broughtItemMessage = PacketBuilder.CreateChat(Messages.FormatBuy25Message(itemInfo.PluralName, buyCost), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
sender.SendPacket(broughtItemMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -799,6 +863,7 @@ namespace HISP.Server
|
||||||
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to buy an item while not in a store.");
|
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to buy an item while not in a store.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PacketBuilder.INFORMATION:
|
case PacketBuilder.INFORMATION:
|
||||||
|
|
|
@ -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_BUY_5 = 0x35;
|
||||||
public const byte ITEM_SELL = 0x3C;
|
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue