diff options
author | Your Name <you@example.com> | 2021-04-13 15:14:34 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-04-13 15:14:34 -0400 |
commit | 2ab51e507d620c4479e07ca0ec47d22c8c66bc90 (patch) | |
tree | 90906ecb043c01034280c767b83a88eb6df6956f /src/test.cc | |
download | dmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.tar.gz dmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.tar.bz2 dmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.zip |
Initial commit
Diffstat (limited to 'src/test.cc')
-rw-r--r-- | src/test.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test.cc b/src/test.cc new file mode 100644 index 0000000..e236860 --- /dev/null +++ b/src/test.cc @@ -0,0 +1,59 @@ +#include "creature.h" +#include "feature.h" +#include <iostream> +#include <sstream> +#include "rules.h" +#include "utils.h" +#include "item.h" +#include "armor.h" +#include "weapon.h" + +using namespace std; + +template<typename T> vector<string> mapItems(const vector<shared_ptr<T>>& items) { + vector<string> out; + for(auto i : items) { + out.push_back(i->getName()); + } + return out; +} + +int main(int argc, char *argv[]) { + creature::Creature c(utils::loadJson(argv[argc-1])); + cout << c.getCreatureName() << " " << c.getGivenName() << ", a cr " << c.getCR() << " " << c.getAlignment() << " " << c.getSize() << " " << c.getType() << ", has " << c.getHP() << " hp, ac " << creature::getAC(c) << " (" << utils::join(mapItems(creature::getItems<item::Armor>(c)), ", ") << "), speaks " << c.getLanguages() << ", has " << utils::join(c.getSenses(), ", ") << ", speed " << c.getSpeed() << ", and wields " << utils::join(mapItems(creature::getItems<item::Weapon>(c)), ", ") << ".\n Stats:\n"; + for(auto ability : abilities) { + cout << ability << ": " << c.getScore(ability) << " (" << c.getBonus(ability) << ")\n"; + } + cout << "\nSkills:\n"; + for(auto skill : c.getSkills()) { + cout << skill.first << " (+" << skill.second << ")\n"; + } + cout << "\nSaves:\n"; + for(auto save : c.getSaves()) { + cout << save.first << " (+" << save.second << ")\n"; + } + cout << "\nFeatures:\n"; + for(auto f: c.getFeatures()) { + cout << f->getName() << " (" << f->getType() << "):\n"; + cout << f->getText() << "\n\n"; + } + cout << "\nWeapons:\n"; + for(auto w : creature::getItems<item::Weapon>(c)) { + cout << w->getName() << " (" << w->getCost() << " cp, i.e., " << utils::getCostString(w->getCost()) << ", " << w->getWeight() << "lbs): "; + cout << item::genActionText(*w, c); + } + cout << "\nArmor:\n"; + for(auto a : creature::getItems<item::Armor>(c)) { + cout << a->getName() << " (" << a->getCost() << " cp, i.e., " << utils::getCostString(a->getCost()) << ", " << a->getWeight() << "lbs): "; + cout << "AC bonus: " << a->getACBonus() << "; type: " << a->getArmorType() << "; strReq: " << a->getStrRequirement() << "; stealthDis: " << a->stealthDisadvantage() << "\n"; + } + + cout << "We strike him with mace, dealing 5 fire damage!\n"; + 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 << "Saving to out.json...\n"; + utils::saveJson(c.toJson(), "out.json"); +} |