#include "item.h" #include "weapon.h" #include "armor.h" #include "utils.h" #include #include #include #include using namespace std; namespace entry { shared_ptr Item::create(const nlohmann::json& data) { if(data["type"] == "weapons" || data["type"] == "spell attack") { auto w = utils::loadDFromJson(data); if(! data["text"].empty()) { w->Entry::setText(data["text"]); } return w; } else if(data["type"] == "armor") { return utils::loadDFromJson(data); } return utils::loadDFromJson(data); } struct itemImpl { int cost; double weight; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(itemImpl, cost, weight); NLOHMANN_FRIEND_DEFS(Entry, Item, data); Item::Item() : data(new itemImpl()) {} int Item::getCost() const {return data->cost;} double Item::getWeight() const {return data->weight;} string Item::getCostWeightText() 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(); } string Item::getText() const { return Entry::getText() + " " + getCostWeightText(); } string Item::getText(const creature::Creature& c) const { return getText(); } }