summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/beingmanager.cpp12
-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
-rw-r--r--src/npc.cpp24
-rw-r--r--src/npc.h2
9 files changed, 63 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index 25de29df..90c563d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
* src/main.cpp, src/game.cpp: Fixed segfault on exit when OpenGL
configuration changed.
+ * src/beingmanager.cpp: Removed dead code.
+ * src/npc.cpp, src/npc.h, src/net/protocol.h, src/net/npchandler.cpp,
+ src/net/gameserver/player.cpp, src/net/gameserver/player.h: Converted
+ to new server.
+ * src/beinghandler.cpp: Added support for NPCs.
2007-07-22 Eugenio Favalli <elvenprogrammer@gmail.com>
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 14b4ea7e..a5be17d2 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -72,19 +72,7 @@ Being* BeingManager::createBeing(Uint16 id, Uint16 job)
else
being = new Being(id, job, mMap);
- // Player or NPC
- if (job < 200)
- {
- // XXX Convert for new server
- /*
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(0x0094);
- outMsg.writeInt32(id);//readLong(2));
- */
- }
-
mBeings.push_back(being);
-
return being;
}
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 }*
diff --git a/src/npc.cpp b/src/npc.cpp
index 2d291104..f65c8d19 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -27,6 +27,8 @@
#include "graphics.h"
#include "gui/gui.h"
+#include "net/messageout.h"
+#include "net/gameserver/player.h"
NPC *current_npc = 0;
@@ -57,34 +59,20 @@ NPC::drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
void
NPC::talk()
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_NPC_TALK);
- outMsg.writeLong(mId);
- outMsg.writeByte(0);
+ Net::GameServer::Player::talkToNPC(mId, true);
current_npc = this;
- */
}
void
NPC::nextDialog()
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
- outMsg.writeLong(mId);
- */
+ Net::GameServer::Player::talkToNPC(mId, false);
}
void
-NPC::dialogChoice(char choice)
+NPC::dialogChoice(int choice)
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
- outMsg.writeLong(mId);
- outMsg.writeByte(choice);
- */
+ Net::GameServer::Player::selectFromNPC(mId, choice);
}
/*
diff --git a/src/npc.h b/src/npc.h
index cf5defbc..90570b36 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -41,7 +41,7 @@ class NPC : public Being
void talk();
void nextDialog();
- void dialogChoice(char choice);
+ void dialogChoice(int choice);
void buy();
void sell();