35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "Lightningbolt.h"
|
|
#include "Engine.h"
|
|
#include "Actor.h"
|
|
#include "Gui.h"
|
|
#include "Destructible.h"
|
|
|
|
LightningBolt::LightningBolt(float range, float damage)
|
|
: range(range), damage(damage) {
|
|
}
|
|
|
|
bool LightningBolt::use(Actor* owner, Actor* wearer) {
|
|
Actor* closestMonster = engine->getClosestMonster(wearer->x, wearer->y, range);
|
|
if (!closestMonster) {
|
|
engine->gui->message(TCOD_ColorRGB(200,200,200), "No enemy is close enough to strike.");
|
|
return false;
|
|
}
|
|
// hit closest monster for <damage> hit points
|
|
engine->gui->message(TCOD_ColorRGB(100, 255, 100),
|
|
"A lighting bolt strikes the %s with a crack of thunder!\n"
|
|
"The damage is %g hit points.",
|
|
closestMonster->name.c_str(), damage);
|
|
closestMonster->destructible->takeDamage(closestMonster, damage);
|
|
return Pickable::use(owner, wearer);
|
|
}
|
|
|
|
void LightningBolt::load(TCODZip& zip) {
|
|
range = zip.getFloat();
|
|
damage = zip.getFloat();
|
|
}
|
|
|
|
void LightningBolt::save(TCODZip& zip) {
|
|
zip.putInt(LIGHTNING_BOLT);
|
|
zip.putFloat(range);
|
|
zip.putFloat(damage);
|
|
} |