summaryrefslogtreecommitdiff
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
parenta3b7888017c387d14e33a2021ed85927b78b776b (diff)
downloadplus-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.gz
plus-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.bz2
plus-7e6d1a6e03052a08fd80ad2589295236ba40a3f1.tar.xz
plus-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.
-rw-r--r--src/actions/actions.cpp50
-rw-r--r--src/actions/actions.h1
-rw-r--r--src/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h9
4 files changed, 52 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
diff --git a/src/actions/actions.h b/src/actions/actions.h
index 0fd1f71c5..1f0346caa 100644
--- a/src/actions/actions.h
+++ b/src/actions/actions.h
@@ -100,6 +100,7 @@ namespace Actions
decHandler(useItemInv);
decHandler(invToStorage);
decHandler(tradeAdd);
+ decHandler(storageToInv);
} // namespace Actions
#undef decHandler
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index 60bbeab61..c0bc6b615 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -507,6 +507,7 @@ namespace InputAction
USE_INV,
INV_TO_STORAGE,
TRADE_ADD,
+ STORAGE_TO_INV,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 26b77a03b..183bb3b6e 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -4306,6 +4306,15 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputCondition::INGAME,
"tradeadd|addtrade",
true},
+ {"keyStorageToInv",
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ Input::GRP_DEFAULT,
+ &Actions::storageToInv,
+ InputAction::NO_VALUE, 50,
+ InputCondition::INGAME,
+ "storagetoinv|storageinv",
+ true},
};
#endif // INPUT_INPUTACTIONMAP_H