Skip to content

Instantly share code, notes, and snippets.

/Attribute.h Secret

Created May 22, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/08dd2f616ef83b641ea7 to your computer and use it in GitHub Desktop.
Save anonymous/08dd2f616ef83b641ea7 to your computer and use it in GitHub Desktop.
class Attribute
{
public:
Attribute();
~Attribute();
Attribute(int value);
void addModifier(Modifier &m);
bool removeModifier(Modifier &m);
void set(int newValue) { _value = newValue; }
int getBase() { return _value; }
int getModifierTotal();
int get() { return getBase() + getModifierTotal(); }
void denyModifierType(Modifier::Type type);
void allowModifierType(Modifier::Type type);
bool modifierTypeIsDenied(Modifier::Type type);
void printModifiers();
private:
int _value;
int _modifierTotal;
bool _modifierTotalNeedsCompiling = true;
std::map < Modifier::Type, std::vector<Modifier*>> _modifierTable;
//std::map < Modifier::Type, std::vector<ModifierPtr>> _modifierTable;
std::vector<Modifier::Type> _deniedModifierTypes;
};
class Modifier
{
public:
static enum class Type {
Generic,
Ability_Score,
Alchemical,
Armor,
Circumstance,
Competence,
Deflection,
Dodge,
Enhancement,
Inherent,
Insight,
Luck,
Morale,
Natural_Armor,
Profane,
Racial,
Resistance,
Sacred,
Shield,
Size,
Trait,
Force
};
static const bool modifierTypeIsStackable(Type t) {
// All Modifier::Types stack with all other Modifier Types (Eg: Sacred + Profane)
// If isStackable, the bonus stacks with itself (Dodge + Dodge, but NOT Racial + Racial)
switch (t) {
case Type::Generic:
case Type::Dodge:
case Type::Circumstance:
return true;
default:
return false;
}
}
Modifier(Type type, int amount) :
_type(type), _amount(amount)
{
}
~Modifier();
bool isStackable() { return modifierTypeIsStackable(_type); }
int getAmount() { return _amount; }
Type getType() { return _type; }
// Used to determine, "Am I the modifier I'm being shown?"
bool compare(Modifier *m) { return (this == m); }
bool operator==(const Modifier &m) {
return this == &m;
}
private:
int _amount;
Type _type;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment