diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/armor.cc | 33 | ||||
| -rw-r--r-- | src/armor.h | 26 | ||||
| -rw-r--r-- | src/creature.cc | 101 | ||||
| -rw-r--r-- | src/creature.h | 43 | ||||
| -rw-r--r-- | src/feature.cc | 29 | ||||
| -rw-r--r-- | src/feature.h | 18 | ||||
| -rw-r--r-- | src/item.cc | 36 | ||||
| -rw-r--r-- | src/item.h | 24 | ||||
| -rw-r--r-- | src/jsonable.h | 25 | ||||
| -rw-r--r-- | src/settings.h | 11 | ||||
| -rw-r--r-- | src/spell.h | 47 | ||||
| -rw-r--r-- | src/spellcasting.h | 46 | ||||
| -rw-r--r-- | src/utils.cc | 33 | ||||
| -rw-r--r-- | src/utils.h | 31 | ||||
| -rw-r--r-- | src/weapon.cc | 39 | ||||
| -rw-r--r-- | src/weapon.h | 33 | 
16 files changed, 280 insertions, 295 deletions
diff --git a/src/armor.cc b/src/armor.cc deleted file mode 100644 index 00e1b05..0000000 --- a/src/armor.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include "json.hpp" -#include "armor.h" - -using namespace std; - -namespace item { -    Armor::Armor(const nlohmann::json& data) : Item(data), acBonus(data["ac"]), armorType(data["type"]), strRequirement(data["strength"]), stealthDis(data["disadvantage"]) {} - -    int Armor::getACBonus() const { -        return acBonus; -    } - -    string Armor::getArmorType() const { -        return armorType; -    } - -    int Armor::getStrRequirement() const { -        return strRequirement; -    } - -    bool Armor::stealthDisadvantage() const { -        return stealthDis; -    } - -    nlohmann::json Armor::toJson() const { -        auto data = Item::toJson(); -        data["ac"] = acBonus; -        data["type"] = armorType; -        data["strength"] = strRequirement; -        data["disadvantage"] = stealthDis; -        return data; -    } -} diff --git a/src/armor.h b/src/armor.h index 0ea7199..2df1fff 100644 --- a/src/armor.h +++ b/src/armor.h @@ -5,18 +5,32 @@  namespace item {      class Armor : public Item {          public: -            Armor(const nlohmann::json& data); -            int getACBonus(void) const; -            std::string getArmorType(void) const; -            int getStrRequirement(void) const; -            bool stealthDisadvantage(void) const; +            Armor(const nlohmann::json& data, const nlohmann::json& base) : Item(base), acBonus(data["ac"]), armorType(data["type"]), strRequirement(data["strength"]), stealthDis(data["disadvantage"]),  cost(data["cost"]), weight(data["weight"]) {} -            virtual nlohmann::json toJson(void) const; +            int getACBonus(void) const {return acBonus;} +            std::string getArmorType(void) const {return armorType;} +            int getStrRequirement(void) const {return strRequirement;} +            bool stealthDisadvantage(void) const {return stealthDis;} +            int getCost(void) const {return cost;} +            double getWeight(void) const {return weight;} + +            /*virtual nlohmann::json toJson(void) const { +                auto data = Item::toJson(); +                data["ac"] = acBonus; +                data["type"] = armorType; +                data["strength"] = strRequirement; +                data["disadvantage"] = stealthDis; +                data["cost"] = cost; +                data["weight"] = weight; +                return data; +            }*/          private:              const int acBonus;              const std::string armorType;              const int strRequirement;              const bool stealthDis; +            const int cost; +            const double weight;      };  } diff --git a/src/creature.cc b/src/creature.cc index 24a8087..3587ab0 100644 --- a/src/creature.cc +++ b/src/creature.cc @@ -12,24 +12,9 @@ typedef nlohmann::json json;  using namespace std;  namespace creature { -    vector<dmgType> initDmgType(const json& dat) { -        vector<dmgType> stuff; -        for(json x : dat) { -            stuff.push_back(dmgType(x)); -        } -        return stuff; -    } - -    Creature::Creature(json data) -        : creatureName(data["name"]), size(data["size"]), type(data["type"]), alignment(data["alignment"]), hdCount(data["hit_die_count"]), hdSides(data["hit_die_sides"]), speed(data["speed"]), stats(data["stats"]), skills(data["skills"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), dmgImmunities(initDmgType(data["d_immunities"])), dmgResistances(initDmgType(data["d_resistances"])), dmgVulnerabilities(initDmgType(data["d_vulnerabilities"])), condImmunities(initDmgType(data["c_immunities"])) +    Creature::Creature(const json& data) +        : inventory(json2ptrvec<item::Item>(data["inventory"])), creatureName(data["name"]), size(data["size"]), type(data["type"]), alignment(data["alignment"]), hdCount(data["hit_die_count"]), hdSides(data["hit_die_sides"]), speed(data["speed"]), stats(data["stats"]), skills(data["skills"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), dmgImmunities(json2vec<dmgType>(data["d_immunities"])), dmgResistances(json2vec<dmgType>(data["d_resistances"])), dmgVulnerabilities(json2vec<dmgType>(data["d_vulnerabilities"])), condImmunities(json2vec<dmgType>(data["c_immunities"])), features(json2ptrvec<feature::Feature>(data["features"]))      { -        // Initialize features + inventory -        for(json data : data["features"]) { -            features.push_back(feature::Feature::create(data)); -        } -        for(json data : data["inventory"]) { -            inventory.push_back(item::Item::create(data)); -        }          // Initialize names and hp          if(((map<string, json>) data).contains("givenName")) {              givenName = data["givenName"]; @@ -53,14 +38,6 @@ namespace creature {          return ret;      } -    template<typename T> vector<json> getJsonVectR(vector<T> src) { -        vector<json> ret; -        for(T i : src) { -            ret.push_back(i.toJson()); -        } -        return ret; -    } -      nlohmann::json Creature::toJson() const {          return nlohmann::json({                      {"name", creatureName}, @@ -76,10 +53,10 @@ namespace creature {                      {"langs", langs},                      {"cr", cr},                      {"prof", proficiency}, -                    {"d_immunities", getJsonVectR(dmgImmunities)}, -                    {"d_resistances", getJsonVectR(dmgResistances)}, -                    {"d_vulnerabilities", getJsonVectR(dmgVulnerabilities)}, -                    {"c_immunities", getJsonVectR(condImmunities)}, +                    {"d_immunities", dmgImmunities}, +                    {"d_resistances", dmgResistances}, +                    {"d_vulnerabilities", dmgVulnerabilities}, +                    {"c_immunities", condImmunities},                      {"givenName", givenName},                      {"hpMax", hpMax},                      {"hp", hp}, @@ -88,48 +65,6 @@ namespace creature {                  });      } -    Creature::~Creature() {} - -    string Creature::getCreatureName() const { -        return creatureName; -    } - -    string Creature::getGivenName() const { -        return givenName; -    } - -    void Creature::setGivenName(string name) { -        givenName = name; -    } - -    string Creature::getType() const { -        return type; -    } - -    string Creature::getSize() const { -        return size; -    } - -    string Creature::getAlignment() const { -        return alignment; -    } - -    double Creature::getCR() const { -        return cr; -    } - -    string Creature::getLanguages() const { -        return langs; -    } - -    int Creature::getHP() const { -        return hp; -    } - -    int Creature::getHPMax() const { -        return hpMax; -    } -      // True if type without matching qualifiers is in subdata      bool conditionApplies(const string& type, const vector<string>& qualifiers, const vector<dmgType> subdata) {          bool applies = false; @@ -158,10 +93,6 @@ namespace creature {          }      } -    vector<string> Creature::getSenses() const { -        return senses; -    } -      int Creature::getSkillBonus(const string& skill) const {          int bonus = this->getBonus(skill2ability[skill]);          if(skills.contains(skill)) { @@ -170,14 +101,6 @@ namespace creature {          return bonus;      } -    int Creature::getScore(const string& ability) const { -        return stats.at(ability); -    } - -    string Creature::getSpeed() const { -        return speed; -    } -      int Creature::getAbilitySaveBonus(const string& ability) const {          int bonus = this->getBonus(ability);          if(find(saves.begin(), saves.end(), ability) != saves.end()) { @@ -186,18 +109,6 @@ namespace creature {          return bonus;      } -    int Creature::getProficiency() const { -        return proficiency; -    } - -    vector<shared_ptr<feature::Feature>> Creature::getFeatures() const { -        return features; -    } - -    vector<shared_ptr<item::Item>> Creature::getInventory() const { -        return inventory; -    } -      void Creature::addInventoryItem(shared_ptr<item::Item> item) {          inventory.push_back(item);      } diff --git a/src/creature.h b/src/creature.h index 6ba8cca..88326f4 100644 --- a/src/creature.h +++ b/src/creature.h @@ -30,37 +30,36 @@ namespace creature {      class Creature : public Jsonable {          public: -            Creature(json data); -            virtual ~Creature(); +            Creature(const 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<std::string> 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<std::string, int> getSkills(void) const;              std::map<std::string, int> getSaves(void) const; -            std::vector<std::shared_ptr<feature::Feature>> getFeatures(void) const; -            std::vector<std::shared_ptr<item::Item>> getInventory(void) const;              // Inline getters -            int getBonus(const std::string& ability) const { -                return (int) (getScore(ability) - 10) / 2; -            } +            std::string getCreatureName(void) const {return creatureName;} +            std::string getGivenName(void) const {return givenName;} +            std::string getType(void) const {return type;} +            std::string getSize(void) const {return size;} +            std::string getAlignment(void) const {return alignment;} +            double getCR(void) const {return cr;} +            std::string getLanguages(void) const {return langs;} +            int getHP(void) const {return hp;} +            int getHPMax(void) const {return hpMax;} +            std::vector<std::string> getSenses(void) const {return senses;} +            std::string getSpeed(void) const {return speed;} +            int getScore(const std::string& ability) const {return stats.at(ability);} +            int getBonus(const std::string& ability) const {return (int) (getScore(ability) - 10) / 2;} +            int getProficiency(void) const {return proficiency;} +            std::vector<std::shared_ptr<feature::Feature>> getFeatures(void) const {return features;} +            std::vector<std::shared_ptr<item::Item>> getInventory(void) const {return inventory;} +              // Setters (mutators) -            void setGivenName(std::string); +            void setGivenName(std::string name) {givenName = name;}              void applyDamage(int amount, const std::string& type, const std::vector<std::string>& qualifiers);              //void setScore(const std::string& ability, int score);              void addInventoryItem(std::shared_ptr<item::Item> item); @@ -94,7 +93,7 @@ namespace creature {              const std::vector<dmgType> dmgResistances;              const std::vector<dmgType> dmgVulnerabilities;              const std::vector<dmgType> condImmunities; -            std::vector<std::shared_ptr<feature::Feature>> features; +            const std::vector<std::shared_ptr<feature::Feature>> features;      }; diff --git a/src/feature.cc b/src/feature.cc index 2747631..84f23fe 100644 --- a/src/feature.cc +++ b/src/feature.cc @@ -1,5 +1,7 @@  #include "json.hpp"  #include "feature.h" +#include "spellcasting.h" +#include "utils.h"  #include <sstream>  #include <map> @@ -8,30 +10,9 @@ typedef nlohmann::json json;  namespace feature {      shared_ptr<Feature> Feature::create(const json& data) { +        if(data["type"] == "spellcasting") { +            return utils::loadDFromJson<Feature, Spellcasting>(data); +        }          return shared_ptr<Feature>(new Feature(data));      } - -    Feature::Feature(const json& data) : name(data["name"]), type(data["type"]), text(data["text"]) {} - -    Feature::~Feature() {} - -    string Feature::getName() const { -        return name; -    } - -    string Feature::getType() const { -        return type; -    } - -    string Feature::getText() const { -        return text; -    } - -    json Feature::toJson() const { -        return json({ -                {"name", name}, -                {"type", type}, -                {"text", text} -                }); -    }  } diff --git a/src/feature.h b/src/feature.h index c433f32..01802bf 100644 --- a/src/feature.h +++ b/src/feature.h @@ -8,16 +8,22 @@ namespace feature {          public:              static std::shared_ptr<Feature> create(const nlohmann::json& data); -            virtual ~Feature(); +            virtual ~Feature() {} -            std::string getName(void) const; -            std::string getType(void) const; -            std::string getText(void) const; +            std::string getName(void) const {return name;} +            std::string getType(void) const {return type;} +            virtual std::string getText(void) const {return text;} -            virtual nlohmann::json toJson(void) const; +            virtual nlohmann::json toJson(void) const { +                return nlohmann::json({ +                        {"name", name}, +                        {"type", type}, +                        {"text", text} +                        }); +            }          protected: -            Feature(const nlohmann::json& data); +            Feature(const nlohmann::json& data) : name(data["name"]), type(data["type"]), text(data["text"]) {};          private:              const std::string name; diff --git a/src/item.cc b/src/item.cc index 0aad620..f602be2 100644 --- a/src/item.cc +++ b/src/item.cc @@ -10,39 +10,13 @@ using namespace std;  typedef nlohmann::json json;  namespace item { +      shared_ptr<Item> Item::create(const json& data) { -        auto dataMap = (map<string, json>) data; -        if(dataMap.contains("damage")) { -            return shared_ptr<Item>(new Weapon(data)); -        } else if(dataMap.contains("ac")) { -            return shared_ptr<Item>(new Armor(data)); +        if(data["type"] == "weapon") { +            return utils::loadDFromJson<Item, Weapon>(data); +        } else if(data["type"] == "armor") { +            return utils::loadDFromJson<Item, Armor>(data);          }          return shared_ptr<Item>(new Item(data));      } - -    Item::Item(const json& data) : name(data["name"]), cost(data["cost"]), weight(data["weight"]) {}; - -    //Item::Item(const std::string& name, int cost, double weight) : name(name), cost(cost), weight(weight) {}; - -    Item::~Item() {} - -    string Item::getName() const { -        return name; -    } - -    int Item::getCost() const { -        return cost; -    } - -    double Item::getWeight() const { -        return weight; -    } - -    json Item::toJson() const { -        return json({ -                {"name", name}, -                {"cost", cost}, -                {"weight", weight} -                }); -    }  } @@ -3,25 +3,31 @@  #include "jsonable.h"  #include <memory> -namespace item{ +namespace item {      class Item : public Jsonable {          public:              static std::shared_ptr<Item> create(const nlohmann::json& data); -            virtual ~Item(); +            virtual ~Item() {} -            virtual std::string getName(void) const; -            virtual int getCost(void) const; -            virtual double getWeight(void) const; +            std::string getName(void) const {return name;} +            std::string getType(void) const {return type;} +            virtual std::string getText(void) const {return text;} -            virtual nlohmann::json toJson(void) const; +            virtual nlohmann::json toJson(void) const { +                return nlohmann::json({ +                        {"name", name}, +                        {"type", type}, +                        {"text", text} +                        }); +            }          protected: -            Item(const nlohmann::json& data); +            Item(const nlohmann::json& data) : name(data["name"]), type(data["type"]), text(data["text"]) {};          private:              const std::string name; -            const int cost; -            const double weight; +            const std::string type; +            const std::string text;      };  } diff --git a/src/jsonable.h b/src/jsonable.h index 87f3f66..4be2bec 100644 --- a/src/jsonable.h +++ b/src/jsonable.h @@ -1,7 +1,32 @@  #pragma once  #include "json.hpp" +#include "utils.h" +#include <memory> +#include <vector>  class Jsonable {      public:          virtual nlohmann::json toJson(void) const = 0; +        operator nlohmann::json() const {return toJson();}  }; + +template<typename T> std::vector<T> json2vec(const nlohmann::json& data) { +    using std::begin; using std::end; +    return std::vector<T>(begin(data), end(data)); +} + +template<typename T> std::vector<T> jsonList2vec(const std::string& type, const std::vector<std::string>& names) { +    std::vector<T> ret; +    for(auto name : names) { +        ret.push_back(utils::loadJson(type, name)); +    } +    return ret; +} + +template<typename T> std::vector<std::shared_ptr<T>> json2ptrvec(const nlohmann::json& data) { +    std::vector<std::shared_ptr<T>> ret; +    for(nlohmann::json d : data) { +        ret.push_back(T::create(d)); +    } +    return ret; +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..43eeb07 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,11 @@ +#pragma once +#include <string> +#include <map> + +namespace settings { +    const std::map<std::string, std::string> dummySettings { +        {"weapon", "parser/items/weapons/"}, +            {"armor", "parser/items/armor/"}, +            {"spellcasting", "parser/spells"} +    }; +} diff --git a/src/spell.h b/src/spell.h new file mode 100644 index 0000000..d493d5d --- /dev/null +++ b/src/spell.h @@ -0,0 +1,47 @@ +#pragma once +#include "json.hpp" +#include "jsonable.h" + +namespace spell { +    class Spell : public Jsonable { +        public: +            Spell(const nlohmann::json& data) : name(data["name"]), level(data["level"]), school(data["school"]), classes(data["classes"]), castingTime(data["casting_time"]), range(data["range"]), components(data["components"]), duration(data["duration"]), text(data["text"]) {}; +            virtual ~Spell() {}; + +            std::string getName(void) const {return name;} +            int getLevel(void) const {return level;} +            std::string getSchool(void) const {return school;} +            std::vector<std::string> getClasses(void) const {return classes;} +            std::string getCastingTime(void) const {return castingTime;} +            std::string getRange(void) const {return range;} +            std::string getComponents(void) const {return components;} +            std::string getDuration(void) const {return duration;} +            std::string getText(void) const {return text;} + +            virtual nlohmann::json toJson(void) const { +                /*return nlohmann::json({ +                        {"name", name}, +                        {"level", level}, +                        {"school", school}, +                        {"classes", classes}, +                        {"casting_time", castingTime}, +                        {"range", range}, +                        {"components", components}, +                        {"duration", duration}, +                        {"text", text} +                        });*/ +                return nlohmann::json(name); +            } + +        private: +            const std::string name; +            const int level; +            const std::string school; +            const std::vector<std::string> classes; +            const std::string castingTime; +            const std::string range; +            const std::string components; +            const std::string duration; +            const std::string text; +    }; +} diff --git a/src/spellcasting.h b/src/spellcasting.h new file mode 100644 index 0000000..f996322 --- /dev/null +++ b/src/spellcasting.h @@ -0,0 +1,46 @@ +#pragma once +#include "feature.h" +#include "json.hpp" +#include "spell.h" +#include "jsonable.h" + +typedef nlohmann::json json; + +namespace feature { +    struct SlotLevel : public Jsonable { +        SlotLevel(const json& data) : numSlots(data["slots"]), spells(jsonList2vec<spell::Spell>("spellcasting", data["spells"])) {} +        virtual ~SlotLevel() {} +        const int numSlots; +        const std::vector<spell::Spell> spells; + +        json toJson(void) const { +            return json({ +                    {"slots", numSlots}, +                    {"spells", spells} +                    }); +        } +    }; + +    class Spellcasting : public Feature { +        public: +            Spellcasting(const json& data, const json& base) : Feature(base), innate(data["innate"]), ability(data["spellcasting_ability"]), spellsBySlot(json2vec<SlotLevel>(data["levels"])) {} +            virtual ~Spellcasting() {} + +            bool isInnate(void) const {return innate;} +            std::string getAbility(void) const {return ability;} +            std::vector<SlotLevel> getSpellsBySlot(void) const {return spellsBySlot;} + +            virtual json toJson(void) const { +                auto data = Feature::toJson(); +                data["innate"] = innate; +                data["ability"] = ability; +                data["levels"] = spellsBySlot; +                return data; +            } + +        private: +            const bool innate; +            const std::string ability; +            const std::vector<SlotLevel> spellsBySlot; +    }; +} diff --git a/src/utils.cc b/src/utils.cc index 009754b..1df3308 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -1,5 +1,6 @@  #include "utils.h"  #include "json.hpp" +#include "settings.h"  #include <sstream>  #include <fstream>  #include <string> @@ -15,23 +16,35 @@ nlohmann::json utils::loadJson(const std::string& path) {      return j;  } +nlohmann::json utils::loadJson(const std::string& type, const std::string& name) { +    for(auto data : utils::loadAllJson(settings::dummySettings.at(type))) { +        if(data["name"] == name) { +            return data; +        } +    } +    throw std::invalid_argument("Unknown name: `" + name + "' for type `" + type + "'."); +} +  void utils::saveJson(const nlohmann::json& data, const std::string& path) {      std::ofstream f(path);      f << std::setw(4) << data << std::endl;  } -/*std::string utils::join(std::vector<std::string> parts, std::string joiner) { -    std::stringstream out; -    bool isFirst = true; -    for(std::string p : parts) { -        if(! isFirst) { -            out << joiner; +static std::map<std::string, std::vector<nlohmann::json>> cache; + +std::vector<nlohmann::json> utils::loadAllJson(const std::string& directory) { +    if(cache.contains(directory)) { +        return cache[directory]; +    } +    std::vector<nlohmann::json> ret; +    for(auto path : std::filesystem::recursive_directory_iterator(directory)) { +        if(path.path().extension() == ".json") { +            ret.push_back(utils::loadJson(path.path()));          } -        isFirst = false; -        out << p;      } -    return out.str(); -}*/ +    cache[directory] = ret; +    return ret; +}  // Accepts coins formatted "X Yp" where X is an integer and Y is any of c, s, e, g, p.  int utils::coins2copper(const std::string& coins) { diff --git a/src/utils.h b/src/utils.h index f7366dc..9f4cf5c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,16 +1,34 @@  #pragma once  #include "json.hpp" +#include "settings.h"  #include <string>  #include <vector>  #include <map>  #include <sstream> - +#include <memory> +#include <stdexcept>  namespace utils {      nlohmann::json loadJson(const std::string& path); +     +    // Recursively loads all .json files under directory +    // If called multiple times with same directory, returns a cached result. +    std::vector<nlohmann::json> loadAllJson(const std::string& directory); + +    // looks up directory in settings. Returns element matching name. +    nlohmann::json loadJson(const std::string& type, const std::string& name);      void saveJson(const nlohmann::json& data, const std::string& path); +    template<typename S, typename D> std::shared_ptr<S> loadDFromJson(const nlohmann::json& data) { +        try { +            return std::shared_ptr<S>(new D(loadJson(data["type"], data["name"]), data)); +        } catch(std::invalid_argument& e) { +            // Fall back on the data passed in +            return std::shared_ptr<S>(new D(data, data)); +        } +    } +      template<typename Container> std::string join(Container parts, std::string joiner) {          std::stringstream out;          bool isFirst = true; @@ -40,15 +58,4 @@ namespace utils {      std::vector<std::pair<std::string, int>> copper2coins(int coppers);      std::string getCostString(int coppers); - -    // Recursively loads all .json files under directory -    /*std::vector<Item> loadAll(std::string directory) { -      std::vector<Item> items; -      for(auto path : std::filesystem::recursive_directory_iterator(directory)) { -      if(path.path().extension() == ".json") { -      items.push_back(Item::instance(loadJson(path.path()))); -      } -      } -      return items; -      }*/  } diff --git a/src/weapon.cc b/src/weapon.cc index b12c2cb..314b1be 100644 --- a/src/weapon.cc +++ b/src/weapon.cc @@ -8,17 +8,6 @@  using namespace std;  namespace item { -    Weapon::Weapon(const nlohmann::json& data) -        : Item(data), damageType(data["damage"]["dmg_type"]), damageDieCount(data["damage"]["dmg_die_count"]), damageDieSides(data["damage"]["dmg_die_sides"]), properties(data["properties"]), weaponType(data["type"]), range(data["range"][0], data["range"][1]), reach(data["reach"]) {} - -    string Weapon::getDamageType() const { -        return damageType; -    } - -    int Weapon::getDamageDieCount() const { -        return damageDieCount; -    } -      int Weapon::getDamageDieSides(bool versatile) const {          if(versatile && getProperties().count("versatile")) {              return damageDieSides + 2; @@ -26,34 +15,6 @@ namespace item {          return damageDieSides;      } -    set<string> Weapon::getProperties() const { -        return properties; -    } - -    string Weapon::getWeaponType() const { -        return weaponType; -    } - -    pair<int, int> Weapon::getRange() const { -        return range; -    } - -    int Weapon::getReach() const { -        return reach; -    } - -    nlohmann::json Weapon::toJson() const { -        auto data = Item::toJson(); -        data["damage"]["dmg_type"] = damageType; -        data["damage"]["dmg_die_count"] = damageDieCount; -        data["damage"]["dmg_die_sides"] = damageDieSides; -        data["properties"] = properties; -        data["type"] = weaponType; -        data["range"] = range; -        data["reach"] = reach; -        return data; -    } -      std::string genActionText(const Weapon& w, const creature::Creature& c) {          stringstream text;          // Determine best ability bonus diff --git a/src/weapon.h b/src/weapon.h index f09e8e5..e4755df 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -10,16 +10,31 @@ namespace creature {  namespace item {      class Weapon : public Item {          public: -            Weapon(const nlohmann::json& data); -            std::string getDamageType(void) const; -            int getDamageDieCount(void) const; +            Weapon(const nlohmann::json& data, const nlohmann::json& base) : Item(base), damageType(data["damage"]["dmg_type"]), damageDieCount(data["damage"]["dmg_die_count"]), damageDieSides(data["damage"]["dmg_die_sides"]), properties(data["properties"]), weaponType(data["type"]), range(data["range"][0], data["range"][1]), reach(data["reach"]), cost(data["cost"]), weight(data["weight"]) {} + +            std::string getDamageType(void) const {return damageType;} +            int getDamageDieCount(void) const {return damageDieCount;}              int getDamageDieSides(bool versatile=false) const; -            std::set<std::string> getProperties(void) const; -            std::string getWeaponType(void) const; -            std::pair<int, int> getRange(void) const; -            int getReach(void) const; +            std::set<std::string> getProperties(void) const {return properties;} +            std::string getWeaponType(void) const {return weaponType;} +            std::pair<int, int> getRange(void) const {return range;} +            int getReach(void) const {return reach;} +            int getCost(void) const {return cost;} +            double getWeight(void) const {return weight;} -            virtual nlohmann::json toJson(void) const; +            /*virtual nlohmann::json toJson(void) const { +                auto data = Item::toJson(); +                data["damage"]["dmg_type"] = damageType; +                data["damage"]["dmg_die_count"] = damageDieCount; +                data["damage"]["dmg_die_sides"] = damageDieSides; +                data["properties"] = properties; +                data["type"] = weaponType; +                data["range"] = range; +                data["reach"] = reach; +                data["cost"] = cost; +                data["weight"] = weight; +                return data; +            }*/          private:              const std::string damageType; @@ -29,6 +44,8 @@ namespace item {              const std::string weaponType;              const std::pair<const int, const int> range;              const int reach; +            const int cost; +            const double weight;      };      std::string genActionText(const Weapon& w, const creature::Creature& c);  | 
