#pragma once #include "rules.h" #include "utils.h" #include "entry.h" #include "feature.h" #include "item.h" #include #include namespace entry { class Weapon; class Attack; class Spell; class Spellcasting; } namespace creature { class Creature; 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: 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; // Inline getters std::string getCreatureName(void) const {return getName();} std::string getGivenName(void) const {return givenName;} std::string getSize(void) const {return size;} std::string getAlignment(void) const {return alignment;} double getCR(void) const {return cr;} NatArmor getNaturalArmor(void) const {return natural_armor;} std::string getLanguages(void) const {return langs;} int getHP(void) const {return hp;} int getHPMax(void) const {return hpMax;} std::vector getSenses(void) const {return senses;} std::string getSpeed(void) const {return speed;} int getScore(const rules::Ability& ability) const {return stats.at(ability);} int getBonus(const rules::Ability& ability) const {return std::floor((getScore(ability) - 10) / 2.0);} int getProficiency(void) const {return prof;} std::vector> getFeatures(void) const {return features;} std::shared_ptr getSpellcasting(void) const; std::vector> getInventory(void) const {return inventory;} std::vector getDmgImmunities(void) const {return d_immunities;} std::vector getDmgResistances(void) const {return d_resistances;} std::vector getDmgVulnerabilities(void) const {return d_vulnerabilities;} std::vector getCondImmunities(void) const {return c_immunities;} // Setters (mutators) void setGivenName(std::string name) {givenName = name;} void applyDamage(int amount, const std::string& type, const std::vector& qualifiers); void applyHealing(int amount); void setScore(const rules::Ability& ability, int score); void setProfLevel(const rules::Skill& skill, int level); void setProficiency(int p) {prof = 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); void longRest(void); NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Entry, Creature, givenName, hpMax, hp, inventory, stats, skills, prof, size, alignment, hit_die_count, hit_die_sides, speed, saves, senses, langs, cr, observant, natural_armor, d_immunities, d_resistances, d_vulnerabilities, c_immunities, features); private: std::string givenName; int hpMax; int hp; std::vector> inventory; std::map stats; std::map skills; int prof; std::string size; std::string alignment; int hit_die_count; int hit_die_sides; std::string speed; std::vector saves; std::vector senses; std::string langs; double cr; bool observant; NatArmor natural_armor; std::vector d_immunities; std::vector d_resistances; std::vector d_vulnerabilities; std::vector c_immunities; std::vector> features; }; // 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); }