aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 08:29:14 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 08:29:14 +0100
commita0e14fa424494ed35da1bd6e5e54bb36178259a7 (patch)
treead167a6d489931bad90c41f1fd47e51cb7d3c3b0 /frontend/cmd
parentda92752a5f9ea2c301ae0d541ae28caf3589f097 (diff)
implement put command
Diffstat (limited to 'frontend/cmd')
-rw-r--r--frontend/cmd/get.cpp2
-rw-r--r--frontend/cmd/put.cpp20
2 files changed, 19 insertions, 3 deletions
diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp
index 2a35657..0d6d12c 100644
--- a/frontend/cmd/get.cpp
+++ b/frontend/cmd/get.cpp
@@ -15,7 +15,7 @@ FollowupAction Player::cmd_get(string & target_name) {
break;
}
if (target == nullptr) {
- lprtf("Object \"%s\" niet gevonden\n", target_name.c_str());
+ lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str());
return FollowupAction::NONE;
}
this->location.remove_visible_object(target.get());
diff --git a/frontend/cmd/put.cpp b/frontend/cmd/put.cpp
index 6e7002b..5460b02 100644
--- a/frontend/cmd/put.cpp
+++ b/frontend/cmd/put.cpp
@@ -1,9 +1,25 @@
+#include <algorithm>
+
#include "../Player.h"
+#include "../strings.h"
+
+#include "backend/print.h"
+#include "backend/Location.h"
using namespace std;
-FollowupAction Player::cmd_put(string & argv) {
- // TODO
+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());
+ 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);
return FollowupAction::NONE;
}