summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-04 15:19:53 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-04 15:19:53 +0300
commita553b3cda91aa095d88e22abcaa81701c2894334 (patch)
treecb44d56a66896fdbf4eaf9673901ee9cf3a60a73 /src
parent343809fe458a08bf96fe4f537db2d81d7523632e (diff)
downloadmv-a553b3cda91aa095d88e22abcaa81701c2894334.tar.gz
mv-a553b3cda91aa095d88e22abcaa81701c2894334.tar.bz2
mv-a553b3cda91aa095d88e22abcaa81701c2894334.tar.xz
mv-a553b3cda91aa095d88e22abcaa81701c2894334.zip
move equip/unequip/use calls into playerinfo.
Diffstat (limited to 'src')
-rw-r--r--src/being/localplayer.cpp10
-rw-r--r--src/being/playerinfo.cpp53
-rw-r--r--src/being/playerinfo.h10
-rw-r--r--src/gui/popups/popupmenu.cpp16
-rw-r--r--src/gui/windows/equipmentwindow.cpp6
-rw-r--r--src/gui/windows/inventorywindow.cpp34
-rw-r--r--src/gui/windows/outfitwindow.cpp4
-rw-r--r--src/itemshortcut.cpp19
-rw-r--r--src/net/ea/tradehandler.cpp3
9 files changed, 82 insertions, 73 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index ffd2593f0..22a214168 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -2349,7 +2349,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
// if sword not equiped
if (!item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
// if need equip shield too
if (mAttackWeaponType == 3)
@@ -2359,7 +2359,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
if (!item)
item = inv->findItem(602, 0);
if (item && !item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
}
// big distance. allowed only bow
@@ -2376,7 +2376,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
return;
if (!item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
}
@@ -3981,7 +3981,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const
const Item *const item = inv->findItemBySprite(path,
player->getGender(), player->getSubType());
if (item && !item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
else
{
@@ -3996,7 +3996,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const
if (item)
{
// logger->log("unequiping");
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
}
}
}
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index be9087b77..954cb20f4 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -245,6 +245,59 @@ void setEquipmentBackend(Equipment::Backend *const backend)
mEquipment->setBackend(backend);
}
+void equipItem(const Item *const item)
+{
+ Net::getInventoryHandler()->equipItem(item);
+}
+
+void unequipItem(const Item *const item)
+{
+ Net::getInventoryHandler()->unequipItem(item);
+}
+
+void useItem(const Item *const item)
+{
+ Net::getInventoryHandler()->useItem(item);
+}
+
+void useEquipItem(const Item *const item)
+{
+ if (item)
+ {
+ if (item->isEquipment())
+ {
+ if (item->isEquipped())
+ Net::getInventoryHandler()->unequipItem(item);
+ else
+ Net::getInventoryHandler()->equipItem(item);
+ }
+ else
+ {
+ if (mProtectedItems.find(item->getId()) == mProtectedItems.end())
+ Net::getInventoryHandler()->useItem(item);
+ }
+ }
+}
+
+void useEquipItem2(const Item *const item)
+{
+ if (item)
+ {
+ if (!item->isEquipment())
+ {
+ if (item->isEquipped())
+ Net::getInventoryHandler()->unequipItem(item);
+ else
+ Net::getInventoryHandler()->equipItem(item);
+ }
+ else
+ {
+ if (mProtectedItems.find(item->getId()) == mProtectedItems.end())
+ Net::getInventoryHandler()->useItem(item);
+ }
+ }
+}
+
// --- Misc -------------------------------------------------------------------
void setBackend(const PlayerInfoBackend &backend)
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index a0b10d4fe..052fbe966 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -255,6 +255,16 @@ namespace PlayerInfo
void setEquipmentBackend(Equipment::Backend *const backend);
+ void equipItem(const Item *const item);
+
+ void unequipItem(const Item *const item);
+
+ void useItem(const Item *const item);
+
+ void useEquipItem(const Item *const item);
+
+ void useEquipItem2(const Item *const item);
+
void protectItem(const int id);
void unprotectItem(const int id);
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index 015067a6f..459925bd0 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -1012,21 +1012,7 @@ void PopupMenu::handleLink(const std::string &link,
if (inv)
{
const Item *const item = inv->findItem(mItemId, mItemColor);
- if (item)
- {
- if (item->isEquipment())
- {
- if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
- else
- Net::getInventoryHandler()->equipItem(item);
- }
- else
- {
- if (!PlayerInfo::isItemProtected(item->getId()))
- Net::getInventoryHandler()->useItem(item);
- }
- }
+ PlayerInfo::useEquipItem(item);
}
}
else if (mItemId < SKILL_MIN_ID && spellManager)
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index 8cfb3b28e..5f214cebe 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -257,7 +257,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
if (event.getId() == "unequip" && mSelected > -1)
{
const Item *const item = mEquipment->getEquipment(mSelected);
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
setSelected(-1);
}
}
@@ -377,7 +377,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent)
if (item->isEquipment())
{
if (!item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
}
else if (dragDrop.getSource() == DRAGDROP_SOURCE_EQUIPMENT)
@@ -401,7 +401,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent)
}
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
}
}
dragDrop.clear();
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 75bd90edc..99d4d4954 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -358,35 +358,11 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
if (eventId == "use")
{
- if (item->isEquipment())
- {
- if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
- else
- Net::getInventoryHandler()->equipItem(item);
- }
- else
- {
- if (PlayerInfo::isItemProtected(item->getId()))
- return;
- Net::getInventoryHandler()->useItem(item);
- }
+ PlayerInfo::useEquipItem(item);
}
if (eventId == "equip")
{
- if (!item->isEquipment())
- {
- if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
- else
- Net::getInventoryHandler()->equipItem(item);
- }
- else
- {
- if (PlayerInfo::isItemProtected(item->getId()))
- return;
- Net::getInventoryHandler()->useItem(item);
- }
+ PlayerInfo::useEquipItem2(item);
}
else if (eventId == "drop")
{
@@ -551,15 +527,15 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (item->isEquipment())
{
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
else
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
else
{
if (PlayerInfo::isItemProtected(item->getId()))
return;
- Net::getInventoryHandler()->useItem(item);
+ PlayerInfo::useItem(item);
}
}
}
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp
index 38a837872..73acf475a 100644
--- a/src/gui/windows/outfitwindow.cpp
+++ b/src/gui/windows/outfitwindow.cpp
@@ -279,7 +279,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty,
{
if (item->isEquipment())
{
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
isEmpty = false;
}
}
@@ -522,7 +522,7 @@ void OutfitWindow::unequipNotInOutfit(const int outfit) const
}
}
if (!found)
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
}
}
}
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index 5ef762de8..7356ff0e7 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -133,20 +133,7 @@ void ItemShortcut::useItem(const int index) const
{
const Item *const item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity())
- {
- if (item->isEquipment())
- {
- if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
- else
- Net::getInventoryHandler()->equipItem(item);
- }
- else
- {
- if (!PlayerInfo::isItemProtected(item->getId()))
- Net::getInventoryHandler()->useItem(item);
- }
- }
+ PlayerInfo::useEquipItem(item);
}
else if (itemId < SKILL_MIN_ID && spellManager)
{
@@ -174,7 +161,7 @@ void ItemShortcut::equipItem(const int index) const
if (item->isEquipment())
{
if (!item->isEquipped())
- Net::getInventoryHandler()->equipItem(item);
+ PlayerInfo::equipItem(item);
}
}
}
@@ -194,7 +181,7 @@ void ItemShortcut::unequipItem(const int index) const
if (item->isEquipment())
{
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ PlayerInfo::unequipItem(item);
}
}
}
diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp
index abfb56559..c4654087b 100644
--- a/src/net/ea/tradehandler.cpp
+++ b/src/net/ea/tradehandler.cpp
@@ -226,9 +226,6 @@ void TradeHandler::processTradeItemAddResponse(Net::MessageIn &msg) const
{
case 0:
// Successfully added item
- if (item->isEquipment() && item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
-
if (tradeWindow)
{
tradeWindow->addItem2(item->getId(), true,