void Player::useItemInvent(Item * pIt) { bool cast = false; //Is consumable Consumable * cons = dynamic_cast<Consumable*>(pIt); if (cons != NULL) { cons->use(static_cast<Character*>(this)); delete cons; cast = true; } //Is Equipment if (!cast) { Equipment * pEquip = dynamic_cast<Equipment*>(pIt); if (pEquip != NULL) { equip(pEquip); cast = true; } } }
double Schematic::getProfitPercentage(bool perHour) { double negative = 0; double positive= 0; int consumableQuatity; double buyPrice; double importCost; int productQuatity = product->getQuantity(); double sellPrice = product->getComponent()->getSellPrice(); double exportCost = product->getComponent()->getExportCost(); if (0 == sellPrice) { return 0; } if (perHour) { productQuatity = cycleTime == 3600 ? productQuatity : productQuatity * 2; } positive = (productQuatity * sellPrice) - (productQuatity * exportCost); Consumable *consumable; for (auto it = consumables.begin(), end = consumables.end(); it != end; ++it) { consumable = it.value(); consumableQuatity = consumable->getQuantity(); buyPrice = consumable->getComponent()->getBuyPrice(); importCost = consumable->getComponent()->getImportCost(); if (perHour) { consumableQuatity = cycleTime == 3600 ? consumableQuatity : consumableQuatity * 2; } consumable = it.value(); negative += (consumableQuatity * buyPrice) + (consumableQuatity * importCost); } if (0 == positive || 0 == negative) { return 0; } double profit = (positive - negative) * 100 / positive; if (cycleTime == 1800) { profit *= 2; } return profit; }
void Player::use(Floor * fl) { //Fetch the vector of items that is currently on the ground and attempt to use all of them vector<Item *> & items = fl->getMap()[getRow()][getCol()]->getItems(); for (int i = 0; i < items.size(); i++) { bool cast = false; Item * pIt = items[i]; //Is consumable Consumable * cons = dynamic_cast<Consumable*>(pIt); if (cons != NULL) { cons->use(static_cast<Character*>(this)); fl->getMap()[getRow()][getCol()]->removeItem(i); cast = true; } //Is Equipment if (!cast) { Equipment * pEquip = dynamic_cast<Equipment*>(pIt); if (pEquip != NULL) { equip(pEquip); fl->getMap()[getRow()][getCol()]->removeItem(i); cast = true; } //Else add to inventory if (!cast) { if (pIt->getName() == "The Holy Grail") { cout << "You have found the mythical holy grail! You are truly the greatest explorer to grace our epoch!" << endl; } vInventory.push_back(pIt); fl->getMap()[getRow()][getCol()]->removeItem(i); } } } }
void Player::initCommands() { std::function<void (std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)>)> addCommands = [this](std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)> operation){ if(commandWords.size() < 1) { throw std::invalid_argument("You must at least have one word associated with the command"); } uniqueCommands.push_back(commandWords.front()); for(std::string word: commandWords){ if(commands.find(word) != commands.end()) { throw std::invalid_argument("The word: " + word + " is associated with more than one command"); } commands[word] = operation; } }; std::function<bool (const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands)> isHelp = [](const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands){ if(commands.size() != 2){ return false; }; if(commands[1] != "help"){ return false; }; std::cout << TEXT_DIVIDER << " HELP: " << commands[0] << " " << TEXT_DIVIDER << std::endl; if(helpText != "") { std::cout << helpText << std::endl; } std::cout << "Usage: " << commands[0] << " " << usageCommands << std::endl; return true; }; addCommands({"go", "move", "goto"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Used for navigating through the world.", "LOCATION")) { return false; } if(commands.size() != 2) { std::cout << "You forgot to write where you wanna go." << std::endl; return false; } int num = -1; try { num = atoi(commands[1].c_str()) - 1; } catch(int) { std::cout << "That is not an option. Write one of the numbers given as option." << std::endl; return false; } auto dirs = getEnvironment()->getDirections(); if(num >= dirs.size()) { std::cout << "That is not an option. Write one of the numbers given as option." << std::endl; return false; } if(!this->move(dirs[num])) { std::cout << "That is not an option. Write one of the numbers given as option." << std::endl; return false; } return true; }); addCommands({"look"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Look for example at different characters or on items to get more information. You can look at almost anything in the world.", "[CONTAINER] [OBJECT]")) { return false;} Environment * env = getEnvironment(); if(commands.size() == 1) { printUpdateInfo(); } else if(commands.size() == 2) { if(isCommandInventory(commands[1])) { std::cout << getInventory()->getDescription() << std::endl; return false; } if(isCommandEquipment(commands[1])) { std::cout << getEquipment()->getDescription() << std::endl; return false; } PhysicalObject * physicalObject = env->find(commands[1]); if(physicalObject == NULL) { std::cout << "Found no item named: " << commands[1] << std::endl; } else { std::cout << physicalObject->getDescription() << std::endl; } } else if(commands.size() == 3) { Item * item = NULL; if(isCommandInventory(commands[1])) { Inventory * inv = getInventory(); item = inv->find(commands[2]); if(item == NULL) { std::cout << "Found no item named: " << commands[2] << " in your inventory." << std::endl; return false; } } else if(isCommandEquipment(commands[1])) { Equipment * eq = getEquipment(); item = eq->find(commands[2]); if(item == NULL) { std::cout << "Found no item named: " << commands[2] << " in your equipment." << std::endl; return false; } } else { Container * con = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[2]); if(con == NULL) { std::cout << "Found no container named: " <<commands[1] << std::endl; return false; } else { item = con->find(commands[2]); if(item == NULL) { std::cout << "Found no item named: " << commands[2] << " in container: " << con->getName() << std::endl; return false; } } } std::cout << item->getDescription() << std::endl; } return false; }); addCommands({"stats"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Get information about you.", "")) { return false;} std::cout << getDescription() << std::endl; return false; }); addCommands({"inventory", "backpack", "inv"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Get information about your inventory that contains items.", "")) { return false;} Inventory * inv = getInventory(); std::cout << inv->getDescription() << std::endl; return false; }); addCommands({"equipment"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Get information about your current equipment.", "")) { return false;} Equipment * eq = getEquipment(); std::cout << eq->getDescription() << std::endl; return false; }); addCommands({"pick"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Pick up items from the ground or from containers like for example Chests.", "[CONTAINER] ITEM")) { return false;} if(commands.size() < 2) { std::cout << "You forgot to write what you wanted to pick up." << std::endl; return false; } Environment * env = getEnvironment(); if(commands.size() == 2) { Item * item = env->find<Item>(OBJECT_TYPE_ITEM, commands[1]); if(item == NULL) { std::cout << "Found no item named: " << commands[1] << std::endl; return false; } if(!pickItem(item)) { std::cout << "You can't pick up item: " << commands[1] << std::endl; return false; } std::cout << "You picked up item: " << commands[1] << std::endl; return false; } else if(commands.size() == 3) { Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]); if(container == NULL) { std::cout << "Found no container named: " <<commands[1] << std::endl; return false; } Item * item = container->find<Item>(OBJECT_TYPE_ITEM, commands[2]); if(item == NULL) { std::cout << "Found no item named: " << commands[2] << " in container: " << commands[1] << std::endl; return false; } if(!pickItem(item, container)) { std::cout << "You can't pick up item: " << commands[2] << " in container: " << commands[1] << std::endl; return false; } std::cout << "You picked up item: " << commands[2] << " from container: " << commands[1]<< std::endl; return false; } std::cout << "Invalid command syntax. Usage: pick [CONTAINER] ITEM" << std::endl; return false; }); addCommands({"drop", "put"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Drop items on the ground or drop them into containers.", "[CONTAINER] ITEM")) { return false;} if(commands.size() < 2) { std::cout << "You forgot to write what you wanted to drop." << std::endl; return false; } Inventory * inv = getInventory(); if(commands.size() == 2) { Item * item = inv->find(commands[1]); if(item == NULL) { std::cout << "Found no item named: " << commands[1] << " in your inventory." << std::endl; return false; } if(!dropItem(item)) { std::cout << "You can't drop item: " << commands[1] << " from your inventory. " << std::endl; return false; } std::cout << "You dropped item: " << commands[1] << " from your inventory. " << std::endl; return false; } else if(commands.size() == 3) { Environment * env = getEnvironment(); Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]); if(container == NULL) { std::cout << "Found no container named: " <<commands[1] << std::endl; return false; } Item * item = inv->find(commands[2]); if(item == NULL) { std::cout << "Found no item named: " << commands[2] << " in your inventory." << std::endl; return false; } if(!putItem(item, container)) { std::cout << "You can't put item: " << commands[2] << " in container: " << commands[1] << std::endl; return false; } std::cout << "You put item: " << commands[2] << " in container: " << commands[1] << std::endl; return false; } std::cout << "Invalid command syntax. Usage: drop [CONTAINER] ITEM" << std::endl; return false; }); addCommands({"open"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"The same as 'look CONTAINER'.", "CONTAINER")) { return false;} if(commands.size() != 2) { std::cout << "You forgot to write what you wanted to open." << std::endl; return false; } Environment * env = getEnvironment(); Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]); if(container == NULL) { std::cout << "Found no container named: " <<commands[1] << std::endl; return false; } int takenSpace = container->getTakenSpace(); std::string takenSpaceText = unsignedValToString(takenSpace); std::cout << container->getDescription() << std::endl; return false; }); addCommands({"unlock"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Unlock containers or items using this command.", "[CONTAINER] LOCKED_OBJECT KEY")) { return false;} Environment * env = getEnvironment(); Inventory * inv = getInventory(); if(commands.size() < 3 || commands.size() > 4) { std::cout << "Invalid command syntax. Usage: unlock [CONTAINER] LOCKED_OBJECT KEY" << std::endl; return false; } KeyLock * lock = NULL; std::string containerString; std::string lockString; std::string keyString; if(commands.size() == 4) { lockString = commands[2]; keyString = commands[3]; Container * con; if(isCommandInventory(commands[1])) { con = inv; } else { con = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]); } if(con == NULL) { std::cout << "Found no container named: " << commands[1] << std::endl; return false; } lock = dynamic_cast<KeyLock *>(con->find(commands[1])); containerString = " in container named: " + con->getName(); } else if(commands.size() == 3) { containerString = ""; lockString = commands[1]; keyString = commands[2]; lock = dynamic_cast<KeyLock *>(env->find(commands[1])); } if(lock == NULL) { std::cout << "Found no lockable object named: " << lockString << containerString << std::endl; return false; } Key * key = inv->find<Key>(OBJECT_TYPE_ITEM, ITEM_TYPE_KEY, keyString); if(key == NULL) { std::cout << "Found no key named: " << keyString << " in your inventory."<< std::endl; return false; } std::string keyName = key->getName(); PhysicalObject * test = dynamic_cast<PhysicalObject*>(lock); // Needed because not strictly if(test == nullptr) { throw std::runtime_error("The lockable item was not a PhysicalObject. Should not be possible."); } std::string lockName = test->getName(); if(lock->unlock(key, *inv)) { std::cout << "You unlocked: " << lockName << containerString << " using key: " << keyName << std::endl; return false; } else { std::cout << "You can't unlock: " << lockName << containerString << " using key: " << keyName << std::endl; return false; } }); addCommands({"eat", "drink"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Use this command to consume items. Tip: Write 'drink' so you don't accidentally chew liquids.", "ITEM")) { return false;} if(commands.size() != 2) { std::cout << "Invalid command syntax. Usage: eat FOOD" << std::endl; return false; } Consumable * cItem = getInventory()->find<Consumable>(OBJECT_TYPE_ITEM, ITEM_TYPE_CONSUMABLE, commands[1]); if(cItem == NULL) { std::cout << "Found no consumable item named: " << commands[1] << " in your inventory."<< std::endl; return false; } std::string consumableName = cItem->getName(); std::string response = cItem->consume(this); std::cout << "You digested " << consumableName << " and " << response << std::endl; return false; }); addCommands({"equip", "eq"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "Used for equipping items. You can only equip one of each type of equippable item.", "[ITEM]")) { return false;} if(commands.size() != 2) { std::cout << "Invalid command syntax. Usage: equip ITEM" << std::endl; return false; } Inventory * inv = getInventory(); Item * item = inv->find(commands[1]); if(item == NULL) { std::cout << "Found no equipable item named: " << commands[1] << std::endl; return false; } BreakableItem * bItem = dynamic_cast<BreakableItem*>(item); if(bItem == nullptr) { std::cout << "The item: " << item->getName() << " is not equipable." << std::endl; return false; } if(equip(bItem)) { std::cout << "You equipeed item: " << bItem->getName() << std::endl; return false; } else { std::cout << "You failed to equip: " << bItem->getName() << std::endl; return false; } }); addCommands({"unequip", "uneq", "ueq"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Used for removing equipped items and putting them back to your inventory, if you have enough space.", "ITEM")) { return false;} if(commands.size() != 2) { std::cout << "Invalid command syntax. Usage: equip ITEM" << std::endl; return false; } Equipment * eq = getEquipment(); BreakableItem * bItem = eq->find(commands[1]); if(bItem == NULL) { std::cout << "Found no equiped item named: " << commands[1] << std::endl; return false; } if(unEquip(bItem)) { std::cout << "You unequiped item: " << bItem->getName() << std::endl; return false; } else { std::cout << "You failed to unequip: " << bItem->getName() << std::endl; return false; } }); addCommands({"attack", "att"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands, "KILL!", "CHARACTER")) { return false;} if(commands.size() != 2) { std::cout << "You forgot to write what you wanted to attack." << std::endl; return false; } Character * character = getEnvironment()->find<Character>(OBJECT_TYPE_CHARACTER, commands[1], {this}); if(character == NULL) { std::cout << "There is no " + commands[1] << " in the area." << std::endl; return false; } if(!character->startInteraction(this)) { std::cout << "The " << character->getName() << " busy fighting already." << std::endl; return false; } std::cout << std::endl << "You are initiating a fight with " << character->getName() << "!" << std::endl; interact(character); character->endInteraction(this); endInteraction(character); return true; }); addCommands({"pass", "wait", "skip"}, [isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Wait a moment and let others take their turn.", "")) { return false;} return true; }); addCommands({"exit"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Exit the game. No turning back after this.", "")) { return false;} this->getEngine()->kill(); return true; }); addCommands({"help"}, [this, isHelp](const std::vector<std::string> & commands) -> bool { if(isHelp(commands,"Helpception?", "")) { return false;} std::cout << std::endl; std::cout << TEXT_DIVIDER << " HELP START " << TEXT_DIVIDER << std::endl; std::cout << "For more help on individual commands, write: COMMAND help" << std::endl; std::cout << "COMMANDS" << std::endl; std::cout << TEXT_DIVIDER << std::endl; for(auto command : getUniqueCommands()) { std::cout << command << std::endl; } std::cout << TEXT_DIVIDER << " HELP END " << TEXT_DIVIDER << std::endl; return false; }); }
void InventoryView::HandleItemSelection() { Player* p = DataManager::Instance()->GetPlayer(); Inventory& inv = p->GetInventory(); if(m_inInventoryArea) { if(inv.NumItems() > 0) { Item* toUse = inv.ItemAtIndex(m_selectIdx); Item* oldItem = NULL; if(!toUse->CanUse()) { stringstream s; s << toUse->GetDisplayName() << " requires level " << toUse->GetRequiredLevel(); string toDisp = s.str(); DataManager::Instance()->AppendStatusString(toDisp); return; } switch(toUse->GetClass()) { case E_HELM: inv.RemoveItem(toUse); oldItem = p->GetHeadItem(); p->SetHeadItem((ArmorItem*)toUse); if(oldItem) { inv.AddItem(oldItem); } break; case E_BODY: inv.RemoveItem(toUse); oldItem = p->GetBodyItem(); p->SetBodyItem((ArmorItem*)toUse); if(oldItem) { inv.AddItem(oldItem); } break; case E_LEGS: inv.RemoveItem(toUse); oldItem = p->GetLegsItem(); p->SetLegsItem((ArmorItem*)toUse); if(oldItem) { inv.AddItem(oldItem); } break; case E_WEAPON: inv.RemoveItem(toUse); oldItem = p->GetWeaponItem(); p->SetWeaponItem((Weapon*)toUse); if(oldItem) { inv.AddItem(oldItem); } break; case E_IMPLANT: inv.RemoveItem(toUse); oldItem = p->GetImplantItem(); p->SetImplantItem((Implant*)toUse); if(oldItem) { inv.AddItem(oldItem); } break; case E_CONSUMABLE: if(toUse->CanStack()) { Consumable* c = (Consumable*)toUse; c->ApplyEffect(); if(toUse->GetStackSize() < 1) { inv.RemoveItem(toUse); } } break; default: break; } } } else { switch(m_selectIdx) { case 0: p->ReturnHeadItemToInventory(); break; case 1: p->ReturnBodyItemToInventory(); break; case 2: p->ReturnLegsItemToInventory(); break; case 3: p->ReturnWeaponItemToInventory(); break; case 4: p->ReturnImplantItemToInventory(); break; } } }
void MenuInventory::getViewScreen() { DM::say("Gear:"); Player *player = _game->getPlayer(); Weapon *main = player->getMainWeapon(); if (main) { int base = player->getStrength(); string type = ""; switch (main->getWeaponType()) { case WeaponType::SIMPLE: type = "Simple Weapon"; break; case WeaponType::FINESSE: if (player->getDexterity() > player->getStrength()) { base = player->getDexterity(); } type = "Finesse Weapon"; break; case WeaponType::MARTIAL: type = "Martial Weapon"; break; case WeaponType::HEAVY: type = "heavy Weapon"; break; case WeaponType::SHIELD: type = "Shield"; break; } DM::say("\t<Main> Weapon: " + main->getName() + " (" + to_string(main->getDiceAmount()) + "d" + to_string(main->getDiceSize()) + "+" + to_string(base) + " " + type + ")"); } else { DM::say("\t<Main> Weapon: None"); } Weapon *off = player->getOffHandWeapon(); if (off) { int base = player->getStrength(); string type = ""; switch (off->getWeaponType()) { case WeaponType::SIMPLE: type = "Simple Weapon"; break; case WeaponType::FINESSE: if (player->getDexterity() > player->getStrength()) { base = player->getDexterity(); } type = "Finesse Weapon"; break; case WeaponType::MARTIAL: type = "Martial Weapon"; break; case WeaponType::HEAVY: type = "heavy Weapon"; break; case WeaponType::SHIELD: type = "Shield (+2AC)"; break; } DM::say("\t<Off>hand Weapon: " + off->getName() + " (" + to_string(off->getDiceAmount()) + "d" + to_string(off->getDiceSize()) + "+" + to_string(base) + " " + type + ")"); } else { DM::say("\t<Off>hand Weapon: None"); } Armor *armor = player->getArmor(); if (armor) { string extra = ""; switch (armor->getArmorType()) { case ArmorType::LIGHT: extra = " + Dex "; break; case ArmorType::MEDIUM: extra = " + max 2 Dex "; break; case ArmorType::HEAVY: break; } DM::say("\t<Armor>: " + armor->getName() + " ( AC: " + to_string(armor->getBaseAC()) + extra + ")"); } else { DM::say("\t<Armor>: None"); } DM::say("\nInventory:"); int i = 1; for (map<Item *, int>::iterator item = _inventory->begin(); item != _inventory->end(); ++item) { switch (item->first->getItemType()) { case ItemType::ARMOR: { Armor *armor = (Armor *) item->first; string extra = ""; switch (armor->getArmorType()) { case ArmorType::LIGHT: extra = " + Dex "; break; case ArmorType::MEDIUM: extra = " + max 2 Dex "; break; case ArmorType::HEAVY: break; } DM::say("\t[" + to_string(i) + "]: " + item->first->getName() + " - AC: " + to_string(armor->getBaseAC()) + extra + "(" + to_string(item->second) + "x)"); break; } case ItemType::WEAPON: { Weapon *weapon = (Weapon *) item->first; string type = ""; switch (weapon->getWeaponType()) { case WeaponType::SIMPLE: type = "Simple Weapon"; break; case WeaponType::FINESSE: type = "Finesse Weapon"; break; case WeaponType::MARTIAL: type = "Martial Weapon"; break; case WeaponType::HEAVY: type = "heavy Weapon"; break; case WeaponType::SHIELD: type = "Shield (+2AC)"; break; } DM::say("\t[" + to_string(i) + "]: " + item->first->getName() + " - " + type + " - " + to_string(weapon->getDiceAmount()) + "d" + to_string(weapon->getDiceSize()) + " dmg (" + to_string(item->second) + "x)"); break; } case ItemType::CONSUMABLE: { Consumable *consumable = (Consumable *) item->first; string type = ""; string effect = ""; switch (consumable->getConsumableType()) { case ConsumableType::FOOD: type = "Food"; effect = "hp max per rest"; break; case ConsumableType::HEALING: type = "Healing item"; effect = "hp max on use"; break; case ConsumableType::ILLUMINATION: type = "Illumination"; effect = "room(s) of light"; break; case ConsumableType::BOMB: type = "Bomb"; if (consumable->getDiceAmount() == 0) { effect = "cave-in(s)"; } else { effect = "probable cave-in(s)"; } break; case ConsumableType::TALISMAN: type = "Talisman"; effect = "maximum distance to exit"; break; } if (consumable->getDiceAmount() == 0) { DM::say("\t[" + to_string(i) + "]: " + consumable->getName() + " - " + type + " - " + to_string(consumable->getBaseValue()) + " " + effect + " (" + to_string(item->second) + "x)"); } else { DM::say("\t[" + to_string(i) + "]: " + consumable->getName() + " - " + type + " - " + to_string(consumable->getDiceAmount()) + "d" + to_string(consumable->getDiceSize()) + "+" + to_string(consumable->getBaseValue()) + " " + effect + " (" + to_string(item->second) + "x)"); } break; } } ++i; } if (i == 1) { DM::say("\tNo items"); } }
void MenuInventory::handleInput(std::string input) { if (regex_match(input, regex("b|back"))) { _game->changeState(GameState::ROAMING); } else if (regex_match(input, regex("(e|equip)"))) { DM::say("Equip what?"); _state = InventoryState::EQUIP; } else if (regex_match(input, regex("(d|drop)"))) { DM::say("Drop what?"); _state = InventoryState::DROP; } else if (regex_match(input, regex("(u|use)"))) { DM::say("Use what?"); _state = InventoryState::USE; } else if (regex_match(input, regex("(unequip)"))) { DM::say("Unequip what?"); _state = InventoryState::UNEQUIP; } else if (_state == InventoryState::UNEQUIP && regex_match(input, regex("^\\w+$"))) { if (regex_match(input, regex("(m|main|Main)"))) { _game->getPlayer()->unequip(_game->getPlayer()->getMainWeapon()); } else if (regex_match(input, regex("(o|off|Off)"))) { _game->getPlayer()->unequip(_game->getPlayer()->getOffHandWeapon()); } else if (regex_match(input, regex("(a|armor|Armor)"))) { _game->getPlayer()->unequip(_game->getPlayer()->getArmor()); } _state = InventoryState::STANDBY; } else if (_state != InventoryState::STANDBY && _state != InventoryState::UNEQUIP && regex_match(input, regex("^\\d+$"))) { int x = stoi(input); int i = 1; for (map<Item *, int>::iterator item = _inventory->begin(); item != _inventory->end(); item++) { bool done = false; if (x == i) { done = true; if (item->second > 0) { switch (_state) { case InventoryState::STANDBY: DM::say("You want to put WHAT WHERE?!?!"); break; case InventoryState::EQUIP: if (item->first->getItemType() != ItemType::CONSUMABLE) { Player *player = _game->getPlayer(); player->equip(item->first); item->second -= 1; if (item->second == 0) { _inventory->erase(item->first); } } else { DM::say("You want to put WHAT WHERE?!?!"); } break; case InventoryState::USE: if (item->first->getItemType() == ItemType::CONSUMABLE) { Consumable *consumable = (Consumable *) item->first; if (consumable->getConsumableType() == ConsumableType::BOMB) { if (_game->getCurrentRoom()->hasLivingMonsters()) { if (consumable->explode(_game->getCurrentFloor(), _game->getPlayer()->getCurrentRoom())) { DM::say(_game->getPlayer()->getName() + " used a(n) " + consumable->getName() + "."); item->second -= 1; if (item->second == 0) { _inventory->erase(item->first); } } else { DM::say("This " + consumable->getName() + " may be a bit too much to handle with the current unstable state of the dungeon...."); } } else { DM::say("EY!! Don't go ruining my beautifull dungeon with a bomb without even a single monster to kill with it."); } } else { consumable->use(_game->getPlayer()); item->second -= 1; if (item->second == 0) { _inventory->erase(item->first); } } } else { DM::say("You want to put WHAT WHERE?!?!"); } break; case InventoryState::DROP: DM::say("Dropped a(n) " + item->first->getName()); _game->getCurrentRoom()->addItemToLootList(item->first); item->second -= 1; if (item->second == 0) { _inventory->erase(item->first); } break; } } else { DM::say("You seem to have nothing left of this."); } } if (done) { break; } ++i; } _state = InventoryState::STANDBY; } else { DM::say("You want to put WHAT WHERE?!?!"); } }