Implement "Grab all"

This commit is contained in:
SilicaAndPina 2020-12-21 16:50:54 +13:00
parent b184a9a3d4
commit 5bfd574b66
6 changed files with 38 additions and 12 deletions

View file

@ -17,7 +17,8 @@
"grab_message":"You grabbed an object off the ground.", "grab_message":"You grabbed an object off the ground.",
"grab_all_message":"You grabbed all objects off the ground.", "grab_all_message":"You grabbed all objects off the ground.",
"dropped_item_message":"You dropped an item on the ground.", "dropped_item_message":"You dropped an item on the ground.",
"grab_but_inv_full":"Your inventory is full! Cannot grab items." "grab_but_inv_full":"Your inventory is full! Cannot grab items.",
"grab_all_but_inv_full":"You grabbed what you could, but your inventory is full."
}, },
"shop":{ "shop":{
"cant_afford_1":"You cannot afford that item!", "cant_afford_1":"You cannot afford that item!",

View file

@ -68,7 +68,8 @@ namespace HISP.Game
public static string GrabAllItemsMessage; public static string GrabAllItemsMessage;
public static string GrabbedItemMessage; public static string GrabbedItemMessage;
public static string GrabbedItemButInventoryFull; public static string GrabbedItemButInventoryFull;
public static string GrabbedAllObjectsMessage; public static string GrabbedAllItemsButInventoryFull;
public static string GrabbedAllItemsMessage;
public static string DroppedAnItemMessage; public static string DroppedAnItemMessage;
public static string ItemInformationFormat; public static string ItemInformationFormat;

View file

@ -1,7 +1,4 @@
using System; using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection; using System.Reflection;
using HISP.Game; using HISP.Game;
using HISP.Security; using HISP.Security;

View file

@ -435,10 +435,11 @@ namespace HISP.Server
Messages.ItemInformationFormat = gameData.messages.meta.dropped_items.item_information_format; Messages.ItemInformationFormat = gameData.messages.meta.dropped_items.item_information_format;
Messages.GrabAllItemsButton = gameData.messages.meta.dropped_items.grab_all; Messages.GrabAllItemsButton = gameData.messages.meta.dropped_items.grab_all;
Messages.DroppedAnItemMessage = gameData.messages.dropped_items.dropped_item_message; Messages.DroppedAnItemMessage = gameData.messages.dropped_items.dropped_item_message;
Messages.GrabbedAllObjectsMessage = gameData.messages.dropped_items.grab_all_message; Messages.GrabbedAllItemsMessage = gameData.messages.dropped_items.grab_all_message;
Messages.GrabbedItemMessage = gameData.messages.dropped_items.grab_message; Messages.GrabbedItemMessage = gameData.messages.dropped_items.grab_message;
Messages.GrabAllItemsMessage = gameData.messages.dropped_items.grab_all_message; Messages.GrabAllItemsMessage = gameData.messages.dropped_items.grab_all_message;
Messages.GrabbedAllItemsButInventoryFull = gameData.messages.dropped_items.grab_all_but_inv_full;
Messages.GrabbedItemButInventoryFull = gameData.messages.dropped_items.grab_but_inv_full; Messages.GrabbedItemButInventoryFull = gameData.messages.dropped_items.grab_but_inv_full;
// Tools // Tools

View file

@ -621,7 +621,7 @@ namespace HISP.Server
Logger.ErrorPrint(sender.RemoteIp + " Send click packet when not logged in."); Logger.ErrorPrint(sender.RemoteIp + " Send click packet when not logged in.");
return; return;
} }
if (packet.Length < 4) if (packet.Length < 6)
{ {
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid Click Packet"); Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid Click Packet");
return; return;
@ -630,15 +630,15 @@ namespace HISP.Server
string packetStr = Encoding.UTF8.GetString(packet); string packetStr = Encoding.UTF8.GetString(packet);
if(packetStr.Contains("|")) if(packetStr.Contains("|"))
{ {
string packetContents = packetStr.Substring(0, packetStr.Length - 3); string packetContents = packetStr.Substring(1, packetStr.Length - 3);
string[] xy = packetContents.Split('|'); string[] xy = packetContents.Split('|');
int x = 0; int x = 0;
int y = 0; int y = 0;
try try
{ {
x = int.Parse(xy[0]); x = int.Parse(xy[0])+4;
y = int.Parse(xy[1]); y = int.Parse(xy[1])+1;
} }
catch(FormatException) catch(FormatException)
{ {
@ -675,9 +675,34 @@ namespace HISP.Server
byte action = packet[1]; byte action = packet[1];
switch(action) switch(action)
{ {
case PacketBuilder.ITEM_PICKUP_ALL:
string chatMsg = Messages.GrabAllItemsMessage;
DroppedItems.DroppedItem[] droppedItems = DroppedItems.GetItemsAt(sender.LoggedinUser.X, sender.LoggedinUser.Y);
foreach(DroppedItems.DroppedItem item in droppedItems)
{
try
{
sender.LoggedinUser.Inventory.Add(item.instance);
}
catch (InventoryException)
{
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.GrabbedItemButInventoryFull, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(inventoryFullMessage);
chatMsg = Messages.GrabbedAllItemsButInventoryFull;
break;
}
DroppedItems.RemoveDroppedItem(item);
}
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y);
byte[] chatMessage = PacketBuilder.CreateChat(chatMsg, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(chatMessage);
break;
case PacketBuilder.ITEM_PICKUP: case PacketBuilder.ITEM_PICKUP:
string packetStr = Encoding.UTF8.GetString(packet); string packetStr = Encoding.UTF8.GetString(packet);
string randomIdStr = packetStr.Substring(2, packet.Length - 2); string randomIdStr = packetStr.Substring(2, packet.Length - 4);
int randomId = 0; int randomId = 0;
try try

View file

@ -70,6 +70,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_PICKUP_ALL = 0x15;
public const byte ITEM_BUY = 0x33; public const byte ITEM_BUY = 0x33;
public const byte ITEM_BUY_5 = 0x35; public const byte ITEM_BUY_5 = 0x35;
public const byte ITEM_BUY_25 = 0x37; public const byte ITEM_BUY_25 = 0x37;