diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-03-22 23:10:27 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-03-22 23:10:27 +0000 |
commit | 346bb6d670d630d65f8c35125831c75d031aac7f (patch) | |
tree | c79877ea0d6b46ae748bf4a6d6d3969dc483f0a4 /src/net | |
parent | 6f9a2e74958d794fb049253833b98982e915df45 (diff) | |
download | mana-346bb6d670d630d65f8c35125831c75d031aac7f.tar.gz mana-346bb6d670d630d65f8c35125831c75d031aac7f.tar.bz2 mana-346bb6d670d630d65f8c35125831c75d031aac7f.tar.xz mana-346bb6d670d630d65f8c35125831c75d031aac7f.zip |
Redesigned the localplayer class to use getters and setters instead of direct access to the member variables. Implemented communication of attributes between server and client.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/buysellhandler.cpp | 4 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 192 | ||||
-rw-r--r-- | src/net/protocol.h | 1 |
4 files changed, 27 insertions, 178 deletions
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 473a706c..45dfb9ad 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -72,7 +72,7 @@ void BuySellHandler::handleMessage(MessageIn &msg) msg.readShort(); // length n_items = (msg.getLength() - 4) / 11; buyDialog->reset(); - buyDialog->setMoney(player_node->mMoney); + buyDialog->setMoney(player_node->getMoney()); buyDialog->setVisible(true); for (int k = 0; k < n_items; k++) @@ -89,7 +89,7 @@ void BuySellHandler::handleMessage(MessageIn &msg) msg.readShort(); // length n_items = (msg.getLength() - 4) / 10; if (n_items > 0) { - sellDialog->setMoney(player_node->mMoney); + sellDialog->setMoney(player_node->getMoney()); sellDialog->reset(); sellDialog->setVisible(true); diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index ebc11bb3..34fc188d 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -202,10 +202,10 @@ CharServerHandler::readPlayerData(MessageIn &msg, int &slot) tempPlayer->setSex(msg.readByte()); tempPlayer->setHairStyle(msg.readByte()); tempPlayer->setHairColor(msg.readByte()); - tempPlayer->mLevel = msg.readByte(); - tempPlayer->mMoney = msg.readShort(); - for (int i = 0; i < 6; i++) { - tempPlayer->mAttr[i] = msg.readByte(); + tempPlayer->setLevel(msg.readByte()); + tempPlayer->setMoney(msg.readLong()); + for (int i = 0; i < 7; i++) { + tempPlayer->setAttributeBase(i, msg.readByte()); } return tempPlayer; } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 327edea3..335c2eb1 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -96,6 +96,7 @@ PlayerHandler::PlayerHandler() //SMSG_PLAYER_ARROW_MESSAGE, GPMSG_PLAYER_MAP_CHANGE, GPMSG_PLAYER_SERVER_CHANGE, + GPMSG_PLAYER_ATTRIBUTE_UPDATE, 0 }; handledMessages = _messages; @@ -117,187 +118,34 @@ void PlayerHandler::handleMessage(MessageIn &msg) logger->log("Changing server to %s:%d", address.c_str(), port); } break; - /* - case SMSG_PLAYER_STAT_UPDATE_1: + case GPMSG_PLAYER_ATTRIBUTE_UPDATE: + { + logger->log("ATTRIBUTE UPDATE:"); + while (msg.getUnreadLength()) { - Sint16 type = msg.readShort(); - Uint32 value = msg.readLong(); + int stat = msg.readShort(); + int value = msg.readShort(); + logger->log("%d set to %d", stat, value); - switch (type) + if (stat < NB_BASE_ATTRIBUTES) { - //case 0x0000: - // player_node->setWalkSpeed(msg.readLong()); - // break; - case 0x0005: player_node->mHp = value; break; - case 0x0006: player_node->mMaxHp = value; break; - case 0x0007: player_node->mMp = value; break; - case 0x0008: player_node->mMaxMp = value; break; - case 0x000b: player_node->mLevel = value; break; - case 0x000c: - player_node->mSkillPoint = value; - skillDialog->update(); - break; - case 0x0018: - if (value >= player_node->mMaxWeight / 2 && - player_node->mTotalWeight < - player_node->mMaxWeight / 2) - { - weightNotice = new OkDialog("Message", - "You are carrying more then half " - "your weight. You are unable to " - "regain health."); - weightNotice->addActionListener( - &weightListener); - } - player_node->mTotalWeight = value; - break; - case 0x0019: player_node->mMaxWeight = value; break; - case 0x0037: player_node->mJobLevel = value; break; - case 0x0009: - player_node->mStatsPointsToAttribute = value; - break; - case 0x0029: player_node->ATK = value; break; - case 0x002b: player_node->MATK = value; break; - case 0x002d: player_node->DEF = value; break; - case 0x002f: player_node->MDEF = value; break; - case 0x0031: player_node->HIT = value; break; - case 0x0032: player_node->FLEE = value; break; - case 0x0035: player_node->mAttackSpeed = value; break; + player_node->setAttributeBase(stat, value); } - - if (player_node->mHp == 0 && deathNotice == NULL) + else if (stat < NB_EFFECTIVE_ATTRIBUTES) { - deathNotice = new OkDialog("Message", - "You're now dead, press ok to restart"); - deathNotice->addActionListener(&deathListener); - player_node->setAction(Being::DEAD); + player_node->setAttributeEffective(stat - NB_BASE_ATTRIBUTES, value); } - } - break; - - case SMSG_PLAYER_STAT_UPDATE_2: - switch (msg.readShort()) { - case 0x0001: - player_node->mXp = msg.readLong(); - break; - case 0x0002: - player_node->mJobXp = msg.readLong(); - break; - case 0x0014: - player_node->mMoney = msg.readLong(); - break; - case 0x0016: - player_node->mXpForNextLevel = msg.readLong(); - break; - case 0x0017: - player_node->mJobXpForNextLevel = msg.readLong(); - break; - } - break; - - case SMSG_PLAYER_STAT_UPDATE_3: - { - Sint32 type = msg.readLong(); - Sint32 base = msg.readLong(); - Sint32 bonus = msg.readLong(); - Sint32 total = base + bonus; - - switch (type) { - case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; - break; - case 0x000e: player_node->mAttr[LocalPlayer::AGI] = total; - break; - case 0x000f: player_node->mAttr[LocalPlayer::VIT] = total; - break; - case 0x0010: player_node->mAttr[LocalPlayer::INT] = total; - break; - case 0x0011: player_node->mAttr[LocalPlayer::DEX] = total; - break; - case 0x0012: player_node->mAttr[LocalPlayer::LUK] = total; - break; + else if (stat == DERIVED_ATTR_HP_MAXIMUM) + { + player_node->setMaxHP(value); } - } - break; - - case SMSG_PLAYER_STAT_UPDATE_4: - { - Sint16 type = msg.readShort(); - Sint8 fail = msg.readByte(); - Sint8 value = msg.readByte(); - - if (fail != 1) - break; - - switch (type) { - case 0x000d: player_node->mAttr[LocalPlayer::STR] = value; - break; - case 0x000e: player_node->mAttr[LocalPlayer::AGI] = value; - break; - case 0x000f: player_node->mAttr[LocalPlayer::VIT] = value; - break; - case 0x0010: player_node->mAttr[LocalPlayer::INT] = value; - break; - case 0x0011: player_node->mAttr[LocalPlayer::DEX] = value; - break; - case 0x0012: player_node->mAttr[LocalPlayer::LUK] = value; - break; + else + { + logger->log("Warning: server wants to update unknown attribute %d to %d", stat, value); } } - break; - - // Updates stats and status points - case SMSG_PLAYER_STAT_UPDATE_5: - player_node->mStatsPointsToAttribute = msg.readShort(); - player_node->mAttr[LocalPlayer::STR] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::STR] = msg.readByte(); - player_node->mAttr[LocalPlayer::AGI] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::AGI] = msg.readByte(); - player_node->mAttr[LocalPlayer::VIT] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::VIT] = msg.readByte(); - player_node->mAttr[LocalPlayer::INT] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::INT] = msg.readByte(); - player_node->mAttr[LocalPlayer::DEX] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::DEX] = msg.readByte(); - player_node->mAttr[LocalPlayer::LUK] = msg.readByte(); - player_node->mAttrUp[LocalPlayer::LUK] = msg.readByte(); - player_node->ATK = msg.readShort(); // ATK - player_node->ATK_BONUS = msg.readShort(); // ATK bonus - player_node->MATK = msg.readShort(); // MATK max - player_node->MATK_BONUS = msg.readShort(); // MATK min - player_node->DEF = msg.readShort(); // DEF - player_node->DEF_BONUS = msg.readShort(); // DEF bonus - player_node->MDEF = msg.readShort(); // MDEF - player_node->MDEF_BONUS = msg.readShort(); // MDEF bonus - player_node->HIT = msg.readShort(); // HIT - player_node->FLEE = msg.readShort(); // FLEE - player_node->FLEE_BONUS = msg.readShort(); // FLEE bonus - msg.readShort(); // critical - msg.readShort(); // unknown - break; - - case SMSG_PLAYER_STAT_UPDATE_6: - switch (msg.readShort()) { - case 0x0020: - player_node->mAttrUp[LocalPlayer::STR] = msg.readByte(); - break; - case 0x0021: - player_node->mAttrUp[LocalPlayer::AGI] = msg.readByte(); - break; - case 0x0022: - player_node->mAttrUp[LocalPlayer::VIT] = msg.readByte(); - break; - case 0x0023: - player_node->mAttrUp[LocalPlayer::INT] = msg.readByte(); - break; - case 0x0024: - player_node->mAttrUp[LocalPlayer::DEX] = msg.readByte(); - break; - case 0x0025: - player_node->mAttrUp[LocalPlayer::LUK] = msg.readByte(); - break; - } - break; - + } break; + /* case SMSG_PLAYER_ARROW_MESSAGE: { Sint16 type = msg.readShort(); diff --git a/src/net/protocol.h b/src/net/protocol.h index 980e841a..a9ee0e5b 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -160,6 +160,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 // player: S name, B hair style, B hair color, B gender // monster: W type id |