diff options
-rw-r--r-- | src/game-server/attributemanager.cpp | 22 | ||||
-rw-r--r-- | src/game-server/attributemanager.h | 38 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 6 |
3 files changed, 41 insertions, 25 deletions
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp index c51054c1..6cbdae9f 100644 --- a/src/game-server/attributemanager.cpp +++ b/src/game-server/attributemanager.cpp @@ -54,7 +54,7 @@ void AttributeManager::reload() j != i->second.second.end(); ++j) { - tag = getTagFromInfo(i->first, lCount); + tag = getTag(ModifierLocation(i->first, lCount)); std::string end = tag ? "tag of '" + (*tag) + "'." : "no tag."; LOG_DEBUG(" stackableType: " << j->stackableType << ", effectType: " << j->effectType << ", and " << end); @@ -68,14 +68,14 @@ void AttributeManager::reload() for (TagMap::const_iterator i = mTagMap.begin(), i_end = mTagMap.end(); i != i_end; ++i) { - LOG_DEBUG("Tag '" << i->first << "': '" << i->second.first << "', '" - << i->second.second << "'."); + LOG_DEBUG("Tag '" << i->first << "': '" << i->second.attributeId + << "', '" << i->second.layer << "'."); } LOG_INFO("Loaded '" << mTagMap.size() << "' modifier tags."); } -const std::vector<struct AttributeInfoType> *AttributeManager::getAttributeInfo(unsigned int id) const +const std::vector<struct AttributeInfoType> *AttributeManager::getAttributeInfo(int id) const { AttributeMap::const_iterator ret = mAttributeMap.find(id); if (ret == mAttributeMap.end()) @@ -88,7 +88,7 @@ const AttributeScope &AttributeManager::getAttributeScope(ScopeType type) const return mAttributeScopes[type]; } -bool AttributeManager::isAttributeDirectlyModifiable(unsigned int id) const +bool AttributeManager::isAttributeDirectlyModifiable(int id) const { AttributeMap::const_iterator ret = mAttributeMap.find(id); if (ret == mAttributeMap.end()) @@ -96,18 +96,16 @@ bool AttributeManager::isAttributeDirectlyModifiable(unsigned int id) const return ret->second.first; } -// { attribute id, layer } -std::pair<unsigned int,unsigned int> AttributeManager::getInfoFromTag(const std::string &tag) const +ModifierLocation AttributeManager::getLocation(const std::string &tag) const { return mTagMap.at(tag); } -const std::string *AttributeManager::getTagFromInfo(unsigned int attribute, - unsigned int layer) const +const std::string *AttributeManager::getTag(const ModifierLocation &location) const { for (TagMap::const_iterator it = mTagMap.begin(), it_end = mTagMap.end(); it != it_end; ++it) - if (it->second.first == attribute && it->second.second == layer) + if (it->second == location) return &it->first; return 0; } @@ -255,7 +253,7 @@ void AttributeManager::readModifierNode(xmlNodePtr modifierNode, if (!tag.empty()) { const int layer = mAttributeMap[attributeId].second.size() - 1; - mTagMap.insert(std::make_pair(tag, std::make_pair(attributeId, - layer))); + mTagMap.insert(std::make_pair(tag, ModifierLocation(attributeId, + layer))); } } diff --git a/src/game-server/attributemanager.h b/src/game-server/attributemanager.h index a26fd6a4..c4843c3a 100644 --- a/src/game-server/attributemanager.h +++ b/src/game-server/attributemanager.h @@ -36,7 +36,25 @@ enum ScopeType MaxScope }; -typedef std::map< int, std::vector<struct AttributeInfoType> * > AttributeScope; +typedef std::map<int, std::vector<struct AttributeInfoType> *> AttributeScope; + +/** + * Identifies a modifier by the attribute id that it applies to and its layer + * index in the stack of modifiers for that attribute. + */ +struct ModifierLocation +{ + int attributeId; + int layer; + + ModifierLocation(int attributeId, int layer) + : attributeId(attributeId) + , layer(layer) + {} + + bool operator==(const ModifierLocation &other) const + { return attributeId == other.attributeId && layer == other.layer; } +}; class AttributeManager { @@ -55,15 +73,15 @@ class AttributeManager */ void reload(); - const std::vector<struct AttributeInfoType> *getAttributeInfo(unsigned int) const; + const std::vector<struct AttributeInfoType> *getAttributeInfo(int id) const; const AttributeScope &getAttributeScope(ScopeType) const; - bool isAttributeDirectlyModifiable(unsigned int) const; + bool isAttributeDirectlyModifiable(int id) const; - std::pair<unsigned int,unsigned int> getInfoFromTag(const std::string &) const; + ModifierLocation getLocation(const std::string &tag) const; - const std::string *getTagFromInfo(unsigned int, unsigned int) const; + const std::string *getTag(const ModifierLocation &location) const; private: void readAttributesFile(); @@ -71,14 +89,14 @@ class AttributeManager void readModifierNode(xmlNodePtr modifierNode, int attributeId); // modifiable, { stackable type, effect type }[] - typedef std::pair< bool, + typedef std::pair<bool, std::vector<struct AttributeInfoType> > AttributeInfoMap; // Attribute id -> { modifiable, { stackable type, effect type }[] } - typedef std::map< int, AttributeInfoMap > AttributeMap; - // tag name -> { attribute id, layer } - typedef std::map< std::string, - std::pair<unsigned int, unsigned int> > TagMap; + typedef std::map<int, AttributeInfoMap> AttributeMap; + + /** Maps tag names to specific modifiers. */ + typedef std::map<std::string, ModifierLocation> TagMap; // being type id -> (*{ stackable type, effect type })[] AttributeScope mAttributeScopes[MaxScope]; diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index ecf9555a..3e7c673a 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -269,10 +269,10 @@ void ItemManager::reload() unsigned int duration = XML::getProperty(effectnode, "duration", 0); - std::pair<unsigned int, unsigned int> info = attributeManager->getInfoFromTag(tag); + ModifierLocation location = attributeManager->getLocation(tag); double value = XML::getFloatProperty(effectnode, "value", 0.0); - item->addEffect(new ItemEffectAttrMod(info.first, - info.second, + item->addEffect(new ItemEffectAttrMod(location.attributeId, + location.layer, value, id, duration), triggerTypes.first, triggerTypes.second); |