diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 10:18:22 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 10:18:22 +0100 |
commit | 798948dbe6f012e194f053c4e862cf697f30b793 (patch) | |
tree | 32c71420d1188f98cfb41b6f0d9536c5fa4bf5a7 /frontend/cmd/put.cpp | |
parent | d7012045bb61f117fb7b9c51ddd03e4c54f25fe6 (diff) |
more WIP (move some Player things to backend)
Diffstat (limited to 'frontend/cmd/put.cpp')
-rw-r--r-- | frontend/cmd/put.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/frontend/cmd/put.cpp b/frontend/cmd/put.cpp index 5460b02..dabac19 100644 --- a/frontend/cmd/put.cpp +++ b/frontend/cmd/put.cpp @@ -1,6 +1,4 @@ -#include <algorithm> - -#include "../Player.h" +#include "../GameController.h" #include "../strings.h" #include "backend/print.h" @@ -8,18 +6,17 @@ using namespace std; -FollowupAction Player::cmd_put(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()); +FollowupAction GameController::cmd_put(string & target_name) { + Location & location = this->player.get_location(); + for (Object * object : this->player.inventory) { + if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue; + + lprtf("Je legt %s neer op de locatie %s.\n", object->get_displayname().c_str(), location.get_name().c_str()); + this->player.inventory.remove(object); + location.add_visible_object(object); return FollowupAction::NONE; } - - lprtf("Je legt %s neer op de locatie %s.\n", (*el)->get_displayname().c_str(), this->location.get_name().c_str()); - this->location.add_visible_object((*el).release()); - this->inventory.erase(el); + lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str()); return FollowupAction::NONE; } |