aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/hit.cpp
blob: d3cb683514722117164e2ac8e67c233738902cd3 (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
#include "backend/Enemy.h"
#include "backend/Location.h"
#include "backend/RNG.h"
#include "backend/print.h"

#include "../Player.h"
#include "../strings.h"

using namespace std;

FollowupAction Player::cmd_hit(string & target_name) {
	RNG & rng = RNG::get();
	for (Enemy * enemy : this->location.get_enemies()) {
		if (str_lower(enemy->get_name().c_str()) != str_lower(target_name)) continue;

		if (rng.rand_double() > this->get_attack()) {
			lprtf("Je hebt gemist!\n");
		} else {
			unsigned damage = rng.rand_int(this->weapon->get_damage_min(), this->weapon->get_damage_max() + 1);
			enemy->take_damage(damage);
			lprtf("Je hebt %s geraakt en %d schade aangericht!\n", enemy->get_displayname().c_str(), damage);
		}
		return FollowupAction::UPDATE;
	}

	lprtf("Vijand \"%s\" niet gevonden.\n", target_name.c_str());
	return FollowupAction::NONE;
}