Source

zorkish / commands / TakeCommand.hpp

/*
 * TakeCommand.hpp
 *
 *  Created on: 11/09/2012
 *      Author: rhys
 */

#ifndef TAKECOMMAND_HPP_
#define TAKECOMMAND_HPP_

#include "../Command.hpp"

class TakeCommand : public Command {
public:
    virtual ~TakeCommand() = default;

    virtual std::string run(std::string params, World&, Player& player) {
        if (params.empty()) {
            return "You must specify an item.";
        }

        std::stringstream ss;
        auto it = player.current_location()->inv.take(params);
        if (it) {
            ss << "You pick up " << it->short_name() << ".";
            player.inv.add(std::move(it));
        } else {
            ss << "There is no " << params << " here.";
        }

        return ss.str();
    }
};

#endif /* TAKECOMMAND_HPP_ */