-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttacker.cpp
30 lines (26 loc) · 988 Bytes
/
Attacker.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
#include <stdio.h>
#include "main.hpp"
Attacker::Attacker(float power) : power(power) {
}
void Attacker::attack(Actor *owner, Actor *target) {
if (target->destructible && ! target->destructible->isDead() ) {
if ( power - target->destructible->defense > 0) {
engine.gui->message(owner==engine.player ? TCODColor::red : TCODColor::lightGrey,
"%s attacks %s for %g hit points.", owner->name, target->name,
power - target->destructible->defense);
} else {
engine.gui->message(TCODColor::lightGrey,
"%s attacks %s but it has no effect!", owner->name, target->name);
}
target->destructible->takeDamage(target, power);
} else {
engine.gui->message(TCODColor::lightGrey,
"%s attacks %s in vain.",owner->name,target->name);
}
}
void Attacker::load(TCODZip &zip) {
power = zip.getFloat();
}
void Attacker::save(TCODZip &zip) {
zip.putFloat(power);
}