Ejemplo n.º 1
0
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;
		}
	}
}
Ejemplo n.º 2
0
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);
			}
		}
	}
}
Ejemplo n.º 3
0
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?!?!");
    }
}