diff options
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/accounthandler.cpp | 29 | ||||
-rw-r--r-- | src/account-server/character.h | 36 | ||||
-rw-r--r-- | src/account-server/storage.cpp | 7 |
3 files changed, 43 insertions, 29 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 41231b9d..9ac1be28 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -83,7 +83,7 @@ static int startPoints, attributesMinimum, attributesMaximum = 0; * The pair contains two elements of the same value (the default) so that the * iterators can be used to copy a range. */ -static std::map< unsigned int, std::pair< double, double> > defAttr; +static AttributeMap defaultAttributes; class AccountHandler : public ConnectionHandler { @@ -190,8 +190,8 @@ AccountHandler::AccountHandler(const std::string &attrFile): std::string defStr = XML::getProperty(attributenode, "default", ""); if (!defStr.empty()) { - double val = string_to<double>()(defStr); - defAttr.insert(std::make_pair(id,std::make_pair(val, val))); + const double val = string_to<double>()(defStr); + defaultAttributes.insert(std::make_pair(id, val)); } } else if (xmlStrEqual(attributenode->name, BAD_CAST "points")) @@ -295,8 +295,8 @@ void AccountHandler::sendCharacterData(AccountClient &client, { // {id, base value in 256ths, modified value in 256ths }* charInfo.writeInt32(it->first); - charInfo.writeInt32((int) (it->second.first * 256)); - charInfo.writeInt32((int) (it->second.second * 256)); + charInfo.writeInt32((int) (it->second.base * 256)); + charInfo.writeInt32((int) (it->second.modified * 256)); } client.send(charInfo); @@ -790,12 +790,16 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, else { Character *newCharacter = new Character(name); + + // Set the initial attributes provided by the client for (unsigned int i = 0; i < initAttr.size(); ++i) - newCharacter->mAttributes.insert(std::make_pair( - (unsigned int) (initAttr.at(i)), - std::make_pair((double) (attributes[i]), - (double) (attributes[i])))); - newCharacter->mAttributes.insert(defAttr.begin(), defAttr.end()); + { + newCharacter->mAttributes.insert( + std::make_pair(initAttr.at(i), attributes[i])); + } + + newCharacter->mAttributes.insert(defaultAttributes.begin(), + defaultAttributes.end()); newCharacter->setAccount(acc); newCharacter->setCharacterSlot(slot); newCharacter->setLevel(1); @@ -803,11 +807,10 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, // Init GP value to avoid flawed ones. AttributeMap::iterator itr = newCharacter->mAttributes.find(ATTR_GP); - // Set up the base and modified attribute to 0. if (itr != newCharacter->mAttributes.end()) { - itr->second.first = 0; - itr->second.second = 0; + itr->second.base = 0; + itr->second.modified = 0; } newCharacter->setCharacterPoints(0); diff --git a/src/account-server/character.h b/src/account-server/character.h index daa8a31c..cab6dc38 100644 --- a/src/account-server/character.h +++ b/src/account-server/character.h @@ -33,7 +33,26 @@ class Account; class MessageIn; class MessageOut; -typedef std::map< unsigned int, std::pair<double, double> > AttributeMap; +struct AttributeValue +{ + AttributeValue() + : base(0) + , modified(0) + {} + + AttributeValue(double value) + : base(value) + , modified(value) + {} + + double base; /**< Base value of the attribute. */ + double modified; /**< Value after various modifiers have been applied. */ +}; + +/** + * Stores attributes by their id. + */ +typedef std::map< unsigned int, AttributeValue > AttributeMap; /** placeholder type needed for include compatibility with game server*/ typedef void Special; @@ -115,10 +134,10 @@ class Character /** Sets the value of a base attribute of the character. */ void setAttribute(unsigned int id, double value) - { mAttributes[id].first = value; } + { mAttributes[id].base = value; } void setModAttribute(unsigned int id, double value) - { mAttributes[id].second = value; } + { mAttributes[id].modified = value; } int getSkillSize() const { return mExperience.size(); } @@ -236,9 +255,9 @@ class Character Character &operator=(const Character &); double getAttrBase(AttributeMap::const_iterator &it) const - { return it->second.first; } + { return it->second.base; } double getAttrMod(AttributeMap::const_iterator &it) const - { return it->second.second; } + { return it->second.modified; } Possessions mPossessions; //!< All the possesions of the character. std::string mName; //!< Name of the character. @@ -247,13 +266,6 @@ class Character int mAccountID; //!< Account ID of the owner. Account *mAccount; //!< Account owning the character. Point mPos; //!< Position the being is at. - /** - * Stores attributes. - * The key is an unsigned int which is the id of the attribute. - * The value stores the base value of the attribute in the first part, - * and the modified value in the second. The modified value is only - * used when transmitting to the client. - */ AttributeMap mAttributes; //!< Attributes. std::map<int, int> mExperience; //!< Skill Experience. std::map<int, int> mStatusEffects; //!< Status Effects diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 50b131b7..9d293a37 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -693,11 +693,10 @@ bool Storage::updateCharacter(Character *character) // Character attributes. try { - std::ostringstream sqlAttr; for (AttributeMap::const_iterator it = character->mAttributes.begin(), it_end = character->mAttributes.end(); it != it_end; ++it) updateAttribute(character->getDatabaseID(), it->first, - it->second.first, it->second.second); + it->second.base, it->second.modified); } catch (const dal::DbSqlQueryExecFailure &e) { @@ -998,8 +997,8 @@ void Storage::flush(Account *account) attr_it != attr_end; ++attr_it) { updateAttribute(character->getDatabaseID(), attr_it->first, - attr_it->second.first, - attr_it->second.second); + attr_it->second.base, + attr_it->second.modified); } // Update the characters skill |