aboutsummaryrefslogtreecommitdiff
path: root/src/creature.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/creature.cc')
-rw-r--r--src/creature.cc44
1 files changed, 4 insertions, 40 deletions
diff --git a/src/creature.cc b/src/creature.cc
index d4cf8c4..9366bac 100644
--- a/src/creature.cc
+++ b/src/creature.cc
@@ -1,5 +1,4 @@
#include "creature.h"
-#include "json.hpp"
#include "dice.h"
#include "rules.h"
#include "feature.h"
@@ -12,21 +11,13 @@
#include <sstream>
#include <iomanip>
-typedef nlohmann::json json;
using namespace std;
namespace creature {
- Creature::Creature(const json& data, const json& base)
- : Entry(base), inventory(data["inventory"]), stats(data["stats"]), skills(data["skills"]), prof(data["prof"]), size(data["size"]), alignment(data["alignment"]), hit_die_count(data["hit_die_count"]), hit_die_sides(data["hit_die_sides"]), speed(data["speed"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), observant(data["observant"]), natural_armor(data["natural_armor"]), d_immunities(data["d_immunities"]), d_resistances(data["d_resistances"]), d_vulnerabilities(data["d_vulnerabilities"]), c_immunities(data["c_immunities"]), features(data["features"])
- {
- // Initialize names and hp
- if(((map<string, json>) data).contains("givenName")) {
- givenName = data["givenName"];
- hpMax = data["hpMax"];
- hp = data["hp"];
- } else {
- givenName = "Jerry"; //TODO: Autogenerate
- hpMax = this->getBonus(rules::Ability::Con()) * hit_die_count;
+ void Creature::init() {
+ if(hpMax == -1) {
+ // Initialize hp
+ hpMax = getBonus(rules::Ability::Con()) * hit_die_count;
for(int i = 0; i < hit_die_count; i++) {
hpMax += dice::roll(hit_die_sides);
}
@@ -34,33 +25,6 @@ namespace creature {
}
}
- nlohmann::json Creature::toJson() const {
- nlohmann::json data = Entry::toJson();
- data["size"] = size;
- data["alignment"] = alignment;
- data["hit_die_count"] = hit_die_count;
- data["hit_die_sides"] = hit_die_sides;
- data["speed"] = speed;
- data["stats"] = stats;
- data["skills"] = skills;
- data["saves"] = saves;
- data["langs"] = langs;
- data["cr"] = cr;
- data["observant"] = observant;
- data["prof"] = prof;
- data["natural_armor"] = natural_armor;
- data["d_immunities"] = d_immunities;
- data["d_resistances"] = d_resistances;
- data["d_vulnerabilities"] = d_vulnerabilities;
- data["c_immunities"] = c_immunities;
- data["givenName"] = givenName;
- data["hpMax"] = hpMax;
- data["hp"] = hp;
- data["inventory"] = inventory;
- data["features"] = features;
- return data;
- }
-
// True if type without matching qualifiers is in subdata
bool conditionApplies(const string& type, const vector<rules::Qualifier>& qualifiers, const vector<dmgType> subdata) {
bool applies = false;