From d0e356d09e30a11c1e072415a5088f829d5c0a04 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 16 Jan 2022 21:32:01 -0500 Subject: Worked on features --- src/rules.h | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/rules.h') diff --git a/src/rules.h b/src/rules.h index 2894947..30464a8 100644 --- a/src/rules.h +++ b/src/rules.h @@ -2,6 +2,7 @@ #include "utils.h" #include #include +#include #include #include #include @@ -18,6 +19,10 @@ namespace rules { ri.payload = j; } std::string getPayload(void) const {return payload;} + bool operator==(const RuleItem& rhs) const {return getPayload() == rhs.getPayload();} + bool operator<(const RuleItem& rhs) const {return getPayload() < rhs.getPayload();} + operator std::string() const {return getPayload();} + operator bool() const {return ! getPayload().empty();} protected: std::string payload; }; @@ -26,10 +31,6 @@ namespace rules { public: std::string getFull() const {return abilities.at(getAbbrev());} std::string getAbbrev() const {return getPayload();} - operator std::string() const {return getAbbrev();} - bool operator<(const Ability& rhs) const {return getAbbrev() < rhs.getAbbrev();} - bool operator==(const Ability& rhs) const {return getAbbrev() == rhs.getAbbrev();} - operator bool() const {return ! getAbbrev().empty();} Ability() {} Ability(const std::string& abbrev) { @@ -67,10 +68,6 @@ namespace rules { public: std::string getName() const {return getPayload();} Ability getAbility() const {return Ability(skill2ability.at(getName()));} - operator std::string() const {return getName();} - bool operator<(const Skill& rhs) const {return getName() < rhs.getName();} - bool operator==(const Skill& rhs) const {return getName() == rhs.getName();} - operator bool() const {return ! getName().empty();} virtual ~Skill() {} @@ -128,9 +125,7 @@ namespace rules { } std::string getNegative() const {return getPayload();} std::string getPositive() const {return negative2positive.at(getNegative());} - operator std::string() const {return getNegative();} virtual ~Qualifier() {} - bool operator==(const Qualifier& rhs) const {return getNegative() == rhs.getNegative();} static Qualifier Magical() {return Qualifier("nonmagical");} static Qualifier Silvered() {return Qualifier("non-silvered");} @@ -140,9 +135,38 @@ namespace rules { static const std::map negative2positive; }; + class Condition : public RuleItem { + public: + Condition() {} + Condition(std::string name) { + utils::lower(name); + if(conditions.count(name) == 0) { + throw std::invalid_argument("No such condition: " + name); + } + payload = name; + } + + virtual ~Condition() {} + + void incExhaustion() { + if(payload.find("exhausted") == std::string::npos) { + throw std::invalid_argument("Cannot increment exhaustion on condition " + payload); + } + int exhLvl = utils::parseInt(std::string(1, payload.back())); + if(exhLvl >= 6) { + throw std::invalid_argument("Cannot increment exhaustion beyond level 6"); + } + payload.back() = '0'+exhLvl+1; + } + + private: + static const std::set conditions; + }; + std::ostream& operator<<(std::ostream& os, const Ability& a); std::ostream& operator<<(std::ostream& os, const Skill& s); std::ostream& operator<<(std::ostream& os, const Qualifier& q); + std::ostream& operator<<(std::ostream& os, const Condition& c); template T tryGetAbilityOrSkill(std::string src) { try { -- cgit v1.2.3