#include #include #include "backend/print.h" #include "../Player.h" #include "../strings.h" using namespace std; FollowupAction Player::cmd_equip(string & target_name) { auto el = find_if(this->inventory.begin(), this->inventory.end(), [target_name](const auto & object) -> bool { return str_lower(object->get_name().c_str()) == str_lower(target_name); }); if (el == this->inventory.end()) { lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str()); return FollowupAction::NONE; } unique_ptr weapon {dynamic_cast((*el).get())}; unique_ptr armor {dynamic_cast((*el).get())}; if (weapon == nullptr && armor == nullptr) { lprtf("Object %s is niet draagbaar.\n", target_name.c_str()); return FollowupAction::NONE; } // remove from inventory w/o free()'ing data (*el).release(); this->inventory.erase(el); if (weapon != nullptr) { lprtf("Je "); if (this->weapon != nullptr) { lprtf("laat %s vallen en ", this->weapon->get_name().c_str()); this->inventory.push_back(std::move(this->weapon)); } this->weapon = std::move(weapon); lprtf("pakt %s vast.\n", this->weapon->get_name().c_str()); } if (armor != nullptr) { lprtf("Je "); if (this->armor != nullptr) { lprtf("trekt %s uit en ", this->armor->get_name().c_str()); this->inventory.push_back(std::move(this->armor)); } this->armor = std::move(armor); lprtf("doet %s aan.\n", this->armor->get_name().c_str()); } return FollowupAction::UPDATE; }