25 lines
930 B
C++
25 lines
930 B
C++
#include "Attacker.h"
|
|
#include "Actor.h"
|
|
#include "Destructible.h"
|
|
#include "Engine.h"
|
|
#include "Gui.h"
|
|
|
|
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(TCOD_ColorRGB(150, 150, 150), "%s attacks %s for %g hit points.\n", owner->name.c_str(), target->name.c_str(),
|
|
power - target->destructible->defense);
|
|
}
|
|
else {
|
|
engine->gui->message(TCOD_ColorRGB(150, 150, 150), "%s attacks %s but it has no effect!\n", owner->name.c_str(), target->name.c_str());
|
|
}
|
|
target->destructible->takeDamage(target, power);
|
|
}
|
|
else {
|
|
engine->gui->message(TCOD_ColorRGB(150, 150, 150), "%s attacks %s in vain.\n", owner->name.c_str(), target->name.c_str());
|
|
}
|
|
}
|