adg5/Attacker.cpp
2025-04-22 11:38:20 +10:00

32 lines
1.0 KiB
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(engine->gui->lightGrey, "%s attacks %s for %g hit points.\n", owner->name.c_str(), target->name.c_str(),
power - target->destructible->defense);
}
else {
engine->gui->message(engine->gui->lightGrey, "%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(engine->gui->lightGrey, "%s attacks %s in vain.\n", owner->name.c_str(), target->name.c_str());
}
}
void Attacker::load(TCODZip& zip) {
power = zip.getFloat();
}
void Attacker::save(TCODZip& zip) {
zip.putFloat(power);
}