summaryrefslogtreecommitdiff
path: root/src/net/manaserv/playerhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/manaserv/playerhandler.cpp')
-rw-r--r--src/net/manaserv/playerhandler.cpp111
1 files changed, 59 insertions, 52 deletions
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 33367927..be09ff69 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -24,14 +24,14 @@
#include "client.h"
#include "effectmanager.h"
+#include "event.h"
#include "game.h"
#include "localplayer.h"
#include "log.h"
#include "particle.h"
-#include "npc.h"
+#include "playerinfo.h"
#include "configuration.h"
-#include "gui/chat.h"
#include "gui/gui.h"
#include "gui/okdialog.h"
#include "gui/viewport.h"
@@ -39,10 +39,11 @@
#include "net/net.h"
#include "net/manaserv/connection.h"
+#include "net/manaserv/defines.h"
#include "net/manaserv/messagein.h"
#include "net/manaserv/messageout.h"
-#include "net/manaserv/npchandler.h"
#include "net/manaserv/protocol.h"
+#include "net/manaserv/attributes.h"
/**
* Max. distance we are willing to scroll after a teleport;
@@ -64,9 +65,7 @@ void RespawnRequestListener::action(const gcn::ActionEvent &event)
{
Net::getPlayerHandler()->respawn();
- ManaServ::NpcHandler *handler =
- static_cast<ManaServ::NpcHandler*>(Net::getNpcHandler());
- handler->clearDialogs();
+ Mana::Event::trigger(CHANNEL_NPC, EVENT_CLOSEALL);
}
PlayerHandler::PlayerHandler()
@@ -112,23 +111,24 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
case GPMSG_PLAYER_ATTRIBUTE_CHANGE:
{
- logger->log("ATTRIBUTE UPDATE:");
while (msg.getUnreadLength())
{
- int stat = msg.readInt16();
- int base = msg.readInt16();
- int value = msg.readInt16();
- logger->log("%d set to %d %d", stat, base, value);
-
- if (stat == BASE_ATTR_HP)
+ int attrId = msg.readInt16();
+ double base = msg.readInt32() / 256.0;
+ double value = msg.readInt32() / 256.0;
+
+ // Set the core player attribute the stat
+ // depending on attribute link.
+ int playerInfoId =
+ Attributes::getPlayerInfoIdFromAttrId(attrId);
+ if (playerInfoId > -1)
{
- player_node->setMaxHp(base);
- player_node->setHp(value);
+ PlayerInfo::setAttribute(playerInfoId, value);
}
else
{
- player_node->setAttributeBase(stat, base);
- player_node->setAttributeEffective(stat, value);
+ PlayerInfo::setStatBase(attrId, base);
+ PlayerInfo::setStatMod(attrId, value - base);
}
}
} break;
@@ -142,33 +142,33 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
int current = msg.readInt32();
int next = msg.readInt32();
- player_node->setExperience(skill, current, next);
+ PlayerInfo::setStatExperience(skill, current, next);
}
} break;
case GPMSG_LEVELUP:
{
- player_node->setLevel(msg.readInt16());
- player_node->setCharacterPoints(msg.readInt16());
- player_node->setCorrectionPoints(msg.readInt16());
+ PlayerInfo::setAttribute(LEVEL, msg.readInt16());
+ PlayerInfo::setAttribute(CHAR_POINTS, msg.readInt16());
+ PlayerInfo::setAttribute(CORR_POINTS, msg.readInt16());
Particle* effect = particleEngine->addEffect(
- paths.getValue("particles", "graphics/particles/")
- + paths.getValue("levelUpEffectFile", "levelup.particle.xml"),
- 0, 0);
+ paths.getStringValue("particles")
+ + paths.getStringValue("levelUpEffectFile")
+ ,0, 0);
player_node->controlParticle(effect);
} break;
case GPMSG_LEVEL_PROGRESS:
{
- player_node->setExp(msg.readInt8(), false);
+ PlayerInfo::setAttribute(EXP, msg.readInt8());
} break;
case GPMSG_RAISE_ATTRIBUTE_RESPONSE:
{
int errCode = msg.readInt8();
- int attrNum = msg.readInt8() - CHAR_ATTR_BEGIN;
+ int attrNum = msg.readInt16();
switch (errCode)
{
case ATTRIBMOD_OK:
@@ -185,18 +185,19 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
// has to be correct. The server is always right!
// undo attribute change and set points to 0
logger->log("Warning: Server denied increase of attribute %d (no points left) ", attrNum);
- int attrValue = player_node->getAttributeBase(attrNum) - 1;
- player_node->setCharacterPoints(0);
- player_node->setAttributeBase(attrNum, attrValue);
+ int attrValue = PlayerInfo::getStatBase(attrNum) - 1;
+ PlayerInfo::setAttribute(CHAR_POINTS, 0);
+ PlayerInfo::setStatBase(attrNum, attrValue);
} break;
case ATTRIBMOD_DENIED:
{
// undo attribute change
logger->log("Warning: Server denied increase of attribute %d (reason unknown) ", attrNum);
- int points = player_node->getCharacterPoints() - 1;
- player_node->setCharacterPoints(points);
- int attrValue = player_node->getAttributeBase(attrNum) - 1;
- player_node->setAttributeBase(attrNum, attrValue);
+ int points = PlayerInfo::getAttribute(CHAR_POINTS) - 1;
+ PlayerInfo::setAttribute(CHAR_POINTS, points);
+
+ int attrValue = PlayerInfo::getStatBase(attrNum) - 1;
+ PlayerInfo::setStatBase(attrNum, attrValue);
} break;
}
} break;
@@ -204,7 +205,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
case GPMSG_LOWER_ATTRIBUTE_RESPONSE:
{
int errCode = msg.readInt8();
- int attrNum = msg.readInt8() - CHAR_ATTR_BEGIN;
+ int attrNum = msg.readInt16();
switch (errCode)
{
case ATTRIBMOD_OK:
@@ -221,21 +222,24 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
// has to be correct. The server is always right!
// undo attribute change and set points to 0
logger->log("Warning: Server denied reduction of attribute %d (no points left) ", attrNum);
- int attrValue = player_node->getAttributeBase(attrNum) + 1;
- player_node->setCorrectionPoints(0);
- player_node->setAttributeBase(attrNum, attrValue);
- break;
+ int attrValue = PlayerInfo::getStatBase(attrNum) + 1;
+ // TODO are these right?
+ PlayerInfo::setAttribute(CHAR_POINTS, 0);
+ PlayerInfo::setAttribute(CORR_POINTS, 0);
+ PlayerInfo::setStatBase(attrNum, attrValue);
} break;
case ATTRIBMOD_DENIED:
{
// undo attribute change
logger->log("Warning: Server denied reduction of attribute %d (reason unknown) ", attrNum);
- int charaPoints = player_node->getCharacterPoints() - 1;
- player_node->setCharacterPoints(charaPoints);
- int correctPoints = player_node->getCorrectionPoints() + 1;
- player_node->setCorrectionPoints(correctPoints);
- int attrValue = player_node->getAttributeBase(attrNum) + 1;
- player_node->setAttributeBase(attrNum, attrValue);
+ int charaPoints = PlayerInfo::getAttribute(CHAR_POINTS) - 1;
+ PlayerInfo::setAttribute(CHAR_POINTS, charaPoints);
+
+ int correctPoints = PlayerInfo::getAttribute(CORR_POINTS) + 1;
+ PlayerInfo::setAttribute(CORR_POINTS, correctPoints);
+
+ int attrValue = PlayerInfo::getStatBase(attrNum) + 1;
+ PlayerInfo::setStatBase(attrNum, attrValue);
} break;
}
@@ -250,7 +254,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
int current = msg.readInt32();
int max = msg.readInt32();
int recharge = msg.readInt32();
- player_node->setSpecialStatus(id, current, max, recharge);
+ PlayerInfo::setSpecialStatus(id, current, max, recharge);
}
} break;
/*
@@ -325,14 +329,14 @@ void PlayerHandler::emote(int emoteId)
void PlayerHandler::increaseAttribute(int attr)
{
MessageOut msg(PGMSG_RAISE_ATTRIBUTE);
- msg.writeInt8(attr);
+ msg.writeInt16(attr);
gameServerConnection->send(msg);
}
void PlayerHandler::decreaseAttribute(int attr)
{
MessageOut msg(PGMSG_LOWER_ATTRIBUTE);
- msg.writeInt8(attr);
+ msg.writeInt16(attr);
gameServerConnection->send(msg);
}
@@ -343,11 +347,14 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- int id = floorItem->getId();
- MessageOut msg(PGMSG_PICKUP);
- msg.writeInt16(id >> 16);
- msg.writeInt16(id & 0xFFFF);
- gameServerConnection->send(msg);
+ if (floorItem)
+ {
+ int id = floorItem->getId();
+ MessageOut msg(PGMSG_PICKUP);
+ msg.writeInt16(id >> 16);
+ msg.writeInt16(id & 0xFFFF);
+ gameServerConnection->send(msg);
+ }
}
void PlayerHandler::setDirection(char direction)