aboutsummaryrefslogtreecommitdiff
path: root/src/weapon.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-01 15:10:54 -0400
committerYour Name <you@example.com>2021-05-01 15:10:54 -0400
commit7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d (patch)
treed9b808542216f71dbab053ad23145903e96c6401 /src/weapon.h
parent5a813a75412ac9b8fadb90c9abd46dd95aee8e9b (diff)
downloaddmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.tar.gz
dmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.tar.bz2
dmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.zip
Added bash completion, amongst others
Diffstat (limited to 'src/weapon.h')
-rw-r--r--src/weapon.h46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/weapon.h b/src/weapon.h
index 7a8c0ba..9384f78 100644
--- a/src/weapon.h
+++ b/src/weapon.h
@@ -1,5 +1,6 @@
#pragma once
#include "item.h"
+#include "rules.h"
#include "json.hpp"
#include <set>
@@ -9,44 +10,61 @@ namespace creature {
namespace entry {
class Weapon;
+ class Damage;
std::string genText(const Weapon& w, const creature::Creature& c);
+ std::vector<rules::Ability> getAbilityOptions(const Weapon& w);
+ std::vector<Damage> rollDmg(const Weapon& w, bool versatile=false);
+ std::string formatDmg(const Weapon& w, const creature::Creature& c);
+
+ class Damage : public Jsonable {
+ public:
+ Damage(const nlohmann::json& data) : count(data["dmg_die_count"]), sides(data["dmg_die_sides"]), type(data["dmg_type"]), isOr(data["is_or"]) {}
+ const int count;
+ const int sides;
+ const std::string type;
+ const bool isOr;
+ int rolled = 0;
+
+ nlohmann::json toJson(void) const {
+ return nlohmann::json({
+ {"dmg_die_count", count},
+ {"dmg_die_sides", sides},
+ {"dmg_type", type},
+ {"is_or", isOr}
+ });
+ }
+ };
class Weapon : public Item, public Substantial {
public:
- Weapon(const nlohmann::json& data, const nlohmann::json& base) : Item(base), damageType(data["damage"]["dmg_type"]), damageDieCount(data["damage"]["dmg_die_count"]), damageDieSides(data["damage"]["dmg_die_sides"]), properties(data["properties"]), weaponType(data["weapon_type"]), range(data["range"][0], data["range"][1]), reach(data["reach"]), cost(data["cost"]), weight(data["weight"]) {}
+ Weapon(const nlohmann::json& data, const nlohmann::json& base) : Item(base), damage(json2vec<Damage>(data["damage"])), properties(data["properties"]), weaponType(data["weapon_type"]), range(data["range"][0], data["range"][1]), reach(data["reach"]), cost(data["cost"]), weight(data["weight"]) {}
- std::string getDamageType(void) const {return damageType;}
- int getDamageDieCount(void) const {return damageDieCount;}
- int getDamageDieSides(bool versatile=false) const;
+ std::vector<Damage> getDamage(void) const {return damage;}
std::set<std::string> getProperties(void) const {return properties;}
std::string getWeaponType(void) const {return weaponType;}
std::pair<int, int> getRange(void) const {return range;}
int getReach(void) const {return reach;}
int getCost(void) const {return cost;}
double getWeight(void) const {return weight;}
-
+
virtual std::string getText() const override;
virtual std::string getText(const creature::Creature& c) const override {return genText(*this, c);}
- /*virtual nlohmann::json toJson(void) const {
+ virtual nlohmann::json toJson(void) const {
auto data = Item::toJson();
- data["damage"]["dmg_type"] = damageType;
- data["damage"]["dmg_die_count"] = damageDieCount;
- data["damage"]["dmg_die_sides"] = damageDieSides;
+ data["damage"] = damage;
data["properties"] = properties;
- data["type"] = weaponType;
+ data["weapon_type"] = weaponType;
data["range"] = range;
data["reach"] = reach;
data["cost"] = cost;
data["weight"] = weight;
return data;
- }*/
+ }
private:
- const std::string damageType;
- const int damageDieCount;
- const int damageDieSides;
+ const std::vector<Damage> damage;
const std::set<std::string> properties;
const std::string weaponType;
const std::pair<const int, const int> range;