summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/character.cpp22
-rw-r--r--src/game-server/character.hpp10
-rw-r--r--src/game-server/itemmanager.cpp2
-rw-r--r--src/game-server/state.cpp8
4 files changed, 41 insertions, 1 deletions
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)
{