aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/equip.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
commitb20f46c15dce8b196dbb8890890978947745e094 (patch)
treed9defa84717ffa843fd11b05d0e856473d6d8d59 /frontend/cmd/equip.cpp
parenta7e84b60366c78b131d43157980fbe4c2df655e6 (diff)
change flow architecture
Diffstat (limited to 'frontend/cmd/equip.cpp')
-rw-r--r--frontend/cmd/equip.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/frontend/cmd/equip.cpp b/frontend/cmd/equip.cpp
index 25a375f..578db0e 100644
--- a/frontend/cmd/equip.cpp
+++ b/frontend/cmd/equip.cpp
@@ -1,33 +1,35 @@
-#include "backend/print.h"
#include "backend/ListIterator.h"
+#include "backend/Dungeon.h"
#include "../GameController.h"
#include "../strings.h"
+#include "../Exception.h"
using namespace std;
-FollowupAction GameController::cmd_equip(string & target_name) {
- for (Object * object : this->player.inventory) {
+void GameController::cmd_equip(string & target_name) {
+ Player & player = this->dungeon->get_player();
+ for (Object * object : player.inventory) {
if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue;
WeaponObject * weapon = dynamic_cast<WeaponObject *>(object);
if (weapon != nullptr) {
- this->player.inventory.remove(weapon);
- this->player.equip(weapon);
- return FollowupAction::UPDATE;
+ player.inventory.remove(weapon);
+ player.equip(weapon);
+ this->dungeon->update();
+ return;
}
ArmorObject * armor = dynamic_cast<ArmorObject *>(object);
if (armor != nullptr) {
- this->player.inventory.remove(armor);
- this->player.equip(armor);
- return FollowupAction::UPDATE;
+ player.inventory.remove(armor);
+ player.equip(armor);
+ this->dungeon->update();
+ return;
}
- lprtf("Object %s is niet draagbaar.\n", target_name.c_str());
- return FollowupAction::NONE;
+ throw Exception("Object \"%s\" is niet draagbaar.", target_name.c_str());
}
- lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str());
- return FollowupAction::NONE;
+ throw Exception("Object \"%s\" niet gevonden.", target_name.c_str());
}