summaryrefslogtreecommitdiff
path: root/src/actions/actions.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-13 15:50:57 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-13 15:55:23 +0300
commit08515585ad0da5ac515c6ad6ac5e49e2362dadb7 (patch)
treefcbef741960600edb287f96e1fba5cb477ad82a6 /src/actions/actions.cpp
parentbfdbe997d3d27ad447a4422e1ccc45e43cfa8e7e (diff)
downloadmv-08515585ad0da5ac515c6ad6ac5e49e2362dadb7.tar.gz
mv-08515585ad0da5ac515c6ad6ac5e49e2362dadb7.tar.bz2
mv-08515585ad0da5ac515c6ad6ac5e49e2362dadb7.tar.xz
mv-08515585ad0da5ac515c6ad6ac5e49e2362dadb7.zip
Extend chat command invtostorage with amount parameter.
Examples: /invtostorage - ask player about amount. /invtostorage 5 10 - store 10 amount of index 5. /invtostorage 5 -2 - store all except 2 of index 5. /invtostorage 5 / - store half of index 5. /invtostorage 5 all - store all of index 5.
Diffstat (limited to 'src/actions/actions.cpp')
-rw-r--r--src/actions/actions.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 36a463da5..dce003cc0 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -1388,8 +1388,50 @@ impHandler(useItemInv)
impHandler(invToStorage)
{
Item *const item = getItemByInvIndex(event);
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
- inventoryWindow, item);
+ if (!item)
+ return true;
+
+ std::string args = event.args;
+ int amount = 0;
+
+ int idx = args.find(" ");
+ if (idx > 0)
+ args = args.substr(idx + 1);
+ 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;
}