aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-13 16:16:27 -0400
committerYour Name <you@example.com>2021-04-13 16:16:27 -0400
commit9034c3d2533177f7cb7a7ce939ec53f7fa63f60e (patch)
tree49bf01a4682c251cb3778f563afeb7e1ec8d41c7 /src
parent2ab51e507d620c4479e07ca0ec47d22c8c66bc90 (diff)
downloaddmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.tar.gz
dmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.tar.bz2
dmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.zip
Added spells
Diffstat (limited to 'src')
-rw-r--r--src/creature.cc5
-rw-r--r--src/creature.cc.bak220
-rw-r--r--src/creature.h23
-rw-r--r--src/feature.cc1
-rw-r--r--src/test.cc4
5 files changed, 15 insertions, 238 deletions
diff --git a/src/creature.cc b/src/creature.cc
index 1a1463c..24a8087 100644
--- a/src/creature.cc
+++ b/src/creature.cc
@@ -23,7 +23,6 @@ namespace creature {
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"]))
{
- cout << "Initialized this far...\n\n";
// Initialize features + inventory
for(json data : data["features"]) {
features.push_back(feature::Feature::create(data));
@@ -175,10 +174,6 @@ namespace creature {
return stats.at(ability);
}
- void Creature::setScore(const string& ability, int score) {
- stats[ability] = score;
- }
-
string Creature::getSpeed() const {
return speed;
}
diff --git a/src/creature.cc.bak b/src/creature.cc.bak
deleted file mode 100644
index 377b0ec..0000000
--- a/src/creature.cc.bak
+++ /dev/null
@@ -1,220 +0,0 @@
-#include "creature.h"
-#include "json.hpp"
-#include "dice.h"
-#include "rules.h"
-#include "feature.h"
-#include "weapon.h"
-#include "armor.h"
-#include <algorithm>
-#include <fstream>
-#include <iostream>
-#include <iomanip>
-#include <exception>
-
-using namespace nlohmann;
-using namespace std;
-
-namespace creature {
- Creature::Creature(json dat) : data(dat) {
- if(! ((map<string, json>) data).contains("maxHP")) {
- data["maxHP"] = getBonus("con") * (int) data["hit_die_count"];
- for(int i = 0; i < data["hit_die_count"]; i++) {
- data["maxHP"] = ((int) data["maxHP"]) + roll(data["hit_die_sides"]);
- }
- data["currentHP"] = data["maxHP"];
- data["givenName"] = "Jerry"; //TODO: Autogenerate
- }
- }
-
- Creature::~Creature() {}
-
- void Creature::save(string saveFile) {
- ofstream f(saveFile);
- f << std::setw(4) << data << std::endl;
- }
-
- string Creature::getCreatureName() const {
- return data["name"];
- }
-
- string Creature::getGivenName() const {
- return data["givenName"];
- }
-
- void Creature::setGivenName(string name) {
- data["givenName"] = name;
- }
-
- string Creature::getType() const {
- return data["type"];
- }
-
- string Creature::getSize() const {
- return data["size"];
- }
-
- string Creature::getAlignment() const {
- return data["alignment"];
- }
-
- double Creature::getCR() const {
- return data["cr"];
- }
-
- string Creature::getLanguages() const {
- return data["langs"];
- }
-
- int Creature::getHP() const {
- return data["currentHP"];
- }
-
- int Creature::getHPMax() const {
- return data["maxHP"];
- }
-
- // True if type without matching qualifiers is in subdata
- bool conditionApplies(const string& type, const vector<string>& qualifiers, const json& subdata) {
- bool applies = false;
- for(auto con : subdata) {
- if(con["type"] == type) {
- applies = true;
- for(string qualifier : qualifiers) {
- if(find(con["qualifiers"].begin(), con["qualifiers"].end(), qualifier) == con["qualifiers"].end()) {
- applies = false;
- }
- }
- }
- }
- return applies;
- }
-
- void Creature::applyDamage(int amount, const string& type, const vector<string>& qualifiers) {
- if(! conditionApplies(type, qualifiers, data["d_immunities"])) {
- if(conditionApplies(type, qualifiers, data["d_resistances"])) {
- data["currentHP"] = ((int) data["currentHP"]) - amount / 2;
- } else if(conditionApplies(type, qualifiers, data["d_vulnerabilities"])) {
- data["currentHP"] = ((int) data["currentHP"]) - amount * 2;
- } else {
- data["currentHP"] = ((int) data["currentHP"]) - amount;
- }
- }
- }
-
- vector<string> Creature::getSenses() const {
- vector<string> senses;
- for(string sense : data["senses"]) {
- senses.push_back(sense);
- }
- return senses;
- }
-
- int Creature::getBonus(const string& ability) const {
- return (int) (getScore(ability) - 10) / 2;
- }
-
- int Creature::getSkillBonus(const string& skill) const {
- int bonus = getBonus(skill2ability[skill]);
- bonus += getProficiencyLevel(skill) * getProficiency();
- return bonus;
- }
-
- int Creature::getProficiencyLevel(const string& skill) const {
- if(data["skills"].find(skill) != data["skills"].end()) {
- return ((int) data["skills"][skill]);
- }
- return 0;
- }
-
- int Creature::getScore(const string& ability) const {
- return data["stats"][ability];
- }
-
- void Creature::setScore(const string& ability, int score) {
- data["stats"][ability] = score;
- }
-
- int Creature::getAC() const {
- int baseBonus = 10 + getBonus("dex");
- int miscBonus = 0;
- for(auto a : getItems<Armor>(*this)) {
- if(getScore("str") < a->getStrRequirement()) {
- continue;
- }
- auto armorType = a->getArmorType();
- if(armorType== "misc" || armorType == "shield") {
- miscBonus += a->getACBonus();
- } else {
- baseBonus = a->getACBonus();
- if(armorType == "light") {
- baseBonus += getBonus("dex");
- } else if(armorType == "medium") {
- baseBonus += (getBonus("dex") > 2)? 2 : getBonus("dex");
- }
- }
- }
- return baseBonus + miscBonus;
- }
-
- string Creature::getSpeed() const {
- return data["speed"];
- }
-
- int Creature::getAbilitySaveBonus(const string& ability) const {
- int bonus = getBonus(ability);
- if(find(data["saves"].begin(), data["saves"].end(), ability) != data["saves"].end()) {
- bonus += getProficiency();
- }
- return bonus;
- }
-
- int Creature::getProficiency() const {
- return data["prof"];
- }
-
- vector<shared_ptr<Feature>> Creature::getFeatures() const {
- vector<shared_ptr<Feature>> f;
- for(auto feat : data["features"]) {
- f.push_back(shared_ptr<Feature>(new Feature(feat)));
- }
- return f;
- }
-
- vector<shared_ptr<Item>> Creature::getInventory() const {
- vector<shared_ptr<Item>> i;
- for(auto item : data["inventory"]) {
- i.push_back(Item::create(item));
- }
- return i;
- }
-
- void Creature::addInventoryItem(Item item) {
- data["inventory"].push_back(item.toJson());
- }
-
- void Creature::removeInventoryItem(const string& name) {
- for(auto it = data["inventory"].begin(); it != data["inventory"].end(); it++) {
- auto i = Item::create(*it);
- if(i->getName() == name) {
- data["inventory"].erase(it);
- break;
- }
- }
- }
-
- map<string, int> Creature::getSkills() const {
- map<string, int> s;
- for(auto skill : (map<string, int>) data["skills"]) {
- s[skill.first] = getSkillBonus(skill.first);
- }
- return s;
- }
-
- map<string, int> Creature::getSaves() const {
- map<string, int> s;
- for(auto save : data["saves"]) {
- s[save] = getBonus(save) + getProficiency();
- }
- return s;
- }
-}
diff --git a/src/creature.h b/src/creature.h
index f73942f..6ba8cca 100644
--- a/src/creature.h
+++ b/src/creature.h
@@ -62,35 +62,38 @@ namespace creature {
// Setters (mutators)
void setGivenName(std::string);
void applyDamage(int amount, const std::string& type, const std::vector<std::string>& qualifiers);
- void setScore(const std::string& ability, int score);
+ //void setScore(const std::string& ability, int score);
void addInventoryItem(std::shared_ptr<item::Item> item);
void removeInventoryItem(const std::string& itemName);
virtual json toJson(void) const;
private:
- const std::string creatureName;
+ // Mutable variables
std::string givenName;
+ int hpMax;
+ int hp;
+ std::vector<std::shared_ptr<item::Item>> inventory;
+
+ //Immutable variables
+ const std::string creatureName;
const std::string size;
const std::string type;
const std::string alignment;
- int hdCount;
+ const int hdCount;
const int hdSides;
- int hpMax;
- int hp;
const std::string speed;
- std::map<std::string, int> stats;
- std::map<std::string, int> skills;
- std::vector<std::string> saves;
+ const std::map<std::string, int> stats;
+ const std::map<std::string, int> skills;
+ const std::vector<std::string> saves;
const std::vector<std::string> senses;
const std::string langs;
const double cr;
- int proficiency;
+ const int proficiency;
const std::vector<dmgType> dmgImmunities;
const std::vector<dmgType> dmgResistances;
const std::vector<dmgType> dmgVulnerabilities;
const std::vector<dmgType> condImmunities;
- std::vector<std::shared_ptr<item::Item>> inventory;
std::vector<std::shared_ptr<feature::Feature>> features;
};
diff --git a/src/feature.cc b/src/feature.cc
index 352850b..2747631 100644
--- a/src/feature.cc
+++ b/src/feature.cc
@@ -1,6 +1,5 @@
#include "json.hpp"
#include "feature.h"
-#include "creature.h"
#include <sstream>
#include <map>
diff --git a/src/test.cc b/src/test.cc
index e236860..1ce3d90 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -52,8 +52,8 @@ int main(int argc, char *argv[]) {
c.applyDamage(5, "fire", vector<string>());
cout << "Now he has " << c.getHP() << " out of " << c.getHPMax() << " hp.\n";
- cout << "Increasing str by 4...\n";
- c.setScore("str", c.getScore("str") + 4);
+ //cout << "Increasing str by 4...\n";
+ //c.setScore("str", c.getScore("str") + 4);
cout << "Saving to out.json...\n";
utils::saveJson(c.toJson(), "out.json");
}