diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-03-22 23:04:06 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-03-22 23:04:06 +0000 |
commit | 164f19d705d0fc5745b7dda0547c23d1d06d05a1 (patch) | |
tree | 21e40e143b641a66b231196d21bd20a474834e26 /src | |
parent | a2f25c34db9db5c8fe57e0abdc9162531667fd06 (diff) | |
download | manaserv-164f19d705d0fc5745b7dda0547c23d1d06d05a1.tar.gz manaserv-164f19d705d0fc5745b7dda0547c23d1d06d05a1.tar.bz2 manaserv-164f19d705d0fc5745b7dda0547c23d1d06d05a1.tar.xz manaserv-164f19d705d0fc5745b7dda0547c23d1d06d05a1.zip |
Implemented communication of attribute changes from server to client.
Diffstat (limited to 'src')
-rw-r--r-- | src/account-server/accounthandler.cpp | 2 | ||||
-rw-r--r-- | src/defines.h | 3 | ||||
-rw-r--r-- | src/game-server/character.cpp | 22 | ||||
-rw-r--r-- | src/game-server/character.hpp | 10 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 2 | ||||
-rw-r--r-- | src/game-server/state.cpp | 8 |
6 files changed, 44 insertions, 3 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index fc61ca72..9d9949f3 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -227,7 +227,7 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) charInfo.writeByte(chars[i]->getHairStyle()); charInfo.writeByte(chars[i]->getHairColor()); charInfo.writeByte(chars[i]->getLevel()); - charInfo.writeShort(chars[i]->getMoney()); + charInfo.writeLong(chars[i]->getMoney()); for (int j = 0; j < NB_BASE_ATTRIBUTES; ++j) charInfo.writeShort(chars[i]->getBaseAttribute(j)); diff --git a/src/defines.h b/src/defines.h index dc27c3b4..ad1b47e0 100644 --- a/src/defines.h +++ b/src/defines.h @@ -147,6 +147,7 @@ enum { PGMSG_EQUIP = 0x0112, // B slot GPMSG_INVENTORY = 0x0120, // { B slot, W item id [, B amount] }* GPMSG_INVENTORY_FULL = 0x0121, // { B slot, W item id [, B amount] }* + GPMSG_PLAYER_ATTRIBUTE_UPDATE = 0x0130, // { W attribute, W value }* GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position // character: S name, B hair style, B hair color, B gender // monster: W type id @@ -302,7 +303,7 @@ enum BeingStats ATTR_EFF_INTELLIGENCE, ATTR_EFF_WILLPOWER, ATTR_EFF_CHARISMA, - NB_EFFECTIVE_ATTRIBUTES = ATTR_EFF_CHARISMA, + NB_EFFECTIVE_ATTRIBUTES, DERIVED_ATTR_HP_MAXIMUM = NB_EFFECTIVE_ATTRIBUTES, // Computed stats DERIVED_ATTR_PHYSICAL_ATTACK_MINIMUM, diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index ea4dd7c4..4e09d791 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -26,6 +26,7 @@ #include "defines.h" #include "net/messagein.hpp" +#include "net/messageout.hpp" InventoryItem tempItem; @@ -42,6 +43,7 @@ Character::Character(MessageIn & msg): } // prepare attributes vector mAttributes.resize(NB_ATTRIBUTES_CHAR, 1); + mOldAttributes.resize(NB_ATTRIBUTES_CHAR, 0); // get base attributes deserialize(msg); // give the player 10 weapon skill for testing purpose @@ -105,6 +107,8 @@ void Character::calculateDerivedAttributes() /* * Do any player character specific attribute calculation here */ + + mAttributesChanged = true; } WeaponStats @@ -122,3 +126,21 @@ Character::getWeaponStats() return weaponStats; }; +void +Character::writeAttributeUpdateMessage(MessageOut &msg) +{ + if (!mAttributesChanged) return; + + for (int i = 0; i<NB_ATTRIBUTES_CHAR; i++) + { + unsigned short attribute = getAttribute(i); + if (attribute != mOldAttributes[i]) + { + msg.writeShort(i); + msg.writeShort(attribute); + mOldAttributes[i] = attribute; + } + } + + mAttributesChanged = false; +} diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index b1c31f1b..db93e5e7 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -172,6 +172,13 @@ class Character : public Being, public AbstractCharacterData { Being::setAttribute(attributeNumber, value); } /** + * Creates a message that informs the client about the attribute + * changes since last call. + */ + void + writeAttributeUpdateMessage(MessageOut &msg); + + /** * Gets the Id of the map that the character is on. * Inherited from Thing through Being, explicitly defined because * of double inheritance. @@ -255,6 +262,9 @@ class Character : public Being, public AbstractCharacterData GameClient *mClient; /**< Client computer. */ + std::vector<unsigned short> mOldAttributes; /**< Atributes as the client should currently know them */ + bool attributesChanged; /**< true when one or more attributes might have changed since the client has been updated about them. */ + int mDatabaseID; /**< Character's database ID. */ std::string mName; /**< Name of the character. */ unsigned char mGender; /**< Gender of the character. */ diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 1c456175..8802ce7a 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -89,9 +89,9 @@ ItemManager::ItemManager(std::string const &itemReferenceFile) modifiers.lifetime = XML::getProperty(node, "lifetime", 0); modifiers.attributes[BASE_ATTR_STRENGTH] = XML::getProperty(node, "strength", 0); modifiers.attributes[BASE_ATTR_AGILITY] = XML::getProperty(node, "agility", 0); + modifiers.attributes[BASE_ATTR_DEXTERITY] = XML::getProperty(node, "dexterity", 0); modifiers.attributes[BASE_ATTR_VITALITY] = XML::getProperty(node, "vitality", 0); modifiers.attributes[BASE_ATTR_INTELLIGENCE] = XML::getProperty(node, "intelligence", 0); - modifiers.attributes[BASE_ATTR_DEXTERITY] = XML::getProperty(node, "dexterity", 0); modifiers.attributes[BASE_ATTR_WILLPOWER] = XML::getProperty(node, "willpower", 0); modifiers.attributes[BASE_ATTR_CHARISMA] = XML::getProperty(node, "charisma", 0); modifiers.attributes[DERIVED_ATTR_HP_MAXIMUM] = XML::getProperty(node, "hp", 0); diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 9a58edc7..929d4304 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -89,6 +89,7 @@ void State::informPlayer(MapComposite *map, Character *p) Point pold = p->getOldPosition(), ppos = p->getPosition(); int pid = p->getPublicID(), pflags = p->getUpdateFlags(); + // Inform client about activities of other beings near its character for (MovingObjectIterator i(map->getAroundCharacterIterator(p, AROUND_AREA)); i; ++i) { MovingObject *o = *i; @@ -233,6 +234,13 @@ void State::informPlayer(MapComposite *map, Character *p) if (damageMsg.getLength() > 2) gameHandler->sendTo(p, damageMsg); + // Inform client about attribute changes of its character + MessageOut attributeUpdateMsg(GPMSG_PLAYER_ATTRIBUTE_UPDATE); + p->writeAttributeUpdateMessage(attributeUpdateMsg); + if (attributeUpdateMsg.getLength() > 2) + gameHandler->sendTo(p, attributeUpdateMsg); + + // Inform client about items on the ground around its character MessageOut itemMsg(GPMSG_ITEMS); for (FixedObjectIterator i(map->getAroundCharacterIterator(p, AROUND_AREA)); i; ++i) { |