summaryrefslogtreecommitdiff
path: root/src/actions/actions.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-13 14:26:19 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-13 14:26:19 +0300
commit100d8af2ef802edc369deba120fcda7c81e25d93 (patch)
treec4e4f1f826262fef25d450f7520184d992307d6c /src/actions/actions.cpp
parent4729d390af864d7f4614ca76ab74dc2cd7e7c1ae (diff)
downloadmanaverse-100d8af2ef802edc369deba120fcda7c81e25d93.tar.gz
manaverse-100d8af2ef802edc369deba120fcda7c81e25d93.tar.bz2
manaverse-100d8af2ef802edc369deba120fcda7c81e25d93.tar.xz
manaverse-100d8af2ef802edc369deba120fcda7c81e25d93.zip
Simplify actions based on inventory index.
Diffstat (limited to 'src/actions/actions.cpp')
-rw-r--r--src/actions/actions.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 165a9add0..4b527d008 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -210,6 +210,15 @@ static Being *findBeing(const std::string &name)
return being;
}
+static Item *getItemByInvIndex(const InputEvent &event)
+{
+ const int index = atoi(event.args.c_str());
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (inv)
+ return inv->getItem(index);
+ return nullptr;
+}
+
impHandler(emote)
{
const int emotion = 1 + event.action - InputAction::EMOTE_1;
@@ -382,12 +391,7 @@ impHandler(dropItemId)
impHandler(dropItemInv)
{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (!inv)
- return false;
-
- Item *const item = inv->getItem(atoi(event.args.c_str()));
-
+ Item *const item = getItemByInvIndex(event);
if (item && !PlayerInfo::isItemProtected(item->getId()))
{
ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop,
@@ -412,12 +416,7 @@ impHandler(dropItemIdAll)
impHandler(dropItemInvAll)
{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (!inv)
- return false;
-
- Item *const item = inv->getItem(atoi(event.args.c_str()));
-
+ Item *const item = getItemByInvIndex(event);
if (item && !PlayerInfo::isItemProtected(item->getId()))
PlayerInfo::dropItem(item, item->getQuantity(), true);
return true;
@@ -1380,26 +1379,16 @@ impHandler(useItem)
impHandler(useItemInv)
{
- const int index = atoi(event.args.c_str());
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv)
- {
- Item *const item = inv->getItem(index);
- PlayerInfo::useEquipItem(item, true);
- }
+ Item *const item = getItemByInvIndex(event);
+ PlayerInfo::useEquipItem(item, true);
return true;
}
impHandler(invToStorage)
{
- const int index = atoi(event.args.c_str());
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv)
- {
- Item *const item = inv->getItem(index);
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
- inventoryWindow, item);
- }
+ Item *const item = getItemByInvIndex(event);
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
+ inventoryWindow, item);
return true;
}