00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "net/tmwserv/inventoryhandler.h"
00023
00024 #include "net/tmwserv/connection.h"
00025 #include "net/tmwserv/protocol.h"
00026
00027 #include "net/tmwserv/gameserver/internal.h"
00028
00029 #include "net/messagein.h"
00030 #include "net/messageout.h"
00031
00032 #include "equipment.h"
00033 #include "inventory.h"
00034 #include "item.h"
00035 #include "itemshortcut.h"
00036 #include "localplayer.h"
00037
00038 #include "gui/chat.h"
00039
00040 #include "resources/iteminfo.h"
00041
00042 Net::InventoryHandler *inventoryHandler;
00043
00044 namespace TmwServ {
00045
00046 InventoryHandler::InventoryHandler()
00047 {
00048 static const Uint16 _messages[] = {
00049 GPMSG_INVENTORY_FULL,
00050 GPMSG_INVENTORY,
00051 0
00052 };
00053 handledMessages = _messages;
00054 inventoryHandler = this;
00055 }
00056
00057 void InventoryHandler::handleMessage(MessageIn &msg)
00058 {
00059 switch (msg.getId())
00060 {
00061 case GPMSG_INVENTORY_FULL:
00062 player_node->clearInventory();
00063
00064
00065 case GPMSG_INVENTORY:
00066 while (msg.getUnreadLength())
00067 {
00068 int slot = msg.readInt8();
00069 if (slot == 255)
00070 {
00071 player_node->setMoney(msg.readInt32());
00072 continue;
00073 }
00074
00075 int id = msg.readInt16();
00076 if (slot < EQUIPMENT_SIZE)
00077 {
00078 player_node->mEquipment->setEquipment(slot, id);
00079 }
00080 else if (slot >= 32 && slot < 32 + INVENTORY_SIZE)
00081 {
00082 int amount = id ? msg.readInt8() : 0;
00083 player_node->setInvItem(slot - 32, id, amount);
00084 }
00085 };
00086 break;
00087 }
00088 }
00089
00090 void InventoryHandler::equipItem(Item *item)
00091 {
00092 MessageOut msg(PGMSG_EQUIP);
00093 msg.writeInt8(item->getInvIndex());
00094 Net::GameServer::connection->send(msg);
00095 }
00096
00097 void InventoryHandler::unequipItem(Item *item)
00098 {
00099 MessageOut msg(PGMSG_UNEQUIP);
00100 msg.writeInt8(item->getInvIndex());
00101 Net::GameServer::connection->send(msg);
00102 }
00103
00104 void InventoryHandler::useItem(Item *item)
00105 {
00106 MessageOut msg(PGMSG_USE_ITEM);
00107 msg.writeInt8(item->getInvIndex());
00108 Net::GameServer::connection->send(msg);
00109 }
00110
00111 void InventoryHandler::dropItem(Item *item, int amount)
00112 {
00113 MessageOut msg(PGMSG_DROP);
00114 msg.writeInt8(item->getInvIndex());
00115 msg.writeInt8(amount);
00116 Net::GameServer::connection->send(msg);
00117 }
00118
00119 void InventoryHandler::splitItem(Item *item, int amount)
00120 {
00121
00122 }
00123
00124 void InventoryHandler::openStorage()
00125 {
00126
00127 }
00128
00129 void InventoryHandler::closeStorage()
00130 {
00131
00132 }
00133
00134 void InventoryHandler::moveItem(StorageType source, int slot, int amount,
00135 StorageType destination)
00136 {
00137
00138 }
00139
00140 }