blob: 5ecdb0c2f6253ec21cfadf460df722cc41fc8f0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "item.h"
#include "weapon.h"
#include "armor.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <nlohmann/json.hpp>
using namespace std;
namespace entry {
shared_ptr<Item> Item::create(const nlohmann::json& data) {
if(data["type"] == "weapons" || data["type"] == "spell attack") {
auto w = utils::loadDFromJson<Item, Weapon>(data);
if(! data["text"].empty()) {
w->Entry::setText(data["text"]);
}
return w;
} else if(data["type"] == "armor") {
return utils::loadDFromJson<Item, Armor>(data);
}
return shared_ptr<Item>(new Item(data));
}
string Substantial::getText() const {
stringstream text;
if(getCost() >= 0) {
text << "Cost: ";
string costStr = to_string(getCost()) + " cp";
text << costStr;
string condensedCostStr = utils::getCostString(getCost());
if(costStr != condensedCostStr) {
text << ", i.e., " << condensedCostStr;
}
}
if(getWeight() >= 0) {
text << ". Weight: " << getWeight() << " lbs.";
}
return text.str();
}
}
|