diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-07-14 22:42:47 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-07-14 22:42:47 +0300 |
commit | 26b43e7164214e8c9e5cdb8842a79a4fcc1493da (patch) | |
tree | 250a4f432ed66dee5a821eab15855cd194b18433 /src/net/eathena | |
parent | 21d0f7cd7b0d8474f1043ae4f283a58ea6d8b352 (diff) | |
download | manaverse-26b43e7164214e8c9e5cdb8842a79a4fcc1493da.tar.gz manaverse-26b43e7164214e8c9e5cdb8842a79a4fcc1493da.tar.bz2 manaverse-26b43e7164214e8c9e5cdb8842a79a4fcc1493da.tar.xz manaverse-26b43e7164214e8c9e5cdb8842a79a4fcc1493da.zip |
Add ability for insert cards into items.
Diffstat (limited to 'src/net/eathena')
-rw-r--r-- | src/net/eathena/inventoryhandler.cpp | 47 | ||||
-rw-r--r-- | src/net/eathena/inventoryhandler.h | 8 | ||||
-rw-r--r-- | src/net/eathena/protocol.h | 2 |
3 files changed, 46 insertions, 11 deletions
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index a2e7c869e..c73425874 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -30,6 +30,10 @@ #include "enums/resources/notifytypes.h" +#include "gui/widgets/createwidget.h" + +#include "gui/windows/insertcarddialog.h" + #include "listeners/arrowslistener.h" #include "net/eathena/itemflags.h" @@ -72,7 +76,8 @@ Ea::InventoryItems InventoryHandler::mCartItems; InventoryHandler::InventoryHandler() : MessageHandler(), - Ea::InventoryHandler() + Ea::InventoryHandler(), + mItemIndex(0) { static const uint16_t _messages[] = { @@ -93,7 +98,7 @@ InventoryHandler::InventoryHandler() : SMSG_PLAYER_UNEQUIP, SMSG_PLAYER_ARROW_EQUIP, SMSG_PLAYER_ATTACK_RANGE, - SMSG_PLAYER_UNE_CARD, + SMSG_PLAYER_USE_CARD, SMSG_PLAYER_INSERT_CARD, SMSG_PLAYER_ITEM_RENTAL_TIME, SMSG_PLAYER_ITEM_RENTAL_EXPIRED, @@ -200,7 +205,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) processPlayerArrowEquip(msg); break; - case SMSG_PLAYER_UNE_CARD: + case SMSG_PLAYER_USE_CARD: processPlayerUseCard(msg); break; @@ -385,10 +390,15 @@ void InventoryHandler::moveItem2(const int source, } } -void InventoryHandler::useCard(const int index) const +void InventoryHandler::useCard(const Item *const item) { + if (!item) + return; + + mItemIndex = item->getInvIndex(); createOutPacket(CMSG_PLAYER_USE_CARD); - outMsg.writeInt16(static_cast<int16_t>(index + INVENTORY_OFFSET), "index"); + outMsg.writeInt16(static_cast<int16_t>( + mItemIndex + INVENTORY_OFFSET), "index"); } void InventoryHandler::insertCard(const int cardIndex, @@ -783,21 +793,40 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg) void InventoryHandler::processPlayerUseCard(Net::MessageIn &msg) { - UNIMPLIMENTEDPACKET; - // +++ here need show dialog with item selection for card. + SellDialog *const dialog = CREATEWIDGETR(InsertCardDialog, + inventoryHandler->getItemIndex()); + Inventory *const inv = PlayerInfo::getInventory(); + const int count = (msg.readInt16("len") - 4) / 2; for (int f = 0; f < count; f ++) - msg.readInt16("item id"); + { + const int itemIndex = msg.readInt16("item index") - INVENTORY_OFFSET; + const Item *const item = inv->getItem(itemIndex); + if (!item) + continue; + dialog->addItem(item, 0); + } } void InventoryHandler::processPlayerInsertCard(Net::MessageIn &msg) { msg.readInt16("item index"); - msg.readInt16("card index"); + const int cardIndex = msg.readInt16("card index") - INVENTORY_OFFSET; if (msg.readUInt8("flag")) + { NotifyManager::notify(NotifyTypes::CARD_INSERT_FAILED); + } else + { NotifyManager::notify(NotifyTypes::CARD_INSERT_SUCCESS); + Inventory *const inv = PlayerInfo::getInventory(); + Item *const item = inv->getItem(cardIndex); + if (!item) + return; + item->increaseQuantity(-1); + if (item->getQuantity() == 0) + inv->removeItemAt(cardIndex); + } } void InventoryHandler::selectEgg(const Item *const item) const diff --git a/src/net/eathena/inventoryhandler.h b/src/net/eathena/inventoryhandler.h index 6497c2e9b..c593a2c67 100644 --- a/src/net/eathena/inventoryhandler.h +++ b/src/net/eathena/inventoryhandler.h @@ -58,7 +58,7 @@ class InventoryHandler final : public MessageHandler, const int amount, const int destination) const override final; - void useCard(const int index) const override final; + void useCard(const Item *const item) override final; void insertCard(const int cardIndex, const int itemIndex) const override final; @@ -74,6 +74,9 @@ class InventoryHandler final : public MessageHandler, int getProjectileSlot() const override final { return 23; } + int getItemIndex() const override final A_WARN_UNUSED + { return mItemIndex; } + protected: static void processPlayerEquipment(Net::MessageIn &msg); @@ -142,6 +145,9 @@ class InventoryHandler final : public MessageHandler, static void processBindItem(Net::MessageIn &msg); static Ea::InventoryItems mCartItems; + + private: + int mItemIndex; }; } // namespace EAthena diff --git a/src/net/eathena/protocol.h b/src/net/eathena/protocol.h index faef51ac2..a8cea65a4 100644 --- a/src/net/eathena/protocol.h +++ b/src/net/eathena/protocol.h @@ -97,7 +97,7 @@ packet(SMSG_PLAYER_REFINE, 0x0188); packet(SMSG_PLAYER_EQUIPMENT, 0x0992); packet(SMSG_PLAYER_EQUIP, 0x0999); packet(SMSG_PLAYER_UNEQUIP, 0x099a); -packet(SMSG_PLAYER_UNE_CARD, 0x017b); +packet(SMSG_PLAYER_USE_CARD, 0x017b); packet(SMSG_PLAYER_INSERT_CARD, 0x017d); packet(SMSG_PLAYER_ATTACK_RANGE, 0x013a); packet(SMSG_PLAYER_ARROW_EQUIP, 0x013c); |