summaryrefslogtreecommitdiff
path: root/src/actions/actions.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-13 19:31:54 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-13 19:36:23 +0300
commit7e6d1a6e03052a08fd80ad2589295236ba40a3f1 (patch)
tree48090a0feded08f3911fbce4f840c78df1c54541 /src/actions/actions.cpp
parenta3b7888017c387d14e33a2021ed85927b78b776b (diff)
downloadmv-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.gz
mv-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.bz2
mv-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.xz
mv-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.zip
Add chat command for move item from storage to inventory.
New chat command: /storagetoinv INDEX AMOUNT Alias: /storageinv INDEX AMOUNT This command accept ammount if format like /invtostorage.
Diffstat (limited to 'src/actions/actions.cpp')
-rw-r--r--src/actions/actions.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index c29d90a50..1397791d1 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -211,18 +211,31 @@ static Being *findBeing(const std::string &name)
return being;
}
-static Item *getItemByInvIndex(const InputEvent &event)
+static Item *getItemByInvIndex(const InputEvent &event, const int invType)
{
const int index = atoi(event.args.c_str());
- const Inventory *const inv = PlayerInfo::getInventory();
+ const Inventory *inv = nullptr;
+ switch (invType)
+ {
+ case Inventory::STORAGE:
+ inv = PlayerInfo::getStorageInventory();
+ break;
+
+ default:
+ case Inventory::INVENTORY:
+ inv = PlayerInfo::getInventory();
+ break;
+ }
if (inv)
return inv->getItem(index);
return nullptr;
}
-static int getAmountFromEvent(const InputEvent &event, Item *&item0)
+static int getAmountFromEvent(const InputEvent &event,
+ Item *&item0,
+ const int invType)
{
- Item *const item = getItemByInvIndex(event);
+ Item *const item = getItemByInvIndex(event, invType);
item0 = item;
if (!item)
return 0;
@@ -430,7 +443,7 @@ impHandler(dropItemId)
impHandler(dropItemInv)
{
- Item *const item = getItemByInvIndex(event);
+ Item *const item = getItemByInvIndex(event, Inventory::INVENTORY);
if (item && !PlayerInfo::isItemProtected(item->getId()))
{
ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop,
@@ -455,7 +468,7 @@ impHandler(dropItemIdAll)
impHandler(dropItemInvAll)
{
- Item *const item = getItemByInvIndex(event);
+ Item *const item = getItemByInvIndex(event, Inventory::INVENTORY);
if (item && !PlayerInfo::isItemProtected(item->getId()))
PlayerInfo::dropItem(item, item->getQuantity(), true);
return true;
@@ -1418,7 +1431,7 @@ impHandler(useItem)
impHandler(useItemInv)
{
- Item *const item = getItemByInvIndex(event);
+ Item *const item = getItemByInvIndex(event, Inventory::INVENTORY);
PlayerInfo::useEquipItem(item, true);
return true;
}
@@ -1426,7 +1439,7 @@ impHandler(useItemInv)
impHandler(invToStorage)
{
Item *item = nullptr;
- const int amount = getAmountFromEvent(event, item);
+ const int amount = getAmountFromEvent(event, item, Inventory::INVENTORY);
if (amount)
{
inventoryHandler->moveItem2(Inventory::INVENTORY,
@@ -1445,7 +1458,7 @@ impHandler(invToStorage)
impHandler(tradeAdd)
{
Item *item = nullptr;
- const int amount = getAmountFromEvent(event, item);
+ const int amount = getAmountFromEvent(event, item, Inventory::INVENTORY);
if (!item || PlayerInfo::isItemProtected(item->getId()))
return true;
@@ -1461,4 +1474,23 @@ impHandler(tradeAdd)
return true;
}
+impHandler(storageToInv)
+{
+ Item *item = nullptr;
+ const int amount = getAmountFromEvent(event, item, Inventory::STORAGE);
+ if (amount)
+ {
+ inventoryHandler->moveItem2(Inventory::STORAGE,
+ item->getInvIndex(),
+ amount,
+ Inventory::INVENTORY);
+ }
+ else
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
+ storageWindow, item);
+ }
+ return true;
+}
+
} // namespace Actions