diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-06-08 18:31:30 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:47 +0200 |
commit | 1e5a15c0a5e24fb4b358fff75a7082d65496e1f9 (patch) | |
tree | 741756128a3587768fa02dbbdd9ba64820afe6cb /src | |
parent | 44ee071d7ece5a2023f79307f36e8a244c9e7b3a (diff) | |
download | manaserv-1e5a15c0a5e24fb4b358fff75a7082d65496e1f9.tar.gz manaserv-1e5a15c0a5e24fb4b358fff75a7082d65496e1f9.tar.bz2 manaserv-1e5a15c0a5e24fb4b358fff75a7082d65496e1f9.tar.xz manaserv-1e5a15c0a5e24fb4b358fff75a7082d65496e1f9.zip |
Readded level handling
Things done:
Wrote a entity:give_experience function (lua side only).
Renamed characterpoints to attributepoints (no db update. Did not want
to do one for a simple rename).
Temponary introduced a ATTR_LEVEL constant. TODO: dehardcode this.
Script binds for settings the correction and attribute points.
Diffstat (limited to 'src')
-rw-r--r-- | src/account-server/accounthandler.cpp | 2 | ||||
-rw-r--r-- | src/account-server/character.cpp | 2 | ||||
-rw-r--r-- | src/account-server/character.h | 10 | ||||
-rw-r--r-- | src/account-server/storage.cpp | 6 | ||||
-rw-r--r-- | src/common/defines.h | 4 | ||||
-rw-r--r-- | src/common/manaserv_protocol.h | 1 | ||||
-rw-r--r-- | src/game-server/character.cpp | 23 | ||||
-rw-r--r-- | src/game-server/character.h | 53 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 4 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 66 | ||||
-rw-r--r-- | src/serialize/characterdata.h | 4 |
11 files changed, 141 insertions, 34 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 87cb2b46..9271c0ab 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -280,7 +280,7 @@ void AccountHandler::sendCharacterData(AccountClient &client, charInfo.writeInt8(ch.getGender()); charInfo.writeInt8(ch.getHairStyle()); charInfo.writeInt8(ch.getHairColor()); - charInfo.writeInt16(ch.getCharacterPoints()); + charInfo.writeInt16(ch.getAttributePoints()); charInfo.writeInt16(ch.getCorrectionPoints()); for (AttributeMap::const_iterator it = ch.mAttributes.begin(), diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp index 3fc3ed19..9c371f54 100644 --- a/src/account-server/character.cpp +++ b/src/account-server/character.cpp @@ -32,7 +32,7 @@ CharacterData::CharacterData(const std::string &name, int id): mGender(0), mHairStyle(0), mHairColor(0), - mCharacterPoints(0), + mAttributePoints(0), mCorrectionPoints(0), mAccountLevel(0) { diff --git a/src/account-server/character.h b/src/account-server/character.h index 58e32dad..1fa0e975 100644 --- a/src/account-server/character.h +++ b/src/account-server/character.h @@ -245,11 +245,11 @@ class CharacterData Possessions &getPossessions() { return mPossessions; } - void setCharacterPoints(int points) - { mCharacterPoints = points; } + void setAttributePoints(int points) + { mAttributePoints = points; } - int getCharacterPoints() const - { return mCharacterPoints; } + int getAttributePoints() const + { return mAttributePoints; } void setCorrectionPoints(int points) { mCorrectionPoints = points; } @@ -283,7 +283,7 @@ class CharacterData unsigned char mGender; //!< Gender of the being. unsigned char mHairStyle; //!< Hair style of the being. unsigned char mHairColor; //!< Hair color of the being. - short mCharacterPoints; //!< Unused character points. + short mAttributePoints; //!< Unused character points. short mCorrectionPoints; //!< Unused correction points. unsigned char mAccountLevel; //!< Level of the associated account. diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 2ddb2e08..c2af965b 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -362,7 +362,7 @@ CharacterData *Storage::getCharacterBySQL(Account *owner) character->setGender(toUshort(charInfo(0, 3))); character->setHairStyle(toUshort(charInfo(0, 4))); character->setHairColor(toUshort(charInfo(0, 5))); - character->setCharacterPoints(toUshort(charInfo(0, 6))); + character->setAttributePoints(toUshort(charInfo(0, 6))); character->setCorrectionPoints(toUshort(charInfo(0, 7))); Point pos(toInt(charInfo(0, 8)), toInt(charInfo(0, 9))); character->setPosition(pos); @@ -702,7 +702,7 @@ bool Storage::updateCharacter(CharacterData *character) << "gender = '" << character->getGender() << "', " << "hair_style = '" << character->getHairStyle() << "', " << "hair_color = '" << character->getHairColor() << "', " - << "char_pts = '" << character->getCharacterPoints() << "', " + << "char_pts = '" << character->getAttributePoints() << "', " << "correct_pts = '"<< character->getCorrectionPoints() << "', " << "x = '" << character->getPosition().x << "', " << "y = '" << character->getPosition().y << "', " @@ -990,7 +990,7 @@ void Storage::flush(Account *account) << character->getGender() << ", " << (int)character->getHairStyle() << ", " << (int)character->getHairColor() << ", " - << (int)character->getCharacterPoints() << ", " + << (int)character->getAttributePoints() << ", " << (int)character->getCorrectionPoints() << ", " << character->getPosition().x << ", " << character->getPosition().y << ", " diff --git a/src/common/defines.h b/src/common/defines.h index 40be064e..86b97e25 100644 --- a/src/common/defines.h +++ b/src/common/defines.h @@ -219,7 +219,9 @@ enum // Money and inventory size attributes. ATTR_GP = 18, - ATTR_INV_CAPACITY = 19 + ATTR_INV_CAPACITY = 19, + + ATTR_LEVEL = 23 }; #endif // DEFINES_H diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 734ba1f2..d3f2c8b4 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -118,6 +118,7 @@ enum { GPMSG_INVENTORY_FULL = 0x0121, // W inventory slot count { W slot, W itemId, W amount }, { W equip slot, W item Id, W item Instance}* GPMSG_EQUIP = 0x0122, // W item Id, W equip slot type count //{ W equip slot, W capacity used}*//<- When equipping, //{ W item instance, W 0}*//<- When unequipping GPMSG_PLAYER_ATTRIBUTE_CHANGE = 0x0130, // { W attribute, D base value (in 1/256ths), D modified value (in 1/256ths)}* + GPMSG_ATTRIBUTE_POINTS_STATUS = 0x0140, // W character points, W correction points PGMSG_RAISE_ATTRIBUTE = 0x0160, // W attribute GPMSG_RAISE_ATTRIBUTE_RESPONSE = 0x0161, // B error, W attribute PGMSG_LOWER_ATTRIBUTE = 0x0170, // W attribute diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index e4a30a2f..a593b58b 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -69,6 +69,9 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mDatabaseID(-1), mHairStyle(0), mHairColor(0), + mSendAttributePointsStatus(false), + mAttributePoints(0), + mCorrectionPoints(0), mSendAbilityCooldown(false), mParty(0), mTransaction(TRANS_NONE), @@ -131,6 +134,9 @@ void CharacterComponent::update(Entity &entity) if (mSendAbilityCooldown) sendAbilityCooldownUpdate(entity); + + if (mSendAttributePointsStatus) + sendAttributePointsStatus(entity); } void CharacterComponent::characterDied(Entity *being) @@ -213,6 +219,15 @@ void CharacterComponent::sendAbilityCooldownUpdate(Entity &entity) mSendAbilityCooldown = false; } +void CharacterComponent::sendAttributePointsStatus(Entity &entity) +{ + MessageOut msg(GPMSG_ATTRIBUTE_POINTS_STATUS); + msg.writeInt16(mAttributePoints); + msg.writeInt16(mCorrectionPoints); + gameHandler->sendTo(mClient, msg); + mSendAttributePointsStatus = false; +} + void CharacterComponent::cancelTransaction() { TransactionType t = mTransaction; @@ -341,10 +356,10 @@ AttribmodResponseCode CharacterComponent::useCharacterPoint(Entity &entity, if (!attributeManager->isAttributeDirectlyModifiable(attribute)) return ATTRIBMOD_INVALID_ATTRIBUTE; - if (!mCharacterPoints) + if (!mAttributePoints) return ATTRIBMOD_NO_POINTS_LEFT; - --mCharacterPoints; + setAttributePoints(mAttributePoints - 1); const double base = beingComponent->getAttributeBase(attribute); beingComponent->setAttribute(entity, attribute, base + 1); @@ -364,8 +379,8 @@ AttribmodResponseCode CharacterComponent::useCorrectionPoint(Entity &entity, if (beingComponent->getAttributeBase(attribute) <= 1) return ATTRIBMOD_DENIED; - --mCorrectionPoints; - ++mCharacterPoints; + setCorrectionPoints(mCorrectionPoints - 1); + setAttributePoints(mAttributePoints + 1); const double base = beingComponent->getAttributeBase(attribute); beingComponent->setAttribute(entity, attribute, base - 1); diff --git a/src/game-server/character.h b/src/game-server/character.h index 162235ad..834f9fe3 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -64,8 +64,8 @@ public: void setAttribute(int id, int base); void setModAttribute(int id, int mod); const AttributeMap &getAttributes() const; - void setCharacterPoints(int characterPoints); - int getCharacterPoints() const; + void setAttributePoints(int characterPoints); + int getAttributePoints() const; void setCorrectionPoints(int correctionPoints); int getCorrectionPoints() const; @@ -285,11 +285,11 @@ class CharacterComponent : public Component AttribmodResponseCode useCorrectionPoint(Entity &entity, int attribute); - void setCharacterPoints(int points) { mCharacterPoints = points; } - int getCharacterPoints() const { return mCharacterPoints; } + void setAttributePoints(int points); + int getAttributePoints() const; - void setCorrectionPoints(int points) { mCorrectionPoints = points; } - int getCorrectionPoints() const { return mCorrectionPoints; } + void setCorrectionPoints(int points); + int getCorrectionPoints() const; /** @@ -350,12 +350,9 @@ class CharacterComponent : public Component void abilityStatusChanged(int id); void abilityCooldownActivated(); - /** - * Informs the client about his characters abilities charge status - */ void sendAbilityUpdate(Entity &entity); - void sendAbilityCooldownUpdate(Entity &entity); + void sendAttributePointsStatus(Entity &entity); enum TransactionType { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; @@ -381,8 +378,11 @@ class CharacterComponent : public Component int mDatabaseID; /**< Character's database ID. */ unsigned char mHairStyle; /**< Hair Style of the character. */ unsigned char mHairColor; /**< Hair Color of the character. */ - int mCharacterPoints; /**< Unused attribute points that can be distributed */ + + bool mSendAttributePointsStatus; + int mAttributePoints; /**< Unused attribute points that can be distributed */ int mCorrectionPoints; /**< Unused attribute correction points */ + bool mSendAbilityCooldown; unsigned char mAccountLevel; /**< Account level of the user. */ int mParty; /**< Party id of the character */ @@ -459,14 +459,14 @@ inline const AttributeMap &CharacterData::getAttributes() const return mEntity->getComponent<BeingComponent>()->getAttributes(); } -inline void CharacterData::setCharacterPoints(int characterPoints) +inline void CharacterData::setAttributePoints(int characterPoints) { - mCharacterComponent->setCharacterPoints(characterPoints); + mCharacterComponent->setAttributePoints(characterPoints); } -inline int CharacterData::getCharacterPoints() const +inline int CharacterData::getAttributePoints() const { - return mCharacterComponent->getCharacterPoints(); + return mCharacterComponent->getAttributePoints(); } inline void CharacterData::setCorrectionPoints(int correctionPoints) @@ -579,4 +579,27 @@ inline Possessions &CharacterData::getPossessions() const return mCharacterComponent->getPossessions(); } + +inline void CharacterComponent::setAttributePoints(int points) +{ + mSendAttributePointsStatus = true; + mAttributePoints = points; +} + +inline int CharacterComponent::getAttributePoints() const +{ + return mAttributePoints; +} + +inline void CharacterComponent::setCorrectionPoints(int points) +{ + mSendAttributePointsStatus = true; + mCorrectionPoints = points; +} + +inline int CharacterComponent::getCorrectionPoints() const +{ + return mCorrectionPoints; +} + #endif // CHARACTER_H diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index e9890c66..c7ff655a 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -890,7 +890,7 @@ void GameHandler::handleRaiseAttribute(GameClient &client, MessageIn &message) { accountHandler->updateCharacterPoints( characterComponent->getDatabaseID(), - characterComponent->getCharacterPoints(), + characterComponent->getAttributePoints(), characterComponent->getCorrectionPoints()); // log transaction @@ -920,7 +920,7 @@ void GameHandler::handleLowerAttribute(GameClient &client, MessageIn &message) { accountHandler->updateCharacterPoints( characterComponent->getDatabaseID(), - characterComponent->getCharacterPoints(), + characterComponent->getAttributePoints(), characterComponent->getCorrectionPoints()); // log transaction diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 624fbda1..13373d81 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1838,6 +1838,68 @@ static int entity_remove_attribute_modifier(lua_State *s) return 0; } +/** LUA entity:attribute_points (being) + * entity:attribute_points() + ** + * Valid only for character entities. + * + * *Returns:* Returns the amount of available attribute points. + */ +static int entity_attribute_points(lua_State *s) +{ + Entity *being = checkCharacter(s, 1); + auto *characterComponent = being->getComponent<CharacterComponent>(); + lua_pushinteger(s, characterComponent->getAttributePoints()); + return 1; +} + +/** LUA entity:set_attribute_points (being) + * entity:set_attribute_points(int amount) + ** + * Valid only for character entities. + * + * Sets the amount of attribute points for the entity + */ +static int entity_set_attribute_points(lua_State *s) +{ + Entity *being = checkCharacter(s, 1); + int points = luaL_checkint(s, 2); + auto *characterComponent = being->getComponent<CharacterComponent>(); + characterComponent->setAttributePoints(points); + return 0; +} + +/** LUA entity:correction_points (being) + * entity:correction_points() + ** + * Valid only for character entities. + * + * *Returns:* Returns the amount of available correction points. + */ +static int entity_correction_points(lua_State *s) +{ + Entity *being = checkCharacter(s, 1); + auto *characterComponent = being->getComponent<CharacterComponent>(); + lua_pushinteger(s, characterComponent->getCorrectionPoints()); + return 1; +} + +/** LUA entity:set_correction_points (being) + * entity:set_correction_points(int amount) + ** + * Valid only for character entities. + * + * Sets the amount of correction points for the entity + */ +static int entity_set_correction_points(lua_State *s) +{ + Entity *being = checkCharacter(s, 1); + int points = luaL_checkint(s, 2); + auto *characterComponent = being->getComponent<CharacterComponent>(); + characterComponent->setCorrectionPoints(points); + return 0; +} + /** LUA entity:gender (being) * entity:gender() ** @@ -3350,6 +3412,10 @@ LuaScript::LuaScript(): { "modified_attribute", entity_get_modified_attribute }, { "apply_attribute_modifier", entity_apply_attribute_modifier }, { "remove_attribute_modifier", entity_remove_attribute_modifier }, + { "attribute_points", entity_attribute_points }, + { "set_attribute_points", entity_set_attribute_points }, + { "correction_points", entity_correction_points }, + { "set_correction_points", entity_set_correction_points }, { "gender", entity_get_gender }, { "set_gender", entity_set_gender }, { "hair_color", entity_get_hair_color }, diff --git a/src/serialize/characterdata.h b/src/serialize/characterdata.h index a8554684..2e4620dc 100644 --- a/src/serialize/characterdata.h +++ b/src/serialize/characterdata.h @@ -38,7 +38,7 @@ void serializeCharacterData(const T &data, MessageOut &msg) msg.writeInt8(data.getGender()); msg.writeInt8(data.getHairStyle()); msg.writeInt8(data.getHairColor()); - msg.writeInt16(data.getCharacterPoints()); + msg.writeInt16(data.getAttributePoints()); msg.writeInt16(data.getCorrectionPoints()); @@ -115,7 +115,7 @@ void deserializeCharacterData(T &data, MessageIn &msg) data.setGender(ManaServ::getGender(msg.readInt8())); data.setHairStyle(msg.readInt8()); data.setHairColor(msg.readInt8()); - data.setCharacterPoints(msg.readInt16()); + data.setAttributePoints(msg.readInt16()); data.setCorrectionPoints(msg.readInt16()); // character attributes |