summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-02-27 03:36:52 +0200
committerAndrei Karas <akaras@inbox.ru>2011-02-27 03:36:52 +0200
commit1b57518ca97c670174f89c5af28659b6ad0c3d42 (patch)
tree369c6e2f8cfbd791f252de68c0f85bd1af47c351 /src
parent037248d338291529e0c044a80ca8345abe05dd2b (diff)
downloadmv-1b57518ca97c670174f89c5af28659b6ad0c3d42.tar.gz
mv-1b57518ca97c670174f89c5af28659b6ad0c3d42.tar.bz2
mv-1b57518ca97c670174f89c5af28659b6ad0c3d42.tar.xz
mv-1b57518ca97c670174f89c5af28659b6ad0c3d42.zip
Implement receiving item color from server.
Diffstat (limited to 'src')
-rw-r--r--src/gui/trade.cpp13
-rw-r--r--src/gui/trade.h7
-rw-r--r--src/inventory.cpp9
-rw-r--r--src/inventory.h5
-rw-r--r--src/item.cpp8
-rw-r--r--src/item.h9
-rw-r--r--src/net/manaserv/tradehandler.cpp4
-rw-r--r--src/net/tmwa/inventoryhandler.cpp13
-rw-r--r--src/net/tmwa/inventoryhandler.h5
-rw-r--r--src/net/tmwa/tradehandler.cpp14
10 files changed, 55 insertions, 32 deletions
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index f7b16d6ae..be4891103 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -151,21 +151,22 @@ void TradeWindow::setMoney(int amount)
mMoneyLabel->adjustSize();
}
-void TradeWindow::addItem(int id, bool own, int quantity, int refine)
+void TradeWindow::addItem(int id, bool own, int quantity,
+ int refine, unsigned char color)
{
if (own)
- mMyInventory->addItem(id, quantity, refine);
+ mMyInventory->addItem(id, quantity, refine, color);
else
- mPartnerInventory->addItem(id, quantity, refine);
+ mPartnerInventory->addItem(id, quantity, refine, color);
}
void TradeWindow::addItem(int id, bool own, int quantity,
- int refine, bool equipment)
+ int refine, unsigned char color, bool equipment)
{
if (own)
- mMyInventory->addItem(id, quantity, refine, equipment);
+ mMyInventory->addItem(id, quantity, refine, color, equipment);
else
- mPartnerInventory->addItem(id, quantity, refine, equipment);
+ mPartnerInventory->addItem(id, quantity, refine, color, equipment);
}
void TradeWindow::changeQuantity(int index, bool own, int quantity)
diff --git a/src/gui/trade.h b/src/gui/trade.h
index c316e2354..fcaa2f6ac 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -63,7 +63,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener
/**
* Add an item to the trade window.
*/
- void addItem(int id, bool own, int quantity, int refine);
+ void addItem(int id, bool own, int quantity,
+ int refine, unsigned char color);
/**
* Reset both item containers
@@ -73,8 +74,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener
/**
* Add an item to the trade window.
*/
- void addItem(int id, bool own, int quantity,
- int refine, bool equipment);
+ void addItem(int id, bool own, int quantity, int refine,
+ unsigned char color, bool equipment);
/**
* Change quantity of an item.
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 04a8a8962..4544c09be 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -83,13 +83,14 @@ Item *Inventory::findItem(int itemId) const
return 0;
}
-void Inventory::addItem(int id, int quantity, int refine, bool equipment)
+void Inventory::addItem(int id, int quantity, int refine,
+ unsigned char color, bool equipment)
{
- setItem(getFreeSlot(), id, quantity, refine, equipment);
+ setItem(getFreeSlot(), id, quantity, refine, color, equipment);
}
void Inventory::setItem(int index, int id, int quantity,
- int refine, bool equipment)
+ int refine, unsigned char color, bool equipment)
{
if (index < 0 || index >= static_cast<int>(mSize))
{
@@ -107,7 +108,7 @@ void Inventory::setItem(int index, int id, int quantity,
}
else if (id > 0 && mItems[index])
{
- mItems[index]->setId(id);
+ mItems[index]->setId(id, color);
mItems[index]->setQuantity(quantity);
mItems[index]->setRefine(refine);
mItems[index]->setEquipment(equipment);
diff --git a/src/inventory.h b/src/inventory.h
index e53052f2b..1e2d8a2bc 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -91,13 +91,14 @@ class Inventory
/**
* Adds a new item in a free slot.
*/
- void addItem(int id, int quantity, int refine, bool equipment = false);
+ void addItem(int id, int quantity, int refine, unsigned char color,
+ bool equipment = false);
/**
* Sets the item at the given position.
*/
void setItem(int index, int id, int quantity, int refine,
- bool equipment = false);
+ unsigned char color, bool equipment = false);
/**
* Remove a item from the inventory.
diff --git a/src/item.cpp b/src/item.cpp
index 79540334a..c3c9b9c18 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -29,7 +29,8 @@
#include "resources/resourcemanager.h"
#include "configuration.h"
-Item::Item(int id, int quantity, int refine, bool equipment, bool equipped):
+Item::Item(int id, int quantity, int refine, unsigned char color,
+ bool equipment, bool equipped):
mImage(0),
mDrawImage(0),
mQuantity(quantity),
@@ -39,7 +40,7 @@ Item::Item(int id, int quantity, int refine, bool equipment, bool equipped):
mRefine(refine),
mInvIndex(0)
{
- setId(id);
+ setId(id, color);
}
Item::~Item()
@@ -48,9 +49,10 @@ Item::~Item()
mImage->decRef();
}
-void Item::setId(int id)
+void Item::setId(int id, unsigned char color)
{
mId = id;
+ mColor = color;
// Types 0 and 1 are not equippable items.
mEquipment = id && getInfo().getType() >= 2;
diff --git a/src/item.h b/src/item.h
index bc21a437a..cb58f6f9f 100644
--- a/src/item.h
+++ b/src/item.h
@@ -39,7 +39,8 @@ class Item
* Constructor.
*/
Item(int id = -1, int quantity = 0, int refine = 0,
- bool equipment = false, bool equipped = false);
+ unsigned char color = 1, bool equipment = false,
+ bool equipped = false);
/**
* Destructor.
@@ -49,7 +50,7 @@ class Item
/**
* Sets the item id, identifying the item type.
*/
- void setId(int id);
+ void setId(int id, unsigned char color);
/**
* Returns the item id.
@@ -157,6 +158,9 @@ class Item
bool isHaveTag(int tagId);
+ unsigned char getColor()
+ { return mColor; }
+
protected:
int mId; /**< Item type id. */
Image *mImage; /**< Item image. */
@@ -167,6 +171,7 @@ class Item
bool mInEquipment; /**< Item is in equipment */
int mRefine; /**< Item refine level. */
int mInvIndex; /**< Inventory index. */
+ unsigned char mColor;
std::map <int, int> mTags;
};
diff --git a/src/net/manaserv/tradehandler.cpp b/src/net/manaserv/tradehandler.cpp
index 18a60a424..cd3a21aca 100644
--- a/src/net/manaserv/tradehandler.cpp
+++ b/src/net/manaserv/tradehandler.cpp
@@ -134,7 +134,7 @@ void TradeHandler::handleMessage(Net::MessageIn &msg)
{
int type = msg.readInt16();
int amount = msg.readInt8();
- tradeWindow->addItem(type, false, amount, 0);
+ tradeWindow->addItem(type, false, amount, 0, 1);
} break;
case GPMSG_TRADE_SET_MONEY:
@@ -201,7 +201,7 @@ void TradeHandler::addItem(Item *item, int amount)
msg.writeInt8(amount);
gameServerConnection->send(msg);
- tradeWindow->addItem(item->getId(), true, amount, 0);
+ tradeWindow->addItem(item->getId(), true, amount, 0, 1);
item->increaseQuantity(-amount);
}
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 9828fb957..340f0c4b2 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -223,7 +223,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
else
{
mInventoryItems.push_back(InventoryItem(index, itemId,
- amount, 0, false));
+ amount, 0, identified, false));
}
}
break;
@@ -256,7 +256,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
}
mInventoryItems.push_back(InventoryItem(index, itemId, amount,
- refine, false));
+ refine, identified, false));
}
break;
@@ -381,7 +381,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
for (; it != it_end; ++it)
{
mStorage->setItem((*it).slot, (*it).id, (*it).quantity,
- (*it).equip);
+ (*it).refine, (*it).color, (*it).equip);
}
mInventoryItems.clear();
@@ -403,13 +403,16 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
if (Item *item = mStorage->getItem(index))
{
- item->setId(itemId);
+ item->setId(itemId, identified);
item->increaseQuantity(amount);
}
else
{
if (mStorage)
- mStorage->setItem(index, itemId, amount, false);
+ {
+ mStorage->setItem(index, itemId, amount, refine,
+ identified, false);
+ }
}
break;
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index cc2286f2f..8dd39a781 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -109,15 +109,18 @@ class InventoryItem
int slot;
int id;
int quantity;
+ unsigned char color;
int refine;
bool equip;
- InventoryItem(int slot, int id, int quantity, int refine, bool equip)
+ InventoryItem(int slot, int id, int quantity, int refine,
+ unsigned char color, bool equip)
{
this->slot = slot;
this->id = id;
this->quantity = quantity;
this->refine = refine;
+ this->color = color;
this->equip = equip;
}
};
diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp
index 3fb05399d..815c8f54d 100644
--- a/src/net/tmwa/tradehandler.cpp
+++ b/src/net/tmwa/tradehandler.cpp
@@ -193,18 +193,23 @@ void TradeHandler::handleMessage(Net::MessageIn &msg)
{
int amount = msg.readInt32();
int type = msg.readInt16();
- msg.readInt8(); // identified flag
+ int identify = msg.readInt8(); // identified flag
msg.readInt8(); // attribute
- msg.readInt8(); // refine
+ int refine = msg.readInt8(); // refine
msg.skip(8); // card (4 shorts)
// TODO: handle also identified, etc
if (tradeWindow)
{
if (type == 0)
+ {
tradeWindow->setMoney(amount);
+ }
else
- tradeWindow->addItem(type, false, amount, false);
+ {
+ tradeWindow->addItem(type, false, amount, refine,
+ identify, false);
+ }
}
}
break;
@@ -233,7 +238,8 @@ void TradeHandler::handleMessage(Net::MessageIn &msg)
if (tradeWindow)
{
tradeWindow->addItem(item->getId(), true, quantity,
- item->isEquipment());
+ item->getRefine(), item->getColor(),
+ item->isEquipment());
}
item->increaseQuantity(-quantity);
break;