aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/view.cpp
blob: 1152efe222dc16c37dce9e04ee5dfaec2d9c1639 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "../Player.h"
#include "../strings.h"

#include "backend/print.h"
#include "backend/Location.h"

using namespace std;

FollowupAction Player::cmd_view(string & target) {
	if (target.size() == 0) {
		lprtf("Fout, gebruik: Bekijk <Zelf|VIJHAND|OBJECT>\n");
		return FollowupAction::NONE;
	}

	// view self
	if (str_lower(target) == "zelf") {
		lprtf("Je hebt %d levenspunten.\n", this->get_health());

		lprtf("Je hebt een aanvalskans van %.0f%%.\n", this->get_attack() * 100);

		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");

		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;
}