diff options
-rw-r--r-- | src/defines.h | 1 | ||||
-rw-r--r-- | src/game-server/character.cpp | 52 | ||||
-rw-r--r-- | src/game-server/character.hpp | 13 |
3 files changed, 58 insertions, 8 deletions
diff --git a/src/defines.h b/src/defines.h index f4d99630..a3669412 100644 --- a/src/defines.h +++ b/src/defines.h @@ -152,6 +152,7 @@ enum { PGMSG_ATTACK = 0x0290, // W being id GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction, B attacktype PGMSG_USE_SPECIAL = 0x0292, // B specialID + GPMSG_SPECIAL_STATUS = 0x0293, // { B specialID, L current, L max, L recharge } PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }* diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 9e68667c..301a8c5c 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -54,9 +54,19 @@ const AttackZone Character::UNARMED_ATTACK_ZONE = {ATTZONESHAPE_RECT, true, 48, Character::Character(MessageIn &msg): Being(OBJECT_CHARACTER), - mClient(NULL), mTransactionHandler(NULL), mDatabaseID(-1), - mGender(0), mHairStyle(0), mHairColor(0), mLevel(1), mLevelProgress(0), - mUpdateLevelProgress(false), mRecalculateLevel(true), mParty(0), + mClient(NULL), + mTransactionHandler(NULL), + mRechargePerSpecial(0), + mSpecialUpdateNeeded(false), + mDatabaseID(-1), + mGender(0), + mHairStyle(0), + mHairColor(0), + mLevel(1), + mLevelProgress(0), + mUpdateLevelProgress(false), + mRecalculateLevel(true), + mParty(0), mTransaction(TRANS_NONE) { Attribute attr = { 0, 0 }; @@ -103,13 +113,19 @@ void Character::update() } if (numRechargeNeeded > 0) { - int rechargePerSpecial = getModifiedAttribute(CHAR_ATTR_INTELLIGENCE) / numRechargeNeeded; + mRechargePerSpecial = getModifiedAttribute(CHAR_ATTR_INTELLIGENCE) / numRechargeNeeded; for (std::list<Special*>::iterator i = rechargeNeeded.begin(); i != rechargeNeeded.end(); i++) { - (*i)->currentMana += rechargePerSpecial; + (*i)->currentMana += mRechargePerSpecial; } } + if (mSpecialUpdateNeeded) + { + sendSpecialUpdate(); + mSpecialUpdateNeeded = false; + } + Being::update(); } @@ -215,9 +231,30 @@ void Character::useSpecial(int id) script->execute(); } + mSpecialUpdateNeeded = true; return; } +void Character::sendSpecialUpdate() +{ + //GPMSG_SPECIAL_STATUS = 0x0293, // { B specialID, L current, L max, L recharge } + for (std::map<int, Special*>::iterator i = mSpecials.begin(); + i != mSpecials.end(); + i++) + { + + MessageOut msg(GPMSG_SPECIAL_STATUS ); + msg.writeByte(i->first); + msg.writeLong(i->second->currentMana); + msg.writeLong(i->second->neededMana); + msg.writeLong(mRechargePerSpecial); + /* yes, the last one is redundant because it is the same for each + special, but I would like to keep the netcode flexible enough + to allow different recharge speed per special when necessary */ + gameHandler->sendTo(this, msg); + } +} + int Character::getMapId() const { return getMap()->getID(); @@ -410,6 +447,10 @@ void Character::flagAttribute(int attr) { // Warn the player of this attribute modification. mModifiedAttributes.insert(attr); + if (attr = CHAR_ATTR_INTELLIGENCE) + { + mSpecialUpdateNeeded = true; + } } int Character::expForLevel(int level) @@ -574,5 +615,6 @@ void Character::giveSpecial(int id) Special *s = new Special(neededMana); mSpecials[id] = s; + mSpecialUpdateNeeded = true; } } diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index 5eb9198e..ea979184 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -239,10 +239,10 @@ class Character : public Being void setMapId(int); /** - * Over loads Being::getAttribute, character skills are + * Over loads Being::getAttribute, character skills are * treated as extend attributes */ - int getAttribute(int) const; + int getAttribute(int) const; /** * Over loads Being::getModifiedAttribute @@ -277,7 +277,7 @@ class Character : public Being const std::map<int, int>::const_iterator getSkillBegin() const { return mExperience.begin(); } - + const std::map<int, int>::const_iterator getSkillEnd() const { return mExperience.end(); } @@ -377,6 +377,11 @@ class Character : public Being */ void recalculateLevel(); + /** + * Informs the client about his characters special charge status + */ + void sendSpecialUpdate(); + enum TransactionType { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; @@ -393,6 +398,8 @@ class Character : public Being std::map<int, int> mExperience; /**< experience collected for each skill.*/ std::map<int, Special*> mSpecials; + int mRechargePerSpecial; + bool mSpecialUpdateNeeded; int mDatabaseID; /**< Character's database ID. */ unsigned char mGender; /**< Gender of the character. */ |