diff options
Diffstat (limited to 'src/net/manaserv/charhandler.cpp')
-rw-r--r-- | src/net/manaserv/charhandler.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index e6723226..961b364a 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -36,8 +36,8 @@ #include "net/manaserv/gamehandler.h" #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" -#include "net/manaserv/protocol.h" -#include "net/manaserv/stats.h" +#include "net/manaserv/manaserv_protocol.h" +#include "net/manaserv/attributes.h" #include "resources/colordb.h" @@ -108,11 +108,15 @@ void CharHandler::handleCharacterInfo(Net::MessageIn &msg) info.level = msg.readInt16(); info.characterPoints = msg.readInt16(); info.correctionPoints = msg.readInt16(); - info.money = msg.readInt32(); - for (int i = 0; i < 7; i++) + while (msg.getUnreadLength() > 0) { - info.attribute[i] = msg.readInt8(); + int id = msg.readInt32(); + CachedAttrbiute attr; + attr.base = msg.readInt32() / 256.0; + attr.mod = msg.readInt32() / 256.0; + + info.attribute[id] = attr; } mCachedCharacterInfos.push_back(info); @@ -157,8 +161,14 @@ void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) case CREATE_ATTRIBUTES_TOO_LOW: errorMessage = _("Character's stats are too low."); break; - case CREATE_ATTRIBUTES_EQUAL_TO_ZERO: - errorMessage = _("One stat is zero."); + case CREATE_ATTRIBUTES_OUT_OF_RANGE: + errorMessage = strprintf( _("At least one stat" + "is out of the permitted range: (%u - %u)."), + Attributes::getAttributeMinimum(), + Attributes::getAttributeMaximum()); + break; + case CREATE_INVALID_SLOT: + errorMessage = _("Invalid slot number."); break; default: errorMessage = _("Unknown error."); @@ -189,7 +199,6 @@ void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) delete mSelectedCharacter; mCharacters.remove(mSelectedCharacter); updateCharSelectDialog(); - unlockCharSelectDialog(); new OkDialog(_("Info"), _("Player deleted.")); } else @@ -210,6 +219,7 @@ void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) new OkDialog(_("Error"), errorMessage); } mSelectedCharacter = 0; + unlockCharSelectDialog(); } void CharHandler::handleCharacterSelectResponse(Net::MessageIn &msg) @@ -233,6 +243,7 @@ void CharHandler::handleCharacterSelectResponse(Net::MessageIn &msg) // Prevent the selected local player from being deleted player_node = mSelectedCharacter->dummy; + PlayerInfo::setBackend(mSelectedCharacter->data); mSelectedCharacter->dummy = 0; Client::setState(STATE_CONNECT_GAME); @@ -259,7 +270,10 @@ void CharHandler::setCharCreateDialog(CharCreateDialog *window) if (!mCharCreateDialog) return; - mCharCreateDialog->setAttributes(Stats::getLabelVector(), 60, 1, 20); + mCharCreateDialog->setAttributes(Attributes::getLabels(), + Attributes::getCreationPoints(), + Attributes::getAttributeMinimum(), + Attributes::getAttributeMaximum()); } void CharHandler::requestCharacters() @@ -285,7 +299,7 @@ void CharHandler::chooseCharacter(Net::Character *character) } void CharHandler::newCharacter(const std::string &name, - int /* slot */, + int slot, bool gender, int hairstyle, int hairColor, @@ -297,6 +311,7 @@ void CharHandler::newCharacter(const std::string &name, msg.writeInt8(hairstyle); msg.writeInt8(hairColor); msg.writeInt8(gender); + msg.writeInt8(slot); std::vector<int>::const_iterator it, it_end; for (it = stats.begin(), it_end = stats.end(); it != it_end; it++) @@ -319,17 +334,17 @@ void CharHandler::switchCharacter() gameHandler->quit(true); } -int CharHandler::baseSprite() const +unsigned int CharHandler::baseSprite() const { return SPRITE_BASE; } -int CharHandler::hairSprite() const +unsigned int CharHandler::hairSprite() const { return SPRITE_HAIR; } -int CharHandler::maxSprite() const +unsigned int CharHandler::maxSprite() const { return SPRITE_VECTOREND; } @@ -350,19 +365,20 @@ void CharHandler::updateCharacters() Net::Character *character = new Net::Character; character->slot = info.slot; - LocalPlayer *player = character->dummy; + LocalPlayer *player = character->dummy = new LocalPlayer; player->setName(info.name); player->setGender(info.gender); player->setSprite(SPRITE_HAIR, info.hairStyle * -1, ColorDB::get(info.hairColor)); - player->setLevel(info.level); - player->setCharacterPoints(info.characterPoints); - player->setCorrectionPoints(info.correctionPoints); - player->setMoney(info.money); + character->data.mAttributes[LEVEL] = info.level; + character->data.mAttributes[CHAR_POINTS] = info.characterPoints; + character->data.mAttributes[CORR_POINTS] = info.correctionPoints; - for (int i = 0; i < 7; i++) + for (CachedAttributes::const_iterator it = info.attribute.begin(), + it_end = info.attribute.end(); it != it_end; it++) { - player->setAttributeBase(i, info.attribute[i], false); + character->data.mStats[i].base = it->second.base; + character->data.mStats[i].mod = it->second.mod; } mCharacters.push_back(character); |