diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 22:42:45 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 22:42:45 +0100 |
commit | da92752a5f9ea2c301ae0d541ae28caf3589f097 (patch) | |
tree | d111fd4293efc2a6a8afbe0cd49f29f9e9c98034 | |
parent | ff7390073ad42b9584aa2c509669867edab8c2f6 (diff) |
update view command
-rw-r--r-- | backend/Enemy.cpp | 2 | ||||
-rw-r--r-- | backend/Enemy.h | 2 | ||||
-rw-r--r-- | frontend/Player.cpp | 6 | ||||
-rw-r--r-- | frontend/Player.h | 3 | ||||
-rw-r--r-- | frontend/cmd/view.cpp | 57 |
5 files changed, 64 insertions, 6 deletions
diff --git a/backend/Enemy.cpp b/backend/Enemy.cpp index bb39359..9d3b26d 100644 --- a/backend/Enemy.cpp +++ b/backend/Enemy.cpp @@ -8,3 +8,5 @@ const String & Enemy::get_name() const { return this->name; } void Enemy::set_description(const String & description) { this->description = description; } const String & Enemy::get_description() const { return this->description; } +unsigned Enemy::get_health() const { return this->health_points; } + diff --git a/backend/Enemy.h b/backend/Enemy.h index 3c58c82..ea08864 100644 --- a/backend/Enemy.h +++ b/backend/Enemy.h @@ -8,6 +8,7 @@ public: const String & get_name() const; void set_description(const String & description); const String & get_description() const; + unsigned get_health() const; private: friend class EnemyFactory; @@ -18,5 +19,6 @@ public: private: String name; String description; + unsigned int health_points = 0; }; diff --git a/frontend/Player.cpp b/frontend/Player.cpp index 27c660c..fde85e6 100644 --- a/frontend/Player.cpp +++ b/frontend/Player.cpp @@ -46,11 +46,15 @@ FollowupAction Player::cmd(string & argv) { return FollowupAction::NONE; } -float Player::get_attack() { +float Player::get_attack() const { if (this->cheating) return 1.f; return this->attack_chance; } +unsigned Player::get_health() const { + return this->health_points; +} + void Player::take_damage(unsigned int dmg) { if (this->cheating) return; diff --git a/frontend/Player.h b/frontend/Player.h index 6d333f5..c01c86a 100644 --- a/frontend/Player.h +++ b/frontend/Player.h @@ -41,7 +41,8 @@ public: public: void take_damage(unsigned int dmg); - float get_attack(); + float get_attack() const; + unsigned get_health() const; private: void cmdset_default(); diff --git a/frontend/cmd/view.cpp b/frontend/cmd/view.cpp index a252715..1152efe 100644 --- a/frontend/cmd/view.cpp +++ b/frontend/cmd/view.cpp @@ -2,6 +2,7 @@ #include "../strings.h" #include "backend/print.h" +#include "backend/Location.h" using namespace std; @@ -11,15 +12,63 @@ FollowupAction Player::cmd_view(string & target) { return FollowupAction::NONE; } + // view self if (str_lower(target) == "zelf") { - lprtf("Je hebt %d levenspunten.\n", this->health_points); + lprtf("Je hebt %d levenspunten.\n", this->get_health()); + lprtf("Je hebt een aanvalskans van %.0f%%.\n", this->get_attack() * 100); - // TODO: weapon - // TODO: armor + + if (this->weapon == nullptr) + lprtf("Je hebt geen wapen vast.\n"); + else + lprtf("Je hebt het volgende wapen vast: %s.\n", this->weapon->get_displayname().c_str()); + + if (this->armor == nullptr) + lprtf("Je draagt geen wapenrusting.\n"); + else + lprtf("Je draagt de volgende wapenrusting: %s.\n", this->armor->get_displayname().c_str()); + lprtf("Je hebt %u goundstuk%s.\n", this->gold, this->gold == 1 ? "" : "ken"); - // TODO: inventory + + size_t items = this->inventory.size(); + lprtf("Je hebt %d overige object%s%s\n", items, items == 1 ? "" : "en", items > 0 ? ":" : "."); + for (auto & object : this->inventory) { + lprtf("- %s\n", object->get_displayname().c_str()); + } + + return FollowupAction::NONE; + } + + // try to find visible object in location + for (Object * object : this->location.get_visible_objects()) { + if (str_lower(object->get_name().c_str()) != str_lower(target)) continue; + + lprtf("%s\n", object->get_description().c_str()); + return FollowupAction::NONE; + } + + // try to find object in inventory + for (auto & object : this->inventory) { + if (str_lower(object->get_name().c_str()) != str_lower(target)) continue; + + lprtf("%s\n", object->get_description().c_str()); + return FollowupAction::NONE; + } + + // try to find enemy by name + for (Enemy * enemy : this->location.get_enemies()) { + if (str_lower(enemy->get_name().c_str()) != str_lower(target)) continue; + + lprtf("%s\n", enemy->get_description().c_str()); + unsigned enemy_health = enemy->get_health(); + lprtf("%s heeft %s levenspunten.\n", enemy->get_name().c_str(), enemy_health); + // IF enemy_health == 0: + // TODO: show enemy hidden objects + // TODO: move enemy hidden objects to location visible objects + return FollowupAction::NONE; } + lprtf("Fout, geen entiteit met naam \"%s\" gevonden.\n", target.c_str()); return FollowupAction::NONE; } |