#pragma once #include "rules.h" #include "utils.h" #include "entry.h" #include "features/feature.h" #include "item.h" #include namespace entry { class Weapon; class Attack; class Spell; class Spellcasting; } namespace creature { class Creature; struct creatureImpl; struct dmgType { std::string type; std::vector qualifiers; std::string getText() const { if(qualifiers.empty()) { return type; } return utils::join(qualifiers, ", ") + " " + type; } }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(dmgType, type, qualifiers); struct NatArmor { std::string name; int bonus; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NatArmor, name, bonus); // Convenience function to calculate AC const int getAC(const Creature& c); class Creature : public entry::Entry { public: Creature(); virtual ~Creature() {} virtual void init() override; // Getters int getSkillBonus(const rules::Skill& skill) const; int getAbilitySaveBonus(const rules::Ability& ability) const; std::map getSkills(void) const; std::map getSaves(void) const; //Override getText virtual std::string getText() const override; std::string getCreatureName(void) const; std::string getGivenName(void) const; std::string getSize(void) const; std::string getAlignment(void) const; double getCR(void) const; NatArmor getNaturalArmor(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 rules::Ability& ability) const; int getBonus(const rules::Ability& ability) const; int getProficiency(void) const; int getInitiative(void) const; std::vector> getFeatures(void) const; std::shared_ptr getSpellcasting(void) const; std::vector> getInventory(void) const; std::vector getDmgImmunities(void) const; std::vector getDmgResistances(void) const; std::vector getDmgVulnerabilities(void) const; std::vector getCondImmunities(void) const; // Setters (mutators) void setGivenName(const std::string& name); void setScore(const rules::Ability& ability, int score); void setProfLevel(const rules::Skill& skill, int level); void setProficiency(int p); void addInventoryItem(std::shared_ptr item); void addSpellcasting(void); void addSpell(std::shared_ptr spell); void removeSpell(std::shared_ptr spell); void removeInventoryItem(std::shared_ptr item); // Events void longRest(void); void turnStart(void); void turnEnd(void); void applyDamage(int amount, const std::string& type, const std::vector& qualifiers); // Returns the amount rolled int saveOrDamage(const rules::Ability& ability, int DC, int amount, const std::string& type, const std::vector& qualifiers, bool saveHalves); void applyHealing(int amount); void opportunityAttack(const creature::Creature& other); NLOHMANN_FRIEND_DECLARES(Creature); private: std::shared_ptr data; }; // Helper function to get all attacks (weapons and pseudo-weapons included) std::vector> getAttacks(const Creature& c); // Helper function to get the best ability for this creature (chooses arbitrarily in case of ties) rules::Ability getBestAbility(const std::vector& abilities, const Creature& c); }