added potion and restore_health
This commit is contained in:
@ -94,29 +94,6 @@ void character::apply_buff(const stat_name statn, const int amount) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
character_list::character_list():
|
|
||||||
layer{layer_num::characters} {}
|
|
||||||
|
|
||||||
void character_list::print() const {
|
|
||||||
// TODO: implement it using ncurses
|
|
||||||
}
|
|
||||||
|
|
||||||
void character_list::print(display &display) const {
|
|
||||||
for (auto &ch : characters)
|
|
||||||
display.print_char(ch->get_position(),
|
|
||||||
CHARACTER_REP[ch->get_race()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<character>>::const_iterator character_list::begin()
|
|
||||||
const {
|
|
||||||
return characters.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<character>>::const_iterator character_list::end()
|
|
||||||
const {
|
|
||||||
return characters.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
direction_list character::moveable(const position_list &available_positions)
|
direction_list character::moveable(const position_list &available_positions)
|
||||||
const {
|
const {
|
||||||
direction_list result;
|
direction_list result;
|
||||||
@ -166,7 +143,7 @@ result character::move(const direction dir,
|
|||||||
|
|
||||||
result character::move_or_attack(const direction dir,
|
result character::move_or_attack(const direction dir,
|
||||||
const position_list &available_positions,
|
const position_list &available_positions,
|
||||||
const character_list &chlist) {
|
character_list &chlist) {
|
||||||
auto res = this->move(dir, available_positions);
|
auto res = this->move(dir, available_positions);
|
||||||
|
|
||||||
if (res != result::fine)
|
if (res != result::fine)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
#include "objects.h"
|
#include "potion.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
|
|
||||||
// #include "inventory.h" // Reserved for later
|
// #include "inventory.h" // Reserved for later
|
||||||
@ -41,11 +41,12 @@ public:
|
|||||||
character_list &chlist) = 0;
|
character_list &chlist) = 0;
|
||||||
virtual result move_or_attack(const direction dir,
|
virtual result move_or_attack(const direction dir,
|
||||||
const position_list &available_positions,
|
const position_list &available_positions,
|
||||||
const character_list &chlist);
|
character_list &chlist);
|
||||||
virtual result apply(direction &dir,
|
virtual result apply(direction &dir,
|
||||||
const potion_list &potions);
|
const potion_list &potions);
|
||||||
virtual result get_hit(const enum race &race, const int atk,
|
virtual result get_hit(const enum race &race, const int atk,
|
||||||
const float hitrate) = 0;
|
const float hitrate) = 0;
|
||||||
|
|
||||||
enum race get_race() const;
|
enum race get_race() const;
|
||||||
position get_position() const;
|
position get_position() const;
|
||||||
int get_HP() const;
|
int get_HP() const;
|
||||||
@ -72,13 +73,15 @@ protected:
|
|||||||
const enum race race;
|
const enum race race;
|
||||||
|
|
||||||
int HP;
|
int HP;
|
||||||
|
|
||||||
|
// IMPORTANT: keep track of ATK and DEF in game at turn time
|
||||||
int ATK;
|
int ATK;
|
||||||
int DEF;
|
int DEF;
|
||||||
|
|
||||||
position pos;
|
position pos;
|
||||||
|
|
||||||
int gold; // characters spawn with gold
|
int gold; // characters spawn with gold
|
||||||
// inventory inventory; // Reserved
|
potion_list potions;// inventory inventory; // Reserved
|
||||||
|
|
||||||
float base_hit_rate; // requires: between [0,1]
|
float base_hit_rate; // requires: between [0,1]
|
||||||
|
|
||||||
|
@ -36,14 +36,25 @@ enum layer_num {map = 0, objects, characters, shop};
|
|||||||
|
|
||||||
const int RACE_CNT = 4; // TODO: update as you go
|
const int RACE_CNT = 4; // TODO: update as you go
|
||||||
|
|
||||||
enum race {unknown = 0, rshade, rvampire, goblin /* TODO: fill out the other races (including enemies) */};
|
enum race {rshade = 0, rvampire, rgoblin, rdrow /* TODO: fill out the other races (including enemies) */};
|
||||||
|
|
||||||
// TODO: fill out the other races (including enemies)
|
// TODO: fill out the other races (including enemies)
|
||||||
const int MAX_HP[RACE_CNT] = {0, 125, INF, 110};
|
const int MAX_HP[RACE_CNT] = {125, INF, 110, 150};
|
||||||
const int STARTING_HP[RACE_CNT] = {0, 125, 50, 110};
|
const int STARTING_HP[RACE_CNT] = {125, 50, 110, 150};
|
||||||
const int STARTING_ATK[RACE_CNT] = {0, 25, 25, 15};
|
const int STARTING_ATK[RACE_CNT] = {25, 25, 15, 25};
|
||||||
const int STARTING_DEF[RACE_CNT] = {0, 25, 25, 20};
|
const int STARTING_DEF[RACE_CNT] = {25, 25, 20, 15};
|
||||||
const char CHARACTER_REP[RACE_CNT] = {'@', 'S', 'V', 'G'};
|
const char CHARACTER_REP[RACE_CNT] = {'S', 'V', 'G', 'D'};
|
||||||
|
|
||||||
|
enum potion_type {restore_health = 0, boost_atk, boost_def,
|
||||||
|
poison_health, wound_atk, wound_def
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculation priorities
|
||||||
|
const int CALC_ADD_BASE = 0;
|
||||||
|
const int CALC_MUL_BASE = 1;
|
||||||
|
const int CALC_ADD_LATER = 2;
|
||||||
|
const int CALC_MUL_LATER = 3;
|
||||||
|
const int CALC_ADD_FIXED = 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
12
src/potion.cc
Normal file
12
src/potion.cc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "potion.h"
|
||||||
|
|
||||||
|
potion::potion(const potion_type type, const int duration):
|
||||||
|
type{type}, remaining_duration{duration} {}
|
||||||
|
|
||||||
|
potion_type potion::get_type() const {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
int potion::get_duration() const {
|
||||||
|
return remaining_duration;
|
||||||
|
}
|
30
src/potion.h
Normal file
30
src/potion.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef __POTIONS_H__
|
||||||
|
#define __POTIONS_H__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
// IMPORTANT: pop all potions of duration == 0, and when entering a
|
||||||
|
// new level, pop all potions of duration == -1
|
||||||
|
|
||||||
|
class potion {
|
||||||
|
protected:
|
||||||
|
// Use -1 to denote that the effect will last until leaving the level
|
||||||
|
// Otherwise, use a positive number
|
||||||
|
// Single use potions have a starting duration of 1
|
||||||
|
const potion_type type;
|
||||||
|
int remaining_duration;
|
||||||
|
public:
|
||||||
|
potion(const potion_type type, const int duration);
|
||||||
|
// apply decrements remaining_duration if it's positive, and
|
||||||
|
// won't do anything if it's non-negative
|
||||||
|
virtual void apply(enum race &race, int &HP, int &ATK, int &DEF,
|
||||||
|
float &base_hit_rate) = 0;
|
||||||
|
virtual int get_priority() const = 0;
|
||||||
|
potion_type get_type() const;
|
||||||
|
int get_duration() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<potion> potion_list;
|
||||||
|
|
||||||
|
#endif
|
22
src/potions/restore_health.cc
Normal file
22
src/potions/restore_health.cc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "restore_health.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
restore_health::restore_health():
|
||||||
|
potion{potion_type::restore_health, -1} {}
|
||||||
|
|
||||||
|
void restore_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, MAX_HP[race]);
|
||||||
|
else
|
||||||
|
HP = std::max(HP + 5, MAX_HP[race]);
|
||||||
|
|
||||||
|
--remaining_duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int restore_health::get_priority() const {
|
||||||
|
return CALC_ADD_BASE;
|
||||||
|
}
|
14
src/potions/restore_health.h
Normal file
14
src/potions/restore_health.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef __RESTORE_HEALTH_H__
|
||||||
|
#define __RESTORE_HEALTH_H__
|
||||||
|
|
||||||
|
#include "../potion.h"
|
||||||
|
|
||||||
|
class restore_health final: public potion {
|
||||||
|
public:
|
||||||
|
restore_health();
|
||||||
|
void apply(enum race &race, int &HP, int &ATK, int &DEF,
|
||||||
|
float &base_hit_rate) override;
|
||||||
|
int get_priority() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user