adg5/Confuser.cpp
2025-04-21 13:04:27 +10:00

28 lines
884 B
C++

#include "libtcod.hpp"
#include "Confuser.h"
#include "Engine.h"
#include "Gui.h"
#include "Ai.h"
#include "Actor.h"
Confuser::Confuser(int nbTurns, float range)
: nbTurns(nbTurns), range(range) {
}
bool Confuser::use(Actor* owner, Actor* wearer) {
engine->gui->message(TCOD_ColorRGB(0, 255, 255), "Left-click an enemy to confuse it,\nor right-click to cancel.");
int x, y;
if (!engine->pickATile(&x, &y, range)) {
return false;
}
Actor* actor = engine->getActor(x, y);
if (!actor) {
return false;
}
// confuse the monster for <nbTurns> turns
Ai* confusedAi = new ConfusedMonsterAi(nbTurns, actor->ai);
actor->ai = confusedAi;
engine->gui->message(TCOD_ColorRGB(100, 255, 100), "The eyes of the %s look vacant,\nas he starts to stumble around!",
actor->name.c_str());
return Pickable::use(owner, wearer);
}