1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-23 16:54:07 +00:00

ru:: refactored enemy::attacked

This commit is contained in:
Zeno Rogue 2025-05-10 02:58:33 +02:00
parent 7183c849a7
commit 55946bdf49
2 changed files with 12 additions and 19 deletions

View File

@ -335,6 +335,7 @@ struct enemy : public entity {
m.experience += (base_xp() * 25 + 24) / (4 + num_kills) / (4 + num_kills);
}
enemy() { num_kills = 0; postfix(); }
void attacked(int s) override;
void regenerate() override { where = respawn; vel = xy(0, 0); existing = true; hp = max_hp(); }
virtual int base_xp() { return 0; }
};
@ -359,7 +360,6 @@ struct ghost : public enemy {
string glyph() override { return "g"; }
color_t color() override { return 0x4040A0FF; }
void act() override;
void attacked(int s) override;
string get_name() override { return "ghost"; }
string get_help() override { return "This apparition looks strangely like you..."; }
int base_xp() { return hp; }

View File

@ -285,10 +285,15 @@ void boar::act() {
}
}
void boar::attacked(int dmg) {
void enemy::attacked(int dmg) {
current_target = this;
reduce_hp(dmg);
if(!existing) addMessage("You kill the wild boar."); else addMessage("You hit the wild boar.");
if(reduce_hp(dmg)) {
if(!existing) addMessage("You kill the " + get_name() + "."); else addMessage("You hit the " + get_name() + ".");
}
}
void boar::attacked(int dmg) {
enemy::attacked(dmg);
auto dat = get_dat();
int s = where.x < m.where.x ? -1 : 1;
if(on_floor) vel.x = dat.d * dat.modv * s * 2, vel.y = -dat.d * dat.modv * 2.5;
@ -311,12 +316,6 @@ void ghost::act() {
}
}
void ghost::attacked(int dmg) {
current_target = this;
reduce_hp(dmg);
if(!existing) addMessage("You kill the ghost."); else addMessage("You hit the ghost.");
}
void snake::act() {
stay_on_screen();
kino();
@ -331,9 +330,7 @@ void snake::act() {
}
void snake::attacked(int dmg) {
current_target = this;
reduce_hp(dmg);
if(!existing) addMessage("You kill the snake."); else addMessage("You hit the snake.");
enemy::attacked(dmg);
if(where.x < m.where.x) vel.x = -abs(vel.x);
if(where.x > m.where.x) vel.x = +abs(vel.x);
}
@ -447,17 +444,13 @@ void bat::act() {
}
void kestrel::attacked(int dmg) {
current_target = this;
reduce_hp(dmg);
if(!existing) addMessage("You kill the kestrel."); else addMessage("You hit the kestrel.");
enemy::attacked(dmg);
if(where.x < m.where.x) vel.x = -abs(vel.x);
if(where.x > m.where.x) vel.x = +abs(vel.x);
}
void bat::attacked(int dmg) {
current_target = this;
reduce_hp(dmg);
if(!existing) addMessage("You kill the bat."); else addMessage("You hit the bat.");
enemy::attacked(dmg);
if(where.x < m.where.x) vel.x = -abs(vel.x);
if(where.x > m.where.x) vel.x = +abs(vel.x);
if(where.y < m.where.y) vel.y = -abs(vel.y);