-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.cpp
56 lines (41 loc) · 1.33 KB
/
Monster.cpp
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
#include <iostream>
#include "json.hpp"
#include "Monster.h"
using json = nlohmann::json;
using namespace std;
Monster::Monster() : Unit("", 0, INVALID_STANCE, 0, 0, DeathEffects(0, 0, 0, 0, 0)){}
Monster::Monster(json j) :
Unit(j["Name"], j["Health"], get_stance_val(j["Stance"]), j["Speed"], j["Location"], DeathEffects(j["Death Effects"])) {
_base_health = get_health();
_attack = j["Attack"];
}
Monster::Monster(string name, int health, int speed, int stance, int attack, node_id_t location, DeathEffects effects) :
Unit(name, health, stance, speed, location, effects){
_base_health = health;
_attack = attack;
}
bool Monster::is_player(){
return false;
}
bool Monster::is_monster() {
return true;
}
string Monster::get_string() {
return "Name: " + get_name() + ", health = " + to_string(get_health()) + ", movement_counter = " + to_string(get_movement_counter());
}
json Monster::to_json() {
json j = Unit::to_json();
j["Type"] = "Monster";
j["Base Health"] = _base_health;
j["Attack"] = _attack;
return j;
}
void Monster::attack(Unit* other) {
other->set_health(other->get_health() - _attack);
}
void Monster::decrement_movement_counter() {
Unit::decrement_movement_counter();
if (time_to_move() && dead()) {
revive(_base_health);
}
}