summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-10-21 17:43:19 +0300
committerAndrei Karas <akaras@inbox.ru>2014-10-21 17:43:19 +0300
commite3ad003fe09ff90524ffa5deae844e6721b903b2 (patch)
tree756f8cae3ee12060548384ece6750a25bee4ab45 /src
parent4ab7d38fe9033695e23042e97b55999b26f00fd7 (diff)
downloadplus-e3ad003fe09ff90524ffa5deae844e6721b903b2.tar.gz
plus-e3ad003fe09ff90524ffa5deae844e6721b903b2.tar.bz2
plus-e3ad003fe09ff90524ffa5deae844e6721b903b2.tar.xz
plus-e3ad003fe09ff90524ffa5deae844e6721b903b2.zip
Set cards from net code.
Diffstat (limited to 'src')
-rw-r--r--src/gui/windows/tradewindow.cpp30
-rw-r--r--src/gui/windows/tradewindow.h2
-rw-r--r--src/inventory.cpp22
-rw-r--r--src/inventory.h18
-rw-r--r--src/item.h3
-rw-r--r--src/net/eathena/inventoryhandler.cpp52
-rw-r--r--src/net/eathena/partyhandler.cpp6
-rw-r--r--src/net/eathena/tradehandler.cpp11
-rw-r--r--src/net/tmwa/inventoryhandler.cpp30
-rw-r--r--src/net/tmwa/tradehandler.cpp17
10 files changed, 100 insertions, 91 deletions
diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp
index 6bf091625..c7cd1712d 100644
--- a/src/gui/windows/tradewindow.cpp
+++ b/src/gui/windows/tradewindow.cpp
@@ -199,19 +199,14 @@ void TradeWindow::addItem(const int id,
const bool damaged,
const bool favorite) const
{
- if (own)
- {
- mMyInventory->addItem(id, quantity, refine, color,
- identified, damaged, favorite, false, false);
- }
- else
- {
- mPartnerInventory->addItem(id, quantity, refine, color,
- identified, damaged, favorite, false, false);
- }
+ Inventory *inv = own ? mMyInventory.get() : mPartnerInventory.get();
+ inv->addItem(id, quantity, refine, color,
+ identified, damaged, favorite, false, false);
}
void TradeWindow::addItem2(const int id,
+ const int *const cards,
+ const int sz,
const bool own,
const int quantity,
const uint8_t refine,
@@ -221,16 +216,11 @@ void TradeWindow::addItem2(const int id,
const bool favorite,
const bool equipment) const
{
- if (own)
- {
- mMyInventory->addItem(id, quantity, refine, color,
- identified, damaged, favorite, equipment, false);
- }
- else
- {
- mPartnerInventory->addItem(id, quantity, refine, color,
- identified, damaged, favorite, equipment, false);
- }
+ Inventory *inv = own ? mMyInventory.get() : mPartnerInventory.get();
+ const int slot = inv->addItem(id, quantity, refine, color,
+ identified, damaged, favorite, equipment, false);
+ if (slot >= 0)
+ inv->setCards(slot, cards, sz);
}
void TradeWindow::changeQuantity(const int index, const bool own,
diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h
index 8f8067902..5c782cf07 100644
--- a/src/gui/windows/tradewindow.h
+++ b/src/gui/windows/tradewindow.h
@@ -85,6 +85,8 @@ class TradeWindow final : public Window,
* Add an item to the trade window.
*/
void addItem2(const int id,
+ const int *const cards,
+ const int sz,
const bool own,
const int quantity,
const uint8_t refine,
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 0a76dff7d..da15cbe42 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -103,18 +103,20 @@ Item *Inventory::findItem(const int itemId, const unsigned char color) const
return nullptr;
}
-void Inventory::addItem(const int id,
- const int quantity,
- const uint8_t refine,
- const uint8_t color,
- const bool identified,
- const bool damaged,
- const bool favorite,
- const bool equipment,
- const bool equipped)
+int Inventory::addItem(const int id,
+ const int quantity,
+ const uint8_t refine,
+ const uint8_t color,
+ const bool identified,
+ const bool damaged,
+ const bool favorite,
+ const bool equipment,
+ const bool equipped)
{
- setItem(getFreeSlot(), id, quantity, refine, color,
+ const int slot = getFreeSlot();
+ setItem(slot, id, quantity, refine, color,
identified, damaged, favorite, equipment, equipped);
+ return slot;
}
void Inventory::setItem(const int index,
diff --git a/src/inventory.h b/src/inventory.h
index 4c9417db4..cddc00709 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -87,15 +87,15 @@ class Inventory final
/**
* Adds a new item in a free slot.
*/
- void addItem(const int id,
- const int quantity,
- const uint8_t refine,
- const unsigned char color,
- const bool identified,
- const bool damaged,
- const bool favorite,
- const bool equipment,
- const bool equipped);
+ int addItem(const int id,
+ const int quantity,
+ const uint8_t refine,
+ const unsigned char color,
+ const bool identified,
+ const bool damaged,
+ const bool favorite,
+ const bool equipment,
+ const bool equipped);
/**
* Sets the item at the given position.
diff --git a/src/item.h b/src/item.h
index 13f34499b..15ea64a07 100644
--- a/src/item.h
+++ b/src/item.h
@@ -197,6 +197,9 @@ class Item notfinal
void setCards(const int *const cards, const int size);
+ const int *getCards() const
+ { return mCards; }
+
int mId; /**< Item type id. */
unsigned char mColor;
int mQuantity; /**< Number of items. */
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index fcdeb68c3..74b8072c8 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -314,10 +314,9 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
msg.readInt32("location");
const int equipType = msg.readInt32("wear state");
const uint8_t refine = static_cast<uint8_t>(msg.readInt8("refine"));
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
msg.readInt32("hire expire date (?)");
msg.readInt16("equip type");
msg.readInt16("item sprite number");
@@ -329,6 +328,7 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
1, flags.bits.isIdentified, flags.bits.isDamaged,
flags.bits.isFavorite,
true, false);
+ inventory->setCards(index, cards, 4);
}
if (equipType)
@@ -355,10 +355,9 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
uint8_t identified = msg.readUInt8("identified");
const uint8_t damaged = msg.readUInt8("is damaged");
const uint8_t refine = msg.readUInt8("refine");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
const int equipType = msg.readInt32("location");
msg.readUInt8("item type");
const unsigned char err = msg.readUInt8("result");
@@ -426,6 +425,7 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
inventory->setItem(index, itemId, amount, refine,
1, identified != 0, damaged != 0, false,
equipType != 0, false);
+ inventory->setCards(index, cards, 4);
}
ArrowsListener::distributeEvent();
}
@@ -458,10 +458,9 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
msg.readUInt8("item type");
const int amount = msg.readInt16("count");
msg.readInt32("wear state / equip");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
msg.readInt32("hire expire date (?)");
ItemFlags flags;
flags.byte = msg.readUInt8("flags");
@@ -472,6 +471,7 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
0, 1, flags.bits.isIdentified,
flags.bits.isDamaged, flags.bits.isFavorite,
false, false);
+ inventory->setCards(index, cards, 4);
}
}
BLOCK_END("InventoryHandler::processPlayerInventory")
@@ -494,16 +494,15 @@ void InventoryHandler::processPlayerStorage(Net::MessageIn &msg)
msg.readUInt8("item type");
const int amount = msg.readInt16("count");
msg.readInt32("wear state / equip");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
msg.readInt32("hire expire date (?)");
ItemFlags flags;
flags.byte = msg.readUInt8("flags");
mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
- amount, 0, 1, flags.bits.isIdentified,
+ cards, amount, 0, 1, flags.bits.isIdentified,
flags.bits.isDamaged, flags.bits.isFavorite, false));
}
BLOCK_END("InventoryHandler::processPlayerInventory")
@@ -591,18 +590,17 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg)
msg.readInt32("location");
msg.readInt32("wear state");
const uint8_t refine = msg.readUInt8("refine level");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
msg.readInt32("hire expire date");
msg.readInt16("bind on equip");
msg.readInt16("sprite");
ItemFlags flags;
flags.byte = msg.readUInt8("flags");
- mInventoryItems.push_back(Ea::InventoryItem(index,
- itemId, amount, refine, 1, flags.bits.isIdentified,
+ mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
+ cards, amount, refine, 1, flags.bits.isIdentified,
flags.bits.isDamaged, flags.bits.isFavorite, false));
}
BLOCK_END("InventoryHandler::processPlayerStorageEquip")
@@ -619,10 +617,9 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg)
const unsigned char identified = msg.readUInt8("identify");
msg.readUInt8("attribute");
const uint8_t refine = msg.readUInt8("refine");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
if (Item *const item = mStorage->getItem(index))
{
@@ -635,6 +632,7 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg)
{
mStorage->setItem(index, itemId, amount,
refine, 1, identified != 0, false, false, false, false);
+ mStorage->setCards(index, cards, 4);
}
}
BLOCK_END("InventoryHandler::processPlayerStorageAdd")
diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp
index a3ccb6776..9a83a739e 100644
--- a/src/net/eathena/partyhandler.cpp
+++ b/src/net/eathena/partyhandler.cpp
@@ -479,10 +479,8 @@ void PartyHandler::processPartyItemPickup(Net::MessageIn &msg)
msg.readUInt8("identify");
msg.readUInt8("attribute");
msg.readUInt8("refine");
- msg.readInt16("card0");
- msg.readInt16("card1");
- msg.readInt16("card2");
- msg.readInt16("card3");
+ for (int f = 0; f < 4; f++)
+ msg.readInt16("card");
msg.readInt16("equip location");
msg.readUInt8("item type");
}
diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp
index 45310761f..921d2f88b 100644
--- a/src/net/eathena/tradehandler.cpp
+++ b/src/net/eathena/tradehandler.cpp
@@ -187,10 +187,9 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg)
const uint8_t identify = msg.readUInt8("identify");
msg.readUInt8("attribute");
const uint8_t refine = msg.readUInt8("refine");
- msg.readInt16("card 0");
- msg.readInt16("card 1");
- msg.readInt16("card 2");
- msg.readInt16("card 3");
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
if (tradeWindow)
{
@@ -200,7 +199,9 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg)
}
else
{
- tradeWindow->addItem2(type, false, amount,
+ tradeWindow->addItem2(type,
+ cards, 4,
+ false, amount,
refine, 1, identify != 0, false, false, false);
}
}
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 645da2da7..79d60e381 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -258,7 +258,9 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
const int equipType = msg.readInt16();
msg.readUInt8(); // attribute
const uint8_t refine = msg.readUInt8();
- msg.skip(8); // card
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
if (mDebugInventory)
{
@@ -278,6 +280,7 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
inventory->setItem(index, itemId, 1, refine,
1, identified != 0, false, false, true, false);
}
+ inventory->setCards(index, cards, 4);
}
if (equipType)
@@ -304,8 +307,9 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
uint8_t identified = msg.readUInt8();
msg.readUInt8(); // attribute
const uint8_t refine = msg.readUInt8();
- for (int i = 0; i < 4; i++)
- msg.readInt16(); // cards[i]
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
const int equipType = msg.readInt16();
msg.readUInt8(); // itemType
@@ -378,6 +382,7 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg)
inventory->setItem(index, itemId, amount, refine,
1, identified != 0, false, false, equipType != 0, false);
}
+ inventory->setCards(index, cards, 4);
}
ArrowsListener::distributeEvent();
}
@@ -438,6 +443,7 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg)
inventory->setItem(index, itemId, amount,
0, 1, identified != 0, false, false, isEquipment, false);
}
+ inventory->setCards(index, cards, 4);
}
}
BLOCK_END("InventoryHandler::processPlayerInventory")
@@ -474,12 +480,12 @@ void InventoryHandler::processPlayerStorage(Net::MessageIn &msg)
if (serverFeatures->haveItemColors())
{
mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
- amount, 0, identified, true, false, false, false));
+ cards, amount, 0, identified, true, false, false, false));
}
else
{
mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
- amount, 0, 1, identified != 0, false, false, false));
+ cards, amount, 0, 1, identified != 0, false, false, false));
}
}
BLOCK_END("InventoryHandler::processPlayerInventory")
@@ -546,14 +552,14 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg)
if (serverFeatures->haveItemColors())
{
- mInventoryItems.push_back(Ea::InventoryItem(index,
- itemId, amount, refine, identified, true,
+ mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
+ cards, amount, refine, identified, true,
false, false, false));
}
else
{
- mInventoryItems.push_back(Ea::InventoryItem(index,
- itemId, amount, refine, 1, identified != 0,
+ mInventoryItems.push_back(Ea::InventoryItem(index, itemId,
+ cards, amount, refine, 1, identified != 0,
false, false, false));
}
}
@@ -570,8 +576,9 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg)
unsigned char identified = msg.readUInt8();
msg.readUInt8(); // attribute
const uint8_t refine = msg.readUInt8();
- for (int i = 0; i < 4; i++)
- msg.readInt16(); // card i
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
if (Item *const item = mStorage->getItem(index))
{
@@ -592,6 +599,7 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg)
mStorage->setItem(index, itemId, amount,
refine, 1, identified != 0, false, false, false, false);
}
+ mStorage->setCards(index, cards, 4);
}
}
BLOCK_END("InventoryHandler::processPlayerStorageAdd")
diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp
index 30b432d2f..5cb9e4ae2 100644
--- a/src/net/tmwa/tradehandler.cpp
+++ b/src/net/tmwa/tradehandler.cpp
@@ -170,7 +170,9 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg)
const uint8_t identify = msg.readUInt8(); // identified flag
msg.readUInt8(); // attribute
const uint8_t refine = msg.readUInt8(); // refine
- msg.skip(8); // card (4 shorts)
+ int cards[4];
+ for (int f = 0; f < 4; f++)
+ cards[f] = msg.readInt16("card");
if (tradeWindow)
{
@@ -182,12 +184,16 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg)
{
if (serverFeatures->haveItemColors())
{
- tradeWindow->addItem2(type, false, amount,
+ tradeWindow->addItem2(type,
+ cards, 4,
+ false, amount,
refine, identify, true, false, false, false);
}
else
{
- tradeWindow->addItem2(type, false, amount,
+ tradeWindow->addItem2(type,
+ cards, 4,
+ false, amount,
refine, 1, identify != 0, false, false, false);
}
}
@@ -217,8 +223,9 @@ void TradeHandler::processTradeItemAddResponse(Net::MessageIn &msg)
// Successfully added item
if (tradeWindow)
{
- tradeWindow->addItem2(item->getId(), true,
- quantity, item->getRefine(), item->getColor(),
+ tradeWindow->addItem2(item->getId(),
+ item->getCards(), 4,
+ true, quantity, item->getRefine(), item->getColor(),
item->getIdentified(), item->getDamaged(),
item->getFavorite(), item->isEquipment());
}