summaryrefslogtreecommitdiff
path: root/src/actions/actions.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-13 16:43:37 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-13 16:43:37 +0300
commitc6204f4b682288b882c2d035381f5bacbe5820c5 (patch)
tree8fdb1ecbf35024fa8710fd1d472a75c3f5154d5f /src/actions/actions.cpp
parentc7833cb8a08cf705e9e67124d746f6f7af2e93c3 (diff)
downloadmv-c6204f4b682288b882c2d035381f5bacbe5820c5.tar.gz
mv-c6204f4b682288b882c2d035381f5bacbe5820c5.tar.bz2
mv-c6204f4b682288b882c2d035381f5bacbe5820c5.tar.xz
mv-c6204f4b682288b882c2d035381f5bacbe5820c5.zip
Improve /invtostorage chat command.
Diffstat (limited to 'src/actions/actions.cpp')
-rw-r--r--src/actions/actions.cpp86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index db2a864e5..a7c0466d2 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -220,6 +220,44 @@ static Item *getItemByInvIndex(const InputEvent &event)
return nullptr;
}
+static int getAmountFromEvent(const InputEvent &event, Item *&item0)
+{
+ Item *const item = getItemByInvIndex(event);
+ item0 = item;
+ if (!item)
+ return 0;
+
+ std::string str = event.args;
+ removeToken(str, " ");
+
+ if (str.empty())
+ return 0;
+
+ int amount = 0;
+ if (str[0] == '-')
+ {
+ if (str.size() > 1)
+ {
+ amount = item->getQuantity() - atoi(str.substr(1).c_str());
+ if (amount <= 0 || amount > item->getQuantity())
+ amount = item->getQuantity();
+ }
+ }
+ else if (str == "/")
+ {
+ amount = item->getQuantity() / 2;
+ }
+ else if (str == "all")
+ {
+ amount = item->getQuantity();
+ }
+ else
+ {
+ amount = atoi(str.c_str());
+ }
+ return amount;
+}
+
impHandler(emote)
{
const int emotion = 1 + event.action - InputAction::EMOTE_1;
@@ -1387,51 +1425,21 @@ impHandler(useItemInv)
impHandler(invToStorage)
{
- Item *const item = getItemByInvIndex(event);
- if (!item)
- return true;
-
- std::string args = event.args;
- int amount = 0;
-
- int idx = args.find(" ");
- if (idx > 0)
- args = args.substr(idx + 1);
+ Item *item = nullptr;
+ const int amount = getAmountFromEvent(event, item);
+ if (amount)
+ {
+ inventoryHandler->moveItem2(Inventory::INVENTORY,
+ item->getInvIndex(),
+ amount,
+ Inventory::STORAGE);
+ }
else
- args.clear();
-
- if (args.empty())
{
ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
inventoryWindow, item);
return true;
}
-
- if (args[0] == '-')
- {
- if (args.size() > 1)
- {
- amount = item->getQuantity() - atoi(args.substr(1).c_str());
- if (amount <= 0 || amount > item->getQuantity())
- amount = item->getQuantity();
- }
- }
- else if (args == "/")
- {
- amount = item->getQuantity() / 2;
- }
- else if (args == "all")
- {
- amount = item->getQuantity();
- }
- else
- {
- amount = atoi(args.c_str());
- }
- inventoryHandler->moveItem2(Inventory::INVENTORY,
- item->getInvIndex(),
- amount,
- Inventory::STORAGE);
return true;
}