-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.hpp
130 lines (99 loc) · 2.9 KB
/
Player.hpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2016 Anton Erholt <aerholt@kth.se>
#ifndef LAB3_PLAYER_HPP_
#define LAB3_PLAYER_HPP_
#include <sstream>
#include "GameObject.hpp"
#include "Actor.hpp"
#include "Race.hpp"
#include "CharacterClass.hpp"
#include "DungeonMap.hpp"
namespace lab3 {
uint64_t player_id;
struct Player: public Actor {
private:
std::string name;
CharacterClass cls;
const Environment *start;
public:
Player(const Environment *start,
DungeonMap *dmap,
std::string name,
const Race *race,
CharacterClass cls) : Actor(start,
dmap,
race),
name(name),
cls(cls),
start(start) {
player_id = Actor::id;
kills = 0;
}
friend class Repl;
const CharacterClass &getCls() const {
return cls;
}
std::string get_name() const {
return name;
}
virtual int getMaxCarryCapacity() const override {
return Actor::getMaxCarryCapacity() + this->kills * 10;
}
virtual void fight(Actor *enemy) override {
uint32_t dmg = this->damage();
enemy->hurt(dmg);
std::stringstream ss;
ss << *enemy->getRace();
this->cls.attack_fn(ss.str(), enemy->getMax_health(), enemy->getCurrent_health(), dmg);
if (!enemy->isDead()) {
std::cout << "The enemy hits you for " << enemy->damage() << " points of damage." << std::endl;
this->hurt(enemy->damage());
} else {
++this->kills;
if (this->kills == 4) {
std::cout <<
"You learned to 'howl'. If you do this, it will give you bonus damage next fighting round." <<
std::endl;
}
}
}
virtual uint32_t damage() {
return Actor::damage() + 7 * kills;
}
virtual void action() override { }
virtual bool take(uint64_t item_id) override {
bool taken = Actor::take(item_id);
Item *item = findItemById(item_id);
if (taken) {
std::cout << "You picked up: " << item->getName() << std::endl;
} else {
if (!this->strongEnoughToCarry(item)) {
std::cout << "You are not strong enough to carry: "
<< item->getName()
<< std::endl;
} else {
std::cout << "No such item here." << std::endl;
}
}
return taken;
}
virtual bool drop(uint64_t item_id) override {
bool dropped = Actor::drop(item_id);
Item * item = findItemById(item_id);
if (dropped) {
std::cout << "You dropped: " << item->getName() << std::endl;
} else {
std::cout << "Unable to drop: " << item->getName() << std::endl;
}
return dropped;
}
void teleport(const Environment *env) {
std::cout << "YOU CHEATER!" << std::endl;
this->position = env;
}
uint32_t kills;
};
Player *getPlayer() {
return dynamic_cast<Player *>(findGameObjectById(player_id));
}
} // namespace lab3
#endif // LAB3_PLAYER_HPP_