summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-14 22:42:47 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-14 22:42:47 +0300
commit26b43e7164214e8c9e5cdb8842a79a4fcc1493da (patch)
tree250a4f432ed66dee5a821eab15855cd194b18433 /src/net
parent21d0f7cd7b0d8474f1043ae4f283a58ea6d8b352 (diff)
downloadmanaverse-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')
-rw-r--r--src/net/eathena/inventoryhandler.cpp47
-rw-r--r--src/net/eathena/inventoryhandler.h8
-rw-r--r--src/net/eathena/protocol.h2
-rw-r--r--src/net/inventoryhandler.h4
-rw-r--r--src/net/tmwa/inventoryhandler.cpp2
-rw-r--r--src/net/tmwa/inventoryhandler.h5
6 files changed, 54 insertions, 14 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);
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index fc1365898..a151e39da 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -71,7 +71,7 @@ class InventoryHandler notfinal
virtual int convertFromServerSlot(const int eAthenaSlot) const = 0;
- virtual void useCard(const int index) const = 0;
+ virtual void useCard(const Item *const item) = 0;
virtual void insertCard(const int cardIndex,
const int itemIndex) const = 0;
@@ -82,6 +82,8 @@ class InventoryHandler notfinal
virtual void selectEgg(const Item *const item) const = 0;
virtual int getProjectileSlot() const = 0;
+
+ virtual int getItemIndex() const A_WARN_UNUSED = 0;
};
} // namespace Net
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 6097f515d..5ff9325ae 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -240,7 +240,7 @@ void InventoryHandler::moveItem2(const int source, const int slot,
}
}
-void InventoryHandler::useCard(const int index A_UNUSED) const
+void InventoryHandler::useCard(const Item *const item A_UNUSED)
{
}
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index 5a8056538..bf6badc48 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/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 10; }
+ int getItemIndex() const override final A_WARN_UNUSED
+ { return 0; }
+
protected:
static void processPlayerEquipment(Net::MessageIn &msg);