-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPC.cpp
100 lines (87 loc) · 2 KB
/
NPC.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
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
#include "NPC.h"
NPC::NPC() :
x(0),
y(0),
alive(true)
{
NPCdef *def = NPCdef::getRandom();
this->hitpoints = def->getHP().Roll();
this->speed = def->getSpeed().Roll();
this->initiative = 100/this->speed;
this->symbol = def->getSymbol();
this->name = def->getName();
this->description = def->getDescription();
this->abilities = def->getAbilities();
this->color = def->getColor();
this->damage = def->getDamage();
}
NPC::NPC(unsigned char x, unsigned char y):
x(x),
y(y),
alive(true)
{
NPCdef* def = NPCdef::getRandom();
this->hitpoints = def->getHP().Roll();
this->speed = def->getSpeed().Roll();
this->initiative = 100/this->speed;
this->symbol = def->getSymbol();
this->name = def->getName();
this->description = def->getDescription();
this->abilities = def->getAbilities();
this->color = def->getColor();
this->damage = def->getDamage();
}
NPC::NPC(unsigned char x, unsigned char y, NPCdef *def) :
x(x),
y(y),
alive(true)
{
this->hitpoints = def->getHP().Roll();
this->speed = def->getSpeed().Roll();
this->initiative = 100/this->speed;
this->initiative = 0;
this->symbol = def->getSymbol();
this->name = def->getName();
this->description = def->getDescription();
this->abilities = def->getAbilities();
this->color = def->getColor();
this->damage = def->getDamage();
}
void NPC::setPos(unsigned char x, unsigned char y)
{
this->x = x;
this->y = y;
}
void NPC::attack(NPC* defender)
{
defender->hit(damage.Roll());
}
void NPC::hit(int amount)
{
this->hitpoints-=amount;
std::cerr << this->name << " got hit for " << amount << "points of damage." << std::endl;
if(this->hitpoints<=0)
{
alive = false;
}
}
void NPC::reset_initiative()
{
this->initiative = 0;
}
void NPC::use_initiative()
{
this->initiative++;
}
bool NPC::is_next_turn()
{
return this->initiative >= 100/speed;
}
NPC::~NPC()
{
}
std::ostream &operator<<(std::ostream &o, const NPC &npc)
{
o << npc.symbol;
return o;
}