summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/gui/status.cpp8
-rw-r--r--src/localplayer.cpp4
-rw-r--r--src/localplayer.h114
-rw-r--r--src/net/playerhandler.cpp30
-rw-r--r--src/net/protocol.h2
6 files changed, 86 insertions, 78 deletions
diff --git a/ChangeLog b/ChangeLog
index f7c396ab..2259852d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-18 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+
+ * src/localplayer.cpp, src/gui/status.cpp, src/net/protocol.h,
+ src/net/playerhandler.cpp, src/localplayer.h: Adapted to new server
+ handling of character attributes.
+
2007-08-14 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/net/messagein.h, src/net/messagein.cpp: Fixed error-prone
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 8be019dd..7da3b905 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -31,6 +31,7 @@
#include "../localplayer.h"
+#include "../utils/strprintf.h"
#include "../utils/tostring.h"
StatusWindow::StatusWindow(LocalPlayer *player):
@@ -237,10 +238,9 @@ void StatusWindow::update()
for (int i = 0; i < 7; i++) {
mStatsLabel[i]->setCaption(attrNames[i]);
mStatsDisplayLabel[i]->setCaption(
- toString(mPlayer->getAttributeEffective(i)) +
- " / " +
- toString(mPlayer->getAttributeBase(i))
- );
+ strprintf("%d / %d",
+ mPlayer->getAttributeEffective(CHAR_ATTR_BEGIN + i),
+ mPlayer->getAttributeBase(CHAR_ATTR_BEGIN + i)));
mStatsLabel[i]->adjustSize();
mStatsDisplayLabel[i]->adjustSize();
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 035c31f6..95e7a478 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -40,8 +40,8 @@ LocalPlayer::LocalPlayer():
Player(65535, 0, NULL),
mAttackRange(0),
mInventory(new Inventory()),
- mAttributeBase(NB_BASE_ATTRIBUTES, 0),
- mAttributeEffective(NB_BASE_ATTRIBUTES, 0),
+ mAttributeBase(NB_CHARACTER_ATTRIBUTES, 0),
+ mAttributeEffective(NB_CHARACTER_ATTRIBUTES, 0),
mAttributeIncreasePoints(0),
mLevel(1), mMoney(0),
mTotalWeight(1), mMaxWeight(1),
diff --git a/src/localplayer.h b/src/localplayer.h
index d2aef38b..111501c7 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -36,64 +36,74 @@ class Inventory;
class Item;
/**
- * Stats every being needs
+ * Attributes used during combat. Available to all the beings.
*/
-enum BeingStats
+enum
{
- BASE_ATTR_STRENGTH = 0, // Basic attributes
- BASE_ATTR_AGILITY,
- BASE_ATTR_DEXTERITY,
- BASE_ATTR_VITALITY,
- BASE_ATTR_INTELLIGENCE,
- BASE_ATTR_WILLPOWER,
- BASE_ATTR_CHARISMA,
- NB_BASE_ATTRIBUTES,
-
- ATTR_EFF_STRENGTH = NB_BASE_ATTRIBUTES, // modified basic attributes
- ATTR_EFF_AGILITY,
- ATTR_EFF_DEXTERITY,
- ATTR_EFF_VITALITY,
- ATTR_EFF_INTELLIGENCE,
- ATTR_EFF_WILLPOWER,
- ATTR_EFF_CHARISMA,
- NB_EFFECTIVE_ATTRIBUTES,
-
- DERIVED_ATTR_HP_MAXIMUM = NB_EFFECTIVE_ATTRIBUTES, // Computed stats
- DERIVED_ATTR_PHYSICAL_ATTACK_MINIMUM,
- DERIVED_ATTR_PHYSICAL_ATTACK_FLUCTUATION,
- DERIVED_ATTR_PHYSICAL_DEFENCE,
- // add new computed statistics when they are needed
- NB_ATTRIBUTES_BEING
+ BASE_ATTR_BEGIN = 0,
+ BASE_ATTR_PHY_ATK = BASE_ATTR_BEGIN,
+ BASE_ATTR_MAG_ATK,
+ BASE_ATTR_PHY_RES,
+ BASE_ATTR_MAG_RES,
+ BASE_ATTR_EVADE,
+ BASE_ATTR_HP,
+ BASE_ATTR_END,
+ BASE_ATTR_NB = BASE_ATTR_END - BASE_ATTR_BEGIN,
+
+ BASE_ELEM_BEGIN = BASE_ATTR_END,
+ BASE_ELEM_NEUTRAL = BASE_ELEM_BEGIN,
+ BASE_ELEM_FIRE,
+ BASE_ELEM_WATER,
+ BASE_ELEM_EARTH,
+ BASE_ELEM_AIR,
+ BASE_ELEM_SACRED,
+ BASE_ELEM_DEATH,
+ BASE_ELEM_END,
+ BASE_ELEM_NB = BASE_ELEM_END - BASE_ELEM_BEGIN,
+
+ NB_BEING_ATTRIBUTES = BASE_ELEM_END
};
/**
- * Player character specific stats
+ * Attributes of characters. Used to derive being attributes.
*/
-enum CharacterStats
+enum
{
- CHAR_SKILL_WEAPON_UNARMED = NB_ATTRIBUTES_BEING,
+ CHAR_ATTR_BEGIN = BASE_ATTR_END,
+ CHAR_ATTR_STRENGTH = CHAR_ATTR_BEGIN,
+ CHAR_ATTR_AGILITY,
+ CHAR_ATTR_DEXTERITY,
+ CHAR_ATTR_VITALITY,
+ CHAR_ATTR_INTELLIGENCE,
+ CHAR_ATTR_WILLPOWER,
+ CHAR_ATTR_CHARISMA,
+ CHAR_ATTR_END,
+ CHAR_ATTR_NB = CHAR_ATTR_END - CHAR_ATTR_BEGIN,
+
+ CHAR_SKILL_WEAPON_BEGIN = CHAR_ATTR_END,
+ CHAR_SKILL_WEAPON_NONE = CHAR_SKILL_WEAPON_BEGIN,
+ CHAR_SKILL_WEAPON_KNIFE,
CHAR_SKILL_WEAPON_SWORD,
- CHAR_SKILL_WEAPON_AXE,
- CHAR_SKILL_WEAPON_POLEARM,
+ CHAR_SKILL_WEAPON_SPEAR,
CHAR_SKILL_WEAPON_JAVELIN,
- CHAR_SKILL_WEAPON_WHIP,
- CHAR_SKILL_WEAPON_DAGGER,
+ CHAR_SKILL_WEAPON_ROD,
CHAR_SKILL_WEAPON_STAFF,
+ CHAR_SKILL_WEAPON_WHIP,
+ CHAR_SKILL_WEAPON_PROJECTILE,
+ CHAR_SKILL_WEAPON_BOOMERANG,
CHAR_SKILL_WEAPON_BOW,
+ CHAR_SKILL_WEAPON_SICKLE,
CHAR_SKILL_WEAPON_CROSSBOW,
- CHAR_SKILL_WEAPON_THROWN,
- NB_CHAR_WEAPONSKILLS,
-
- CHAR_SKILL_MAGIC_IAMJUSTAPLACEHOLDER = NB_CHAR_WEAPONSKILLS,
- NB_CHAR_MAGICSKILLS,
-
- CHAR_SKILL_CRAFT_IAMJUSTAPLACEHOLDER = NB_CHAR_MAGICSKILLS,
- NB_CHAR_CRAFTSKILLS,
+ CHAR_SKILL_WEAPON_STICK,
+ CHAR_SKILL_WEAPON_HAMMER,
+ CHAR_SKILL_WEAPON_AXE,
+ CHAR_SKILL_WEAPON_HAND_PROJECTILE,
+ CHAR_SKILL_WEAPON_END,
+ CHAR_SKILL_WEAPON_NB = CHAR_SKILL_WEAPON_END - CHAR_SKILL_WEAPON_BEGIN,
- CHAR_SKILL_IAMJUSTAPLACEHOLDER = NB_CHAR_CRAFTSKILLS,
- NB_CHAR_OTHERSKILLS,
+ // Magic skills should follow.
- NB_ATTRIBUTES_CHAR = NB_CHAR_OTHERSKILLS
+ NB_CHARACTER_ATTRIBUTES = CHAR_SKILL_WEAPON_END
};
@@ -256,17 +266,17 @@ class LocalPlayer : public Player
int getMaxWeight() const
{ return mMaxWeight; }
- int getAttributeBase(size_t num) const
- { return mAttributeBase.at(num); }
+ int getAttributeBase(int num) const
+ { return mAttributeBase[num]; }
- void setAttributeBase(size_t num, int value)
- { mAttributeBase.at(num) = value; }
+ void setAttributeBase(int num, int value)
+ { mAttributeBase[num] = value; }
- int getAttributeEffective(size_t num) const
- { return mAttributeEffective.at(num); }
+ int getAttributeEffective(int num) const
+ { return mAttributeEffective[num]; }
- void setAttributeEffective(size_t num, int value)
- { mAttributeEffective.at(num) = value; }
+ void setAttributeEffective(int num, int value)
+ { mAttributeEffective[num] = value; }
int getAttributeIncreasePoints() const
{ return mAttributeIncreasePoints; }
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 335c2eb1..b94b5128 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -87,16 +87,9 @@ namespace {
PlayerHandler::PlayerHandler()
{
static const Uint16 _messages[] = {
- //SMSG_PLAYER_STAT_UPDATE_1,
- //SMSG_PLAYER_STAT_UPDATE_2,
- //SMSG_PLAYER_STAT_UPDATE_3,
- //SMSG_PLAYER_STAT_UPDATE_4,
- //SMSG_PLAYER_STAT_UPDATE_5,
- //SMSG_PLAYER_STAT_UPDATE_6,
- //SMSG_PLAYER_ARROW_MESSAGE,
GPMSG_PLAYER_MAP_CHANGE,
GPMSG_PLAYER_SERVER_CHANGE,
- GPMSG_PLAYER_ATTRIBUTE_UPDATE,
+ GPMSG_PLAYER_ATTRIBUTE_CHANGE,
0
};
handledMessages = _messages;
@@ -118,26 +111,25 @@ void PlayerHandler::handleMessage(MessageIn &msg)
logger->log("Changing server to %s:%d", address.c_str(), port);
} break;
- case GPMSG_PLAYER_ATTRIBUTE_UPDATE:
+ case GPMSG_PLAYER_ATTRIBUTE_CHANGE:
{
logger->log("ATTRIBUTE UPDATE:");
while (msg.getUnreadLength())
{
- int stat = msg.readShort();
+ int stat = msg.readByte();
+ int base = msg.readShort();
int value = msg.readShort();
- logger->log("%d set to %d", stat, value);
+ logger->log("%d set to %d %d", stat, base, value);
- if (stat < NB_BASE_ATTRIBUTES)
+ if (stat == BASE_ATTR_HP)
{
- player_node->setAttributeBase(stat, value);
+ player_node->setMaxHP(base);
+ player_node->setHP(value);
}
- else if (stat < NB_EFFECTIVE_ATTRIBUTES)
+ else if (stat < NB_CHARACTER_ATTRIBUTES)
{
- player_node->setAttributeEffective(stat - NB_BASE_ATTRIBUTES, value);
- }
- else if (stat == DERIVED_ATTR_HP_MAXIMUM)
- {
- player_node->setMaxHP(value);
+ player_node->setAttributeBase(stat, base);
+ player_node->setAttributeEffective(stat, value);
}
else
{
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 3e67e647..d8b9fcb2 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -82,7 +82,7 @@ enum {
PGMSG_MOVE_ITEM = 0x0114, // B slot1, B slot2, B amount
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_PLAYER_ATTRIBUTE_CHANGE = 0x0130, // { B attribute, W base value, W modified value }*
GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position
// player: S name, B hair style, B hair color, B gender, B item bitmask, { W item id }*
// monster: W type id