From de22f4c1aa060e05db8a235860bad3b4414159ce Mon Sep 17 00:00:00 2001 From: a25liang Date: Fri, 12 Jul 2024 14:42:20 -0400 Subject: [PATCH] -impl all potions, and race: drow --- src/boost_atk.cc | 28 ++++++++++++++++++++++++++++ src/boost_atk.h | 15 +++++++++++++++ src/boost_def.cc | 26 ++++++++++++++++++++++++++ src/boost_def.h | 14 ++++++++++++++ src/drow.cc | 32 ++++++++++++++++++++++++++++++++ src/drow.h | 15 +++++++++++++++ src/poison_health.cc | 22 ++++++++++++++++++++++ src/poison_health.h | 14 ++++++++++++++ src/restore_health.cc | 2 +- src/vampire.cc | 2 +- src/wound_atk.cc | 26 ++++++++++++++++++++++++++ src/wound_atk.h | 14 ++++++++++++++ src/wound_def.cc | 25 +++++++++++++++++++++++++ src/wound_def.h | 14 ++++++++++++++ 14 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 src/boost_atk.cc create mode 100644 src/boost_atk.h create mode 100644 src/boost_def.cc create mode 100644 src/boost_def.h create mode 100644 src/drow.cc create mode 100644 src/drow.h create mode 100644 src/poison_health.cc create mode 100644 src/poison_health.h create mode 100644 src/wound_atk.cc create mode 100644 src/wound_atk.h create mode 100644 src/wound_def.cc create mode 100644 src/wound_def.h diff --git a/src/boost_atk.cc b/src/boost_atk.cc new file mode 100644 index 0000000..2c4c00d --- /dev/null +++ b/src/boost_atk.cc @@ -0,0 +1,28 @@ +#include "boost_atk.h" + +#include + +const int BOOST_ATK = 5; +const int BOOST_ATK_DROW = 7; + +boost_atk::boost_atk(): + potion{potion_type::boost_atk, -1} {} + +void boost_atk::apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + ATK += BOOST_ATK_DROW; + else + ATK += BOOST_ATK; + + --remaining_duration; + } +} + +int boost_atk::get_priority() const { + return CALC_ADD_BASE; +} + + + diff --git a/src/boost_atk.h b/src/boost_atk.h new file mode 100644 index 0000000..aea5029 --- /dev/null +++ b/src/boost_atk.h @@ -0,0 +1,15 @@ +#ifndef __BOOST_ATK_H__ +#define __BOOST_ATK_H__ + +#include "potion.h" + +class boost_atk final: public potion { +public: + boost_atk(); + void apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) override; + int get_priority() const override; +}; + +#endif + diff --git a/src/boost_def.cc b/src/boost_def.cc new file mode 100644 index 0000000..77b5d01 --- /dev/null +++ b/src/boost_def.cc @@ -0,0 +1,26 @@ +#include "boost_def.h" + +#include + +const int BOOST_DEF = 5; +const int BOOST_DEF_DROW = 7; + + +boost_def::boost_def(): + potion{potion_type::boost_def, -1} {} + +void boost_def::apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + DEF += BOOST_DEF_DROW; + else + DEF += BOOST_DEF; + + --remaining_duration; + } +} + +int boost_def::get_priority() const { + return CALC_ADD_BASE; +} \ No newline at end of file diff --git a/src/boost_def.h b/src/boost_def.h new file mode 100644 index 0000000..aa4ce36 --- /dev/null +++ b/src/boost_def.h @@ -0,0 +1,14 @@ +#ifndef __BOOST_DEF_H__ +#define __BOOST_DEF_H__ + +#include "potion.h" + +class boost_def final: public potion { +public: + boost_def(); + void apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) override; + int get_priority() const override; +}; + +#endif diff --git a/src/drow.cc b/src/drow.cc new file mode 100644 index 0000000..5158d1d --- /dev/null +++ b/src/drow.cc @@ -0,0 +1,32 @@ +#include "drow.h" +#include +#include + +drow::drow(RNG &rng, const position_list &available_positions): + character{rng, race::rdrow} { + pos = available_positions[rng.rand_under(available_positions.size())]; + gold = 0; + hostile = true; +} + +result drow::attack(const direction dir, character_list &chlist) { + position tmp{pos + MOVE[dir]}; + + for (auto &ch : chlist) + if (tmp == ch.get_position()) { + return ch.get_hit(race, ATK, base_hit_rate); + } + + return result::fine; +} + +result drow::get_hit(const enum race &race, const int atk, + const float hitrate) { + if (rng.rand_num() <= hitrate * (float)RAND_MAX) + HP = std::max(HP - calc_dmg(atk, DEF), 0); + + if (HP == 0) + return result::died; + + return result::hit; +} diff --git a/src/drow.h b/src/drow.h new file mode 100644 index 0000000..9d5c1fd --- /dev/null +++ b/src/drow.h @@ -0,0 +1,15 @@ +#ifndef __DROW_H__ +#define __DROW_H__ +#include "characters.h" + +class drow final: public character { +public: + drow(RNG &rng, + const position_list &available_positions); + virtual result attack(const direction dir, + character_list &chlist) override; + virtual result get_hit(const enum race &race, const int atk, + const float hit_rate) override; +}; + +#endif diff --git a/src/poison_health.cc b/src/poison_health.cc new file mode 100644 index 0000000..6b49fc0 --- /dev/null +++ b/src/poison_health.cc @@ -0,0 +1,22 @@ +#include "poison_health.h" + +#include + +poison_health::poison_health(): + potion{potion_type::poison_health, 1} {} + +void poison_health::apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + HP = std::max(HP - 7, 0); + else + HP = std::max(HP - 5, 0); + + --remaining_duration; + } +} + +int poison_health::get_priority() const { + return CALC_ADD_BASE; +} diff --git a/src/poison_health.h b/src/poison_health.h new file mode 100644 index 0000000..49263fd --- /dev/null +++ b/src/poison_health.h @@ -0,0 +1,14 @@ +#ifndef __POISON_HEALTH_H__ +#define __POISON_HEALTH_H__ + +#include "potion.h" + +class poison_health final: public potion { +public: + poison_health(); + void apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) override; + int get_priority() const override; +}; + +#endif diff --git a/src/restore_health.cc b/src/restore_health.cc index 6d725c0..961708c 100644 --- a/src/restore_health.cc +++ b/src/restore_health.cc @@ -3,7 +3,7 @@ #include restore_health::restore_health(): - potion{potion_type::restore_health, -1} {} + potion{potion_type::restore_health, 1} {} void restore_health::apply(enum race &race, int &HP, int &ATK, int &DEF, float &base_hit_rate) { diff --git a/src/vampire.cc b/src/vampire.cc index 2d5657f..79bfd94 100644 --- a/src/vampire.cc +++ b/src/vampire.cc @@ -3,7 +3,7 @@ #include vampire::vampire(RNG &rng, const position_list &available_positions): - character{rng, race::rshade} { + character{rng, race::rvampire} { pos = available_positions[rng.rand_under(available_positions.size())]; gold = 0; hostile = true; diff --git a/src/wound_atk.cc b/src/wound_atk.cc new file mode 100644 index 0000000..9a0af32 --- /dev/null +++ b/src/wound_atk.cc @@ -0,0 +1,26 @@ +#include "wound_atk.h" + +#include + +const int WOUND_ATK = 5; +const int WOUND_ATK_DROW = 7; + +wound_atk::wound_atk(): + potion{potion_type::wound_atk, -1} {} + +void wound_atk::apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + ATK = std::max(ATK - WOUND_ATK_DROW, 0); + else + ATK = std::max(ATK - WOUND_ATK, 0); + + --remaining_duration; + } +} + +int wound_atk::get_priority() const { + return CALC_ADD_BASE; +} + diff --git a/src/wound_atk.h b/src/wound_atk.h new file mode 100644 index 0000000..bf1bdb6 --- /dev/null +++ b/src/wound_atk.h @@ -0,0 +1,14 @@ +#ifndef __WOUND_ATK_H__ +#define __WOUND_ATK_H__ + +#include "potion.h" + +class wound_atk final: public potion { +public: + wound_atk(); + void apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) override; + int get_priority() const override; +}; + +#endif diff --git a/src/wound_def.cc b/src/wound_def.cc new file mode 100644 index 0000000..7025361 --- /dev/null +++ b/src/wound_def.cc @@ -0,0 +1,25 @@ +#include "wound_def.h" + +#include + +const int WOUND_DEF = 5; +const int WOUND_DEF_DROW = 7; + +wound_def::wound_def(): + potion{potion_type::wound_def, -1} {} + +void wound_def::apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + DEF = std::max(DEF - WOUND_DEF_DROW, 0); + else + DEF = std::max(DEF - WOUND_DEF, 0); + + --remaining_duration; + } +} + +int wound_def::get_priority() const { + return CALC_ADD_BASE; +} diff --git a/src/wound_def.h b/src/wound_def.h new file mode 100644 index 0000000..2f40cf0 --- /dev/null +++ b/src/wound_def.h @@ -0,0 +1,14 @@ +#ifndef __WOUND_DEF_H__ +#define __WOUND_DEF_H__ + +#include "potion.h" + +class wound_def final: public potion { +public: + wound_def(); + void apply(enum race &race, int &HP, int &ATK, int &DEF, + float &base_hit_rate) override; + int get_priority() const override; +}; + +#endif