From 71380426426dffe787d1704a8fd639c4b1bbfad3 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 30 Oct 2024 16:34:29 +0100 Subject: cmd_get complete --- frontend/Player.h | 2 ++ frontend/cmd/get.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'frontend') diff --git a/frontend/Player.h b/frontend/Player.h index 09e3a73..6d333f5 100644 --- a/frontend/Player.h +++ b/frontend/Player.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "backend/WeaponObject.h" #include "backend/ArmorObject.h" @@ -29,6 +30,7 @@ private: std::unique_ptr armor = nullptr; Location & location; bool cheating = false; + std::vector> inventory = {}; public: Player(Dungeon & dungeon); 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 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); + 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(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; } -- cgit v1.2.3