blob: 8f37c0cac55bbcc438b60bc53150c4d635cbc793 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include "backend/ListIterator.h"
#include "backend/Dungeon.h"
#include "backend/Exception.h"
#include "../GameController.h"
#include "../util.h"
using namespace std;
void GameController::cmd_equip(string & target_name) {
Player & player = this->dungeon->get_player();
auto it = find_if_range(player.inventory.range(), by_name_case_insensitive(target_name));
if (!it)
throw Exception("object \"%s\" niet gevonden", target_name.c_str());
Object & object = **it;
try {
WeaponObject & weapon = dynamic_cast<WeaponObject &>(object);
player.inventory.remove(&weapon);
player.equip(&weapon);
this->dungeon->update();
return;
} catch (std::bad_cast &) {};
try {
ArmorObject & armor = dynamic_cast<ArmorObject &>(object);
player.inventory.remove(&armor);
player.equip(&armor);
this->dungeon->update();
return;
} catch (std::bad_cast &) {};
throw Exception("object \"%s\" is niet draagbaar", target_name.c_str());
}
|