aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:34:29 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:34:29 +0100
commit71380426426dffe787d1704a8fd639c4b1bbfad3 (patch)
treef550cc1dfa100e208712e20b4442687cc2a7f157 /frontend/cmd
parenta3c1ba7b49e4c5901d7c9dd917049744ad20fc96 (diff)
cmd_get complete
Diffstat (limited to 'frontend/cmd')
-rw-r--r--frontend/cmd/get.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp
index 77ad727..78c6ec1 100644
--- a/frontend/cmd/get.cpp
+++ b/frontend/cmd/get.cpp
@@ -1,9 +1,38 @@
#include "../Player.h"
+#include "../strings.h"
+#include "../print.h"
+
+#include "backend/GoldObject.h"
+#include "backend/Location.h"
using namespace std;
-FollowupAction Player::cmd_get(string & argv) {
- // TODO
+FollowupAction Player::cmd_get(string & target_name) {
+ unique_ptr<Object> target = nullptr;
+ for (Object * object : this->location.get_objects()) {
+ if (object->get_hidden() == true) continue;
+ if (str_lower(object->get_name()) != str_lower(target_name)) continue;
+ target = unique_ptr<Object>(object);
+ this->location.remove_object(object);
+ break;
+ }
+ if (target == nullptr) {
+ lprtf("Object \"%s\" niet gevonden\n", target_name.c_str());
+ return FollowupAction::NONE;
+ }
+
+ // gold objects are collected and (implicitly) destroyed
+ GoldObject * gold = dynamic_cast<GoldObject *>(target.get());
+ if (gold != nullptr) {
+ int count = gold->get_count();
+ this->gold += count;
+ lprtf("Je bent %d goudstuk%s rijker.\n", count, count == 1 ? "" : "ken");
+ return FollowupAction::NONE;
+ }
+
+ // other objects go in the inventory
+ lprtf("Je voegt %s toe aan je bezit.\n", target->get_displayname());
+ this->inventory.push_back(std::move(target));
return FollowupAction::NONE;
}