From 08515585ad0da5ac515c6ad6ac5e49e2362dadb7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Dec 2014 15:50:57 +0300 Subject: 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. --- src/actions/actions.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/actions/actions.cpp') 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; } -- cgit v1.2.3-60-g2f50