diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp index 5be7fdd..5bb325d 100644 --- a/src/saland/GameConsoleCommand.cpp +++ b/src/saland/GameConsoleCommand.cpp @@ -39,8 +39,21 @@ struct ConcoleCommandGiveItem : public ConsoleCommand { error_msg += args.at(2)+ "\" into an integer"; throw std::runtime_error(error_msg); } + if (quantity == 0) { + return std::string("Inventory not touched"); + } + int prevCount = globalData.player.item_inventory[item_name]; globalData.player.item_inventory[item_name] += quantity; - return std::string("Added ")+std::to_string(quantity)+" of "+item_name; + if (quantity > 0) { + return std::string("Added ")+std::to_string(quantity)+" of "+item_name; + } + else { + if (globalData.player.item_inventory[item_name] < 0) { + globalData.player.item_inventory[item_name] = 0; + } + return std::string("Removed ")+std::to_string(prevCount-globalData.player.item_inventory[item_name])+" of "+item_name; + } + } virtual std::string helpMessage() const override { @@ -48,6 +61,7 @@ struct ConcoleCommandGiveItem : public ConsoleCommand { } }; + static ConcoleCommandGiveItem cc_give_item;