From 2ab51e507d620c4479e07ca0ec47d22c8c66bc90 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 Apr 2021 15:14:34 -0400 Subject: Initial commit --- src/creature.h | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/creature.h (limited to 'src/creature.h') diff --git a/src/creature.h b/src/creature.h new file mode 100644 index 0000000..f73942f --- /dev/null +++ b/src/creature.h @@ -0,0 +1,112 @@ +#pragma once +#include "json.hpp" +#include "jsonable.h" + +namespace feature { + class Feature; +} +namespace item { + class Item; +} +class Armor; +class Weapon; + +typedef nlohmann::json json; + +namespace creature { + class dmgType : public Jsonable { + public: + dmgType(const json& data) : type(data["type"]), qualifiers(data["qualifiers"]) {} + std::string type; + std::vector qualifiers; + json toJson(void) const { + return json({ + {"type", type}, + {"qualifiers", qualifiers} + }); + } + + }; + + class Creature : public Jsonable { + public: + Creature(json data); + virtual ~Creature(); + + // Getters + std::string getCreatureName(void) const; + std::string getGivenName(void) const; + std::string getType(void) const; + std::string getSize(void) const; + std::string getAlignment(void) const; + double getCR(void) const; + std::string getLanguages(void) const; + int getHP(void) const; + int getHPMax(void) const; + std::vector getSenses(void) const; + std::string getSpeed(void) const; + int getScore(const std::string& ability) const; + int getSkillBonus(const std::string& skill) const; + int getAbilitySaveBonus(const std::string& ability) const; + int getProficiency(void) const; + std::map getSkills(void) const; + std::map getSaves(void) const; + std::vector> getFeatures(void) const; + std::vector> getInventory(void) const; + + // Inline getters + int getBonus(const std::string& ability) const { + return (int) (getScore(ability) - 10) / 2; + } + + // Setters (mutators) + void setGivenName(std::string); + void applyDamage(int amount, const std::string& type, const std::vector& qualifiers); + void setScore(const std::string& ability, int score); + void addInventoryItem(std::shared_ptr item); + void removeInventoryItem(const std::string& itemName); + + virtual json toJson(void) const; + + private: + const std::string creatureName; + std::string givenName; + const std::string size; + const std::string type; + const std::string alignment; + int hdCount; + const int hdSides; + int hpMax; + int hp; + const std::string speed; + std::map stats; + std::map skills; + std::vector saves; + const std::vector senses; + const std::string langs; + const double cr; + int proficiency; + const std::vector dmgImmunities; + const std::vector dmgResistances; + const std::vector dmgVulnerabilities; + const std::vector condImmunities; + std::vector> inventory; + std::vector> features; + + }; + + // Convenience function to get any instances of T (subclass of Item) in the inventory + template std::vector> getItems(const Creature& c) { + std::vector> Ts; + for(auto item : c.getInventory()) { + std::shared_ptr t = dynamic_pointer_cast(item); + if(t) { + Ts.push_back(t); + } + } + return Ts; + } + + // Convenience function to calculate AC + const int getAC(const Creature& c); +} -- cgit v1.2.3