summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 16:51:13 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 16:51:13 +0000
commit430bbe292eb51b3f3bb7b356d8b218b28bed0ff4 (patch)
treeafe53ed4e2978408a0082ec974f0b9dfab32a00c /src/net
parenta30bb2e92405fb379db298f2996e1c0ecd3f4bbd (diff)
downloadmana-client-430bbe292eb51b3f3bb7b356d8b218b28bed0ff4.tar.gz
mana-client-430bbe292eb51b3f3bb7b356d8b218b28bed0ff4.tar.bz2
mana-client-430bbe292eb51b3f3bb7b356d8b218b28bed0ff4.tar.xz
mana-client-430bbe292eb51b3f3bb7b356d8b218b28bed0ff4.zip
Converted NPC code to new server.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/beinghandler.cpp13
-rw-r--r--src/net/gameserver/player.cpp17
-rw-r--r--src/net/gameserver/player.h4
-rw-r--r--src/net/npchandler.cpp34
-rw-r--r--src/net/protocol.h6
5 files changed, 51 insertions, 23 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 51609b1d..bce2c3b8 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -486,13 +486,24 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg)
{
int monsterId = msg.readShort();
Being *being;
- being = beingManager->createBeing(id, 1002 + monsterId);
+ being = beingManager->createBeing(id, monsterId);
being->setWalkSpeed(150); // TODO
being->mX = px;
being->mY = py;
being->setDestination(px, py);
being->setAction(action);
} break;
+
+ case OBJECT_NPC:
+ {
+ int npcId = msg.readShort();
+ Being *being;
+ being = beingManager->createBeing(id, npcId);
+ being->mX = px;
+ being->mY = py;
+ being->setDestination(px, py);
+ being->setAction(action);
+ } break;
}
}
diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp
index 9af0c238..daf76c3e 100644
--- a/src/net/gameserver/player.cpp
+++ b/src/net/gameserver/player.cpp
@@ -67,7 +67,7 @@ void Net::GameServer::Player::equip(int slot)
Net::GameServer::connection->send(msg);
}
-void Net::GameServer::Player::attack(unsigned char direction)
+void Net::GameServer::Player::attack(int direction)
{
MessageOut msg(PGMSG_ATTACK);
msg.writeByte(direction);
@@ -80,3 +80,18 @@ void Net::GameServer::Player::changeAction(Being::Action action)
msg.writeByte(action);
Net::GameServer::connection->send(msg);
}
+
+void Net::GameServer::Player::talkToNPC(int id, bool restart)
+{
+ MessageOut msg(restart ? PGMSG_NPC_TALK : PGMSG_NPC_TALK_NEXT);
+ msg.writeShort(id);
+ Net::GameServer::connection->send(msg);
+}
+
+void Net::GameServer::Player::selectFromNPC(int id, int choice)
+{
+ MessageOut msg(PGMSG_NPC_SELECT);
+ msg.writeShort(id);
+ msg.writeByte(choice);
+ Net::GameServer::connection->send(msg);
+}
diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h
index 7cc45486..cb6927ba 100644
--- a/src/net/gameserver/player.h
+++ b/src/net/gameserver/player.h
@@ -39,8 +39,10 @@ namespace Net
void pickUp(int x, int y);
void drop(int slot, int amount);
void equip(int slot);
- void attack(unsigned char direction);
+ void attack(int direction);
void changeAction(Being::Action action);
+ void talkToNPC(int id, bool restart);
+ void selectFromNPC(int id, int choice);
}
}
}
diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp
index 02204a84..888a3a29 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -38,10 +38,8 @@ extern NpcTextDialog *npcTextDialog;
NPCHandler::NPCHandler()
{
static const Uint16 _messages[] = {
- SMSG_NPC_CHOICE,
- SMSG_NPC_MESSAGE,
- SMSG_NPC_NEXT,
- SMSG_NPC_CLOSE,
+ GPMSG_NPC_CHOICE,
+ GPMSG_NPC_MESSAGE,
0
};
handledMessages = _messages;
@@ -49,30 +47,26 @@ NPCHandler::NPCHandler()
void NPCHandler::handleMessage(MessageIn &msg)
{
- int id;
+ Being *being = beingManager->findBeing(msg.readShort());
+ if (!being || being->getType() != Being::NPC)
+ {
+ return;
+ }
+
+ current_npc = static_cast< NPC * >(being);
+ std::string text = msg.readString(msg.getUnreadLength());
switch (msg.getId())
{
- case SMSG_NPC_CHOICE:
- msg.readShort(); // length
- id = msg.readLong();
- current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id));
- npcListDialog->parseItems(msg.readString(msg.getLength() - 8));
+ case GPMSG_NPC_CHOICE:
+ npcListDialog->parseItems(text);
npcListDialog->setVisible(true);
break;
- case SMSG_NPC_MESSAGE:
- msg.readShort(); // length
- id = msg.readLong();
- current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id));
- npcTextDialog->addText(msg.readString(msg.getLength() - 8));
+ case GPMSG_NPC_MESSAGE:
+ npcTextDialog->addText(text);
npcListDialog->setVisible(false);
npcTextDialog->setVisible(true);
break;
-
- case SMSG_NPC_NEXT:
- case SMSG_NPC_CLOSE:
- // Next/Close button in NPC dialog, currently unused
- break;
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index f13b6a02..8fe7e1b6 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -165,6 +165,7 @@ enum {
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
+ // npc: W type id
GPMSG_BEING_LEAVE = 0x0201, // W being id
GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position
GPMSG_BEING_LOOKS_CHANGE = 0x0210, // W weapon, W hat, W top clothes, W bottom clothes
@@ -177,6 +178,11 @@ enum {
GPMSG_BEING_ATTACK = 0x0291, // W being id
PGMSG_SAY = 0x02A0, // S text
GPMSG_SAY = 0x02A1, // W being id, S text
+ GPMSG_NPC_CHOICE = 0x02B0, // W being id, B* text
+ GPMSG_NPC_MESSAGE = 0x02B1, // W being id, B* text
+ PGMSG_NPC_TALK = 0x02B2, // W being id
+ PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id
+ PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*